source: branches/version-2_5-dev/data/class/pages/admin/products/LC_Page_Admin_Products_Product.php @ 20501

Revision 20501, 51.5 KB checked in by shutta, 13 years ago (diff)

SC_FormParamクラスのclass_extends対応

  • 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_EX_REALDIR . "page_extends/admin/products/LC_Page_Admin_Products_Ex.php");
26
27/**
28 * 商品登録 のページクラス
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Products_Product extends LC_Page_Admin_Products_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'products/product.tpl';
47        $this->tpl_subnavi = 'products/subnavi.tpl';
48        $this->tpl_mainno = 'products';
49        $this->tpl_subno = 'product';
50        $this->tpl_subtitle = '商品登録';
51
52        $masterData = new SC_DB_MasterData_Ex();
53        $this->arrProductType = $masterData->getMasterData("mtb_product_type");
54        $this->arrDISP = $masterData->getMasterData("mtb_disp");
55        $this->arrCLASS = $masterData->getMasterData("mtb_class");
56        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
57        $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image");
58        $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date");
59        $this->arrMaker = SC_Helper_DB_Ex::sfGetIDValueList("dtb_maker", "maker_id", "name");
60        $this->arrAllowedTag = $masterData->getMasterData("mtb_allowed_tag");
61    }
62
63    /**
64     * Page のプロセス.
65     *
66     * @return void
67     */
68    function process() {
69        $this->action();
70        $this->sendResponse();
71    }
72
73    /**
74     * Page のアクション.
75     *
76     * @return void
77     */
78    function action() {
79        $objFormParam = new SC_FormParam_Ex();
80
81        // アップロードファイル情報の初期化
82        $objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR);
83        $this->lfInitFile($objUpFile);
84        $objUpFile->setHiddenFileList($_POST);
85
86        // ダウンロード販売ファイル情報の初期化
87        $objDownFile = new SC_UploadFile_Ex(DOWN_TEMP_REALDIR, DOWN_SAVE_REALDIR);
88        $this->lfInitDownFile($objDownFile);
89        $objDownFile->setHiddenFileList($_POST);
90
91        // 検索パラメータ引き継ぎ
92        $this->arrSearchHidden = $this->lfGetSearchParam($_POST);
93
94        $mode = $this->getMode();
95        switch($mode) {
96        case 'pre_edit':
97        case 'copy' :
98            // パラメータ初期化(商品ID)
99            $this->lfInitFormParam_PreEdit($objFormParam, $_POST);
100            // エラーチェック
101            $this->arrErr = $objFormParam->checkError();
102            if(count($this->arrErr) > 0) {
103                SC_Utils_Ex::sfDispException();
104            }
105
106            // 商品ID取得
107            $product_id = $objFormParam->getValue('product_id');
108            // 商品データ取得
109            $arrForm = $this->lfGetFormParam_PreEdit($objUpFile, $objDownFile, $product_id);
110            // ページ表示用パラメータ設定
111            $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm);
112
113            // 商品複製の場合、画像ファイルコピー
114            if($mode == "copy") {
115                $this->arrForm["copy_product_id"] = $this->arrForm["product_id"];
116                $this->arrForm["product_id"] = "";
117                // 画像ファイルのコピー
118                $this->lfCopyProductImageFiles($objUpFile);
119            }
120
121            // ページonload時のJavaScript設定
122            $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage();
123            break;
124
125        case 'edit':
126            // パラメータ初期化, 取得
127            $this->lfInitFormParam($objFormParam, $_POST);
128            $arrForm = $objFormParam->getHashArray();
129            // エラーチェック
130            $this->arrErr = $this->lfCheckError_Edit($objFormParam, $objUpFile, $objDownFile, $arrForm);
131            if(count($this->arrErr) == 0) {
132                // 確認画面表示設定
133                $this->tpl_mainpage = 'products/confirm.tpl';
134                $this->arrCatList = $this->lfGetCategoryList_Edit();
135                $this->arrForm = $this->lfSetViewParam_ConfirmPage($objUpFile, $objDownFile, $arrForm);
136            } else {
137                // 入力画面表示設定
138                $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm);
139                // ページonload時のJavaScript設定
140                $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage();
141            }
142            break;
143
144        case 'complete':
145            // パラメータ初期化, 取得
146            $this->lfInitFormParam($objFormParam, $_POST);
147            $arrForm = $this->lfGetFormParam_Complete($objFormParam);
148            // エラーチェック
149            $this->arrErr = $this->lfCheckError_Edit($objFormParam, $objUpFile, $objDownFile, $arrForm);
150            if(count($this->arrErr) == 0) {
151                // DBへデータ登録
152                $product_id = $this->lfRegistProduct($objUpFile, $objDownFile, $arrForm);
153
154                // 件数カウントバッチ実行
155                $objQuery =& SC_Query::getSingletonInstance();
156                $objDb = new SC_Helper_DB_Ex();
157                $objDb->sfCountCategory($objQuery);
158                $objDb->sfCountMaker($objQuery);
159
160                // 一時ファイルを本番ディレクトリに移動する
161                $this->lfSaveUploadFiles($objUpFile, $objDownFile, $product_id);
162
163                $this->tpl_mainpage = 'products/complete.tpl';
164                $this->arrForm['product_id'] = $product_id;
165            } else {
166                // 入力画面表示設定
167                $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm);
168                // ページonload時のJavaScript設定
169                $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage();
170            }
171            break;
172
173        // 画像のアップロード
174        case 'upload_image':
175        case 'delete_image':
176            // パラメータ初期化
177            $this->lfInitFormParam_UploadImage($objFormParam);
178            $this->lfInitFormParam($objFormParam, $_POST);
179            $arrForm = $objFormParam->getHashArray();
180
181            switch($mode) {
182            case 'upload_image':
183                // ファイルを一時ディレクトリにアップロード
184                $this->arrErr[$arrForm['image_key']] = $objUpFile->makeTempFile($arrForm['image_key'], IMAGE_RENAME);
185                if($this->arrErr[$arrForm['image_key']] == "") {
186                    // 縮小画像作成
187                    $this->lfSetScaleImage($objUpFile, $arrForm['image_key']);
188                }
189                break;
190            case 'delete_image':
191                // ファイル削除
192                $this->lfDeleteTempFile($objUpFile, $arrForm['image_key']);
193                break;
194            }
195
196            // 入力画面表示設定
197            $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm);
198            // ページonload時のJavaScript設定
199            $anchor_hash = $this->getAnchorHash($arrForm['image_key']);
200            $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage($anchor_hash);
201            break;
202
203        // ダウンロード商品ファイルアップロード
204        case 'upload_down':
205        case 'delete_down':
206            // パラメータ初期化
207            $this->lfInitFormParam_UploadDown($objFormParam);
208            $this->lfInitFormParam($objFormParam, $_POST);
209            $arrForm = $objFormParam->getHashArray();
210
211            switch($mode) {
212            case 'upload_down':
213                // ファイルを一時ディレクトリにアップロード
214                $this->arrErr[$arrForm['down_key']] = $objDownFile->makeTempDownFile();
215                break;
216            case 'delete_down':
217                // ファイル削除
218                $objDownFile->deleteFile($arrForm['down_key']);
219                break;
220            }
221
222            // 入力画面表示設定
223            $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm);
224            // ページonload時のJavaScript設定
225            $anchor_hash = $this->getAnchorHash($arrForm['down_key']);
226            $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage($anchor_hash);
227            break;
228
229        // 関連商品選択
230        case 'recommend_select' :
231            // パラメータ初期化
232            $this->lfInitFormParam_RecommendSelect($objFormParam);
233            $this->lfInitFormParam($objFormParam, $_POST);
234            $arrForm = $objFormParam->getHashArray();
235            // 入力画面表示設定
236            $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm);
237            // ページonload時のJavaScript設定
238            $anchor_hash = $this->getAnchorHash($arrForm['anchor_key']);
239            $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage($anchor_hash);
240            break;
241
242        // 確認ページからの戻り
243        case 'confirm_return':
244            // パラメータ初期化
245            $this->lfInitFormParam($objFormParam, $_POST);
246            $arrForm = $objFormParam->getHashArray();
247            // 入力画面表示設定
248            $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm);
249            // ページonload時のJavaScript設定
250            $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage();
251            break;
252
253        default:
254            // 入力画面表示設定
255            $arrForm = array();
256            $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm);
257            // ページonload時のJavaScript設定
258            $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage();
259            break;
260        }
261
262        // 関連商品の読み込み
263        $this->arrRecommend = $this->lfGetRecommendProducts($this->arrForm);
264    }
265
266    /**
267     * デストラクタ.
268     *
269     * @return void
270     */
271    function destroy() {
272        parent::destroy();
273    }
274
275    /**
276     * パラメータ情報の初期化
277     * - 編集/複製モード
278     *
279     * @param object $objFormParam SC_FormParamインスタンス
280     * @param array $arrPost $_POSTデータ
281     * @return void
282     */
283    function lfInitFormParam_PreEdit(&$objFormParam, $arrPost) {
284        $objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
285        $objFormParam->setParam($arrPost);
286        $objFormParam->convParam();
287    }
288
289    /**
290     * パラメータ情報の初期化
291     *
292     * @param object $objFormParam SC_FormParamインスタンス
293     * @param array $arrPost $_POSTデータ
294     * @return void
295     */
296    function lfInitFormParam(&$objFormParam, $arrPost) {
297        $objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
298        $objFormParam->addParam("商品名", "name", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
299        $objFormParam->addParam("商品カテゴリ", "category_id", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
300        $objFormParam->addParam("公開・非公開", "status", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
301        $objFormParam->addParam("商品ステータス", "product_status", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
302
303        if($this->lfGetProductClassFlag($arrPost['has_product_class']) == false) {
304            // 新規登録, 規格なし商品の編集の場合
305            $objFormParam->addParam("商品種別", "product_type_id", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
306            $objFormParam->addParam("ダウンロード商品ファイル名", "down_filename", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
307            $objFormParam->addParam("ダウンロード商品実ファイル名", "down_realfilename", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
308            $objFormParam->addParam("temp_down_file", "temp_down_file", '', "", array());
309            $objFormParam->addParam("save_down_file", "save_down_file", '', "", array());
310            $objFormParam->addParam("商品コード", "product_code", STEXT_LEN, "KVna", array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK"));
311            $objFormParam->addParam(NORMAL_PRICE_TITLE, "price01", PRICE_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
312            $objFormParam->addParam(SALE_PRICE_TITLE, "price02", PRICE_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
313            $objFormParam->addParam("在庫数", "stock", AMOUNT_LEN, "n", array("SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
314            $objFormParam->addParam("在庫無制限", "stock_unlimited", INT_LEN, "n", array("SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
315        }
316        $objFormParam->addParam("商品送料", "deliv_fee", PRICE_LEN, "n", array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
317        $objFormParam->addParam("ポイント付与率", "point_rate", PERCENTAGE_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
318        $objFormParam->addParam("発送日目安", "deliv_date_id", INT_LEN, "n", array("NUM_CHECK"));
319        $objFormParam->addParam("購入制限", "sale_limit", AMOUNT_LEN, "n", array("SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
320        $objFormParam->addParam("メーカー", "maker_id", INT_LEN, "n", array("NUM_CHECK"));
321        $objFormParam->addParam("メーカーURL", "comment1", URL_LEN, "a", array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK"));
322        $objFormParam->addParam("検索ワード", "comment3", LLTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
323        $objFormParam->addParam("備考欄(SHOP専用)", "note", LLTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
324        $objFormParam->addParam("一覧-メインコメント", "main_list_comment", MTEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
325        $objFormParam->addParam("詳細-メインコメント", "main_comment", LLTEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
326        $objFormParam->addParam("save_main_list_image", "save_main_list_image", '', "", array());
327        $objFormParam->addParam("save_main_image", "save_main_image", '', "", array());
328        $objFormParam->addParam("save_main_large_image", "save_main_large_image", '', "", array());
329        $objFormParam->addParam("temp_main_list_image", "temp_main_list_image", '', "", array());
330        $objFormParam->addParam("temp_main_image", "temp_main_image", '', "", array());
331        $objFormParam->addParam("temp_main_large_image", "temp_main_large_image", '', "", array());
332
333        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
334            $objFormParam->addParam("詳細-サブタイトル" . $cnt, "sub_title" . $cnt, STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
335            $objFormParam->addParam("詳細-サブコメント" . $cnt, "sub_comment" . $cnt, LLTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
336            $objFormParam->addParam("save_sub_image" . $cnt, "save_sub_image" . $cnt, '', "", array());
337            $objFormParam->addParam("save_sub_large_image" . $cnt, "save_sub_large_image" . $cnt, '', "", array());
338            $objFormParam->addParam("temp_sub_image" . $cnt, "temp_sub_image" . $cnt, '', "", array());
339            $objFormParam->addParam("temp_sub_large_image" . $cnt, "temp_sub_large_image" . $cnt, '', "", array());
340        }
341
342        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
343            $objFormParam->addParam("関連商品コメント" . $cnt, "recommend_comment" . $cnt, LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
344            $objFormParam->addParam("関連商品ID" . $cnt, "recommend_id" . $cnt, INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
345            $objFormParam->addParam("recommend_delete" . $cnt, "recommend_delete" . $cnt, '', "n", array());
346        }
347
348                $objFormParam->addParam("商品ID", "copy_product_id", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
349
350        $objFormParam->addParam("has_product_class", "has_product_class", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
351        $objFormParam->addParam("product_class_id", "product_class_id", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
352
353        $objFormParam->setParam($arrPost);
354        $objFormParam->convParam();
355    }
356
357    /**
358     * パラメータ情報の初期化
359     * - 画像ファイルアップロードモード
360     *
361     * @param object $objFormParam SC_FormParamインスタンス
362     * @return void
363     */
364    function lfInitFormParam_UploadImage(&$objFormParam) {
365        $objFormParam->addParam("image_key", "image_key", "", "", array());
366    }
367
368    /**
369     * パラメータ情報の初期化
370     * - ダウンロード商品ファイルアップロードモード
371     *
372     * @param object $objFormParam SC_FormParamインスタンス
373     * @return void
374     */
375    function lfInitFormParam_UploadDown(&$objFormParam) {
376        $objFormParam->addParam("down_key", "down_key", "", "", array());
377    }
378
379    /**
380     * パラメータ情報の初期化
381     * - 関連商品追加モード
382     *
383     * @param object $objFormParam SC_FormParamインスタンス
384     * @return void
385     */
386    function lfInitFormParam_RecommendSelect(&$objFormParam) {
387        $objFormParam->addParam("anchor_key", "anchor_key", "", "", array());
388    }
389
390    /**
391     * アップロードファイルパラメータ情報の初期化
392     * - 画像ファイル用
393     *
394     * @param object $objUpFile SC_UploadFileインスタンス
395     * @return void
396     */
397    function lfInitFile(&$objUpFile) {
398        $objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg', 'gif', 'png'),IMAGE_SIZE, false, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
399        $objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
400        $objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT);
401        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
402            $objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_WIDTH, NORMAL_SUBIMAGE_HEIGHT);
403            $objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_SUBIMAGE_WIDTH, LARGE_SUBIMAGE_HEIGHT);
404        }
405    }
406
407    /**
408     * アップロードファイルパラメータ情報の初期化
409     * - ダウンロード商品ファイル用
410     *
411     * @param object $objDownFile SC_UploadFileインスタンス
412     * @return void
413     */
414    function lfInitDownFile(&$objDownFile) {
415        $objDownFile->addFile("ダウンロード販売用ファイル", 'down_file', explode(",", DOWNLOAD_EXTENSION),DOWN_SIZE, true, 0, 0);
416    }
417
418    /**
419     * フォーム入力パラメータのエラーチェック
420     *
421     * @param object $objFormParam SC_FormParamインスタンス
422     * @param object $objUpFile SC_UploadFileインスタンス
423     * @param object $objDownFile SC_UploadFileインスタンス
424     * @param array $arrForm フォーム入力パラメータ配列
425     * @return array エラー情報を格納した連想配列
426     */
427    function lfCheckError_Edit(&$objFormParam, &$objUpFile, &$objDownFile, $arrForm) {
428        $objErr = new SC_CheckError($arrForm);
429        $arrErr = array();
430
431        // 入力パラメータチェック
432        $arrErr = $objFormParam->checkError();
433
434        // アップロードファイル必須チェック
435        $arrErr = array_merge((array)$arrErr, (array)$objUpFile->checkEXISTS());
436
437        // HTMLタグ許可チェック
438        $objErr->doFunc(array("詳細-メインコメント", "main_comment", $this->arrAllowedTag), array("HTML_TAG_CHECK"));
439        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
440            $objErr->doFunc(array("詳細-サブコメント" . $cnt, "sub_comment" . $cnt, $this->arrAllowedTag), array("HTML_TAG_CHECK"));
441        }
442
443        // 規格情報がない商品の場合のチェック
444        if($arrForm['has_product_class'] != true) {
445            // 在庫必須チェック(在庫無制限ではない場合)
446            if(!isset($arrForm['stock_unlimited']) && $arrForm['stock_unlimited'] != UNLIMITED_FLG_UNLIMITED) {
447                $objErr->doFunc(array("在庫数", "stock"), array("EXIST_CHECK"));
448            }
449            // ダウンロード商品ファイル必須チェック(ダウンロード商品の場合)
450            if($arrForm['product_type_id'] == PRODUCT_TYPE_DOWNLOAD) {
451                $arrErr = array_merge((array)$arrErr, (array)$objDownFile->checkEXISTS());
452            }
453        }
454
455        $arrErr = array_merge((array)$arrErr, (array)$objErr->arrErr);
456        return $arrErr;
457    }
458
459    /**
460     * 検索パラメータ引き継ぎ用配列取得
461     *
462     * @param array $arrPost $_POSTデータ
463     * @return array 検索パラメータ配列
464     */
465    function lfGetSearchParam($arrPost) {
466        $arrSearchParam = array();
467        $objFormParam = new SC_FormParam_Ex();
468
469        parent::lfInitParam($objFormParam);
470        $objFormParam->setParam($arrPost);
471        $arrSearchParam = $objFormParam->getSearchArray();
472
473        return $arrSearchParam;
474    }
475
476    /**
477     * フォームパラメータ取得
478     * - 編集/複製モード
479     *
480     * @param object $objUpFile SC_UploadFileインスタンス
481     * @param object $objDownFile SC_UploadFileインスタンス
482     * @param integer $product_id 商品ID
483     * @return array フォームパラメータ配列
484     */
485    function lfGetFormParam_PreEdit(&$objUpFile, &$objDownFile, $product_id) {
486        $arrForm = array();
487
488        // DBから商品データ取得
489        $arrForm = $this->lfGetProductData_FromDB($product_id);
490        // DBデータから画像ファイル名の読込
491        $objUpFile->setDBFileList($arrForm);
492        // DBデータからダウンロードファイル名の読込
493        $objDownFile->setDBDownFile($arrForm);
494
495        return $arrForm;
496    }
497
498    /**
499     * フォームパラメータ取得
500     * - 登録モード
501     *
502     * @param object $objFormParam SC_FormParamインスタンス
503     * @return array フォームパラメータ配列
504     */
505    function lfGetFormParam_Complete(&$objFormParam) {
506        $arrForm = $objFormParam->getHashArray();
507        $arrForm['category_id'] = unserialize($arrForm['category_id']);
508        $objFormParam->setValue('category_id', $arrForm['category_id']);
509
510        return $arrForm;
511    }
512
513    /**
514     * 表示用フォームパラメータ取得
515     * - 入力画面
516     *
517     * @param object $objUpFile SC_UploadFileインスタンス
518     * @param object $objDownFile SC_UploadFileインスタンス
519     * @param array $arrForm フォーム入力パラメータ配列
520     * @return array 表示用フォームパラメータ配列
521     */
522    function lfSetViewParam_InputPage(&$objUpFile, &$objDownFile, &$arrForm) {
523        // カテゴリマスタデータ取得
524        $objDb = new SC_Helper_DB_Ex();
525        list($this->arrCatVal, $this->arrCatOut) = $objDb->sfGetLevelCatList(false);
526
527        if (isset($arrForm['category_id']) && !is_array($arrForm['category_id'])) {
528            $arrForm['category_id'] = unserialize($arrForm['category_id']);
529        }
530        if($arrForm['status'] == "") {
531            $arrForm['status'] = DEFAULT_PRODUCT_DISP;
532        }
533        if($arrForm['product_type_id'] == "") {
534            $arrForm['product_type_id'] = DEFAULT_PRODUCT_DOWN;
535        }
536        // アップロードファイル情報取得(Hidden用)
537        $arrHidden = $objUpFile->getHiddenFileList();
538        $arrForm['arrHidden'] = array_merge((array)$arrHidden, (array)$objDownFile->getHiddenFileList());
539
540        // 画像ファイル表示用データ取得
541        $arrForm['arrFile'] = $objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH);
542
543        // ダウンロード商品実ファイル名取得
544        $arrForm['down_realfilename'] = $objDownFile->getFormDownFile();
545
546        // 基本情報(デフォルトポイントレート用)
547        $arrForm['arrInfo'] = SC_Helper_DB_Ex::sfGetBasisData();
548
549        // サブ情報ありなしフラグ
550        $arrForm['sub_find'] = $this->hasSubProductData($arrForm);
551
552        return $arrForm;
553    }
554
555    /**
556     * 表示用フォームパラメータ取得
557     * - 確認画面
558     *
559     * @param object $objUpFile SC_UploadFileインスタンス
560     * @param object $objDownFile SC_UploadFileインスタンス
561     * @param array $arrForm フォーム入力パラメータ配列
562     * @return array 表示用フォームパラメータ配列
563     */
564    function lfSetViewParam_ConfirmPage(&$objUpFile, &$objDownFile, &$arrForm) {
565        // カテゴリ表示用
566        $arrForm['arrCategoryId'] = $arrForm['category_id'];
567        // hidden に渡す値は serialize する
568        $arrForm['category_id'] = serialize($arrForm['category_id']);
569        // 画像ファイル用データ取得
570        $arrForm['arrFile'] = $objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH);
571        // ダウンロード商品実ファイル名取得
572        $arrForm['down_realfilename'] = $objDownFile->getFormDownFile();
573
574        return $arrForm;
575    }
576
577    /**
578     * 縮小した画像をセットする
579     *
580     * @param object $objUpFile SC_UploadFileインスタンス
581     * @param string $image_key 画像ファイルキー
582     * @return void
583     */
584    function lfSetScaleImage(&$objUpFile, $image_key){
585        $subno = str_replace("sub_large_image", "", $image_key);
586        switch ($image_key){
587        case "main_large_image":
588            // 詳細メイン画像
589            $this->lfMakeScaleImage($objUpFile, $image_key, "main_image");
590        case "main_image":
591            // 一覧メイン画像
592            $this->lfMakeScaleImage($objUpFile, $image_key, "main_list_image");
593            break;
594        case "sub_large_image" . $subno:
595            // サブメイン画像
596            $this->lfMakeScaleImage($objUpFile, $_POST['image_key'], "sub_image" . $subno);
597            break;
598        default:
599            break;
600        }
601    }
602
603    /**
604     * 画像ファイルのコピー
605     *
606     * @param object $objUpFile SC_UploadFileインスタンス
607     * @return void
608     */
609    function lfCopyProductImageFiles(&$objUpFile) {
610        $arrKey = $objUpFile->keyname;
611        $arrSaveFile = $objUpFile->save_file;
612
613        foreach($arrSaveFile as $key => $val){
614            $this->lfMakeScaleImage($objUpFile, $arrKey[$key], $arrKey[$key], true);
615        }
616    }
617
618    /**
619     * 縮小画像生成
620     *
621     * @param object $objUpFile SC_UploadFileインスタンス
622     * @param string $from_key 元画像ファイルキー
623     * @param string $to_key 縮小画像ファイルキー
624     * @param boolean $forced
625     * @return void
626     */
627    function lfMakeScaleImage(&$objUpFile, $from_key, $to_key, $forced = false){
628        $arrImageKey = array_flip($objUpFile->keyname);
629        $from_path = "";
630
631        if($objUpFile->temp_file[$arrImageKey[$from_key]]) {
632            $from_path = $objUpFile->temp_dir . $objUpFile->temp_file[$arrImageKey[$from_key]];
633        } elseif($objUpFile->save_file[$arrImageKey[$from_key]]){
634            $from_path = $objUpFile->save_dir . $objUpFile->save_file[$arrImageKey[$from_key]];
635        }
636
637        if(file_exists($from_path)) {
638            // 生成先の画像サイズを取得
639            $to_w = $objUpFile->width[$arrImageKey[$to_key]];
640            $to_h = $objUpFile->height[$arrImageKey[$to_key]];
641
642            if($forced) $objUpFile->save_file[$arrImageKey[$to_key]] = "";
643
644            if(empty($objUpFile->temp_file[$arrImageKey[$to_key]])
645                    && empty($objUpFile->save_file[$arrImageKey[$to_key]])) {
646                // リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
647                $dst_file = $objUpFile->lfGetTmpImageName(IMAGE_RENAME, "", $objUpFile->temp_file[$arrImageKey[$from_key]]) . $this->lfGetAddSuffix($to_key);
648                $path = $objUpFile->makeThumb($from_path, $to_w, $to_h, $dst_file);
649                $objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path);
650            }
651        }
652    }
653
654    /**
655     * アップロードファイルパラメータ情報から削除
656     * 一時ディレクトリに保存されている実ファイルも削除する
657     *
658     * @param object $objUpFile SC_UploadFileインスタンス
659     * @param string $image_key 画像ファイルキー
660     * @return void
661     */
662    function lfDeleteTempFile(&$objUpFile, $image_key) {
663        // TODO: SC_UploadFile::deleteFileの画像削除条件見直し要
664        $arrTempFile = $objUpFile->temp_file;
665        $arrKeyName = $objUpFile->keyname;
666
667        foreach($arrKeyName as $key => $keyname) {
668            if($keyname != $image_key) continue;
669
670            if(!empty($arrTempFile[$key])) {
671                $temp_file = $arrTempFile[$key];
672                $arrTempFile[$key] = '';
673
674                if(!in_array($temp_file, $arrTempFile)) {
675                    $objUpFile->deleteFile($image_key);
676                } else {
677                    $objUpFile->temp_file[$key] = '';
678                    $objUpFile->save_file[$key] = '';
679                }
680            } else {
681                $objUpFile->temp_file[$key] = '';
682                $objUpFile->save_file[$key] = '';
683            }
684        }
685    }
686
687    /**
688     * アップロードファイルを保存する
689     *
690     * @param object $objUpFile SC_UploadFileインスタンス
691     * @param object $objDownFile SC_UploadFileインスタンス
692     * @param integer $product_id 商品ID
693     * @return void
694     */
695    function lfSaveUploadFiles(&$objUpFile, &$objDownFile, $product_id) {
696        // TODO: SC_UploadFile::moveTempFileの画像削除条件見直し要
697        $objImage = new SC_Image_Ex($objUpFile->temp_dir);
698        $arrKeyName = $objUpFile->keyname;
699        $arrTempFile = $objUpFile->temp_file;
700        $arrSaveFile = $objUpFile->save_file;
701        $arrImageKey = array();
702        foreach($arrTempFile as $key => $temp_file) {
703            if($temp_file) {
704                $objImage->moveTempImage($temp_file, $objUpFile->save_dir);
705                $arrImageKey[] = $arrKeyName[$key];
706                if(!empty($arrSaveFile[$key])
707                        && !$this->lfHasSameProductImage($product_id, $arrImageKey, $arrSaveFile[$key])
708                        && !in_array($temp_file, $arrSaveFile)) {
709                    $objImage->deleteImage($arrSaveFile[$key], $objUpFile->save_dir);
710                }
711            }
712        }
713        $objDownFile->moveTempDownFile();
714    }
715
716    /**
717     * 同名画像ファイル登録の有無を確認する.
718     *
719     * 画像ファイルの削除可否判定用。
720     * 同名ファイルの登録がある場合には画像ファイルの削除を行わない。
721     * 戻り値:同名ファイル有り(true) 同名ファイル無し(false)
722     *
723     * @param string $product_id 商品ID
724     * @param string $arrImageKey 対象としない画像カラム名
725     * @param string $image_file_name 画像ファイル名
726     * @return boolean
727     */
728    function lfHasSameProductImage($product_id, $arrImageKey, $image_file_name) {
729        if (!SC_Utils_Ex::sfIsInt($product_id)) return false;
730        if (!$arrImageKey) return false;
731        if (!$image_file_name) return false;
732
733        $arrWhere = array();
734        $sqlval = array('0', $product_id);
735        foreach ($arrImageKey as $image_key) {
736            $arrWhere[] = "{$image_key} = ?";
737            $sqlval[] = $image_file_name;
738        }
739        $where = implode(" OR ", $arrWhere);
740        $where = "del_flg = ? AND ((product_id <> ? AND ({$where}))";
741
742        $arrKeyName = $this->objUpFile->keyname;
743        foreach ($arrKeyName as $key => $keyname) {
744            if (in_array($keyname, $arrImageKey)) continue;
745            $where .= " OR {$keyname} = ?";
746            $sqlval[] = $image_file_name;
747        }
748        $where .= ")";
749
750        $objQuery = new SC_Query();
751        $count = $objQuery->count('dtb_products', $where, $sqlval);
752        if (!$count) return false;
753        return true;
754    }
755
756    /**
757     * DBから商品データを取得する
758     *
759     * @param integer $product_id 商品ID
760     * @return array 商品データ配列
761     */
762    function lfGetProductData_FromDB($product_id) {
763        $objQuery =& SC_Query::getSingletonInstance();
764        $arrProduct = array();
765
766        // 商品データ取得
767        $col = "*";
768        $table = <<< __EOF__
769                      dtb_products AS T1
770            LEFT JOIN (
771                       SELECT product_id AS product_id_sub,
772                              product_code,
773                              price01,
774                              price02,
775                              deliv_fee,
776                              stock,
777                              stock_unlimited,
778                              sale_limit,
779                              point_rate,
780                              product_type_id,
781                              down_filename,
782                              down_realfilename
783                        FROM dtb_products_class
784                        WHERE class_combination_id IS NULL
785                       ) AS T2
786                     ON T1.product_id = T2.product_id_sub
787__EOF__;
788        $where = "product_id = ?";
789        $arrProduct = $objQuery->select($col, $table, $where, array($product_id));
790
791        // カテゴリID取得
792        $col = "category_id";
793        $table = "dtb_product_categories";
794        $where = "product_id = ?";
795        $arrProduct[0]['category_id'] = $objQuery->getCol($col, $table, $where, array($product_id));
796
797        // 規格情報ありなしフラグ取得
798        $objDb = new SC_Helper_DB_Ex();
799        $arrProduct[0]['has_product_class'] = $objDb->sfHasProductClass($product_id);
800
801        // 規格が登録されていなければ規格ID取得
802        if ($arrProduct[0]['has_product_class'] == false) {
803            $arrProduct[0]['product_class_id'] = SC_Utils_Ex::sfGetProductClassId($product_id,"0","0");
804        }
805
806        // 商品ステータス取得
807        $objProduct = new SC_Product_Ex();
808        $productStatus = $objProduct->getProductStatus(array($product_id));
809        $arrProduct[0]['product_status'] = $productStatus[$product_id];
810
811        // 関連商品データ取得
812        $arrRecommend = $this->lfGetRecommendProductsData_FromDB($product_id);
813        $arrProduct[0] = array_merge($arrProduct[0], $arrRecommend);
814
815        return $arrProduct[0];
816    }
817
818    /**
819     * DBから関連商品データを取得する
820     *
821     * @param integer $product_id 商品ID
822     * @return array 関連商品データ配列
823     */
824    function lfGetRecommendProductsData_FromDB($product_id) {
825        $objQuery =& SC_Query::getSingletonInstance();
826        $arrRecommendProducts = array();
827
828        $col = 'recommend_product_id,';
829        $col.= 'comment';
830        $table = 'dtb_recommend_products';
831        $where = 'product_id = ?';
832        $objQuery->setOrder("rank DESC");
833        $arrRet = $objQuery->select($col, $table, $where, array($product_id));
834
835        $no = 1;
836        foreach ($arrRet as $arrVal) {
837            $arrRecommendProducts['recommend_id' . $no] = $arrVal['recommend_product_id'];
838            $arrRecommendProducts['recommend_comment' . $no] = $arrVal['comment'];
839            $no++;
840        }
841
842        return $arrRecommendProducts;
843    }
844
845    /**
846     * 関連商品データ表示用配列を取得する
847     *
848     * @param string $arrForm フォーム入力パラメータ配列
849     * @return array 関連商品データ配列
850     */
851    function lfGetRecommendProducts(&$arrForm) {
852        $arrRecommend = array();
853
854        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
855            $keyname = "recommend_id" . $i;
856            $delkey = "recommend_delete" . $i;
857            $commentkey = "recommend_comment" . $i;
858
859            if (!isset($arrForm[$delkey])) $arrForm[$delkey] = null;
860
861            if((isset($arrForm[$keyname]) && !empty($arrForm[$keyname])) && $arrForm[$delkey] != 1) {
862                $objProduct = new SC_Product_Ex();
863                $arrRecommend[$i] = $objProduct->getDetail($arrForm[$keyname]);
864                $arrRecommend[$i]['product_id'] = $arrForm[$keyname];
865                $arrRecommend[$i]['comment'] = $arrForm[$commentkey];
866            }
867        }
868        return $arrRecommend;
869    }
870
871    /**
872     * 表示用カテゴリマスタデータ配列を取得する
873     * - 編集モード
874     *
875     * @param void
876     * @return array カテゴリマスタデータ配列
877     */
878    function lfGetCategoryList_Edit() {
879        $objDb = new SC_Helper_DB_Ex();
880        $arrCategoryList = array();
881
882        list($arrCatVal, $arrCatOut) = $objDb->sfGetLevelCatList(false);
883        for ($i = 0; $i < count($arrCatVal); $i++) {
884            $arrCategoryList[$arrCatVal[$i]] = $arrCatOut[$i];
885        }
886
887        return $arrCategoryList;
888    }
889
890    /**
891     * 入力フォームパラメータの規格ありなしフラグを判定
892     *
893     * @param string $has_product_class 入力フォームパラメータの規格ありなしフラグ
894     * @return boolean true: 規格あり, false: 規格なし
895     */
896    function lfGetProductClassFlag($has_product_class) {
897        if($has_product_class == '1') {
898            return true;
899        } else {
900            return false;
901        }
902    }
903
904    /**
905     * ページonload用JavaScriptを取得する
906     * - 入力画面
907     *
908     * @param string $anchor_hash アンカー用ハッシュ文字列(省略可)
909     * @return string ページonload用JavaScript
910     */
911    function lfSetOnloadJavaScript_InputPage($anchor_hash = "") {
912        return "fnCheckStockLimit('" . DISABLED_RGB . "'); fnMoveSelect('category_id_unselect', 'category_id');" . $anchor_hash;
913    }
914
915    /**
916     * DBに商品データを登録する
917     *
918     * @param object $objUpFile SC_UploadFileインスタンス
919     * @param object $objDownFile SC_UploadFileインスタンス
920     * @param array $arrList フォーム入力パラメータ配列
921     * @return integer 登録商品ID
922     */
923    function lfRegistProduct(&$objUpFile, &$objDownFile, $arrList) {
924        $objQuery =& SC_Query::getSingletonInstance();
925        $objDb = new SC_Helper_DB_Ex();
926
927        // 配列の添字を定義
928        $checkArray = array("name", "status",
929                            "main_list_comment", "main_comment",
930                            "deliv_fee", "comment1", "comment2", "comment3",
931                            "comment4", "comment5", "comment6", "main_list_comment",
932                            "sale_limit", "deliv_date_id", "maker_id", "note");
933        $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray);
934
935        // INSERTする値を作成する。
936        $sqlval['name'] = $arrList['name'];
937        $sqlval['status'] = $arrList['status'];
938        $sqlval['main_list_comment'] = $arrList['main_list_comment'];
939        $sqlval['main_comment'] = $arrList['main_comment'];
940        $sqlval['comment1'] = $arrList['comment1'];
941        $sqlval['comment2'] = $arrList['comment2'];
942        $sqlval['comment3'] = $arrList['comment3'];
943        $sqlval['comment4'] = $arrList['comment4'];
944        $sqlval['comment5'] = $arrList['comment5'];
945        $sqlval['comment6'] = $arrList['comment6'];
946        $sqlval['main_list_comment'] = $arrList['main_list_comment'];
947        $sqlval['deliv_date_id'] = $arrList['deliv_date_id'];
948        $sqlval['maker_id'] = $arrList['maker_id'];
949        $sqlval['note'] = $arrList['note'];
950        $sqlval['update_date'] = "Now()";
951        $sqlval['creator_id'] = $_SESSION['member_id'];
952        $arrRet = $objUpFile->getDBFileList();
953        $sqlval = array_merge($sqlval, $arrRet);
954
955        for($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
956            $sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt];
957            $sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt];
958        }
959
960        $objQuery->begin();
961
962        // 新規登録(複製時を含む)
963        if($arrList['product_id'] == "") {
964            $product_id = $objQuery->nextVal("dtb_products_product_id");
965            $sqlval['product_id'] = $product_id;
966
967            // INSERTの実行
968            $sqlval['create_date'] = "Now()";
969            $objQuery->insert("dtb_products", $sqlval);
970
971            $arrList['product_id'] = $product_id;
972
973            // カテゴリを更新
974            $objDb->updateProductCategories($arrList['category_id'], $product_id);
975
976            // 複製商品の場合には規格も複製する
977            if($arrList["copy_product_id"] != "" && SC_Utils_Ex::sfIsInt($arrList["copy_product_id"])) {
978                if($arrList["has_product_class"] == "1") {
979                    //規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う
980                    $this->lfCopyProductClass($arrList, $objQuery);
981                } else {
982                    //規格がある場合の複製は複製元の内容で追加登録を行う
983                    // dtb_products_class のカラムを取得
984                    $dbFactory = SC_DB_DBFactory_Ex::getInstance();
985                    $arrColList = $dbFactory->sfGetColumnList("dtb_products_class", $objQuery);
986                    $arrColList_tmp = array_flip($arrColList);
987
988                    // 複製しない列
989                    unset($arrColList[$arrColList_tmp["product_class_id"]]);     //規格ID
990                    unset($arrColList[$arrColList_tmp["product_id"]]);           //商品ID
991                    unset($arrColList[$arrColList_tmp["create_date"]]);
992
993                    $col = SC_Utils_Ex::sfGetCommaList($arrColList);
994                    $product_class_id = $objQuery->nextVal('dtb_products_class_product_class_id');
995                    $objQuery->query("INSERT INTO dtb_products_class (product_class_id, product_id, create_date, ". $col .") SELECT ?, now(), " . $col. " FROM dtb_products_class WHERE product_id = ? ORDER BY product_class_id", array($product_class_id, $product_id, $arrList["copy_product_id"]));
996                }
997            }
998        // 更新
999        } else {
1000            $product_id = $arrList['product_id'];
1001            // 削除要求のあった既存ファイルの削除
1002            $arrRet = $this->lfGetProductData_FromDB($arrList['product_id']);
1003            // TODO: SC_UploadFile::deleteDBFileの画像削除条件見直し要
1004            $objImage = new SC_Image_Ex($objUpFile->temp_dir);
1005            $arrKeyName = $objUpFile->keyname;
1006            $arrSaveFile = $objUpFile->save_file;
1007            $arrImageKey = array();
1008            foreach ($arrKeyName as $key => $keyname) {
1009                if ($arrRet[$keyname] && !$arrSaveFile[$key]) {
1010                    $arrImageKey[] = $keyname;
1011                    $has_same_image = $this->lfHasSameProductImage($arrList['product_id'], $arrImageKey, $arrRet[$keyname]);
1012                    if (!$has_same_image) {
1013                        $objImage->deleteImage($arrRet[$keyname], $objUpFile->save_dir);
1014                    }
1015                }
1016            }
1017            $objDownFile->deleteDBDownFile($arrRet);
1018            // UPDATEの実行
1019            $where = "product_id = ?";
1020            $objQuery->update("dtb_products", $sqlval, $where, array($product_id));
1021
1022            // カテゴリを更新
1023            $objDb->updateProductCategories($arrList['category_id'], $product_id);
1024        }
1025
1026        //商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。
1027        if($arrList["copy_product_id"] == "") {
1028            // 規格登録
1029            $this->lfInsertDummyProductClass($arrList);
1030        }
1031
1032        // ステータス設定
1033        $objProduct = new SC_Product_Ex();
1034        $objProduct->setProductStatus($product_id, $arrList['product_status']);
1035
1036        // 関連商品登録
1037        $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id);
1038
1039        $objQuery->commit();
1040        return $product_id;
1041    }
1042
1043    /**
1044     * 規格を設定していない商品を商品規格テーブルに登録
1045     *
1046     * @param array $arrList
1047     * @return void
1048     */
1049    function lfInsertDummyProductClass($arrList) {
1050        $objQuery = new SC_Query();
1051        $objDb = new SC_Helper_DB_Ex();
1052
1053        $product_id = $arrList['product_id'];
1054        // 規格登録してある商品の場合、処理しない
1055        if ($objDb->sfHasProductClass($product_id)) return;
1056
1057        // 配列の添字を定義
1058        $checkArray = array('product_class_id', 'product_id', 'product_code', 'stock', 'stock_unlimited', 'price01', 'price02', 'sale_limit', 'deliv_fee', 'point_rate' ,'product_type_id', 'down_filename', 'down_realfilename');
1059        $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $checkArray);
1060        $sqlval = SC_Utils_Ex::arrayDefineIndexes($sqlval, $checkArray);
1061
1062        $sqlval['stock_unlimited'] = $sqlval['stock_unlimited'] ? UNLIMITED_FLG_UNLIMITED : UNLIMITED_FLG_LIMITED;
1063        $sqlval['creator_id'] = strlen($_SESSION['member_id']) >= 1 ? $_SESSION['member_id'] : '0';
1064
1065        if (strlen($sqlval['product_class_id']) == 0) {
1066            $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id');
1067            $sqlval['create_date'] = 'now()';
1068            $sqlval['update_date'] = 'now()';
1069            // INSERTの実行
1070            $objQuery->insert('dtb_products_class', $sqlval);
1071        } else {
1072            $sqlval['update_date'] = 'now()';
1073            // UPDATEの実行
1074            $objQuery->update('dtb_products_class', $sqlval, "product_class_id = ?", array($sqlval['product_class_id']));
1075
1076        }
1077    }
1078
1079    /**
1080     * DBに関連商品データを登録する
1081     *
1082     * @param object $objQuery SC_Queryインスタンス
1083     * @param string $arrList フォーム入力パラメータ配列
1084     * @param integer $product_id 登録する商品ID
1085     * @return void
1086     */
1087    function lfInsertRecommendProducts($objQuery, $arrList, $product_id) {
1088        // 一旦関連商品をすべて削除する
1089        $objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id));
1090        $sqlval['product_id'] = $product_id;
1091        $rank = RECOMMEND_PRODUCT_MAX;
1092        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
1093            $keyname = "recommend_id" . $i;
1094            $commentkey = "recommend_comment" . $i;
1095            $deletekey = "recommend_delete" . $i;
1096
1097            if (!isset($arrList[$deletekey])) $arrList[$deletekey] = null;
1098
1099            if($arrList[$keyname] != "" && $arrList[$deletekey] != '1') {
1100                $sqlval['recommend_product_id'] = $arrList[$keyname];
1101                $sqlval['comment'] = $arrList[$commentkey];
1102                $sqlval['rank'] = $rank;
1103                $sqlval['creator_id'] = $_SESSION['member_id'];
1104                $sqlval['create_date'] = "now()";
1105                $sqlval['update_date'] = "now()";
1106                $objQuery->insert("dtb_recommend_products", $sqlval);
1107                $rank--;
1108            }
1109        }
1110    }
1111
1112    /**
1113     * 規格データをコピーする
1114     *
1115     * @param array $arrList フォーム入力パラメータ配列
1116     * @param object $objQuery SC_Queryインスタンス
1117     * @return boolean エラーフラグ
1118     */
1119    function lfCopyProductClass($arrList, $objQuery) {
1120        // 複製元のdtb_products_classを取得(規格なしのため、1件のみの取得)
1121        $col = "*";
1122        $table = "dtb_products_class";
1123        $where = "product_id = ?";
1124        $arrProductClass = $objQuery->select($col, $table, $where, array($arrList["copy_product_id"]));
1125
1126        //トランザクション開始
1127        $objQuery->begin();
1128        $err_flag = false;
1129        //非編集項目は複製、編集項目は上書きして登録
1130        foreach($arrProductClass as $records) {
1131            foreach($records as $key => $value) {
1132                if(isset($arrList[$key])) {
1133                    $records[$key] = $arrList[$key];
1134                }
1135            }
1136
1137            $records["product_class_id"] = $objQuery->nextVal('dtb_products_class_product_class_id');
1138            $records["update_date"] = 'now()';
1139            $records["create_date"] = "Now()";
1140            $objQuery->insert($table, $records);
1141            //エラー発生時は中断
1142            if($objQuery->isError()) {
1143                $err_flag = true;
1144                continue;
1145            }
1146        }
1147        //トランザクション終了
1148        if($err_flag) {
1149            $objQuery->rollback();
1150        } else {
1151            $objQuery->commit();
1152        }
1153        return !$err_flag;
1154    }
1155
1156    /**
1157     * リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
1158     *
1159     * @param string $to_key
1160     * @return string
1161     */
1162    function lfGetAddSuffix($to_key){
1163        if( IMAGE_RENAME === true ) return ;
1164
1165        // 自動生成される画像名
1166        $dist_name = "";
1167        switch($to_key) {
1168        case "main_list_image":
1169            $dist_name = '_s';
1170            break;
1171        case "main_image":
1172            $dist_name = '_m';
1173            break;
1174        default:
1175            $arrRet = explode('sub_image', $to_key);
1176            $dist_name = '_sub' .$arrRet[1];
1177            break;
1178        }
1179        return $dist_name;
1180    }
1181
1182    /**
1183     * サブ情報の登録があるかを取得する
1184     * タイトル, コメント, 画像のいずれかに登録があれば「あり」と判定する
1185     *
1186     * @param array $arrSubProductData サブ情報配列
1187     * @return boolean true: サブ情報あり, false: サブ情報なし
1188     */
1189    function hasSubProductData($arrSubProductData) {
1190        $has_subproduct_data = false;
1191
1192        for($i = 1; $i <= PRODUCTSUB_MAX; $i++) {
1193            if(SC_Utils_Ex::isBlank($arrSubProductData['sub_title'.$i]) == false
1194                    || SC_Utils_Ex::isBlank($arrSubProductData['sub_comment'.$i]) == false
1195                    || SC_Utils_Ex::isBlank($arrSubProductData['sub_image'.$i]) == false
1196                    || SC_Utils_Ex::isBlank($arrSubProductData['sub_large_image'.$i]) == false
1197                    || SC_Utils_Ex::isBlank($arrSubProductData['temp_sub_image'.$i]) == false
1198                    || SC_Utils_Ex::isBlank($arrSubProductData['temp_sub_large_image'.$i]) == false) {
1199                $has_subproduct_data = true;
1200                break;
1201            }
1202        }
1203
1204        return $has_subproduct_data;
1205    }
1206
1207    /**
1208     * アンカーハッシュ文字列を取得する
1209     * アンカーキーをサニタイジングする
1210     *
1211     * @param string $anchor_key フォーム入力パラメータで受け取ったアンカーキー
1212     * @return <type>
1213     */
1214    function getAnchorHash($anchor_key) {
1215        if($anchor_key != "") {
1216            return "location.hash='#" . htmlspecialchars($anchor_key) . "'";
1217        } else {
1218            return "";
1219        }
1220    }
1221}
1222?>
Note: See TracBrowser for help on using the repository browser.