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

Revision 22926, 11.7 KB checked in by Seasoft, 11 years ago (diff)

#2287 (環境によりデストラクタが正しく動作しないケースがある)
#2288 (リクエスト単位で実行されるべきログ出力がブロックにも適用されている)
#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

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