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

Revision 18788, 37.1 KB checked in by nanasess, 14 years ago (diff)

シーケンス値の出力に SC_Query::nextVal() を使用するよう修正(#780)

  • インストーラでシーケンスの生成/削除を行うよう修正
  • html/install/sql/insert_data.sql を, シーケンス値を含めたものに修正
  • PostgreSQL の serial 型を int 型に修正
  • MySQL で auto_increment を使用しないように修正
  • シーケンスIDを使用するテーブルへの INSERT を行っている個所で, 事前にシーケンス値を取得するよう修正
  • FIXME data/class/pages/admin/system/LC_Page_Admin_System_Bkup.php を要改修
  • 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 = $objQuery->nextVal("dtb_products_product_id");
477            $sqlval['product_id'] = $product_id;
478
479            // INSERTの実行
480            $sqlval['create_date'] = "Now()";
481            $objQuery->insert("dtb_products", $sqlval);
482
483            $arrList['product_id'] = $product_id;
484
485            // カテゴリを更新
486            $objDb->updateProductCategories($arrList['category_id'], $product_id);
487
488            // 複製商品の場合には規格も複製する
489            if($_POST["copy_product_id"] != "" and SC_Utils_Ex::sfIsInt($_POST["copy_product_id"])){
490
491                if($this->tpl_nonclass)
492                {
493                    //規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う
494                    $this->lfCopyProductClass($arrList, $objQuery);
495                }
496                else
497                {
498                    //規格がある場合の複製は複製元の内容で追加登録を行う
499                    // dtb_products_class のカラムを取得
500                    $dbFactory = SC_DB_DBFactory_Ex::getInstance();
501                    $arrColList = $dbFactory->sfGetColumnList("dtb_products_class", $objQuery);
502                    $arrColList_tmp = array_flip($arrColList);
503
504                    // 複製しない列
505                    unset($arrColList[$arrColList_tmp["product_class_id"]]);     //規格ID
506                    unset($arrColList[$arrColList_tmp["product_id"]]);           //商品ID
507                    unset($arrColList[$arrColList_tmp["create_date"]]);
508
509                    $col = SC_Utils_Ex::sfGetCommaList($arrColList);
510                    $product_class_id = $objQuery->nextVal('dtb_products_class_product_class_id');
511                    $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"]));
512                }
513            }
514        }
515        // 更新
516        else {
517            $product_id = $arrList['product_id'];
518            // 削除要求のあった既存ファイルの削除
519            $arrRet = $this->lfGetProduct($arrList['product_id']);
520            $this->objUpFile->deleteDBFile($arrRet);
521            $this->objDownFile->deleteDBDownFile($arrRet);
522
523            // UPDATEの実行
524            $where = "product_id = ?";
525            $objQuery->update("dtb_products", $sqlval, $where, array($product_id));
526
527            // カテゴリを更新
528            $objDb->updateProductCategories($arrList['category_id'], $product_id);
529        }
530
531        //商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。
532        if( $_POST["copy_product_id"] == "" ){
533            // 規格登録
534            $this->lfInsertDummyProductClass($arrList);
535        }
536
537        // 関連商品登録
538        $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id);
539
540        $objQuery->commit();
541        return $product_id;
542    }
543
544
545    /* 取得文字列の変換 */
546    function lfConvertParam($array) {
547        /*
548         *  文字列の変換
549         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
550         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
551         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
552         *  n :  「全角」数字を「半角(ハンカク)」に変換
553         */
554
555        // スポット商品
556        $arrConvList['name'] = "KVa";
557        $arrConvList['main_list_comment'] = "KVa";
558        $arrConvList['main_comment'] = "KVa";
559        $arrConvList['price01'] = "n";
560        $arrConvList['price02'] = "n";
561        $arrConvList['stock'] = "n";
562        $arrConvList['sale_limit'] = "n";
563        $arrConvList['point_rate'] = "n";
564        $arrConvList['product_code'] = "KVna";
565        $arrConvList['comment1'] = "a";
566        $arrConvList['deliv_fee'] = "n";
567
568        // 詳細-サブ
569        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
570            $arrConvList["sub_title$cnt"] = "KVa";
571        }
572        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
573            $arrConvList["sub_comment$cnt"] = "KVa";
574        }
575
576        // 関連商品
577        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
578            $arrConvList["recommend_comment$cnt"] = "KVa";
579        }
580
581        // 文字変換
582        foreach ($arrConvList as $key => $val) {
583            // POSTされてきた値のみ変換する。
584            if(isset($array[$key])) {
585                $array[$key] = mb_convert_kana($array[$key] ,$val);
586            }
587        }
588
589        if (!isset($array['product_flag'])) $array['product_flag'] = "";
590        $max = max(array_keys($this->arrSTATUS));
591        $array['product_flag'] = SC_Utils_Ex::sfMergeCheckBoxes($array['product_flag'], $max);
592
593        return $array;
594    }
595
596    // 入力エラーチェック
597    function lfErrorCheck($array) {
598
599        $objErr = new SC_CheckError($array);
600        $objErr->doFunc(array("商品名", "name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
601        $objErr->doFunc(array("一覧-メインコメント", "main_list_comment", MTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
602        $objErr->doFunc(array("詳細-メインコメント", "main_comment", LLTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
603        $objErr->doFunc(array("詳細-メインコメント", "main_comment", $this->arrAllowedTag), array("HTML_TAG_CHECK"));
604        $objErr->doFunc(array("ポイント付与率", "point_rate", PERCENTAGE_LEN), array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
605        $objErr->doFunc(array("商品送料", "deliv_fee", PRICE_LEN), array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
606        $objErr->doFunc(array("備考欄(SHOP専用)", "note", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
607        $objErr->doFunc(array("検索ワード", "comment3", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
608        $objErr->doFunc(array("メーカーURL", "comment1", URL_LEN), array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK"));
609        $objErr->doFunc(array("発送日目安", "deliv_date_id", INT_LEN), array("NUM_CHECK"));
610        $objErr->doFunc(array("メーカー", 'maker_id', INT_LEN), array("NUM_CHECK"));
611
612        //ダウンロード商品チェック
613        if($array['down'] == "2") {
614            $objErr->doFunc(array("ダウンロードファイル名", "down_filename", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
615            if($array['down_realfilename'] == "") {
616                $objErr->arrErr['down_realfilename'] = "※ ダウンロード商品の場合はダウンロード商品用ファイルをアップロードしてください。<br />";
617            }
618        }
619        //実商品チェック
620        if($array['down'] == "1") {
621            if($array['down_filename'] != "") {
622                $objErr->arrErr['down_filename'] = "※ 実商品の場合はダウンロードファイル名を設定できません。<br />";
623            }
624            if($array['down_realfilename'] != "") {
625                $objErr->arrErr['down_realfilename'] = "※ 実商品の場合はダウンロード商品用ファイルをアップロードできません。<br />ファイルを取り消してください。<br />";
626            }
627        }
628
629        if($this->tpl_nonclass) {
630            $objErr->doFunc(array("商品コード", "product_code", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK"));
631            $objErr->doFunc(array(NORMAL_PRICE_TITLE, "price01", PRICE_LEN), array("NUM_CHECK", "MAX_LENGTH_CHECK"));
632            $objErr->doFunc(array(SALE_PRICE_TITLE, "price02", PRICE_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
633
634            if(!isset($array['stock_unlimited']) && $array['stock_unlimited'] != "1") {
635                $objErr->doFunc(array("在庫数", "stock", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
636            }
637        }
638
639        $objErr->doFunc(array("購入制限", "sale_limit", AMOUNT_LEN), array("SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
640
641        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
642            $objErr->doFunc(array("詳細-サブタイトル$cnt", "sub_title$cnt", STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
643            $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
644            $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", $this->arrAllowedTag),  array("HTML_TAG_CHECK"));
645        }
646
647        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
648
649            if (!isset($_POST["recommend_delete$cnt"]))  $_POST["recommend_delete$cnt"] = "";
650
651            if(isset($_POST["recommend_id$cnt"])
652            && $_POST["recommend_id$cnt"] != ""
653            && $_POST["recommend_delete$cnt"] != 1) {
654                $objErr->doFunc(array("関連商品コメント$cnt", "recommend_comment$cnt", LTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
655            }
656        }
657
658        // カテゴリID のチェック
659        if (empty($array['category_id'])) {
660            $objErr->arrErr['category_id'] = "※ 商品カテゴリが選択されていません。<br />";
661        } else {
662            $arrCategory_id = array();
663            for ($i = 0; $i < count($array['category_id']); $i++) {
664                $arrCategory_id['category_id' . $i] = $array['category_id'][$i];
665            }
666            $objCheckCategory = new SC_CheckError($arrCategory_id);
667            for ($i = 0; $i < count($array['category_id']); $i++) {
668                $objCheckCategory->doFunc(array("商品カテゴリ", "category_id" . $i, STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
669            }
670            if (!empty($objCheckCategory->arrErr)) {
671                $objErr->arrErr = array_merge($objErr->arrErr,
672                $objCheckCategory->arrErr);
673            }
674        }
675        return $objErr->arrErr;
676    }
677
678    /* 確認ページ表示用 */
679    function lfProductConfirmPage() {
680        $this->tpl_mainpage = 'products/confirm.tpl';
681        $this->arrForm['mode'] = 'complete';
682
683        $objDb = new SC_Helper_DB_Ex();
684
685        // カテゴリ表示
686        $this->arrCategory_id = $this->arrForm['category_id'];
687        $this->arrCatList = array();
688        list($arrCatVal, $arrCatOut) = $objDb->sfGetLevelCatList(false);
689        for ($i = 0; $i < count($arrCatVal); $i++) {
690            $this->arrCatList[$arrCatVal[$i]] = $arrCatOut[$i];
691        }
692
693        // hidden に渡す値は serialize する
694        $this->arrForm['category_id'] = serialize($this->arrForm['category_id']);
695
696        // Form用配列を渡す。
697        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
698        $this->arrForm['down_realfilename'] = $this->objDownFile->getFormDownFile();
699    }
700
701    // 縮小した画像をセットする
702    function lfSetScaleImage(){
703
704        $subno = str_replace("sub_large_image", "", $_POST['image_key']);
705        switch ($_POST['image_key']){
706            case "main_large_image":
707                // 詳細メイン画像
708                $this->lfMakeScaleImage($_POST['image_key'], "main_image");
709            case "main_image":
710                // 一覧メイン画像
711                $this->lfMakeScaleImage($_POST['image_key'], "main_list_image");
712                break;
713            case "sub_large_image" . $subno:
714                // サブメイン画像
715                $this->lfMakeScaleImage($_POST['image_key'], "sub_image" . $subno);
716                break;
717            default:
718                break;
719        }
720    }
721
722    // 縮小画像生成
723    function lfMakeScaleImage($from_key, $to_key, $forced = false){
724        $arrImageKey = array_flip($this->objUpFile->keyname);
725
726        if($this->objUpFile->temp_file[$arrImageKey[$from_key]]){
727            $from_path = $this->objUpFile->temp_dir . $this->objUpFile->temp_file[$arrImageKey[$from_key]];
728        }elseif($this->objUpFile->save_file[$arrImageKey[$from_key]]){
729            $from_path = $this->objUpFile->save_dir . $this->objUpFile->save_file[$arrImageKey[$from_key]];
730        }else{
731            return "";
732        }
733
734        if(file_exists($from_path)){
735            // 生成先の画像サイズを取得
736            $to_w = $this->objUpFile->width[$arrImageKey[$to_key]];
737            $to_h = $this->objUpFile->height[$arrImageKey[$to_key]];
738
739            if($forced) $this->objUpFile->save_file[$arrImageKey[$to_key]] = "";
740
741            if(empty($this->objUpFile->temp_file[$arrImageKey[$to_key]]) &&
742            empty($this->objUpFile->save_file[$arrImageKey[$to_key]])) {
743
744                // リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
745                $dst_file = $this->objUpFile->lfGetTmpImageName(IMAGE_RENAME, "", $this->objUpFile->temp_file[$arrImageKey[$from_key]]) . $this->lfGetAddSuffix($to_key);
746                $path = $this->objUpFile->makeThumb($from_path, $to_w, $to_h, $dst_file);
747                $this->objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path);
748            }
749        }else{
750            return "";
751        }
752    }
753
754    /**
755     * リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
756     */
757    function lfGetAddSuffix($to_key){
758        if( IMAGE_RENAME === true ){ return ; }
759
760        // 自動生成される画像名
761        $dist_name = "";
762        switch($to_key){
763            case "main_list_image":
764                $dist_name = '_s';
765                break;
766            case "main_image":
767                $dist_name = '_m';
768                break;
769            default:
770                $arrRet = explode('sub_image', $to_key);
771                $dist_name = '_sub' .$arrRet[1];
772                break;
773        }
774        return $dist_name;
775    }
776
777    /**
778     * dtb_products_classの複製
779     * 複製後、価格や商品コードを更新する
780     *
781     * @param array $arrList
782     * @param array $objQuery
783     * @return bool
784     */
785    function lfCopyProductClass($arrList,$objQuery)
786    {
787        // 複製元のdtb_products_classを取得(規格なしのため、1件のみの取得)
788        $col = "*";
789        $table = "dtb_products_class";
790        $where = "product_id = ?";
791        $arrProductClass = $objQuery->select($col, $table, $where, array($arrList["copy_product_id"]));
792
793        //トランザクション開始
794        $objQuery->begin();
795        $err_flag = false;
796        //非編集項目は複製、編集項目は上書きして登録
797        foreach($arrProductClass as $records)
798        {
799            foreach($records as $key => $value)
800            {
801                if(isset($arrList[$key]))
802                {
803                    $records[$key] = $arrList[$key];
804                }
805            }
806
807            $records["product_class_id"] = $objQuery->nextVal('dtb_products_class_product_class_id');
808            unset($records["update_date"]);
809
810            $records["create_date"] = "Now()";
811            $objQuery->insert($table, $records);
812            //エラー発生時は中断
813            if($objQuery->isError())
814            {
815                $err_flag = true;
816                continue;
817            }
818        }
819        //トランザクション終了
820        if($err_flag)
821        {
822            $objQuery->rollback();
823        }
824        else
825        {
826            $objQuery->commit();
827        }
828        return !$err_flag;
829    }
830
831    /**
832     * 規格を設定していない商品を商品規格テーブルに登録
833     *
834     * @param array $arrList
835     * @return void
836     */
837    function lfInsertDummyProductClass($arrList) {
838        $objQuery  = new SC_Query();
839        $objDb = new SC_Helper_DB_Ex();
840
841        $product_id = $arrList['product_id'];
842        // 規格登録してある商品の場合、処理しない
843        if ($objDb->sfHasProductClass($product_id)) return;
844
845        // 既存規格の削除
846        $where = 'product_id = ?';
847        $objQuery->delete('dtb_products_class', $where, array($product_id));
848
849        // 配列の添字を定義
850        $checkArray = array('product_class_id', 'product_id', 'product_code', 'stock', 'stock_unlimited', 'price01', 'price02');
851        $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $checkArray);
852        $sqlval = SC_Utils_Ex::arrayDefineIndexes($sqlval, $checkArray);
853
854        if (strlen($sqlval['product_class_id']) == 0) {
855            $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id');
856        }
857        $sqlval['classcategory_id1'] = '0';
858        $sqlval['classcategory_id2'] = '0';
859        $sqlval['stock_unlimited'] = $sqlval['stock_unlimited'] ? '1' : '0';
860        $sqlval['creator_id'] = strlen($_SESSION['member_id']) >= 1 ? $_SESSION['member_id'] : '0';
861        $sqlval['create_date'] = 'now()';
862
863        // INSERTの実行
864        $objQuery->insert('dtb_products_class', $sqlval);
865    }
866    /* ダウンロードファイル情報の初期化 */
867    function lfInitDownFile() {
868        $this->objDownFile->addFile("ダウンロード販売用ファイル", 'down_file', explode(",", DOWNLOAD_EXTENSION),DOWN_SIZE, true, 0, 0);
869    }
870}
871?>
Note: See TracBrowser for help on using the repository browser.