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

Revision 21701, 56.8 KB checked in by Seasoft, 12 years ago (diff)

#1607 (未使用定義の削除)

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