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

Revision 21693, 12.7 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 フックポイント名を変更

  • 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        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
98        $objPlugin->doAction('LC_Page_Admin_Mail_action_before', array($this));
99
100        // パラメーター管理クラス
101        $objFormParam = new SC_FormParam_Ex();
102        $this->lfInitParamSearchCustomer($objFormParam);
103        $objFormParam->setParam($_POST);
104
105        // パラメーター読み込み
106        $this->arrHidden = $objFormParam->getSearchArray();
107
108        // 入力パラメーターチェック
109        $this->arrErr = SC_Helper_Customer_Ex::sfCheckErrorSearchParam($objFormParam);
110        $this->arrForm = $objFormParam->getFormParamList();
111        if (!SC_Utils_Ex::isBlank($this->arrErr)) return;
112
113        // モードによる処理切り替え
114        switch ($this->getMode()) {
115            // 配信先検索
116            case 'search':
117            case 'back':
118                list($this->tpl_linemax, $this->arrResults, $this->objNavi) = SC_Helper_Customer_Ex::sfGetSearchData($objFormParam->getHashArray());
119                $this->arrPagenavi = $this->objNavi->arrPagenavi;
120                break;
121            // input:検索結果画面「配信内容を設定する」押下後
122            case 'input':
123                $this->tpl_mainpage = 'mail/input.tpl';
124                break;
125            // template:テンプレート選択時
126            case 'template':
127            case 'regist_back':
128                $this->tpl_mainpage = 'mail/input.tpl';
129                if (SC_Utils_Ex::sfIsInt($_POST['template_id']) === true) {
130                    $this->lfAddParamSelectTemplate($objFormParam);
131                    $this->lfGetTemplateData($objFormParam, $_POST['template_id']);
132                    // regist_back時、subject,bodyにはテンプレートを読み込むのではなく、入力内容で上書き
133                    if ($this->getMode()=='regist_back') {
134                        $objFormParam->setParam($_POST);
135                    }
136                }
137                break;
138            case 'regist_confirm':
139                $this->tpl_mainpage = 'mail/input.tpl';
140                $this->lfAddParamSelectTemplate($objFormParam);
141                $objFormParam->setParam($_POST);
142                $this->arrErr = $objFormParam->checkError();
143                if (SC_Utils_Ex::isBlank($this->arrErr)) $this->tpl_mainpage = 'mail/input_confirm.tpl';
144                break;
145            case 'regist_complete':
146                $this->tpl_mainpage = 'mail/input.tpl';
147                $this->lfAddParamSelectTemplate($objFormParam);
148                $objFormParam->setParam($_POST);
149                $this->arrErr = $objFormParam->checkError();
150                if (SC_Utils_Ex::isBlank($this->arrErr)) {
151                    $this->tpl_mainpage = 'mail/index.tpl';
152                    SC_Helper_Mail_Ex::sfSendMailmagazine($this->lfRegisterData($objFormParam));  // DB登録・送信
153
154                    // フックポイント.
155                    $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
156                    $objPlugin->doAction('LC_Page_Admin_Mail_action_regist_complete', array($this));
157
158                    SC_Response_Ex::sendRedirect('./history.php');
159                }
160                break;
161            // query:配信履歴から「確認」
162            case 'query':
163                if (SC_Utils_Ex::sfIsInt($_GET['send_id'])) {
164                    $this->arrSearchData = $this->lfGetMailQuery();
165                }
166                $this->setTemplate('mail/query.tpl');
167                break;
168            // query:配信履歴から「再送信」
169            case 'retry':
170                if (SC_Utils_Ex::sfIsInt($_GET['send_id'])) {
171                    SC_Helper_Mail_Ex::sfSendMailmagazine($_GET['send_id']);  // DB登録・送信
172
173                    // フックポイント.
174                    $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
175                    $objPlugin->doAction('LC_Page_Admin_Mail_action_retry', array($this));
176
177                    SC_Response_Ex::sendRedirect('./history.php');
178                } else {
179                    $this->tpl_onload = "window.alert('メール送信IDが正しくありません');";
180                }
181                break;
182            default:
183                break;
184        }
185        $this->arrForm = $objFormParam->getFormParamList();
186
187        // フックポイント.
188        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
189        $objPlugin->doAction('LC_Page_Admin_Mail_action_after', array($this));
190    }
191
192    /**
193     * デストラクタ.
194     *
195     * @return void
196     */
197    function destroy() {
198        parent::destroy();
199    }
200
201    /**
202     * パラメーター情報の初期化(初期会員検索時)
203     *
204     * @param array $objFormParam フォームパラメータークラス
205     * @return void
206     */
207    function lfInitParamSearchCustomer(&$objFormParam) {
208        SC_Helper_Customer_Ex::sfSetSearchParam($objFormParam);
209        $objFormParam->addParam('配信形式', 'search_htmlmail', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK'));
210        $objFormParam->addParam('配信メールアドレス種別', 'search_mail_type', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK'));
211    }
212
213    /**
214     * パラメーター情報の追加(テンプレート選択)
215     *
216     * @param array $objFormParam フォームパラメータークラス
217     * @return void
218     */
219    function lfAddParamSelectTemplate(&$objFormParam) {
220        $objFormParam->addParam('メール形式', 'mail_method', INT_LEN, 'n', array('EXIST_CHECK','ALNUM_CHECK'));
221        $objFormParam->addParam('Subject', 'subject', STEXT_LEN, 'KVa', array('EXIST_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
222        $objFormParam->addParam('本文', 'body', LLTEXT_LEN, 'KVCa', array('EXIST_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
223        $objFormParam->addParam('テンプレートID', 'template_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false);
224    }
225
226    /**
227     * メルマガテンプレート一覧情報の取得
228     *
229     * @param array $arrTemplate SC_Helper_Mail_Ex::sfGetMailmagaTemplate()の戻り値
230     * @return array key:template_id value:サブジェクト【配信形式】
231     */
232    function lfGetMailTemplateList($arrTemplate) {
233        if (is_array($arrTemplate)) {
234            foreach ($arrTemplate as $line) {
235                $return[$line['template_id']] = '【' . $this->arrHtmlmail[$line['mail_method']] . '】' . $line['subject'];
236            }
237        }
238        return $return;
239    }
240
241    /**
242     * テンプレートIDから情報の取得して$objFormParamにset_paramする
243     *
244     * @param array $objFormParam フォームパラメータークラス
245     * @param array $template_id テンプレートID
246     * @return void
247     */
248    function lfGetTemplateData(&$objFormParam, $template_id) {
249        $objQuery =& SC_Query_Ex::getSingletonInstance();
250        $objQuery->setOrder('template_id DESC');
251        $where = 'template_id = ?';
252        $arrResults = $objQuery->getRow('*', 'dtb_mailmaga_template', $where, array($template_id));
253        $objFormParam->setParam($arrResults);
254    }
255
256    /**
257     * 配信内容と配信リストを書き込む
258     *
259     * @return integer 登録した行の dtb_send_history.send_id の値
260     */
261    function lfRegisterData(&$objFormParam) {
262        $objQuery =& SC_Query_Ex::getSingletonInstance();
263
264        list($linemax, $arrSendCustomer, $objNavi) = SC_Helper_Customer_Ex::sfGetSearchData($objFormParam->getHashArray(), 'All');
265        $send_customer_cnt = count($arrSendCustomer);
266
267        $send_id = $objQuery->nextVal('dtb_send_history_send_id');
268        $dtb_send_history = array();
269        $dtb_send_history['mail_method'] = $objFormParam->getValue('mail_method');
270        $dtb_send_history['subject'] = $objFormParam->getValue('subject');
271        $dtb_send_history['body'] = $objFormParam->getValue('body');
272        $dtb_send_history['start_date'] = 'CURRENT_TIMESTAMP';
273        $dtb_send_history['creator_id'] = $_SESSION['member_id'];
274        $dtb_send_history['send_count'] = $send_customer_cnt;
275        $dtb_send_history['search_data'] = serialize($objFormParam->getSearchArray());
276        $dtb_send_history['update_date'] = 'CURRENT_TIMESTAMP';
277        $dtb_send_history['create_date'] = 'CURRENT_TIMESTAMP';
278        $dtb_send_history['send_id'] = $send_id;
279        $objQuery->insert('dtb_send_history', $dtb_send_history);
280        // 「配信メールアドレス種別」に携帯メールアドレスが指定されている場合は、携帯メールアドレスに配信
281        $emailtype='email';
282        $searchmailtype = $objFormParam->getValue('search_mail_type');
283        if ($searchmailtype==2 || $searchmailtype==4) {
284            $emailtype='email_mobile';
285        }
286        if (is_array($arrSendCustomer)) {
287            foreach ($arrSendCustomer as $line) {
288                $dtb_send_customer = array();
289                $dtb_send_customer['customer_id'] = $line['customer_id'];
290                $dtb_send_customer['send_id'] = $send_id;
291                $dtb_send_customer['email'] = $line[$emailtype];
292                $dtb_send_customer['name'] = $line['name01'] . ' ' . $line['name02'];
293                $objQuery->insert('dtb_send_customer', $dtb_send_customer);
294            }
295        }
296        return $send_id;
297    }
298
299    /**
300     * 配信履歴から条件を取得する
301     *
302     * @param integer $send_id 配信履歴番号
303     * @return array
304     */
305    function lfGetMailQuery($send_id) {
306
307        $objQuery =& SC_Query_Ex::getSingletonInstance();
308
309        // 送信履歴より、送信条件確認画面
310        $sql = 'SELECT search_data FROM dtb_send_history WHERE send_id = ?';
311        $searchData = $objQuery->getOne($sql, array($_GET['send_id']));
312        return unserialize($searchData);
313    }
314}
Note: See TracBrowser for help on using the repository browser.