source: branches/version-2_5-dev/data/class/pages/admin/customer/LC_Page_Admin_Customer.php @ 19805

Revision 19805, 22.5 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある) 一部実装

  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 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_REALDIR . "pages/admin/LC_Page_Admin.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_Admin {
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
56        $this->arrJob = $masterData->getMasterData("mtb_job");
57        $this->arrJob["不明"] = "不明";
58        $this->arrSex = $masterData->getMasterData("mtb_sex");
59        $this->arrPageRows = $masterData->getMasterData("mtb_page_rows");
60        $this->arrMAILMAGATYPE = $masterData->getMasterData("mtb_mail_magazine_type");
61        $this->arrHtmlmail[''] = "すべて";
62        $this->arrHtmlmail[1] = $this->arrMAILMAGATYPE[1];
63        $this->arrHtmlmail[2] = $this->arrMAILMAGATYPE[2];
64
65        $this->arrStatus[1] = "仮会員";
66        $this->arrStatus[2] = "本会員";
67
68        //---- CSVダウンロード用
69        $this->arrColumnCSV = array(
70            array(
71                "sql" => "customer_id",
72                "csv" => "customer_id",
73                "header" => "顧客ID"
74            ),
75            array(
76                "sql" => "name01",
77                "csv" => "name01",
78                "header" => "名前1"
79            ),
80            array(
81                "sql" => "name02",
82                "csv" => "name02",
83                "header" => "名前2"
84            ),
85            array(
86                "sql" => "kana01",
87                "csv" => "kana01",
88                "header" => "お名前(フリガナ・姓)"
89            ),
90            array(
91                "sql" => "kana02",
92                "csv" => "kana02",
93                "header" => "お名前(フリガナ・名)"
94            ),
95            array(
96                "sql" => "zip01",
97                "csv" => "zip01",
98                "header" => "郵便番号1"
99            ),
100            array(
101                "sql" => "zip02",
102                "csv" => "zip02",
103                "header" => "郵便番号2"
104            ),
105            array(
106                "sql" => "pref",
107                "csv" => "pref",
108                "header" => "都道府県"
109            ),
110            array(
111                "sql" => "addr01",
112                "csv" => "addr01",
113                "header" => "住所1"
114            ),
115            array(
116                "sql" => "addr02",
117                "csv" => "addr02",
118                "header" => "住所2"
119            ),
120            array(
121                "sql" => "email",
122                "csv" => "email",
123                "header" => "E-MAIL"
124            ),
125            array(
126                "sql" => "tel01",
127                "csv" => "tel01",
128                "header" => "TEL1"
129            ),
130            array(
131                "sql" => "tel02",
132                "csv" => "tel02",
133                "header" => "TEL2"
134            ),
135            array(
136                "sql" => "tel03",
137                "csv" => "tel03",
138                "header" => "TEL3"
139            ),
140            array(
141                "sql" => "fax01",
142                "csv" => "fax01",
143                "header" => "FAX1"
144            ),
145            array(
146                "sql" => "fax02",
147                "csv" => "fax02",
148                "header" => "FAX2"
149            ),
150            array(
151                "sql" => "fax03",
152                "csv" => "fax03",
153                "header" => "FAX3"
154            ),
155            array(
156                "sql" => "CASE WHEN sex = 1 THEN '男性' ELSE '女性' END AS sex",
157                "csv" => "sex",
158                "header" => "性別"
159            ),
160            array(
161                "sql" => "job",
162                "csv" => "job",
163                "header" => "職業"
164            ),
165            array(
166                "sql" => "cast(birth as date) AS birth",
167                "csv" => "birth",
168                "header" => "誕生日"
169            ),
170            array(
171                "sql" => "cast(first_buy_date as date) AS first_buy_date",
172                "csv" => "first_buy_date",
173                "header" => "初回購入日"
174            ),
175            array(
176                "sql" => "cast(last_buy_date as date) AS last_buy_date",
177                "csv" => "last_buy_date",
178                "header" => "最終購入日"
179            ),
180            array(
181                "sql" => "buy_times",
182                "csv" => "buy_times",
183                "header" => "購入回数"
184            ),
185            array(
186                "sql" => "point",
187                "csv" => "point",
188                "header" => "ポイント残高"
189            ),
190            array(
191                "sql" => "note",
192                "csv" => "note",
193                "header" => "備考"
194            ),
195            array(
196                "sql" => "cast(create_date as date) AS create_date",
197                "csv" => "create_date",
198                "header" => "登録日"
199            ),
200            array(
201                "sql" => "cast(update_date as date) AS update_date",
202                "csv" => "update_date",
203                "header" => "更新日"
204            ),
205        );
206        $this->httpCacheControl('nocache');
207    }
208
209    /**
210     * Page のプロセス.
211     *
212     * @return void
213     */
214    function process() {
215        $this->action();
216        $this->sendResponse();
217    }
218
219    /**
220     * Page のアクション.
221     *
222     * @return void
223     */
224    function action() {
225        //---- ページ初期設定
226        $objQuery = new SC_Query();
227        $objView = new SC_AdminView();
228        $objDate = new SC_Date(1901);
229        $objDb = new SC_Helper_DB_Ex();
230        $this->arrYear = $objDate->getYear();   // 日付プルダウン設定
231        $this->arrMonth = $objDate->getMonth();
232        $this->arrDay = $objDate->getDay();
233        $this->objDate = $objDate;
234
235        // 認証可否の判定
236        $objSess = new SC_Session();
237        SC_Utils_Ex::sfIsSuccess($objSess);
238
239        // POST値の引き継ぎ
240        $this->arrForm = $_POST;
241
242        // ページ送り用
243        $this->arrHidden['search_pageno'] =
244                isset($_POST['search_pageno']) ? $_POST['search_pageno'] : "";
245
246        // 検索ワードの引き継ぎ
247        foreach ($_POST as $key => $val) {
248            switch($key) {
249            case 'sex':
250            case 'status':
251                $this->arrHidden[$key] = SC_Utils_Ex::sfMergeParamCheckBoxes($val);
252                if(!is_array($val)) {
253                    $this->arrForm[$key] = split("-", $val);
254                }
255                break;
256            default:
257                $this->arrHidden[$key] = $val;
258                break;
259            }
260        }
261
262        if (!isset($_POST['mode'])) $_POST['mode'] = "";
263
264        // 顧客削除
265        if ($_POST['mode'] == "delete") {
266            $sql = "SELECT status,email FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
267            $result_customer = $objQuery->getAll($sql, array($_POST["edit_customer_id"]));
268
269            if ($result_customer[0]["status"] == 2) {           //本会員削除
270                $arrDel = array("del_flg" => 1, "update_date" => "NOW()");
271                $objQuery->conn->autoExecute("dtb_customer", $arrDel, "customer_id = " . SC_Utils_Ex::sfQuoteSmart($_POST["edit_customer_id"]) );
272            } elseif ($result_customer[0]["status"] == 1) {     //仮会員削除
273                $sql = "DELETE FROM dtb_customer WHERE customer_id = ?";
274                $objQuery->query($sql, array($_POST["edit_customer_id"]));
275            }
276        }
277        // 登録メール再送
278        if ($_POST['mode'] == "resend_mail") {
279            $arrRet = $objQuery->select("name01, name02, secret_key, email, email_mobile", "dtb_customer","customer_id = ? AND del_flg <> 1 AND status = 1", array($_POST["edit_customer_id"]));
280            if( is_array($arrRet) === true && count($arrRet) > 0 ){
281
282                $this->name01 = $arrRet[0]['name01'];
283                $this->name02 = $arrRet[0]['name02'];
284                $this->uniqid = $arrRet[0]['secret_key'];
285
286                $CONF = $objDb->sfGetBasisData();
287                $this->CONF = $CONF;
288                /**
289                 * 携帯メールアドレスが登録されていれば携帯サイトから仮会員登録したものと判定する。
290                 * TODO: とりあえずの簡易的な判定なので、将来的には判定ルーチンを修正した方が良い。
291                 */
292                if (!empty($arrRet[0]['email_mobile'])) {
293                    $objMailText = new SC_MobileView(false);
294                    $this->to_name01 = $arrRet[0]['name01'];
295                    $this->to_name02 = $arrRet[0]['name02'];
296                } else {
297                    $objMailText = new SC_SiteView(false);
298                }
299                $objMailText->assignobj($this);
300                $mailHelper = new SC_Helper_Mail_Ex();
301
302                $subject = $mailHelper->sfMakesubject('会員登録のご確認');
303                $toCustomerMail = $objMailText->fetch("mail_templates/customer_mail.tpl");
304
305                $objMail = new SC_SendMail();
306                $objMail->setItem(
307                                    ''                  // 宛先
308                                    , $subject          // サブジェクト
309                                    , $toCustomerMail   // 本文
310                                    , $CONF["email03"]  // 配送元アドレス
311                                    , $CONF["shop_name"]// 配送元 名前
312                                    , $CONF["email03"]  // reply_to
313                                    , $CONF["email04"]  // return_path
314                                    , $CONF["email04"]  //  Errors_to
315                                 );
316                // 宛先の設定
317                $name = $this->name01 . $this->name02 ." 様";
318                $objMail->setTo($arrRet[0]["email"], $name);
319                $objMail->sendMail();
320            }
321
322        }
323
324        if ($_POST['mode'] == "search" || $_POST['mode'] == "csv"  || $_POST['mode'] == "delete" || $_POST['mode'] == "delete_all" || $_POST['mode'] == "resend_mail") {
325
326            // 入力文字の強制変換
327            $this->lfConvertParam();
328            // エラーチェック
329            $this->arrErr = $this->lfCheckError($this->arrForm);
330
331            $where = "del_flg = 0";
332
333            /* 入力エラーなし */
334            if (count($this->arrErr) == 0) {
335
336                //-- 検索データ取得
337                $objSelect = new SC_CustomerList($this->arrForm, "customer");
338
339                // 表示件数設定
340                $page_rows = $this->arrForm['page_rows'];
341                if(is_numeric($page_rows)) {
342                    $page_max = $page_rows;
343                } else {
344                    $page_max = SEARCH_PMAX;
345                }
346
347                if (!isset($this->arrForm['search_pageno'])) $this->arrForm['search_pageno'] = "";
348
349                if ($this->arrForm['search_pageno'] == 0){
350                    $this->arrForm['search_pageno'] = 1;
351                }
352
353                $offset = $page_max * ($this->arrForm['search_pageno'] - 1);
354                $objSelect->setLimitOffset($page_max, $offset);
355
356                if ($_POST["mode"] == 'csv') {
357                    $searchSql = $objSelect->getListCSV($this->arrColumnCSV);
358                }else{
359                    $searchSql = $objSelect->getList();
360                }
361
362                $this->search_data = $objQuery->getAll($searchSql, $objSelect->arrVal);
363
364                switch($_POST['mode']) {
365                case 'csv':
366                    require_once(CLASS_EX_REALDIR . "helper_extends/SC_Helper_CSV_Ex.php");
367
368                    $objCSV = new SC_Helper_CSV_Ex();
369                    $i = 0;
370                    $header = "";
371
372                    // CSVカラム取得
373                    $arrCsvOutput = ($objCSV->sfgetCsvOutput(2, 'status = 1'));
374
375                    if (count($arrCsvOutput) <= 0) break;
376
377                    foreach($arrCsvOutput as $data) {
378                        $arrColumn[] = $data["col"];
379                        if ($i != 0) $header .= ", ";
380                        $header .= $data["disp_name"];
381                        $i ++;
382                    }
383                    $header .= "\n";
384
385                    //- 都道府県/職業の変換
386                    for($i = 0; $i < count($this->search_data); $i ++) {
387                        $this->search_data[$i]["pref"] = $this->arrPref[ $this->search_data[$i]["pref"] ];
388                        $this->search_data[$i]["job"]  = $this->arrJob[ $this->search_data[$i]["job"] ];
389                    }
390
391                    //- CSV出力
392                    $data = SC_Utils_Ex::getCSVData($this->search_data, $arrColumn);
393
394
395                    // CSVを送信する。
396                    list($fime_name, $data) = SC_Utils_Ex::sfGetCSVData($head.$data);
397                    $this->sendResponseCSV($fime_name, $data);
398                    exit;
399                    break;
400                case 'delete_all':
401                    // 検索結果をすべて削除
402                    $where = "product_id IN (SELECT product_id FROM SC_Product::alldtlSQL() WHERE $where)";
403                    $sqlval['del_flg'] = 1;
404                    $objQuery->update("dtb_products", $sqlval, $where, $arrval);
405
406                    $sql = "SELECT status,email FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
407                    $result_customer = $objQuery->getAll($sql, array($_POST["del_customer_id"]));
408
409                    if ($result_customer[0]["status"] == 2) {           //本会員削除
410                        $arrDel = array("del_flg" => 1, "update_date" => "NOW()");
411                        $objQuery->conn->autoExecute("dtb_customer", $arrDel, "customer_id = " . SC_Utils_Ex::sfQuoteSmart($_POST["del_customer_id"]) );
412                    } elseif ($result_customer[0]["status"] == 1) {     //仮会員削除
413                        $sql = "DELETE FROM dtb_customer WHERE customer_id = ?";
414                        $objQuery->query($sql, array($_POST["del_customer_id"]));
415                    }
416
417                    break;
418                default:
419
420                    // 行数の取得
421                    $linemax = $objQuery->getOne( $objSelect->getListCount(), $objSelect->arrVal);
422                    $this->tpl_linemax = $linemax;              // 何件が該当しました。表示用
423
424                    // ページ送りの取得
425                    $objNavi = new SC_PageNavi($this->arrHidden['search_pageno'],
426                                               $linemax, $page_max,
427                                               "fnCustomerPage", NAVI_PMAX);
428                    $startno = $objNavi->start_row;
429                    $this->arrPagenavi = $objNavi->arrPagenavi;
430                }
431            }
432        }
433
434        $this->arrCatList = $objDb->sfGetCategoryList();
435    }
436
437    /**
438     * デストラクタ.
439     *
440     * @return void
441     */
442    function destroy() {
443        parent::destroy();
444    }
445
446    //---- 取得文字列の変換
447    function lfConvertParam() {
448        /*
449         *  文字列の変換
450         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
451         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
452         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
453         *  n :  「全角」数字を「半角(ハンカク)」に変換
454         *  a :  全角英数字を半角英数字に変換する
455         */
456        // カラム名とコンバート情報
457        $arrConvList['customer_id'] = "n" ;
458        $arrConvList['name'] = "aKV" ;
459        $arrConvList['pref'] = "n" ;
460        $arrConvList['kana'] = "CKV" ;
461        $arrConvList['b_start_year'] = "n" ;
462        $arrConvList['b_start_month'] = "n" ;
463        $arrConvList['b_start_day'] = "n" ;
464        $arrConvList['b_end_year'] = "n" ;
465        $arrConvList['b_end_month'] = "n" ;
466        $arrConvList['b_end_day'] = "n" ;
467        $arrConvList['tel'] = "n" ;
468        $arrConvList['birth_month'] = "n" ;
469        $arrConvList['email'] = "a" ;
470        $arrConvList['buy_total_from'] = "n" ;
471        $arrConvList['buy_total_to'] = "n" ;
472        $arrConvList['buy_times_from'] = "n" ;
473        $arrConvList['buy_times_to'] = "n" ;
474        $arrConvList['start_year'] = "n" ;
475        $arrConvList['start_month'] = "n" ;
476        $arrConvList['start_day'] = "n" ;
477        $arrConvList['end_year'] = "n" ;
478        $arrConvList['end_month'] = "n" ;
479        $arrConvList['end_day'] = "n" ;
480        $arrConvList['page_rows'] = "n" ;
481        $arrConvList['buy_start_year'] = "n" ;      // 最終購入日 START 年
482        $arrConvList['buy_start_month'] = "n" ;     // 最終購入日 START 月
483        $arrConvList['buy_start_day'] = "n" ;       // 最終購入日 START 日
484        $arrConvList['buy_end_year'] = "n" ;            // 最終購入日 END 年
485        $arrConvList['buy_end_month'] = "n" ;       // 最終購入日 END 月
486        $arrConvList['buy_end_day'] = "n" ;         // 最終購入日 END 日
487        $arrConvList['buy_product_name'] = "aKV" ;  // 購入商品名
488        $arrConvList['buy_product_code'] = "aKV" ;  // 購入商品コード
489        $arrConvList['category_id'] = "" ;          // カテゴリ
490
491        // 文字変換
492        foreach ($arrConvList as $key => $val) {
493            // POSTされてきた値のみ変換する。
494            if(isset($this->arrForm[$key])) {
495                $this->arrForm[$key] = mb_convert_kana($this->arrForm[$key] ,$val);
496            }
497        }
498    }
499
500    //---- 入力エラーチェック
501    function lfCheckError($array) {
502
503        $objErr = new SC_CheckError($array);
504
505        $objErr->doFunc(array("顧客コード", "customer_id", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
506        $objErr->doFunc(array("都道府県", "pref", 2), array("NUM_CHECK","MAX_LENGTH_CHECK"));
507        $objErr->doFunc(array("顧客名", "name", STEXT_LEN), array("MAX_LENGTH_CHECK"));
508        $objErr->doFunc(array("顧客名(カナ)", "kana", STEXT_LEN), array("SPTAB_CHECK" ,"MAX_LENGTH_CHECK", "KANABLANK_CHECK"));
509        $objErr->doFunc(array("誕生日(開始日)", "b_start_year", "b_start_month", "b_start_day"), array("CHECK_DATE"));
510        $objErr->doFunc(array("誕生日(終了日)", "b_end_year", "b_end_month", "b_end_day"), array("CHECK_DATE"));
511        $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"));
512        $objErr->doFunc(array("誕生月", "birth_month", 2), array("NUM_CHECK","MAX_LENGTH_CHECK"));
513        $objErr->doFunc(array('メールアドレス', "email", STEXT_LEN) ,array("EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
514        $objErr->doFunc(array('携帯メールアドレス', "email_mobile", STEXT_LEN) ,array("EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
515        $objErr->doFunc(array("電話番号", "tel", TEL_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
516        $objErr->doFunc(array("購入金額(開始)", "buy_total_from", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
517        $objErr->doFunc(array("購入金額(終了)", "buy_total_to", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
518        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"] .= "※ 購入金額の指定範囲が不正です。";
519        $objErr->doFunc(array("購入回数(開始)", "buy_times_from", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
520        $objErr->doFunc(array("購入回数(終了)", "buy_times_to", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
521        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"] .= "※ 購入回数の指定範囲が不正です。";
522        $objErr->doFunc(array("登録・更新日(開始日)", "start_year", "start_month", "start_day",), array("CHECK_DATE"));
523        $objErr->doFunc(array("登録・更新日(終了日)", "end_year", "end_month", "end_day"), array("CHECK_DATE"));
524        $objErr->doFunc(array("登録・更新日(開始日)","登録・更新日(終了日)", "start_year", "start_month", "start_day", "end_year", "end_month", "end_day"), array("CHECK_SET_TERM"));
525        $objErr->doFunc(array("表示件数", "page_rows", 3), array("NUM_CHECK","MAX_LENGTH_CHECK"));
526        $objErr->doFunc(array("最終購入日(開始日)", "buy_start_year", "buy_start_month", "buy_start_day",), array("CHECK_DATE"));   //最終購入日(開始日)
527        $objErr->doFunc(array("最終購入(終了日)", "buy_end_year", "buy_end_month", "buy_end_day"), array("CHECK_DATE"));            //最終購入日(終了日)
528        //購入金額(from) > 購入金額(to) の場合はエラーとする
529        $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"));
530        $objErr->doFunc(array("購入商品コード", "buy_product_code", STEXT_LEN), array("MAX_LENGTH_CHECK"));                     //購入商品コード
531        $objErr->doFunc(array("購入商品名", "buy_product_name", STEXT_LEN), array("MAX_LENGTH_CHECK"));                         //購入商品名称
532
533        return $objErr->arrErr;
534    }
535}
536?>
Note: See TracBrowser for help on using the repository browser.