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 |
---|
25 | require_once(CLASS_PATH . "pages/LC_Page.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 { |
---|
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_subnavi = 'mail/subnavi.tpl'; |
---|
49 | $this->tpl_subno = "index"; |
---|
50 | $this->tpl_pager = TEMPLATE_DIR . 'admin/pager.tpl'; |
---|
51 | $this->tpl_subtitle = '配信内容設定'; |
---|
52 | |
---|
53 | $masterData = new SC_DB_MasterData_Ex(); |
---|
54 | $this->arrPref = $masterData->getMasterData("mtb_pref", array("pref_id", "pref_name", "rank")); |
---|
55 | $this->arrJob = $masterData->getMasterData("mtb_job"); |
---|
56 | $this->arrJob["不明"] = "不明"; |
---|
57 | $this->arrSex = $masterData->getMasterData("mtb_sex"); |
---|
58 | $this->arrMailType = $masterData->getMasterData("mtb_mail_type"); |
---|
59 | $this->arrPageRows = $masterData->getMasterData("mtb_page_rows"); |
---|
60 | // ページナビ用 |
---|
61 | $this->tpl_pageno = isset($_POST['search_pageno']) ? $_POST['search_pageno'] : ""; |
---|
62 | $this->arrMAILMAGATYPE = $masterData->getMasterData("mtb_mail_magazine_type"); |
---|
63 | $this->arrHtmlmail[''] = "すべて"; |
---|
64 | $this->arrHtmlmail[1] = $this->arrMAILMAGATYPE[1]; |
---|
65 | $this->arrHtmlmail[2] = $this->arrMAILMAGATYPE[2]; |
---|
66 | $this->arrMagazineTypeAll = $masterData->getMasterData("mtb_magazine_type"); |
---|
67 | |
---|
68 | // 検索用項目配列 |
---|
69 | $this->arrHtmlmail = array( "" => "両方", 1 => "HTML", 2 => "TEXT" ); |
---|
70 | |
---|
71 | |
---|
72 | // 配列内容専用項目の配列 |
---|
73 | $this->arrRegistColumn = array( |
---|
74 | array( "column" => "template_id", "convert" => "n" ), |
---|
75 | array( "column" => "mail_method", "convert" => "n" ), |
---|
76 | array( "column" => "send_year", "convert" => "n" ), |
---|
77 | array( "column" => "send_month", "convert" => "n" ), |
---|
78 | array( "column" => "send_day", "convert" => "n" ), |
---|
79 | array( "column" => "send_hour", "convert" => "n" ), |
---|
80 | array( "column" => "send_minutes", "convert" => "n" ), |
---|
81 | array( "column" => "subject", "convert" => "aKV" ), |
---|
82 | array( "column" => "body", "convert" => "KV" ) |
---|
83 | ); |
---|
84 | |
---|
85 | // メルマガ会員種別 |
---|
86 | $this->arrCustomerType = array(1 => "会員", |
---|
87 | 2 => "非会員", |
---|
88 | // 3 => "CSV登録" |
---|
89 | ); |
---|
90 | |
---|
91 | // 検索項目 |
---|
92 | $this->arrSearchColumn = array( |
---|
93 | array( "column" => "name", "convert" => "aKV"), |
---|
94 | array( "column" => "pref", "convert" => "n" ), |
---|
95 | array( "column" => "kana", "convert" => "CKV"), |
---|
96 | array( "column" => "sex", "convert" => "" ), |
---|
97 | array( "column" => "tel", "convert" => "n" ), |
---|
98 | array( "column" => "job", "convert" => "" ), |
---|
99 | array( "column" => "email", "convert" => "a" ), |
---|
100 | array( "column" => "email_mobile", "convert" => "a" ), |
---|
101 | array( "column" => "htmlmail", "convert" => "n" ), |
---|
102 | array( "column" => "customer", "convert" => "" ), |
---|
103 | array( "column" => "buy_total_from", "convert" => "n" ), |
---|
104 | array( "column" => "buy_total_to", "convert" => "n" ), |
---|
105 | array( "column" => "buy_times_from", "convert" => "n" ), |
---|
106 | array( "column" => "buy_times_to", "convert" => "n" ), |
---|
107 | array( "column" => "birth_month", "convert" => "n" ), |
---|
108 | array( "column" => "b_start_year", "convert" => "n" ), |
---|
109 | array( "column" => "b_start_month", "convert" => "n" ), |
---|
110 | array( "column" => "b_start_day", "convert" => "n" ), |
---|
111 | array( "column" => "b_end_year", "convert" => "n" ), |
---|
112 | array( "column" => "b_end_month", "convert" => "n" ), |
---|
113 | array( "column" => "b_end_day", "convert" => "n" ), |
---|
114 | array( "column" => "start_year", "convert" => "n" ), |
---|
115 | array( "column" => "start_month", "convert" => "n" ), |
---|
116 | array( "column" => "start_day", "convert" => "n" ), |
---|
117 | array( "column" => "end_year", "convert" => "n" ), |
---|
118 | array( "column" => "end_month", "convert" => "n" ), |
---|
119 | array( "column" => "end_day", "convert" => "n" ), |
---|
120 | array( "column" => "buy_start_year", "convert" => "n" ), |
---|
121 | array( "column" => "buy_start_month", "convert" => "n" ), |
---|
122 | array( "column" => "buy_start_day", "convert" => "n" ), |
---|
123 | array( "column" => "buy_end_year", "convert" => "n" ), |
---|
124 | array( "column" => "buy_end_month", "convert" => "n" ), |
---|
125 | array( "column" => "buy_end_day", "convert" => "n" ), |
---|
126 | array( "column" => "buy_product_code", "convert" => "aKV" ), |
---|
127 | array( "column" => "buy_product_name", "convert" => "aKV" ), |
---|
128 | array( "column" => "category_id", "convert" => "" ), |
---|
129 | array( "column" => "buy_total_from", "convert" => "n" ), |
---|
130 | array( "column" => "buy_total_to", "convert" => "n" ), |
---|
131 | array( "column" => "campaign_id", "convert" => "" ), |
---|
132 | array( "column" => "mail_type", "convert" => "" ) |
---|
133 | ); |
---|
134 | |
---|
135 | if (!isset($_POST['htmlmail'])) $_POST['htmlmail'] = ""; |
---|
136 | if (!isset($_POST['mail_type'])) $_POST['mail_type'] = ""; |
---|
137 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
138 | if (!isset($_POST['buy_product_code'])) $_POST['buy_product_code'] = ""; |
---|
139 | if (!isset($_GET['mode'])) $_GET['mode'] = ""; |
---|
140 | |
---|
141 | $this->httpCacheControl('nocache'); |
---|
142 | } |
---|
143 | |
---|
144 | /** |
---|
145 | * Page のプロセス. |
---|
146 | * |
---|
147 | * @return void |
---|
148 | */ |
---|
149 | function process() { |
---|
150 | |
---|
151 | // ページ初期設定 |
---|
152 | $objView = new SC_AdminView(); |
---|
153 | $objDate = new SC_Date(); |
---|
154 | $objQuery = new SC_Query(); |
---|
155 | $objDb = new SC_Helper_DB_Ex(); |
---|
156 | $this->objDate = $objDate; |
---|
157 | $this->arrTemplate = $this->getTemplateList($objQuery); |
---|
158 | |
---|
159 | $objSess = new SC_Session(); |
---|
160 | |
---|
161 | // 認証可否の判定 |
---|
162 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
163 | |
---|
164 | /* |
---|
165 | query:配信履歴「確認」 |
---|
166 | */ |
---|
167 | if ($_GET["mode"] == "query" && SC_Utils_Ex::sfCheckNumLength($_GET["send_id"])) { |
---|
168 | // 送信履歴より、送信条件確認画面 |
---|
169 | $sql = "SELECT search_data FROM dtb_send_history WHERE send_id = ?"; |
---|
170 | $result = $objQuery->getOne($sql, array($_GET["send_id"])); |
---|
171 | $tpl_path = "mail/query.tpl"; |
---|
172 | |
---|
173 | $list_data = unserialize($result); |
---|
174 | |
---|
175 | // 都道府県を変換 |
---|
176 | $list_data['pref_disp'] = $this->arrPref[$list_data['pref']]; |
---|
177 | |
---|
178 | // 配信形式 |
---|
179 | $list_data['htmlmail_disp'] = $this->arrHtmlmail[$list_data['htmlmail']]; |
---|
180 | |
---|
181 | // 性別の変換 |
---|
182 | if (count($list_data['sex']) > 0) { |
---|
183 | foreach($list_data['sex'] as $key => $val){ |
---|
184 | $list_data['sex'][$key] = $this->arrSex[$val]; |
---|
185 | $sex_disp .= $list_data['sex'][$key] . " "; |
---|
186 | } |
---|
187 | $list_data['sex_disp'] = $sex_disp; |
---|
188 | } |
---|
189 | |
---|
190 | // 職業の変換 |
---|
191 | if (count($list_data['job']) > 0) { |
---|
192 | foreach($list_data['job'] as $key => $val){ |
---|
193 | $list_data['job'][$key] = $this->arrJob[$val]; |
---|
194 | $job_disp .= $list_data['job'][$key] . " "; |
---|
195 | } |
---|
196 | $list_data['job_disp'] = $job_disp; |
---|
197 | } |
---|
198 | |
---|
199 | // カテゴリ変換 |
---|
200 | $arrCatList = $objDb->sfGetCategoryList(); |
---|
201 | $list_data['category_name'] = $arrCatList[$list_data['category_id']]; |
---|
202 | |
---|
203 | $this->list_data = $list_data; |
---|
204 | $this->arrCampaignList = $this->lfGetCampaignList($objQuery); |
---|
205 | |
---|
206 | $objView->assignobj($this); |
---|
207 | $objView->display($tpl_path); |
---|
208 | exit; |
---|
209 | } |
---|
210 | |
---|
211 | if($_POST['mode'] == 'delete') { |
---|
212 | } |
---|
213 | |
---|
214 | switch($_POST['mode']) { |
---|
215 | /* |
---|
216 | search:「検索」ボタン |
---|
217 | back:検索結果画面「戻る」ボタン |
---|
218 | */ |
---|
219 | case 'delete': |
---|
220 | case 'search': |
---|
221 | case 'back': |
---|
222 | // 入力値コンバート |
---|
223 | $this->list_data = $this->lfConvertParam($_POST, $this->arrSearchColumn); |
---|
224 | |
---|
225 | // 入力エラーのチェック |
---|
226 | $this->arrErr = $this->lfErrorCheck($this->list_data); |
---|
227 | |
---|
228 | // 検索開始 |
---|
229 | if (empty($this->arrErr)) { |
---|
230 | $this->list_data['name'] = isset($this->list_data['name']) |
---|
231 | ? $this->list_data['name'] : ""; |
---|
232 | // hidden要素作成 |
---|
233 | $this->arrHidden = $this->lfGetHidden($this->list_data); |
---|
234 | |
---|
235 | // 検索データ取得 |
---|
236 | $objSelect = new SC_CustomerList($this->list_data, "magazine"); |
---|
237 | // 生成されたWHERE文を取得する |
---|
238 | list($where, $arrval) = $objSelect->getWhere(); |
---|
239 | |
---|
240 | // 「WHERE」部分を削除する。 |
---|
241 | $where = ereg_replace("^WHERE", "", $where); |
---|
242 | |
---|
243 | // 検索結果の取得 |
---|
244 | $from = "dtb_customer"; |
---|
245 | |
---|
246 | // 行数の取得 |
---|
247 | $linemax = $objQuery->count($from, $where, $arrval); |
---|
248 | $this->tpl_linemax = $linemax; // 何件が該当しました。表示用 |
---|
249 | |
---|
250 | // ページ送りの取得 |
---|
251 | $objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, SEARCH_PMAX, "fnResultPageNavi", NAVI_PMAX); |
---|
252 | $this->arrPagenavi = $objNavi->arrPagenavi; |
---|
253 | $startno = $objNavi->start_row; |
---|
254 | |
---|
255 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
256 | $objQuery->setLimitOffset(SEARCH_PMAX, $startno); |
---|
257 | // 表示順序 |
---|
258 | $objQuery->setOrder("customer_id DESC"); |
---|
259 | |
---|
260 | // 検索結果の取得 |
---|
261 | $col = $objSelect->getMailMagazineColumn($this->lfGetIsMobile($_POST['mail_type'])); |
---|
262 | $this->arrResults = $objQuery->select($col, $from, $where, $arrval); |
---|
263 | // 現在時刻の取得 |
---|
264 | $this->arrNowDate = $this->lfGetNowDate(); |
---|
265 | } |
---|
266 | break; |
---|
267 | /* |
---|
268 | input:検索結果画面「htmlmail内容設定」ボタン |
---|
269 | */ |
---|
270 | case 'input': |
---|
271 | // 入力値コンバート |
---|
272 | $this->list_data = $this->lfConvertParam($_POST, $this->arrSearchColumn); |
---|
273 | // 入力エラーのチェック |
---|
274 | $this->arrErr = $this->lfErrorCheck($this->list_data); |
---|
275 | // エラーなし |
---|
276 | if (empty($this->arrErr)) { |
---|
277 | // 現在時刻の取得 |
---|
278 | $this->arrNowDate = $this->lfGetNowDate(); |
---|
279 | $this->arrHidden = $this->lfGetHidden($this->list_data); // hidden要素作成 |
---|
280 | $this->tpl_mainpage = 'mail/input.tpl'; |
---|
281 | } |
---|
282 | break; |
---|
283 | /* |
---|
284 | template:テンプレート選択 |
---|
285 | */ |
---|
286 | case 'template': |
---|
287 | // 入力値コンバート |
---|
288 | $this->list_data = $this->lfConvertParam($_POST, $this->arrSearchColumn); |
---|
289 | |
---|
290 | // 時刻設定の取得 |
---|
291 | $this->arrNowDate['year'] = isset($_POST['send_year']) ? $_POST['send_year'] : ""; |
---|
292 | $this->arrNowDate['month'] = isset($_POST['send_month']) ? $_POST['send_month'] : ""; |
---|
293 | $this->arrNowDate['day'] = isset($_POST['send_day']) ? $_POST['send_day'] : ""; |
---|
294 | $this->arrNowDate['hour'] = isset($_POST['send_hour']) ? $_POST['send_hour'] : ""; |
---|
295 | $this->arrNowDate['minutes'] = isset($_POST['send_minutes']) ? $_POST['send_minutes'] : ""; |
---|
296 | |
---|
297 | // 入力エラーのチェック |
---|
298 | $this->arrErr = $this->lfErrorCheck($this->list_data); |
---|
299 | |
---|
300 | // 検索開始 |
---|
301 | if (empty($this->arrErr)) { |
---|
302 | $this->list_data['name'] = isset($this->list_data['name']) ? $this->list_data['name'] : ""; |
---|
303 | $this->arrHidden = $this->lfGetHidden($this->list_data); // hidden要素作成 |
---|
304 | |
---|
305 | $this->tpl_mainpage = 'mail/input.tpl'; |
---|
306 | $template_data = $this->getTemplateData($objQuery, $_POST['template_id']); |
---|
307 | if ( $template_data ){ |
---|
308 | foreach( $template_data as $key=>$val ){ |
---|
309 | $this->list_data[$key] = $val; |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | // HTMLテンプレートを使用する場合は、HTMLソースを生成してBODYへ挿入 |
---|
314 | if ( $this->list_data["mail_method"] == 3) { |
---|
315 | $objTemplate = new LC_HTMLtemplate; |
---|
316 | $objTemplate->list_data = lfGetHtmlTemplateData($_POST['template_id']); |
---|
317 | $objSiteInfo = new SC_SiteInfo(); |
---|
318 | $objTemplate->arrInfo = $objSiteInfo->data; |
---|
319 | // メール担当写真の表示 |
---|
320 | $objUpFile = new SC_UploadFile(IMAGE_TEMP_URL, IMAGE_SAVE_URL); |
---|
321 | $objUpFile->addFile("メール担当写真", 'charge_image', array('jpg'), IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); |
---|
322 | $objUpFile->setDBFileList($objTemplate->list_data); |
---|
323 | $objTemplate->arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL); |
---|
324 | $objMakeTemplate = new SC_AdminView(); |
---|
325 | $objMakeTemplate->assignobj($objTemplate); |
---|
326 | $this->list_data["body"] = $objMakeTemplate->fetch("mail/html_template.tpl"); |
---|
327 | } |
---|
328 | } |
---|
329 | break; |
---|
330 | /* |
---|
331 | regist_confirm:「入力内容を確認」 |
---|
332 | regist_back:「テンプレート設定画面へ戻る」 |
---|
333 | regist_complete:「登録」 |
---|
334 | */ |
---|
335 | case 'regist_confirm': |
---|
336 | case 'regist_back': |
---|
337 | case 'regist_complete': |
---|
338 | // 入力値コンバート |
---|
339 | $this->arrCheckColumn = array_merge( $this->arrSearchColumn, $this->arrRegistColumn ); |
---|
340 | $this->list_data = $this->lfConvertParam($_POST, $this->arrCheckColumn); |
---|
341 | |
---|
342 | // 現在時刻の取得 |
---|
343 | $this->arrNowDate = $this->lfGetNowDate(); |
---|
344 | |
---|
345 | // 入力エラーのチェック |
---|
346 | $this->arrErr = $this->lfErrorCheck($this->list_data, 1); |
---|
347 | $this->tpl_mainpage = 'mail/input.tpl'; |
---|
348 | $this->arrHidden = $this->lfGetHidden($this->list_data); // hidden要素作成 |
---|
349 | |
---|
350 | // 検索開始 |
---|
351 | if (empty($this->arrErr)) { |
---|
352 | $this->list_data['name'] = |
---|
353 | isset($this->list_data['name']) |
---|
354 | ? $this->list_data['name'] : ""; |
---|
355 | |
---|
356 | if ( $_POST['mode'] == 'regist_confirm'){ |
---|
357 | $this->tpl_mainpage = 'mail/input_confirm.tpl'; |
---|
358 | } else if( $_POST['mode'] == 'regist_complete' ){ |
---|
359 | $sendId = $this->lfRegistData($objQuery, $this->list_data); |
---|
360 | if (MELMAGA_SEND) { |
---|
361 | if (MELMAGA_BATCH_MODE) { |
---|
362 | $this->sendRedirect($this->getLocation(URL_DIR . 'admin/mail/history.php')); |
---|
363 | } else { |
---|
364 | $this->sendRedirect($this->getLocation(URL_DIR . 'admin/mail/sendmail.php', array('mode' => 'now', 'send_id' => $sendId))); |
---|
365 | } |
---|
366 | exit; |
---|
367 | } else { |
---|
368 | SC_Utils_Ex::sfErrorHeader(">> 本サイトではメルマガ配信は行えません。"); |
---|
369 | } |
---|
370 | } |
---|
371 | } |
---|
372 | break; |
---|
373 | default: |
---|
374 | $this->list_data['mail_type'] = 1; |
---|
375 | break; |
---|
376 | } |
---|
377 | |
---|
378 | // 配信時間の年を、「現在年~現在年+1」の範囲に設定 |
---|
379 | for ($year=date("Y"); $year<=date("Y") + 1;$year++){ |
---|
380 | $arrYear[$year] = $year; |
---|
381 | } |
---|
382 | $this->arrYear = $arrYear; |
---|
383 | |
---|
384 | $this->arrCustomerOrderId = $this->lfGetCustomerOrderId($_POST['buy_product_code']); |
---|
385 | |
---|
386 | $this->arrCatList = $objDb->sfGetCategoryList(); |
---|
387 | |
---|
388 | $this->arrCampaignList = $this->lfGetCampaignList($objQuery); |
---|
389 | |
---|
390 | // ページ表示 |
---|
391 | $objView->assignobj($this); |
---|
392 | $objView->display(MAIN_FRAME); |
---|
393 | |
---|
394 | } |
---|
395 | |
---|
396 | /** |
---|
397 | * デストラクタ. |
---|
398 | * |
---|
399 | * @return void |
---|
400 | */ |
---|
401 | function destroy() { |
---|
402 | parent::destroy(); |
---|
403 | } |
---|
404 | |
---|
405 | // 商品コードで検索された場合にヒットした注文番号を取得する。 |
---|
406 | function lfGetCustomerOrderId($keyword) { |
---|
407 | $arrCustomerOrderId = null; |
---|
408 | if($keyword != "") { |
---|
409 | $col = "dtb_order.customer_id, dtb_order.order_id"; |
---|
410 | $from = "dtb_order LEFT JOIN dtb_order_detail USING(order_id)"; |
---|
411 | $where = "product_code LIKE ? AND del_flg = 0"; |
---|
412 | $objQuery = new SC_Query(); |
---|
413 | $objQuery->setGroupBy("customer_id, order_id"); |
---|
414 | $arrRet = $objQuery->select($col, $from, $where, array($keyword)); |
---|
415 | $arrCustomerOrderId = SC_Utils_Ex::sfArrKeyValues($arrRet, "customer_id", "order_id"); |
---|
416 | } |
---|
417 | return $arrCustomerOrderId; |
---|
418 | } |
---|
419 | |
---|
420 | // 現在時刻の取得(配信時間デフォルト値) |
---|
421 | function lfGetNowDate(){ |
---|
422 | $nowdate = date("Y/n/j/G/i"); |
---|
423 | list($year, $month, $day, $hour, $minute) = split("[/]", $nowdate); |
---|
424 | $arrNowDate = array( 'year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'minutes' => $minute); |
---|
425 | foreach ($arrNowDate as $key => $val){ |
---|
426 | switch ($key){ |
---|
427 | case 'minutes': |
---|
428 | $val = ereg_replace('^[0]','', $val); |
---|
429 | if ($val < 30){ |
---|
430 | $list_date[$key] = '30'; |
---|
431 | }else{ |
---|
432 | $list_date[$key] = '00'; |
---|
433 | } |
---|
434 | break; |
---|
435 | case 'year': |
---|
436 | case 'month': |
---|
437 | case 'day': |
---|
438 | $list_date[$key] = $val; |
---|
439 | break; |
---|
440 | } |
---|
441 | } |
---|
442 | if ($arrNowDate['minutes'] < 30){ |
---|
443 | $list_date['hour'] = $hour; |
---|
444 | }else{ |
---|
445 | $list_date['hour'] = $hour + 1; |
---|
446 | } |
---|
447 | return $list_date; |
---|
448 | } |
---|
449 | |
---|
450 | /** |
---|
451 | * 配信内容と配信リストを書き込む |
---|
452 | * |
---|
453 | * @return string 登録した行の dtb_send_history.send_id の値 |
---|
454 | */ |
---|
455 | function lfRegistData(&$objQuery, $arrData){ |
---|
456 | |
---|
457 | $objSelect = new SC_CustomerList($this->lfConvertParam($arrData, $this->arrSearchColumn), "magazine" ); |
---|
458 | |
---|
459 | $search_data = $objQuery->getAll($objSelect->getListMailMagazine($this->lfGetIsMobile($_POST['mail_type'])), $objSelect->arrVal); |
---|
460 | $dataCnt = count($search_data); |
---|
461 | |
---|
462 | $dtb_send_history = array(); |
---|
463 | $dtb_send_history["mail_method"] = $arrData['mail_method']; |
---|
464 | $dtb_send_history["subject"] = $arrData['subject']; |
---|
465 | $dtb_send_history["body"] = $arrData['body']; |
---|
466 | if(MELMAGA_BATCH_MODE) { |
---|
467 | $dtb_send_history["start_date"] = $arrData['send_year'] ."/".$arrData['send_month']."/".$arrData['send_day']." ".$arrData['send_hour'].":".$arrData['send_minutes']; |
---|
468 | } else { |
---|
469 | $dtb_send_history["start_date"] = "now()"; |
---|
470 | } |
---|
471 | $dtb_send_history["creator_id"] = $_SESSION['member_id']; |
---|
472 | $dtb_send_history["send_count"] = $dataCnt; |
---|
473 | $arrData['body'] = ""; |
---|
474 | $dtb_send_history["search_data"] = serialize($arrData); |
---|
475 | $dtb_send_history["update_date"] = "now()"; |
---|
476 | $dtb_send_history["create_date"] = "now()"; |
---|
477 | $dtb_send_history['send_id'] = $objQuery->nextVal('dtb_send_history_send_id'); |
---|
478 | $objQuery->insert("dtb_send_history", $dtb_send_history ); |
---|
479 | |
---|
480 | $sendId = $objQuery->currval('dtb_send_history', 'send_id'); |
---|
481 | |
---|
482 | if ( is_array( $search_data ) ){ |
---|
483 | foreach( $search_data as $line ){ |
---|
484 | $dtb_send_customer = array(); |
---|
485 | $dtb_send_customer["customer_id"] = $line["customer_id"]; |
---|
486 | $dtb_send_customer["send_id"] = $sendId; |
---|
487 | $dtb_send_customer["email"] = $line["email"]; |
---|
488 | $dtb_send_customer["name"] = $line["name01"] . " " . $line["name02"]; |
---|
489 | $objQuery->insert("dtb_send_customer", $dtb_send_customer ); |
---|
490 | } |
---|
491 | } |
---|
492 | |
---|
493 | return $sendId; |
---|
494 | } |
---|
495 | |
---|
496 | // キャンペーン一覧 |
---|
497 | function lfGetCampaignList(&$objQuery) { |
---|
498 | $arrCampaign = null; |
---|
499 | $sql = "SELECT campaign_id, campaign_name FROM dtb_campaign ORDER BY update_date DESC"; |
---|
500 | $arrResult = $objQuery->getAll($sql); |
---|
501 | |
---|
502 | foreach($arrResult as $arrVal) { |
---|
503 | $arrCampaign[$arrVal['campaign_id']] = $arrVal['campaign_name']; |
---|
504 | } |
---|
505 | |
---|
506 | return $arrCampaign; |
---|
507 | } |
---|
508 | |
---|
509 | function lfGetIsMobile($mail_type) { |
---|
510 | // 検索結果の取得 |
---|
511 | $is_mobile = false; |
---|
512 | switch($mail_type) { |
---|
513 | case 1: |
---|
514 | $is_mobile = false; |
---|
515 | break; |
---|
516 | case 2: |
---|
517 | $is_mobile = true; |
---|
518 | break; |
---|
519 | default: |
---|
520 | $is_mobile = false; |
---|
521 | break; |
---|
522 | } |
---|
523 | |
---|
524 | return $is_mobile; |
---|
525 | } |
---|
526 | |
---|
527 | |
---|
528 | // HTMLテンプレートを使用する場合、データを取得する。 |
---|
529 | // FIXME |
---|
530 | function lfGetHtmlTemplateData($id) { |
---|
531 | |
---|
532 | $objQuery = new SC_Query(); |
---|
533 | $sql = "SELECT * FROM dtb_mailmaga_template WHERE template_id = ?"; |
---|
534 | $result = $objQuery->getAll($sql, array($id)); |
---|
535 | $list_data = $result[0]; |
---|
536 | |
---|
537 | // メイン商品の情報取得 |
---|
538 | $sql = "SELECT name, main_image, point_rate, deliv_fee, price01_min, price01_max, price02_min, price02_max FROM vw_products_allclass AS allcls WHERE product_id = ?"; |
---|
539 | $main = $objQuery->getAll($sql, array($list_data["sub_product_id" .$j])); |
---|
540 | $list_data["sub"][$k][$l] = $result[0]; |
---|
541 | $list_data["sub"][$k]["data_exists"] = "OK"; // 当該段にデータが1つ以上存在するフラグ |
---|
542 | } |
---|
543 | $l ++; |
---|
544 | } |
---|
545 | return $list_data; |
---|
546 | } |
---|
547 | |
---|
548 | // hidden要素出力用配列の作成 |
---|
549 | function lfGetHidden( $array ){ |
---|
550 | if ( is_array($array) ){ |
---|
551 | foreach( $array as $key => $val ){ |
---|
552 | if ( is_array( $val )){ |
---|
553 | for ( $i=0; $i<count($val); $i++){ |
---|
554 | $return[ $key.'['.$i.']'] = $val[$i]; |
---|
555 | } |
---|
556 | } else { |
---|
557 | $return[$key] = $val; |
---|
558 | } |
---|
559 | } |
---|
560 | } |
---|
561 | return $return; |
---|
562 | } |
---|
563 | |
---|
564 | // 取得文字列の変換 |
---|
565 | function lfConvertParam($array, $arrSearchColumn) { |
---|
566 | |
---|
567 | // 文字変換 |
---|
568 | foreach ($arrSearchColumn as $data) { |
---|
569 | $arrConvList[ $data["column"] ] = $data["convert"]; |
---|
570 | } |
---|
571 | |
---|
572 | $new_array = array(); |
---|
573 | foreach ($arrConvList as $key => $val) { |
---|
574 | if (isset($array[$key]) && strlen($array[$key]) > 0 ){ // データのあるものだけ返す |
---|
575 | $new_array[$key] = $array[$key]; |
---|
576 | if( strlen($val) > 0) { |
---|
577 | $new_array[$key] = mb_convert_kana($new_array[$key] ,$val); |
---|
578 | } |
---|
579 | } |
---|
580 | } |
---|
581 | return $new_array; |
---|
582 | |
---|
583 | } |
---|
584 | |
---|
585 | |
---|
586 | // 入力エラーチェック |
---|
587 | function lfErrorCheck($array, $flag = '') { |
---|
588 | |
---|
589 | // flag は登録時用 |
---|
590 | |
---|
591 | $objErr = new SC_CheckError($array); |
---|
592 | |
---|
593 | $objErr->doFunc(array("顧客コード", "customer_id", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
---|
594 | $objErr->doFunc(array("都道府県", "pref", 2), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
---|
595 | $objErr->doFunc(array("顧客名", "name", STEXT_LEN), array("MAX_LENGTH_CHECK")); |
---|
596 | $objErr->doFunc(array("顧客名(カナ)", "kana", STEXT_LEN), array("KANA_CHECK", "MAX_LENGTH_CHECK")); |
---|
597 | |
---|
598 | $objErr->doFunc(array('メールアドレス', "email", STEXT_LEN) ,array("EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK")); |
---|
599 | $objErr->doFunc(array("電話番号", "tel", TEL_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
---|
600 | |
---|
601 | $objErr->doFunc(array("購入回数(開始)", "buy_times_from", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
---|
602 | $objErr->doFunc(array("購入回数(終了)", "buy_times_to", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
---|
603 | if (!isset($array['buy_total_from'])) $array['buy_total_from'] = ""; |
---|
604 | if (!isset($array['buy_total_to'])) $array['buy_total_to'] = ""; |
---|
605 | if (!isset($array['buy_times_from'])) $array['buy_times_from'] = ""; |
---|
606 | if (!isset($array['buy_times_from'])) $array['buy_times_from'] = ""; |
---|
607 | if ((is_numeric($array["buy_total_from"]) && is_numeric($array["buy_total_to"]) ) && ($array["buy_times_from"] > $array["buy_times_to"]) ) $objErr->arrErr["buy_times_from"] .= "※ 購入回数の指定範囲が不正です。"; |
---|
608 | |
---|
609 | $objErr->doFunc(array("誕生月", "birth_month", 2), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
---|
610 | |
---|
611 | $objErr->doFunc(array("誕生日(開始日)", "b_start_year", "b_start_month", "b_start_day",), array("CHECK_DATE")); |
---|
612 | $objErr->doFunc(array("誕生日(終了日)", "b_end_year", "b_end_month", "b_end_day"), array("CHECK_DATE")); |
---|
613 | $objErr->doFunc(array("誕生日(開始日)","誕生日(終了日)", "b_start_year", "b_start_month", "b_start_day", "b_end_year", "b_end_month", "b_end_day"), array("CHECK_SET_TERM")); |
---|
614 | |
---|
615 | $objErr->doFunc(array("登録・更新日(開始日)", "start_year", "start_month", "start_day",), array("CHECK_DATE")); |
---|
616 | $objErr->doFunc(array("登録・更新日(終了日)", "end_year", "end_month", "end_day"), array("CHECK_DATE")); |
---|
617 | $objErr->doFunc(array("登録・更新日(開始日)","登録・更新日(終了日)", "start_year", "start_month", "start_day", "end_year", "end_month", "end_day"), array("CHECK_SET_TERM")); |
---|
618 | |
---|
619 | $objErr->doFunc(array("最終購入日(開始日)", "buy_start_year", "buy_start_month", "buy_start_day",), array("CHECK_DATE")); |
---|
620 | $objErr->doFunc(array("最終購入(終了日)", "buy_end_year", "buy_end_month", "buy_end_day"), array("CHECK_DATE")); |
---|
621 | $objErr->doFunc(array("最終購入日(開始日)","登録・更新日(終了日)", "buy_start_year", "buy_start_month", "buy_start_day", "buy_end_year", "buy_end_month", "buy_end_day"), array("CHECK_SET_TERM")); |
---|
622 | |
---|
623 | $objErr->doFunc(array("購入商品コード", "buy_product_code", STEXT_LEN), array("MAX_LENGTH_CHECK")); |
---|
624 | |
---|
625 | $objErr->doFunc(array("購入商品名", "buy_product_name", STEXT_LEN), array("MAX_LENGTH_CHECK")); |
---|
626 | |
---|
627 | $objErr->doFunc(array("購入金額(開始)", "buy_total_from", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
---|
628 | $objErr->doFunc(array("購入金額(終了)", "buy_total_to", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK")); |
---|
629 | |
---|
630 | $objErr->doFunc(array("キャンペーン", "campaign_id", INT_LEN), array("NUM_CHECK")); |
---|
631 | |
---|
632 | // 購入金額(from) > 購入金額(to) の場合はエラーとする |
---|
633 | if ( (is_numeric($array["buy_total_from"]) && is_numeric($array["buy_total_to"]) ) && |
---|
634 | ($array["buy_total_from"] > $array["buy_total_to"]) ) { |
---|
635 | $objErr->arrErr["buy_total_from"] .= "※ 購入金額の指定範囲が不正です。"; |
---|
636 | } |
---|
637 | |
---|
638 | if ( $flag ){ |
---|
639 | $objErr->doFunc(array("テンプレート", "template_id"), array("EXIST_CHECK", "NUM_CHECK")); |
---|
640 | $objErr->doFunc(array("メール送信法法", "mail_method"), array("EXIST_CHECK", "NUM_CHECK")); |
---|
641 | |
---|
642 | if(MELMAGA_BATCH_MODE) { |
---|
643 | $objErr->doFunc(array("配信日(年)","send_year"), array("EXIST_CHECK", "NUM_CHECK")); |
---|
644 | $objErr->doFunc(array("配信日(月)","send_month"), array("EXIST_CHECK", "NUM_CHECK")); |
---|
645 | $objErr->doFunc(array("配信日(日)","send_day"), array("EXIST_CHECK", "NUM_CHECK")); |
---|
646 | $objErr->doFunc(array("配信日(時)","send_hour"), array("EXIST_CHECK", "NUM_CHECK")); |
---|
647 | $objErr->doFunc(array("配信日(分)","send_minutes"), array("EXIST_CHECK", "NUM_CHECK")); |
---|
648 | $objErr->doFunc(array("配信日", "send_year", "send_month", "send_day"), array("CHECK_DATE")); |
---|
649 | $objErr->doFunc(array("配信日", "send_year", "send_month", "send_day","send_hour", "send_minutes"), array("ALL_EXIST_CHECK")); |
---|
650 | } |
---|
651 | $objErr->doFunc(array("Subject", "subject", STEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK")); |
---|
652 | $objErr->doFunc(array("本文", 'body', LLTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK")); // HTMLテンプレートを使用しない場合 |
---|
653 | } |
---|
654 | |
---|
655 | return $objErr->arrErr; |
---|
656 | } |
---|
657 | |
---|
658 | /* テンプレートIDとsubjectの配列を返す */ |
---|
659 | function getTemplateList(&$objQuery){ |
---|
660 | $return = ""; |
---|
661 | $sql = "SELECT template_id, subject, mail_method FROM dtb_mailmaga_template WHERE del_flg = 0 "; |
---|
662 | if ($_POST["htmlmail"] == 2 || $_POST['mail_type'] == 2) { |
---|
663 | $sql .= " AND mail_method = 2 "; // TEXT希望者へのTESTメールテンプレートリスト |
---|
664 | } |
---|
665 | $sql .= " ORDER BY template_id DESC"; |
---|
666 | $result = $objQuery->getAll($sql); |
---|
667 | |
---|
668 | if ( is_array($result) ){ |
---|
669 | foreach( $result as $line ){ |
---|
670 | $return[$line['template_id']] = "【" . $this->arrMagazineTypeAll[$line['mail_method']] . "】" . $line['subject']; |
---|
671 | } |
---|
672 | } |
---|
673 | |
---|
674 | return $return; |
---|
675 | } |
---|
676 | |
---|
677 | /* テンプレートIDからテンプレートデータを取得 */ |
---|
678 | function getTemplateData(&$objQuery, $id){ |
---|
679 | |
---|
680 | if ( SC_Utils_Ex::sfCheckNumLength($id) ){ |
---|
681 | $sql = "SELECT * FROM dtb_mailmaga_template WHERE template_id = ? ORDER BY template_id DESC"; |
---|
682 | $result = $objQuery->getAll( $sql, array($id) ); |
---|
683 | if ( is_array($result) ) { |
---|
684 | $return = $result[0]; |
---|
685 | } |
---|
686 | } |
---|
687 | return $return; |
---|
688 | } |
---|
689 | |
---|
690 | } |
---|
691 | class LC_HTMLtemplate { |
---|
692 | var $list_data; |
---|
693 | } |
---|
694 | |
---|
695 | ?> |
---|