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