1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2012 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_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 | */ |
---|
34 | class 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 = t('c_Mail magazine_02'); |
---|
51 | $this->tpl_subtitle = t('LC_Page_Admin_Mail_002'); |
---|
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[t('c_Unknown_01')] = t('c_Unknown_01'); |
---|
57 | $this->arrSex = $masterData->getMasterData('mtb_sex'); |
---|
58 | $this->arrPageRows = $masterData->getMasterData('mtb_page_max'); |
---|
59 | $this->arrHtmlmail = array('' => t('LC_Page_Admin_Mail_004'), 1 => t('LC_Page_Admin_Mail_005'), 2 => t('LC_Page_Admin_Mail_006')); |
---|
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') { |
---|
131 | $objFormParam->setParam($_POST); |
---|
132 | } |
---|
133 | } |
---|
134 | break; |
---|
135 | case 'regist_confirm': |
---|
136 | $this->tpl_mainpage = 'mail/input.tpl'; |
---|
137 | $this->lfAddParamSelectTemplate($objFormParam); |
---|
138 | $objFormParam->setParam($_POST); |
---|
139 | $this->arrErr = $objFormParam->checkError(); |
---|
140 | if (SC_Utils_Ex::isBlank($this->arrErr)) $this->tpl_mainpage = 'mail/input_confirm.tpl'; |
---|
141 | break; |
---|
142 | case 'regist_complete': |
---|
143 | $this->tpl_mainpage = 'mail/input.tpl'; |
---|
144 | $this->lfAddParamSelectTemplate($objFormParam); |
---|
145 | $objFormParam->setParam($_POST); |
---|
146 | $this->arrErr = $objFormParam->checkError(); |
---|
147 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
148 | $this->tpl_mainpage = 'mail/index.tpl'; |
---|
149 | SC_Helper_Mail_Ex::sfSendMailmagazine($this->lfRegisterData($objFormParam)); // DB登録・送信 |
---|
150 | |
---|
151 | SC_Response_Ex::sendRedirect('./history.php'); |
---|
152 | } |
---|
153 | break; |
---|
154 | // query:配信履歴から「確認」 |
---|
155 | case 'query': |
---|
156 | if (SC_Utils_Ex::sfIsInt($_GET['send_id'])) { |
---|
157 | $this->arrSearchData = $this->lfGetMailQuery(); |
---|
158 | } |
---|
159 | $this->setTemplate('mail/query.tpl'); |
---|
160 | break; |
---|
161 | // query:配信履歴から「再送信」 |
---|
162 | case 'retry': |
---|
163 | if (SC_Utils_Ex::sfIsInt($_GET['send_id'])) { |
---|
164 | SC_Helper_Mail_Ex::sfSendMailmagazine($_GET['send_id']); // DB登録・送信 |
---|
165 | |
---|
166 | SC_Response_Ex::sendRedirect('./history.php'); |
---|
167 | } else { |
---|
168 | $this->tpl_onload = "window.alert('" . t('c_The e-mail sending ID is not correct._01') . "');"; |
---|
169 | } |
---|
170 | break; |
---|
171 | default: |
---|
172 | break; |
---|
173 | } |
---|
174 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
175 | |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | * デストラクタ. |
---|
180 | * |
---|
181 | * @return void |
---|
182 | */ |
---|
183 | function destroy() { |
---|
184 | parent::destroy(); |
---|
185 | } |
---|
186 | |
---|
187 | /** |
---|
188 | * パラメーター情報の初期化(初期会員検索時) |
---|
189 | * |
---|
190 | * @param array $objFormParam フォームパラメータークラス |
---|
191 | * @return void |
---|
192 | */ |
---|
193 | function lfInitParamSearchCustomer(&$objFormParam) { |
---|
194 | SC_Helper_Customer_Ex::sfSetSearchParam($objFormParam); |
---|
195 | $objFormParam->addParam(t('c_Delivery format_01'), 'search_htmlmail', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK')); |
---|
196 | $objFormParam->addParam(t('c_Type of delivery e-mail address_01'), 'search_mail_type', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK')); |
---|
197 | } |
---|
198 | |
---|
199 | /** |
---|
200 | * パラメーター情報の追加(テンプレート選択) |
---|
201 | * |
---|
202 | * @param array $objFormParam フォームパラメータークラス |
---|
203 | * @return void |
---|
204 | */ |
---|
205 | function lfAddParamSelectTemplate(&$objFormParam) { |
---|
206 | $objFormParam->addParam(t('c_E-mail format_01'), 'mail_method', INT_LEN, 'n', array('EXIST_CHECK','ALNUM_CHECK')); |
---|
207 | $objFormParam->addParam(t('c_Subject_01'), 'subject', STEXT_LEN, 'KVa', array('EXIST_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK')); |
---|
208 | $objFormParam->addParam(t('c_Text_01'), 'body', LLTEXT_LEN, 'KVCa', array('EXIST_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK')); |
---|
209 | $objFormParam->addParam(t('c_Template ID_01'), 'template_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'), '', false); |
---|
210 | } |
---|
211 | |
---|
212 | /** |
---|
213 | * メルマガテンプレート一覧情報の取得 |
---|
214 | * |
---|
215 | * @param array $arrTemplate SC_Helper_Mail_Ex::sfGetMailmagaTemplate()の戻り値 |
---|
216 | * @return array key:template_id value:サブジェクト【配信形式】 |
---|
217 | */ |
---|
218 | function lfGetMailTemplateList($arrTemplate) { |
---|
219 | if (is_array($arrTemplate)) { |
---|
220 | foreach ($arrTemplate as $line) { |
---|
221 | $return[$line['template_id']] = t('LC_Page_Admin_Mail_007', array('T_ARG1' => $this->arrHtmlmail[$line['mail_method']])) . $line['subject']; |
---|
222 | } |
---|
223 | } |
---|
224 | return $return; |
---|
225 | } |
---|
226 | |
---|
227 | /** |
---|
228 | * テンプレートIDから情報の取得して$objFormParamにset_paramする |
---|
229 | * |
---|
230 | * @param array $objFormParam フォームパラメータークラス |
---|
231 | * @param array $template_id テンプレートID |
---|
232 | * @return void |
---|
233 | */ |
---|
234 | function lfGetTemplateData(&$objFormParam, $template_id) { |
---|
235 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
236 | $objQuery->setOrder('template_id DESC'); |
---|
237 | $where = 'template_id = ?'; |
---|
238 | $arrResults = $objQuery->getRow('*', 'dtb_mailmaga_template', $where, array($template_id)); |
---|
239 | $objFormParam->setParam($arrResults); |
---|
240 | } |
---|
241 | |
---|
242 | /** |
---|
243 | * 配信内容と配信リストを書き込む |
---|
244 | * |
---|
245 | * @return integer 登録した行の dtb_send_history.send_id の値 |
---|
246 | */ |
---|
247 | function lfRegisterData(&$objFormParam) { |
---|
248 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
249 | |
---|
250 | list($linemax, $arrSendCustomer, $objNavi) = SC_Helper_Customer_Ex::sfGetSearchData($objFormParam->getHashArray(), 'All'); |
---|
251 | $send_customer_cnt = count($arrSendCustomer); |
---|
252 | |
---|
253 | $send_id = $objQuery->nextVal('dtb_send_history_send_id'); |
---|
254 | $dtb_send_history = array(); |
---|
255 | $dtb_send_history['mail_method'] = $objFormParam->getValue('mail_method'); |
---|
256 | $dtb_send_history['subject'] = $objFormParam->getValue('subject'); |
---|
257 | $dtb_send_history['body'] = $objFormParam->getValue('body'); |
---|
258 | $dtb_send_history['start_date'] = 'CURRENT_TIMESTAMP'; |
---|
259 | $dtb_send_history['creator_id'] = $_SESSION['member_id']; |
---|
260 | $dtb_send_history['send_count'] = $send_customer_cnt; |
---|
261 | $dtb_send_history['search_data'] = serialize($objFormParam->getSearchArray()); |
---|
262 | $dtb_send_history['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
263 | $dtb_send_history['create_date'] = 'CURRENT_TIMESTAMP'; |
---|
264 | $dtb_send_history['send_id'] = $send_id; |
---|
265 | $objQuery->insert('dtb_send_history', $dtb_send_history); |
---|
266 | // 「配信メールアドレス種別」に携帯メールアドレスが指定されている場合は、携帯メールアドレスに配信 |
---|
267 | $emailtype='email'; |
---|
268 | $searchmailtype = $objFormParam->getValue('search_mail_type'); |
---|
269 | if ($searchmailtype==2 || $searchmailtype==4) { |
---|
270 | $emailtype='email_mobile'; |
---|
271 | } |
---|
272 | if (is_array($arrSendCustomer)) { |
---|
273 | foreach ($arrSendCustomer as $line) { |
---|
274 | $dtb_send_customer = array(); |
---|
275 | $dtb_send_customer['customer_id'] = $line['customer_id']; |
---|
276 | $dtb_send_customer['send_id'] = $send_id; |
---|
277 | $dtb_send_customer['email'] = $line[$emailtype]; |
---|
278 | $dtb_send_customer['name'] = $line['name01'] . ' ' . $line['name02']; |
---|
279 | $objQuery->insert('dtb_send_customer', $dtb_send_customer); |
---|
280 | } |
---|
281 | } |
---|
282 | return $send_id; |
---|
283 | } |
---|
284 | |
---|
285 | /** |
---|
286 | * 配信履歴から条件を取得する |
---|
287 | * |
---|
288 | * @param integer $send_id 配信履歴番号 |
---|
289 | * @return array |
---|
290 | */ |
---|
291 | function lfGetMailQuery($send_id) { |
---|
292 | |
---|
293 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
294 | |
---|
295 | // 送信履歴より、送信条件確認画面 |
---|
296 | $sql = 'SELECT search_data FROM dtb_send_history WHERE send_id = ?'; |
---|
297 | $searchData = $objQuery->getOne($sql, array($_GET['send_id'])); |
---|
298 | return unserialize($searchData); |
---|
299 | } |
---|
300 | } |
---|