source: branches/comu-ver2/data/class/pages/admin/mail/LC_Page_Admin_Mail_Sendmail.php @ 18701

Revision 18701, 6.7 KB checked in by nanasess, 14 years ago (diff)

Copyright の更新(#601)

  • 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        $conn = new SC_DbConn();
65        $objQuery = new SC_Query();
66        $objSite = new SC_SiteInfo($conn);
67
68        if (MELMAGA_SEND != true) {
69            exit;
70        }
71
72        $where = 'del_flg = 0';
73        $sqlval = array();
74        // リアルタイム配信モードがオンのとき
75        if ($_GET['mode'] == 'now') {
76            // 指定データを取得する
77            $where .= ' AND send_id = ?';
78            $sqlval[] = $_GET['send_id'];
79            if ($_GET['retry'] != 'yes') {
80                $where .= ' AND complete_count = 0 AND end_date IS NULL';
81            }
82        } else {
83            $where .= ' AND end_date IS NULL';
84            // postgresql と mysql とでSQLをわける
85            if (DB_TYPE == "pgsql") {
86                $where .= "start_date BETWEEN current_timestamp + '- 5 minutes' AND current_timestamp + '5 minutes'";
87            } else if (DB_TYPE == "mysql") {
88                $where .= "start_date BETWEEN date_add(now(),INTERVAL -5 minute) AND date_add(now(),INTERVAL 5 minute)";
89            }
90            // 30分毎にCronが送信時間データ確認
91        }
92        $objQuery->setOrder('send_id');
93        $arrMailList = $objQuery->select('*', 'dtb_send_history', $where, $sqlval);
94        $objQuery->setOrder('');
95
96        // 未送信メルマガがあれば送信処理を続ける。なければ中断する。
97        if (empty($arrMailList)) {
98            echo "not found\n";
99            exit;
100        }
101
102        echo "start sending\n";
103
104        // メール生成と送信
105        foreach ($arrMailList as $arrMail) {
106            $sendFlag = null;
107
108            // 送信先リストの取得
109            $arrDestinationList = $objQuery->select(
110                '*',
111                'dtb_send_customer',
112                'send_id = ? AND (send_flag = 2 OR send_flag IS NULL)',
113                array($arrMail["send_id"])
114            );
115
116            foreach ($arrDestinationList as $arrDestination) {
117
118                // 顧客名の変換
119                $name = trim($arrDestination["name"]);
120
121                if ($name == "") {
122                    $name = "お客";
123                }
124
125                $customerName = htmlspecialchars($name);
126                $subjectBody = ereg_replace("{name}", $customerName, $arrMail["subject"]);
127                $mailBody = ereg_replace("{name}", $customerName, $arrMail["body"]);
128
129                $this->objMail->setItem(
130                    $arrDestination["email"],
131                    $subjectBody,
132                    $mailBody,
133                    $objSite->data["email03"],      // 送信元メールアドレス
134                    $objSite->data["shop_name"],    // 送信元名
135                    $objSite->data["email03"],      // reply_to
136                    $objSite->data["email04"],      // return_path
137                    $objSite->data["email04"]       // errors_to
138                );
139
140                // テキストメール配信の場合
141                if ($arrMail["mail_method"] == 2) {
142                    $sendResut = $this->objMail->sendMail();
143                // HTMLメール配信の場合
144                } else {
145                    $sendResut = $this->objMail->sendHtmlMail();
146                }
147
148                // 送信完了なら1、失敗なら2をメール送信結果フラグとしてDBに挿入
149                if (!$sendResut) {
150                    $sendFlag = '2';
151                } else {
152                    $sendFlag = '1';
153
154                    // 完了を 1 増やす
155                    $sql = "UPDATE dtb_send_history SET complete_count = complete_count + 1 WHERE send_id = ?";
156                    $conn->query($sql, array($arrMail["send_id"]));
157                }
158
159                // 送信結果フラグ
160                $sql ="UPDATE dtb_send_customer SET send_flag = ? WHERE send_id = ? AND customer_id = ?";
161                $conn->query($sql, array($sendFlag, $arrMail["send_id"], $arrDestination["customer_id"]));
162            }
163
164            // メール全件送信完了後の処理
165            $completeSql = "UPDATE dtb_send_history SET end_date = now() WHERE send_id = ?";
166            $conn->query($completeSql, array($arrMail["send_id"]));
167
168            // 送信完了 報告メール
169            $compSubject = date("Y年m月d日H時i分") . "  下記メールの配信が完了しました。";
170            // 管理者宛に変更
171            $this->objMail->setTo($objSite->data["email03"]);
172            $this->objMail->setSubject($compSubject);
173
174            // テキストメール配信の場合
175            if ($arrMail["mail_method"] == 2 ) {
176                $sendResut = $this->objMail->sendMail();
177            // HTMLメール配信の場合
178            } else {
179                $sendResut = $this->objMail->sendHtmlMail();
180            }
181        }
182        if ($_GET['mode'] == 'now') {
183            $this->sendRedirect($this->getLocation(URL_DIR . 'admin/mail/history.php'));
184        }
185        echo "complete\n";
186    }
187
188    /**
189     * デストラクタ.
190     *
191     * @return void
192     */
193    function destroy() {
194        parent::destroy();
195    }
196}
197?>
Note: See TracBrowser for help on using the repository browser.