source: trunk/data/class/pages/admin/customer/LC_Page_Admin_Customer_Edit.php @ 18758

Revision 18758, 17.4 KB checked in by kajiwara, 14 years ago (diff)

EC-CUBE Ver2.4.4 分コミット。詳細はこちら( http://www.ec-cube.net/release/detail.php?release_id=223

  • 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-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_Edit 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/edit.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", array("pref_id", "pref_name", "rank"));
55        $this->arrJob = $masterData->getMasterData("mtb_job");
56        $this->arrSex = $masterData->getMasterData("mtb_sex");
57        $this->arrReminder = $masterData->getMasterData("mtb_reminder");
58    }
59
60    /**
61     * Page のプロセス.
62     *
63     * @return void
64     */
65    function process() {
66
67        // 認証可否の判定
68        $objSess = new SC_Session();
69        SC_Utils_Ex::sfIsSuccess($objSess);
70
71        $this->objQuery = new SC_Query();
72        $this->objConn = new SC_DBConn();
73        $objView = new SC_AdminView();
74        $objDb = new SC_Helper_DB_Ex();
75        $objDate = new SC_Date(1901);
76        $this->arrYear = $objDate->getYear();    // 日付プルダウン設定
77        $this->arrMonth = $objDate->getMonth();
78        $this->arrDay = $objDate->getDay();
79
80        //---- 登録用カラム配列
81        $arrRegistColumn = array(
82                                 array(  "column" => "name01",        "convert" => "aKV" ),
83                                 array(  "column" => "name02",        "convert" => "aKV" ),
84                                 array(  "column" => "kana01",        "convert" => "CKV" ),
85                                 array(  "column" => "kana02",        "convert" => "CKV" ),
86                                 array(  "column" => "zip01",        "convert" => "n" ),
87                                 array(  "column" => "zip02",        "convert" => "n" ),
88                                 array(  "column" => "pref",        "convert" => "n" ),
89                                 array(  "column" => "addr01",        "convert" => "aKV" ),
90                                 array(  "column" => "addr02",        "convert" => "aKV" ),
91                                 array(  "column" => "email",        "convert" => "a" ),
92                                 array(  "column" => "email_mobile",    "convert" => "a" ),
93                                 array(  "column" => "tel01",        "convert" => "n" ),
94                                 array(  "column" => "tel02",        "convert" => "n" ),
95                                 array(  "column" => "tel03",        "convert" => "n" ),
96                                 array(  "column" => "fax01",        "convert" => "n" ),
97                                 array(  "column" => "fax02",        "convert" => "n" ),
98                                 array(  "column" => "fax03",        "convert" => "n" ),
99                                 array(  "column" => "sex",            "convert" => "n" ),
100                                 array(  "column" => "job",            "convert" => "n" ),
101                                 array(  "column" => "birth",        "convert" => "n" ),
102                                 array(  "column" => "password",    "convert" => "a" ),
103                                 array(  "column" => "reminder",    "convert" => "n" ),
104                                 array(  "column" => "reminder_answer", "convert" => "aKV" ),
105                                 array(  "column" => "mailmaga_flg", "convert" => "n" ),
106                                 array(  "column" => "note",        "convert" => "aKV" ),
107                                 array(  "column" => "point",        "convert" => "n" ),
108                                 array(  "column" => "status",        "convert" => "n" )
109                                 );
110
111        //---- 登録除外用カラム配列
112        $arrRejectRegistColumn = array("year", "month", "day");
113
114        // 検索条件を保持
115        if ($_POST['mode'] == "edit_search") {
116            $arrSearch = $_POST;
117        }else{
118            $arrSearch = $_POST['search_data'];
119        }
120        if(is_array($arrSearch)){
121            foreach($arrSearch as $key => $val){
122                $arrSearchData[$key] = $val;
123            }
124        }
125
126        $this->arrSearchData= $arrSearchData;
127
128        //---- 顧客編集情報取得
129        if (($_POST["mode"] == "edit" || $_POST["mode"] == "edit_search") && is_numeric($_POST["edit_customer_id"])) {
130
131            //-- 顧客データ取得
132            $sql = "SELECT * FROM dtb_customer WHERE del_flg = 0 AND customer_id = ?";
133            $result = $this->objConn->getAll($sql, array($_POST["edit_customer_id"]));
134            $this->list_data = $result[0];
135
136            $birth = split(" ", $this->list_data["birth"]);
137            $birth = split("-",$birth[0]);
138
139            $this->list_data["year"] = $birth[0];
140            $this->list_data["month"] = isset($birth[1]) ? $birth[1] : "";
141            $this->list_data["day"] = isset($birth[2]) ? $birth[2] : "";
142
143            $this->list_data["password"] = DEFAULT_PASSWORD;
144            //DB登録のメールアドレスを渡す
145            $this->tpl_edit_email = $result[0]['email'];
146            //購入履歴情報の取得
147            $this->arrPurchaseHistory = $this->lfPurchaseHistory($_POST['edit_customer_id']);
148            // 支払い方法の取得
149            $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
150        }
151
152        //---- 顧客情報編集
153        if ( $_POST["mode"] != "edit" && $_POST["mode"] != "edit_search" && is_numeric($_POST["customer_id"])) {
154
155            //-- POSTデータの引き継ぎ
156            $this->arrForm = $_POST;
157            $this->arrForm['email'] = strtolower($this->arrForm['email']);        // emailはすべて小文字で処理
158
159            //-- 入力データの変換
160            $this->arrForm = $this->lfConvertParam($this->arrForm, $arrRegistColumn);
161            //-- 入力チェック
162            $this->arrErr = $this->lfErrorCheck($this->arrForm);
163
164            //-- 入力エラー発生 or リターン時
165            if ($this->arrErr || $_POST["mode"] == "return") {
166                foreach($this->arrForm as $key => $val) {
167                    $this->list_data[ $key ] = $val;
168                }
169                //購入履歴情報の取得
170                $this->arrPurchaseHistory = $this->lfPurchaseHistory($_POST['customer_id']);
171                // 支払い方法の取得
172                $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
173
174            } else {
175                //-- 確認
176                if ($_POST["mode"] == "confirm") {
177                    $this->tpl_mainpage = 'customer/edit_confirm.tpl';
178                    $passlen = strlen($this->arrForm['password']);
179                    $this->passlen = $this->lfPassLen($passlen);
180
181                }
182                //-- 編集
183                if($_POST["mode"] == "complete") {
184                    $this->tpl_mainpage = 'customer/edit_complete.tpl';
185
186                    // 現在の会員情報を取得する
187                    $arrCusSts = $this->objQuery->getOne("SELECT status FROM dtb_customer WHERE customer_id = ?", array($_POST["customer_id"]));
188
189                    // 会員情報が変更されている場合にはシークレット№も更新する。
190                    if ($arrCusSts != $_POST['status']){
191                        $secret = SC_Utils_Ex::sfGetUniqRandomId("r");
192                        $this->arrForm['secret_key'] = $secret;
193                        array_push($arrRegistColumn, array('column' => 'secret_key', 'convert' => 'n'));
194                    }
195                    //-- 編集登録
196                    $objDb->sfEditCustomerData($this->arrForm, $arrRegistColumn);
197                }
198            }
199        }
200
201        //---- ページ表示
202        $objView->assignobj($this);
203        $objView->display(MAIN_FRAME);
204    }
205
206    /**
207     * デストラクタ.
208     *
209     * @return void
210     */
211    function destroy() {
212        parent::destroy();
213    }
214
215
216    // 編集登録
217    function lfRegisDatat($array, $arrRegistColumn) {
218
219        foreach ($arrRegistColumn as $data) {
220            if($array[$data["column"]] != "") {
221                $arrRegist[$data["column"]] = $array[$data["column"]];
222            } else {
223                $arrRegist[$data["column"]] = NULL;
224            }
225        }
226        if (strlen($array["year"]) > 0) {
227            $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00";
228        }
229
230        //-- パスワードの更新がある場合は暗号化。(更新がない場合はUPDATE文を構成しない)
231        if ($array["password"] != DEFAULT_PASSWORD) {
232            $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC);
233        } else {
234            unset($arrRegist['password']);
235        }
236
237        $arrRegist["update_date"] = "Now()";
238
239        //-- 編集登録実行
240        $this->objConn->query("BEGIN");
241        $this->objQuery->Insert("dtb_customer", $arrRegist, "customer_id = '" .addslashes($array["customer_id"]). "'");
242
243        $this->objConn->query("COMMIT");
244    }
245
246
247    //---- 取得文字列の変換
248    function lfConvertParam($array, $arrRegistColumn) {
249        /*
250         *    文字列の変換
251         *    K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
252         *    C :  「全角ひら仮名」を「全角かた仮名」に変換
253         *    V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
254         *    n :  「全角」数字を「半角(ハンカク)」に変換
255         *  a :  全角英数字を半角英数字に変換する
256         */
257        // カラム名とコンバート情報
258        foreach ($arrRegistColumn as $data) {
259            $arrConvList[ $data["column"] ] = $data["convert"];
260        }
261        // 文字変換
262        foreach ($arrConvList as $key => $val) {
263            // POSTされてきた値のみ変換する。
264            if(strlen(($array[$key])) > 0) {
265                $array[$key] = mb_convert_kana($array[$key] ,$val);
266            }
267        }
268        return $array;
269    }
270
271    //---- 入力エラーチェック
272    function lfErrorCheck($array) {
273
274        $objErr = new SC_CheckError($array);
275
276        $objErr->doFunc(array("会員状態", 'status'), array("EXIST_CHECK"));
277        $objErr->doFunc(array("お名前(姓)", 'name01', STEXT_LEN), array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
278        $objErr->doFunc(array("お名前(名)", 'name02', STEXT_LEN), array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
279        $objErr->doFunc(array("フリガナ(姓)", 'kana01', STEXT_LEN), array("EXIST_CHECK", "MAX_LENGTH_CHECK", "KANA_CHECK"));
280        $objErr->doFunc(array("フリガナ(名)", 'kana02', STEXT_LEN), array("EXIST_CHECK", "MAX_LENGTH_CHECK", "KANA_CHECK"));
281        $objErr->doFunc(array("郵便番号1", "zip01", ZIP01_LEN ) ,array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
282        $objErr->doFunc(array("郵便番号2", "zip02", ZIP02_LEN ) ,array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
283        $objErr->doFunc(array("郵便番号", "zip01", "zip02"), array("ALL_EXIST_CHECK"));
284        $objErr->doFunc(array("都道府県", 'pref'), array("SELECT_CHECK","NUM_CHECK"));
285        $objErr->doFunc(array("ご住所(1)", "addr01", MTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
286        $objErr->doFunc(array("ご住所(2)", "addr02", MTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
287        $objErr->doFunc(array('メールアドレス', "email", MTEXT_LEN) ,array("EXIST_CHECK", "NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
288
289        //現会員の判定 → 現会員もしくは仮登録中は、メアド一意が前提になってるので同じメアドで登録不可
290        if (strlen($array["email"]) > 0) {
291            $array['email'] = strtolower($array['email']);
292            $sql = "SELECT customer_id FROM dtb_customer WHERE (email ILIKE ? escape '#' OR email_mobile ILIKE ? escape '#') AND (status = 1 OR status = 2) AND del_flg = 0 AND customer_id <> ?";
293            $checkMail = ereg_replace( "_", "#_", $array["email"]);
294            $result = $this->objConn->getAll($sql, array($checkMail, $checkMail, $array["customer_id"]));
295            if (count($result) > 0) {
296                $objErr->arrErr["email"] .= "※ すでに登録されているメールアドレスです。";
297            }
298        }
299
300        $objErr->doFunc(array('メールアドレス(モバイル)', "email_mobile", MTEXT_LEN) ,array("EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
301        //現会員の判定 → 現会員もしくは仮登録中は、メアド一意が前提になってるので同じメアドで登録不可
302        if (strlen($array["email_mobile"]) > 0) {
303            $array['email_mobile'] = strtolower($array['email_mobile']);
304            $sql = "SELECT customer_id FROM dtb_customer WHERE (email ILIKE ? escape '#' OR email_mobile ILIKE ? escape '#') AND (status = 1 OR status = 2) AND del_flg = 0 AND customer_id <> ?";
305            $checkMail = ereg_replace( "_", "#_", $array["email_mobile"]);
306            $result = $this->objConn->getAll($sql, array($checkMail, $checkMail, $array["customer_id"]));
307            if (count($result) > 0) {
308                $objErr->arrErr["email_mobile"] .= "※ すでに登録されているメールアドレス(モバイル)です。";
309            }
310        }
311
312
313        $objErr->doFunc(array("お電話番号1", 'tel01'), array("EXIST_CHECK"));
314        $objErr->doFunc(array("お電話番号2", 'tel02'), array("EXIST_CHECK"));
315        $objErr->doFunc(array("お電話番号3", 'tel03'), array("EXIST_CHECK"));
316        $objErr->doFunc(array("お電話番号", "tel01", "tel02", "tel03", TEL_LEN) ,array("TEL_CHECK"));
317        $objErr->doFunc(array("FAX番号", "fax01", "fax02", "fax03", TEL_LEN) ,array("TEL_CHECK"));
318        $objErr->doFunc(array("ご性別", "sex") ,array("SELECT_CHECK", "NUM_CHECK"));
319        $objErr->doFunc(array("ご職業", "job") ,array("NUM_CHECK"));
320        if ($array["password"] != DEFAULT_PASSWORD) {
321            $objErr->doFunc(array("パスワード", 'password', PASSWORD_LEN1, PASSWORD_LEN2), array("EXIST_CHECK", "ALNUM_CHECK", "NUM_RANGE_CHECK"));
322        }
323        $objErr->doFunc(array("パスワードを忘れたときのヒント 質問", "reminder") ,array("SELECT_CHECK", "NUM_CHECK"));
324        $objErr->doFunc(array("パスワードを忘れたときのヒント 答え", "reminder_answer", STEXT_LEN) ,array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
325        $objErr->doFunc(array("メールマガジン", "mailmaga_flg") ,array("SELECT_CHECK", "NUM_CHECK"));
326        $objErr->doFunc(array("生年月日", "year", "month", "day"), array("CHECK_DATE"));
327        $objErr->doFunc(array("SHOP用メモ", 'note', LTEXT_LEN), array("MAX_LENGTH_CHECK"));
328        $objErr->doFunc(array("所持ポイント", "point", TEL_LEN) ,array("MAX_LENGTH_CHECK", "NUM_CHECK"));
329        return $objErr->arrErr;
330
331    }
332
333    //購入履歴情報の取得
334    function lfPurchaseHistory($customer_id){
335        $this->tpl_pageno = $_POST['search_pageno'];
336        $this->edit_customer_id = $customer_id;
337
338        // ページ送りの処理
339        $page_max = SEARCH_PMAX;
340        //購入履歴の件数取得
341        $this->tpl_linemax = $this->objQuery->count("dtb_order","customer_id=? AND del_flg = 0 ", array($customer_id));
342        $linemax = $this->tpl_linemax;
343
344        // ページ送りの取得
345        $objNavi = new SC_PageNavi($_POST['search_pageno'], $linemax, $page_max, "fnNaviSearchPage2", NAVI_PMAX);
346        $this->arrPagenavi = $objNavi->arrPagenavi;
347        $this->arrPagenavi['mode'] = 'edit';
348        $startno = $objNavi->start_row;
349
350        // 取得範囲の指定(開始行番号、行数のセット)
351        $this->objQuery->setLimitOffset($page_max, $startno);
352        // 表示順序
353        $order = "order_id DESC";
354        $this->objQuery->setOrder($order);
355        //購入履歴情報の取得
356        $arrPurchaseHistory = $this->objQuery->select("*", "dtb_order", "customer_id=? AND del_flg = 0 ", array($customer_id));
357
358        return $arrPurchaseHistory;
359    }
360
361    //確認ページ用パスワード表示用
362    function lfPassLen($passlen){
363        $ret = "";
364        for ($i=0;$i<$passlen;true){
365            $ret.="*";
366            $i++;
367        }
368        return $ret;
369    }
370}
371?>
Note: See TracBrowser for help on using the repository browser.