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

Revision 18819, 37.4 KB checked in by eccuore, 14 years ago (diff)

#792(ダウンロード販売機能) 入金日追加、規格対応(規格構成変更と並行で作業中なので、作業途中の部分有)

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