source: branches/comu-ver2/data/class/pages/admin/customer/LC_Page_Admin_Customer.php @ 18701

Revision 18701, 24.2 KB checked in by nanasess, 14 years ago (diff)

Copyright の更新(#601)

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