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

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