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

Revision 20041, 42.0 KB checked in by eccuore, 13 years ago (diff)

#642(共通ロジックの機能向上) mode 取得用の関数を利用するように修正(switchリファクタリングは未対応)

  • 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        switch($this->getMode()) {
134            // 検索画面からの編集
135            case 'pre_edit':
136            case 'copy' :
137                if (!SC_Utils_Ex::sfIsInt($_POST['product_id'])) {
138                    SC_Utils_Ex::sfDispException();
139                }
140
141                // DBから商品情報の読込
142                $this->arrForm = $this->lfGetProduct($_POST['product_id']);
143                $productStatus= $objProduct->getProductStatus(array($_POST['product_id']));
144                $this->arrForm['product_status'] = $productStatus[$_POST['product_id']];
145                $this->arrForm['payment_ids'] = $objProduct->getEnablePaymentIds(array($this->arrForm['product_class_id']));
146
147                // DBデータから画像ファイル名の読込
148                $this->objUpFile->setDBFileList($this->arrForm);
149                // DBデータからダウンロードファイル名の読込
150                $this->objDownFile->setDBDownFile($this->arrForm);
151
152                // 商品ステータスの変換
153                $arrRet = SC_Utils_Ex::sfSplitCBValue($this->arrForm['product_flag'], "product_flag");
154                $this->arrForm = array_merge($this->arrForm, $arrRet);
155                // DBから関連商品の読み込み
156                $this->lfPreGetRecommendProducts($_POST['product_id']);
157
158                $this->lfProductPage();     // 商品登録ページ
159
160                if($this->getMode() == "copy"){
161                    $this->arrForm["copy_product_id"] = $this->arrForm["product_id"];
162                    $this->arrForm["product_id"] = "";
163                    // 画像ファイルのコピー
164                    $arrKey = $this->objUpFile->keyname;
165                    $arrSaveFile = $this->objUpFile->save_file;
166
167                    foreach($arrSaveFile as $key => $val){
168                        $this->lfMakeScaleImage($arrKey[$key], $arrKey[$key], true);
169                    }
170                }
171                break;
172            // 商品登録・編集
173            case 'edit':
174                if($_POST['product_id'] == "" and SC_Utils_Ex::sfIsInt($_POST['copy_product_id'])){
175                    $this->tpl_nonclass = !$objDb->sfHasProductClass($_POST['copy_product_id']);
176                }
177
178                // 入力値の変換
179                $this->arrForm = $this->lfConvertParam($this->arrForm);
180                // エラーチェック
181                $this->arrErr = $this->lfErrorCheck($this->arrForm);
182                // ファイル存在チェック
183                $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS());
184                // エラーなしの場合
185                if(count($this->arrErr) == 0) {
186                    $this->lfProductConfirmPage(); // 確認ページ
187                } else {
188                    $this->lfProductPage();     // 商品登録ページ
189                }
190                break;
191            // 確認ページから完了ページへ
192            case 'complete':
193                $this->tpl_mainpage = 'products/complete.tpl';
194
195                $this->arrForm['product_id'] = $this->lfRegistProduct($_POST);      // データ登録
196
197                // 件数カウントバッチ実行
198                $objDb->sfCountCategory($objQuery);
199                $objDb->sfCountMaker($objQuery);
200                // 一時ファイルを本番ディレクトリに移動する
201                // TODO: SC_UploadFile::moveTempFileの画像削除条件見直し要
202                $objImage = new SC_Image($this->objUpFile->temp_dir);
203                $arrKeyName = $this->objUpFile->keyname;
204                $arrTempFile = $this->objUpFile->temp_file;
205                $arrSaveFile = $this->objUpFile->save_file;
206                $arrImageKey = array();
207                foreach ($arrTempFile as $key => $temp_file) {
208                    if ($temp_file) {
209                        $objImage->moveTempImage($temp_file, $this->objUpFile->save_dir);
210                        $arrImageKey[] = $arrKeyName[$key];
211                        if (!empty($arrSaveFile[$key]) && !$this->lfHasSameProductImage($this->arrForm['product_id'], $arrImageKey, $arrSaveFile[$key]) && !in_array($temp_file, $arrSaveFile)) {
212                            $objImage->deleteImage($arrSaveFile[$key], $this->objUpFile->save_dir);
213                        }
214                    }
215                }
216                $this->objDownFile->moveTempDownFile();
217
218                break;
219            // 画像のアップロード
220            case 'upload_image':
221                // ファイル存在チェック
222                $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS($_POST['image_key']));
223                // 画像保存処理
224                $this->arrErr[$_POST['image_key']] = $this->objUpFile->makeTempFile($_POST['image_key'],IMAGE_RENAME);
225
226                // 中、小画像生成
227                $this->lfSetScaleImage();
228
229                $this->lfProductPage(); // 商品登録ページ
230                break;
231            // 画像の削除
232            case 'delete_image':
233                // TODO: SC_UploadFile::deleteFileの画像削除条件見直し要
234                $arrTempFile = $this->objUpFile->temp_file;
235                $arrKeyName = $this->objUpFile->keyname;
236                foreach ($arrKeyName as $key => $keyname) {
237                    if ($keyname != $_POST['image_key']) continue;
238                    if (!empty($arrTempFile[$key])) {
239                        $temp_file = $arrTempFile[$key];
240                        $arrTempFile[$key] = '';
241                        if (!in_array($temp_file, $arrTempFile)) {
242                            $this->objUpFile->deleteFile($_POST['image_key']);
243                        } else {
244                            $this->objUpFile->temp_file[$key] = '';
245                            $this->objUpFile->save_file[$key] = '';
246                        }
247                    } else {
248                        $this->objUpFile->temp_file[$key] = '';
249                        $this->objUpFile->save_file[$key] = '';
250                    }
251                }
252                $this->lfProductPage(); // 商品登録ページ
253                break;
254            // ダウンロード商品ファイルアップロード
255            case 'upload_down':
256                // ファイル存在チェック
257                $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objDownFile->checkEXISTS($_POST['down_key']));
258                // 画像保存処理
259                $this->arrErr[$_POST['down_key']] = $this->objDownFile->makeTempDownFile();
260
261                $this->lfProductPage(); // 商品登録ページ
262                break;
263            // ダウンロードファイルの削除
264            case 'delete_down':
265                $this->objDownFile->deleteFile($_POST['down_key']);
266                $this->lfProductPage(); // 商品登録ページ
267                break;
268            // 確認ページからの戻り
269            case 'confirm_return':
270                $this->lfProductPage();     // 商品登録ページ
271                break;
272            // 関連商品選択
273            case 'recommend_select' :
274                $this->lfProductPage();     // 商品登録ページ
275                break;
276            default:
277                $this->lfProductPage();     // 商品登録ページ
278                break;
279        }
280
281        // 関連商品の読み込み
282        $this->arrRecommend = $this->lfGetRecommendProducts();
283
284        // 基本情報を渡す
285        $this->arrInfo = $objSiteInfo->data;
286
287        // サブ情報の入力があるかどうかチェックする
288        $sub_find = false;
289        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
290            if( (isset($this->arrForm['sub_title'.$cnt])
291            && !empty($this->arrForm['sub_title'.$cnt])) ||
292            (isset($this->arrForm['sub_comment'.$cnt])
293            && !empty($this->arrForm['sub_comment'.$cnt])) ||
294            (isset($this->arrForm['sub_image'.$cnt])
295            && !empty($this->arrForm['sub_image'.$cnt])) ||
296            (isset($this->arrForm['sub_large_image'.$cnt])
297            && !empty($this->arrForm['sub_large_image'.$cnt])) ||
298            (isset($this->arrForm['sub_image'.$cnt])
299            && is_array($this->arrFile['sub_image'.$cnt])) ||
300            (isset($this->arrForm['sub_large_image'.$cnt])
301            && is_array($this->arrFile['sub_large_image'.$cnt]))) {
302                $sub_find = true;
303                break;
304            }
305        }
306
307        // サブ情報表示・非表示のチェックに使用する。
308        $this->sub_find = $sub_find;
309    }
310
311    /**
312     * デストラクタ.
313     *
314     * @return void
315     */
316    function destroy() {
317        parent::destroy();
318    }
319
320    /**
321     * 関連商品の名称などを商品マスタから読み込み、一つの配列にまとめて返す
322     *
323     * @return array 関連商品の情報を格納した2次元配列
324     */
325    function lfGetRecommendProducts() {
326        $objQuery = new SC_Query();
327        $arrRecommend = array();
328        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
329            $keyname = "recommend_id" . $i;
330            $delkey = "recommend_delete" . $i;
331            $commentkey = "recommend_comment" . $i;
332
333            if (!isset($this->arrForm[$delkey])) $this->arrForm[$delkey] = null;
334
335            if((isset($this->arrForm[$keyname]) && !empty($this->arrForm[$keyname])) && $this->arrForm[$delkey] != 1) {
336                $objProduct = new SC_Product();
337                $arrRecommend[$i] = $objProduct->getDetail($this->arrForm[$keyname]);
338                $arrRecommend[$i]['product_id'] = $this->arrForm[$keyname];
339                $arrRecommend[$i]['comment'] = $this->arrForm[$commentkey];
340            }
341        }
342        return $arrRecommend;
343    }
344
345    /* 関連商品の登録 */
346    function lfInsertRecommendProducts($objQuery, $arrList, $product_id) {
347        // 一旦関連商品をすべて削除する
348        $objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id));
349        $sqlval['product_id'] = $product_id;
350        $rank = RECOMMEND_PRODUCT_MAX;
351        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
352            $keyname = "recommend_id" . $i;
353            $commentkey = "recommend_comment" . $i;
354            $deletekey = "recommend_delete" . $i;
355
356            if (!isset($arrList[$deletekey])) $arrList[$deletekey] = null;
357
358            if($arrList[$keyname] != "" && $arrList[$deletekey] != '1') {
359                $sqlval['recommend_product_id'] = $arrList[$keyname];
360                $sqlval['comment'] = $arrList[$commentkey];
361                $sqlval['rank'] = $rank;
362                $sqlval['creator_id'] = $_SESSION['member_id'];
363                $sqlval['create_date'] = "now()";
364                $sqlval['update_date'] = "now()";
365                $objQuery->insert("dtb_recommend_products", $sqlval);
366                $rank--;
367            }
368        }
369    }
370
371    /**
372     * 指定商品の関連商品をDBから読み込む
373     *
374     * @param string $product_id 商品ID
375     * @return void
376     */
377    function lfPreGetRecommendProducts($product_id) {
378        $objQuery = new SC_Query();
379        $objQuery->setOrder("rank DESC");
380        $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
381        $no = 1;
382
383        foreach ($arrRet as $ret) {
384            $this->arrForm['recommend_id' . $no] = $ret['recommend_product_id'];
385            $this->arrForm['recommend_comment' . $no] = $ret['comment'];
386            $no++;
387        }
388    }
389
390    /* 商品情報の読み込み */
391    function lfGetProduct($product_id) {
392        $objQuery = new SC_Query();
393        $objDb = new SC_Helper_DB_Ex();
394
395        $col = "*";
396        $table = <<< __EOF__
397                      dtb_products AS T1
398            LEFT JOIN (
399                       SELECT product_id AS product_id_sub,
400                              product_code,
401                              price01,
402                              price02,
403                              stock,
404                              stock_unlimited,
405                              sale_limit,
406                              point_rate,
407                              product_type_id,
408                              down_filename,
409                              down_realfilename
410                         FROM dtb_products_class
411                        WHERE class_combination_id IS NULL
412                       ) AS T2
413                     ON T1.product_id = T2.product_id_sub
414__EOF__;
415        $where = "product_id = ?";
416
417        $arrRet = $objQuery->select($col, $table, $where, array($product_id));
418
419        // カテゴリID を取得
420        $arrRet[0]['category_id'] = $objQuery->getCol(
421            "category_id",
422            "dtb_product_categories",
423            "product_id = ?",
424            array($product_id)
425        );
426        //編集時に規格IDが変わってしまうのを防ぐために規格が登録されていなければ規格IDを取得する
427        if (!$objDb->sfHasProductClass($_POST['product_id'])) {
428            $arrRet[0]['product_class_id'] = SC_Utils::sfGetProductClassId($product_id,"0","0");
429        }
430        return $arrRet[0];
431    }
432
433    /* 商品登録ページ表示用 */
434    function lfProductPage() {
435        $objDb = new SC_Helper_DB_Ex();
436
437        // カテゴリの読込
438        list($this->arrCatVal, $this->arrCatOut) = $objDb->sfGetLevelCatList(false);
439
440        if (isset($this->arrForm['category_id']) && !is_array($this->arrForm['category_id'])) {
441            $this->arrForm['category_id'] = unserialize($this->arrForm['category_id']);
442        }
443        if($this->arrForm['status'] == "") {
444            $this->arrForm['status'] = DEFAULT_PRODUCT_DISP;
445        }
446        if($this->arrForm['product_type_id'] == "") {
447            $this->arrForm['product_type_id'] = DEFAULT_PRODUCT_DOWN;
448        }
449
450        // HIDDEN用に配列を渡す。
451        $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objUpFile->getHiddenFileList());
452        $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objDownFile->getHiddenFileList());
453        // Form用配列を渡す。
454        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH);
455
456        $this->arrForm['down_realfilename'] = $this->objDownFile->getFormDownFile();
457
458        // アンカーを設定
459        if (isset($_POST['image_key']) && !empty($_POST['image_key'])) {
460            $anchor_hash = "location.hash='#" . $_POST['image_key'] . "'";
461        } elseif (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
462            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
463        } else {
464            $anchor_hash = "";
465        }
466
467        $this->tpl_onload = "fnCheckStockLimit('" . DISABLED_RGB . "'); fnMoveSelect('category_id_unselect', 'category_id');" . $anchor_hash;
468    }
469
470    /* ファイル情報の初期化 */
471    function lfInitFile() {
472        $this->objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg', 'gif', 'png'),IMAGE_SIZE, false, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
473        $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
474        $this->objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT);
475        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
476            $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_WIDTH, NORMAL_SUBIMAGE_HEIGHT);
477            $this->objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_SUBIMAGE_WIDTH, LARGE_SUBIMAGE_HEIGHT);
478        }
479    }
480
481    /* 商品の登録 */
482    function lfRegistProduct($arrList) {
483        $objQuery = new SC_Query();
484        $objDb = new SC_Helper_DB_Ex();
485        $objQuery->begin();
486
487        // 配列の添字を定義
488        $checkArray = array("name", "status",
489                            "main_list_comment", "main_comment",
490                            "deliv_fee", "comment1", "comment2", "comment3",
491                            "comment4", "comment5", "comment6", "main_list_comment",
492                            "sale_limit", "deliv_date_id", "maker_id", "note");
493        $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray);
494
495        // INSERTする値を作成する。
496        $sqlval['name'] = $arrList['name'];
497        $sqlval['status'] = $arrList['status'];
498        $sqlval['main_list_comment'] = $arrList['main_list_comment'];
499        $sqlval['main_comment'] = $arrList['main_comment'];
500        $sqlval['comment1'] = $arrList['comment1'];
501        $sqlval['comment2'] = $arrList['comment2'];
502        $sqlval['comment3'] = $arrList['comment3'];
503        $sqlval['comment4'] = $arrList['comment4'];
504        $sqlval['comment5'] = $arrList['comment5'];
505        $sqlval['comment6'] = $arrList['comment6'];
506        $sqlval['main_list_comment'] = $arrList['main_list_comment'];
507        $sqlval['deliv_date_id'] = $arrList['deliv_date_id'];
508        $sqlval['maker_id'] = $arrList['maker_id'];
509        $sqlval['note'] = $arrList['note'];
510        $sqlval['update_date'] = "Now()";
511        $sqlval['creator_id'] = $_SESSION['member_id'];
512        $arrRet = $this->objUpFile->getDBFileList();
513        $sqlval = array_merge($sqlval, $arrRet);
514
515        $arrList['category_id'] = unserialize($arrList['category_id']);
516
517        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
518            $sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt];
519            $sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt];
520        }
521
522        // 新規登録(複製時を含む)
523        if ($arrList['product_id'] == "") {
524            $product_id = $objQuery->nextVal("dtb_products_product_id");
525            $sqlval['product_id'] = $product_id;
526
527            // INSERTの実行
528            $sqlval['create_date'] = "Now()";
529            $objQuery->insert("dtb_products", $sqlval);
530
531            $arrList['product_id'] = $product_id;
532
533            // カテゴリを更新
534            $objDb->updateProductCategories($arrList['category_id'], $product_id);
535
536            // 複製商品の場合には規格も複製する
537            if($_POST["copy_product_id"] != "" and SC_Utils_Ex::sfIsInt($_POST["copy_product_id"])){
538
539                if($this->tpl_nonclass)
540                {
541                    //規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う
542                    $this->lfCopyProductClass($arrList, $objQuery);
543                }
544                else
545                {
546                    //規格がある場合の複製は複製元の内容で追加登録を行う
547                    // dtb_products_class のカラムを取得
548                    $dbFactory = SC_DB_DBFactory_Ex::getInstance();
549                    $arrColList = $dbFactory->sfGetColumnList("dtb_products_class", $objQuery);
550                    $arrColList_tmp = array_flip($arrColList);
551
552                    // 複製しない列
553                    unset($arrColList[$arrColList_tmp["product_class_id"]]);     //規格ID
554                    unset($arrColList[$arrColList_tmp["product_id"]]);           //商品ID
555                    unset($arrColList[$arrColList_tmp["create_date"]]);
556
557                    $col = SC_Utils_Ex::sfGetCommaList($arrColList);
558                    $product_class_id = $objQuery->nextVal('dtb_products_class_product_class_id');
559                    $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"]));
560                }
561            }
562        }
563        // 更新
564        else {
565            $product_id = $arrList['product_id'];
566            // 削除要求のあった既存ファイルの削除
567            $arrRet = $this->lfGetProduct($arrList['product_id']);
568            // TODO: SC_UploadFile::deleteDBFileの画像削除条件見直し要
569            $objImage = new SC_Image($this->objUpFile->temp_dir);
570            $arrKeyName = $this->objUpFile->keyname;
571            $arrSaveFile = $this->objUpFile->save_file;
572            $arrImageKey = array();
573            foreach ($arrKeyName as $key => $keyname) {
574                if ($arrRet[$keyname] && !$arrSaveFile[$key]) {
575                    $arrImageKey[] = $keyname;
576                    $has_same_image = $this->lfHasSameProductImage($arrList['product_id'], $arrImageKey, $arrRet[$keyname]);
577                    if (!$has_same_image) {
578                        $objImage->deleteImage($arrRet[$keyname], $this->objUpFile->save_dir);
579                    }
580                }
581            }
582            $this->objDownFile->deleteDBDownFile($arrRet);
583
584            // UPDATEの実行
585            $where = "product_id = ?";
586            $objQuery->update("dtb_products", $sqlval, $where, array($product_id));
587
588            // カテゴリを更新
589            $objDb->updateProductCategories($arrList['category_id'], $product_id);
590        }
591
592        //商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。
593        if( $_POST["copy_product_id"] == "" ){
594            // 規格登録
595            $this->lfInsertDummyProductClass($arrList);
596        }
597
598        // ステータス設定
599        $objProduct = new SC_Product();
600        $objProduct->setProductStatus($product_id, $arrList['product_status']);
601
602        // 関連商品登録
603        $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id);
604
605        $objQuery->commit();
606        return $product_id;
607    }
608
609
610    /* 取得文字列の変換 */
611    function lfConvertParam($array) {
612        /*
613         *  文字列の変換
614         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
615         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
616         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
617         *  n :  「全角」数字を「半角(ハンカク)」に変換
618         */
619
620        // スポット商品
621        $arrConvList['name'] = "KVa";
622        $arrConvList['main_list_comment'] = "KVa";
623        $arrConvList['main_comment'] = "KVa";
624        $arrConvList['price01'] = "n";
625        $arrConvList['price02'] = "n";
626        $arrConvList['stock'] = "n";
627        $arrConvList['sale_limit'] = "n";
628        $arrConvList['point_rate'] = "n";
629        $arrConvList['product_code'] = "KVna";
630        $arrConvList['comment1'] = "a";
631        $arrConvList['deliv_fee'] = "n";
632
633        // 詳細-サブ
634        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
635            $arrConvList["sub_title$cnt"] = "KVa";
636        }
637        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
638            $arrConvList["sub_comment$cnt"] = "KVa";
639        }
640
641        // 関連商品
642        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
643            $arrConvList["recommend_comment$cnt"] = "KVa";
644        }
645
646        // 文字変換
647        foreach ($arrConvList as $key => $val) {
648            // POSTされてきた値のみ変換する。
649            if(isset($array[$key])) {
650                $array[$key] = mb_convert_kana($array[$key] ,$val);
651            }
652        }
653
654        if (!isset($array['product_flag'])) $array['product_flag'] = "";
655        $max = max(array_keys($this->arrSTATUS));
656        $array['product_flag'] = SC_Utils_Ex::sfMergeCheckBoxes($array['product_flag'], $max);
657
658        return $array;
659    }
660
661    // 入力エラーチェック
662    function lfErrorCheck($array) {
663
664        $objErr = new SC_CheckError($array);
665        $objErr->doFunc(array("商品名", "name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
666        $objErr->doFunc(array("一覧-メインコメント", "main_list_comment", MTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
667        $objErr->doFunc(array("詳細-メインコメント", "main_comment", LLTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
668        $objErr->doFunc(array("詳細-メインコメント", "main_comment", $this->arrAllowedTag), array("HTML_TAG_CHECK"));
669        $objErr->doFunc(array("ポイント付与率", "point_rate", PERCENTAGE_LEN), array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
670        $objErr->doFunc(array("商品送料", "deliv_fee", PRICE_LEN), array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
671        $objErr->doFunc(array("備考欄(SHOP専用)", "note", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
672        $objErr->doFunc(array("検索ワード", "comment3", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
673        $objErr->doFunc(array("メーカーURL", "comment1", URL_LEN), array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK"));
674        $objErr->doFunc(array("発送日目安", "deliv_date_id", INT_LEN), array("NUM_CHECK"));
675        $objErr->doFunc(array("メーカー", 'maker_id', INT_LEN), array("NUM_CHECK"));
676
677        if($this->tpl_nonclass) {
678            $objErr->doFunc(array("商品コード", "product_code", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK"));
679            $objErr->doFunc(array(NORMAL_PRICE_TITLE, "price01", PRICE_LEN), array("NUM_CHECK", "MAX_LENGTH_CHECK"));
680            $objErr->doFunc(array(SALE_PRICE_TITLE, "price02", PRICE_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
681
682            if(!isset($array['stock_unlimited']) && $array['stock_unlimited'] != UNLIMITED_FLG_UNLIMITED) {
683                $objErr->doFunc(array("在庫数", "stock", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
684            }
685
686            // 支払方法チェック
687            if (empty($array['payment_ids'])) {
688                $objErr->arrErr['payment_ids'] = "※ 支払方法は、いずれかを選択してください。<br />";
689            }
690
691            //ダウンロード商品チェック
692            if($array['product_type_id'] == PRODUCT_TYPE_DOWNLOAD) {
693                $objErr->doFunc(array("ダウンロードファイル名", "down_filename", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
694                if($array['down_realfilename'] == "") {
695                    $objErr->arrErr['down_realfilename'] = "※ ダウンロード商品の場合はダウンロード商品用ファイルをアップロードしてください。<br />";
696                }
697            }
698            //実商品チェック
699            if($array['product_type_id'] == PRODUCT_TYPE_NORMAL) {
700                if($array['down_filename'] != "") {
701                    $objErr->arrErr['down_filename'] = "※ 通常商品の場合はダウンロードファイル名を設定できません。<br />";
702                }
703                if($array['down_realfilename'] != "") {
704                    $objErr->arrErr['down_realfilename'] = "※ 通常商品の場合はダウンロード商品用ファイルをアップロードできません。<br />ファイルを取り消してください。<br />";
705                }
706            }
707        }
708
709        $objErr->doFunc(array("購入制限", "sale_limit", AMOUNT_LEN), array("SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
710
711        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
712            $objErr->doFunc(array("詳細-サブタイトル$cnt", "sub_title$cnt", STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
713            $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
714            $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", $this->arrAllowedTag),  array("HTML_TAG_CHECK"));
715        }
716
717        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
718
719            if (!isset($_POST["recommend_delete$cnt"]))  $_POST["recommend_delete$cnt"] = "";
720
721            if(isset($_POST["recommend_id$cnt"])
722            && $_POST["recommend_id$cnt"] != ""
723            && $_POST["recommend_delete$cnt"] != 1) {
724                $objErr->doFunc(array("関連商品コメント$cnt", "recommend_comment$cnt", LTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
725            }
726        }
727
728        // カテゴリID のチェック
729        if (empty($array['category_id'])) {
730            $objErr->arrErr['category_id'] = "※ 商品カテゴリが選択されていません。<br />";
731        } else {
732            $arrCategory_id = array();
733            for ($i = 0; $i < count($array['category_id']); $i++) {
734                $arrCategory_id['category_id' . $i] = $array['category_id'][$i];
735            }
736            $objCheckCategory = new SC_CheckError($arrCategory_id);
737            for ($i = 0; $i < count($array['category_id']); $i++) {
738                $objCheckCategory->doFunc(array("商品カテゴリ", "category_id" . $i, STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
739            }
740            if (!empty($objCheckCategory->arrErr)) {
741                $objErr->arrErr = array_merge($objErr->arrErr,
742                $objCheckCategory->arrErr);
743            }
744        }
745        return $objErr->arrErr;
746    }
747
748    /* 確認ページ表示用 */
749    function lfProductConfirmPage() {
750        $this->tpl_mainpage = 'products/confirm.tpl';
751        $this->arrForm['mode'] = 'complete';
752
753        $objDb = new SC_Helper_DB_Ex();
754
755        // カテゴリ表示
756        $this->arrCategory_id = $this->arrForm['category_id'];
757        $this->arrCatList = array();
758        list($arrCatVal, $arrCatOut) = $objDb->sfGetLevelCatList(false);
759        for ($i = 0; $i < count($arrCatVal); $i++) {
760            $this->arrCatList[$arrCatVal[$i]] = $arrCatOut[$i];
761        }
762
763        // hidden に渡す値は serialize する
764        $this->arrForm['category_id'] = serialize($this->arrForm['category_id']);
765
766        // Form用配列を渡す。
767        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH);
768        $this->arrForm['down_realfilename'] = $this->objDownFile->getFormDownFile();
769    }
770
771    // 縮小した画像をセットする
772    function lfSetScaleImage(){
773
774        $subno = str_replace("sub_large_image", "", $_POST['image_key']);
775        switch ($_POST['image_key']){
776            case "main_large_image":
777                // 詳細メイン画像
778                $this->lfMakeScaleImage($_POST['image_key'], "main_image");
779            case "main_image":
780                // 一覧メイン画像
781                $this->lfMakeScaleImage($_POST['image_key'], "main_list_image");
782                break;
783            case "sub_large_image" . $subno:
784                // サブメイン画像
785                $this->lfMakeScaleImage($_POST['image_key'], "sub_image" . $subno);
786                break;
787            default:
788                break;
789        }
790    }
791
792    // 縮小画像生成
793    function lfMakeScaleImage($from_key, $to_key, $forced = false){
794        $arrImageKey = array_flip($this->objUpFile->keyname);
795
796        if($this->objUpFile->temp_file[$arrImageKey[$from_key]]){
797            $from_path = $this->objUpFile->temp_dir . $this->objUpFile->temp_file[$arrImageKey[$from_key]];
798        }elseif($this->objUpFile->save_file[$arrImageKey[$from_key]]){
799            $from_path = $this->objUpFile->save_dir . $this->objUpFile->save_file[$arrImageKey[$from_key]];
800        }else{
801            return "";
802        }
803
804        if(file_exists($from_path)){
805            // 生成先の画像サイズを取得
806            $to_w = $this->objUpFile->width[$arrImageKey[$to_key]];
807            $to_h = $this->objUpFile->height[$arrImageKey[$to_key]];
808
809            if($forced) $this->objUpFile->save_file[$arrImageKey[$to_key]] = "";
810
811            if(empty($this->objUpFile->temp_file[$arrImageKey[$to_key]]) &&
812            empty($this->objUpFile->save_file[$arrImageKey[$to_key]])) {
813
814                // リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
815                $dst_file = $this->objUpFile->lfGetTmpImageName(IMAGE_RENAME, "", $this->objUpFile->temp_file[$arrImageKey[$from_key]]) . $this->lfGetAddSuffix($to_key);
816                $path = $this->objUpFile->makeThumb($from_path, $to_w, $to_h, $dst_file);
817                $this->objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path);
818            }
819        }else{
820            return "";
821        }
822    }
823
824    /**
825     * リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
826     */
827    function lfGetAddSuffix($to_key){
828        if( IMAGE_RENAME === true ){ return ; }
829
830        // 自動生成される画像名
831        $dist_name = "";
832        switch($to_key){
833            case "main_list_image":
834                $dist_name = '_s';
835                break;
836            case "main_image":
837                $dist_name = '_m';
838                break;
839            default:
840                $arrRet = explode('sub_image', $to_key);
841                $dist_name = '_sub' .$arrRet[1];
842                break;
843        }
844        return $dist_name;
845    }
846
847    /**
848     * dtb_products_classの複製
849     * 複製後、価格や商品コードを更新する
850     *
851     * @param array $arrList
852     * @param array $objQuery
853     * @return bool
854     */
855    function lfCopyProductClass($arrList,$objQuery)
856    {
857        // 複製元のdtb_products_classを取得(規格なしのため、1件のみの取得)
858        $col = "*";
859        $table = "dtb_products_class";
860        $where = "product_id = ?";
861        $arrProductClass = $objQuery->select($col, $table, $where, array($arrList["copy_product_id"]));
862
863        //トランザクション開始
864        $objQuery->begin();
865        $err_flag = false;
866        //非編集項目は複製、編集項目は上書きして登録
867        foreach($arrProductClass as $records)
868        {
869            foreach($records as $key => $value)
870            {
871                if(isset($arrList[$key]))
872                {
873                    $records[$key] = $arrList[$key];
874                }
875            }
876
877            $records["product_class_id"] = $objQuery->nextVal('dtb_products_class_product_class_id');
878            $records["update_date"] = 'now()';
879            $records["create_date"] = "Now()";
880            $objQuery->insert($table, $records);
881            //エラー発生時は中断
882            if($objQuery->isError())
883            {
884                $err_flag = true;
885                continue;
886            }
887        }
888        //トランザクション終了
889        if($err_flag)
890        {
891            $objQuery->rollback();
892        }
893        else
894        {
895            $objQuery->commit();
896        }
897        return !$err_flag;
898    }
899
900    /**
901     * 規格を設定していない商品を商品規格テーブルに登録
902     *
903     * @param array $arrList
904     * @return void
905     */
906    function lfInsertDummyProductClass($arrList) {
907        $objQuery = new SC_Query();
908        $objDb = new SC_Helper_DB_Ex();
909
910        $product_id = $arrList['product_id'];
911        // 規格登録してある商品の場合、処理しない
912        if ($objDb->sfHasProductClass($product_id)) return;
913
914        // 配列の添字を定義
915        $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');
916        $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $checkArray);
917        $sqlval = SC_Utils_Ex::arrayDefineIndexes($sqlval, $checkArray);
918
919        $sqlval['stock_unlimited'] = $sqlval['stock_unlimited'] ? UNLIMITED_FLG_UNLIMITED : UNLIMITED_FLG_LIMITED;
920        $sqlval['creator_id'] = strlen($_SESSION['member_id']) >= 1 ? $_SESSION['member_id'] : '0';
921
922        if (strlen($sqlval['product_class_id']) == 0) {
923            $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id');
924            $sqlval['create_date'] = 'now()';
925            $sqlval['update_date'] = 'now()';
926            // INSERTの実行
927            $objQuery->insert('dtb_products_class', $sqlval);
928        } else {
929            $sqlval['update_date'] = 'now()';
930            // UPDATEの実行
931            $objQuery->update('dtb_products_class', $sqlval, "product_class_id = ?", array($sqlval['product_class_id']));
932
933        }
934
935        $objProduct = new SC_Product();
936        $objProduct->setPaymentOptions($sqlval['product_class_id'], $arrList['payment_ids']);
937    }
938
939    /* ダウンロードファイル情報の初期化 */
940    function lfInitDownFile() {
941        $this->objDownFile->addFile("ダウンロード販売用ファイル", 'down_file', explode(",", DOWNLOAD_EXTENSION),DOWN_SIZE, true, 0, 0);
942    }
943
944    /**
945     * 同名画像ファイル登録の有無を確認する.
946     *
947     * 画像ファイルの削除可否判定用。
948     * 同名ファイルの登録がある場合には画像ファイルの削除を行わない。
949     * 戻り値: 同名ファイル有り(true) 同名ファイル無し(false)
950     *
951     * @param string $product_id 商品ID
952     * @param string $arrImageKey 対象としない画像カラム名
953     * @param string $image_file_name 画像ファイル名
954     * @return boolean
955     */
956    function lfHasSameProductImage($product_id, $arrImageKey, $image_file_name) {
957        if (!SC_Utils_Ex::sfIsInt($product_id)) return false;
958        if (!$arrImageKey) return false;
959        if (!$image_file_name) return false;
960
961        $arrWhere = array();
962        $sqlval = array('0', $product_id);
963        foreach ($arrImageKey as $image_key) {
964            $arrWhere[] = "{$image_key} = ?";
965            $sqlval[] = $image_file_name;
966        }
967        $where = implode(" OR ", $arrWhere);
968        $where = "del_flg = ? AND ((product_id <> ? AND ({$where}))";
969
970        $arrKeyName = $this->objUpFile->keyname;
971        foreach ($arrKeyName as $key => $keyname) {
972            if (in_array($keyname, $arrImageKey)) continue;
973            $where .= " OR {$keyname} = ?";
974            $sqlval[] = $image_file_name;
975        }
976        $where .= ")";
977
978        $objQuery = new SC_Query();
979        $count = $objQuery->count('dtb_products', $where, $sqlval);
980        if (!$count) return false;
981        return true;
982    }
983}
984?>
Note: See TracBrowser for help on using the repository browser.