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

Revision 20116, 11.2 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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        $objQuery = new SC_Query();
70        $objCustomer = new SC_Customer();
71        $ParentPage = MYPAGE_DELIVADDR_URLPATH;
72
73        // GETでページを指定されている場合には指定ページに戻す
74        if (isset($_GET['page'])) {
75            $ParentPage = htmlspecialchars($_GET['page'],ENT_QUOTES);
76        }else if(isset($_POST['ParentPage'])) {
77            $ParentPage = htmlspecialchars($_POST['ParentPage'],ENT_QUOTES);
78        }
79        $this->ParentPage = $ParentPage;
80
81        /*
82         * ログイン判定 及び 退会判定
83         * 未ログインでも, 複数配送設定ページからのアクセスの場合は表示する
84         */
85        if (!$objCustomer->isLoginSuccess(true) && $ParentPage != MULTIPLE_URLPATH){
86            $this->tpl_onload = "fnUpdateParent('". $this->getLocation($_POST['ParentPage']) ."'); window.close();";
87        }
88
89        if (!isset($_GET['other_deliv_id'])) $_GET['other_deliv_id'] = "";
90
91        //TODO 要リファクタリング(MODE if利用)
92        if ($this->getMode() == null){
93            $_SESSION['other_deliv_id'] = $_GET['other_deliv_id'];
94        }
95
96        if ($_GET['other_deliv_id'] != ""){
97            //不正アクセス判定
98            $flag = $objQuery->count("dtb_other_deliv", "customer_id=? AND other_deliv_id=?", array($objCustomer->getValue("customer_id"), $_SESSION['other_deliv_id']));
99            if (!$objCustomer->isLoginSuccess(true) || $flag == 0){
100                SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
101            }
102        }
103
104        //別のお届け先DB登録用カラム配列
105        $arrRegistColumn = array(
106                                 array("column" => "name01",    "convert" => "aKV"),
107                                 array("column" => "name02",    "convert" => "aKV"),
108                                 array("column" => "kana01",    "convert" => "CKV"),
109                                 array("column" => "kana02",    "convert" => "CKV"),
110                                 array("column" => "zip01",     "convert" => "n"),
111                                 array("column" => "zip02",     "convert" => "n"),
112                                 array("column" => "pref",      "convert" => "n"),
113                                 array("column" => "addr01",    "convert" => "aKV"),
114                                 array("column" => "addr02",    "convert" => "aKV"),
115                                 array("column" => "tel01",     "convert" => "n"),
116                                 array("column" => "tel02",     "convert" => "n"),
117                                 array("column" => "tel03",     "convert" => "n"),
118                                 );
119
120
121        if ($_GET['other_deliv_id'] != ""){
122            //別のお届け先情報取得
123            $arrOtherDeliv = $objQuery->select("*", "dtb_other_deliv", "other_deliv_id=? ", array($_SESSION['other_deliv_id']));
124            $this->arrForm = $arrOtherDeliv[0];
125        }
126
127        switch ($this->getMode()) {
128            case 'edit':
129                $_POST = $this->lfConvertParam($_POST,$arrRegistColumn);
130                $this->arrErr = $this->lfErrorCheck($_POST);
131                if ($this->arrErr){
132                    foreach ($_POST as $key => $val){
133                        if ($val != "") $this->arrForm[$key] = $val;
134                    }
135                } else {
136                    $validUrl = array(MYPAGE_DELIVADDR_URLPATH,
137                                      DELIV_URLPATH,
138                                      MULTIPLE_URLPATH);
139                    if (in_array($_POST['ParentPage'], $validUrl)) {
140                        $this->tpl_onload = "fnUpdateParent('". $this->getLocation($_POST['ParentPage']) ."'); window.close();";
141                    } else {
142                        SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
143                    }
144
145                    if ($objCustomer->isLoginSuccess(true)) {
146                        $this->lfRegistData($_POST, $arrRegistColumn, $objCustomer);
147                    } else {
148                        $this->lfRegistDataNonMember($_POST, $arrRegistColumn);
149                    }
150
151                    if(Net_UserAgent_Mobile::isMobile() === true) {
152                        // モバイルの場合、元のページに遷移
153                        SC_Response_Ex::sendRedirect($this->getLocation($_POST['ParentPage']));
154                        exit;
155                    }
156                }
157                break;
158        }
159        if(Net_UserAgent_Mobile::isMobile() === true) {
160            $this->tpl_mainpage = 'mypage/delivery_addr.tpl';
161        } else {
162            $this->setTemplate('mypage/delivery_addr.tpl');
163        }
164    }
165
166    /**
167     * デストラクタ.
168     *
169     * @return void
170     */
171    function destroy() {
172        parent::destroy();
173    }
174
175    /* エラーチェック */
176    function lfErrorCheck() {
177        $objErr = new SC_CheckError();
178
179        $objErr->doFunc(array("お名前(姓)", 'name01', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
180        $objErr->doFunc(array("お名前(名)", 'name02', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK", "MAX_LENGTH_CHECK"));
181        $objErr->doFunc(array("お名前(フリガナ・姓)", 'kana01', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK", "MAX_LENGTH_CHECK", "KANA_CHECK"));
182        $objErr->doFunc(array("お名前(フリガナ・名)", 'kana02', STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK", "MAX_LENGTH_CHECK", "KANA_CHECK"));
183        $objErr->doFunc(array("郵便番号1", "zip01", ZIP01_LEN ) ,array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
184        $objErr->doFunc(array("郵便番号2", "zip02", ZIP02_LEN ) ,array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
185        $objErr->doFunc(array("郵便番号", "zip01", "zip02"), array("ALL_EXIST_CHECK"));
186        $objErr->doFunc(array("都道府県", 'pref'), array("SELECT_CHECK","NUM_CHECK"));
187        $objErr->doFunc(array("住所(1)", "addr01", MTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
188        $objErr->doFunc(array("住所(2)", "addr02", MTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
189        $objErr->doFunc(array("電話番号1", 'tel01'), array("EXIST_CHECK","NUM_CHECK"));
190        $objErr->doFunc(array("電話番号2", 'tel02'), array("EXIST_CHECK","NUM_CHECK"));
191        $objErr->doFunc(array("電話番号3", 'tel03'), array("EXIST_CHECK","NUM_CHECK"));
192        $objErr->doFunc(array("電話番号", "tel01", "tel02", "tel03") ,array("TEL_CHECK"));
193        return $objErr->arrErr;
194
195    }
196
197    /* 登録実行 */
198    function lfRegistData($array, $arrRegistColumn, &$objCustomer) {
199        $objQuery = new SC_Query();
200        foreach ($arrRegistColumn as $data) {
201            $arrRegist[ $data["column"] ] = $array[ $data["column"] ];
202        }
203
204        $arrRegist['customer_id'] = $objCustomer->getvalue('customer_id');
205
206        // 追加
207        if (strlen($_POST['other_deliv_id'] == 0)) {
208            // 別のお届け先登録数の取得
209            $deliv_count = $objQuery->count("dtb_other_deliv", "customer_id=?", array($objCustomer->getValue('customer_id')));
210            // 別のお届け先最大登録数に達している場合、エラー
211            if ($deliv_count >= DELIV_ADDR_MAX) {
212                SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", false, '別のお届け先最大登録数に達しています。');
213            }
214
215            // 実行
216            $arrRegist['other_deliv_id'] = $objQuery->nextVal('dtb_other_deliv_other_deliv_id');
217            $objQuery->insert("dtb_other_deliv", $arrRegist);
218
219        // 変更
220        } else {
221            $deliv_count = $objQuery->count("dtb_other_deliv","customer_id=? and other_deliv_id = ?" ,array($objCustomer->getValue('customer_id'), $_POST['other_deliv_id']));
222            if ($deliv_count != 1) {
223                SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", false, '一致する別のお届け先がありません。');
224            }
225
226            // 実行
227            $objQuery->update("dtb_other_deliv", $arrRegist,
228                                  "other_deliv_id = "
229                                  . SC_Utils_Ex::sfQuoteSmart($array["other_deliv_id"]));
230        }
231    }
232
233    function lfRegistDataNonMember($array, $arrRegistColumn) {
234        foreach ($arrRegistColumn as $data) {
235            $arrRegist['shipping_' . $data["column"] ] = $array[ $data["column"] ];
236        }
237        if (count($shipping) >= DELIV_ADDR_MAX) {
238            SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", false, '別のお届け先最大登録数に達しています。');
239        } else {
240            $_SESSION['shipping'][] = $arrRegist;
241        }
242    }
243
244    //---- 取得文字列の変換
245    function lfConvertParam($array, $arrRegistColumn) {
246        /*
247         *  文字列の変換
248         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
249         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
250         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
251         *  n :  「全角」数字を「半角(ハンカク)」に変換
252         *  a :  全角英数字を半角英数字に変換する
253         */
254        // カラム名とコンバート情報
255        foreach ($arrRegistColumn as $data) {
256            $arrConvList[ $data["column"] ] = $data["convert"];
257        }
258
259        // 文字変換
260        foreach ($arrConvList as $key => $val) {
261            // POSTされてきた値のみ変換する。
262            if(strlen(($array[$key])) > 0) {
263                $array[$key] = mb_convert_kana($array[$key] ,$val);
264            }
265        }
266        return $array;
267    }
268}
269?>
Note: See TracBrowser for help on using the repository browser.