source: branches/version-2_11-dev/data/class/pages/admin/mail/LC_Page_Admin_Mail.php @ 21185

Revision 21185, 11.5 KB checked in by shutta, 13 years ago (diff)

refs #800 (SQL標準関数を使用する)
CURRENT_TIMESTAMP を使用するように now() を置換。

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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-2011 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_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
26
27/**
28 * メルマガ管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Mail extends LC_Page_Admin_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'mail/index.tpl';
47        $this->tpl_mainno = 'mail';
48        $this->tpl_subno = 'index';
49        $this->tpl_pager = 'pager.tpl';
50        $this->tpl_maintitle = 'メルマガ管理';
51        $this->tpl_subtitle = '配信内容設定';
52
53        $masterData = new SC_DB_MasterData_Ex();
54        $this->arrPref = $masterData->getMasterData('mtb_pref');
55        $this->arrJob = $masterData->getMasterData("mtb_job");
56        $this->arrJob["不明"] = "不明";
57        $this->arrSex = $masterData->getMasterData("mtb_sex");
58        $this->arrPageRows = $masterData->getMasterData("mtb_page_max");
59        $this->arrHtmlmail = array( "" => "両方",  1 => 'HTML', 2 => 'TEXT' );
60        $this->arrMailType = $masterData->getMasterData("mtb_mail_type");
61
62        // 日付プルダウン設定
63        $objDate = new SC_Date_Ex(BIRTH_YEAR);
64        $this->arrBirthYear = $objDate->getYear();
65        $this->arrRegistYear = $objDate->getYear();
66        $this->arrMonth = $objDate->getMonth();
67        $this->arrDay = $objDate->getDay();
68        $this->objDate = $objDate;
69
70        // カテゴリ一覧設定
71        $objDb = new SC_Helper_DB_Ex();
72        $this->arrCatList = $objDb->sfGetCategoryList();
73
74        // テンプレート一覧設定
75        $this->arrTemplate = $this->lfGetMailTemplateList(SC_Helper_Mail_Ex::sfGetMailmagaTemplate());
76
77        $this->httpCacheControl('nocache');
78    }
79
80    /**
81     * Page のプロセス.
82     *
83     * @return void
84     */
85    function process() {
86        $this->action();
87        $this->sendResponse();
88    }
89
90    /**
91     * Page のアクション.
92     *
93     * @return void
94     */
95    function action() {
96
97        // パラメーター管理クラス
98        $objFormParam = new SC_FormParam_Ex();
99        $this->lfInitParamSearchCustomer($objFormParam);
100        $objFormParam->setParam($_POST);
101
102        // パラメーター読み込み
103        $this->arrHidden = $objFormParam->getSearchArray();
104
105        // 入力パラメーターチェック
106        $this->arrErr = SC_Helper_Customer_Ex::sfCheckErrorSearchParam($objFormParam);
107        $this->arrForm = $objFormParam->getFormParamList();
108        if(!SC_Utils_Ex::isBlank($this->arrErr)) return;
109
110        // モードによる処理切り替え
111        switch ($this->getMode()) {
112        // 配信先検索
113        case 'search':
114        case 'back':
115            list($this->tpl_linemax, $this->arrResults, $this->objNavi) = SC_Helper_Customer_Ex::sfGetSearchData($objFormParam->getHashArray());
116            $this->arrPagenavi = $this->objNavi->arrPagenavi;
117            break;
118        // input:検索結果画面「配信内容を設定する」押下後
119        case 'input':
120            $this->tpl_mainpage = 'mail/input.tpl';
121            break;
122        // template:テンプレート選択時
123        case 'template':
124        case 'regist_back':
125            $this->tpl_mainpage = 'mail/input.tpl';
126            if (SC_Utils_Ex::sfIsInt($_POST['template_id']) === true) {
127                $this->lfAddParamSelectTemplate($objFormParam);
128                $this->lfGetTemplateData($objFormParam, $_POST['template_id']);
129                // regist_back時、subject,bodyにはテンプレートを読み込むのではなく、入力内容で上書き
130                if($this->getMode()=='regist_back') $objFormParam->setParam($_POST);
131            }
132            break;
133        case 'regist_confirm':
134            $this->tpl_mainpage = 'mail/input.tpl';
135            $this->lfAddParamSelectTemplate($objFormParam);
136            $objFormParam->setParam($_POST);
137            $this->arrErr = $objFormParam->checkError();
138            if (SC_Utils_Ex::isBlank($this->arrErr)) $this->tpl_mainpage = 'mail/input_confirm.tpl';
139            break;
140        case 'regist_complete':
141            $this->tpl_mainpage = 'mail/input.tpl';
142            $this->lfAddParamSelectTemplate($objFormParam);
143            $objFormParam->setParam($_POST);
144            $this->arrErr = $objFormParam->checkError();
145            if (SC_Utils_Ex::isBlank($this->arrErr)){
146                $this->tpl_mainpage = 'mail/index.tpl';
147                SC_Helper_Mail_Ex::sfSendMailmagazine($this->lfRegisterData($objFormParam));  // DB登録・送信
148                SC_Response_Ex::sendRedirect("./history.php");
149            }
150            break;
151        // query:配信履歴から「確認」
152        case 'query':
153            if (SC_Utils_Ex::sfIsInt($_GET["send_id"])) {
154                $this->arrSearchData = $this->lfGetMailQuery();
155            }
156            $this->setTemplate('mail/query.tpl');
157            break;
158        // query:配信履歴から「再送信」
159        case 'retry':
160            if (SC_Utils_Ex::sfIsInt($_GET["send_id"])) {
161                SC_Helper_Mail_Ex::sfSendMailmagazine($_GET['send_id']);  // DB登録・送信
162                SC_Response_Ex::sendRedirect("./history.php");
163            } else {
164                $this->tpl_onload = "window.alert('メール送信IDが正しくありません');";
165            }
166        default:
167            break;
168        }
169        $this->arrForm = $objFormParam->getFormParamList();
170    }
171
172    /**
173     * デストラクタ.
174     *
175     * @return void
176     */
177    function destroy() {
178        parent::destroy();
179    }
180
181    /**
182     * パラメーター情報の初期化(初期顧客検索時)
183     *
184     * @param array $objFormParam フォームパラメータークラス
185     * @return void
186     */
187    function lfInitParamSearchCustomer(&$objFormParam) {
188        SC_Helper_Customer_Ex::sfSetSearchParam($objFormParam);
189        $objFormParam->addParam('配信形式', 'search_htmlmail', INT_LEN, 'n', array("NUM_CHECK","MAX_LENGTH_CHECK"));
190        $objFormParam->addParam('配信メールアドレス種別', 'search_mail_type', INT_LEN, 'n', array("NUM_CHECK","MAX_LENGTH_CHECK"));
191    }
192
193    /**
194     * パラメーター情報の追加(テンプレート選択)
195     *
196     * @param array $objFormParam フォームパラメータークラス
197     * @return void
198     */
199    function lfAddParamSelectTemplate(&$objFormParam) {
200        $objFormParam->addParam("メール形式", 'mail_method', INT_LEN, 'n', array("EXIST_CHECK","ALNUM_CHECK"));
201        $objFormParam->addParam('Subject', 'subject', STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
202        $objFormParam->addParam("本文", 'body', LLTEXT_LEN, 'KVCa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
203        $objFormParam->addParam("テンプレートID", "template_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), "", false);
204    }
205
206    /**
207     * メルマガテンプレート一覧情報の取得
208     *
209     * @param array $arrTemplate SC_Helper_Mail_Ex::sfGetMailmagaTemplate()の戻り値
210     * @return array key:template_id value:サブジェクト【配信形式】
211     */
212    function lfGetMailTemplateList($arrTemplate){
213        if ( is_array($arrTemplate) ){
214            foreach( $arrTemplate as $line ){
215                $return[$line['template_id']] = "【" . $this->arrHtmlmail[$line['mail_method']] . "】" . $line['subject'];
216            }
217        }
218        return $return;
219    }
220
221    /**
222     * テンプレートIDから情報の取得して$objFormParamにset_paramする
223     *
224     * @param array $objFormParam フォームパラメータークラス
225     * @param array $template_id テンプレートID
226     * @return void
227     */
228    function lfGetTemplateData(&$objFormParam, $template_id){
229        $objQuery =& SC_Query_Ex::getSingletonInstance();
230        $objQuery->setOrder("template_id DESC");
231        $where = 'template_id = ?';
232        $arrResults = $objQuery->getRow('*', 'dtb_mailmaga_template', $where, array($template_id));
233        $objFormParam->setParam($arrResults);
234    }
235
236    /**
237     * 配信内容と配信リストを書き込む
238     *
239     * @return integer 登録した行の dtb_send_history.send_id の値
240     */
241    function lfRegisterData(&$objFormParam){
242        $objQuery =& SC_Query_Ex::getSingletonInstance();
243
244        list($linemax, $arrSendCustomer, $objNavi) = SC_Helper_Customer_Ex::sfGetSearchData($objFormParam->getHashArray());
245        $send_customer_cnt = count($arrSendCustomer);
246
247        $send_id = $objQuery->nextVal('dtb_send_history_send_id');
248        $dtb_send_history = array();
249        $dtb_send_history["mail_method"] = $objFormParam->getValue('mail_method');
250        $dtb_send_history['subject'] = $objFormParam->getValue('subject');
251        $dtb_send_history['body'] = $objFormParam->getValue('body');
252        $dtb_send_history["start_date"] = 'CURRENT_TIMESTAMP';
253        $dtb_send_history["creator_id"] = $_SESSION['member_id'];
254        $dtb_send_history["send_count"] = $send_customer_cnt;
255        $dtb_send_history["search_data"] = serialize($objFormParam->getSearchArray());
256        $dtb_send_history["update_date"] = 'CURRENT_TIMESTAMP';
257        $dtb_send_history["create_date"] = 'CURRENT_TIMESTAMP';
258        $dtb_send_history['send_id'] = $send_id;
259        $objQuery->insert("dtb_send_history", $dtb_send_history );
260        // 「配信メールアドレス種別」に携帯メールアドレスが指定されている場合は、携帯メールアドレスに配信
261        $emailtype="email";
262        $searchmailtype = $objFormParam->getValue('search_mail_type');
263        if($searchmailtype==2||$searchmailtype==4)$emailtype="email_mobile";
264        if ( is_array( $arrSendCustomer ) ){
265            foreach( $arrSendCustomer as $line ){
266                $dtb_send_customer = array();
267                $dtb_send_customer["customer_id"] = $line["customer_id"];
268                $dtb_send_customer["send_id"] = $send_id;
269                $dtb_send_customer['email'] = $line[$emailtype];
270                $dtb_send_customer['name'] = $line["name01"] . " " . $line["name02"];
271                $objQuery->insert("dtb_send_customer", $dtb_send_customer );
272            }
273        }
274        return $send_id;
275    }
276
277    /**
278     * 配信履歴から条件を取得する
279     *
280     * @param integer $send_id 配信履歴番号
281     * @return array
282     */
283    function lfGetMailQuery($send_id){
284
285        $objQuery =& SC_Query_Ex::getSingletonInstance();
286
287        // 送信履歴より、送信条件確認画面
288        $sql = "SELECT search_data FROM dtb_send_history WHERE send_id = ?";
289        $searchData = $objQuery->getOne($sql, array($_GET["send_id"]));
290        return unserialize($searchData);
291    }
292}
293?>
Note: See TracBrowser for help on using the repository browser.