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

Revision 18820, 17.3 KB checked in by nanasess, 14 years ago (diff)

#781(規格のデータベースを木構造に)

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