source: branches/dev/html/admin/mail/index.php @ 13298

Revision 13298, 13.0 KB checked in by nakanishi, 15 years ago (diff)
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once("../require.php");
8require_once("./inc_mailmagazine.php");
9
10class LC_Page {
11    var $arrSession;
12    var $arrHtmlmail;
13    var $arrNowDate;
14    function LC_Page() {
15        $this->tpl_mainpage = 'mail/index.tpl';
16        $this->tpl_mainno = 'mail';
17        $this->tpl_subnavi = 'mail/subnavi.tpl';
18        $this->tpl_subno = "index";
19        $this->tpl_pager = DATA_PATH . 'Smarty/templates/admin/pager.tpl';
20        $this->tpl_subtitle = 'ÇÛ¿®ÆâÍÆÀßÄê';
21       
22        global $arrPref;
23        $this->arrPref = $arrPref;
24        global $arrJob;
25        $arrJob["ÉÔÌÀ"] = "ÉÔÌÀ";
26        $this->arrJob = $arrJob;
27        global $arrSex;     
28        $this->arrSex = $arrSex;
29        global $arrMailType;
30        $this->arrMailType = $arrMailType;
31        global $arrDomain;
32        $this->arrDomain = $arrDomain;
33        global $arrPageRows;
34        $this->arrPageRows = $arrPageRows;
35        // ¥Ú¡¼¥¸¥Ê¥ÓÍÑ
36        $this->tpl_pageno = $_POST['search_pageno'];
37        global $arrMAILMAGATYPE;
38        $this->arrMAILMAGATYPE = $arrMAILMAGATYPE;
39        $this->arrHtmlmail[''] = "¤¹¤Ù¤Æ";
40        $this->arrHtmlmail[1] = $arrMAILMAGATYPE[1];
41        $this->arrHtmlmail[2] = $arrMAILMAGATYPE[2];
42        global $arrCustomerType;
43        $this->arrCustomerType = $arrCustomerType;
44    }
45}
46
47class LC_HTMLtemplate {
48    var $list_data;
49}
50
51//---- ¥Ú¡¼¥¸½é´üÀßÄê
52$conn = new SC_DBConn();
53$objPage = new LC_Page();
54$objView = new SC_AdminView();
55$objDate = new SC_Date();
56$objQuery = new SC_Query();
57$objPage->objDate = $objDate;
58$objPage->arrTemplate = getTemplateList($conn);
59
60$objSess = new SC_Session();
61
62// ǧ¾Ú²ÄÈݤÎȽÄê
63sfIsSuccess($objSess);
64
65/*
66    query:ÇÛ¿®ÍúÎò¡Ö³Îǧ¡×
67*/
68if ($_GET["mode"] == "query" && sfCheckNumLength($_GET["send_id"])) {
69    // Á÷¿®ÍúÎò¤è¤ê¡¢Á÷¿®¾ò·ï³Îǧ²èÌÌ
70    $sql = "SELECT search_data FROM dtb_send_history WHERE send_id = ?";
71    $result = $conn->getOne($sql, array($_GET["send_id"]));
72    $tpl_path = "mail/query.tpl";
73       
74    $list_data = unserialize($result);
75   
76    // ÅÔÆ»Éܸ©¤òÊÑ´¹
77    $list_data['pref_disp'] = $objPage->arrPref[$list_data['pref']];
78   
79    // ÇÛ¿®·Á¼°
80    $list_data['htmlmail_disp'] = $objPage->arrHtmlmail[$list_data['htmlmail']];
81   
82    // À­Ê̤ÎÊÑ´¹
83    if (count($list_data['sex']) > 0) {
84        foreach($list_data['sex'] as $key => $val){
85            $list_data['sex'][$key] = $objPage->arrSex[$val];
86            $sex_disp .= $list_data['sex'][$key] . " ";
87        }
88        $list_data['sex_disp'] = $sex_disp;
89    }
90   
91    // ¿¦¶È¤ÎÊÑ´¹
92    if (count($list_data['job']) > 0) {
93        foreach($list_data['job'] as $key => $val){
94            $list_data['job'][$key] = $objPage->arrJob[$val];
95            $job_disp .= $list_data['job'][$key] . " ";
96        }
97        $list_data['job_disp'] = $job_disp;
98    }
99       
100    // ¥«¥Æ¥´¥êÊÑ´¹
101    $arrCatList = sfGetCategoryList();
102    $list_data['category_name'] = $arrCatList[$list_data['category_id']];
103   
104    $objPage->list_data = $list_data;
105
106    $objView->assignobj($objPage);
107    $objView->display($tpl_path);
108    exit;
109}
110
111if($_POST['mode'] == 'delete') {
112}
113
114switch($_POST['mode']) {
115/*
116    search:¡Ö¸¡º÷¡×¥Ü¥¿¥ó
117    back:¸¡º÷·ë²Ì²èÌÌ¡ÖÌá¤ë¡×¥Ü¥¿¥ó
118*/
119case 'delete':
120case 'search':
121case 'back':
122    //-- ÆþÎÏÃÍ¥³¥ó¥Ð¡¼¥È
123    $objPage->list_data = lfConvertParam($_POST, $arrSearchColumn);
124       
125    //-- ÆþÎÏ¥¨¥é¡¼¤Î¥Á¥§¥Ã¥¯
126    $objPage->arrErr = lfErrorCheck($objPage->list_data);
127
128    //-- ¸¡º÷³«»Ï
129    if (!is_array($objPage->arrErr)) {
130        $objPage->list_data['name'] = sfManualEscape($objPage->list_data['name']);
131        // hiddenÍ×ÁǺîÀ®
132        $objPage->arrHidden = lfGetHidden($objPage->list_data);
133
134        //-- ¸¡º÷¥Ç¡¼¥¿¼èÆÀ
135        $objSelect = new SC_CustomerList($objPage->list_data, "magazine");
136        // À¸À®¤µ¤ì¤¿WHEREʸ¤ò¼èÆÀ¤¹¤ë     
137        list($where, $arrval) = $objSelect->getWhere();
138   
139        // ¡ÖWHERE¡×Éôʬ¤òºï½ü¤¹¤ë¡£
140        $where = ereg_replace("^WHERE", "", $where);
141
142        // ¸¡º÷·ë²Ì¤Î¼èÆÀ
143        $objQuery = new SC_Query();
144        $from = "dtb_customer";
145
146        // ¹Ô¿ô¤Î¼èÆÀ
147        $linemax = $objQuery->count($from, $where, $arrval);
148        $objPage->tpl_linemax = $linemax;               // ²¿·ï¤¬³ºÅö¤·¤Þ¤·¤¿¡£É½¼¨ÍÑ
149       
150        // ¥Ú¡¼¥¸Á÷¤ê¤Î¼èÆÀ
151        $objNavi = new SC_PageNavi($_POST['search_pageno'], $linemax, SEARCH_PMAX, "fnResultPageNavi", NAVI_PMAX);
152        $objPage->arrPagenavi = $objNavi->arrPagenavi; 
153        $startno = $objNavi->start_row;
154
155        // ¼èÆÀÈϰϤλØÄê(³«»Ï¹ÔÈֹ桢¹Ô¿ô¤Î¥»¥Ã¥È)
156        $objQuery->setlimitoffset(SEARCH_PMAX, $startno);
157        // ɽ¼¨½ç½ø
158        $objQuery->setorder("customer_id DESC");
159       
160        // ¸¡º÷·ë²Ì¤Î¼èÆÀ   
161        $col = $objSelect->getMailMagazineColumn(lfGetIsMobile($_POST['mail_type']));
162        $objPage->arrResults = $objQuery->select($col, $from, $where, $arrval);
163        //¸½ºß»þ¹ï¤Î¼èÆÀ
164        $objPage->arrNowDate = lfGetNowDate();
165    }
166    break;
167/*
168    input:¸¡º÷·ë²Ì²èÌÌ¡ÖhtmlmailÆâÍÆÀßÄê¡×¥Ü¥¿¥ó
169*/
170case 'input':
171    //-- ÆþÎÏÃÍ¥³¥ó¥Ð¡¼¥È
172    $objPage->list_data = lfConvertParam($_POST, $arrSearchColumn);
173    //-- ÆþÎÏ¥¨¥é¡¼¤Î¥Á¥§¥Ã¥¯
174    $objPage->arrErr = lfErrorCheck($objPage->list_data);
175    //-- ¥¨¥é¡¼¤Ê¤·
176    if (!is_array($objPage->arrErr)) {
177        //-- ¸½ºß»þ¹ï¤Î¼èÆÀ
178        $objPage->arrNowDate = lfGetNowDate();
179        $objPage->arrHidden = lfGetHidden($objPage->list_data); // hiddenÍ×ÁǺîÀ®
180        $objPage->tpl_mainpage = 'mail/input.tpl';
181    }
182    break;
183/*
184    template:¥Æ¥ó¥×¥ì¡¼¥ÈÁªÂò
185*/
186case 'template':
187    //-- ÆþÎÏÃÍ¥³¥ó¥Ð¡¼¥È
188    $objPage->list_data = lfConvertParam($_POST, $arrSearchColumn);
189   
190    //-- »þ¹ïÀßÄê¤Î¼èÆÀ
191    $objPage->arrNowDate['year'] = $_POST['send_year'];
192    $objPage->arrNowDate['month'] = $_POST['send_month'];
193    $objPage->arrNowDate['day'] = $_POST['send_day'];
194    $objPage->arrNowDate['hour'] = $_POST['send_hour'];
195    $objPage->arrNowDate['minutes'] = $_POST['send_minutes'];
196   
197    //-- ÆþÎÏ¥¨¥é¡¼¤Î¥Á¥§¥Ã¥¯
198    $objPage->arrErr = lfErrorCheck($objPage->list_data);
199
200    //-- ¸¡º÷³«»Ï
201    if ( ! is_array($objPage->arrErr)) {
202        $objPage->list_data['name'] = sfManualEscape($objPage->list_data['name']);
203        $objPage->arrHidden = lfGetHidden($objPage->list_data); // hiddenÍ×ÁǺîÀ®
204   
205        $objPage->tpl_mainpage = 'mail/input.tpl';
206        $template_data = getTemplateData($conn, $_POST['template_id']);
207        if ( $template_data ){
208            foreach( $template_data as $key=>$val ){
209                $objPage->list_data[$key] = $val;
210            }
211        }
212
213        //-- HTML¥Æ¥ó¥×¥ì¡¼¥È¤ò»ÈÍѤ¹¤ë¾ì¹ç¤Ï¡¢HTML¥½¡¼¥¹¤òÀ¸À®¤·¤ÆBODY¤ØÁÞÆþ
214        if ( $objPage->list_data["mail_method"] == 3) {
215            $objTemplate = new LC_HTMLtemplate;
216            $objTemplate->list_data = lfGetHtmlTemplateData($_POST['template_id']);
217            $objSiteInfo = new SC_SiteInfo();
218            $objTemplate->arrInfo = $objSiteInfo->data;
219            //¥á¡¼¥ëôÅö¼Ì¿¿¤Îɽ¼¨
220            $objUpFile = new SC_UploadFile(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
221            $objUpFile->addFile("¥á¡¼¥ëôÅö¼Ì¿¿", 'charge_image', array('jpg'), IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
222            $objUpFile->setDBFileList($objTemplate->list_data);
223            $objTemplate->arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
224            $objMakeTemplate = new SC_AdminView();
225            $objMakeTemplate->assignobj($objTemplate);     
226            $objPage->list_data["body"] = $objMakeTemplate->fetch("mail/html_template.tpl");
227        }
228    }
229    break;
230/*
231    regist_confirm:¡ÖÆþÎÏÆâÍƤò³Îǧ¡×
232    regist_back:¡Ö¥Æ¥ó¥×¥ì¡¼¥ÈÀßÄê²èÌ̤ØÌá¤ë¡×
233    regist_complete:¡ÖÅÐÏ¿¡×
234*/ 
235case 'regist_confirm':
236case 'regist_back':
237case 'regist_complete':
238    //-- ÆþÎÏÃÍ¥³¥ó¥Ð¡¼¥È
239    $arrCheckColumn = array_merge( $arrSearchColumn, $arrRegistColumn );
240    $objPage->list_data = lfConvertParam($_POST, $arrCheckColumn);
241   
242    //¸½ºß»þ¹ï¤Î¼èÆÀ
243    $objPage->arrNowDate = lfGetNowDate();
244
245    //-- ÆþÎÏ¥¨¥é¡¼¤Î¥Á¥§¥Ã¥¯
246    $objPage->arrErr = lfErrorCheck($objPage->list_data, 1);
247    $objPage->tpl_mainpage = 'mail/input.tpl';
248    $objPage->arrHidden = lfGetHidden($objPage->list_data); // hiddenÍ×ÁǺîÀ®
249   
250    //-- ¸¡º÷³«»Ï
251    if ( ! is_array($objPage->arrErr)) {
252            $objPage->list_data['name'] = sfManualEscape($objPage->list_data['name']);
253        if ( $_POST['mode'] == 'regist_confirm'){
254            $objPage->tpl_mainpage = 'mail/input_confirm.tpl';
255        } else if( $_POST['mode'] == 'regist_complete' ){
256            lfRegistData($objPage->list_data);
257            if(MELMAGA_SEND == true) {
258                //ͽÌóÇÛ¿®¥â¡¼¥É¤Îʬ´ô
259                if(MELMAGA_BATCH_MODE) {
260                    header("Location: " . URL_DIR . "admin/mail/history.php");
261                } else {   
262                    header("Location: " . URL_DIR . "admin/mail/sendmail.php?mode=now");
263                }
264                exit;
265            } else {
266                sfErrorHeader(">> ËÜ¥µ¥¤¥È¤Ç¤Ï¥á¥ë¥Þ¥¬ÇÛ¿®¤Ï¹Ô¤¨¤Þ¤»¤ó¡£");
267            }
268        }
269    }
270    break;
271default:
272    $objPage->list_data['mail_type'] = 1;
273    break;
274}
275
276// ÇÛ¿®»þ´Ö¤Îǯ¤ò¡¢¡Ö¸½ºßǯ¢·¸½ºßǯ¡Ü£±¡×¤ÎÈϰϤËÀßÄê
277for ($year=date("Y"); $year<=date("Y") + 1;$year++){
278    $arrYear[$year] = $year;
279}
280$objPage->arrYear = $arrYear;
281
282$objPage->arrCustomerOrderId = lfGetCustomerOrderId($_POST['buy_product_code']);
283
284$objPage->arrCatList = sfGetCategoryList();
285
286$objPage->arrCampaignList = lfGetCampaignList();
287
288//----¡¡¥Ú¡¼¥¸É½¼¨
289$objView->assignobj($objPage);
290$objView->display(MAIN_FRAME);
291
292//-------------------------------------------------------------------------------------------------------------------------------
293
294// ¾¦ÉÊ¥³¡¼¥É¤Ç¸¡º÷¤µ¤ì¤¿¾ì¹ç¤Ë¥Ò¥Ã¥È¤·¤¿¼õÃíÈÖ¹æ¤ò¼èÆÀ¤¹¤ë¡£
295function lfGetCustomerOrderId($keyword) {
296    if($keyword != "") {
297        $col = "dtb_order.customer_id, dtb_order.order_id";
298        $from = "dtb_order LEFT JOIN dtb_order_detail USING(order_id)";
299        $where = "product_code LIKE ? AND del_flg = 0";
300        $val = sfManualEscape($keyword);
301        $arrVal[] = "%$val%";
302        $objQuery = new SC_Query();
303        $objQuery->setgroupby("customer_id, order_id");
304        $arrRet = $objQuery->select($col, $from, $where, $arrVal);
305        $arrCustomerOrderId = sfArrKeyValues($arrRet, "customer_id", "order_id");
306    }
307    return $arrCustomerOrderId;
308}
309
310function lfMakeCsvData( $send_id ){
311       
312    global $conn;
313
314    $arrTitle  = array(  'name01','email');
315               
316    $sql = "SELECT name01,email FROM dtb_send_customer WHERE send_id = ? ORDER BY email";
317    $result = $conn->getAll($sql, array($send_id) );
318   
319    if ( $result ){
320        $return = lfGetCSVData( $result, $arrTitle);
321    }
322    return $return;
323}
324
325//---- CSV½ÐÎÏÍѥǡ¼¥¿¼èÆÀ
326function lfGetCSVData( $array, $arrayIndex){   
327   
328    for ($i=0; $i<count($array); $i++){
329       
330        for ($j=0; $j<count($array[$i]); $j++ ){
331            if ( $j > 0 ) $return .= ",";
332            $return .= "\"";           
333            if ( $arrayIndex ){
334                $return .= mb_ereg_replace("<","¡ã",mb_ereg_replace( "\"","\"\"",$array[$i][$arrayIndex[$j]] )) ."\""; 
335            } else {
336                $return .= mb_ereg_replace("<","¡ã",mb_ereg_replace( "\"","\"\"",$array[$i][$j] )) ."\"";
337            }
338        }
339        $return .= "\n";           
340    }
341    return $return;
342}
343
344//¸½ºß»þ¹ï¤Î¼èÆÀ¡ÊÇÛ¿®»þ´Ö¥Ç¥Õ¥©¥ë¥ÈÃÍ¡Ë
345function lfGetNowDate(){
346    $nowdate = date("Y/n/j/G/i");
347    list($year, $month, $day, $hour, $minute) = split("[/]", $nowdate);
348    $arrNowDate = array( 'year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'minutes' => $minute);
349    foreach ($arrNowDate as $key => $val){
350        switch ($key){
351            case 'minutes':
352            $val = ereg_replace('^[0]','', $val);
353            if ($val < 30){
354            $list_date[$key] = '30';
355            }else{
356            $list_date[$key] = '00';
357            }
358            break;
359            case 'year':
360            case 'month':
361            case 'day':
362            $list_date[$key] = $val;
363            break;
364        }
365    }
366        if ($arrNowDate['minutes'] < 30){
367            $list_date['hour'] = $hour;
368        }else{
369            $list_date['hour'] = $hour + 1;
370        }
371    return $list_date;
372}
373
374// ÇÛ¿®ÆâÍƤÈÇÛ¿®¥ê¥¹¥È¤ò½ñ¤­¹þ¤à
375function lfRegistData($arrData){
376   
377    global $conn;
378    global $arrSearchColumn;
379   
380    $objQuery = new SC_Query();
381    $objSelect = new SC_CustomerList( lfConvertParam($arrData, $arrSearchColumn), "magazine" );
382   
383    $search_data = $conn->getAll($objSelect->getListMailMagazine(lfGetIsMobile($_POST['mail_type'])), $objSelect->arrVal);
384    $dataCnt = count($search_data);
385    $dtb_send_history = array();
386   
387    $dtb_send_history["send_id"] = $objQuery->nextval('dtb_send_history', 'send_id');
388   
389    $dtb_send_history["mail_method"] = $arrData['mail_method'];
390    $dtb_send_history["subject"] = $arrData['subject'];
391    $dtb_send_history["body"] = $arrData['body'];
392    if(MELMAGA_BATCH_MODE) {
393        //¥¤¥ó¥¹¥È¡¼¥ëÀè¤Î¥µ¡¼¥Ð¡¼¤ÇCRON¤¬Í­¸ú¤Ç¤¢¤ë¤Ê¤é»ØÄꤵ¤ì¤¿»þ´Ö¤Ë¥á¡¼¥ë¤òÁ÷¤ë
394        $dtb_send_history["start_date"] = $arrData['send_year'] ."/".$arrData['send_month']."/".$arrData['send_day']." ".$arrData['send_hour'].":".$arrData['send_minutes'];
395    } else {
396        //CRON¤¬Ìµ¸ú¤Ç¤¢¤ì¤Ð¥ê¥¢¥ë¥¿¥¤¥à¤ËÁ÷¿®¤¹¤ë
397        $dtb_send_history["start_date"] = "now()";
398    }
399    $dtb_send_history["creator_id"] = $_SESSION['member_id'];
400    $dtb_send_history["send_count"] = $dataCnt;
401    $arrData['body'] = "";
402    $dtb_send_history["search_data"] = serialize($arrData);
403    $dtb_send_history["update_date"] = "now()";
404    $dtb_send_history["create_date"] = "now()";
405    //¥Ï¥Ã¥·¥ådtb_send_history¤ò¥Ç¡¼¥¿¥Ù¡¼¥¹dtb_send_history¤ËÁÞÆþ
406    $objQuery->insert("dtb_send_history", $dtb_send_history );
407   
408    if ( is_array( $search_data ) ){
409        foreach( $search_data as $line ){
410            $dtb_send_customer = array();
411            $dtb_send_customer["customer_id"] = $line["customer_id"];
412            $dtb_send_customer["send_id"] = $dtb_send_history["send_id"];
413            $dtb_send_customer["email"] = $line["email"];
414           
415            $dtb_send_customer["name"] = $line["name01"] . " " . $line["name02"];
416               
417            $conn->autoExecute("dtb_send_customer", $dtb_send_customer );                   
418        }   
419    }   
420}
421
422// ¥­¥ã¥ó¥Ú¡¼¥ó°ìÍ÷
423function lfGetCampaignList() {
424   
425    global $objQuery;
426   
427    $sql = "SELECT campaign_id, campaign_name FROM dtb_campaign ORDER BY update_date DESC";
428    $arrResult = $objQuery->getall($sql);
429
430    foreach($arrResult as $arrVal) {
431        $arrCampaign[$arrVal['campaign_id']] = $arrVal['campaign_name'];
432    }
433    return $arrCampaign;
434}
435
436function lfGetIsMobile($mail_type) {
437    // ¸¡º÷·ë²Ì¤Î¼èÆÀ           
438    $is_mobile = false;
439    switch($mail_type) {
440        case 1:
441            $is_mobile = false;
442            break;
443        case 2:
444            $is_mobile = true;     
445            break;
446        default:
447            $is_mobile = false;
448            break;
449    }
450   
451    return $is_mobile;
452}
453?>
Note: See TracBrowser for help on using the repository browser.