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