source: branches/rel/html/admin/total/index.php @ 13452

Revision 13452, 24.0 KB checked in by kakinaka, 15 years ago (diff)

GDライブラリがインストールされていない場合はグラフ出力を行わないように修正。

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("./index_sub.php");
9require_once("../batch/daily.php");
10
11require_once("./class/SC_GraphPie.php");
12require_once("./class/SC_GraphLine.php");
13require_once("./class/SC_GraphBar.php");
14
15// GD¥é¥¤¥Ö¥é¥ê¤Î¥¤¥ó¥¹¥È¡¼¥ëȽÄê
16$install_GD = (function_exists("gd_info"))?true:false;
17
18class LC_Page {
19    var $arrResults;
20    var $keyname;
21    var $tpl_image;
22    var $arrTitle;
23    function LC_Page() {
24        $this->tpl_mainpage = 'total/index.tpl';
25        $this->tpl_subnavi = 'total/subnavi.tpl';
26        $this->tpl_graphsubtitle = 'total/subtitle.tpl';
27        $this->tpl_titleimage = URL_DIR.'img/title/title_sale.jpg';
28        $this->tpl_mainno = 'total';
29        global $arrWDAY;
30        $this->arrWDAY = $arrWDAY;
31        // ¥Ú¡¼¥¸¥¿¥¤¥È¥ë
32        $this->arrTitle[''] = "´ü´ÖÊ̽¸·×";
33        $this->arrTitle['term'] = "´ü´ÖÊ̽¸·×";
34        $this->arrTitle['products'] = "¾¦ÉÊÊ̽¸·×";
35        $this->arrTitle['age'] = "ǯÂåÊ̽¸·×";
36        $this->arrTitle['job'] = "¿¦¶ÈÊ̽¸·×";
37        $this->arrTitle['member'] = "²ñ°÷Ê̽¸·×";
38       
39        // ¥­¥ã¥Ã¥·¥å²óÈò¤Î¤¿¤á¤ËÆüÉÕ¤òÅϤ¹
40        $this->cashtime = time();
41    }
42}
43
44$objPage = new LC_Page();
45$objView = new SC_AdminView();
46$objSess = new SC_Session();
47// ǧ¾Ú²ÄÈݤÎȽÄê
48sfIsSuccess($objSess);
49
50// ÆþÎÏ´ü´Ö¤ò¥»¥Ã¥·¥ç¥ó¤Ëµ­Ï¿¤¹¤ë
51lfSaveDateSession();
52
53if($_GET['draw_image'] != ""){
54    define(DRAW_IMAGE , true);
55}else{
56    define(DRAW_IMAGE , false);
57}
58
59// ¥Ñ¥é¥á¡¼¥¿´ÉÍý¥¯¥é¥¹
60$objFormParam = new SC_FormParam();
61// ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
62lfInitParam();
63$objFormParam->setParam($_POST);
64$objFormParam->setParam($_GET);
65
66// ¸¡º÷¥ï¡¼¥É¤Î°ú¤­·Ñ¤®
67foreach ($_POST as $key => $val) {
68    if (ereg("^search_", $key)) {
69        $objPage->arrHidden[$key] = $val;       
70    }
71}
72
73$mode = $objFormParam->getValue('mode');
74switch($mode) {
75case 'pdf':
76case 'csv':
77case 'search':
78    // ÆþÎÏÃͤÎÊÑ´¹
79    $objFormParam->convParam();
80    $objPage->arrErr = lfCheckError($arrRet);
81    $arrRet = $objFormParam->getHashArray();
82   
83    // ÆþÎÏ¥¨¥é¡¼¤Ê¤·
84    if (count($objPage->arrErr) == 0) {
85        foreach ($arrRet as $key => $val) {
86            if($val == "") {
87                continue;
88            }
89            switch ($key) {
90            case 'search_startyear':
91                $sdate = $objFormParam->getValue('search_startyear') . "/" . $objFormParam->getValue('search_startmonth') . "/" . $objFormParam->getValue('search_startday');
92                break;
93            case 'search_endyear':
94                $edate = $objFormParam->getValue('search_endyear') . "/" . $objFormParam->getValue('search_endmonth') . "/" . $objFormParam->getValue('search_endday');
95                break;
96            case 'search_startyear_m':
97                list($sdate, $edate) = sfTermMonth($objFormParam->getValue('search_startyear_m'), $objFormParam->getValue('search_startmonth_m'), CLOSE_DAY);
98                break;
99            default:
100                break;
101            }
102        }
103
104        if($objFormParam->getValue('type') != "") {
105            $type = $objFormParam->getValue('type');
106        }
107               
108        $page = $objFormParam->getValue('page');
109       
110        switch($page) {
111        // ¾¦ÉÊÊ̽¸·×
112        case 'products':
113            if($type == "") {
114                $type = 'all';
115            }
116            $objPage->tpl_page_type = "total/page_products.tpl";
117            // ̤½¸·×¥Ç¡¼¥¿¤Î½¸·×¤ò¹Ô¤¦
118            if(!DAILY_BATCH_MODE) {
119                lfRealTimeDailyTotal($sdate, $edate);
120            }
121            // ¸¡º÷·ë²Ì¤Î¼èÆÀ
122            $objPage = lfGetOrderProducts($type, $sdate, $edate, $objPage, $install_GD, $mode);
123            break;
124        // ¿¦¶ÈÊ̽¸·×
125        case 'job':
126            if($type == "") {
127                $type = 'all';
128            }
129            $objPage->tpl_page_type = "total/page_job.tpl";
130            // ̤½¸·×¥Ç¡¼¥¿¤Î½¸·×¤ò¹Ô¤¦
131            if(!DAILY_BATCH_MODE) {
132                lfRealTimeDailyTotal($sdate, $edate);
133            }
134            // ¸¡º÷·ë²Ì¤Î¼èÆÀ
135            $objPage = lfGetOrderJob($type, $sdate, $edate, $objPage, $install_GD);
136            break;
137        // ²ñ°÷Ê̽¸·×
138        case 'member':
139            if($type == "") {
140                $type = 'all';
141            }
142            $objPage->tpl_page_type = "total/page_member.tpl";
143            // ̤½¸·×¥Ç¡¼¥¿¤Î½¸·×¤ò¹Ô¤¦
144            if(!DAILY_BATCH_MODE) {
145                lfRealTimeDailyTotal($sdate, $edate);
146            }
147            // ¸¡º÷·ë²Ì¤Î¼èÆÀ
148            $objPage = lfGetOrderMember($type, $sdate, $edate, $objPage, $install_GD);
149            break;
150        // ǯÂåÊ̽¸·×
151        case 'age':
152            if($type == "") {
153                $type = 'all';
154            }
155           
156            $objPage->tpl_page_type = "total/page_age.tpl";
157            // ̤½¸·×¥Ç¡¼¥¿¤Î½¸·×¤ò¹Ô¤¦
158            if(!DAILY_BATCH_MODE) {
159                lfRealTimeDailyTotal($sdate, $edate);
160            }
161            // ¸¡º÷·ë²Ì¤Î¼èÆÀ
162            $objPage = lfGetOrderAge($type, $sdate, $edate, $objPage, $install_GD);
163            break;
164        // ´ü´ÖÊ̽¸·×
165        default:
166            if($type == "") {
167                $type = 'day';
168            }
169            $objPage->tpl_page_type = "total/page_term.tpl";
170            // ̤½¸·×¥Ç¡¼¥¿¤Î½¸·×¤ò¹Ô¤¦
171            if(!DAILY_BATCH_MODE) {
172                lfRealTimeDailyTotal($sdate, $edate);
173            }
174            // ¸¡º÷·ë²Ì¤Î¼èÆÀ
175            $objPage = lfGetOrderTerm($type, $sdate, $edate, $objPage, $install_GD);
176           
177            break;
178        }
179
180        if($mode == 'csv') {
181            // CSV½ÐÎÏ¥¿¥¤¥È¥ë¹Ô¤Î¼èÆÀ
182            list($arrTitleCol, $arrDataCol) = lfGetCSVColum($page, $objPage->keyname);
183            $head = sfGetCSVList($arrTitleCol);
184            $data = lfGetDataColCSV($objPage->arrResults, $arrDataCol);
185            // CSV¤òÁ÷¿®¤¹¤ë¡£
186            sfCSVDownload($head.$data, $page."_".$type);
187            exit;
188        }
189       
190        if($mode == 'pdf') {
191            // CSV½ÐÎÏ¥¿¥¤¥È¥ë¹Ô¤Î¼èÆÀ
192            list($arrTitleCol, $arrDataCol, $arrColSize, $arrAlign, $title) = lfGetPDFColum($page, $type, $objPage->keyname);
193            $head = sfGetPDFList($arrTitleCol);
194            $data = lfGetDataColPDF($objPage->arrResults, $arrDataCol, 40);
195            // PDF½ÐÎÏÍÑ
196            $graph_name = basename($objPage->tpl_image);
197            lfPDFDownload($graph_name, $head . $data, $arrColSize, $arrAlign, $sdate, $edate, $title, $page);
198            exit;
199        }
200    }
201    break;
202default:
203    if(count($_GET) == 0) {
204        // ¥Ð¥Ã¥Á¥â¡¼¥É¤Î¾ì¹ç¤Î¤ß¼Â¹Ô¤¹¤ë¡ÊÅöÆü¤Î½¸·×¤ò¹Ô¤¦¤¿¤á¡Ë
205        if(DAILY_BATCH_MODE) {
206            // 3ÆüÁ°¤Þ¤Ç¤Î½¸·×
207            lfStartDailyTotal(3,0);
208        }
209    }
210    break;
211}
212
213
214$objPage->install_GD = $install_GD;
215
216// ÅÐÏ¿¡¦¹¹¿·Æü¸¡º÷ÍÑ
217$objDate = new SC_Date();
218$objDate->setStartYear(RELEASE_YEAR);
219$objDate->setEndYear(DATE("Y"));
220$objPage->arrYear = $objDate->getYear();
221$objPage->arrMonth = $objDate->getMonth();
222$objPage->arrDay = $objDate->getDay();
223// ÆþÎÏÃͤμèÆÀ
224$objPage->arrForm = $objFormParam->getFormParamList();
225
226$objPage->tpl_subtitle = $objPage->arrTitle[$objFormParam->getValue('page')];
227
228$objView->assignobj($objPage);
229$objView->display(MAIN_FRAME);
230
231//---------------------------------------------------------------------------------------------------------------------------
232/* PDF½ÐÎÏ */
233function lfPDFDownload($image, $table, $arrColSize, $arrAlign, $sdate, $edate, $title, $page = "") {
234   
235    $objPdf = new SC_Pdf();
236    $objPdf->setTableColor("CCCCCC", "F0F0F0", "D1DEFE");
237           
238    // ÅÚÂæ¤È¤Ê¤ëPDF¥Õ¥¡¥¤¥ë¤Î»ØÄê
239    $objPdf->setTemplate(PDF_DIR . "total.pdf");
240
241    $disp_sdate = sfDispDBDate($sdate, false);
242    $disp_edate = sfDispDBDate($edate, false);
243               
244    $arrText['title_block'] = $title;
245    $arrText['date_block'] = "$disp_sdate-$disp_edate";
246    $arrImage['graph_block'] = GRAPH_DIR . $image;
247   
248    // ʸËö¤Î\n¤òºï½ü¤¹¤ë
249    $table = ereg_replace("\n$", "", $table);
250    $arrRet = split("\n", $table);
251    $page_max = intval((count($arrRet) / 35) + 1);
252   
253    for($page = 1; $page <= $page_max; $page++) {
254        if($page > 1) {
255            // 2¥Ú¡¼¥¸°Ê¹ß
256            $start_no = 35 * ($page - 1) + 1;
257        } else {
258            // ³«»Ï¥Ú¡¼¥¸
259            $start_no = 1;         
260        }
261               
262        $arrText['page_block'] = $page . " / " . $page_max;
263        $objPdf->setTextBlock($arrText);
264        $objPdf->setImageBlock($arrImage);
265        // ¥Ö¥í¥Ã¥¯ÃͤÎÆþÎÏ
266        $objPdf->writeBlock();
267        // ºÇ½ª¥Ú¡¼¥¸¤Î¤ß¡¢¾¦ÉÊÊ̽¸·×¤Ï¹ç·×¤¬¤Ê¤¤¤Î¤ÇºÇ½ª¹Ô¤Î¿§¤òÊѹ¹¤·¤Ê¤¤¡£
268        if($page == $page_max && $page != 'products') {
269            $last_color_flg = true;
270        } else {
271            $last_color_flg = false;
272        }   
273        $objPdf->writeTableCenter($table, 500, $arrColSize, $arrAlign, 35, $start_no, $last_color_flg);
274        $objPdf->closePage();
275    }
276
277    // PDF¤Î½ÐÎÏ
278    $objPdf->output(); 
279}
280
281/* ¥»¥Ã¥·¥ç¥ó¤ËÆþÎÏ´ü´Ö¤òµ­Ï¿¤¹¤ë */
282function lfSaveDateSession() {
283    if($_POST['form'] == 1) {
284        $_SESSION['total']['startyear_m'] = $_POST['search_startyear_m'];
285        $_SESSION['total']['startmonth_m'] = $_POST['search_startmonth_m'];
286    }
287   
288    if($_POST['form'] == 2) {
289        $_SESSION['total']['startyear'] = $_POST['search_startyear'];
290        $_SESSION['total']['startmonth'] = $_POST['search_startmonth'];
291        $_SESSION['total']['startday'] = $_POST['search_startday'];
292        $_SESSION['total']['endyear'] = $_POST['search_endyear'];
293        $_SESSION['total']['endmonth'] = $_POST['search_endmonth'];
294        $_SESSION['total']['endday'] = $_POST['search_endday'];
295    }
296}
297
298/* ¥Ç¥Õ¥©¥ë¥ÈÃͤμèÆÀ */
299function lfGetDateDefault() {
300    $year = date("Y");
301    $month = date("m");
302    $day = date("d");
303   
304    $list = $_SESSION['total'];
305   
306    // ¥»¥Ã¥·¥ç¥ó¾ðÊó¤Ë³«»Ï·îÅÙ¤¬Êݸ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
307    if($_SESSION['total']['startyear_m'] == "") {
308        $list['startyear_m'] = $year;
309        $list['startmonth_m'] = $month;
310    }
311   
312    // ¥»¥Ã¥·¥ç¥ó¾ðÊó¤Ë³«»ÏÆüÉÕ¡¢½ªÎ»ÆüÉÕ¤¬Êݸ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
313    if($_SESSION['total']['startyear'] == "" && $_SESSION['total']['endyear'] == "") {
314        $list['startyear'] = $year;
315        $list['startmonth'] = $month;
316        $list['startday'] = $day;
317        $list['endyear'] = $year;
318        $list['endmonth'] = $month;
319        $list['endday'] = $day;
320    }
321   
322    return $list;   
323}
324
325/* ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½ */
326function lfInitParam() {
327    global $objFormParam;
328       
329    // ¥Ç¥Õ¥©¥ë¥ÈÃͤμèÆÀ
330    $arrList = lfGetDateDefault();
331   
332    // ·îÅÙ½¸·×
333    $objFormParam->addParam("·îÅÙ", "search_startyear_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear_m']);
334    $objFormParam->addParam("·îÅÙ", "search_startmonth_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth_m']);
335    // ´ü´Ö½¸·×
336    $objFormParam->addParam("³«»ÏÆü", "search_startyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear']);
337    $objFormParam->addParam("³«»ÏÆü", "search_startmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth']);
338    $objFormParam->addParam("³«»ÏÆü", "search_startday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startday']);
339    $objFormParam->addParam("½ªÎ»Æü", "search_endyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endyear']);
340    $objFormParam->addParam("½ªÎ»Æü", "search_endmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endmonth']);
341    $objFormParam->addParam("½ªÎ»Æü", "search_endday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endday']);
342   
343    // hidden¥Ç¡¼¥¿¤Î¼èÆÀÍÑ
344    $objFormParam->addParam("", "page");
345    $objFormParam->addParam("", "type");
346    $objFormParam->addParam("", "mode");
347
348}
349
350/* ÆþÎÏÆâÍƤΥÁ¥§¥Ã¥¯ */
351function lfCheckError() {
352    global $objFormParam;
353    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
354    $arrRet =  $objFormParam->getHashArray();
355    $objErr = new SC_CheckError($arrRet);
356    $objErr->arrErr = $objFormParam->checkError();
357   
358    // Æüì¹àÌÜ¥Á¥§¥Ã¥¯
359    if($_POST['form'] == 1) {
360        $objErr->doFunc(array("·îÅÙ", "search_startyear_m"), array("ONE_EXIST_CHECK"));
361    }
362   
363    if($_POST['form'] == 2) {
364        $objErr->doFunc(array("´ü´Ö", "search_startyear", "search_endyear"), array("ONE_EXIST_CHECK"));
365    }
366           
367    $objErr->doFunc(array("·îÅÙ", "search_startyear_m", "search_startmonth_m"), array("ALL_EXIST_CHECK"));
368    $objErr->doFunc(array("³«»ÏÆü", "search_startyear", "search_startmonth", "search_startday"), array("CHECK_DATE"));
369    $objErr->doFunc(array("½ªÎ»Æü", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_DATE"));
370    $objErr->doFunc(array("³«»ÏÆü", "½ªÎ»Æü", "search_startyear", "search_startmonth", "search_startday", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_SET_TERM"));
371    return $objErr->arrErr;
372}
373
374/* ÀÞ¤ìÀþ¥°¥é¥Õ¤ÎºîÀ® */
375function lfGetGraphLine($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) {
376   
377    $ret_path = "";
378   
379    // ·ë²Ì¤¬0¹Ô°Ê¾å¤¢¤ë¾ì¹ç¤Î¤ß¥°¥é¥Õ¤òÀ¸À®¤¹¤ë¡£
380    if(count($arrResults) > 0) {
381       
382        // ¥°¥é¥Õ¤ÎÀ¸À®
383        $arrList = sfArrKeyValue($arrResults, $keyname, "total");
384
385        // °ì»þ¥Õ¥¡¥¤¥ë̾¤Î¼èÆÀ
386        $pngname = lfGetGraphPng($type);
387       
388        $path = GRAPH_DIR . $pngname;
389       
390        // ¥é¥Ù¥ëɽ¼¨¥¤¥ó¥¿¡¼¥Ð¥ë¤òµá¤á¤ë
391        $interval = intval(count($arrList) / 20);
392        if($interval < 1) {
393            $interval = 1;
394        }
395        $objGraphPie = new SC_GraphPie();
396        $objGraphLine = new SC_GraphLine();
397       
398        // ÃͤΥ»¥Ã¥È
399        $objGraphLine->setData($arrList);
400        $objGraphLine->setXLabel(array_keys($arrList));
401       
402        // ¥é¥Ù¥ë²óž(ÆüËܸìÉÔ²Ä)
403        if($keyname == "key_day"){
404            $objGraphLine->setXLabelAngle(45);
405        }
406
407        // ¥¿¥¤¥È¥ë¥»¥Ã¥È
408        $objGraphLine->setXTitle($xtitle);
409        $objGraphLine->setYTitle($ytitle);
410       
411        // ¥á¥¤¥ó¥¿¥¤¥È¥ëºîÀ®
412        list($sy, $sm, $sd) = split("[/ ]" , $sdate);
413        list($ey, $em, $ed) = split("[/ ]" , $edate);
414        $start_date = $sy . "ǯ" . $sm . "·î" . $sd . "Æü";
415        $end_date = $ey . "ǯ" . $em . "·î" . $ed . "Æü";
416        $objGraphLine->drawTitle("½¸·×´ü´Ö¡§" . $start_date . " - " . $end_date);
417       
418        // ¥°¥é¥ÕÉÁ²è
419        $objGraphLine->drawGraph();
420       
421        // ¥°¥é¥Õ¤Î½ÐÎÏ
422        if(DRAW_IMAGE){
423            $objGraphLine->outputGraph();
424            exit();
425        }
426
427        // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¤òÊÖ¤¹
428        $ret_path = GRAPH_URL . $pngname;
429    }
430    return $ret_path;
431}
432
433// ±ß¥°¥é¥Õ¤ÎºîÀ®
434function lfGetGraphPie($arrResults, $keyname, $type, $title = "", $sdate = "", $edate = "") {
435   
436    $ret_path = "";
437   
438    // ·ë²Ì¤¬0¹Ô°Ê¾å¤¢¤ë¾ì¹ç¤Î¤ß¥°¥é¥Õ¤òÀ¸À®¤¹¤ë¡£
439    if(count($arrResults) > 0) {
440        // ¥°¥é¥Õ¤ÎÀ¸À®
441        $arrList = sfArrKeyValue($arrResults, $keyname, "total", GRAPH_PIE_MAX, GRAPH_LABEL_MAX);
442       
443        // °ì»þ¥Õ¥¡¥¤¥ë̾¤Î¼èÆÀ
444        $pngname = lfGetGraphPng($type);
445        $path = GRAPH_DIR . $pngname;
446       
447        $objGraphPie = new SC_GraphPie();
448       
449        /* ¥Ç¥Ð¥Ã¥°É½¼¨ÍÑ by naka
450        foreach($arrList as $key => $val) {
451            $objGraphPie->debugPrint("key:$key val:$val");
452        }
453        */
454       
455        // ¥Ç¡¼¥¿¤ò¥»¥Ã¥È¤¹¤ë
456        $objGraphPie->setData($arrList);
457        // ËÞÎã¤ò¥»¥Ã¥È¤¹¤ë
458        $objGraphPie->setLegend(array_keys($arrList));
459                               
460        // ¥á¥¤¥ó¥¿¥¤¥È¥ëºîÀ®
461        list($sy, $sm, $sd) = split("[/ ]" , $sdate);
462        list($ey, $em, $ed) = split("[/ ]" , $edate);
463        $start_date = $sy . "ǯ" . $sm . "·î" . $sd . "Æü";
464        $end_date = $ey . "ǯ" . $em . "·î" . $ed . "Æü";
465        $objGraphPie->drawTitle("½¸·×´ü´Ö¡§" . $start_date . " - " . $end_date);
466               
467        // ±ß¥°¥é¥ÕÉÁ²è
468        $objGraphPie->drawGraph();
469       
470        // ¥°¥é¥Õ¤Î½ÐÎÏ
471        if(DRAW_IMAGE){
472            $objGraphPie->outputGraph();
473            exit();
474        }
475
476        // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¤òÊÖ¤¹
477        $ret_path = GRAPH_URL . $pngname;
478    }
479    return $ret_path;
480}
481
482// ËÀ¥°¥é¥Õ¤ÎºîÀ®
483function lfGetGraphBar($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) {
484    $ret_path = "";
485   
486    // ·ë²Ì¤¬0¹Ô°Ê¾å¤¢¤ë¾ì¹ç¤Î¤ß¥°¥é¥Õ¤òÀ¸À®¤¹¤ë¡£
487    if(count($arrResults) > 0) {
488        // ¥°¥é¥Õ¤ÎÀ¸À®
489        $arrList = sfArrKeyValue($arrResults, $keyname, "total", GRAPH_PIE_MAX, GRAPH_LABEL_MAX);
490       
491        // °ì»þ¥Õ¥¡¥¤¥ë̾¤Î¼èÆÀ
492        $pngname = lfGetGraphPng($type);
493        $path = GRAPH_DIR . $pngname;
494       
495        $objGraphBar = new SC_GraphBar();
496       
497        foreach(array_keys($arrList) as $val) {
498            $arrKey[] = ereg_replace("¡Á", "-", $val);
499        }
500       
501        // ¥°¥é¥ÕÉÁ²è
502        $objGraphBar->setXLabel($arrKey);
503        $objGraphBar->setXTitle($xtitle);
504        $objGraphBar->setYTitle($ytitle);
505        $objGraphBar->setData($arrList);
506       
507        // ¥á¥¤¥ó¥¿¥¤¥È¥ëºîÀ®
508        $arrKey = array_keys($arrList);
509        list($sy, $sm, $sd) = split("[/ ]" , $sdate);
510        list($ey, $em, $ed) = split("[/ ]" , $edate);
511        $start_date = $sy . "ǯ" . $sm . "·î" . $sd . "Æü";
512        $end_date = $ey . "ǯ" . $em . "·î" . $ed . "Æü";
513        $objGraphBar->drawTitle("½¸·×´ü´Ö¡§" . $start_date . " - " . $end_date);
514       
515        $objGraphBar->drawGraph();
516       
517        if(DRAW_IMAGE){
518            $objGraphBar->outputGraph();
519            exit();
520        }
521       
522        // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¤òÊÖ¤¹
523        $ret_path = GRAPH_URL . $pngname;
524    }
525    return $ret_path;
526}
527
528// ¥°¥é¥ÕÍѤÎPNG¥Õ¥¡¥¤¥ë̾
529function lfGetGraphPng($keyname) {
530    if($_POST['search_startyear_m'] != "") {
531        $pngname = sprintf("%s_%02d%02d.png", $keyname, substr($_POST['search_startyear_m'],2), $_POST['search_startmonth_m']);
532    } else {
533        $pngname = sprintf("%s_%02d%02d%02d_%02d%02d%02d.png", $keyname, substr($_POST['search_startyear'], 2), $_POST['search_startmonth'], $_POST['search_startday'], substr($_POST['search_endyear'],2), $_POST['search_endmonth'], $_POST['search_endday']);
534    }
535    return $pngname;
536}
537
538// ²ñ°÷¡¢Èó²ñ°÷½¸·×¤ÎWHEREʬ¤ÎºîÀ®
539function lfGetWhereMember($col_date, $sdate, $edate, $type, $col_member = "customer_id") {
540    // ¼èÆÀÆüÉդλØÄê
541    if($sdate != "") {
542        if ($where != "") {
543            $where.= " AND ";
544        }           
545        $where.= " $col_date >= '". $sdate ."'";
546    }
547       
548    if($edate != "") {
549        if ($where != "") {
550            $where.= " AND ";
551        }
552        $edate = date("Y/m/d",strtotime("1 day" ,strtotime($edate)));   
553        $where.= " $col_date < date('" . $edate ."')";
554    }
555   
556    // ²ñ°÷¡¢Èó²ñ°÷¤ÎȽÄê
557    switch($type) {
558    // Á´ÂÎ
559    case 'all':
560        break;
561    case 'member':
562        if ($where != "") {
563            $where.= " AND ";
564        }
565        $where.= " $col_member <> 0";
566        break;
567    case 'nonmember':
568        if ($where != "") {
569            $where.= " AND ";
570        }
571        $where.= " $col_member = 0";
572        break;
573    default:
574        break;
575    }
576   
577    return array($where, $arrval);
578}
579
580/** ²ñ°÷Ê̽¸·× **/
581function lfGetOrderMember($type, $sdate, $edate, $objPage, $graph = true) {
582    global $arrSex;
583       
584    list($where, $arrval) = lfGetWhereMember('create_date', $sdate, $edate, $type);
585   
586    // ²ñ°÷½¸·×¤Î¼èÆÀ
587    $col = "COUNT(*) AS order_count, SUM(total) AS total, (AVG(total)) AS total_average, order_sex";
588    $from = "dtb_order";
589    $objQuery = new SC_Query();
590    $objQuery->setGroupBy("order_sex");
591   
592    $tmp_where = $where . " AND customer_id <> 0 AND del_flg = 0 ";
593    $arrRet = $objQuery->select($col, $from, $tmp_where, $arrval);
594   
595    // ²ñ°÷¹ØÆþ¤Ç¤¢¤ë¤³¤È¤òµ­Ï¿¤¹¤ë¡£
596    $max = count($arrRet);
597    for($i = 0; $i < $max; $i++) {
598        $arrRet[$i]['member_name'] = '²ñ°÷'.$arrSex[$arrRet[$i]['order_sex']];
599    }
600    $objPage->arrResults = $arrRet;
601   
602    // Èó²ñ°÷½¸·×¤Î¼èÆÀ
603    $tmp_where = $where . " AND customer_id = 0 AND del_flg = 0 ";
604    $arrRet = $objQuery->select($col, $from, $tmp_where, $arrval);
605    // Èó²ñ°÷¹ØÆþ¤Ç¤¢¤ë¤³¤È¤òµ­Ï¿¤¹¤ë¡£
606    $max = count($arrRet);
607    for($i = 0; $i < $max; $i++) {
608        $arrRet[$i]['member_name'] = 'Èó²ñ°÷'.$arrSex[$arrRet[$i]['order_sex']];
609    }
610   
611    $objPage->arrResults = array_merge($objPage->arrResults, $arrRet);
612   
613    // ±ß¥°¥é¥Õ¤ÎÀ¸À®
614    if($graph) {   
615        $image_key = "member";
616        $objPage->tpl_image = lfGetGraphPie($objPage->arrResults, "member_name", $image_key, "(Çä¾åÈæΨ)", $sdate, $edate);
617    }
618   
619    return $objPage;
620}
621
622/** ¾¦ÉÊÊ̽¸·× **/
623function lfGetOrderProducts($type, $sdate, $edate, $objPage, $graph = true, $mode = "") {
624    list($where, $arrval) = lfGetWhereMember('create_date', $sdate, $edate, $type);
625   
626    $where .= " and del_flg=0 and status <> " . ORDER_CANCEL;
627   
628    $sql = "SELECT T1.product_id, T1.product_code, T1.product_name as name, T1.products_count, T1.order_count, T1.price, T1.total ";
629    $sql.= "FROM ( ";
630    $sql.= "SELECT product_id, product_name, product_code, price, ";
631    $sql.= "COUNT(*) AS order_count, ";
632    $sql.= "SUM(quantity) AS products_count, ";
633    $sql.= "(price * sum(quantity)) AS total ";
634    $sql.= "FROM dtb_order_detail WHERE order_id IN (SELECT order_id FROM dtb_order WHERE $where ) ";
635    $sql.= "GROUP BY product_id, product_name, product_code, price ";
636    $sql.= ") AS T1 ";
637    $sql.= "ORDER BY T1.total DESC ";
638   
639    if($mode != "csv") {
640        $sql.= "LIMIT " . PRODUCTS_TOTAL_MAX;
641    }
642   
643    $objQuery = new SC_Query();
644    $objPage->arrResults = $objQuery->getall($sql, $arrval);
645   
646    // ±ß¥°¥é¥Õ¤ÎÀ¸À®
647    if($graph) {
648        $image_key = "products_" . $type;
649        $objPage->tpl_image = lfGetGraphPie($objPage->arrResults, "name", $image_key, "(Çä¾åÈæΨ)", $sdate, $edate);
650    }
651   
652    return $objPage;
653}
654
655/** ¿¦¶ÈÊ̽¸·× **/
656function lfGetOrderJob($type, $sdate, $edate, $objPage, $graph = true) {
657    global $arrJob;
658       
659    list($where, $arrval) = lfGetWhereMember('T2.create_date', $sdate, $edate, $type);
660   
661    $sql = "SELECT job, count(*) AS order_count, SUM(total) AS total, (AVG(total)) AS total_average ";
662    $sql.= "FROM dtb_customer AS T1 LEFT JOIN dtb_order AS T2 USING ( customer_id ) WHERE $where AND T2.del_flg = 0 and T2.status <> " . ORDER_CANCEL;
663    $sql.= " GROUP BY job ORDER BY total DESC";
664   
665    $objQuery = new SC_Query();
666    $objPage->arrResults = $objQuery->getall($sql, $arrval);
667   
668    $max = count($objPage->arrResults);
669    for($i = 0; $i < $max; $i++) {
670        $job_key = $objPage->arrResults[$i]['job'];
671        if($job_key != "") {
672            $objPage->arrResults[$i]['job_name'] = $arrJob[$job_key];
673        } else {
674            $objPage->arrResults[$i]['job_name'] = "̤²óÅú";
675        }
676    }
677
678    // ±ß¥°¥é¥Õ¤ÎÀ¸À®   
679    if($graph) {
680        $image_key = "job_" . $type;
681        $objPage->tpl_image = lfGetGraphPie($objPage->arrResults, "job_name", $image_key, "(Çä¾åÈæΨ)", $sdate, $edate);
682    }
683   
684    return $objPage;
685}
686
687/** ǯÂåÊ̽¸·× **/
688function lfGetOrderAge($type, $sdate, $edate, $objPage, $graph = true) {
689
690    list($where, $arrval) = lfGetWhereMember('order_date', $sdate, $edate, $type, "member");
691   
692    $sql = "SELECT SUM(order_count) AS order_count, SUM(total) AS total, start_age, end_age ";
693    $sql.= "FROM dtb_bat_order_daily_age WHERE $where ";
694    $sql.= "GROUP BY start_age, end_age ORDER BY start_age, end_age";
695
696    $objQuery = new SC_Query();
697    $objPage->arrResults = $objQuery->getall($sql, $arrval);
698   
699    $max = count($objPage->arrResults);
700    for($i = 0; $i < $max; $i++) {
701        if($objPage->arrResults[$i]['order_count'] > 0) {
702            $objPage->arrResults[$i]['total_average'] = intval($objPage->arrResults[$i]['total'] / $objPage->arrResults[$i]['order_count']);
703        }   
704        $start_age = $objPage->arrResults[$i]['start_age'];
705        $end_age = $objPage->arrResults[$i]['end_age'];
706        if($start_age != "" || $end_age != "") {
707            if($end_age != 999) {
708                $objPage->arrResults[$i]['age_name'] = $start_age . "¡Á" . $end_age . "ºÐ";
709            } else {
710                $objPage->arrResults[$i]['age_name'] = $start_age . "ºÐ¡Á";
711            }
712        } else {
713            $objPage->arrResults[$i]['age_name'] = "̤²óÅú";
714        }
715    }
716   
717    // ËÀ¥°¥é¥Õ¤ÎÀ¸À®
718    if($graph) {
719        $image_key = "age_" . $type;
720        $xtitle = "(ǯÎð)";
721        $ytitle = "(Çä¾å¹ç·×)";
722        $objPage->tpl_image = lfGetGraphBar($objPage->arrResults, "age_name", $image_key, $xtitle, $ytitle, $sdate, $edate);
723    }
724   
725    return $objPage;
726}
727
728/** ´ü´ÖÊ̽¸·× **/
729function lfGetOrderTerm($type, $sdate, $edate, $objPage, $graph = true) {
730       
731        $tmp_col = "sum(total_order) as total_order, sum(men) as men, sum(women) as women,";
732        $tmp_col.= "sum(men_member) as men_member, sum(men_nonmember) as men_nonmember,";
733        $tmp_col.= "sum(women_member) as women_member, sum(women_nonmember) as women_nonmember,";
734        $tmp_col.= "sum(total) as total, (avg(total_average)) as total_average";
735        $objQuery = new SC_Query();
736       
737        switch($type) {
738        // ·îÊÌ
739        case 'month':
740            $col = $tmp_col . ",key_month";
741            $objQuery->setgroupby("key_month");
742            $objQuery->setOrder("key_month");
743            $objPage->keyname = "key_month";
744            $objPage->tpl_tail = "·î";
745            $from = "dtb_bat_order_daily";
746            $xtitle = "(·îÊÌ)";
747            $ytitle = "(Çä¾å¹ç·×)";
748            break;
749        // ǯÊÌ
750        case 'year':
751            $col = $tmp_col . ",key_year";
752            $objQuery->setgroupby("key_year");
753            $objQuery->setOrder("key_year");
754            $objPage->keyname = "key_year";
755            $objPage->tpl_tail = "ǯ";
756            $from = "dtb_bat_order_daily";
757            $xtitle = "(ǯÊÌ)";
758            $ytitle = "(Çä¾å¹ç·×)";
759            break;
760        // ÍËÆüÊÌ
761        case 'wday':
762            $col = $tmp_col . ",key_wday, wday";
763            $objQuery->setgroupby("key_wday, wday");
764            $objQuery->setOrder("wday");
765            $objPage->keyname = "key_wday";
766            $objPage->tpl_tail = "ÍËÆü";
767            $from = "dtb_bat_order_daily";
768            $xtitle = "(ÍËÆüÊÌ)";
769            $ytitle = "(Çä¾å¹ç·×)";
770            break;
771        // »þ´ÖÊÌ
772        case 'hour':
773            $col = $tmp_col . ",hour";
774            $objQuery->setgroupby("hour");
775            $objQuery->setOrder("hour");
776            $objPage->keyname = "hour";
777            $objPage->tpl_tail = "»þ";
778            $from = "dtb_bat_order_daily_hour";
779            $xtitle = "(»þ´ÖÊÌ)";
780            $ytitle = "(Çä¾å¹ç·×)";
781            break;
782        default:
783            $col = "*";
784            $objQuery->setOrder("key_day");
785            $objPage->keyname = "key_day";
786            $from = "dtb_bat_order_daily";
787            $xtitle = "(ÆüÊÌ)";
788            $ytitle = "(Çä¾å¹ç·×)";
789            break;
790        }
791       
792
793    // ¼èÆÀÆüÉդλØÄê
794        if($sdate != "") {
795            if ($where != "") {
796                $where.= " AND ";
797            }           
798            $where.= " order_date >= '". $sdate ."'";
799        }
800       
801        if($edate != "") {
802            if ($where != "") {
803                $where.= " AND ";
804            }
805            $edate_next = date("Y/m/d",strtotime("1 day" ,strtotime($edate)));
806            $where.= " order_date < date('" . $edate_next ."')";
807        }
808       
809        // ¸¡º÷·ë²Ì¤Î¼èÆÀ
810        $objPage->arrResults = $objQuery->select($col, $from, $where, $arrval);
811       
812        // ÀÞ¤ìÀþ¥°¥é¥Õ¤ÎÀ¸À®   
813        if($graph) {
814            $image_key = "term_" . $type;
815            $objPage->tpl_image = lfGetGraphLine($objPage->arrResults, $objPage->keyname, $image_key, $xtitle, $ytitle, $sdate, $edate);
816        }
817       
818        // ¸¡º÷·ë²Ì¤¬0¤Ç¤Ê¤¤¾ì¹ç
819        if(count($objPage->arrResults) > 0) {
820            // ºÇ½ª½¸·×¹Ô¼èÆÀ¤¹¤ë
821            $col = $tmp_col;
822            $objQuery = new SC_Query();
823            $arrRet = $objQuery->select($col, $from, $where, $arrval);
824            $arrRet[0][$objPage->keyname] = "¹ç·×";
825            $objPage->arrResults[] = $arrRet[0];
826        }
827
828        // Ê¿¶ÑÃͤη׻»
829        $max = count($objPage->arrResults);
830        for($i = 0; $i < $max; $i++) {
831            if($objPage->arrResults[$i]['total_order'] > 0) {
832                $objPage->arrResults[$i]['total_average'] = intval($objPage->arrResults[$i]['total'] / $objPage->arrResults[$i]['total_order']);
833            }
834        }
835       
836        return $objPage;
837}
838
839?>
Note: See TracBrowser for help on using the repository browser.