[15342] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
| 4 | * |
---|
| 5 | * http://www.lockon.co.jp/ |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | // {{{ requires |
---|
| 9 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
| 10 | |
---|
| 11 | /** |
---|
| 12 | * 商品登録 のページクラス. |
---|
| 13 | * |
---|
| 14 | * @package Page |
---|
| 15 | * @author LOCKON CO.,LTD. |
---|
| 16 | * @version $Id$ |
---|
| 17 | */ |
---|
| 18 | class LC_Page_Admin_Products_Product extends LC_Page { |
---|
| 19 | |
---|
| 20 | // {{{ properties |
---|
| 21 | |
---|
| 22 | /** ファイル管理クラスのインスタンス */ |
---|
| 23 | var $objUpFile; |
---|
| 24 | |
---|
| 25 | /** hidden 項目の配列 */ |
---|
| 26 | var $arrHidden; |
---|
| 27 | |
---|
| 28 | /** エラー情報 */ |
---|
| 29 | var $arrErr; |
---|
| 30 | |
---|
| 31 | // }}} |
---|
| 32 | // {{{ functions |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * Page を初期化する. |
---|
| 36 | * |
---|
| 37 | * @return void |
---|
| 38 | */ |
---|
| 39 | function init() { |
---|
| 40 | parent::init(); |
---|
| 41 | $this->tpl_mainpage = 'products/product.tpl'; |
---|
| 42 | $this->tpl_subnavi = 'products/subnavi.tpl'; |
---|
| 43 | $this->tpl_mainno = 'products'; |
---|
| 44 | $this->tpl_subno = 'product'; |
---|
| 45 | $this->tpl_subtitle = '商品登録'; |
---|
| 46 | $this->arrErr = array(); |
---|
| 47 | |
---|
| 48 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 49 | $this->arrSRANK = $masterData->getMasterData("mtb_srank"); |
---|
| 50 | $this->arrDISP = $masterData->getMasterData("mtb_disp"); |
---|
| 51 | $this->arrCLASS = $masterData->getMasterData("mtb_class"); |
---|
| 52 | $this->arrSTATUS = $masterData->getMasterData("mtb_status"); |
---|
| 53 | $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image"); |
---|
| 54 | $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date"); |
---|
| 55 | $this->arrAllowedTag = $masterData->getMasterData("mtb_allowed_tag"); |
---|
| 56 | $this->tpl_nonclass = true; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * Page のプロセス. |
---|
| 61 | * |
---|
| 62 | * @return void |
---|
| 63 | */ |
---|
| 64 | function process() { |
---|
| 65 | $objView = new SC_AdminView(); |
---|
| 66 | $objSiteInfo = new SC_SiteInfo(); |
---|
| 67 | $objQuery = new SC_Query(); |
---|
| 68 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 69 | |
---|
| 70 | // 認証可否の判定 |
---|
| 71 | $objSess = new SC_Session(); |
---|
| 72 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
| 73 | |
---|
| 74 | // ファイル管理クラス |
---|
| 75 | $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR); |
---|
| 76 | |
---|
| 77 | // ファイル情報の初期化 |
---|
| 78 | $this->lfInitFile(); |
---|
| 79 | // Hiddenからのデータを引き継ぐ |
---|
| 80 | $this->objUpFile->setHiddenFileList($_POST); |
---|
| 81 | |
---|
| 82 | // 検索パラメータの引き継ぎ |
---|
| 83 | foreach ($_POST as $key => $val) { |
---|
| 84 | if (ereg("^search_", $key)) { |
---|
| 85 | $this->arrSearchHidden[$key] = $val; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | // FORMデータの引き継ぎ |
---|
| 90 | $this->arrForm = $_POST; |
---|
| 91 | |
---|
| 92 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
| 93 | |
---|
| 94 | switch($_POST['mode']) { |
---|
| 95 | // 検索画面からの編集 |
---|
| 96 | case 'pre_edit': |
---|
| 97 | case 'copy' : |
---|
| 98 | // 編集時 |
---|
| 99 | if(SC_Utils_Ex::sfIsInt($_POST['product_id'])){ |
---|
| 100 | // DBから商品情報の読込 |
---|
| 101 | $arrForm = $this->lfGetProduct($_POST['product_id']); |
---|
| 102 | // DBデータから画像ファイル名の読込 |
---|
| 103 | $this->objUpFile->setDBFileList($arrForm); |
---|
| 104 | |
---|
| 105 | if($_POST['mode'] == "copy"){ |
---|
| 106 | $arrForm["copy_product_id"] = $arrForm["product_id"]; |
---|
| 107 | $arrForm["product_id"] = ""; |
---|
| 108 | // 画像ファイルのコピー |
---|
| 109 | $arrKey = $this->objUpFile->keyname; |
---|
| 110 | $arrSaveFile = $this->objUpFile->save_file; |
---|
| 111 | |
---|
| 112 | foreach($arrSaveFile as $key => $val){ |
---|
| 113 | $this->lfMakeScaleImage($arrKey[$key], $arrKey[$key], true); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | $this->arrForm = $arrForm; |
---|
| 117 | |
---|
| 118 | // 商品ステータスの変換 |
---|
| 119 | $arrRet = SC_Utils_Ex::sfSplitCBValue($this->arrForm['product_flag'], "product_flag"); |
---|
| 120 | $this->arrForm = array_merge($this->arrForm, $arrRet); |
---|
| 121 | // DBからおすすめ商品の読み込み |
---|
| 122 | $this->arrRecommend = $this->lfPreGetRecommendProducts($_POST['product_id']); |
---|
| 123 | |
---|
| 124 | // 規格登録ありなし判定 |
---|
| 125 | $this->tpl_nonclass = $this->lfCheckNonClass($_POST['product_id']); |
---|
| 126 | $this->lfProductPage(); // 商品登録ページ |
---|
| 127 | } |
---|
| 128 | break; |
---|
| 129 | // 商品登録・編集 |
---|
| 130 | case 'edit': |
---|
| 131 | // 規格登録ありなし判定 |
---|
| 132 | $tpl_nonclass = $this->lfCheckNonClass($_POST['product_id']); |
---|
| 133 | |
---|
| 134 | if($_POST['product_id'] == "" and SC_Utils_Ex::sfIsInt($_POST['copy_product_id'])){ |
---|
| 135 | $tpl_nonclass = $this->lfCheckNonClass($_POST['copy_product_id']); |
---|
| 136 | } |
---|
| 137 | $this->tpl_nonclass = $tpl_nonclass; |
---|
| 138 | |
---|
| 139 | // 入力値の変換 |
---|
| 140 | $this->arrForm = $this->lfConvertParam($this->arrForm); |
---|
| 141 | // エラーチェック |
---|
| 142 | $this->arrErr = $this->lfErrorCheck($this->arrForm); |
---|
| 143 | // ファイル存在チェック |
---|
| 144 | $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS()); |
---|
| 145 | // エラーなしの場合 |
---|
| 146 | if(count($this->arrErr) == 0) { |
---|
| 147 | $this->lfProductConfirmPage(); // 確認ページ |
---|
| 148 | } else { |
---|
| 149 | $this->lfProductPage(); // 商品登録ページ |
---|
| 150 | } |
---|
| 151 | break; |
---|
| 152 | // 確認ページから完了ページへ |
---|
| 153 | case 'complete': |
---|
| 154 | $this->tpl_mainpage = 'products/complete.tpl'; |
---|
| 155 | |
---|
| 156 | $this->tpl_product_id = $this->lfRegistProduct($_POST); // データ登録 |
---|
| 157 | |
---|
| 158 | // 件数カウントバッチ実行 |
---|
| 159 | $objDb->sfCategory_Count($objQuery); |
---|
| 160 | // 一時ファイルを本番ディレクトリに移動する |
---|
| 161 | $this->objUpFile->moveTempFile(); |
---|
| 162 | |
---|
| 163 | break; |
---|
| 164 | // 画像のアップロード |
---|
| 165 | case 'upload_image': |
---|
| 166 | // ファイル存在チェック |
---|
| 167 | $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS($_POST['image_key'])); |
---|
| 168 | // 画像保存処理 |
---|
| 169 | $this->arrErr[$_POST['image_key']] = $this->objUpFile->makeTempFile($_POST['image_key']); |
---|
| 170 | |
---|
| 171 | // 中、小画像生成 |
---|
| 172 | $this->lfSetScaleImage(); |
---|
| 173 | |
---|
| 174 | $this->lfProductPage(); // 商品登録ページ |
---|
| 175 | break; |
---|
| 176 | // 画像の削除 |
---|
| 177 | case 'delete_image': |
---|
| 178 | $this->objUpFile->deleteFile($_POST['image_key']); |
---|
| 179 | $this->lfProductPage(); // 商品登録ページ |
---|
| 180 | break; |
---|
| 181 | // 確認ページからの戻り |
---|
| 182 | case 'confirm_return': |
---|
| 183 | // 規格登録ありなし判定 |
---|
| 184 | $this->tpl_nonclass = lfCheckNonClass($_POST['product_id']); |
---|
| 185 | $this->lfProductPage(); // 商品登録ページ |
---|
| 186 | break; |
---|
| 187 | // おすすめ商品選択 |
---|
| 188 | case 'recommend_select' : |
---|
| 189 | $this->lfProductPage(); // 商品登録ページ |
---|
| 190 | break; |
---|
| 191 | default: |
---|
| 192 | // 公開・非公開のデフォルト値 |
---|
| 193 | $this->arrForm['status'] = DEFAULT_PRODUCT_DISP; |
---|
| 194 | $this->lfProductPage(); // 商品登録ページ |
---|
| 195 | break; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | if($_POST['mode'] != 'pre_edit') { |
---|
| 199 | // おすすめ商品の読み込み |
---|
| 200 | $this->arrRecommend = $this->lfGetRecommendProducts(); |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | // 基本情報を渡す |
---|
| 204 | $this->arrInfo = $objSiteInfo->data; |
---|
| 205 | |
---|
| 206 | // サブ情報の入力があるかどうかチェックする |
---|
| 207 | $sub_find = false; |
---|
| 208 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
| 209 | if( (isset($this->arrForm['sub_title'.$cnt]) |
---|
| 210 | && !empty($this->arrForm['sub_title'.$cnt])) || |
---|
| 211 | (isset($this->arrForm['sub_comment'.$cnt]) |
---|
| 212 | && !empty($this->arrForm['sub_comment'.$cnt])) || |
---|
| 213 | (isset($this->arrForm['sub_image'.$cnt]) |
---|
| 214 | && !empty($this->arrForm['sub_image'.$cnt])) || |
---|
| 215 | (isset($this->arrForm['sub_large_image'.$cnt]) |
---|
| 216 | && !empty($this->arrForm['sub_large_image'.$cnt])) || |
---|
| 217 | (isset($this->arrForm['sub_image'.$cnt]) |
---|
| 218 | && is_array($this->arrFile['sub_image'.$cnt])) || |
---|
| 219 | (isset($this->arrForm['sub_large_image'.$cnt]) |
---|
| 220 | && is_array($this->arrFile['sub_large_image'.$cnt]))) { |
---|
| 221 | $sub_find = true; |
---|
| 222 | break; |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | // サブ情報表示・非表示のチェックに使用する。 |
---|
| 226 | $this->sub_find = $sub_find; |
---|
| 227 | |
---|
| 228 | $objView->assignobj($this); |
---|
| 229 | $objView->display(MAIN_FRAME); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | /** |
---|
| 233 | * デストラクタ. |
---|
| 234 | * |
---|
| 235 | * @return void |
---|
| 236 | */ |
---|
| 237 | function destroy() { |
---|
| 238 | parent::destroy(); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | /* おすすめ商品の読み込み */ |
---|
| 242 | function lfGetRecommendProducts() { |
---|
| 243 | $objQuery = new SC_Query(); |
---|
| 244 | $arrRecommend = array(); |
---|
| 245 | for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { |
---|
| 246 | $keyname = "recommend_id" . $i; |
---|
| 247 | $delkey = "recommend_delete" . $i; |
---|
| 248 | $commentkey = "recommend_comment" . $i; |
---|
| 249 | |
---|
| 250 | if((isset($_POST[$keyname]) && !empty($_POST[$keyname])) && $_POST[$delkey] != 1) { |
---|
| 251 | $arrRet = $objQuery->select("main_list_image, product_code_min, name", "vw_products_allclass AS allcls", "product_id = ?", array($_POST[$keyname])); |
---|
| 252 | $arrRecommend[$i] = $arrRet[0]; |
---|
| 253 | $arrRecommend[$i]['product_id'] = $_POST[$keyname]; |
---|
| 254 | $arrRecommend[$i]['comment'] = $this->arrForm[$commentkey]; |
---|
| 255 | } |
---|
| 256 | } |
---|
| 257 | return $arrRecommend; |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | /* おすすめ商品の登録 */ |
---|
| 261 | function lfInsertRecommendProducts($objQuery, $arrList, $product_id) { |
---|
| 262 | // 一旦オススメ商品をすべて削除する |
---|
| 263 | $objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id)); |
---|
| 264 | $sqlval['product_id'] = $product_id; |
---|
| 265 | $rank = RECOMMEND_PRODUCT_MAX; |
---|
| 266 | for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { |
---|
| 267 | $keyname = "recommend_id" . $i; |
---|
| 268 | $commentkey = "recommend_comment" . $i; |
---|
| 269 | $deletekey = "recommend_delete" . $i; |
---|
| 270 | if($arrList[$keyname] != "" && $arrList[$deletekey] != '1') { |
---|
| 271 | $sqlval['recommend_product_id'] = $arrList[$keyname]; |
---|
| 272 | $sqlval['comment'] = $arrList[$commentkey]; |
---|
| 273 | $sqlval['rank'] = $rank; |
---|
| 274 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
| 275 | $sqlval['create_date'] = "now()"; |
---|
| 276 | $sqlval['update_date'] = "now()"; |
---|
| 277 | $objQuery->insert("dtb_recommend_products", $sqlval); |
---|
| 278 | $rank--; |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | /* 登録済みおすすめ商品の読み込み */ |
---|
| 284 | function lfPreGetRecommendProducts($product_id) { |
---|
[15446] | 285 | $arrRecommend = array(); |
---|
[15342] | 286 | $objQuery = new SC_Query(); |
---|
| 287 | $objQuery->setorder("rank DESC"); |
---|
| 288 | $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id)); |
---|
| 289 | $max = count($arrRet); |
---|
| 290 | $no = 1; |
---|
| 291 | |
---|
| 292 | for($i = 0; $i < $max; $i++) { |
---|
| 293 | $arrProductInfo = $objQuery->select("main_list_image, product_code_min, name", "vw_products_allclass AS allcls", "product_id = ?", array($arrRet[$i]['recommend_product_id'])); |
---|
| 294 | $arrRecommend[$no] = $arrProductInfo[0]; |
---|
| 295 | $arrRecommend[$no]['product_id'] = $arrRet[$i]['recommend_product_id']; |
---|
| 296 | $arrRecommend[$no]['comment'] = $arrRet[$i]['comment']; |
---|
| 297 | $no++; |
---|
| 298 | } |
---|
| 299 | return $arrRecommend; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | /* 商品情報の読み込み */ |
---|
| 303 | function lfGetProduct($product_id) { |
---|
| 304 | $objQuery = new SC_Query(); |
---|
| 305 | $col = "*"; |
---|
| 306 | $table = "vw_products_nonclass AS noncls "; |
---|
| 307 | $where = "product_id = ?"; |
---|
| 308 | |
---|
| 309 | // viewも絞込み(mysql対応) TODO |
---|
| 310 | //sfViewWhere("&&noncls_where&&", $where, array($product_id)); |
---|
| 311 | |
---|
| 312 | $arrRet = $objQuery->select($col, $table, $where, array($product_id)); |
---|
| 313 | |
---|
| 314 | return $arrRet[0]; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | /* 商品登録ページ表示用 */ |
---|
| 318 | function lfProductPage() { |
---|
| 319 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 320 | |
---|
| 321 | // カテゴリの読込 |
---|
| 322 | list($this->arrCatVal, $this->arrCatOut) = $objDb->sfGetLevelCatList(false); |
---|
| 323 | |
---|
| 324 | if($this->arrForm['status'] == "") { |
---|
| 325 | $this->arrForm['status'] = 1; |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | if(isset($this->arrForm['product_flag']) && !is_array($this->arrForm['product_flag'])) { |
---|
| 329 | // 商品ステータスの分割読込 |
---|
| 330 | $this->arrForm['product_flag'] = SC_Utils_Ex::sfSplitCheckBoxes($this->arrForm['product_flag']); |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | // HIDDEN用に配列を渡す。 |
---|
| 334 | $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objUpFile->getHiddenFileList()); |
---|
| 335 | // Form用配列を渡す。 |
---|
| 336 | $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL); |
---|
| 337 | |
---|
| 338 | |
---|
| 339 | // アンカーを設定 |
---|
| 340 | if (isset($_POST['image_key']) && !empty($_POST['image_key'])) { |
---|
| 341 | $anchor_hash = "location.hash='#" . $_POST['image_key'] . "'"; |
---|
| 342 | } elseif (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) { |
---|
| 343 | $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'"; |
---|
| 344 | } else { |
---|
| 345 | $anchor_hash = ""; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | $this->tpl_onload = "fnCheckSaleLimit('" . DISABLED_RGB . "'); fnCheckStockLimit('" . DISABLED_RGB . "'); " . $anchor_hash; |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | /* ファイル情報の初期化 */ |
---|
| 352 | function lfInitFile() { |
---|
| 353 | $this->objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg', 'gif', 'png'),IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); |
---|
| 354 | $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, true, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT); |
---|
| 355 | $this->objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT); |
---|
| 356 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
| 357 | $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_WIDTH, NORMAL_SUBIMAGE_HEIGHT); |
---|
| 358 | $this->objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_SUBIMAGE_WIDTH, LARGE_SUBIMAGE_HEIGHT); |
---|
| 359 | } |
---|
| 360 | $this->objUpFile->addFile("商品比較画像", 'file1', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, OTHER_IMAGE1_WIDTH, OTHER_IMAGE1_HEIGHT); |
---|
| 361 | $this->objUpFile->addFile("商品詳細ファイル", 'file2', array('pdf'), PDF_SIZE, false, 0, 0, false); |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | /* 商品の登録 */ |
---|
| 365 | function lfRegistProduct($arrList) { |
---|
| 366 | $objQuery = new SC_Query(); |
---|
| 367 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 368 | $objQuery->begin(); |
---|
| 369 | |
---|
| 370 | // 配列の添字を定義 |
---|
| 371 | $checkArray = array("name", "category_id", "status", "product_flag", |
---|
| 372 | "main_list_comment", "main_comment", "point_rate", |
---|
| 373 | "deliv_fee", "comment1", "comment2", "comment3", |
---|
| 374 | "comment4", "comment5", "comment6", "main_list_comment", |
---|
| 375 | "sale_limit", "sale_unlimited", "deliv_date_id"); |
---|
| 376 | $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray); |
---|
| 377 | |
---|
| 378 | // INSERTする値を作成する。 |
---|
| 379 | $sqlval['name'] = $arrList['name']; |
---|
| 380 | $sqlval['category_id'] = $arrList['category_id']; |
---|
| 381 | $sqlval['status'] = $arrList['status']; |
---|
| 382 | $sqlval['product_flag'] = $arrList['product_flag']; |
---|
| 383 | $sqlval['main_list_comment'] = $arrList['main_list_comment']; |
---|
| 384 | $sqlval['main_comment'] = $arrList['main_comment']; |
---|
| 385 | $sqlval['point_rate'] = $arrList['point_rate']; |
---|
| 386 | $sqlval['deliv_fee'] = $arrList['deliv_fee']; |
---|
| 387 | $sqlval['comment1'] = $arrList['comment1']; |
---|
| 388 | $sqlval['comment2'] = $arrList['comment2']; |
---|
| 389 | $sqlval['comment3'] = $arrList['comment3']; |
---|
| 390 | $sqlval['comment4'] = $arrList['comment4']; |
---|
| 391 | $sqlval['comment5'] = $arrList['comment5']; |
---|
| 392 | $sqlval['comment6'] = $arrList['comment6']; |
---|
| 393 | $sqlval['main_list_comment'] = $arrList['main_list_comment']; |
---|
| 394 | $sqlval['sale_limit'] = $arrList['sale_limit']; |
---|
| 395 | $sqlval['sale_unlimited'] = $arrList['sale_unlimited']; |
---|
| 396 | $sqlval['deliv_date_id'] = $arrList['deliv_date_id']; |
---|
| 397 | $sqlval['update_date'] = "Now()"; |
---|
| 398 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
| 399 | $arrRet = $this->objUpFile->getDBFileList(); |
---|
| 400 | $sqlval = array_merge($sqlval, $arrRet); |
---|
| 401 | |
---|
| 402 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
| 403 | $sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt]; |
---|
| 404 | $sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt]; |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | if($arrList['product_id'] == "") { |
---|
| 408 | if (DB_TYPE == "pgsql") { |
---|
| 409 | $product_id = $objQuery->nextval("dtb_products", "product_id"); |
---|
| 410 | $sqlval['product_id'] = $product_id; |
---|
| 411 | } |
---|
| 412 | // カテゴリ内で最大のランクを割り当てる |
---|
| 413 | $sqlval['rank'] = $objQuery->max("dtb_products", "rank", "category_id = ?", array($arrList['category_id'])) + 1; |
---|
| 414 | // INSERTの実行 |
---|
| 415 | $sqlval['create_date'] = "Now()"; |
---|
| 416 | $objQuery->insert("dtb_products", $sqlval); |
---|
| 417 | |
---|
| 418 | if (DB_TYPE == "mysql") { |
---|
| 419 | $product_id = $objQuery->nextval("dtb_products", "product_id"); |
---|
| 420 | $sqlval['product_id'] = $product_id; |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | // コピー商品の場合には規格もコピーする |
---|
| 424 | if($_POST["copy_product_id"] != "" and sfIsInt($_POST["copy_product_id"])){ |
---|
| 425 | // dtb_products_class のカラムを取得 |
---|
| 426 | $dbFactory = SC_DB_DBFactory::getInstance(); |
---|
| 427 | $arrColList = $dbFactory->sfGetColumnList("dtb_products_class", $objQuery); |
---|
| 428 | $arrColList_tmp = array_flip($arrColList); |
---|
| 429 | |
---|
| 430 | // コピーしない列 |
---|
| 431 | unset($arrColList[$arrColList_tmp["product_class_id"]]); //規格ID |
---|
| 432 | unset($arrColList[$arrColList_tmp["product_id"]]); //商品ID |
---|
| 433 | |
---|
| 434 | $col = SC_Utils_Ex::sfGetCommaList($arrColList); |
---|
| 435 | |
---|
| 436 | $objQuery->query("INSERT INTO dtb_products_class (product_id, ". $col .") SELECT ?, " . $col. " FROM dtb_products_class WHERE product_id = ? ORDER BY product_class_id", array($product_id, $_POST["copy_product_id"])); |
---|
| 437 | |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | } else { |
---|
| 441 | $product_id = $arrList['product_id']; |
---|
| 442 | // 削除要求のあった既存ファイルの削除 |
---|
[15479] | 443 | $arrRet = $this->lfGetProduct($arrList['product_id']); |
---|
[15342] | 444 | $this->objUpFile->deleteDBFile($arrRet); |
---|
| 445 | |
---|
| 446 | // カテゴリ内ランクの調整処理 |
---|
| 447 | $old_catid = $objQuery->get("dtb_products", "category_id", "product_id = ?", array($arrList['product_id'])); |
---|
[15479] | 448 | SC_Utils_Ex::sfMoveCatRank($objQuery, "dtb_products", "product_id", "category_id", $old_catid, $arrList['category_id'], $arrList['product_id']); |
---|
[15342] | 449 | |
---|
| 450 | // UPDATEの実行 |
---|
| 451 | $where = "product_id = ?"; |
---|
| 452 | $objQuery->update("dtb_products", $sqlval, $where, array($arrList['product_id'])); |
---|
| 453 | } |
---|
| 454 | |
---|
| 455 | // 規格登録 |
---|
| 456 | SC_Utils_Ex::sfInsertProductClass($objQuery, $arrList, $product_id); |
---|
| 457 | |
---|
| 458 | // おすすめ商品登録 |
---|
| 459 | $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id); |
---|
| 460 | |
---|
| 461 | $objQuery->commit(); |
---|
| 462 | return $product_id; |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | |
---|
| 466 | /* 取得文字列の変換 */ |
---|
| 467 | function lfConvertParam($array) { |
---|
| 468 | /* |
---|
| 469 | * 文字列の変換 |
---|
| 470 | * K : 「半角(ハンカク)片仮名」を「全角片仮名」に変換 |
---|
| 471 | * C : 「全角ひら仮名」を「全角かた仮名」に変換 |
---|
| 472 | * V : 濁点付きの文字を一文字に変換。"K","H"と共に使用します |
---|
| 473 | * n : 「全角」数字を「半角(ハンカク)」に変換 |
---|
| 474 | */ |
---|
| 475 | // 人物基本情報 |
---|
| 476 | |
---|
| 477 | // スポット商品 |
---|
| 478 | $arrConvList['name'] = "KVa"; |
---|
| 479 | $arrConvList['main_list_comment'] = "KVa"; |
---|
| 480 | $arrConvList['main_comment'] = "KVa"; |
---|
| 481 | $arrConvList['price01'] = "n"; |
---|
| 482 | $arrConvList['price02'] = "n"; |
---|
| 483 | $arrConvList['stock'] = "n"; |
---|
| 484 | $arrConvList['sale_limit'] = "n"; |
---|
| 485 | $arrConvList['point_rate'] = "n"; |
---|
| 486 | $arrConvList['product_code'] = "KVna"; |
---|
| 487 | $arrConvList['comment1'] = "a"; |
---|
| 488 | //ホネケーキ:送料の指定なし |
---|
| 489 | $arrConvList['deliv_fee'] = "n"; |
---|
| 490 | |
---|
| 491 | // 詳細-サブ |
---|
| 492 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
| 493 | $arrConvList["sub_title$cnt"] = "KVa"; |
---|
| 494 | } |
---|
| 495 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
| 496 | $arrConvList["sub_comment$cnt"] = "KVa"; |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | // おすすめ商品 |
---|
| 500 | for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) { |
---|
| 501 | $arrConvList["recommend_comment$cnt"] = "KVa"; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | // 文字変換 |
---|
| 505 | foreach ($arrConvList as $key => $val) { |
---|
| 506 | // POSTされてきた値のみ変換する。 |
---|
| 507 | if(isset($array[$key])) { |
---|
| 508 | $array[$key] = mb_convert_kana($array[$key] ,$val); |
---|
| 509 | } |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | if (!isset($array['product_flag'])) $array['product_flag'] = ""; |
---|
| 513 | $array['product_flag'] = SC_Utils_Ex::sfMergeCheckBoxes($array['product_flag'], count($this->arrSTATUS)); |
---|
| 514 | |
---|
| 515 | return $array; |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | // 入力エラーチェック |
---|
| 519 | function lfErrorCheck($array) { |
---|
| 520 | |
---|
| 521 | $objErr = new SC_CheckError($array); |
---|
| 522 | $objErr->doFunc(array("商品名", "name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 523 | $objErr->doFunc(array("商品カテゴリ", "category_id", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 524 | $objErr->doFunc(array("一覧-メインコメント", "main_list_comment", MTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 525 | $objErr->doFunc(array("詳細-メインコメント", "main_comment", LLTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 526 | $objErr->doFunc(array("詳細-メインコメント", "main_comment", $this->arrAllowedTag), array("HTML_TAG_CHECK")); |
---|
| 527 | $objErr->doFunc(array("ポイント付与率", "point_rate", PERCENTAGE_LEN), array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 528 | $objErr->doFunc(array("商品送料", "deliv_fee", PRICE_LEN), array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 529 | $objErr->doFunc(array("検索ワード", "comment3", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 530 | $objErr->doFunc(array("メーカーURL", "comment1", URL_LEN), array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 531 | $objErr->doFunc(array("発送日目安", "deliv_date_id", INT_LEN), array("NUM_CHECK")); |
---|
| 532 | |
---|
| 533 | if($this->tpl_nonclass) { |
---|
| 534 | $objErr->doFunc(array("商品コード", "product_code", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK","MAX_LENGTH_CHECK")); |
---|
| 535 | $objErr->doFunc(array("通常価格", "price01", PRICE_LEN), array("ZERO_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 536 | $objErr->doFunc(array("商品価格", "price02", PRICE_LEN), array("EXIST_CHECK", "NUM_CHECK", "ZERO_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 537 | |
---|
| 538 | if(isset($array['stock_unlinited']) && $array['stock_unlimited'] != "1") { |
---|
| 539 | $objErr->doFunc(array("在庫数", "stock", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 540 | } |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | if(isset($array['sale_unlimited']) && $array['sale_unlimited'] != "1") { |
---|
| 544 | $objErr->doFunc(array("購入制限", "sale_limit", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 545 | } |
---|
| 546 | |
---|
| 547 | if(isset($objErr->arrErr['category_id'])) { |
---|
| 548 | // 自動選択を防ぐためにダミー文字を入れておく |
---|
| 549 | $this->arrForm['category_id'] = "#"; |
---|
| 550 | } |
---|
| 551 | |
---|
| 552 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
| 553 | $objErr->doFunc(array("詳細-サブタイトル$cnt", "sub_title$cnt", STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 554 | $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 555 | $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", $this->arrAllowedTag), array("HTML_TAG_CHECK")); |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) { |
---|
| 559 | if($_POST["recommend_id$cnt"] != "" && $_POST["recommend_delete$cnt"] != 1) { |
---|
| 560 | $objErr->doFunc(array("おすすめ商品コメント$cnt", "recommend_comment$cnt", LTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 561 | } |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | return $objErr->arrErr; |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | /* 確認ページ表示用 */ |
---|
| 568 | function lfProductConfirmPage() { |
---|
| 569 | $this->tpl_mainpage = 'products/confirm.tpl'; |
---|
| 570 | $this->arrForm['mode'] = 'complete'; |
---|
| 571 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 572 | // カテゴリの読込 |
---|
| 573 | $this->arrCatList = $objDb->sfGetCategoryList(); |
---|
| 574 | // Form用配列を渡す。 |
---|
| 575 | $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL); |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | /* 規格あり判定用(規格が登録されていない場合:TRUE) */ |
---|
| 579 | function lfCheckNonClass($product_id) { |
---|
| 580 | if(SC_Utils_Ex::sfIsInt($product_id)) { |
---|
| 581 | $objQuery = new SC_Query(); |
---|
| 582 | $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0"; |
---|
| 583 | $count = $objQuery->count("dtb_products_class", $where, array($product_id)); |
---|
| 584 | if($count > 0) { |
---|
| 585 | return false; |
---|
| 586 | } |
---|
| 587 | } |
---|
| 588 | return true; |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | // 縮小した画像をセットする |
---|
| 592 | function lfSetScaleImage(){ |
---|
| 593 | |
---|
| 594 | $subno = str_replace("sub_large_image", "", $_POST['image_key']); |
---|
| 595 | switch ($_POST['image_key']){ |
---|
| 596 | case "main_large_image": |
---|
| 597 | // 詳細メイン画像 |
---|
| 598 | $this->lfMakeScaleImage($_POST['image_key'], "main_image"); |
---|
| 599 | case "main_image": |
---|
| 600 | // 一覧メイン画像 |
---|
| 601 | $this->lfMakeScaleImage($_POST['image_key'], "main_list_image"); |
---|
| 602 | break; |
---|
| 603 | case "sub_large_image" . $subno: |
---|
| 604 | // サブメイン画像 |
---|
| 605 | $this->lfMakeScaleImage($_POST['image_key'], "sub_image" . $subno); |
---|
| 606 | break; |
---|
| 607 | default: |
---|
| 608 | break; |
---|
| 609 | } |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | // 縮小画像生成 |
---|
| 613 | function lfMakeScaleImage($from_key, $to_key, $forced = false){ |
---|
| 614 | $arrImageKey = array_flip($this->objUpFile->keyname); |
---|
| 615 | |
---|
| 616 | if($this->objUpFile->temp_file[$arrImageKey[$from_key]]){ |
---|
| 617 | $from_path = $this->objUpFile->temp_dir . $this->objUpFile->temp_file[$arrImageKey[$from_key]]; |
---|
| 618 | }elseif($this->objUpFile->save_file[$arrImageKey[$from_key]]){ |
---|
| 619 | $from_path = $this->objUpFile->save_dir . $this->objUpFile->save_file[$arrImageKey[$from_key]]; |
---|
| 620 | }else{ |
---|
| 621 | return ""; |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | if(file_exists($from_path)){ |
---|
| 625 | // 元画像サイズを取得 |
---|
| 626 | list($from_w, $from_h) = getimagesize($from_path); |
---|
| 627 | |
---|
| 628 | // 生成先の画像サイズを取得 |
---|
| 629 | $to_w = $this->objUpFile->width[$arrImageKey[$to_key]]; |
---|
| 630 | $to_h = $this->objUpFile->height[$arrImageKey[$to_key]]; |
---|
| 631 | |
---|
| 632 | |
---|
| 633 | if($forced) $this->objUpFile->save_file[$arrImageKey[$to_key]] = ""; |
---|
| 634 | |
---|
| 635 | if((isset($this->objUpFile->temp_file[$arrImageKey[$to_key]]) |
---|
| 636 | && $this->objUpFile->temp_file[$arrImageKey[$to_key]] == "" |
---|
| 637 | and isset($this->objUpFile->save_file[$arrImageKey[$to_key]]) |
---|
| 638 | && $this->objUpFile->save_file[$arrImageKey[$to_key]] == "")) { |
---|
| 639 | |
---|
| 640 | $path = $this->objUpFile->makeThumb($from_path, $to_w, $to_h); |
---|
| 641 | $this->objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path); |
---|
| 642 | } |
---|
| 643 | }else{ |
---|
| 644 | return ""; |
---|
| 645 | } |
---|
| 646 | } |
---|
| 647 | } |
---|
| 648 | ?> |
---|