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

Revision 16992, 29.6 KB checked in by satou, 16 years ago (diff)

[オペビルダー連携モジュール]スペルミスで商品IDが引き継げず、初回登録できない不具合を修正。

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