1 | <?php
|
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2007 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_PATH . "pages/LC_Page.php");
|
---|
26 |
|
---|
27 | // SC_SendMailの拡張
|
---|
28 | if(file_exists(MODULE2_PATH . "module_inc.php")) {
|
---|
29 | require_once(MODULE2_PATH . "module_inc.php");
|
---|
30 | } else {
|
---|
31 | require_once(CLASS_EX_PATH . "SC_SendMail_Ex.php");
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * メール配信履歴 のページクラス.
|
---|
36 | *
|
---|
37 | * @package Page
|
---|
38 | * @author LOCKON CO.,LTD.
|
---|
39 | * @version $Id$
|
---|
40 | */
|
---|
41 | class LC_Page_Admin_Mail_Sendmail extends LC_Page {
|
---|
42 |
|
---|
43 | // }}}
|
---|
44 | // {{{ functions
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Page を初期化する.
|
---|
48 | *
|
---|
49 | * @return void
|
---|
50 | */
|
---|
51 | function init() {
|
---|
52 | parent::init();
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Page のプロセス.
|
---|
57 | *
|
---|
58 | * @return void
|
---|
59 | */
|
---|
60 | function process() {
|
---|
61 | $conn = new SC_DbConn();
|
---|
62 | $objSite = new SC_SiteInfo($conn);
|
---|
63 |
|
---|
64 | if(MELMAGA_SEND != true) {
|
---|
65 | exit;
|
---|
66 | }
|
---|
67 |
|
---|
68 | //リアルタイム配信モードがオンのとき
|
---|
69 | if($_GET['mode'] == 'now') {
|
---|
70 | //---- 未送信データを取得する
|
---|
71 | $time_data = $conn->getAll( "SELECT send_id FROM dtb_send_history WHERE complete_count = 0 AND del_flg = 0 AND end_date IS NULL ORDER BY send_id ASC, start_date ASC" );
|
---|
72 | } else {
|
---|
73 | // postgresql と mysql とでSQLをわける
|
---|
74 | if (DB_TYPE == "pgsql") {
|
---|
75 | $sql = "SELECT send_id FROM dtb_send_history ";
|
---|
76 | $sql.= "WHERE start_date BETWEEN current_timestamp + '- 5 minutes' AND current_timestamp + '5 minutes' AND del_flg = 0 AND end_date IS NULL ORDER BY send_id ASC, start_date ASC";
|
---|
77 | }else if (DB_TYPE == "mysql") {
|
---|
78 | $sql = "SELECT send_id FROM dtb_send_history ";
|
---|
79 | $sql.= "WHERE start_date BETWEEN date_add(now(),INTERVAL -5 minute) AND date_add(now(),INTERVAL 5 minute) AND del_flg = 0 AND end_date IS NULL ORDER BY send_id ASC, start_date ASC";
|
---|
80 | }
|
---|
81 | //---- 30分毎にCronが送信時間データ確認
|
---|
82 | $time_data = $conn->getAll($sql);
|
---|
83 | }
|
---|
84 |
|
---|
85 | //未送信メルマガの数
|
---|
86 | $count = count($time_data);
|
---|
87 |
|
---|
88 | //未送信メルマガがあれば送信処理を続ける。なければ中断する。
|
---|
89 | if( $count > 0 ){
|
---|
90 | print("start sending <br />\n");
|
---|
91 | } else {
|
---|
92 | print("not found <br />\n");
|
---|
93 | exit;
|
---|
94 | }
|
---|
95 |
|
---|
96 | //---- メール送信準備
|
---|
97 | for( $i = 0; $i < $count; $i++ ) {
|
---|
98 | // 送信先リストの取得
|
---|
99 | $sql = "SELECT * FROM dtb_send_customer WHERE send_id = ? AND (send_flag = 2 OR send_flag IS NULL)";
|
---|
100 | $list_data[] = $conn->getAll( $sql, array( $time_data[$i]["send_id"] ) );
|
---|
101 | // 送信先データの取得
|
---|
102 | $sql = "SELECT * FROM dtb_send_history WHERE send_id = ?";
|
---|
103 | $mail_data[] = $conn->getAll( $sql, array( $time_data[$i]["send_id"] ) );
|
---|
104 | }
|
---|
105 |
|
---|
106 | //---- 送信結果フラグ用SQL
|
---|
107 | $sql_flag ="UPDATE dtb_send_customer SET send_flag = ? WHERE send_id = ? AND customer_id = ?";
|
---|
108 | $objMail = new SC_SendMail_Ex();
|
---|
109 |
|
---|
110 | //---- メール生成と送信
|
---|
111 | for( $i = 0; $i < $count; $i++ ) {
|
---|
112 | for( $j = 0; $j < count( $list_data[$i] ); $j ++ ) {
|
---|
113 | $customerName = "";
|
---|
114 | $mailBody = "";
|
---|
115 | $sendFlag = "";
|
---|
116 |
|
---|
117 | //-- 顧客名の変換
|
---|
118 | $name = trim($list_data[$i][$j]["name"]);
|
---|
119 |
|
---|
120 | if ($name == "") {
|
---|
121 | $name = "お客";
|
---|
122 | }
|
---|
123 |
|
---|
124 | $customerName = htmlspecialchars($name);
|
---|
125 | $subjectBody = ereg_replace( "{name}", $customerName , $mail_data[$i][0]["subject"] );
|
---|
126 | $mailBody = ereg_replace( "{name}", $customerName , $mail_data[$i][0]["body"] );
|
---|
127 |
|
---|
128 | $objMail->setItem(
|
---|
129 | $list_data[$i][$j]["email"]
|
---|
130 | ,$subjectBody
|
---|
131 | ,$mailBody
|
---|
132 | ,$objSite->data["email03"] // 送信元メールアドレス
|
---|
133 | ,$objSite->data["company_name"] // 送信元名
|
---|
134 | ,$objSite->data["email03"] // reply_to
|
---|
135 | ,$objSite->data["email04"] // return_path
|
---|
136 | ,$objSite->data["email04"] // errors_to
|
---|
137 | );
|
---|
138 |
|
---|
139 | //-- テキストメール配信の場合
|
---|
140 | if( $mail_data[$i][0]["mail_method"] == 2 ) {
|
---|
141 | $sendResut = $objMail->sendMail();
|
---|
142 | //-- HTMLメール配信の場合
|
---|
143 | } else {
|
---|
144 | $sendResut = $objMail->sendHtmlMail();
|
---|
145 | }
|
---|
146 |
|
---|
147 | //-- 送信完了なら1、失敗なら-1をメール送信結果フラグとしてDBに挿入
|
---|
148 | if( ! $sendResut ){
|
---|
149 | $sendFlag = "-1";
|
---|
150 | } else {
|
---|
151 | $sendFlag = "1";
|
---|
152 |
|
---|
153 | // 完了を 1 増やす
|
---|
154 | $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?";
|
---|
155 | $conn->query( $sql, array($mail_data[$i][0]["send_id"]));
|
---|
156 | }
|
---|
157 | $conn->query( $sql_flag, array( $sendFlag, $mail_data[$i][0]["send_id"], $list_data[$i][$j]["customer_id"] ) );
|
---|
158 | }
|
---|
159 |
|
---|
160 | //--- メール全件送信完了後の処理
|
---|
161 | $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?";
|
---|
162 | $conn->query( $completeSql, array( $time_data[$i]["send_id"] ) );
|
---|
163 |
|
---|
164 | //--- 送信完了 報告メール
|
---|
165 | $compSubject = date("Y年m月d日H時i分" . " 下記メールの配信が完了しました。" );
|
---|
166 | // 管理者宛に変更
|
---|
167 | $objMail->setTo($objSite->data["email03"]);
|
---|
168 | $objMail->setSubject($compSubject);
|
---|
169 |
|
---|
170 | //-- テキストメール配信の場合
|
---|
171 | if( $mail_data[$i][0]["mail_method"] == 2 ) {
|
---|
172 | $sendResut = $objMail->sendMail();
|
---|
173 | //-- HTMLメール配信の場合
|
---|
174 | } else {
|
---|
175 | $sendResut = $objMail->sendHtmlMail();
|
---|
176 | }
|
---|
177 | }
|
---|
178 | if ($_GET['mode'] = "now") {
|
---|
179 | header("Location: " . URL_DIR . "admin/mail/history.php");
|
---|
180 | }
|
---|
181 | echo "complete\n";
|
---|
182 | }
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * デストラクタ.
|
---|
186 | *
|
---|
187 | * @return void
|
---|
188 | */
|
---|
189 | function destroy() {
|
---|
190 | parent::destroy();
|
---|
191 | }
|
---|
192 | }
|
---|
193 | ?>
|
---|