source: branches/comu-ver2/data/class/pages/admin/products/LC_Page_Admin_Products_Product.php @ 18275

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