source: trunk/data/class/pages/admin/products/LC_Page_Admin_Products_Product.php @ 18758

Revision 18758, 33.0 KB checked in by kajiwara, 14 years ago (diff)

EC-CUBE Ver2.4.4 分コミット。詳細はこちら( http://www.ec-cube.net/release/detail.php?release_id=223

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