1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2007 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_Admin_Products_Product extends LC_Page { |
---|
35 | |
---|
36 | // {{{ properties |
---|
37 | |
---|
38 | /** ファイル管理クラスのインスタンス */ |
---|
39 | var $objUpFile; |
---|
40 | |
---|
41 | /** hidden 項目の配列 */ |
---|
42 | var $arrHidden; |
---|
43 | |
---|
44 | /** エラー情報 */ |
---|
45 | var $arrErr; |
---|
46 | |
---|
47 | // }}} |
---|
48 | // {{{ functions |
---|
49 | |
---|
50 | /** |
---|
51 | * Page を初期化する. |
---|
52 | * |
---|
53 | * @return void |
---|
54 | */ |
---|
55 | function init() { |
---|
56 | parent::init(); |
---|
57 | $this->tpl_mainpage = 'products/product.tpl'; |
---|
58 | $this->tpl_subnavi = 'products/subnavi.tpl'; |
---|
59 | $this->tpl_mainno = 'products'; |
---|
60 | $this->tpl_subno = 'product'; |
---|
61 | $this->tpl_subtitle = '商品登録'; |
---|
62 | $this->arrErr = array(); |
---|
63 | |
---|
64 | $masterData = new SC_DB_MasterData_Ex(); |
---|
65 | $this->arrSRANK = $masterData->getMasterData("mtb_srank"); |
---|
66 | $this->arrDISP = $masterData->getMasterData("mtb_disp"); |
---|
67 | $this->arrCLASS = $masterData->getMasterData("mtb_class"); |
---|
68 | $this->arrSTATUS = $masterData->getMasterData("mtb_status"); |
---|
69 | $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image"); |
---|
70 | $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date"); |
---|
71 | $this->arrAllowedTag = $masterData->getMasterData("mtb_allowed_tag"); |
---|
72 | $this->tpl_nonclass = true; |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * Page のプロセス. |
---|
77 | * |
---|
78 | * @return void |
---|
79 | */ |
---|
80 | function process() { |
---|
81 | $objView = new SC_AdminView(); |
---|
82 | $objSiteInfo = new SC_SiteInfo(); |
---|
83 | $objQuery = new SC_Query(); |
---|
84 | $objDb = new SC_Helper_DB_Ex(); |
---|
85 | |
---|
86 | // 認証可否の判定 |
---|
87 | $objSess = new SC_Session(); |
---|
88 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
89 | |
---|
90 | // ファイル管理クラス |
---|
91 | $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR); |
---|
92 | |
---|
93 | // ファイル情報の初期化 |
---|
94 | $this->lfInitFile(); |
---|
95 | // Hiddenからのデータを引き継ぐ |
---|
96 | $this->objUpFile->setHiddenFileList($_POST); |
---|
97 | |
---|
98 | // 規格の有り無し判定 |
---|
99 | $this->tpl_nonclass = $this->lfCheckNonClass($_POST['product_id']); |
---|
100 | |
---|
101 | // 検索パラメータの引き継ぎ |
---|
102 | foreach ($_POST as $key => $val) { |
---|
103 | if (ereg("^search_", $key)) { |
---|
104 | $this->arrSearchHidden[$key] = $val; |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | // FORMデータの引き継ぎ |
---|
109 | $this->arrForm['status'] = DEFAULT_PRODUCT_DISP; // 公開・非公開のデフォルト値 |
---|
110 | $this->arrForm = $_POST; |
---|
111 | |
---|
112 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
113 | |
---|
114 | switch($_POST['mode']) { |
---|
115 | // 検索画面からの編集 |
---|
116 | case 'pre_edit': |
---|
117 | case 'copy' : |
---|
118 | // 編集時 |
---|
119 | if(SC_Utils_Ex::sfIsInt($_POST['product_id'])){ |
---|
120 | // DBから商品情報の読込 |
---|
121 | $arrForm = $this->lfGetProduct($_POST['product_id']); |
---|
122 | // DBデータから画像ファイル名の読込 |
---|
123 | $this->objUpFile->setDBFileList($arrForm); |
---|
124 | |
---|
125 | if($_POST['mode'] == "copy"){ |
---|
126 | $arrForm["copy_product_id"] = $arrForm["product_id"]; |
---|
127 | $arrForm["product_id"] = ""; |
---|
128 | // 画像ファイルのコピー |
---|
129 | $arrKey = $this->objUpFile->keyname; |
---|
130 | $arrSaveFile = $this->objUpFile->save_file; |
---|
131 | |
---|
132 | foreach($arrSaveFile as $key => $val){ |
---|
133 | $this->lfMakeScaleImage($arrKey[$key], $arrKey[$key], true); |
---|
134 | } |
---|
135 | } |
---|
136 | $this->arrForm = $arrForm; |
---|
137 | |
---|
138 | // 商品ステータスの変換 |
---|
139 | $arrRet = SC_Utils_Ex::sfSplitCBValue($this->arrForm['product_flag'], "product_flag"); |
---|
140 | $this->arrForm = array_merge($this->arrForm, $arrRet); |
---|
141 | // DBからおすすめ商品の読み込み |
---|
142 | $this->arrRecommend = $this->lfPreGetRecommendProducts($_POST['product_id']); |
---|
143 | |
---|
144 | $this->lfProductPage(); // 商品登録ページ |
---|
145 | } |
---|
146 | break; |
---|
147 | // 商品登録・編集 |
---|
148 | case 'edit': |
---|
149 | if($_POST['product_id'] == "" and SC_Utils_Ex::sfIsInt($_POST['copy_product_id'])){ |
---|
150 | $this->tpl_nonclass = $this->lfCheckNonClass($_POST['copy_product_id']); |
---|
151 | } |
---|
152 | |
---|
153 | // 入力値の変換 |
---|
154 | $this->arrForm = $this->lfConvertParam($this->arrForm); |
---|
155 | // エラーチェック |
---|
156 | $this->arrErr = $this->lfErrorCheck($this->arrForm); |
---|
157 | // ファイル存在チェック |
---|
158 | $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS()); |
---|
159 | // エラーなしの場合 |
---|
160 | if(count($this->arrErr) == 0) { |
---|
161 | $this->lfProductConfirmPage(); // 確認ページ |
---|
162 | } else { |
---|
163 | $this->lfProductPage(); // 商品登録ページ |
---|
164 | } |
---|
165 | break; |
---|
166 | // 確認ページから完了ページへ |
---|
167 | case 'complete': |
---|
168 | $this->tpl_mainpage = 'products/complete.tpl'; |
---|
169 | |
---|
170 | $this->arrForm['product_id'] = $this->lfRegistProduct($_POST); // データ登録 |
---|
171 | |
---|
172 | // 件数カウントバッチ実行 |
---|
173 | $objDb->sfCategory_Count($objQuery); |
---|
174 | // 一時ファイルを本番ディレクトリに移動する |
---|
175 | $this->objUpFile->moveTempFile(); |
---|
176 | |
---|
177 | break; |
---|
178 | // 画像のアップロード |
---|
179 | case 'upload_image': |
---|
180 | // ファイル存在チェック |
---|
181 | $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS($_POST['image_key'])); |
---|
182 | // 画像保存処理 |
---|
183 | $this->arrErr[$_POST['image_key']] = $this->objUpFile->makeTempFile($_POST['image_key']); |
---|
184 | |
---|
185 | // 中、小画像生成 |
---|
186 | $this->lfSetScaleImage(); |
---|
187 | |
---|
188 | $this->lfProductPage(); // 商品登録ページ |
---|
189 | break; |
---|
190 | // 画像の削除 |
---|
191 | case 'delete_image': |
---|
192 | $this->objUpFile->deleteFile($_POST['image_key']); |
---|
193 | $this->lfProductPage(); // 商品登録ページ |
---|
194 | break; |
---|
195 | // 確認ページからの戻り |
---|
196 | case 'confirm_return': |
---|
197 | $this->lfProductPage(); // 商品登録ページ |
---|
198 | break; |
---|
199 | // おすすめ商品選択 |
---|
200 | case 'recommend_select' : |
---|
201 | $this->lfProductPage(); // 商品登録ページ |
---|
202 | break; |
---|
203 | default: |
---|
204 | $this->lfProductPage(); // 商品登録ページ |
---|
205 | break; |
---|
206 | } |
---|
207 | |
---|
208 | if($_POST['mode'] != 'pre_edit') { |
---|
209 | // おすすめ商品の読み込み |
---|
210 | $this->arrRecommend = $this->lfGetRecommendProducts(); |
---|
211 | } |
---|
212 | |
---|
213 | // 基本情報を渡す |
---|
214 | $this->arrInfo = $objSiteInfo->data; |
---|
215 | |
---|
216 | // サブ情報の入力があるかどうかチェックする |
---|
217 | $sub_find = false; |
---|
218 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
219 | if( (isset($this->arrForm['sub_title'.$cnt]) |
---|
220 | && !empty($this->arrForm['sub_title'.$cnt])) || |
---|
221 | (isset($this->arrForm['sub_comment'.$cnt]) |
---|
222 | && !empty($this->arrForm['sub_comment'.$cnt])) || |
---|
223 | (isset($this->arrForm['sub_image'.$cnt]) |
---|
224 | && !empty($this->arrForm['sub_image'.$cnt])) || |
---|
225 | (isset($this->arrForm['sub_large_image'.$cnt]) |
---|
226 | && !empty($this->arrForm['sub_large_image'.$cnt])) || |
---|
227 | (isset($this->arrForm['sub_image'.$cnt]) |
---|
228 | && is_array($this->arrFile['sub_image'.$cnt])) || |
---|
229 | (isset($this->arrForm['sub_large_image'.$cnt]) |
---|
230 | && is_array($this->arrFile['sub_large_image'.$cnt]))) { |
---|
231 | $sub_find = true; |
---|
232 | break; |
---|
233 | } |
---|
234 | } |
---|
235 | // サブ情報表示・非表示のチェックに使用する。 |
---|
236 | $this->sub_find = $sub_find; |
---|
237 | $objView->assignobj($this); |
---|
238 | $objView->display(MAIN_FRAME); |
---|
239 | } |
---|
240 | |
---|
241 | /** |
---|
242 | * デストラクタ. |
---|
243 | * |
---|
244 | * @return void |
---|
245 | */ |
---|
246 | function destroy() { |
---|
247 | parent::destroy(); |
---|
248 | } |
---|
249 | |
---|
250 | /* おすすめ商品の読み込み */ |
---|
251 | function lfGetRecommendProducts() { |
---|
252 | $objQuery = new SC_Query(); |
---|
253 | $arrRecommend = array(); |
---|
254 | for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { |
---|
255 | $keyname = "recommend_id" . $i; |
---|
256 | $delkey = "recommend_delete" . $i; |
---|
257 | $commentkey = "recommend_comment" . $i; |
---|
258 | |
---|
259 | if (!isset($_POST[$delkey])) $_POST[$delkey] = null; |
---|
260 | |
---|
261 | if((isset($_POST[$keyname]) && !empty($_POST[$keyname])) && $_POST[$delkey] != 1) { |
---|
262 | $arrRet = $objQuery->select("main_list_image, product_code_min, name", "vw_products_allclass AS allcls", "product_id = ?", array($_POST[$keyname])); |
---|
263 | $arrRecommend[$i] = $arrRet[0]; |
---|
264 | $arrRecommend[$i]['product_id'] = $_POST[$keyname]; |
---|
265 | $arrRecommend[$i]['comment'] = $this->arrForm[$commentkey]; |
---|
266 | } |
---|
267 | } |
---|
268 | return $arrRecommend; |
---|
269 | } |
---|
270 | |
---|
271 | /* おすすめ商品の登録 */ |
---|
272 | function lfInsertRecommendProducts($objQuery, $arrList, $product_id) { |
---|
273 | // 一旦オススメ商品をすべて削除する |
---|
274 | $objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id)); |
---|
275 | $sqlval['product_id'] = $product_id; |
---|
276 | $rank = RECOMMEND_PRODUCT_MAX; |
---|
277 | for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { |
---|
278 | $keyname = "recommend_id" . $i; |
---|
279 | $commentkey = "recommend_comment" . $i; |
---|
280 | $deletekey = "recommend_delete" . $i; |
---|
281 | |
---|
282 | if (!isset($arrList[$deletekey])) $arrList[$deletekey] = null; |
---|
283 | |
---|
284 | if($arrList[$keyname] != "" && $arrList[$deletekey] != '1') { |
---|
285 | $sqlval['recommend_product_id'] = $arrList[$keyname]; |
---|
286 | $sqlval['comment'] = $arrList[$commentkey]; |
---|
287 | $sqlval['rank'] = $rank; |
---|
288 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
289 | $sqlval['create_date'] = "now()"; |
---|
290 | $sqlval['update_date'] = "now()"; |
---|
291 | $objQuery->insert("dtb_recommend_products", $sqlval); |
---|
292 | $rank--; |
---|
293 | } |
---|
294 | } |
---|
295 | } |
---|
296 | |
---|
297 | /* 登録済みおすすめ商品の読み込み */ |
---|
298 | function lfPreGetRecommendProducts($product_id) { |
---|
299 | $arrRecommend = array(); |
---|
300 | $objQuery = new SC_Query(); |
---|
301 | $objQuery->setorder("rank DESC"); |
---|
302 | $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id)); |
---|
303 | $max = count($arrRet); |
---|
304 | $no = 1; |
---|
305 | |
---|
306 | for($i = 0; $i < $max; $i++) { |
---|
307 | $arrProductInfo = $objQuery->select("main_list_image, product_code_min, name", "vw_products_allclass AS allcls", "product_id = ?", array($arrRet[$i]['recommend_product_id'])); |
---|
308 | $arrRecommend[$no] = $arrProductInfo[0]; |
---|
309 | $arrRecommend[$no]['product_id'] = $arrRet[$i]['recommend_product_id']; |
---|
310 | $arrRecommend[$no]['comment'] = $arrRet[$i]['comment']; |
---|
311 | $no++; |
---|
312 | } |
---|
313 | return $arrRecommend; |
---|
314 | } |
---|
315 | |
---|
316 | /* 商品情報の読み込み */ |
---|
317 | function lfGetProduct($product_id) { |
---|
318 | $objQuery = new SC_Query(); |
---|
319 | $col = "*"; |
---|
320 | $table = "vw_products_nonclass AS noncls "; |
---|
321 | $where = "product_id = ?"; |
---|
322 | |
---|
323 | $arrRet = $objQuery->select($col, $table, $where, array($product_id)); |
---|
324 | |
---|
325 | // カテゴリID を取得 |
---|
326 | $arrRet[0]['category_id'] = $objQuery->getCol("dtb_product_categories", |
---|
327 | "category_id", |
---|
328 | "product_id = ?", |
---|
329 | array($product_id)); |
---|
330 | //編集時に規格IDが変わってしまうのを防ぐために規格が登録されていなければ規格IDを取得する |
---|
331 | if( $this->lfCheckNonClass($_POST['product_id']) ){ |
---|
332 | $arrRet[0]['product_class_id'] = SC_Utils::sfGetProductClassId($product_id,"0","0"); |
---|
333 | } |
---|
334 | return $arrRet[0]; |
---|
335 | } |
---|
336 | |
---|
337 | /* 商品登録ページ表示用 */ |
---|
338 | function lfProductPage() { |
---|
339 | $objDb = new SC_Helper_DB_Ex(); |
---|
340 | |
---|
341 | // カテゴリの読込 |
---|
342 | list($this->arrCatVal, $this->arrCatOut) = $objDb->sfGetLevelCatList(false); |
---|
343 | |
---|
344 | if (isset($this->arrForm['category_id']) && !is_array($this->arrForm['category_id'])) { |
---|
345 | $this->arrForm['category_id'] = unserialize($this->arrForm['category_id']); |
---|
346 | } |
---|
347 | if($this->arrForm['status'] == "") { |
---|
348 | $this->arrForm['status'] = 1; |
---|
349 | } |
---|
350 | |
---|
351 | if(isset($this->arrForm['product_flag']) && !is_array($this->arrForm['product_flag'])) { |
---|
352 | // 商品ステータスの分割読込 |
---|
353 | $this->arrForm['product_flag'] = SC_Utils_Ex::sfSplitCheckBoxes($this->arrForm['product_flag']); |
---|
354 | } |
---|
355 | |
---|
356 | // HIDDEN用に配列を渡す。 |
---|
357 | $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objUpFile->getHiddenFileList()); |
---|
358 | // Form用配列を渡す。 |
---|
359 | $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL); |
---|
360 | |
---|
361 | |
---|
362 | // アンカーを設定 |
---|
363 | if (isset($_POST['image_key']) && !empty($_POST['image_key'])) { |
---|
364 | $anchor_hash = "location.hash='#" . $_POST['image_key'] . "'"; |
---|
365 | } elseif (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) { |
---|
366 | $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'"; |
---|
367 | } else { |
---|
368 | $anchor_hash = ""; |
---|
369 | } |
---|
370 | |
---|
371 | $this->tpl_onload = "fnCheckSaleLimit('" . DISABLED_RGB . "'); fnCheckStockLimit('" . DISABLED_RGB . "'); fnMoveSelect('category_id_unselect', 'category_id');" . $anchor_hash; |
---|
372 | } |
---|
373 | |
---|
374 | /* ファイル情報の初期化 */ |
---|
375 | function lfInitFile() { |
---|
376 | $this->objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg', 'gif', 'png'),IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); |
---|
377 | $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, true, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT); |
---|
378 | $this->objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT); |
---|
379 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
380 | $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_WIDTH, NORMAL_SUBIMAGE_HEIGHT); |
---|
381 | $this->objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_SUBIMAGE_WIDTH, LARGE_SUBIMAGE_HEIGHT); |
---|
382 | } |
---|
383 | $this->objUpFile->addFile("商品比較画像", 'file1', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, OTHER_IMAGE1_WIDTH, OTHER_IMAGE1_HEIGHT); |
---|
384 | $this->objUpFile->addFile("商品詳細ファイル", 'file2', array('pdf'), PDF_SIZE, false, 0, 0, false); |
---|
385 | } |
---|
386 | |
---|
387 | /* 商品の登録 */ |
---|
388 | function lfRegistProduct($arrList) { |
---|
389 | $objQuery = new SC_Query(); |
---|
390 | $objDb = new SC_Helper_DB_Ex(); |
---|
391 | $objQuery->begin(); |
---|
392 | |
---|
393 | // 配列の添字を定義 |
---|
394 | $checkArray = array("name", "status", "product_flag", |
---|
395 | "main_list_comment", "main_comment", "point_rate", |
---|
396 | "deliv_fee", "comment1", "comment2", "comment3", |
---|
397 | "comment4", "comment5", "comment6", "main_list_comment", |
---|
398 | "sale_limit", "sale_unlimited", "deliv_date_id", "note"); |
---|
399 | $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray); |
---|
400 | |
---|
401 | // INSERTする値を作成する。 |
---|
402 | $sqlval['name'] = $arrList['name']; |
---|
403 | $sqlval['status'] = $arrList['status']; |
---|
404 | $sqlval['product_flag'] = $arrList['product_flag']; |
---|
405 | $sqlval['main_list_comment'] = $arrList['main_list_comment']; |
---|
406 | $sqlval['main_comment'] = $arrList['main_comment']; |
---|
407 | $sqlval['point_rate'] = $arrList['point_rate']; |
---|
408 | $sqlval['deliv_fee'] = $arrList['deliv_fee']; |
---|
409 | $sqlval['comment1'] = $arrList['comment1']; |
---|
410 | $sqlval['comment2'] = $arrList['comment2']; |
---|
411 | $sqlval['comment3'] = $arrList['comment3']; |
---|
412 | $sqlval['comment4'] = $arrList['comment4']; |
---|
413 | $sqlval['comment5'] = $arrList['comment5']; |
---|
414 | $sqlval['comment6'] = $arrList['comment6']; |
---|
415 | $sqlval['main_list_comment'] = $arrList['main_list_comment']; |
---|
416 | $sqlval['sale_limit'] = $arrList['sale_limit']; |
---|
417 | $sqlval['sale_unlimited'] = $arrList['sale_unlimited']; |
---|
418 | $sqlval['deliv_date_id'] = $arrList['deliv_date_id']; |
---|
419 | $sqlval['note'] = $arrList['note']; |
---|
420 | $sqlval['update_date'] = "Now()"; |
---|
421 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
422 | $arrRet = $this->objUpFile->getDBFileList(); |
---|
423 | $sqlval = array_merge($sqlval, $arrRet); |
---|
424 | |
---|
425 | $arrList['category_id'] = unserialize($arrList['category_id']); |
---|
426 | |
---|
427 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
428 | $sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt]; |
---|
429 | $sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt]; |
---|
430 | } |
---|
431 | |
---|
432 | if($arrList['product_id'] == "") { |
---|
433 | // product_id 取得(PostgreSQLの場合) |
---|
434 | if(DB_TYPE=='pgsql'){ |
---|
435 | $product_id = $objQuery->nextval("dtb_products", "product_id"); |
---|
436 | $sqlval['product_id'] = $product_id; |
---|
437 | } |
---|
438 | |
---|
439 | // INSERTの実行 |
---|
440 | $sqlval['create_date'] = "Now()"; |
---|
441 | $objQuery->insert("dtb_products", $sqlval); |
---|
442 | |
---|
443 | // product_id 取得(MySQLの場合) |
---|
444 | if(DB_TYPE=='mysql'){ |
---|
445 | $product_id = $objQuery->nextval("dtb_products", "product_id"); |
---|
446 | } |
---|
447 | |
---|
448 | // カテゴリを更新 |
---|
449 | $objDb->updateProductCategories($arrList['category_id'], $product_id); |
---|
450 | |
---|
451 | // コピー商品の場合には規格もコピーする |
---|
452 | if($_POST["copy_product_id"] != "" and SC_Utils_Ex::sfIsInt($_POST["copy_product_id"])){ |
---|
453 | // dtb_products_class のカラムを取得 |
---|
454 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
455 | $arrColList = $dbFactory->sfGetColumnList("dtb_products_class", $objQuery); |
---|
456 | $arrColList_tmp = array_flip($arrColList); |
---|
457 | |
---|
458 | // コピーしない列 |
---|
459 | unset($arrColList[$arrColList_tmp["product_class_id"]]); //規格ID |
---|
460 | unset($arrColList[$arrColList_tmp["product_id"]]); //商品ID |
---|
461 | unset($arrColList[$arrColList_tmp["create_date"]]); |
---|
462 | |
---|
463 | $col = SC_Utils_Ex::sfGetCommaList($arrColList); |
---|
464 | |
---|
465 | $objQuery->query("INSERT INTO dtb_products_class (product_id, ". $col .") SELECT ?, " . $col. " FROM dtb_products_class WHERE product_id = ? ORDER BY product_class_id", array($product_id, $_POST["copy_product_id"])); |
---|
466 | |
---|
467 | } |
---|
468 | |
---|
469 | } else { |
---|
470 | $product_id = $arrList['product_id']; |
---|
471 | // 削除要求のあった既存ファイルの削除 |
---|
472 | $arrRet = $this->lfGetProduct($arrList['product_id']); |
---|
473 | $this->objUpFile->deleteDBFile($arrRet); |
---|
474 | |
---|
475 | // UPDATEの実行 |
---|
476 | $where = "product_id = ?"; |
---|
477 | $objQuery->update("dtb_products", $sqlval, $where, array($product_id)); |
---|
478 | |
---|
479 | // カテゴリを更新 |
---|
480 | $objDb->updateProductCategories($arrList['category_id'], $product_id); |
---|
481 | } |
---|
482 | |
---|
483 | //商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。 |
---|
484 | if( $_POST["copy_product_id"] == "" ){ |
---|
485 | // 規格登録 |
---|
486 | SC_Utils_Ex::sfInsertProductClass($objQuery, $arrList, $product_id , $arrList['product_class_id'] ); |
---|
487 | } |
---|
488 | |
---|
489 | // おすすめ商品登録 |
---|
490 | $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id); |
---|
491 | |
---|
492 | $objQuery->commit(); |
---|
493 | return $product_id; |
---|
494 | } |
---|
495 | |
---|
496 | |
---|
497 | /* 取得文字列の変換 */ |
---|
498 | function lfConvertParam($array) { |
---|
499 | /* |
---|
500 | * 文字列の変換 |
---|
501 | * K : 「半角(ハンカク)片仮名」を「全角片仮名」に変換 |
---|
502 | * C : 「全角ひら仮名」を「全角かた仮名」に変換 |
---|
503 | * V : 濁点付きの文字を一文字に変換。"K","H"と共に使用します |
---|
504 | * n : 「全角」数字を「半角(ハンカク)」に変換 |
---|
505 | */ |
---|
506 | |
---|
507 | // スポット商品 |
---|
508 | $arrConvList['name'] = "KVa"; |
---|
509 | $arrConvList['main_list_comment'] = "KVa"; |
---|
510 | $arrConvList['main_comment'] = "KVa"; |
---|
511 | $arrConvList['note'] = "KVa"; |
---|
512 | $arrConvList['price01'] = "n"; |
---|
513 | $arrConvList['price02'] = "n"; |
---|
514 | $arrConvList['stock'] = "n"; |
---|
515 | $arrConvList['sale_limit'] = "n"; |
---|
516 | $arrConvList['point_rate'] = "n"; |
---|
517 | $arrConvList['product_code'] = "KVna"; |
---|
518 | $arrConvList['comment1'] = "a"; |
---|
519 | $arrConvList['deliv_fee'] = "n"; |
---|
520 | |
---|
521 | // 詳細-サブ |
---|
522 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
523 | $arrConvList["sub_title$cnt"] = "KVa"; |
---|
524 | } |
---|
525 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
526 | $arrConvList["sub_comment$cnt"] = "KVa"; |
---|
527 | } |
---|
528 | |
---|
529 | // おすすめ商品 |
---|
530 | for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) { |
---|
531 | $arrConvList["recommend_comment$cnt"] = "KVa"; |
---|
532 | } |
---|
533 | |
---|
534 | // 文字変換 |
---|
535 | foreach ($arrConvList as $key => $val) { |
---|
536 | // POSTされてきた値のみ変換する。 |
---|
537 | if(isset($array[$key])) { |
---|
538 | $array[$key] = mb_convert_kana($array[$key] ,$val); |
---|
539 | } |
---|
540 | } |
---|
541 | |
---|
542 | if (!isset($array['product_flag'])) $array['product_flag'] = ""; |
---|
543 | $array['product_flag'] = SC_Utils_Ex::sfMergeCheckBoxes($array['product_flag'], count($this->arrSTATUS)); |
---|
544 | |
---|
545 | return $array; |
---|
546 | } |
---|
547 | |
---|
548 | // 入力エラーチェック |
---|
549 | function lfErrorCheck($array) { |
---|
550 | |
---|
551 | $objErr = new SC_CheckError($array); |
---|
552 | $objErr->doFunc(array("商品名", "name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
553 | $objErr->doFunc(array("一覧-メインコメント", "main_list_comment", MTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
554 | $objErr->doFunc(array("詳細-メインコメント", "main_comment", LLTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
555 | $objErr->doFunc(array("詳細-メインコメント", "main_comment", $this->arrAllowedTag), array("HTML_TAG_CHECK")); |
---|
556 | $objErr->doFunc(array("ポイント付与率", "point_rate", PERCENTAGE_LEN), array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
557 | $objErr->doFunc(array("商品送料", "deliv_fee", PRICE_LEN), array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
558 | $objErr->doFunc(array("備考欄(SHOP専用)", "note", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
559 | $objErr->doFunc(array("検索ワード", "comment3", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
560 | $objErr->doFunc(array("メーカーURL", "comment1", URL_LEN), array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK")); |
---|
561 | $objErr->doFunc(array("発送日目安", "deliv_date_id", INT_LEN), array("NUM_CHECK")); |
---|
562 | |
---|
563 | if($this->tpl_nonclass) { |
---|
564 | $objErr->doFunc(array("商品コード", "product_code", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK","MAX_LENGTH_CHECK")); |
---|
565 | $objErr->doFunc(array("通常価格", "price01", PRICE_LEN), array("ZERO_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
566 | $objErr->doFunc(array("商品価格", "price02", PRICE_LEN), array("EXIST_CHECK", "NUM_CHECK", "ZERO_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
567 | |
---|
568 | if(!isset($array['stock_unlinited']) && $array['stock_unlimited'] != "1") { |
---|
569 | $objErr->doFunc(array("在庫数", "stock", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
570 | } |
---|
571 | } |
---|
572 | |
---|
573 | if(!isset($array['sale_unlimited']) && $array['sale_unlimited'] != "1") { |
---|
574 | $objErr->doFunc(array("購入制限", "sale_limit", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
575 | } |
---|
576 | |
---|
577 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
578 | $objErr->doFunc(array("詳細-サブタイトル$cnt", "sub_title$cnt", STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
579 | $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
580 | $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", $this->arrAllowedTag), array("HTML_TAG_CHECK")); |
---|
581 | } |
---|
582 | |
---|
583 | for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) { |
---|
584 | |
---|
585 | if (!isset($_POST["recommend_delete$cnt"])) $_POST["recommend_delete$cnt"] = ""; |
---|
586 | |
---|
587 | if(isset($_POST["recommend_id$cnt"]) |
---|
588 | && $_POST["recommend_id$cnt"] != "" |
---|
589 | && $_POST["recommend_delete$cnt"] != 1) { |
---|
590 | $objErr->doFunc(array("おすすめ商品コメント$cnt", "recommend_comment$cnt", LTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
591 | } |
---|
592 | } |
---|
593 | |
---|
594 | // カテゴリID のチェック |
---|
595 | if (empty($array['category_id'])) { |
---|
596 | $objErr->arrErr['category_id'] = "※ 商品カテゴリが選択されていません。<br />"; |
---|
597 | } else { |
---|
598 | $arrCategory_id = array(); |
---|
599 | for ($i = 0; $i < count($array['category_id']); $i++) { |
---|
600 | $arrCategory_id['category_id' . $i] = $array['category_id'][$i]; |
---|
601 | } |
---|
602 | $objCheckCategory = new SC_CheckError($arrCategory_id); |
---|
603 | for ($i = 0; $i < count($array['category_id']); $i++) { |
---|
604 | $objCheckCategory->doFunc(array("商品カテゴリ", "category_id" . $i, STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
605 | } |
---|
606 | if (!empty($objCheckCategory->arrErr)) { |
---|
607 | $objErr->arrErr = array_merge($objErr->arrErr, |
---|
608 | $objCheckCategory->arrErr); |
---|
609 | } |
---|
610 | } |
---|
611 | return $objErr->arrErr; |
---|
612 | } |
---|
613 | |
---|
614 | /* 確認ページ表示用 */ |
---|
615 | function lfProductConfirmPage() { |
---|
616 | $this->tpl_mainpage = 'products/confirm.tpl'; |
---|
617 | $this->arrForm['mode'] = 'complete'; |
---|
618 | |
---|
619 | $objDb = new SC_Helper_DB_Ex(); |
---|
620 | |
---|
621 | // カテゴリ表示 |
---|
622 | $this->arrCategory_id = $this->arrForm['category_id']; |
---|
623 | $this->arrCatList = array(); |
---|
624 | list($arrCatVal, $arrCatOut) = $objDb->sfGetLevelCatList(false); |
---|
625 | for ($i = 0; $i < count($arrCatVal); $i++) { |
---|
626 | $this->arrCatList[$arrCatVal[$i]] = $arrCatOut[$i]; |
---|
627 | } |
---|
628 | |
---|
629 | // hidden に渡す値は serialize する |
---|
630 | $this->arrForm['category_id'] = serialize($this->arrForm['category_id']); |
---|
631 | |
---|
632 | // Form用配列を渡す。 |
---|
633 | $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL); |
---|
634 | } |
---|
635 | |
---|
636 | /* 規格あり判定用(規格が登録されていない場合:TRUE) */ |
---|
637 | function lfCheckNonClass($product_id) { |
---|
638 | if(SC_Utils_Ex::sfIsInt($product_id)) { |
---|
639 | $objQuery = new SC_Query(); |
---|
640 | $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0"; |
---|
641 | $count = $objQuery->count("dtb_products_class", $where, array($product_id)); |
---|
642 | if($count > 0) { |
---|
643 | return false; |
---|
644 | } |
---|
645 | } |
---|
646 | return true; |
---|
647 | } |
---|
648 | |
---|
649 | // 縮小した画像をセットする |
---|
650 | function lfSetScaleImage(){ |
---|
651 | |
---|
652 | $subno = str_replace("sub_large_image", "", $_POST['image_key']); |
---|
653 | switch ($_POST['image_key']){ |
---|
654 | case "main_large_image": |
---|
655 | // 詳細メイン画像 |
---|
656 | $this->lfMakeScaleImage($_POST['image_key'], "main_image"); |
---|
657 | case "main_image": |
---|
658 | // 一覧メイン画像 |
---|
659 | $this->lfMakeScaleImage($_POST['image_key'], "main_list_image"); |
---|
660 | break; |
---|
661 | case "sub_large_image" . $subno: |
---|
662 | // サブメイン画像 |
---|
663 | $this->lfMakeScaleImage($_POST['image_key'], "sub_image" . $subno); |
---|
664 | break; |
---|
665 | default: |
---|
666 | break; |
---|
667 | } |
---|
668 | } |
---|
669 | |
---|
670 | // 縮小画像生成 |
---|
671 | function lfMakeScaleImage($from_key, $to_key, $forced = false){ |
---|
672 | $arrImageKey = array_flip($this->objUpFile->keyname); |
---|
673 | |
---|
674 | if($this->objUpFile->temp_file[$arrImageKey[$from_key]]){ |
---|
675 | $from_path = $this->objUpFile->temp_dir . $this->objUpFile->temp_file[$arrImageKey[$from_key]]; |
---|
676 | }elseif($this->objUpFile->save_file[$arrImageKey[$from_key]]){ |
---|
677 | $from_path = $this->objUpFile->save_dir . $this->objUpFile->save_file[$arrImageKey[$from_key]]; |
---|
678 | }else{ |
---|
679 | return ""; |
---|
680 | } |
---|
681 | |
---|
682 | if(file_exists($from_path)){ |
---|
683 | // 元画像サイズを取得 |
---|
684 | list($from_w, $from_h) = getimagesize($from_path); |
---|
685 | |
---|
686 | // 生成先の画像サイズを取得 |
---|
687 | $to_w = $this->objUpFile->width[$arrImageKey[$to_key]]; |
---|
688 | $to_h = $this->objUpFile->height[$arrImageKey[$to_key]]; |
---|
689 | |
---|
690 | |
---|
691 | if($forced) $this->objUpFile->save_file[$arrImageKey[$to_key]] = ""; |
---|
692 | |
---|
693 | if(empty($this->objUpFile->temp_file[$arrImageKey[$to_key]]) && |
---|
694 | empty($this->objUpFile->save_file[$arrImageKey[$to_key]])) { |
---|
695 | |
---|
696 | $path = $this->objUpFile->makeThumb($from_path, $to_w, $to_h); |
---|
697 | $this->objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path); |
---|
698 | } |
---|
699 | }else{ |
---|
700 | return ""; |
---|
701 | } |
---|
702 | } |
---|
703 | } |
---|
704 | ?> |
---|