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

Revision 19805, 38.0 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある) 一部実装

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.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 {
35
36    // {{{ properties
37
38    /** ファイル管理クラスのインスタンス */
39    var $objUpFile;
40
41    /** ダウンロード用ファイル管理クラスのインスタンス */
42    var $objDownFile;
43
44    /** hidden 項目の配列 */
45    var $arrHidden;
46
47    /** エラー情報 */
48    var $arrErr;
49
50    // }}}
51    // {{{ functions
52
53    /**
54     * Page を初期化する.
55     *
56     * @return void
57     */
58    function init() {
59        parent::init();
60        $this->tpl_mainpage = 'products/product.tpl';
61        $this->tpl_subnavi = 'products/subnavi.tpl';
62        $this->tpl_mainno = 'products';
63        $this->tpl_subno = 'product';
64        $this->tpl_subtitle = '商品登録';
65        $this->arrErr = array();
66
67        $masterData = new SC_DB_MasterData_Ex();
68        $this->arrDISP = $masterData->getMasterData("mtb_disp");
69        $this->arrCLASS = $masterData->getMasterData("mtb_class");
70        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
71        $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image");
72        $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date");
73        $this->arrAllowedTag = $masterData->getMasterData("mtb_allowed_tag");
74        $this->arrProductType = $masterData->getMasterData("mtb_product_type");
75        $this->arrMaker = SC_Helper_DB_Ex::sfGetIDValueList("dtb_maker", "maker_id", "name");
76        $this->arrPayments = SC_Helper_DB_Ex::sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
77        $this->tpl_nonclass = true;
78    }
79
80    /**
81     * Page のプロセス.
82     *
83     * @return void
84     */
85    function process() {
86        $this->action();
87        $this->sendResponse();
88    }
89
90    /**
91     * Page のアクション.
92     *
93     * @return void
94     */
95    function action() {
96        $objSiteInfo = new SC_SiteInfo();
97        $objQuery = new SC_Query();
98        $objDb = new SC_Helper_DB_Ex();
99        $objProduct = new SC_Product();
100
101        // 認証可否の判定
102        $objSess = new SC_Session();
103        SC_Utils_Ex::sfIsSuccess($objSess);
104
105        // Downファイル管理クラス
106        $this->objDownFile = new SC_UploadFile(DOWN_TEMP_REALDIR, DOWN_SAVE_REALDIR);
107        // Downファイル情報の初期化
108        $this->lfInitDownFile();
109        // Hiddenからのデータを引き継ぐ
110        $this->objDownFile->setHiddenFileList($_POST);
111
112        // ファイル管理クラス
113        $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR);
114
115        // ファイル情報の初期化
116        $this->lfInitFile();
117        // Hiddenからのデータを引き継ぐ
118        $this->objUpFile->setHiddenFileList($_POST);
119
120        // 規格の有り無し判定
121        $this->tpl_nonclass = !$objDb->sfHasProductClass($_POST['product_id']);
122
123        // 検索パラメータの引き継ぎ
124        foreach ($_POST as $key => $val) {
125            if (ereg("^search_", $key)) {
126                $this->arrSearchHidden[$key] = $val;
127            }
128        }
129
130        // FORMデータの引き継ぎ
131        $this->arrForm = $_POST;
132
133        if (!isset($_POST['mode'])) $_POST['mode'] = "";
134
135        switch($_POST['mode']) {
136            // 検索画面からの編集
137            case 'pre_edit':
138            case 'copy' :
139                if (!SC_Utils_Ex::sfIsInt($_POST['product_id'])) {
140                    SC_Utils_Ex::sfDispException();
141                }
142
143                // DBから商品情報の読込
144                $this->arrForm = $this->lfGetProduct($_POST['product_id']);
145                $productStatus= $objProduct->getProductStatus(array($_POST['product_id']));
146                $this->arrForm['product_status'] = $productStatus[$_POST['product_id']];
147                $this->arrForm['payment_ids'] = $objProduct->getEnablePaymentIds(array($this->arrForm['product_class_id']));
148
149                // DBデータから画像ファイル名の読込
150                $this->objUpFile->setDBFileList($this->arrForm);
151                // DBデータからダウンロードファイル名の読込
152                $this->objDownFile->setDBDownFile($this->arrForm);
153
154                // 商品ステータスの変換
155                $arrRet = SC_Utils_Ex::sfSplitCBValue($this->arrForm['product_flag'], "product_flag");
156                $this->arrForm = array_merge($this->arrForm, $arrRet);
157                // DBから関連商品の読み込み
158                $this->lfPreGetRecommendProducts($_POST['product_id']);
159
160                $this->lfProductPage();     // 商品登録ページ
161
162                if($_POST['mode'] == "copy"){
163                    $this->arrForm["copy_product_id"] = $this->arrForm["product_id"];
164                    $this->arrForm["product_id"] = "";
165                    // 画像ファイルのコピー
166                    $arrKey = $this->objUpFile->keyname;
167                    $arrSaveFile = $this->objUpFile->save_file;
168
169                    foreach($arrSaveFile as $key => $val){
170                        $this->lfMakeScaleImage($arrKey[$key], $arrKey[$key], true);
171                    }
172                }
173                break;
174            // 商品登録・編集
175            case 'edit':
176                if($_POST['product_id'] == "" and SC_Utils_Ex::sfIsInt($_POST['copy_product_id'])){
177                    $this->tpl_nonclass = !$objDb->sfHasProductClass($_POST['copy_product_id']);
178                }
179
180                // 入力値の変換
181                $this->arrForm = $this->lfConvertParam($this->arrForm);
182                // エラーチェック
183                $this->arrErr = $this->lfErrorCheck($this->arrForm);
184                // ファイル存在チェック
185                $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS());
186                // エラーなしの場合
187                if(count($this->arrErr) == 0) {
188                    $this->lfProductConfirmPage(); // 確認ページ
189                } else {
190                    $this->lfProductPage();     // 商品登録ページ
191                }
192                break;
193            // 確認ページから完了ページへ
194            case 'complete':
195                $this->tpl_mainpage = 'products/complete.tpl';
196
197                $this->arrForm['product_id'] = $this->lfRegistProduct($_POST);      // データ登録
198
199                // 件数カウントバッチ実行
200                $objDb->sfCategory_Count($objQuery);
201                $objDb->sfMaker_Count($objQuery);
202                // 一時ファイルを本番ディレクトリに移動する
203                $this->objUpFile->moveTempFile();
204                $this->objDownFile->moveTempDownFile();
205
206                break;
207            // 画像のアップロード
208            case 'upload_image':
209                // ファイル存在チェック
210                $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS($_POST['image_key']));
211                // 画像保存処理
212                $this->arrErr[$_POST['image_key']] = $this->objUpFile->makeTempFile($_POST['image_key'],IMAGE_RENAME);
213
214                // 中、小画像生成
215                $this->lfSetScaleImage();
216
217                $this->lfProductPage(); // 商品登録ページ
218                break;
219            // 画像の削除
220            case 'delete_image':
221                $this->objUpFile->deleteFile($_POST['image_key']);
222                $this->lfProductPage(); // 商品登録ページ
223                break;
224            // ダウンロード商品ファイルアップロード
225            case 'upload_down':
226                // ファイル存在チェック
227                $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objDownFile->checkEXISTS($_POST['down_key']));
228                // 画像保存処理
229                $this->arrErr[$_POST['down_key']] = $this->objDownFile->makeTempDownFile();
230
231                $this->lfProductPage(); // 商品登録ページ
232                break;
233            // ダウンロードファイルの削除
234            case 'delete_down':
235                $this->objDownFile->deleteFile($_POST['down_key']);
236                $this->lfProductPage(); // 商品登録ページ
237                break;
238            // 確認ページからの戻り
239            case 'confirm_return':
240                $this->lfProductPage();     // 商品登録ページ
241                break;
242            // 関連商品選択
243            case 'recommend_select' :
244                $this->lfProductPage();     // 商品登録ページ
245                break;
246            default:
247                $this->lfProductPage();     // 商品登録ページ
248                break;
249        }
250
251        // 関連商品の読み込み
252        $this->arrRecommend = $this->lfGetRecommendProducts();
253
254        // 基本情報を渡す
255        $this->arrInfo = $objSiteInfo->data;
256
257        // サブ情報の入力があるかどうかチェックする
258        $sub_find = false;
259        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
260            if( (isset($this->arrForm['sub_title'.$cnt])
261            && !empty($this->arrForm['sub_title'.$cnt])) ||
262            (isset($this->arrForm['sub_comment'.$cnt])
263            && !empty($this->arrForm['sub_comment'.$cnt])) ||
264            (isset($this->arrForm['sub_image'.$cnt])
265            && !empty($this->arrForm['sub_image'.$cnt])) ||
266            (isset($this->arrForm['sub_large_image'.$cnt])
267            && !empty($this->arrForm['sub_large_image'.$cnt])) ||
268            (isset($this->arrForm['sub_image'.$cnt])
269            && is_array($this->arrFile['sub_image'.$cnt])) ||
270            (isset($this->arrForm['sub_large_image'.$cnt])
271            && is_array($this->arrFile['sub_large_image'.$cnt]))) {
272                $sub_find = true;
273                break;
274            }
275        }
276
277        // サブ情報表示・非表示のチェックに使用する。
278        $this->sub_find = $sub_find;
279    }
280
281    /**
282     * デストラクタ.
283     *
284     * @return void
285     */
286    function destroy() {
287        parent::destroy();
288    }
289
290    /**
291     * 関連商品の名称などを商品マスタから読み込み、一つの配列にまとめて返す
292     *
293     * @return array 関連商品の情報を格納した2次元配列
294     */
295    function lfGetRecommendProducts() {
296        $objQuery = new SC_Query();
297        $arrRecommend = array();
298        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
299            $keyname = "recommend_id" . $i;
300            $delkey = "recommend_delete" . $i;
301            $commentkey = "recommend_comment" . $i;
302
303            if (!isset($this->arrForm[$delkey])) $this->arrForm[$delkey] = null;
304
305            if((isset($this->arrForm[$keyname]) && !empty($this->arrForm[$keyname])) && $this->arrForm[$delkey] != 1) {
306                $objProduct = new SC_Product();
307                $arrRecommend[$i] = $objProduct->getDetail($this->arrForm[$keyname]);
308                $arrRecommend[$i]['product_id'] = $this->arrForm[$keyname];
309                $arrRecommend[$i]['comment'] = $this->arrForm[$commentkey];
310            }
311        }
312        return $arrRecommend;
313    }
314
315    /* 関連商品の登録 */
316    function lfInsertRecommendProducts($objQuery, $arrList, $product_id) {
317        // 一旦関連商品をすべて削除する
318        $objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id));
319        $sqlval['product_id'] = $product_id;
320        $rank = RECOMMEND_PRODUCT_MAX;
321        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
322            $keyname = "recommend_id" . $i;
323            $commentkey = "recommend_comment" . $i;
324            $deletekey = "recommend_delete" . $i;
325
326            if (!isset($arrList[$deletekey])) $arrList[$deletekey] = null;
327
328            if($arrList[$keyname] != "" && $arrList[$deletekey] != '1') {
329                $sqlval['recommend_product_id'] = $arrList[$keyname];
330                $sqlval['comment'] = $arrList[$commentkey];
331                $sqlval['rank'] = $rank;
332                $sqlval['creator_id'] = $_SESSION['member_id'];
333                $sqlval['create_date'] = "now()";
334                $sqlval['update_date'] = "now()";
335                $objQuery->insert("dtb_recommend_products", $sqlval);
336                $rank--;
337            }
338        }
339    }
340
341    /**
342     * 指定商品の関連商品をDBから読み込む
343     *
344     * @param string $product_id 商品ID
345     * @return void
346     */
347    function lfPreGetRecommendProducts($product_id) {
348        $objQuery = new SC_Query();
349        $objQuery->setOrder("rank DESC");
350        $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
351        $no = 1;
352
353        foreach ($arrRet as $ret) {
354            $this->arrForm['recommend_id' . $no] = $ret['recommend_product_id'];
355            $this->arrForm['recommend_comment' . $no] = $ret['comment'];
356            $no++;
357        }
358    }
359
360    /* 商品情報の読み込み */
361    function lfGetProduct($product_id) {
362        $objQuery = new SC_Query();
363        $objDb = new SC_Helper_DB_Ex();
364
365        $col = "*";
366        $table = <<< __EOF__
367                      dtb_products AS T1
368            LEFT JOIN (
369                       SELECT product_id AS product_id_sub,
370                              product_code,
371                              price01,
372                              price02,
373                              stock,
374                              stock_unlimited,
375                              sale_limit,
376                              point_rate,
377                              product_type_id,
378                              down_filename,
379                              down_realfilename
380                         FROM dtb_products_class
381                        WHERE class_combination_id IS NULL
382                       ) AS T2
383                     ON T1.product_id = T2.product_id_sub
384__EOF__;
385        $where = "product_id = ?";
386
387        $arrRet = $objQuery->select($col, $table, $where, array($product_id));
388
389        // カテゴリID を取得
390        $arrRet[0]['category_id'] = $objQuery->getCol(
391            "category_id",
392            "dtb_product_categories",
393            "product_id = ?",
394            array($product_id)
395        );
396        //編集時に規格IDが変わってしまうのを防ぐために規格が登録されていなければ規格IDを取得する
397        if (!$objDb->sfHasProductClass($_POST['product_id'])) {
398            $arrRet[0]['product_class_id'] = SC_Utils::sfGetProductClassId($product_id,"0","0");
399        }
400        return $arrRet[0];
401    }
402
403    /* 商品登録ページ表示用 */
404    function lfProductPage() {
405        $objDb = new SC_Helper_DB_Ex();
406
407        // カテゴリの読込
408        list($this->arrCatVal, $this->arrCatOut) = $objDb->sfGetLevelCatList(false);
409
410        if (isset($this->arrForm['category_id']) && !is_array($this->arrForm['category_id'])) {
411            $this->arrForm['category_id'] = unserialize($this->arrForm['category_id']);
412        }
413        if($this->arrForm['status'] == "") {
414            $this->arrForm['status'] = DEFAULT_PRODUCT_DISP;
415        }
416        if($this->arrForm['product_type_id'] == "") {
417            $this->arrForm['product_type_id'] = DEFAULT_PRODUCT_DOWN;
418        }
419
420        // HIDDEN用に配列を渡す。
421        $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objUpFile->getHiddenFileList());
422        $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objDownFile->getHiddenFileList());
423        // Form用配列を渡す。
424        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
425
426        $this->arrForm['down_realfilename'] = $this->objDownFile->getFormDownFile();
427
428        // アンカーを設定
429        if (isset($_POST['image_key']) && !empty($_POST['image_key'])) {
430            $anchor_hash = "location.hash='#" . $_POST['image_key'] . "'";
431        } elseif (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
432            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
433        } else {
434            $anchor_hash = "";
435        }
436
437        $this->tpl_onload = "fnCheckStockLimit('" . DISABLED_RGB . "'); fnMoveSelect('category_id_unselect', 'category_id');" . $anchor_hash;
438    }
439
440    /* ファイル情報の初期化 */
441    function lfInitFile() {
442        $this->objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg', 'gif', 'png'),IMAGE_SIZE, false, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
443        $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
444        $this->objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT);
445        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
446            $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_WIDTH, NORMAL_SUBIMAGE_HEIGHT);
447            $this->objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_SUBIMAGE_WIDTH, LARGE_SUBIMAGE_HEIGHT);
448        }
449    }
450
451    /* 商品の登録 */
452    function lfRegistProduct($arrList) {
453        $objQuery = new SC_Query();
454        $objDb = new SC_Helper_DB_Ex();
455        $objQuery->begin();
456
457        // 配列の添字を定義
458        $checkArray = array("name", "status",
459                            "main_list_comment", "main_comment",
460                            "deliv_fee", "comment1", "comment2", "comment3",
461                            "comment4", "comment5", "comment6", "main_list_comment",
462                            "sale_limit", "deliv_date_id", "maker_id", "note");
463        $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray);
464
465        // INSERTする値を作成する。
466        $sqlval['name'] = $arrList['name'];
467        $sqlval['status'] = $arrList['status'];
468        $sqlval['main_list_comment'] = $arrList['main_list_comment'];
469        $sqlval['main_comment'] = $arrList['main_comment'];
470        $sqlval['comment1'] = $arrList['comment1'];
471        $sqlval['comment2'] = $arrList['comment2'];
472        $sqlval['comment3'] = $arrList['comment3'];
473        $sqlval['comment4'] = $arrList['comment4'];
474        $sqlval['comment5'] = $arrList['comment5'];
475        $sqlval['comment6'] = $arrList['comment6'];
476        $sqlval['main_list_comment'] = $arrList['main_list_comment'];
477        $sqlval['deliv_date_id'] = $arrList['deliv_date_id'];
478        $sqlval['maker_id'] = $arrList['maker_id'];
479        $sqlval['note'] = $arrList['note'];
480        $sqlval['update_date'] = "Now()";
481        $sqlval['creator_id'] = $_SESSION['member_id'];
482        $arrRet = $this->objUpFile->getDBFileList();
483        $sqlval = array_merge($sqlval, $arrRet);
484
485        $arrList['category_id'] = unserialize($arrList['category_id']);
486
487        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
488            $sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt];
489            $sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt];
490        }
491
492        // 新規登録(複製時を含む)
493        if ($arrList['product_id'] == "") {
494            $product_id = $objQuery->nextVal("dtb_products_product_id");
495            $sqlval['product_id'] = $product_id;
496
497            // INSERTの実行
498            $sqlval['create_date'] = "Now()";
499            $objQuery->insert("dtb_products", $sqlval);
500
501            $arrList['product_id'] = $product_id;
502
503            // カテゴリを更新
504            $objDb->updateProductCategories($arrList['category_id'], $product_id);
505
506            // 複製商品の場合には規格も複製する
507            if($_POST["copy_product_id"] != "" and SC_Utils_Ex::sfIsInt($_POST["copy_product_id"])){
508
509                if($this->tpl_nonclass)
510                {
511                    //規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う
512                    $this->lfCopyProductClass($arrList, $objQuery);
513                }
514                else
515                {
516                    //規格がある場合の複製は複製元の内容で追加登録を行う
517                    // dtb_products_class のカラムを取得
518                    $dbFactory = SC_DB_DBFactory_Ex::getInstance();
519                    $arrColList = $dbFactory->sfGetColumnList("dtb_products_class", $objQuery);
520                    $arrColList_tmp = array_flip($arrColList);
521
522                    // 複製しない列
523                    unset($arrColList[$arrColList_tmp["product_class_id"]]);     //規格ID
524                    unset($arrColList[$arrColList_tmp["product_id"]]);           //商品ID
525                    unset($arrColList[$arrColList_tmp["create_date"]]);
526
527                    $col = SC_Utils_Ex::sfGetCommaList($arrColList);
528                    $product_class_id = $objQuery->nextVal('dtb_products_class_product_class_id');
529                    $objQuery->query("INSERT INTO dtb_products_class (product_class_id, product_id, create_date, ". $col .") SELECT ?, now(), " . $col. " FROM dtb_products_class WHERE product_id = ? ORDER BY product_class_id", array($product_class_id, $product_id, $_POST["copy_product_id"]));
530                }
531            }
532        }
533        // 更新
534        else {
535            $product_id = $arrList['product_id'];
536            // 削除要求のあった既存ファイルの削除
537            $arrRet = $this->lfGetProduct($arrList['product_id']);
538            $this->objUpFile->deleteDBFile($arrRet);
539            $this->objDownFile->deleteDBDownFile($arrRet);
540
541            // UPDATEの実行
542            $where = "product_id = ?";
543            $objQuery->update("dtb_products", $sqlval, $where, array($product_id));
544
545            // カテゴリを更新
546            $objDb->updateProductCategories($arrList['category_id'], $product_id);
547        }
548
549        //商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。
550        if( $_POST["copy_product_id"] == "" ){
551            // 規格登録
552            $this->lfInsertDummyProductClass($arrList);
553        }
554
555        // ステータス設定
556        $objProduct = new SC_Product();
557        $objProduct->setProductStatus($product_id, $arrList['product_status']);
558
559        // 関連商品登録
560        $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id);
561
562        $objQuery->commit();
563        return $product_id;
564    }
565
566
567    /* 取得文字列の変換 */
568    function lfConvertParam($array) {
569        /*
570         *  文字列の変換
571         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
572         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
573         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
574         *  n :  「全角」数字を「半角(ハンカク)」に変換
575         */
576
577        // スポット商品
578        $arrConvList['name'] = "KVa";
579        $arrConvList['main_list_comment'] = "KVa";
580        $arrConvList['main_comment'] = "KVa";
581        $arrConvList['price01'] = "n";
582        $arrConvList['price02'] = "n";
583        $arrConvList['stock'] = "n";
584        $arrConvList['sale_limit'] = "n";
585        $arrConvList['point_rate'] = "n";
586        $arrConvList['product_code'] = "KVna";
587        $arrConvList['comment1'] = "a";
588        $arrConvList['deliv_fee'] = "n";
589
590        // 詳細-サブ
591        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
592            $arrConvList["sub_title$cnt"] = "KVa";
593        }
594        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
595            $arrConvList["sub_comment$cnt"] = "KVa";
596        }
597
598        // 関連商品
599        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
600            $arrConvList["recommend_comment$cnt"] = "KVa";
601        }
602
603        // 文字変換
604        foreach ($arrConvList as $key => $val) {
605            // POSTされてきた値のみ変換する。
606            if(isset($array[$key])) {
607                $array[$key] = mb_convert_kana($array[$key] ,$val);
608            }
609        }
610
611        if (!isset($array['product_flag'])) $array['product_flag'] = "";
612        $max = max(array_keys($this->arrSTATUS));
613        $array['product_flag'] = SC_Utils_Ex::sfMergeCheckBoxes($array['product_flag'], $max);
614
615        return $array;
616    }
617
618    // 入力エラーチェック
619    function lfErrorCheck($array) {
620
621        $objErr = new SC_CheckError($array);
622        $objErr->doFunc(array("商品名", "name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
623        $objErr->doFunc(array("一覧-メインコメント", "main_list_comment", MTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
624        $objErr->doFunc(array("詳細-メインコメント", "main_comment", LLTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
625        $objErr->doFunc(array("詳細-メインコメント", "main_comment", $this->arrAllowedTag), array("HTML_TAG_CHECK"));
626        $objErr->doFunc(array("ポイント付与率", "point_rate", PERCENTAGE_LEN), array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
627        $objErr->doFunc(array("商品送料", "deliv_fee", PRICE_LEN), array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
628        $objErr->doFunc(array("備考欄(SHOP専用)", "note", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
629        $objErr->doFunc(array("検索ワード", "comment3", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
630        $objErr->doFunc(array("メーカーURL", "comment1", URL_LEN), array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK"));
631        $objErr->doFunc(array("発送日目安", "deliv_date_id", INT_LEN), array("NUM_CHECK"));
632        $objErr->doFunc(array("メーカー", 'maker_id', INT_LEN), array("NUM_CHECK"));
633
634        if($this->tpl_nonclass) {
635            $objErr->doFunc(array("商品コード", "product_code", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK"));
636            $objErr->doFunc(array(NORMAL_PRICE_TITLE, "price01", PRICE_LEN), array("NUM_CHECK", "MAX_LENGTH_CHECK"));
637            $objErr->doFunc(array(SALE_PRICE_TITLE, "price02", PRICE_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
638
639            if(!isset($array['stock_unlimited']) && $array['stock_unlimited'] != "1") {
640                $objErr->doFunc(array("在庫数", "stock", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
641            }
642
643            // 支払方法チェック
644            if (empty($array['payment_ids'])) {
645                $objErr->arrErr['payment_ids'] = "※ 支払方法は、いずれかを選択してください。<br />";
646            }
647
648            //ダウンロード商品チェック
649            if($array['product_type_id'] == PRODUCT_TYPE_DOWNLOAD) {
650                $objErr->doFunc(array("ダウンロードファイル名", "down_filename", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
651                if($array['down_realfilename'] == "") {
652                    $objErr->arrErr['down_realfilename'] = "※ ダウンロード商品の場合はダウンロード商品用ファイルをアップロードしてください。<br />";
653                }
654            }
655            //実商品チェック
656            if($array['product_type_id'] == PRODUCT_TYPE_NORMAL) {
657                if($array['down_filename'] != "") {
658                    $objErr->arrErr['down_filename'] = "※ 通常商品の場合はダウンロードファイル名を設定できません。<br />";
659                }
660                if($array['down_realfilename'] != "") {
661                    $objErr->arrErr['down_realfilename'] = "※ 通常商品の場合はダウンロード商品用ファイルをアップロードできません。<br />ファイルを取り消してください。<br />";
662                }
663            }
664        }
665
666        $objErr->doFunc(array("購入制限", "sale_limit", AMOUNT_LEN), array("SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
667
668        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
669            $objErr->doFunc(array("詳細-サブタイトル$cnt", "sub_title$cnt", STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
670            $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
671            $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", $this->arrAllowedTag),  array("HTML_TAG_CHECK"));
672        }
673
674        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
675
676            if (!isset($_POST["recommend_delete$cnt"]))  $_POST["recommend_delete$cnt"] = "";
677
678            if(isset($_POST["recommend_id$cnt"])
679            && $_POST["recommend_id$cnt"] != ""
680            && $_POST["recommend_delete$cnt"] != 1) {
681                $objErr->doFunc(array("関連商品コメント$cnt", "recommend_comment$cnt", LTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
682            }
683        }
684
685        // カテゴリID のチェック
686        if (empty($array['category_id'])) {
687            $objErr->arrErr['category_id'] = "※ 商品カテゴリが選択されていません。<br />";
688        } else {
689            $arrCategory_id = array();
690            for ($i = 0; $i < count($array['category_id']); $i++) {
691                $arrCategory_id['category_id' . $i] = $array['category_id'][$i];
692            }
693            $objCheckCategory = new SC_CheckError($arrCategory_id);
694            for ($i = 0; $i < count($array['category_id']); $i++) {
695                $objCheckCategory->doFunc(array("商品カテゴリ", "category_id" . $i, STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
696            }
697            if (!empty($objCheckCategory->arrErr)) {
698                $objErr->arrErr = array_merge($objErr->arrErr,
699                $objCheckCategory->arrErr);
700            }
701        }
702        return $objErr->arrErr;
703    }
704
705    /* 確認ページ表示用 */
706    function lfProductConfirmPage() {
707        $this->tpl_mainpage = 'products/confirm.tpl';
708        $this->arrForm['mode'] = 'complete';
709
710        $objDb = new SC_Helper_DB_Ex();
711
712        // カテゴリ表示
713        $this->arrCategory_id = $this->arrForm['category_id'];
714        $this->arrCatList = array();
715        list($arrCatVal, $arrCatOut) = $objDb->sfGetLevelCatList(false);
716        for ($i = 0; $i < count($arrCatVal); $i++) {
717            $this->arrCatList[$arrCatVal[$i]] = $arrCatOut[$i];
718        }
719
720        // hidden に渡す値は serialize する
721        $this->arrForm['category_id'] = serialize($this->arrForm['category_id']);
722
723        // Form用配列を渡す。
724        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
725        $this->arrForm['down_realfilename'] = $this->objDownFile->getFormDownFile();
726    }
727
728    // 縮小した画像をセットする
729    function lfSetScaleImage(){
730
731        $subno = str_replace("sub_large_image", "", $_POST['image_key']);
732        switch ($_POST['image_key']){
733            case "main_large_image":
734                // 詳細メイン画像
735                $this->lfMakeScaleImage($_POST['image_key'], "main_image");
736            case "main_image":
737                // 一覧メイン画像
738                $this->lfMakeScaleImage($_POST['image_key'], "main_list_image");
739                break;
740            case "sub_large_image" . $subno:
741                // サブメイン画像
742                $this->lfMakeScaleImage($_POST['image_key'], "sub_image" . $subno);
743                break;
744            default:
745                break;
746        }
747    }
748
749    // 縮小画像生成
750    function lfMakeScaleImage($from_key, $to_key, $forced = false){
751        $arrImageKey = array_flip($this->objUpFile->keyname);
752
753        if($this->objUpFile->temp_file[$arrImageKey[$from_key]]){
754            $from_path = $this->objUpFile->temp_dir . $this->objUpFile->temp_file[$arrImageKey[$from_key]];
755        }elseif($this->objUpFile->save_file[$arrImageKey[$from_key]]){
756            $from_path = $this->objUpFile->save_dir . $this->objUpFile->save_file[$arrImageKey[$from_key]];
757        }else{
758            return "";
759        }
760
761        if(file_exists($from_path)){
762            // 生成先の画像サイズを取得
763            $to_w = $this->objUpFile->width[$arrImageKey[$to_key]];
764            $to_h = $this->objUpFile->height[$arrImageKey[$to_key]];
765
766            if($forced) $this->objUpFile->save_file[$arrImageKey[$to_key]] = "";
767
768            if(empty($this->objUpFile->temp_file[$arrImageKey[$to_key]]) &&
769            empty($this->objUpFile->save_file[$arrImageKey[$to_key]])) {
770
771                // リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
772                $dst_file = $this->objUpFile->lfGetTmpImageName(IMAGE_RENAME, "", $this->objUpFile->temp_file[$arrImageKey[$from_key]]) . $this->lfGetAddSuffix($to_key);
773                $path = $this->objUpFile->makeThumb($from_path, $to_w, $to_h, $dst_file);
774                $this->objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path);
775            }
776        }else{
777            return "";
778        }
779    }
780
781    /**
782     * リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
783     */
784    function lfGetAddSuffix($to_key){
785        if( IMAGE_RENAME === true ){ return ; }
786
787        // 自動生成される画像名
788        $dist_name = "";
789        switch($to_key){
790            case "main_list_image":
791                $dist_name = '_s';
792                break;
793            case "main_image":
794                $dist_name = '_m';
795                break;
796            default:
797                $arrRet = explode('sub_image', $to_key);
798                $dist_name = '_sub' .$arrRet[1];
799                break;
800        }
801        return $dist_name;
802    }
803
804    /**
805     * dtb_products_classの複製
806     * 複製後、価格や商品コードを更新する
807     *
808     * @param array $arrList
809     * @param array $objQuery
810     * @return bool
811     */
812    function lfCopyProductClass($arrList,$objQuery)
813    {
814        // 複製元のdtb_products_classを取得(規格なしのため、1件のみの取得)
815        $col = "*";
816        $table = "dtb_products_class";
817        $where = "product_id = ?";
818        $arrProductClass = $objQuery->select($col, $table, $where, array($arrList["copy_product_id"]));
819
820        //トランザクション開始
821        $objQuery->begin();
822        $err_flag = false;
823        //非編集項目は複製、編集項目は上書きして登録
824        foreach($arrProductClass as $records)
825        {
826            foreach($records as $key => $value)
827            {
828                if(isset($arrList[$key]))
829                {
830                    $records[$key] = $arrList[$key];
831                }
832            }
833
834            $records["product_class_id"] = $objQuery->nextVal('dtb_products_class_product_class_id');
835            unset($records["update_date"]);
836
837            $records["create_date"] = "Now()";
838            $objQuery->insert($table, $records);
839            //エラー発生時は中断
840            if($objQuery->isError())
841            {
842                $err_flag = true;
843                continue;
844            }
845        }
846        //トランザクション終了
847        if($err_flag)
848        {
849            $objQuery->rollback();
850        }
851        else
852        {
853            $objQuery->commit();
854        }
855        return !$err_flag;
856    }
857
858    /**
859     * 規格を設定していない商品を商品規格テーブルに登録
860     *
861     * @param array $arrList
862     * @return void
863     */
864    function lfInsertDummyProductClass($arrList) {
865        $objQuery = new SC_Query();
866        $objDb = new SC_Helper_DB_Ex();
867
868        $product_id = $arrList['product_id'];
869        // 規格登録してある商品の場合、処理しない
870        if ($objDb->sfHasProductClass($product_id)) return;
871
872        // 配列の添字を定義
873        $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');
874        $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $checkArray);
875        $sqlval = SC_Utils_Ex::arrayDefineIndexes($sqlval, $checkArray);
876
877        $sqlval['stock_unlimited'] = $sqlval['stock_unlimited'] ? '1' : '0';
878        $sqlval['creator_id'] = strlen($_SESSION['member_id']) >= 1 ? $_SESSION['member_id'] : '0';
879
880        if (strlen($sqlval['product_class_id']) == 0) {
881            $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id');
882            $sqlval['create_date'] = 'now()';
883            $sqlval['update_date'] = 'now()';
884            // INSERTの実行
885            $objQuery->insert('dtb_products_class', $sqlval);
886        } else {
887            $sqlval['update_date'] = 'now()';
888            // UPDATEの実行
889            $objQuery->update('dtb_products_class', $sqlval, "product_class_id = ?", array($sqlval['product_class_id']));
890
891        }
892
893        $objProduct = new SC_Product();
894        $objProduct->setPaymentOptions($sqlval['product_class_id'], $arrList['payment_ids']);
895    }
896
897    /* ダウンロードファイル情報の初期化 */
898    function lfInitDownFile() {
899        $this->objDownFile->addFile("ダウンロード販売用ファイル", 'down_file', explode(",", DOWNLOAD_EXTENSION),DOWN_SIZE, true, 0, 0);
900    }
901}
902?>
Note: See TracBrowser for help on using the repository browser.