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

Revision 19661, 37.4 KB checked in by nanasess, 13 years ago (diff)

source:branches/camp/camp-2_5-E のマージ

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