source: branches/version-2_5-dev/data/class/pages/admin/mail/LC_Page_Admin_Mail_Sendmail.php @ 18770

Revision 18770, 6.7 KB checked in by nanasess, 14 years ago (diff)
  • SC_DbConn のインスタンスを直接使用している個所を SC_Query に変更(#565)
    • 削除予定の機能については未対応
  • SC_Customer で未使用の処理を削除
  • Property svn:eol-style set to LF
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27/**
28 * メール配信履歴 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Mail_Sendmail extends LC_Page {
35   
36    var $objMail;
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init() {
46         // SC_SendMailの拡張
47        if (file_exists(MODULE_PATH . "mdl_speedmail/SC_SpeedMail.php")) {
48            require_once(MODULE_PATH . "mdl_speedmail/SC_SpeedMail.php");
49            // SpeedMail対応
50            $this->objMail = new SC_SpeedMail();
51        } else {
52            $this->objMail = new SC_SendMail_Ex();
53        }
54
55        parent::init();
56    }
57
58    /**
59     * Page のプロセス.
60     *
61     * @return void
62     */
63    function process() {
64        $objQuery = new SC_Query();
65
66        $objDb = new SC_Helper_DB_Ex();
67        $objSite = $objDb->sf_getBasisData();
68
69        if (MELMAGA_SEND != true) {
70            exit;
71        }
72
73        $where = 'del_flg = 0';
74        $sqlval = array();
75        // リアルタイム配信モードがオンのとき
76        if ($_GET['mode'] == 'now') {
77            // 指定データを取得する
78            $where .= ' AND send_id = ?';
79            $sqlval[] = $_GET['send_id'];
80            if ($_GET['retry'] != 'yes') {
81                $where .= ' AND complete_count = 0 AND end_date IS NULL';
82            }
83        } else {
84            $where .= ' AND end_date IS NULL';
85            // postgresql と mysql とでSQLをわける
86            if (DB_TYPE == "pgsql") {
87                $where .= "start_date BETWEEN current_timestamp + '- 5 minutes' AND current_timestamp + '5 minutes'";
88            } else if (DB_TYPE == "mysql") {
89                $where .= "start_date BETWEEN date_add(now(),INTERVAL -5 minute) AND date_add(now(),INTERVAL 5 minute)";
90            }
91            // 30分毎にCronが送信時間データ確認
92        }
93        $objQuery->setOrder('send_id');
94        $arrMailList = $objQuery->select('*', 'dtb_send_history', $where, $sqlval);
95        $objQuery->setOrder('');
96
97        // 未送信メルマガがあれば送信処理を続ける。なければ中断する。
98        if (empty($arrMailList)) {
99            echo "not found\n";
100            exit;
101        }
102
103        echo "start sending\n";
104
105        // メール生成と送信
106        foreach ($arrMailList as $arrMail) {
107            $sendFlag = null;
108
109            // 送信先リストの取得
110            $arrDestinationList = $objQuery->select(
111                '*',
112                'dtb_send_customer',
113                'send_id = ? AND (send_flag = 2 OR send_flag IS NULL)',
114                array($arrMail["send_id"])
115            );
116
117            foreach ($arrDestinationList as $arrDestination) {
118
119                // 顧客名の変換
120                $name = trim($arrDestination["name"]);
121
122                if ($name == "") {
123                    $name = "お客";
124                }
125
126                $customerName = htmlspecialchars($name);
127                $subjectBody = ereg_replace("{name}", $customerName, $arrMail["subject"]);
128                $mailBody = ereg_replace("{name}", $customerName, $arrMail["body"]);
129
130                $this->objMail->setItem(
131                    $arrDestination["email"],
132                    $subjectBody,
133                    $mailBody,
134                    $objSite->data["email03"],      // 送信元メールアドレス
135                    $objSite->data["shop_name"],    // 送信元名
136                    $objSite->data["email03"],      // reply_to
137                    $objSite->data["email04"],      // return_path
138                    $objSite->data["email04"]       // errors_to
139                );
140
141                // テキストメール配信の場合
142                if ($arrMail["mail_method"] == 2) {
143                    $sendResut = $this->objMail->sendMail();
144                // HTMLメール配信の場合
145                } else {
146                    $sendResut = $this->objMail->sendHtmlMail();
147                }
148
149                // 送信完了なら1、失敗なら2をメール送信結果フラグとしてDBに挿入
150                if (!$sendResut) {
151                    $sendFlag = '2';
152                } else {
153                    $sendFlag = '1';
154
155                    // 完了を 1 増やす
156                    $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?";
157                    $objQuery->query($sql, array($arrMail["send_id"]));
158                }
159
160                // 送信結果フラグ
161                $sql ="UPDATE dtb_send_customer SET send_flag = ? WHERE send_id = ? AND customer_id = ?";
162                $objQuery->query($sql, array($sendFlag, $arrMail["send_id"], $arrDestination["customer_id"]));
163            }
164
165            // メール全件送信完了後の処理
166            $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?";
167            $objQuery->query($completeSql, array($arrMail["send_id"]));
168
169            // 送信完了 報告メール
170            $compSubject = date("Y年m月d日H時i分") . "  下記メールの配信が完了しました。";
171            // 管理者宛に変更
172            $this->objMail->setTo($objSite->data["email03"]);
173            $this->objMail->setSubject($compSubject);
174
175            // テキストメール配信の場合
176            if ($arrMail["mail_method"] == 2 ) {
177                $sendResut = $this->objMail->sendMail();
178            // HTMLメール配信の場合
179            } else {
180                $sendResut = $this->objMail->sendHtmlMail();
181            }
182        }
183        if ($_GET['mode'] == 'now') {
184            $this->sendRedirect($this->getLocation(URL_DIR . 'admin/mail/history.php'));
185        }
186        echo "complete\n";
187    }
188
189    /**
190     * デストラクタ.
191     *
192     * @return void
193     */
194    function destroy() {
195        parent::destroy();
196    }
197}
198?>
Note: See TracBrowser for help on using the repository browser.