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

Revision 18777, 37.2 KB checked in by eccuore, 14 years ago (diff)

#792(ダウンロード販売機能) 機能追加

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