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

Revision 13348, 13.3 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            //¥á¥ë¥Þ¥¬µ¡Ç½¤¬¥ª¥ó¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤«¤É¤¦¤«¤ÎȽÄê
258            if(MELMAGA_SEND == true) {
259                //ͽÌóÇÛ¿®¥â¡¼¥É¤Îʬ´ô
260                if(MELMAGA_BATCH_MODE) {
261                    header("Location: " . URL_DIR . "admin/mail/history.php");
262                } else {   
263                    header("Location: " . URL_DIR . "admin/mail/sendmail.php?mode=now");
264                }
265                exit;
266            } else {
267                sfErrorHeader(">> ËÜ¥µ¥¤¥È¤Ç¤Ï¥á¥ë¥Þ¥¬ÇÛ¿®¤Ï¹Ô¤¨¤Þ¤»¤ó¡£");
268            }
269        }
270    }
271    break;
272default:
273    $objPage->list_data['mail_type'] = 1;
274    break;
275}
276
277// ÇÛ¿®»þ´Ö¤Îǯ¤ò¡¢¡Ö¸½ºßǯ¢·¸½ºßǯ¡Ü£±¡×¤ÎÈϰϤËÀßÄê
278for ($year=date("Y"); $year<=date("Y") + 1;$year++){
279    $arrYear[$year] = $year;
280}
281$objPage->arrYear = $arrYear;
282
283$objPage->arrCustomerOrderId = lfGetCustomerOrderId($_POST['buy_product_code']);
284
285$objPage->arrCatList = sfGetCategoryList();
286
287$objPage->arrCampaignList = lfGetCampaignList();
288
289//----¡¡¥Ú¡¼¥¸É½¼¨
290$objView->assignobj($objPage);
291$objView->display(MAIN_FRAME);
292
293//-------------------------------------------------------------------------------------------------------------------------------
294
295// ¾¦ÉÊ¥³¡¼¥É¤Ç¸¡º÷¤µ¤ì¤¿¾ì¹ç¤Ë¥Ò¥Ã¥È¤·¤¿¼õÃíÈÖ¹æ¤ò¼èÆÀ¤¹¤ë¡£
296function lfGetCustomerOrderId($keyword) {
297    if($keyword != "") {
298        $col = "dtb_order.customer_id, dtb_order.order_id";
299        $from = "dtb_order LEFT JOIN dtb_order_detail USING(order_id)";
300        $where = "product_code LIKE ? AND del_flg = 0";
301        $val = sfManualEscape($keyword);
302        $arrVal[] = "%$val%";
303        $objQuery = new SC_Query();
304        $objQuery->setgroupby("customer_id, order_id");
305        $arrRet = $objQuery->select($col, $from, $where, $arrVal);
306        $arrCustomerOrderId = sfArrKeyValues($arrRet, "customer_id", "order_id");
307    }
308    return $arrCustomerOrderId;
309}
310
311function lfMakeCsvData( $send_id ){
312       
313    global $conn;
314
315    $arrTitle  = array(  'name01','email');
316               
317    $sql = "SELECT name01,email FROM dtb_send_customer WHERE send_id = ? ORDER BY email";
318    $result = $conn->getAll($sql, array($send_id) );
319   
320    if ( $result ){
321        $return = lfGetCSVData( $result, $arrTitle);
322    }
323    return $return;
324}
325
326//---- CSV½ÐÎÏÍѥǡ¼¥¿¼èÆÀ
327function lfGetCSVData( $array, $arrayIndex){   
328   
329    for ($i=0; $i<count($array); $i++){
330       
331        for ($j=0; $j<count($array[$i]); $j++ ){
332            if ( $j > 0 ) $return .= ",";
333            $return .= "\"";           
334            if ( $arrayIndex ){
335                $return .= mb_ereg_replace("<","¡ã",mb_ereg_replace( "\"","\"\"",$array[$i][$arrayIndex[$j]] )) ."\""; 
336            } else {
337                $return .= mb_ereg_replace("<","¡ã",mb_ereg_replace( "\"","\"\"",$array[$i][$j] )) ."\"";
338            }
339        }
340        $return .= "\n";           
341    }
342    return $return;
343}
344
345//¸½ºß»þ¹ï¤Î¼èÆÀ¡ÊÇÛ¿®»þ´Ö¥Ç¥Õ¥©¥ë¥ÈÃÍ¡Ë
346function lfGetNowDate(){
347    $nowdate = date("Y/n/j/G/i");
348    list($year, $month, $day, $hour, $minute) = split("[/]", $nowdate);
349    $arrNowDate = array( 'year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'minutes' => $minute);
350    foreach ($arrNowDate as $key => $val){
351        switch ($key){
352            case 'minutes':
353            $val = ereg_replace('^[0]','', $val);
354            if ($val < 30){
355            $list_date[$key] = '30';
356            }else{
357            $list_date[$key] = '00';
358            }
359            break;
360            case 'year':
361            case 'month':
362            case 'day':
363            $list_date[$key] = $val;
364            break;
365        }
366    }
367        if ($arrNowDate['minutes'] < 30){
368            $list_date['hour'] = $hour;
369        }else{
370            $list_date['hour'] = $hour + 1;
371        }
372    return $list_date;
373}
374
375// ÇÛ¿®ÆâÍƤÈÇÛ¿®¥ê¥¹¥È¤ò½ñ¤­¹þ¤à
376function lfRegistData($arrData){
377   
378    global $conn;
379    global $arrSearchColumn;
380   
381    $objQuery = new SC_Query();
382    $objSelect = new SC_CustomerList( lfConvertParam($arrData, $arrSearchColumn), "magazine" );
383   
384    $search_data = $conn->getAll($objSelect->getListMailMagazine(lfGetIsMobile($_POST['mail_type'])), $objSelect->arrVal);
385    $dataCnt = count($search_data);
386    $dtb_send_history = array();
387   
388   
389    if(DB_TYPE=="pqsql"){
390       $dtb_send_history["send_id"] = $objQuery->nextval('dtb_send_history', 'send_id');
391    }
392   
393    $dtb_send_history["mail_method"] = $arrData['mail_method'];
394    $dtb_send_history["subject"] = $arrData['subject'];
395    $dtb_send_history["body"] = $arrData['body'];
396    if(MELMAGA_BATCH_MODE) {
397        //¥¤¥ó¥¹¥È¡¼¥ëÀè¤Î¥µ¡¼¥Ð¡¼¤ÇCRON¤¬Í­¸ú¤Ç¤¢¤ë¤Ê¤é»ØÄꤵ¤ì¤¿»þ´Ö¤Ë¥á¡¼¥ë¤òÁ÷¤ë
398        $dtb_send_history["start_date"] = $arrData['send_year'] ."/".$arrData['send_month']."/".$arrData['send_day']." ".$arrData['send_hour'].":".$arrData['send_minutes'];
399    } else {
400        //CRON¤¬Ìµ¸ú¤Ç¤¢¤ì¤Ð¥ê¥¢¥ë¥¿¥¤¥à¤ËÁ÷¿®¤¹¤ë
401        $dtb_send_history["start_date"] = "now()";
402    }
403    $dtb_send_history["creator_id"] = $_SESSION['member_id'];
404    $dtb_send_history["send_count"] = $dataCnt;
405    $arrData['body'] = "";
406    $dtb_send_history["search_data"] = serialize($arrData);
407    $dtb_send_history["update_date"] = "now()";
408    $dtb_send_history["create_date"] = "now()";
409    //¥Ï¥Ã¥·¥ådtb_send_history¤ò¥Ç¡¼¥¿¥Ù¡¼¥¹dtb_send_history¤ËÁÞÆþ
410    $objQuery->insert("dtb_send_history", $dtb_send_history );
411   
412    if (DB_TYPE == "mysql") {
413¡¡¡¡  $dtb_send_history["send_id"] = $objQuery->nextval('dtb_send_history', 'send_id');
414    }
415   
416    if ( is_array( $search_data ) ){
417        foreach( $search_data as $line ){
418            $dtb_send_customer = array();
419            $dtb_send_customer["customer_id"] = $line["customer_id"];
420            $dtb_send_customer["send_id"] = $dtb_send_history["send_id"];
421            $dtb_send_customer["email"] = $line["email"];
422           
423            $dtb_send_customer["name"] = $line["name01"] . " " . $line["name02"];
424               
425            $conn->autoExecute("dtb_send_customer", $dtb_send_customer );                   
426        }   
427    }   
428}
429
430// ¥­¥ã¥ó¥Ú¡¼¥ó°ìÍ÷
431function lfGetCampaignList() {
432   
433    global $objQuery;
434   
435    $sql = "SELECT campaign_id, campaign_name FROM dtb_campaign ORDER BY update_date DESC";
436    $arrResult = $objQuery->getall($sql);
437
438    foreach($arrResult as $arrVal) {
439        $arrCampaign[$arrVal['campaign_id']] = $arrVal['campaign_name'];
440    }
441    return $arrCampaign;
442}
443
444function lfGetIsMobile($mail_type) {
445    // ¸¡º÷·ë²Ì¤Î¼èÆÀ           
446    $is_mobile = false;
447    switch($mail_type) {
448        case 1:
449            $is_mobile = false;
450            break;
451        case 2:
452            $is_mobile = true;     
453            break;
454        default:
455            $is_mobile = false;
456            break;
457    }
458   
459    return $is_mobile;
460}
461?>
Note: See TracBrowser for help on using the repository browser.