source: branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage_DeliveryAddr.php @ 19862

Revision 19862, 10.3 KB checked in by nanasess, 13 years ago (diff)

#843(複数配送先の指定)

  • 会員購入時のデータの保存まで対応
  • TODO 非会員購入/数量変更のカート反映/戻るボタン/購入確認画面/Myページ/管理画面
  • 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/LC_Page.php");
26
27/**
28 * お届け先追加 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Mypage_DeliveryAddr 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_title = "お届け先の追加・変更";
47        $masterData = new SC_DB_MasterData_Ex();
48        $this->arrPref= $masterData->getMasterData('mtb_pref');
49        $this->httpCacheControl('nocache');
50    }
51
52    /**
53     * Page のプロセス.
54     *
55     * @return void
56     */
57    function process() {
58        parent::process();
59        $this->action();
60        $this->sendResponse();
61    }
62
63    /**
64     * Page のAction.
65     *
66     * @return void
67     */
68    function action() {
69        //$objView = new SC_SiteView(false);
70        $objQuery = new SC_Query();
71        $objCustomer = new SC_Customer();
72        $ParentPage = MYPAGE_DELIVADDR_URL_PATH;
73
74        // GETでページを指定されている場合には指定ページに戻す
75        if (isset($_GET['page'])) {
76            $ParentPage = htmlspecialchars($_GET['page'],ENT_QUOTES);
77        }else if(isset($_POST['ParentPage'])) {
78            $ParentPage = htmlspecialchars($_POST['ParentPage'],ENT_QUOTES);
79        }
80        $this->ParentPage = $ParentPage;
81       
82        // ログイン判定 及び 退会判定
83        if (!$objCustomer->isLoginSuccess()){
84            $this->tpl_onload = "fnUpdateParent('". $this->getLocation($_POST['ParentPage']) ."'); window.close();";
85        }
86         
87        //退会判定に統合
88        ////ログイン判定
89        // if (!$objCustomer->isLoginSuccess()){
90        //     SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
91        //}
92
93        if (!isset($_POST['mode'])) $_POST['mode'] = "";
94        if (!isset($_GET['other_deliv_id'])) $_GET['other_deliv_id'] = "";
95
96        if ($_POST['mode'] == ""){
97            $_SESSION['other_deliv_id'] = $_GET['other_deliv_id'];
98        }
99
100        if ($_GET['other_deliv_id'] != ""){
101            //不正アクセス判定
102            $flag = $objQuery->count("dtb_other_deliv", "customer_id=? AND other_deliv_id=?", array($objCustomer->getValue("customer_id"), $_SESSION['other_deliv_id']));
103            if (!$objCustomer->isLoginSuccess() || $flag == 0){
104                SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
105            }
106        }
107
108        //別のお届け先DB登録用カラム配列
109        $arrRegistColumn = array(
110                                 array("column" => "name01",    "convert" => "aKV"),
111                                 array("column" => "name02",    "convert" => "aKV"),
112                                 array("column" => "kana01",    "convert" => "CKV"),
113                                 array("column" => "kana02",    "convert" => "CKV"),
114                                 array("column" => "zip01",     "convert" => "n"),
115                                 array("column" => "zip02",     "convert" => "n"),
116                                 array("column" => "pref",      "convert" => "n"),
117                                 array("column" => "addr01",    "convert" => "aKV"),
118                                 array("column" => "addr02",    "convert" => "aKV"),
119                                 array("column" => "tel01",     "convert" => "n"),
120                                 array("column" => "tel02",     "convert" => "n"),
121                                 array("column" => "tel03",     "convert" => "n"),
122                                 );
123
124
125        if ($_GET['other_deliv_id'] != ""){
126            //別のお届け先情報取得
127            $arrOtherDeliv = $objQuery->select("*", "dtb_other_deliv", "other_deliv_id=? ", array($_SESSION['other_deliv_id']));
128            $this->arrForm = $arrOtherDeliv[0];
129        }
130
131        switch ($_POST['mode']) {
132            case 'edit':
133                $_POST = $this->lfConvertParam($_POST,$arrRegistColumn);
134                $this->arrErr = $this->lfErrorCheck($_POST);
135                if ($this->arrErr){
136                    foreach ($_POST as $key => $val){
137                        if ($val != "") $this->arrForm[$key] = $val;
138                    }
139                } else {
140                    $validUrl = array(MYPAGE_DELIVADDR_URL_PATH,
141                                      DELIV_URL_PATH,
142                                      MULTIPLE_URL_PATH);
143                    if (in_array($_POST['ParentPage'], $validUrl)) {
144                        $this->tpl_onload = "fnUpdateParent('". $this->getLocation($_POST['ParentPage']) ."'); window.close();";
145                    } else {
146                        SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
147                    }
148                   
149                    $this->lfRegistData($_POST, $arrRegistColumn, $objCustomer);
150                }
151                break;
152        }
153        $this->setTemplate('mypage/delivery_addr.tpl');
154    }
155
156    /**
157     * デストラクタ.
158     *
159     * @return void
160     */
161    function destroy() {
162        parent::destroy();
163    }
164
165    /* エラーチェック */
166    function lfErrorCheck() {
167        $objErr = new SC_CheckError();
168
169        $objErr->doFunc(array("お名前(姓)", 'name01', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
170        $objErr->doFunc(array("お名前(名)", 'name02', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK", "MAX_LENGTH_CHECK"));
171        $objErr->doFunc(array("お名前(フリガナ・姓)", 'kana01', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK", "MAX_LENGTH_CHECK", "KANA_CHECK"));
172        $objErr->doFunc(array("お名前(フリガナ・名)", 'kana02', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK", "MAX_LENGTH_CHECK", "KANA_CHECK"));
173        $objErr->doFunc(array("郵便番号1", "zip01", ZIP01_LEN ) ,array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
174        $objErr->doFunc(array("郵便番号2", "zip02", ZIP02_LEN ) ,array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
175        $objErr->doFunc(array("郵便番号", "zip01", "zip02"), array("ALL_EXIST_CHECK"));
176        $objErr->doFunc(array("都道府県", 'pref'), array("SELECT_CHECK","NUM_CHECK"));
177        $objErr->doFunc(array("住所(1)", "addr01", MTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
178        $objErr->doFunc(array("住所(2)", "addr02", MTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
179        $objErr->doFunc(array("電話番号1", 'tel01'), array("EXIST_CHECK","NUM_CHECK"));
180        $objErr->doFunc(array("電話番号2", 'tel02'), array("EXIST_CHECK","NUM_CHECK"));
181        $objErr->doFunc(array("電話番号3", 'tel03'), array("EXIST_CHECK","NUM_CHECK"));
182        $objErr->doFunc(array("電話番号", "tel01", "tel02", "tel03") ,array("TEL_CHECK"));
183        return $objErr->arrErr;
184
185    }
186
187    /* 登録実行 */
188    function lfRegistData($array, $arrRegistColumn, &$objCustomer) {
189        $objQuery = new SC_Query();
190        foreach ($arrRegistColumn as $data) {
191            $arrRegist[ $data["column"] ] = $array[ $data["column"] ];
192        }
193
194        $arrRegist['customer_id'] = $objCustomer->getvalue('customer_id');
195
196        // 追加
197        if (strlen($_POST['other_deliv_id'] == 0)) {
198            // 別のお届け先登録数の取得
199            $deliv_count = $objQuery->count("dtb_other_deliv", "customer_id=?", array($objCustomer->getValue('customer_id')));
200            // 別のお届け先最大登録数に達している場合、エラー
201            if ($deliv_count >= DELIV_ADDR_MAX) {
202                SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", false, '別のお届け先最大登録数に達しています。');
203            }
204           
205            // 実行
206            $arrRegist['other_deliv_id'] = $objQuery->nextVal('dtb_other_deliv_other_deliv_id');
207            $objQuery->insert("dtb_other_deliv", $arrRegist);
208           
209        // 変更
210        } else {
211            $deliv_count = $objQuery->count("dtb_other_deliv","customer_id=? and other_deliv_id = ?" ,array($objCustomer->getValue('customer_id'), $_POST['other_deliv_id']));
212            if ($deliv_count != 1) {
213                SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", false, '一致する別のお届け先がありません。');
214            }
215           
216            // 実行
217            $objQuery->update("dtb_other_deliv", $arrRegist,
218                                  "other_deliv_id = "
219                                  . SC_Utils_Ex::sfQuoteSmart($array["other_deliv_id"]));
220        }
221    }
222
223    //---- 取得文字列の変換
224    function lfConvertParam($array, $arrRegistColumn) {
225        /*
226         *  文字列の変換
227         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
228         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
229         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
230         *  n :  「全角」数字を「半角(ハンカク)」に変換
231         *  a :  全角英数字を半角英数字に変換する
232         */
233        // カラム名とコンバート情報
234        foreach ($arrRegistColumn as $data) {
235            $arrConvList[ $data["column"] ] = $data["convert"];
236        }
237
238        // 文字変換
239        foreach ($arrConvList as $key => $val) {
240            // POSTされてきた値のみ変換する。
241            if(strlen(($array[$key])) > 0) {
242                $array[$key] = mb_convert_kana($array[$key] ,$val);
243            }
244        }
245        return $array;
246    }
247}
248?>
Note: See TracBrowser for help on using the repository browser.