1 | <?php |
---|
2 | /* |
---|
3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
4 | * |
---|
5 | * http://www.lockon.co.jp/ |
---|
6 | */ |
---|
7 | |
---|
8 | // {{{ requires |
---|
9 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
10 | |
---|
11 | /** |
---|
12 | * 配送業者設定 のページクラス. |
---|
13 | * |
---|
14 | * @package Page |
---|
15 | * @author LOCKON CO.,LTD. |
---|
16 | * @version $Id$ |
---|
17 | */ |
---|
18 | class LC_Page_Admin_Basis_Delivery_Input extends LC_Page { |
---|
19 | |
---|
20 | // {{{ properties |
---|
21 | |
---|
22 | /** フォームパラメータの配列 */ |
---|
23 | var $objFormParam; |
---|
24 | |
---|
25 | // }}} |
---|
26 | // {{{ functions |
---|
27 | |
---|
28 | /** |
---|
29 | * Page を初期化する. |
---|
30 | * |
---|
31 | * @return void |
---|
32 | */ |
---|
33 | function init() { |
---|
34 | parent::init(); |
---|
35 | $this->tpl_mainpage = 'basis/delivery_input.tpl'; |
---|
36 | $this->tpl_subnavi = 'basis/subnavi.tpl'; |
---|
37 | $this->tpl_subno = 'delivery'; |
---|
38 | $this->tpl_mainno = 'basis'; |
---|
39 | $masterData = new SC_DB_MasterData_Ex(); |
---|
40 | $this->arrPref = $masterData->getMasterData("mtb_pref", array("pref_id", "pref_name", "rank")); |
---|
41 | $this->tpl_subtitle = '配送業者設定'; |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | * Page のプロセス. |
---|
46 | * |
---|
47 | * @return void |
---|
48 | */ |
---|
49 | function process() { |
---|
50 | $conn = new SC_DBConn(); |
---|
51 | $objView = new SC_AdminView(); |
---|
52 | $objSess = new SC_Session(); |
---|
53 | $objQuery = new SC_Query(); |
---|
54 | |
---|
55 | // 認証可否の判定 |
---|
56 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
57 | |
---|
58 | // パラメータ管理クラス |
---|
59 | $this->objFormParam = new SC_FormParam(); |
---|
60 | // パラメータ情報の初期化 |
---|
61 | $this->lfInitParam(); |
---|
62 | // POST値の取得 |
---|
63 | $this->objFormParam->setParam($_POST); |
---|
64 | |
---|
65 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
66 | |
---|
67 | switch($_POST['mode']) { |
---|
68 | case 'edit': |
---|
69 | // 入力値の変換 |
---|
70 | $this->objFormParam->convParam(); |
---|
71 | $this->arrErr = $this->lfCheckError(); |
---|
72 | if(count($this->arrErr) == 0) { |
---|
73 | $this->tpl_deliv_id = $this->lfRegistData(); |
---|
74 | $this->tpl_onload = "window.alert('配送業者設定が完了しました。');"; |
---|
75 | } |
---|
76 | break; |
---|
77 | case 'pre_edit': |
---|
78 | if($_POST['deliv_id'] != "") { |
---|
79 | $this->lfGetDelivData($_POST['deliv_id']); |
---|
80 | $this->tpl_deliv_id = $_POST['deliv_id']; |
---|
81 | } |
---|
82 | break; |
---|
83 | default: |
---|
84 | break; |
---|
85 | } |
---|
86 | |
---|
87 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
88 | $objView->assignobj($this); |
---|
89 | $objView->display(MAIN_FRAME); |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * デストラクタ. |
---|
94 | * |
---|
95 | * @return void |
---|
96 | */ |
---|
97 | function destroy() { |
---|
98 | parent::destroy(); |
---|
99 | } |
---|
100 | |
---|
101 | /* パラメータ情報の初期化 */ |
---|
102 | function lfInitParam() { |
---|
103 | $this->objFormParam->addParam("配送業者名", "name", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK")); |
---|
104 | $this->objFormParam->addParam("名称", "service_name", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK")); |
---|
105 | $this->objFormParam->addParam("伝票No.確認URL", "confirm_url", STEXT_LEN, "n", array("URL_CHECK", "MAX_LENGTH_CHECK"), "http://"); |
---|
106 | |
---|
107 | for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) { |
---|
108 | $this->objFormParam->addParam("配送時間$cnt", "deliv_time$cnt", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK")); |
---|
109 | } |
---|
110 | |
---|
111 | if(INPUT_DELIV_FEE) { |
---|
112 | for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) { |
---|
113 | $this->objFormParam->addParam("配送料金$cnt", "fee$cnt", PRICE_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | /* DBに登録する */ |
---|
119 | function lfRegistData() { |
---|
120 | $arrRet = $this->objFormParam->getHashArray(); |
---|
121 | $objQuery = new SC_Query(); |
---|
122 | $objQuery->begin(); |
---|
123 | |
---|
124 | // 入力データを渡す。 |
---|
125 | $sqlval['name'] = $arrRet['name']; |
---|
126 | $sqlval['service_name'] = $arrRet['service_name']; |
---|
127 | $sqlval['confirm_url'] = $arrRet['confirm_url']; |
---|
128 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
129 | $sqlval['update_date'] = 'Now()'; |
---|
130 | |
---|
131 | if($_POST['deliv_id'] != "") { |
---|
132 | $deliv_id = $_POST['deliv_id']; |
---|
133 | $where = "deliv_id = ?"; |
---|
134 | $objQuery->update("dtb_deliv", $sqlval, $where, array($deliv_id)); |
---|
135 | $objQuery->delete("dtb_delivfee", $where, array($deliv_id)); |
---|
136 | $objQuery->delete("dtb_delivtime", $where, array($deliv_id)); |
---|
137 | } else { |
---|
138 | // 登録する配送業者IDの取得 |
---|
139 | |
---|
140 | if (DB_TYPE == "pgsql") { |
---|
141 | $deliv_id = $objQuery->nextval('dtb_deliv', 'deliv_id'); |
---|
142 | $sqlval['deliv_id'] = $deliv_id; |
---|
143 | } |
---|
144 | |
---|
145 | $sqlval['rank'] = $objQuery->max("dtb_deliv", "rank") + 1; |
---|
146 | $sqlval['create_date'] = 'Now()'; |
---|
147 | // INSERTの実行 |
---|
148 | $objQuery->insert("dtb_deliv", $sqlval); |
---|
149 | |
---|
150 | if (DB_TYPE == "mysql") { |
---|
151 | $deliv_id = $objQuery->nextval('dtb_deliv', 'deliv_id'); |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | $sqlval = array(); |
---|
156 | // 配送時間の設定 |
---|
157 | for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) { |
---|
158 | $keyname = "deliv_time$cnt"; |
---|
159 | if($arrRet[$keyname] != "") { |
---|
160 | $sqlval['deliv_id'] = $deliv_id; |
---|
161 | $sqlval['deliv_time'] = $arrRet[$keyname]; |
---|
162 | // INSERTの実行 |
---|
163 | $objQuery->insert("dtb_delivtime", $sqlval); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | if(INPUT_DELIV_FEE) { |
---|
168 | $sqlval = array(); |
---|
169 | // 配送料金の設定 |
---|
170 | for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) { |
---|
171 | $keyname = "fee$cnt"; |
---|
172 | if($arrRet[$keyname] != "") { |
---|
173 | $sqlval['deliv_id'] = $deliv_id; |
---|
174 | $sqlval['fee'] = $arrRet[$keyname]; |
---|
175 | $sqlval['pref'] = $cnt; |
---|
176 | // INSERTの実行 |
---|
177 | $objQuery->insert("dtb_delivfee", $sqlval); |
---|
178 | } |
---|
179 | } |
---|
180 | } |
---|
181 | $objQuery->commit(); |
---|
182 | return $deliv_id; |
---|
183 | } |
---|
184 | |
---|
185 | /* 配送業者情報の取得 */ |
---|
186 | function lfGetDelivData($deliv_id) { |
---|
187 | $objQuery = new SC_Query(); |
---|
188 | // 配送業者一覧の取得 |
---|
189 | $col = "deliv_id, name, service_name, confirm_url"; |
---|
190 | $where = "deliv_id = ?"; |
---|
191 | $table = "dtb_deliv"; |
---|
192 | $arrRet = $objQuery->select($col, $table, $where, array($deliv_id)); |
---|
193 | $this->objFormParam->setParam($arrRet[0]); |
---|
194 | // 配送時間の取得 |
---|
195 | $col = "deliv_time"; |
---|
196 | $where = "deliv_id = ? ORDER BY time_id"; |
---|
197 | $table = "dtb_delivtime"; |
---|
198 | $arrRet = $objQuery->select($col, $table, $where, array($deliv_id)); |
---|
199 | $this->objFormParam->setParamList($arrRet, 'deliv_time'); |
---|
200 | // 配送料金の取得 |
---|
201 | $col = "fee"; |
---|
202 | $where = "deliv_id = ? ORDER BY pref"; |
---|
203 | $table = "dtb_delivfee"; |
---|
204 | $arrRet = $objQuery->select($col, $table, $where, array($deliv_id)); |
---|
205 | $this->objFormParam->setParamList($arrRet, 'fee'); |
---|
206 | } |
---|
207 | |
---|
208 | /* 入力内容のチェック */ |
---|
209 | function lfCheckError() { |
---|
210 | // 入力データを渡す。 |
---|
211 | $arrRet = $this->objFormParam->getHashArray(); |
---|
212 | $objErr = new SC_CheckError($arrRet); |
---|
213 | $objErr->arrErr = $this->objFormParam->checkError(); |
---|
214 | |
---|
215 | if(!isset($objErr->arrErr['name']) && $_POST['deliv_id'] == "") { |
---|
216 | // 既存チェック |
---|
217 | $objDb = new SC_Helper_DB_Ex(); |
---|
218 | $ret = $objDb->sfIsRecord("dtb_deliv", "service_name", array($arrRet['service_name'])); |
---|
219 | if ($ret) { |
---|
220 | $objErr->arrErr['name'] = "※ 同じ名称の組み合わせは登録できません。<br>"; |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | return $objErr->arrErr; |
---|
225 | } |
---|
226 | } |
---|
227 | ?> |
---|