source: branches/feature-module-update/data/class/pages/admin/customer/LC_Page_Admin_Customer.php @ 16741

Revision 16741, 24.8 KB checked in by adachi, 16 years ago (diff)

set eol-style:LF

  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27/**
28 * 顧客管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Customer extends LC_Page {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'customer/index.tpl';
47        $this->tpl_mainno = 'customer';
48        $this->tpl_subnavi = 'customer/subnavi.tpl';
49        $this->tpl_subno = 'index';
50        $this->tpl_pager = TEMPLATE_DIR . 'admin/pager.tpl';
51        $this->tpl_subtitle = '顧客マスタ';
52
53        $masterData = new SC_DB_MasterData_Ex();
54        $this->arrPref = $masterData->getMasterData("mtb_pref",
55                             array("pref_id", "pref_name", "rank"));
56
57        $this->arrJob = $masterData->getMasterData("mtb_job");
58        $this->arrJob["不明"] = "不明";
59        $this->arrSex = $masterData->getMasterData("mtb_sex");
60        $this->arrPageRows = $masterData->getMasterData("mtb_page_rows");
61        $this->arrMAILMAGATYPE = $masterData->getMasterData("mtb_mail_magazine_type");
62        $this->arrHtmlmail[''] = "すべて";
63        $this->arrHtmlmail[1] = $this->arrMAILMAGATYPE[1];
64        $this->arrHtmlmail[2] = $this->arrMAILMAGATYPE[2];
65
66        //---- CSVダウンロード用
67        $this->arrColumnCSV = array(0  => array("sql" => "customer_id",
68                                                "csv" => "customer_id",
69                                                "header" => "顧客ID"),
70                                    1  => array("sql" => "name01",
71                                                "csv" => "name01",
72                                                "header" => "名前1"),
73                                    2  => array("sql" => "name02",
74                                                "csv" => "name02",
75                                                "header" => "名前2"),
76                                    3  => array("sql" => "kana01",
77                                                "csv" => "kana01",
78                                                "header" => "フリガナ1"),
79                                    4  => array("sql" => "kana02",
80                                                "csv" => "kana02",
81                                                "header" => "フリガナ2"),
82                                    5  => array("sql" => "zip01",
83                                                "csv" => "zip01",
84                                                "header" => "郵便番号1"),
85                                    6  => array("sql" => "zip02",
86                                                "csv" => "zip02",
87                                                "header" => "郵便番号2"),
88                                    7  => array("sql" => "pref",
89                                                "csv" => "pref",
90                                                "header" => "都道府県"),
91                                    8  => array("sql" => "addr01",
92                                                "csv" => "addr01",
93                                                "header" => "住所1"),
94                                    9  => array("sql" => "addr02",
95                                                "csv" => "addr02",
96                                                "header" => "住所2"),
97                                    10 => array("sql" => "email",
98                                                "csv" => "email",
99                                                "header" => "E-MAIL"),
100                                    11 => array("sql" => "tel01",
101                                                "csv" => "tel01",
102                                                "header" => "TEL1"),
103                                    12 => array("sql" => "tel02",
104                                                "csv" => "tel02",
105                                                "header" => "TEL2"),
106                                    13 => array("sql" => "tel03",
107                                                "csv" => "tel03",
108                                                "header" => "TEL3"),
109                                    14 => array("sql" => "fax01",
110                                                "csv" => "fax01",
111                                                "header" => "FAX1"),
112                                    15 => array("sql" => "fax02",
113                                                "csv" => "fax02",
114                                                "header" => "FAX2"),
115                                    16 => array("sql" => "fax03",
116                                                "csv" => "fax03",
117                                                "header" => "FAX3"),
118                                    17 => array("sql" => "CASE WHEN sex = 1 "
119                                                . " THEN '男性' "
120                                                . " ELSE '女性' END AS sex",
121                                                "csv" => "sex",
122                                                "header" => "性別"),
123                                    18 => array("sql" => "job",
124                                                "csv" => "job",
125                                                "header" => "職業"),
126                                    19 => array("sql" => "cast(birth as date) AS birth",
127                                                "csv" => "birth",
128                                                "header" => "誕生日"),
129                                    20 => array("sql" => "cast(first_buy_date as date) AS first_buy_date",
130                                                "csv" => "first_buy_date",
131                                                "header" => "初回購入日"),
132                                    21 => array("sql" => "cast(last_buy_date as date) AS last_buy_date",
133                                                "csv" => "last_buy_date",
134                                                "header" => "最終購入日"),
135                                    22 => array("sql" => "buy_times",
136                                                "csv" => "buy_times",
137                                                "header" => "購入回数"),
138                                    23 => array("sql" => "point",
139                                                "csv" => "point",
140                                                "header" => "ポイント残高"),
141                                    24 => array("sql" => "note",
142                                                "csv" => "note",
143                                                "header" => "備考"),
144                                    25 => array("sql" => "cast(create_date as date) AS create_date",
145                                                "csv" => "create_date",
146                                                "header" => "登録日"),
147                                    26 => array("sql" => "cast(update_date as date) AS update_date",
148                                                "csv" => "update_date",
149                                                "header" => "更新日")
150                                    );
151    }
152
153    /**
154     * Page のプロセス.
155     *
156     * @return void
157     */
158    function process() {
159        //---- ページ初期設定
160        $objQuery = new SC_Query();
161        $objView = new SC_AdminView();
162        $objDate = new SC_Date(1901);
163        $objDb = new SC_Helper_DB_Ex();
164        $this->arrYear = $objDate->getYear();   // 日付プルダウン設定
165        $this->arrMonth = $objDate->getMonth();
166        $this->arrDay = $objDate->getDay();
167        $this->objDate = $objDate;
168
169        // 認証可否の判定
170        $objSess = new SC_Session();
171        SC_Utils_Ex::sfIsSuccess($objSess);
172
173        // POST値の引き継ぎ
174        $this->arrForm = $_POST;
175
176        // ページ送り用
177        $this->arrHidden['search_pageno'] =
178                isset($_POST['search_pageno']) ? $_POST['search_pageno'] : "";
179
180        // 検索ワードの引き継ぎ
181        foreach ($_POST as $key => $val) {
182            switch($key) {
183            case 'sex':
184                $this->arrHidden[$key] = SC_Utils_Ex::sfMergeParamCheckBoxes($val);
185                if(!is_array($val)) {
186                    $this->arrForm[$key] = split("-", $val);
187                }
188                break;
189            default:
190                $this->arrHidden[$key] = $val;
191                break;
192            }
193        }
194
195        if (!isset($_POST['mode'])) $_POST['mode'] = "";
196
197        // 顧客削除
198        if ($_POST['mode'] == "delete") {
199            $sql = "SELECT status,email FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
200            $result_customer = $objQuery->conn->getAll($sql, array($_POST["edit_customer_id"]));
201
202            if ($result_customer[0]["status"] == 2) {           //本会員削除
203                $arrDel = array("del_flg" => 1, "update_date" => "NOW()");
204                $objQuery->conn->autoExecute("dtb_customer", $arrDel, "customer_id = " . SC_Utils_Ex::sfQuoteSmart($_POST["edit_customer_id"]) );
205            } elseif ($result_customer[0]["status"] == 1) {     //仮会員削除
206                $sql = "DELETE FROM dtb_customer WHERE customer_id = ?";
207                $objQuery->conn->query($sql, array($_POST["edit_customer_id"]));
208            }
209        }
210        if ($_POST['mode'] == "search" || $_POST['mode'] == "csv"  || $_POST['mode'] == "delete" || $_POST['mode'] == "delete_all") {
211            // 入力文字の強制変換
212            $this->lfConvertParam();
213            // エラーチェック
214            $this->arrErr = $this->lfCheckError($this->arrForm);
215
216            $where = "del_flg = 0";
217
218            /* 入力エラーなし */
219            if (count($this->arrErr) == 0) {
220
221                //-- 検索データ取得
222                $objSelect = new SC_CustomerList($this->arrForm, "customer");
223
224                // 表示件数設定
225                $page_rows = $this->arrForm['page_rows'];
226                if(is_numeric($page_rows)) {
227                    $page_max = $page_rows;
228                } else {
229                    $page_max = SEARCH_PMAX;
230                }
231
232                if (!isset($this->arrForm['search_pageno'])) $this->arrForm['search_pageno'] = "";
233
234                if ($this->arrForm['search_pageno'] == 0){
235                    $this->arrForm['search_pageno'] = 1;
236                }
237
238                $offset = $page_max * ($this->arrForm['search_pageno'] - 1);
239                $objSelect->setLimitOffset($page_max, $offset);
240
241                if ($_POST["mode"] == 'csv') {
242                    $searchSql = $objSelect->getListCSV($this->arrColumnCSV);
243                }else{
244                    $searchSql = $objSelect->getList();
245                }
246
247                $this->search_data = $objQuery->conn->getAll($searchSql, $objSelect->arrVal);
248
249                switch($_POST['mode']) {
250                case 'csv':
251                    require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php");
252
253                    $objCSV = new SC_Helper_CSV_Ex();
254                    $i = 0;
255                    $header = "";
256
257                    // CSVカラム取得
258                    $arrCsvOutput = ($objCSV->sfgetCsvOutput(2, " WHERE csv_id = 2 AND status = 1"));
259
260                    if (count($arrCsvOutput) <= 0) break;
261
262                    foreach($arrCsvOutput as $data) {
263                        $arrColumn[] = $data["col"];
264                        if ($i != 0) $header .= ", ";
265                        $header .= $data["disp_name"];
266                        $i ++;
267                    }
268                    $header .= "\n";
269
270                    //- 都道府県/職業の変換
271                    for($i = 0; $i < count($this->search_data); $i ++) {
272                        $this->search_data[$i]["pref"] = $arrPref[ $this->search_data[$i]["pref"] ];
273                        $this->search_data[$i]["job"]  = $arrJob[ $this->search_data[$i]["job"] ];
274                    }
275
276                    //- CSV出力
277                    $data = $this->lfGetCSVData($this->search_data, $arrColumn);
278
279                    SC_Utils_Ex::sfCSVDownload($header.$data);
280                    exit;
281                    break;
282                case 'delete_all':
283                    // 検索結果をすべて削除
284                    $where = "product_id IN (SELECT product_id FROM vw_products_nonclass AS noncls WHERE $where)";
285                    $sqlval['del_flg'] = 1;
286                    $objQuery->update("dtb_products", $sqlval, $where, $arrval);
287
288                    $sql = "SELECT status,email FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
289                    $result_customer = $objQuery->conn->getAll($sql, array($_POST["del_customer_id"]));
290
291                    if ($result_customer[0]["status"] == 2) {           //本会員削除
292                        $arrDel = array("del_flg" => 1, "update_date" => "NOW()");
293                        $objQuery->conn->autoExecute("dtb_customer", $arrDel, "customer_id = " . SC_Utils_Ex::sfQuoteSmart($_POST["del_customer_id"]) );
294                    } elseif ($result_customer[0]["status"] == 1) {     //仮会員削除
295                        $sql = "DELETE FROM dtb_customer WHERE customer_id = ?";
296                        $objQuery->conn->query($sql, array($_POST["del_customer_id"]));
297                    }
298
299                    break;
300                default:
301
302                    // 行数の取得
303                    $linemax = $objQuery->conn->getOne( $objSelect->getListCount(), $objSelect->arrVal);
304                    $this->tpl_linemax = $linemax;              // 何件が該当しました。表示用
305
306                    // ページ送りの取得
307                    $objNavi = new SC_PageNavi($this->arrHidden['search_pageno'],
308                                               $linemax, $page_max,
309                                               "fnCustomerPage", NAVI_PMAX);
310                    $startno = $objNavi->start_row;
311                    $this->arrPagenavi = $objNavi->arrPagenavi;
312                }
313            }
314        }
315
316        $this->arrCatList = $objDb->sfGetCategoryList();
317
318        //---- ページ表示
319        $objView->assignobj($this);
320        $objView->display(MAIN_FRAME);
321    }
322
323    /**
324     * デストラクタ.
325     *
326     * @return void
327     */
328    function destroy() {
329        parent::destroy();
330    }
331
332    //---- 取得文字列の変換
333    function lfConvertParam() {
334        /*
335         *  文字列の変換
336         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
337         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
338         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
339         *  n :  「全角」数字を「半角(ハンカク)」に変換
340         *  a :  全角英数字を半角英数字に変換する
341         */
342        // カラム名とコンバート情報
343        $arrConvList['customer_id'] = "n" ;
344        $arrConvList['name'] = "aKV" ;
345        $arrConvList['pref'] = "n" ;
346        $arrConvList['kana'] = "CKV" ;
347        $arrConvList['b_start_year'] = "n" ;
348        $arrConvList['b_start_month'] = "n" ;
349        $arrConvList['b_start_day'] = "n" ;
350        $arrConvList['b_end_year'] = "n" ;
351        $arrConvList['b_end_month'] = "n" ;
352        $arrConvList['b_end_day'] = "n" ;
353        $arrConvList['tel'] = "n" ;
354        $arrConvList['birth_month'] = "n" ;
355        $arrConvList['email'] = "a" ;
356        $arrConvList['buy_total_from'] = "n" ;
357        $arrConvList['buy_total_to'] = "n" ;
358        $arrConvList['buy_times_from'] = "n" ;
359        $arrConvList['buy_times_to'] = "n" ;
360        $arrConvList['start_year'] = "n" ;
361        $arrConvList['start_month'] = "n" ;
362        $arrConvList['start_day'] = "n" ;
363        $arrConvList['end_year'] = "n" ;
364        $arrConvList['end_month'] = "n" ;
365        $arrConvList['end_day'] = "n" ;
366        $arrConvList['page_rows'] = "n" ;
367        $arrConvList['buy_start_year'] = "n" ;      // 最終購入日 START 年
368        $arrConvList['buy_start_month'] = "n" ;     // 最終購入日 START 月
369        $arrConvList['buy_start_day'] = "n" ;       // 最終購入日 START 日
370        $arrConvList['buy_end_year'] = "n" ;            // 最終購入日 END 年
371        $arrConvList['buy_end_month'] = "n" ;       // 最終購入日 END 月
372        $arrConvList['buy_end_day'] = "n" ;         // 最終購入日 END 日
373        $arrConvList['buy_product_name'] = "aKV" ;  // 購入商品名
374        $arrConvList['buy_product_code'] = "aKV" ;  // 購入商品コード
375        $arrConvList['category_id'] = "" ;          // カテゴリ
376
377        // 文字変換
378        foreach ($arrConvList as $key => $val) {
379            // POSTされてきた値のみ変換する。
380            if(isset($this->arrForm[$key])) {
381                $this->arrForm[$key] = mb_convert_kana($this->arrForm[$key] ,$val);
382            }
383        }
384    }
385
386    //---- 入力エラーチェック
387    function lfCheckError($array) {
388
389        $objErr = new SC_CheckError($array);
390
391        $objErr->doFunc(array("顧客コード", "customer_id", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
392        $objErr->doFunc(array("都道府県", "pref", 2), array("NUM_CHECK","MAX_LENGTH_CHECK"));
393        $objErr->doFunc(array("顧客名", "name", STEXT_LEN), array("MAX_LENGTH_CHECK"));
394        $objErr->doFunc(array("顧客名(カナ)", "kana", STEXT_LEN), array("SPTAB_CHECK" ,"MAX_LENGTH_CHECK", "KANABLANK_CHECK"));
395        $objErr->doFunc(array("誕生日(開始日)", "b_start_year", "b_start_month", "b_start_day"), array("CHECK_DATE"));
396        $objErr->doFunc(array("誕生日(終了日)", "b_end_year", "b_end_month", "b_end_day"), array("CHECK_DATE"));
397        $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"));
398        $objErr->doFunc(array("誕生月", "birth_month", 2), array("NUM_CHECK","MAX_LENGTH_CHECK"));
399        $objErr->doFunc(array('メールアドレス', "email", STEXT_LEN) ,array("EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
400        $objErr->doFunc(array('携帯メールアドレス', "email_mobile", STEXT_LEN) ,array("EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
401        $objErr->doFunc(array("電話番号", "tel", TEL_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
402        $objErr->doFunc(array("購入金額(開始)", "buy_total_from", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
403        $objErr->doFunc(array("購入金額(終了)", "buy_total_to", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
404        if ( (is_numeric($array["buy_total_from"]) && is_numeric($array["buy_total_to"]) ) && ($array["buy_total_from"] > $array["buy_total_to"]) ) $objErr->arrErr["buy_total_from"] .= "※ 購入金額の指定範囲が不正です。";
405        $objErr->doFunc(array("購入回数(開始)", "buy_times_from", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
406        $objErr->doFunc(array("購入回数(終了)", "buy_times_to", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
407        if ( (is_numeric($array["buy_times_from"]) && is_numeric($array["buy_times_to"]) ) && ($array["buy_times_from"] > $array["buy_times_to"]) ) $objErr->arrErr["buy_times_from"] .= "※ 購入回数の指定範囲が不正です。";
408        $objErr->doFunc(array("登録・更新日(開始日)", "start_year", "start_month", "start_day",), array("CHECK_DATE"));
409        $objErr->doFunc(array("登録・更新日(終了日)", "end_year", "end_month", "end_day"), array("CHECK_DATE"));
410        $objErr->doFunc(array("登録・更新日(開始日)","登録・更新日(終了日)", "start_year", "start_month", "start_day", "end_year", "end_month", "end_day"), array("CHECK_SET_TERM"));
411        $objErr->doFunc(array("表示件数", "page_rows", 3), array("NUM_CHECK","MAX_LENGTH_CHECK"));
412        $objErr->doFunc(array("最終購入日(開始日)", "buy_start_year", "buy_start_month", "buy_start_day",), array("CHECK_DATE"));   //最終購入日(開始日)
413        $objErr->doFunc(array("最終購入(終了日)", "buy_end_year", "buy_end_month", "buy_end_day"), array("CHECK_DATE"));            //最終購入日(終了日)
414        //購入金額(from) > 購入金額(to) の場合はエラーとする
415        $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"));
416        $objErr->doFunc(array("購入商品コード", "buy_product_code", STEXT_LEN), array("MAX_LENGTH_CHECK"));                     //購入商品コード
417        $objErr->doFunc(array("購入商品名", "buy_product_name", STEXT_LEN), array("MAX_LENGTH_CHECK"));                         //購入商品名称
418
419        return $objErr->arrErr;
420    }
421
422    function lfSetWhere($arrForm){
423        foreach ($arrForm as $key => $val) {
424
425            $val = sfManualEscape($val);
426
427            if($val == "") continue;
428
429            switch ($key) {
430            case 'product_id':
431                $where .= " AND product_id = ?";
432                $arrval[] = $val;
433                break;
434            case 'product_class_id':
435                $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_class_id = ?)";
436                $arrval[] = $val;
437                break;
438            case 'name':
439                $where .= " AND name ILIKE ?";
440                $arrval[] = "%$val%";
441                break;
442            case 'category_id':
443                list($tmp_where, $tmp_arrval) = sfGetCatWhere($val);
444                if($tmp_where != "") {
445                    $where.= " AND $tmp_where";
446                    $arrval = array_merge($arrval, $tmp_arrval);
447                }
448                break;
449            case 'product_code':
450                $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? GROUP BY product_id)";
451                $arrval[] = "%$val%";
452                break;
453            case 'startyear':
454                $date = sfGetTimestamp($_POST['startyear'], $_POST['startmonth'], $_POST['startday']);
455                $where.= " AND update_date >= ?";
456                $arrval[] = $date;
457                break;
458            case 'endyear':
459                $date = sfGetTimestamp($_POST['endyear'], $_POST['endmonth'], $_POST['endday']);
460                $where.= " AND update_date <= ?";
461                $arrval[] = $date;
462                break;
463            case 'product_flag':
464                global $arrSTATUS;
465                $product_flag = sfSearchCheckBoxes($val);
466                if($product_flag != "") {
467                    $where.= " AND product_flag LIKE ?";
468                    $arrval[] = $product_flag;
469                }
470                break;
471            case 'status':
472                $tmp_where = "";
473                foreach ($val as $element){
474                    if ($element != ""){
475                        if ($tmp_where == ""){
476                            $tmp_where.="AND (status LIKE ? ";
477                        }else{
478                            $tmp_where.="OR status LIKE ? ";
479                        }
480                        $arrval[]=$element;
481                    }
482                }
483                if ($tmp_where != ""){
484                    $tmp_where.=")";
485                    $where.= "$tmp_where";
486                }
487                break;
488            default:
489                break;
490            }
491        }
492    }
493
494    //---- CSV出力用データ取得
495    function lfGetCSVData( $array, $arrayIndex){
496
497        for ($i=0; $i<count($array); $i++){
498
499            for ($j=0; $j<count($array[$i]); $j++ ){
500                if ( $j > 0 ) $return .= ",";
501                $return .= "\"";
502                if ( $arrayIndex ){
503                    $return .= mb_ereg_replace("<","<",mb_ereg_replace( "\"","\"\"",$array[$i][$arrayIndex[$j]] )) ."\"";
504                } else {
505                    $return .= mb_ereg_replace("<","<",mb_ereg_replace( "\"","\"\"",$array[$i][$j] )) ."\"";
506                }
507            }
508            $return .= "\n";
509        }
510
511        return $return;
512    }
513}
514?>
Note: See TracBrowser for help on using the repository browser.