source: branches/version-2_5-dev/data/class/pages/shopping/LC_Page_Shopping_Deliv.php @ 19868

Revision 19868, 22.5 KB checked in by nanasess, 13 years ago (diff)

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

  • 購入確認画面を修正
  • 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:LC_Page_Shopping_Deliv.php 15532 2007-08-31 14:39:46Z nanasess $
33 */
34class LC_Page_Shopping_Deliv extends LC_Page {
35
36    // {{{ properties
37
38    /** フォームパラメータの配列 */
39    var $objFormParam;
40
41    /** ログインフォームパラメータ配列 */
42    var $objLoginFormParam;
43
44    // }}}
45    // {{{ functions
46
47    /**
48     * Page を初期化する.
49     *
50     * @return void
51     */
52    function init() {
53        parent::init();
54        $masterData = new SC_DB_MasterData();
55        $this->arrPref = $masterData->getMasterData('mtb_pref');
56        $this->tpl_title = "お届け先の指定";
57        $this->httpCacheControl('nocache');
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        $objView = new SC_SiteView();
77        $objSiteSess = new SC_SiteSession();
78        $objCartSess = new SC_CartSession();
79        $objCustomer = new SC_Customer();
80        $objDb = new SC_Helper_DB_Ex();
81        $objPurchase = new SC_Helper_Purchase_Ex();
82        $objQuery = SC_Query::getSingletonInstance();;
83        // クッキー管理クラス
84        $objCookie = new SC_Cookie(COOKIE_EXPIRE);
85        // パラメータ管理クラス
86        $this->objFormParam = new SC_FormParam();
87        // パラメータ情報の初期化
88        $this->lfInitParam();
89        // POST値の取得
90        $this->objFormParam->setParam($_POST);
91
92        $this->objLoginFormParam = new SC_FormParam();  // ログインフォーム用
93        $this->lfInitLoginFormParam();
94        //パスワード・Eメールにある空白をトリム
95        $this->lfConvertEmail($_POST["login_email"]);
96        $this->lfConvertLoginPass($_POST["login_pass"]);
97        $this->objLoginFormParam->setParam($_POST);     // POST値の取得
98
99        // ユーザユニークIDの取得と購入状態の正当性をチェック
100        $uniqid = $objSiteSess->getUniqId();
101        $objPurchase->verifyChangeCart($uniqid, $objCartSess);
102
103        $this->tpl_uniqid = $uniqid;
104
105        $this->cartKey = $objCartSess->getKey();
106
107        if (!isset($_POST['mode'])) $_POST['mode'] = "";
108
109        // ログインチェック
110        if($_POST['mode'] != 'login' && !$objCustomer->isLoginSuccess()) {
111            // 不正アクセスとみなす
112            SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
113        }
114
115        switch($_POST['mode']) {
116        case 'login':
117            $this->objLoginFormParam->toLower('login_email');
118            $this->arrErr = $this->objLoginFormParam->checkError();
119            $arrForm =  $this->objLoginFormParam->getHashArray();
120            // クッキー保存判定
121            if($arrForm['login_memory'] == "1" && $arrForm['login_email'] != "") {
122                $objCookie->setCookie('login_email', $_POST['login_email']);
123            } else {
124                $objCookie->setCookie('login_email', '');
125            }
126
127            if(count($this->arrErr) > 0) {
128                SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
129            }
130            // ログイン判定
131            if(!$objCustomer->getCustomerDataFromEmailPass($arrForm['login_pass'], $arrForm['login_email'])) {
132                // 仮登録の判定
133
134                $where = "email = ? AND status = 1 AND del_flg = 0";
135                $ret = $objQuery->count("dtb_customer", $where, array($arrForm['login_email']));
136
137                if($ret > 0) {
138                    SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
139                } else {
140                    SC_Utils_Ex::sfDispSiteError(SITE_LOGIN_ERROR);
141                }
142            }
143            //ダウンロード商品判定
144            if($this->cartKey == PRODUCT_TYPE_DOWNLOAD){
145                // 会員情報の住所を受注一時テーブルに書き込む
146                $objPurchase->copyFromCustomer($sqlval, $objCustomer, 'shipping');
147                $sqlval['deliv_id'] = $objPurchase->getDeliv($this->cartKey);
148                $objPurchase->saveShippingTemp($sqlval);
149                $objPurchase->saveOrderTemp($uniqid, $sqlval, $objCustomer);
150                // 正常に登録されたことを記録しておく
151                $objSiteSess->setRegistFlag();
152                // ダウンロード商品有りの場合は、支払方法画面に転送
153                SC_Response_Ex::sendRedirect('payment.php');
154                exit;
155            }
156            break;
157        // 削除
158        case 'delete':
159            if (SC_Utils_Ex::sfIsInt($_POST['other_deliv_id'])) {
160                $where = "other_deliv_id = ?";
161                $arrRet = $objQuery->delete("dtb_other_deliv", $where, array($_POST['other_deliv_id']));
162                $this->objFormParam->setValue('select_addr_id', '');
163            }
164            break;
165        // 会員登録住所に送る
166        case 'customer_addr':
167            $sqlval = array();
168            // 会員登録住所がチェックされている場合
169            if ($_POST['deliv_check'] == '-1') {
170                // 会員情報の住所を受注一時テーブルに書き込む
171                $objPurchase->copyFromCustomer($sqlval, $objCustomer, 'shipping');
172                $sqlval['deliv_id'] = $objPurchase->getDeliv($this->cartKey);
173                $objPurchase->saveShippingTemp($sqlval);
174                $objPurchase->saveOrderTemp($uniqid, $sqlval, $objCustomer);
175
176                // 正常に登録されたことを記録しておく
177                $objSiteSess->setRegistFlag();
178                // お支払い方法選択ページへ移動
179                SC_Response_Ex::sendRedirect(SHOPPING_PAYMENT_URL_PATH);
180                exit;
181            // 別のお届け先がチェックされている場合
182            } elseif($_POST['deliv_check'] >= 1) {
183                if (SC_Utils_Ex::sfIsInt($_POST['deliv_check'])) {
184                    $deliv_count = $objQuery->count("dtb_other_deliv","customer_id=? and other_deliv_id = ?" ,array($objCustomer->getValue('customer_id'), $_POST['deliv_check']));
185                    if ($deliv_count != 1) {
186                        SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
187                    }
188
189                    $otherDeliv = $objQuery->select("*", "dtb_other_deliv",
190                                                    "other_deliv_id = ?",
191                                                    array($other_deliv_id));
192                    $sqlval = $otherDeliv[0];
193                    $sqlval['deliv_id'] = $objPurchase->getDeliv($this->cartKey);
194                    $objPurchase->saveShippingTemp($sqlval, $other_deliv_id);
195                    $objPurchase->saveOrderTemp($uniqid, $sqlval, $objCustomer);
196
197                    // 正常に登録されたことを記録しておく
198                    $objSiteSess->setRegistFlag();
199                    // お支払い方法選択ページへ移動
200                    SC_Response_Ex::sendRedirect(SHOPPING_PAYMENT_URL_PATH);
201                    exit;
202                }
203            }else{
204                // エラーを返す
205                $arrErr['deli'] = '※ お届け先を選択してください。';
206            }
207            break;
208        // 前のページに戻る
209        case 'return':
210            // 確認ページへ移動
211            SC_Response_Ex::sendRedirect(CART_URL_PATH);
212            exit;
213            break;
214        // お届け先複数指定
215        case 'multiple':
216            SC_Response_Ex::sendRedirect('multiple.php');
217            exit;
218            break;
219
220        default:
221            //$objPurchase->unsetShippingTemp();
222            $arrOrderTemp = $objPurchase->getOrderTemp($uniqid);
223            if (empty($arrOrderTemp)) $arrOrderTemp = array("");
224            $this->objFormParam->setParam($arrOrderTemp);
225            break;
226        }
227
228        // 登録済み住所を取得
229        $this->arrAddr = $objCustomer->getCustomerAddress($_SESSION['customer']['customer_id']);
230        // 入力値の取得
231        if (!isset($arrErr)) $arrErr = array();
232        $this->arrForm = $this->objFormParam->getFormParamList();
233        $this->arrErr = $arrErr;
234    }
235
236    /**
237     * モバイルページを初期化する.
238     *
239     * @return void
240     */
241    function mobileInit() {
242        $this->init();
243    }
244
245    /**
246     * Page のプロセス(モバイル).
247     *
248     * @return void
249     */
250    function mobileProcess() {
251        $this->mobileAction();
252        $this->sendResponse();
253    }
254
255    /**
256     * Page のプロセス(モバイル).
257     *
258     * @return void
259     */
260    function mobileAction() {
261        $objView = new SC_MobileView();
262        $objSiteSess = new SC_SiteSession();
263        $objCartSess = new SC_CartSession();
264        $objCustomer = new SC_Customer();
265        $objDb = new SC_Helper_DB_Ex();
266        // クッキー管理クラス
267        $objCookie = new SC_Cookie(COOKIE_EXPIRE);
268        // パラメータ管理クラス
269        $this->objFormParam = new SC_FormParam();
270        // パラメータ情報の初期化
271        $this->lfInitParam();
272        // POST値の取得
273        $this->lfConvertEmail($_POST["login_email"]);
274        $this->lfConvertLoginPass($_POST["login_pass"]);
275
276        $this->objFormParam->setParam($_POST);
277
278        $this->objLoginFormParam = new SC_FormParam();  // ログインフォーム用
279        $this->lfInitLoginFormParam();                      // 初期設定
280        $this->objLoginFormParam->setParam($_POST);     // POST値の取得
281
282        // ユーザユニークIDの取得と購入状態の正当性をチェック
283        $uniqid = SC_Utils_Ex::sfCheckNormalAccess($objSiteSess, $objCartSess);
284        $this->tpl_uniqid = $uniqid;
285
286        //ダウンロード商品判定
287        $this->cartdown = $objDb->chkCartDown($objCartSess);
288
289        if (!isset($_POST['mode'])) $_POST['mode'] = "";
290
291        // ログインチェック
292        if($_POST['mode'] != 'login' && !$objCustomer->isLoginSuccess(true)) {
293            // 不正アクセスとみなす
294            SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
295        }
296
297        switch($_POST['mode']) {
298        case 'login':
299            $this->objLoginFormParam->toLower('login_email');
300            $this->arrErr = $this->objLoginFormParam->checkError();
301            $arrForm =  $this->objLoginFormParam->getHashArray();
302            // クッキー保存判定
303            if($arrForm['login_memory'] == "1" && $arrForm['login_email'] != "") {
304                $objCookie->setCookie('login_email', $_POST['login_email']);
305            } else {
306                $objCookie->setCookie('login_email', '');
307            }
308
309            if(count($this->arrErr) == 0) {
310                // ログイン判定
311                if(!$objCustomer->getCustomerDataFromMobilePhoneIdPass($arrForm['login_pass']) &&
312                   !$objCustomer->getCustomerDataFromEmailPass($arrForm['login_pass'], $arrForm['login_email'], true)) {
313                    // 仮登録の判定
314                    $objQuery = new SC_Query;
315                    $where = "(email = ? OR email_mobile = ?) AND status = 1 AND del_flg = 0";
316                    $ret = $objQuery->count("dtb_customer", $where, array($arrForm['login_email'], $arrForm['login_email']));
317
318                    if($ret > 0) {
319                        SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
320                    } else {
321                        SC_Utils_Ex::sfDispSiteError(SITE_LOGIN_ERROR);
322                    }
323                }
324                //ダウンロード商品判定
325                if($this->cartdown==2){
326                    // 会員情報の住所を受注一時テーブルに書き込む
327                    $objDb->sfRegistDelivData($uniqid, $objCustomer);
328                    // 正常に登録されたことを記録しておく
329                    $objSiteSess->setRegistFlag();
330                    // ダウンロード商品有りの場合は、支払方法画面に転送
331                    $this->objDisplay->redirect($this->getLocation(MOBILE_SHOPPING_PAYMENT_URL_PATH), array());
332                    exit;
333                }
334            } else {
335                // ログインページに戻る
336                $this->objDisplay->redirect($this->getLocation(MOBILE_SHOPPING_URL));
337                exit;
338            }
339
340            // ログインが成功した場合は携帯端末IDを保存する。
341            $objCustomer->updateMobilePhoneId();
342
343            /*
344             * 携帯メールアドレスが登録されていない場合は,
345             * 携帯メールアドレス登録画面へ遷移
346             */
347            $objMobile = new SC_Helper_Mobile_Ex();
348            if (!$objMobile->gfIsMobileMailAddress($objCustomer->getValue('email'))) {
349                if (!$objCustomer->hasValue('email_mobile')) {
350                    $this->objDisplay->redirect($this->getLocation("../entry/email_mobile.php"));
351                    exit;
352                }
353            }
354            break;
355            // 削除
356        case 'delete':
357            if (SC_Utils_Ex::sfIsInt($_POST['other_deliv_id'])) {
358                $objQuery = new SC_Query();
359                $where = "other_deliv_id = ?";
360                $arrRet = $objQuery->delete("dtb_other_deliv", $where, array($_POST['other_deliv_id']));
361                $this->objFormParam->setValue('select_addr_id', '');
362            }
363            break;
364            // 会員登録住所に送る
365        case 'customer_addr':
366            // お届け先がチェックされている場合には更新処理を行う
367            if ($_POST['deli'] != "") {
368                // 会員情報の住所を受注一時テーブルに書き込む
369                $this->lfRegistDelivData($uniqid, $objCustomer);
370                // 正常に登録されたことを記録しておく
371                $objSiteSess->setRegistFlag();
372                // お支払い方法選択ページへ移動
373                $this->objDisplay->redirect($this->getLocation(MOBILE_SHOPPING_PAYMENT_URL_PATH));
374                exit;
375            }else{
376                // エラーを返す
377                $arrErr['deli'] = '※ お届け先を選択してください。';
378            }
379            break;
380
381            // 登録済みの別のお届け先に送る
382        case 'other_addr':
383            // お届け先がチェックされている場合には更新処理を行う
384            if ($_POST['deli'] != "") {
385                if (SC_Utils_Ex::sfIsInt($_POST['other_deliv_id'])) {
386                    $objQuery = new SC_Query();
387                    $deliv_count = $objQuery->count("dtb_other_deliv","customer_id=? and other_deliv_id = ?" ,array($objCustomer->getValue('customer_id'), $_POST['other_deliv_id']));
388                    if ($deliv_count != 1) {
389                        SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
390                    }
391                    // 登録済みの別のお届け先を受注一時テーブルに書き込む
392                    $this->lfRegistOtherDelivData($uniqid, $objCustomer, $_POST['other_deliv_id']);
393                    // 正常に登録されたことを記録しておく
394                    $objSiteSess->setRegistFlag();
395                    // お支払い方法選択ページへ移動
396                    $this->objDisplay->redirect($this->getLocation(MOBILE_SHOPPING_PAYMENT_URL_PATH));
397                    exit;
398                }
399            }else{
400                // エラーを返す
401                $arrErr['deli'] = '※ お届け先を選択してください。';
402            }
403            break;
404
405            // 前のページに戻る
406        case 'return':
407            // 確認ページへ移動
408            $this->objDisplay->redirect($this->getLocation(MOBILE_CART_URL_PATH));
409            exit;
410            break;
411        default:
412            $objQuery = new SC_Query();
413            $where = "order_temp_id = ?";
414            $arrRet = $objQuery->select("*", "dtb_order_temp", $where, array($uniqid));
415            $this->objFormParam->setParam($arrRet[0]);
416            break;
417        }
418
419        /** 表示処理 **/
420
421        // 会員登録住所の取得
422        $col = "name01, name02, pref, addr01, addr02, zip01, zip02";
423        $where = "customer_id = ?";
424        $objQuery = new SC_Query();
425        $arrCustomerAddr = $objQuery->select($col, "dtb_customer", $where, array($_SESSION['customer']['customer_id']));
426        // 別のお届け先住所の取得
427        $col = "other_deliv_id, name01, name02, pref, addr01, addr02, zip01, zip02";
428        $objQuery->setOrder("other_deliv_id DESC");
429        $objOtherAddr = $objQuery->select($col, "dtb_other_deliv", $where, array($_SESSION['customer']['customer_id']));
430        $this->arrAddr = $arrCustomerAddr;
431        $cnt = 1;
432        foreach($objOtherAddr as $val) {
433            $this->arrAddr[$cnt] = $val;
434            $cnt++;
435        }
436
437        // 入力値の取得
438        if (!isset($arrErr)) $arrErr = array();
439        $this->arrForm = $this->objFormParam->getFormParamList();
440        $this->arrErr = $arrErr;
441    }
442
443    /**
444     * デストラクタ.
445     *
446     * @return void
447     */
448    function destroy() {
449        parent::destroy();
450    }
451
452    /* パラメータ情報の初期化 */
453    function lfInitParam() {
454        $this->objFormParam->addParam("お名前1", "deliv_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
455        $this->objFormParam->addParam("お名前2", "deliv_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
456        $this->objFormParam->addParam("お名前(フリガナ・姓)", "deliv_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
457        $this->objFormParam->addParam("お名前(フリガナ・名)", "deliv_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
458        $this->objFormParam->addParam("郵便番号1", "deliv_zip01", ZIP01_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
459        $this->objFormParam->addParam("郵便番号2", "deliv_zip02", ZIP02_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
460        $this->objFormParam->addParam("都道府県", "deliv_pref", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
461        $this->objFormParam->addParam("住所1", "deliv_addr01", MTEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
462        $this->objFormParam->addParam("住所2", "deliv_addr02", MTEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
463        $this->objFormParam->addParam("電話番号1", "deliv_tel01", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
464        $this->objFormParam->addParam("電話番号2", "deliv_tel02", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
465        $this->objFormParam->addParam("電話番号3", "deliv_tel03", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
466        $this->objFormParam->addParam("", "deliv_check");
467    }
468
469    function lfInitLoginFormParam() {
470        $this->objLoginFormParam->addParam("記憶する", "login_memory", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
471        $this->objLoginFormParam->addParam("メールアドレス", "login_email", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
472        $this->objLoginFormParam->addParam("パスワード", "login_pass", PASSWORD_LEN1, "", array("EXIST_CHECK"));
473        $this->objLoginFormParam->addParam("パスワード", "login_pass1", PASSWORD_LEN1, "", array("EXIST_CHECK", "MIN_LENGTH_CHECK"));
474        $this->objLoginFormParam->addParam("パスワード", "login_pass2", PASSWORD_LEN2, "", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
475    }
476
477    /* DBへデータの登録 */
478    function lfRegistNewAddrData($uniqid, $objCustomer) {
479        $sqlval = $this->objFormParam->getDbArray();
480        // 登録データの作成
481        $sqlval['deliv_check'] = '1';
482        $sqlval['order_temp_id'] = $uniqid;
483        $sqlval['update_date'] = 'Now()';
484        $sqlval['customer_id'] = $objCustomer->getValue('customer_id');
485        $sqlval['order_birth'] = $objCustomer->getValue('birth');
486
487        $objDb = new SC_Helper_DB_Ex();
488        $objDb->sfRegistTempOrder($uniqid, $sqlval);
489    }
490
491    /* 入力内容のチェック */
492    function lfCheckError() {
493        // 入力データを渡す。
494        $arrRet =  $this->objFormParam->getHashArray();
495        $objErr = new SC_CheckError($arrRet);
496        $objErr->arrErr = $this->objFormParam->checkError();
497        // 複数項目チェック
498        if ($_POST['mode'] == 'login'){
499            $objErr->doFunc(array("メールアドレス", "login_email", STEXT_LEN), array("EXIST_CHECK"));
500            $objErr->doFunc(array("パスワード", "login_pass", STEXT_LEN), array("EXIST_CHECK"));
501        }
502        $objErr->doFunc(array("TEL", "deliv_tel01", "deliv_tel02", "deliv_tel03"), array("TEL_CHECK"));
503        return $objErr->arrErr;
504    }
505
506    /**
507     * 入力されたEmailから余分な改行・空白を削除する
508     *
509     * @param string $_POST["login_email"]
510     */
511    function lfConvertEmail(){
512        if( strlen($_POST["login_email"]) < 1 ){ return ; }
513        $_POST["login_email"] = preg_replace('/^[  \r\n]*(.*?)[  \r\n]*$/u', '$1', $_POST["login_email"]);
514    }
515
516    /**
517     * 入力されたPassから余分な空白を削除し、最小桁数・最大桁数チェック用に変数に入れる
518     *
519     * @param string $_POST["login_pass"]
520     */
521    function lfConvertLoginPass(){
522    if( strlen($_POST["login_pass"]) < 1 ){ return ; }
523        $_POST["login_pass"] = trim($_POST["login_pass"]); //認証用
524        $_POST["login_pass1"] = $_POST["login_pass"];      //最小桁数比較用
525        $_POST["login_pass2"] = $_POST["login_pass"];      //最大桁数比較用
526    }
527}
528?>
Note: See TracBrowser for help on using the repository browser.