source: branches/beta/html/admin/mail/index.php @ 13398

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