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
RevLine 
[15342]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[20764]5 * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
[15342]6 *
7 * http://www.lockon.co.jp/
[16582]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.
[15342]22 */
23
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/admin/products/LC_Page_Admin_Products_Ex.php';
[15342]26
27/**
[17840]28 * 商品登録 のページクラス
[15342]29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
[20386]34class LC_Page_Admin_Products_Product extends LC_Page_Admin_Products_Ex {
[15342]35
[17902]36    // }}}
37    // {{{ functions
[15342]38
[17902]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';
[20911]49        $this->tpl_maintitle = '商品管理';
[17902]50        $this->tpl_subtitle = '商品登録';
[15342]51
[17902]52        $masterData = new SC_DB_MasterData_Ex();
[21481]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');
[17902]60    }
[15342]61
[17902]62    /**
63     * Page のプロセス.
64     *
65     * @return void
66     */
67    function process() {
[19661]68        $this->action();
69        $this->sendResponse();
70    }
71
72    /**
73     * Page のアクション.
74     *
75     * @return void
76     */
77    function action() {
[21591]78        // フックポイント.
[21689]79        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
[21693]80        $objPlugin->doAction('LC_Page_Admin_Products_Product_action_before', array($this));
[21591]81
[20501]82        $objFormParam = new SC_FormParam_Ex();
[15342]83
[20386]84        // アップロードファイル情報の初期化
[20497]85        $objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR);
[20386]86        $this->lfInitFile($objUpFile);
87        $objUpFile->setHiddenFileList($_POST);
[18777]88
[20386]89        // ダウンロード販売ファイル情報の初期化
[20497]90        $objDownFile = new SC_UploadFile_Ex(DOWN_TEMP_REALDIR, DOWN_SAVE_REALDIR);
[20386]91        $this->lfInitDownFile($objDownFile);
92        $objDownFile->setHiddenFileList($_POST);
[15342]93
[20970]94        // 検索パラメーター引き継ぎ
[20386]95        $this->arrSearchHidden = $this->lfGetSearchParam($_POST);
[15342]96
[20386]97        $mode = $this->getMode();
[21441]98        switch ($mode) {
[21526]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) {
[21582]106                    trigger_error('', E_USER_ERROR);
[21526]107                }
[15342]108
[21526]109                // 商品ID取得
110                $product_id = $objFormParam->getValue('product_id');
111                // 商品データ取得
112                $arrForm = $this->lfGetFormParam_PreEdit($objUpFile, $objDownFile, $product_id);
[21214]113
[21526]114                // 複製の場合は、ダウンロード商品情報部分はコピーしない
115                if ($mode == 'copy') {
116                    // ダウンロード商品ファイル名をunset
117                    $arrForm['down_filename'] = '';
[21214]118
[21526]119                    // $objDownFile->setDBDownFile()でsetされたダウンロードファイル名をunset
120                    unset($objDownFile->save_file[0]);
121                }
[21214]122
[21526]123                // ページ表示用パラメーター設定
124                $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm);
[15342]125
[21526]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                }
[15342]133
[20386]134                // ページonload時のJavaScript設定
135                $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage();
[21526]136                break;
[15342]137
[21526]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;
[15342]156
[21526]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);
[20386]166
[21526]167                    // 件数カウントバッチ実行
168                    $objQuery =& SC_Query_Ex::getSingletonInstance();
169                    $objDb = new SC_Helper_DB_Ex();
170                    $objDb->sfCountCategory($objQuery);
171                    $objDb->sfCountMaker($objQuery);
[21202]172
[21526]173                    // ダウンロード商品の複製時に、ダウンロード商品用ファイルを
174                    // 変更すると、複製元のファイルが削除されるのを回避。
175                    if (!empty($arrForm['copy_product_id'])) {
176                        $objDownFile->save_file = array();
177                    }
[15342]178
[21526]179                    // 一時ファイルを本番ディレクトリに移動する
180                    $this->lfSaveUploadFiles($objUpFile, $objDownFile, $product_id);
[15342]181
[21526]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;
[15342]191
[21526]192            // 画像のアップロード
[20386]193            case 'upload_image':
[17902]194            case 'delete_image':
[21526]195                // パラメーター初期化
196                $this->lfInitFormParam_UploadImage($objFormParam);
197                $this->lfInitFormParam($objFormParam, $_POST);
198                $arrForm = $objFormParam->getHashArray();
[20386]199
[21526]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                }
[20386]216
[21526]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;
[20386]223
[21526]224            // ダウンロード商品ファイルアップロード
[18777]225            case 'upload_down':
226            case 'delete_down':
[21526]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);
[18777]250                break;
[15342]251
[21526]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);
[15342]260
[21526]261                // 選択された関連商品IDがすでに登録している関連商品と重複していないかチェック
262                $this->lfCheckError_RecommendSelect($this->arrForm, $this->arrErr);
[20638]263
[21526]264                // ページonload時のJavaScript設定
265                $anchor_hash = $this->getAnchorHash($this->arrForm['anchor_key']);
266                $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage($anchor_hash);
267                break;
[20638]268
[21526]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;
[15342]279
[21526]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;
[17902]287        }
[18777]288
[20386]289        // 関連商品の読み込み
290        $this->arrRecommend = $this->lfGetRecommendProducts($this->arrForm);
[21591]291
292        // フックポイント.
[21689]293        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
[21693]294        $objPlugin->doAction('LC_Page_Admin_Products_Product_action_after', array($this));
[17902]295    }
[15342]296
[17902]297    /**
298     * デストラクタ.
299     *
300     * @return void
301     */
302    function destroy() {
303        parent::destroy();
304    }
[15342]305
[18378]306    /**
[20970]307     * パラメーター情報の初期化
[20386]308     * - 編集/複製モード
[18378]309     *
[20386]310     * @param object $objFormParam SC_FormParamインスタンス
311     * @param array $arrPost $_POSTデータ
312     * @return void
[18378]313     */
[20386]314    function lfInitFormParam_PreEdit(&$objFormParam, $arrPost) {
[21514]315        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
[20386]316        $objFormParam->setParam($arrPost);
317        $objFormParam->convParam();
318    }
[15342]319
[20386]320    /**
[20970]321     * パラメーター情報の初期化
[20386]322     *
323     * @param object $objFormParam SC_FormParamインスタンス
324     * @param array $arrPost $_POSTデータ
325     * @return void
326     */
327    function lfInitFormParam(&$objFormParam, $arrPost) {
[21514]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'));
[15556]333
[21441]334        if ($this->lfGetProductClassFlag($arrPost['has_product_class']) == false) {
[20386]335            // 新規登録, 規格なし商品の編集の場合
[21514]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'));
[21515]339            $objFormParam->addParam('temp_down_file', 'temp_down_file', '', '', array());
340            $objFormParam->addParam('save_down_file', 'save_down_file', '', '', array());
[21514]341            $objFormParam->addParam('商品コード', 'product_code', STEXT_LEN, 'KVna', array('EXIST_CHECK', 'SPTAB_CHECK','MAX_LENGTH_CHECK'));
[21481]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'));
[21514]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'));
[20386]346        }
[21514]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'));
[21515]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());
[20386]363
364        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
[21514]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'));
[21515]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());
[20386]371        }
372
373        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
[21514]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'));
[21481]376            $objFormParam->addParam('recommend_delete' . $cnt, 'recommend_delete' . $cnt, '', 'n', array());
[20386]377        }
378
[21514]379        $objFormParam->addParam('商品ID', 'copy_product_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
[20386]380
[21481]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'));
[20386]383
384        $objFormParam->setParam($arrPost);
385        $objFormParam->convParam();
386    }
387
388    /**
[20970]389     * パラメーター情報の初期化
[20386]390     * - 画像ファイルアップロードモード
391     *
392     * @param object $objFormParam SC_FormParamインスタンス
393     * @return void
394     */
395    function lfInitFormParam_UploadImage(&$objFormParam) {
[21515]396        $objFormParam->addParam('image_key', 'image_key', '', '', array());
[20386]397    }
398
399    /**
[20970]400     * パラメーター情報の初期化
[20386]401     * - ダウンロード商品ファイルアップロードモード
402     *
403     * @param object $objFormParam SC_FormParamインスタンス
404     * @return void
405     */
406    function lfInitFormParam_UploadDown(&$objFormParam) {
[21515]407        $objFormParam->addParam('down_key', 'down_key', '', '', array());
[20386]408    }
409
410    /**
[20970]411     * パラメーター情報の初期化
[20386]412     * - 関連商品追加モード
413     *
414     * @param object $objFormParam SC_FormParamインスタンス
415     * @return void
416     */
417    function lfInitFormParam_RecommendSelect(&$objFormParam) {
[21515]418        $objFormParam->addParam('anchor_key', 'anchor_key', '', '', array());
[21481]419        $objFormParam->addParam('select_recommend_no', 'select_recommend_no', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
[20386]420    }
421
422    /**
[20970]423     * アップロードファイルパラメーター情報の初期化
[20386]424     * - 画像ファイル用
425     *
426     * @param object $objUpFile SC_UploadFileインスタンス
427     * @return void
428     */
429    function lfInitFile(&$objUpFile) {
[21514]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);
[20386]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    /**
[20970]440     * アップロードファイルパラメーター情報の初期化
[20386]441     * - ダウンロード商品ファイル用
442     *
443     * @param object $objDownFile SC_UploadFileインスタンス
444     * @return void
445     */
446    function lfInitDownFile(&$objDownFile) {
[21515]447        $objDownFile->addFile('ダウンロード販売用ファイル', 'down_file', explode(',', DOWNLOAD_EXTENSION),DOWN_SIZE, true, 0, 0);
[20386]448    }
449
450    /**
[20970]451     * フォーム入力パラメーターのエラーチェック
[20386]452     *
453     * @param object $objFormParam SC_FormParamインスタンス
454     * @param object $objUpFile SC_UploadFileインスタンス
455     * @param object $objDownFile SC_UploadFileインスタンス
[20970]456     * @param array $arrForm フォーム入力パラメーター配列
[20386]457     * @return array エラー情報を格納した連想配列
458     */
459    function lfCheckError_Edit(&$objFormParam, &$objUpFile, &$objDownFile, $arrForm) {
[20503]460        $objErr = new SC_CheckError_Ex($arrForm);
[20386]461        $arrErr = array();
462
[20970]463        // 入力パラメーターチェック
[20386]464        $arrErr = $objFormParam->checkError();
465
466        // アップロードファイル必須チェック
467        $arrErr = array_merge((array)$arrErr, (array)$objUpFile->checkEXISTS());
468
469        // HTMLタグ許可チェック
[21514]470        $objErr->doFunc(array('詳細-メインコメント', 'main_comment', $this->arrAllowedTag), array('HTML_TAG_CHECK'));
[20386]471        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
[21514]472            $objErr->doFunc(array('詳細-サブコメント' . $cnt, 'sub_comment' . $cnt, $this->arrAllowedTag), array('HTML_TAG_CHECK'));
[20386]473        }
474
475        // 規格情報がない商品の場合のチェック
[21441]476        if ($arrForm['has_product_class'] != true) {
[20386]477            // 在庫必須チェック(在庫無制限ではない場合)
[21440]478            if ($arrForm['stock_unlimited'] != UNLIMITED_FLG_UNLIMITED) {
[21514]479                $objErr->doFunc(array('在庫数', 'stock'), array('EXIST_CHECK'));
[17902]480            }
[20386]481            // ダウンロード商品ファイル必須チェック(ダウンロード商品の場合)
[21441]482            if ($arrForm['product_type_id'] == PRODUCT_TYPE_DOWNLOAD) {
[20386]483                $arrErr = array_merge((array)$arrErr, (array)$objDownFile->checkEXISTS());
[21514]484                $objErr->doFunc(array('ダウンロード商品ファイル名', 'down_filename'), array('EXIST_CHECK'));
[20386]485            }
[17902]486        }
[20386]487
488        $arrErr = array_merge((array)$arrErr, (array)$objErr->arrErr);
489        return $arrErr;
[17902]490    }
[15342]491
[20386]492    /**
[20638]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
[21441]505        foreach (array_keys($arrForm) as $key) {
506            if (preg_match('/^recommend_id/', $key)) {
507                if ($select_recommend_no == preg_replace('/^recommend_id/', '', $key)) {
[20638]508                    continue;
509                }
510
[21441]511                if ($select_recommend_id == $arrForm[$key]) {
[20638]512                    // 重複した場合、選択されたデータをリセットする
513                    $arrForm['recommend_id' . $select_recommend_no] = '';
514                    $arrErr['recommend_comment' . $select_recommend_no] = '※ すでに登録されている関連商品です。<br />';
515                    break;
516                }
517            }
518        }
519    }
520
521    /**
[20970]522     * 検索パラメーター引き継ぎ用配列取得
[20386]523     *
524     * @param array $arrPost $_POSTデータ
[20970]525     * @return array 検索パラメーター配列
[20386]526     */
527    function lfGetSearchParam($arrPost) {
528        $arrSearchParam = array();
[20501]529        $objFormParam = new SC_FormParam_Ex();
[15556]530
[20386]531        parent::lfInitParam($objFormParam);
532        $objFormParam->setParam($arrPost);
533        $arrSearchParam = $objFormParam->getSearchArray();
[15556]534
[20386]535        return $arrSearchParam;
536    }
537
538    /**
[20970]539     * フォームパラメーター取得
[20386]540     * - 編集/複製モード
541     *
542     * @param object $objUpFile SC_UploadFileインスタンス
543     * @param object $objDownFile SC_UploadFileインスタンス
544     * @param integer $product_id 商品ID
[20970]545     * @return array フォームパラメーター配列
[20386]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    /**
[20970]561     * フォームパラメーター取得
[20386]562     * - 登録モード
563     *
564     * @param object $objFormParam SC_FormParamインスタンス
[20970]565     * @return array フォームパラメーター配列
[20386]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    /**
[20970]576     * 表示用フォームパラメーター取得
[20386]577     * - 入力画面
578     *
579     * @param object $objUpFile SC_UploadFileインスタンス
580     * @param object $objDownFile SC_UploadFileインスタンス
[20970]581     * @param array $arrForm フォーム入力パラメーター配列
582     * @return array 表示用フォームパラメーター配列
[20386]583     */
584    function lfSetViewParam_InputPage(&$objUpFile, &$objDownFile, &$arrForm) {
[20970]585        // カテゴリマスターデータ取得
[20386]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        }
[21514]592        if ($arrForm['status'] == '') {
[20386]593            $arrForm['status'] = DEFAULT_PRODUCT_DISP;
594        }
[21514]595        if ($arrForm['product_type_id'] == '') {
[20386]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        // 基本情報(デフォルトポイントレート用)
[20484]609        $arrForm['arrInfo'] = SC_Helper_DB_Ex::sfGetBasisData();
[20386]610
611        // サブ情報ありなしフラグ
612        $arrForm['sub_find'] = $this->hasSubProductData($arrForm);
613
614        return $arrForm;
615    }
616
617    /**
[20970]618     * 表示用フォームパラメーター取得
[20386]619     * - 確認画面
620     *
621     * @param object $objUpFile SC_UploadFileインスタンス
622     * @param object $objDownFile SC_UploadFileインスタンス
[20970]623     * @param array $arrForm フォーム入力パラメーター配列
624     * @return array 表示用フォームパラメーター配列
[20386]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     */
[21479]646    function lfSetScaleImage(&$objUpFile, $image_key) {
[21514]647        $subno = str_replace('sub_large_image', '', $image_key);
[21441]648        switch ($image_key) {
[21481]649        case 'main_large_image':
[20386]650            // 詳細メイン画像
[21481]651            $this->lfMakeScaleImage($objUpFile, $image_key, 'main_image');
652        case 'main_image':
[20386]653            // 一覧メイン画像
[21481]654            $this->lfMakeScaleImage($objUpFile, $image_key, 'main_list_image');
[20386]655            break;
[21481]656        case 'sub_large_image' . $subno:
[20386]657            // サブメイン画像
[21481]658            $this->lfMakeScaleImage($objUpFile, $_POST['image_key'], 'sub_image' . $subno);
[20386]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
[21441]675        foreach ($arrSaveFile as $key => $val) {
[20386]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     */
[21479]689    function lfMakeScaleImage(&$objUpFile, $from_key, $to_key, $forced = false) {
[20386]690        $arrImageKey = array_flip($objUpFile->keyname);
[21514]691        $from_path = '';
[20386]692
[21441]693        if ($objUpFile->temp_file[$arrImageKey[$from_key]]) {
[20386]694            $from_path = $objUpFile->temp_dir . $objUpFile->temp_file[$arrImageKey[$from_key]];
[21441]695        } elseif ($objUpFile->save_file[$arrImageKey[$from_key]]) {
[20386]696            $from_path = $objUpFile->save_dir . $objUpFile->save_file[$arrImageKey[$from_key]];
697        }
698
[21441]699        if (file_exists($from_path)) {
[20386]700            // 生成先の画像サイズを取得
701            $to_w = $objUpFile->width[$arrImageKey[$to_key]];
702            $to_h = $objUpFile->height[$arrImageKey[$to_key]];
703
[21684]704            if ($forced) {
705                $objUpFile->save_file[$arrImageKey[$to_key]] = '';
706            }
[20386]707
[21684]708            if (empty($objUpFile->temp_file[$arrImageKey[$to_key]])
709                && empty($objUpFile->save_file[$arrImageKey[$to_key]])
710            ) {
[20386]711                // リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
[21514]712                $dst_file = $objUpFile->lfGetTmpImageName(IMAGE_RENAME, '', $objUpFile->temp_file[$arrImageKey[$from_key]]) . $this->lfGetAddSuffix($to_key);
[20386]713                $path = $objUpFile->makeThumb($from_path, $to_w, $to_h, $dst_file);
714                $objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path);
[17902]715            }
716        }
717    }
[15342]718
[18378]719    /**
[20970]720     * アップロードファイルパラメーター情報から削除
[20386]721     * 一時ディレクトリに保存されている実ファイルも削除する
[18378]722     *
[20386]723     * @param object $objUpFile SC_UploadFileインスタンス
724     * @param string $image_key 画像ファイルキー
[18378]725     * @return void
726     */
[20386]727    function lfDeleteTempFile(&$objUpFile, $image_key) {
728        // TODO: SC_UploadFile::deleteFileの画像削除条件見直し要
729        $arrTempFile = $objUpFile->temp_file;
730        $arrKeyName = $objUpFile->keyname;
[15342]731
[21441]732        foreach ($arrKeyName as $key => $keyname) {
[21684]733            if ($keyname != $image_key) continue;
[20386]734
[21441]735            if (!empty($arrTempFile[$key])) {
[20386]736                $temp_file = $arrTempFile[$key];
737                $arrTempFile[$key] = '';
738
[21441]739                if (!in_array($temp_file, $arrTempFile)) {
[20386]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            }
[17902]749        }
750    }
[15342]751
[20386]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の画像削除条件見直し要
[20498]762        $objImage = new SC_Image_Ex($objUpFile->temp_dir);
[20386]763        $arrKeyName = $objUpFile->keyname;
764        $arrTempFile = $objUpFile->temp_file;
765        $arrSaveFile = $objUpFile->save_file;
766        $arrImageKey = array();
[21441]767        foreach ($arrTempFile as $key => $temp_file) {
768            if ($temp_file) {
[20386]769                $objImage->moveTempImage($temp_file, $objUpFile->save_dir);
770                $arrImageKey[] = $arrKeyName[$key];
[21684]771                if (!empty($arrSaveFile[$key])
772                    && !$this->lfHasSameProductImage($product_id, $arrImageKey, $arrSaveFile[$key])
773                    && !in_array($temp_file, $arrSaveFile)
774                ) {
[20386]775                    $objImage->deleteImage($arrSaveFile[$key], $objUpFile->save_dir);
776                }
777            }
778        }
779        $objDownFile->moveTempDownFile();
780    }
781
782    /**
783     * 同名画像ファイル登録の有無を確認する.
784     *
785     * 画像ファイルの削除可否判定用。
786     * 同名ファイルの登録がある場合には画像ファイルの削除を行わない。
[20532]787     * 戻り値: 同名ファイル有り(true) 同名ファイル無し(false)
[20386]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        }
[21514]805        $where = implode(' OR ', $arrWhere);
[20386]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        }
[21514]814        $where .= ')';
[20386]815
[20507]816        $objQuery = new SC_Query_Ex();
[21376]817        $exists = $objQuery->exists('dtb_products', $where, $sqlval);
818        return $exists;
[20386]819    }
[18435]820
[20386]821    /**
822     * DBから商品データを取得する
823     *
824     * @param integer $product_id 商品ID
825     * @return array 商品データ配列
826     */
827    function lfGetProductData_FromDB($product_id) {
[20507]828        $objQuery =& SC_Query_Ex::getSingletonInstance();
[20386]829        $arrProduct = array();
830
831        // 商品データ取得
[21514]832        $col = '*';
[18815]833        $table = <<< __EOF__
[21527]834            dtb_products AS T1
[18815]835            LEFT JOIN (
[21527]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
[18815]851__EOF__;
[21514]852        $where = 'product_id = ?';
[20602]853        $objQuery->setLimit('1');
[20386]854        $arrProduct = $objQuery->select($col, $table, $where, array($product_id));
[15342]855
[20386]856        // カテゴリID取得
[21481]857        $col = 'category_id';
858        $table = 'dtb_product_categories';
[21514]859        $where = 'product_id = ?';
[20796]860        $objQuery->setOption('');
[20386]861        $arrProduct[0]['category_id'] = $objQuery->getCol($col, $table, $where, array($product_id));
[15342]862
[20386]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) {
[21481]869            $arrProduct[0]['product_class_id'] = SC_Utils_Ex::sfGetProductClassId($product_id,'0','0');
[17902]870        }
[20386]871
872        // 商品ステータス取得
[20487]873        $objProduct = new SC_Product_Ex();
[20386]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];
[17902]882    }
[15342]883
[20386]884    /**
885     * DBから関連商品データを取得する
886     *
887     * @param integer $product_id 商品ID
888     * @return array 関連商品データ配列
889     */
890    function lfGetRecommendProductsData_FromDB($product_id) {
[20507]891        $objQuery =& SC_Query_Ex::getSingletonInstance();
[20386]892        $arrRecommendProducts = array();
[15342]893
[20386]894        $col = 'recommend_product_id,';
895        $col.= 'comment';
896        $table = 'dtb_recommend_products';
897        $where = 'product_id = ?';
[21514]898        $objQuery->setOrder('rank DESC');
[20386]899        $arrRet = $objQuery->select($col, $table, $where, array($product_id));
[15342]900
[20386]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++;
[17902]906        }
[15342]907
[20386]908        return $arrRecommendProducts;
909    }
[15342]910
[20386]911    /**
912     * 関連商品データ表示用配列を取得する
913     *
[20970]914     * @param string $arrForm フォーム入力パラメーター配列
[20386]915     * @return array 関連商品データ配列
916     */
917    function lfGetRecommendProducts(&$arrForm) {
918        $arrRecommend = array();
[15342]919
[21441]920        for ($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
[21481]921            $keyname = 'recommend_id' . $i;
922            $delkey = 'recommend_delete' . $i;
923            $commentkey = 'recommend_comment' . $i;
[20386]924
925            if (!isset($arrForm[$delkey])) $arrForm[$delkey] = null;
926
[21441]927            if ((isset($arrForm[$keyname]) && !empty($arrForm[$keyname])) && $arrForm[$delkey] != 1) {
[20487]928                $objProduct = new SC_Product_Ex();
[20386]929                $arrRecommend[$i] = $objProduct->getDetail($arrForm[$keyname]);
930                $arrRecommend[$i]['product_id'] = $arrForm[$keyname];
931                $arrRecommend[$i]['comment'] = $arrForm[$commentkey];
932            }
[17902]933        }
[20386]934        return $arrRecommend;
935    }
[15342]936
[20386]937    /**
[20970]938     * 表示用カテゴリマスターデータ配列を取得する
[20386]939     * - 編集モード
940     *
941     * @param void
[20970]942     * @return array カテゴリマスターデータ配列
[20386]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;
[17902]954    }
[15342]955
[20386]956    /**
[20970]957     * 入力フォームパラメーターの規格ありなしフラグを判定
[20386]958     *
[20970]959     * @param string $has_product_class 入力フォームパラメーターの規格ありなしフラグ
[20386]960     * @return boolean true: 規格あり, false: 規格なし
961     */
962    function lfGetProductClassFlag($has_product_class) {
[21441]963        if ($has_product_class == '1') {
[20386]964            return true;
965        } else {
966            return false;
[17902]967        }
968    }
[15342]969
[20386]970    /**
971     * ページonload用JavaScriptを取得する
972     * - 入力画面
973     *
974     * @param string $anchor_hash アンカー用ハッシュ文字列(省略可)
975     * @return string ページonload用JavaScript
976     */
[21514]977    function lfSetOnloadJavaScript_InputPage($anchor_hash = '') {
[20386]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インスタンス
[20970]986     * @param array $arrList フォーム入力パラメーター配列
[20386]987     * @return integer 登録商品ID
988     */
989    function lfRegistProduct(&$objUpFile, &$objDownFile, $arrList) {
[20507]990        $objQuery =& SC_Query_Ex::getSingletonInstance();
[17902]991        $objDb = new SC_Helper_DB_Ex();
[15342]992
[17902]993        // 配列の添字を定義
[20538]994        $checkArray = array('name', 'status',
[21481]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');
[17902]999        $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray);
[15342]1000
[17902]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'];
[21185]1016        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
[17902]1017        $sqlval['creator_id'] = $_SESSION['member_id'];
[20386]1018        $arrRet = $objUpFile->getDBFileList();
[17902]1019        $sqlval = array_merge($sqlval, $arrRet);
[15342]1020
[21441]1021        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
[17902]1022            $sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt];
1023            $sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt];
1024        }
[15342]1025
[20386]1026        $objQuery->begin();
1027
[18435]1028        // 新規登録(複製時を含む)
[21514]1029        if ($arrList['product_id'] == '') {
[21481]1030            $product_id = $objQuery->nextVal('dtb_products_product_id');
[18788]1031            $sqlval['product_id'] = $product_id;
[17579]1032
[17902]1033            // INSERTの実行
[21185]1034            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
[21481]1035            $objQuery->insert('dtb_products', $sqlval);
[17579]1036
[18435]1037            $arrList['product_id'] = $product_id;
1038
[17902]1039            // カテゴリを更新
1040            $objDb->updateProductCategories($arrList['category_id'], $product_id);
[16546]1041
[18435]1042            // 複製商品の場合には規格も複製する
[21514]1043            if ($arrList['copy_product_id'] != '' && SC_Utils_Ex::sfIsInt($arrList['copy_product_id'])) {
[21481]1044                if ($this->lfGetProductClassFlag($arrList['has_product_class']) == false) {
[18435]1045                    //規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う
[17902]1046                    $this->lfCopyProductClass($arrList, $objQuery);
[20386]1047                } else {
[18435]1048                    //規格がある場合の複製は複製元の内容で追加登録を行う
[17902]1049                    // dtb_products_class のカラムを取得
1050                    $dbFactory = SC_DB_DBFactory_Ex::getInstance();
[20784]1051                    $arrColList = $objQuery->listTableFields('dtb_products_class');
[17902]1052                    $arrColList_tmp = array_flip($arrColList);
[15342]1053
[18435]1054                    // 複製しない列
[21481]1055                    unset($arrColList[$arrColList_tmp['product_class_id']]);     //規格ID
1056                    unset($arrColList[$arrColList_tmp['product_id']]);           //商品ID
1057                    unset($arrColList[$arrColList_tmp['create_date']]);
[15342]1058
[20556]1059                    // 複製元商品の規格データ取得
[17902]1060                    $col = SC_Utils_Ex::sfGetCommaList($arrColList);
[20556]1061                    $table = 'dtb_products_class';
1062                    $where = 'product_id = ?';
1063                    $objQuery->setOrder('product_class_id');
[21481]1064                    $arrProductsClass = $objQuery->select($col, $table, $where, array($arrList['copy_product_id']));
[20556]1065
1066                    // 規格データ登録
[20616]1067                    $objQuery =& SC_Query_Ex::getSingletonInstance();
[21441]1068                    foreach ($arrProductsClass as $arrData) {
[21502]1069                        $sqlval = $arrData;
[20556]1070                        $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id');
1071                        $sqlval['product_id'] = $product_id;
[21185]1072                        $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
1073                        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
[20556]1074                        $objQuery->insert($table, $sqlval);
1075                    }
[17902]1076                }
1077            }
[18435]1078        // 更新
[20386]1079        } else {
[17902]1080            $product_id = $arrList['product_id'];
1081            // 削除要求のあった既存ファイルの削除
[20386]1082            $arrRet = $this->lfGetProductData_FromDB($arrList['product_id']);
[19948]1083            // TODO: SC_UploadFile::deleteDBFileの画像削除条件見直し要
[20498]1084            $objImage = new SC_Image_Ex($objUpFile->temp_dir);
[20386]1085            $arrKeyName = $objUpFile->keyname;
1086            $arrSaveFile = $objUpFile->save_file;
[19948]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) {
[20386]1093                        $objImage->deleteImage($arrRet[$keyname], $objUpFile->save_dir);
[19948]1094                    }
1095                }
1096            }
[20386]1097            $objDownFile->deleteDBDownFile($arrRet);
[17902]1098            // UPDATEの実行
[21514]1099            $where = 'product_id = ?';
[21481]1100            $objQuery->update('dtb_products', $sqlval, $where, array($product_id));
[16546]1101
[17902]1102            // カテゴリを更新
1103            $objDb->updateProductCategories($arrList['category_id'], $product_id);
1104        }
[15342]1105
[20602]1106        // 商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。
[21514]1107        if ($arrList['copy_product_id'] == '') {
[17902]1108            // 規格登録
[20602]1109            if ($objDb->sfHasProductClass($product_id)) {
[20970]1110                // 規格あり商品(商品規格テーブルのうち、商品登録フォームで設定するパラメーターのみ更新)
[20602]1111                $this->lfUpdateProductClass($arrList);
1112            } else {
1113                // 規格なし商品(商品規格テーブルの更新)
1114                $this->lfInsertDummyProductClass($arrList);
1115            }
[17902]1116        }
[15342]1117
[21182]1118        // 商品ステータス設定
[20487]1119        $objProduct = new SC_Product_Ex();
[18863]1120        $objProduct->setProductStatus($product_id, $arrList['product_status']);
1121
[17902]1122        // 関連商品登録
1123        $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id);
[15342]1124
[17902]1125        $objQuery->commit();
1126        return $product_id;
1127    }
[15342]1128
[20386]1129    /**
1130     * 規格を設定していない商品を商品規格テーブルに登録
1131     *
1132     * @param array $arrList
1133     * @return void
1134     */
1135    function lfInsertDummyProductClass($arrList) {
[20507]1136        $objQuery = new SC_Query_Ex();
[20386]1137        $objDb = new SC_Helper_DB_Ex();
[15342]1138
[20386]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);
[15342]1143
[20386]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';
[15342]1146
[20386]1147        if (strlen($sqlval['product_class_id']) == 0) {
1148            $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id');
[21185]1149            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
1150            $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
[20386]1151            // INSERTの実行
1152            $objQuery->insert('dtb_products_class', $sqlval);
[17902]1153        } else {
[21185]1154            $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
[20386]1155            // UPDATEの実行
[21514]1156            $objQuery->update('dtb_products_class', $sqlval, 'product_class_id = ?', array($sqlval['product_class_id']));
[16546]1157
[17902]1158        }
1159    }
[15342]1160
[20386]1161    /**
[20616]1162     * 規格を設定している商品の商品規格テーブルを更新
[20602]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();
[21420]1171
[20602]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    /**
[20386]1180     * DBに関連商品データを登録する
1181     *
1182     * @param object $objQuery SC_Queryインスタンス
[20970]1183     * @param string $arrList フォーム入力パラメーター配列
[20386]1184     * @param integer $product_id 登録する商品ID
1185     * @return void
1186     */
[20616]1187    function lfInsertRecommendProducts(&$objQuery, $arrList, $product_id) {
[20386]1188        // 一旦関連商品をすべて削除する
[21514]1189        $objQuery->delete('dtb_recommend_products', 'product_id = ?', array($product_id));
[20386]1190        $sqlval['product_id'] = $product_id;
1191        $rank = RECOMMEND_PRODUCT_MAX;
[21441]1192        for ($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
[21481]1193            $keyname = 'recommend_id' . $i;
1194            $commentkey = 'recommend_comment' . $i;
1195            $deletekey = 'recommend_delete' . $i;
[15342]1196
[20386]1197            if (!isset($arrList[$deletekey])) $arrList[$deletekey] = null;
[15342]1198
[21514]1199            if ($arrList[$keyname] != '' && $arrList[$deletekey] != '1') {
[20386]1200                $sqlval['recommend_product_id'] = $arrList[$keyname];
1201                $sqlval['comment'] = $arrList[$commentkey];
1202                $sqlval['rank'] = $rank;
1203                $sqlval['creator_id'] = $_SESSION['member_id'];
[21185]1204                $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
1205                $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
[21481]1206                $objQuery->insert('dtb_recommend_products', $sqlval);
[20386]1207                $rank--;
[17902]1208            }
1209        }
1210    }
[18171]1211
[17902]1212    /**
[20386]1213     * 規格データをコピーする
1214     *
[20970]1215     * @param array $arrList フォーム入力パラメーター配列
[20386]1216     * @param object $objQuery SC_Queryインスタンス
1217     * @return boolean エラーフラグ
[18171]1218     */
[20616]1219    function lfCopyProductClass($arrList, &$objQuery) {
[18304]1220        // 複製元のdtb_products_classを取得(規格なしのため、1件のみの取得)
[21514]1221        $col = '*';
[21481]1222        $table = 'dtb_products_class';
[21514]1223        $where = 'product_id = ?';
[21481]1224        $arrProductClass = $objQuery->select($col, $table, $where, array($arrList['copy_product_id']));
[17840]1225
[17902]1226        //トランザクション開始
1227        $objQuery->begin();
1228        $err_flag = false;
[18435]1229        //非編集項目は複製、編集項目は上書きして登録
[21441]1230        foreach ($arrProductClass as $records) {
1231            foreach ($records as $key => $value) {
1232                if (isset($arrList[$key])) {
1233                    switch ($key) {
[20556]1234                    case 'stock_unlimited':
1235                        $records[$key] = (int)$arrList[$key];
1236                        break;
1237                    default:
1238                        $records[$key] = $arrList[$key];
1239                        break;
1240                    }
[17902]1241                }
1242            }
[18788]1243
[21481]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';
[17902]1247            $objQuery->insert($table, $records);
1248            //エラー発生時は中断
[21441]1249            if ($objQuery->isError()) {
[17902]1250                $err_flag = true;
1251                continue;
1252            }
1253        }
1254        //トランザクション終了
[21441]1255        if ($err_flag) {
[17902]1256            $objQuery->rollback();
[20386]1257        } else {
[17902]1258            $objQuery->commit();
1259        }
1260        return !$err_flag;
1261    }
[18435]1262
1263    /**
[20386]1264     * リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
1265     *
1266     * @param string $to_key
1267     * @return string
[18435]1268     */
[21479]1269    function lfGetAddSuffix($to_key) {
[21684]1270        if ( IMAGE_RENAME === true) return;
[18435]1271
[20386]1272        // 自動生成される画像名
[21514]1273        $dist_name = '';
[21441]1274        switch ($to_key) {
[21481]1275        case 'main_list_image':
[20386]1276            $dist_name = '_s';
1277            break;
[21481]1278        case 'main_image':
[20386]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    }
[18435]1288
[20386]1289    /**
1290     * サブ情報の登録があるかを取得する
1291     * タイトル, コメント, 画像のいずれかに登録があれば「あり」と判定する
1292     *
1293     * @param array $arrSubProductData サブ情報配列
1294     * @return boolean true: サブ情報あり, false: サブ情報なし
1295     */
1296    function hasSubProductData($arrSubProductData) {
1297        $has_subproduct_data = false;
[18435]1298
[21441]1299        for ($i = 1; $i <= PRODUCTSUB_MAX; $i++) {
[21684]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            ) {
[20386]1307                $has_subproduct_data = true;
1308                break;
1309            }
[18435]1310        }
1311
[20386]1312        return $has_subproduct_data;
[18777]1313    }
[19948]1314
1315    /**
[20386]1316     * アンカーハッシュ文字列を取得する
1317     * アンカーキーをサニタイジングする
1318     *
[20970]1319     * @param string $anchor_key フォーム入力パラメーターで受け取ったアンカーキー
[20386]1320     * @return <type>
[19948]1321     */
[20386]1322    function getAnchorHash($anchor_key) {
[21514]1323        if ($anchor_key != '') {
[20386]1324            return "location.hash='#" . htmlspecialchars($anchor_key) . "'";
1325        } else {
[21514]1326            return '';
[19948]1327        }
1328    }
[15342]1329}
Note: See TracBrowser for help on using the repository browser.