Changeset 19182


Ignore:
Timestamp:
2010/11/06 23:44:52 (13 years ago)
Author:
konishi
Message:

プレビューページ修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/camp/camp-2_5-C/data/class/pages/admin/products/LC_Page_Admin_Products_Preview.php

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