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 |
---|
25 | require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * メール配信履歴 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Mail_Sendmail extends LC_Page_Admin { |
---|
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_REALDIR . "mdl_speedmail/SC_SpeedMail.php")) { |
---|
48 | require_once(MODULE_REALDIR . "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->sfGetBasisData(); |
---|
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 | $dbFactory = SC_DB_DBFactory::getInstance(); |
---|
86 | $where .= $dbFactory->getSendHistoryWhereStartdateSql(); |
---|
87 | // 30分毎にCronが送信時間データ確認 |
---|
88 | } |
---|
89 | $objQuery->setOrder('send_id'); |
---|
90 | $arrMailList = $objQuery->select('*', 'dtb_send_history', $where, $sqlval); |
---|
91 | $objQuery->setOrder(''); |
---|
92 | |
---|
93 | // 未送信メルマガがあれば送信処理を続ける。なければ中断する。 |
---|
94 | if (empty($arrMailList)) { |
---|
95 | echo "not found\n"; |
---|
96 | exit; |
---|
97 | } |
---|
98 | |
---|
99 | echo "start sending\n"; |
---|
100 | |
---|
101 | // メール生成と送信 |
---|
102 | foreach ($arrMailList as $arrMail) { |
---|
103 | $sendFlag = null; |
---|
104 | |
---|
105 | // 送信先リストの取得 |
---|
106 | $arrDestinationList = $objQuery->select( |
---|
107 | '*', |
---|
108 | 'dtb_send_customer', |
---|
109 | 'send_id = ? AND (send_flag = 2 OR send_flag IS NULL)', |
---|
110 | array($arrMail["send_id"]) |
---|
111 | ); |
---|
112 | |
---|
113 | foreach ($arrDestinationList as $arrDestination) { |
---|
114 | |
---|
115 | // 顧客名の変換 |
---|
116 | $name = trim($arrDestination["name"]); |
---|
117 | |
---|
118 | if ($name == "") { |
---|
119 | $name = "お客"; |
---|
120 | } |
---|
121 | |
---|
122 | $customerName = htmlspecialchars($name); |
---|
123 | $subjectBody = ereg_replace("{name}", $customerName, $arrMail["subject"]); |
---|
124 | $mailBody = ereg_replace("{name}", $customerName, $arrMail["body"]); |
---|
125 | |
---|
126 | $this->objMail->setItem( |
---|
127 | $arrDestination["email"], |
---|
128 | $subjectBody, |
---|
129 | $mailBody, |
---|
130 | $objSite->data["email03"], // 送信元メールアドレス |
---|
131 | $objSite->data["shop_name"], // 送信元名 |
---|
132 | $objSite->data["email03"], // reply_to |
---|
133 | $objSite->data["email04"], // return_path |
---|
134 | $objSite->data["email04"] // errors_to |
---|
135 | ); |
---|
136 | |
---|
137 | // テキストメール配信の場合 |
---|
138 | if ($arrMail["mail_method"] == 2) { |
---|
139 | $sendResut = $this->objMail->sendMail(); |
---|
140 | // HTMLメール配信の場合 |
---|
141 | } else { |
---|
142 | $sendResut = $this->objMail->sendHtmlMail(); |
---|
143 | } |
---|
144 | |
---|
145 | // 送信完了なら1、失敗なら2をメール送信結果フラグとしてDBに挿入 |
---|
146 | if (!$sendResut) { |
---|
147 | $sendFlag = '2'; |
---|
148 | } else { |
---|
149 | $sendFlag = '1'; |
---|
150 | |
---|
151 | // 完了を 1 増やす |
---|
152 | $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?"; |
---|
153 | $objQuery->query($sql, array($arrMail["send_id"])); |
---|
154 | } |
---|
155 | |
---|
156 | // 送信結果フラグ |
---|
157 | $sql ="UPDATE dtb_send_customer SET send_flag = ? WHERE send_id = ? AND customer_id = ?"; |
---|
158 | $objQuery->query($sql, array($sendFlag, $arrMail["send_id"], $arrDestination["customer_id"])); |
---|
159 | } |
---|
160 | |
---|
161 | // メール全件送信完了後の処理 |
---|
162 | $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?"; |
---|
163 | $objQuery->query($completeSql, array($arrMail["send_id"])); |
---|
164 | |
---|
165 | // 送信完了 報告メール |
---|
166 | $compSubject = date("Y年m月d日H時i分") . " 下記メールの配信が完了しました。"; |
---|
167 | // 管理者宛に変更 |
---|
168 | $this->objMail->setTo($objSite->data["email03"]); |
---|
169 | $this->objMail->setSubject($compSubject); |
---|
170 | |
---|
171 | // テキストメール配信の場合 |
---|
172 | if ($arrMail["mail_method"] == 2 ) { |
---|
173 | $sendResut = $this->objMail->sendMail(); |
---|
174 | // HTMLメール配信の場合 |
---|
175 | } else { |
---|
176 | $sendResut = $this->objMail->sendHtmlMail(); |
---|
177 | } |
---|
178 | } |
---|
179 | if ($_GET['mode'] == 'now') { |
---|
180 | $this->objDisplay->redirect($this->getLocation(URL_PATH . ADMIN_DIR . 'mail/history.php')); |
---|
181 | } |
---|
182 | echo "complete\n"; |
---|
183 | } |
---|
184 | |
---|
185 | /** |
---|
186 | * デストラクタ. |
---|
187 | * |
---|
188 | * @return void |
---|
189 | */ |
---|
190 | function destroy() { |
---|
191 | parent::destroy(); |
---|
192 | } |
---|
193 | } |
---|
194 | ?> |
---|