| 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 |
|---|
| 25 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * キャンペーン のページクラス. |
|---|
| 29 | * |
|---|
| 30 | * @package Page |
|---|
| 31 | * @author LOCKON CO.,LTD. |
|---|
| 32 | * @version $Id$ |
|---|
| 33 | */ |
|---|
| 34 | class LC_Page_Campaign extends LC_Page { |
|---|
| 35 | |
|---|
| 36 | // }}} |
|---|
| 37 | // {{{ functions |
|---|
| 38 | |
|---|
| 39 | /** |
|---|
| 40 | * Page を初期化する. |
|---|
| 41 | * |
|---|
| 42 | * @return void |
|---|
| 43 | */ |
|---|
| 44 | function init() { |
|---|
| 45 | parent::init(); |
|---|
| 46 | $this->tpl_mainpage = TEMPLATE_DIR . '/campaign/index.tpl'; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | /** |
|---|
| 50 | * Page のプロセス. |
|---|
| 51 | * |
|---|
| 52 | * @return void |
|---|
| 53 | */ |
|---|
| 54 | function process() { |
|---|
| 55 | global $objCampaignSess; |
|---|
| 56 | |
|---|
| 57 | $objView = new SC_SiteView(false); |
|---|
| 58 | $objQuery = new SC_Query(); |
|---|
| 59 | $objCampaignSess = new SC_CampaignSession(); |
|---|
| 60 | |
|---|
| 61 | // ディレクトリ名を取得 |
|---|
| 62 | $dir_name = dirname($_SERVER['PHP_SELF']); |
|---|
| 63 | $arrDir = split('/', $dir_name); |
|---|
| 64 | $dir_name = $arrDir[count($arrDir) -1]; |
|---|
| 65 | |
|---|
| 66 | /* セッションにキャンペーンデータを書き込む */ |
|---|
| 67 | // キャンペーンからの遷移という情報を保持 |
|---|
| 68 | $objCampaignSess->setIsCampaign(); |
|---|
| 69 | // キャンペーンIDを保持 |
|---|
| 70 | $campaign_id = $objQuery->get("dtb_campaign", "campaign_id", "directory_name = ? AND del_flg = 0", array($dir_name)); |
|---|
| 71 | $objCampaignSess->setCampaignId($campaign_id); |
|---|
| 72 | // キャンペーンディレクトリ名を保持 |
|---|
| 73 | $objCampaignSess->setCampaignDir($dir_name); |
|---|
| 74 | |
|---|
| 75 | // カートに入れないページの場合のページ(申込のみページ)へリダイレクト |
|---|
| 76 | $cart_flg = $objQuery->get("dtb_campaign", "cart_flg", "campaign_id = ?", array($campaign_id)); |
|---|
| 77 | if(!$cart_flg) { |
|---|
| 78 | $this->sendRedirect($this->getLocation(CAMPAIGN_URL . "$dir_name/application.php")); |
|---|
| 79 | exit; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | // キャンペーンが開催中かをチェック |
|---|
| 83 | if($this->lfCheckActive($dir_name, $objQuery)) { |
|---|
| 84 | $status = CAMPAIGN_TEMPLATE_ACTIVE; |
|---|
| 85 | } else { |
|---|
| 86 | $status = CAMPAIGN_TEMPLATE_END; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | if($_GET['init'] != "") { |
|---|
| 90 | $this->tpl_init = 'false'; |
|---|
| 91 | $this->lfDispProductsList($_GET['ids'], $objQuery); |
|---|
| 92 | } else { |
|---|
| 93 | $this->tpl_init = 'true'; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | switch($_POST['mode']) { |
|---|
| 97 | |
|---|
| 98 | case 'cart': |
|---|
| 99 | $this->arrErr = $this->lfCheckError($_POST['product_id']); |
|---|
| 100 | if(count($this->arrErr) == 0) { |
|---|
| 101 | $objCartSess = new SC_CartSession(); |
|---|
| 102 | $classcategory_id = "classcategory_id". $_POST['product_id']; |
|---|
| 103 | $classcategory_id1 = $_POST[$classcategory_id. '_1']; |
|---|
| 104 | $classcategory_id2 = $_POST[$classcategory_id. '_2']; |
|---|
| 105 | $quantity = "quantity". $_POST['product_id']; |
|---|
| 106 | // 規格1が設定されていない場合 |
|---|
| 107 | if(!$this->tpl_classcat_find1[$_POST['product_id']]) { |
|---|
| 108 | $classcategory_id1 = '0'; |
|---|
| 109 | } |
|---|
| 110 | // 規格2が設定されていない場合 |
|---|
| 111 | if(!$this->tpl_classcat_find2[$_POST['product_id']]) { |
|---|
| 112 | $classcategory_id2 = '0'; |
|---|
| 113 | } |
|---|
| 114 | $objCartSess->setPrevURL($_SERVER['REQUEST_URI']); |
|---|
| 115 | $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $_POST[$quantity], $campaign_id); |
|---|
| 116 | $this->sendRedirect($this->getLocation(URL_CART_TOP)); |
|---|
| 117 | exit; |
|---|
| 118 | } |
|---|
| 119 | break; |
|---|
| 120 | default : |
|---|
| 121 | break; |
|---|
| 122 | } |
|---|
| 123 | // 入力情報を渡す |
|---|
| 124 | $this->arrForm = $_POST; |
|---|
| 125 | $this->tpl_dir_name = CAMPAIGN_TEMPLATE_PATH . $dir_name . "/" . $status; |
|---|
| 126 | |
|---|
| 127 | //---- ページ表示 |
|---|
| 128 | $objView->assignobj($this); |
|---|
| 129 | $objView->display($this->tpl_mainpage); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | /** |
|---|
| 133 | * デストラクタ. |
|---|
| 134 | * |
|---|
| 135 | * @return void |
|---|
| 136 | */ |
|---|
| 137 | function destroy() { |
|---|
| 138 | parent::destroy(); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | /* |
|---|
| 142 | * 関数名:lfCheckActive() |
|---|
| 143 | * 引数1 :ディレクトリ名 |
|---|
| 144 | * 説明 :キャンペーン中かチェック |
|---|
| 145 | * 戻り値:キャンペーン中なら true 終了なら false |
|---|
| 146 | */ |
|---|
| 147 | function lfCheckActive($directory_name, &$objQuery) { |
|---|
| 148 | |
|---|
| 149 | $is_active = false; |
|---|
| 150 | |
|---|
| 151 | $col = "limit_count, total_count, start_date, end_date"; |
|---|
| 152 | $arrRet = $objQuery->select($col, "dtb_campaign", "directory_name = ? AND del_flg = 0", array($directory_name)); |
|---|
| 153 | |
|---|
| 154 | // 開始日時・停止日時を成型 |
|---|
| 155 | $start_date = (date("YmdHis", strtotime($arrRet[0]['start_date']))); |
|---|
| 156 | $end_date = (date("YmdHis", strtotime($arrRet[0]['end_date']))); |
|---|
| 157 | $now_date = (date("YmdHis")); |
|---|
| 158 | |
|---|
| 159 | // キャンペーンが開催期間で、かつ申込制限内である |
|---|
| 160 | if($now_date > $start_date && $now_date < $end_date |
|---|
| 161 | && ($arrRet[0]['limit_count'] > $arrRet[0]['total_count'] || $arrRet[0]['limit_count'] < 1)) { |
|---|
| 162 | $is_active = true; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | return $is_active; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | /* 商品一覧の表示 */ |
|---|
| 169 | function lfDispProductsList($ids, &$objQuery) { |
|---|
| 170 | $objDb = new SC_Helper_DB_Ex(); |
|---|
| 171 | // 規格名一覧 |
|---|
| 172 | $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name"); |
|---|
| 173 | // 規格分類名一覧 |
|---|
| 174 | $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); |
|---|
| 175 | |
|---|
| 176 | $arrProductIds = split('-', $ids); |
|---|
| 177 | if(!is_array($arrProductIds)) { |
|---|
| 178 | $arrProductIds[0] = $ids; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | // where句生成 |
|---|
| 182 | $count = 0; |
|---|
| 183 | $where = "product_id IN ("; |
|---|
| 184 | foreach($arrProductIds as $key =>$val) { |
|---|
| 185 | if($count > 0) $where .= ","; |
|---|
| 186 | $where .= "?"; |
|---|
| 187 | $arrval[] = $val; |
|---|
| 188 | $count++; |
|---|
| 189 | } |
|---|
| 190 | $where .= ")"; |
|---|
| 191 | |
|---|
| 192 | // 商品一覧 |
|---|
| 193 | $arrProducts = $objQuery->select("*", "vw_products_allclass AS allcls", $where, $arrval); |
|---|
| 194 | |
|---|
| 195 | for($i = 0; $i < count($arrProducts); $i++) { |
|---|
| 196 | $this->lfMakeSelect($arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName); |
|---|
| 197 | // 購入制限数を取得 |
|---|
| 198 | $this->lfGetSaleLimit($arrProducts); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | foreach($arrProducts as $key =>$val) { |
|---|
| 202 | $arrCamp[$val['product_id']] = $val; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | $this->arrProducts = $arrCamp; |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | /* 規格セレクトボックスの作成 */ |
|---|
| 209 | function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) { |
|---|
| 210 | |
|---|
| 211 | $classcat_find1 = false; |
|---|
| 212 | $classcat_find2 = false; |
|---|
| 213 | // 在庫ありの商品の有無 |
|---|
| 214 | $stock_find = false; |
|---|
| 215 | |
|---|
| 216 | // 商品規格情報の取得 |
|---|
| 217 | $arrProductsClass = $this->lfGetProductsClass($product_id); |
|---|
| 218 | |
|---|
| 219 | // 規格1クラス名の取得 |
|---|
| 220 | $this->tpl_class_name1[$product_id] = $arrClassName[$arrProductsClass[0]['class_id1']]; |
|---|
| 221 | // 規格2クラス名の取得 |
|---|
| 222 | $this->tpl_class_name2[$product_id] = $arrClassName[$arrProductsClass[0]['class_id2']]; |
|---|
| 223 | |
|---|
| 224 | // すべての組み合わせ数 |
|---|
| 225 | $count = count($arrProductsClass); |
|---|
| 226 | |
|---|
| 227 | $classcat_id1 = ""; |
|---|
| 228 | |
|---|
| 229 | $arrSele = array(); |
|---|
| 230 | $arrList = array(); |
|---|
| 231 | |
|---|
| 232 | $list_id = 0; |
|---|
| 233 | $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'"; |
|---|
| 234 | $arrVal[0] = "\tval". $product_id. "_0 = new Array(''"; |
|---|
| 235 | |
|---|
| 236 | for ($i = 0; $i < $count; $i++) { |
|---|
| 237 | // 在庫のチェック |
|---|
| 238 | if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') { |
|---|
| 239 | continue; |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | $stock_find = true; |
|---|
| 243 | |
|---|
| 244 | // 規格1のセレクトボックス用 |
|---|
| 245 | if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){ |
|---|
| 246 | $arrList[$list_id].=");\n"; |
|---|
| 247 | $arrVal[$list_id].=");\n"; |
|---|
| 248 | $classcat_id1 = $arrProductsClass[$i]['classcategory_id1']; |
|---|
| 249 | $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1]; |
|---|
| 250 | $list_id++; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | // 規格2のセレクトボックス用 |
|---|
| 254 | $classcat_id2 = $arrProductsClass[$i]['classcategory_id2']; |
|---|
| 255 | |
|---|
| 256 | // セレクトボックス表示値 |
|---|
| 257 | if($arrList[$list_id] == "") { |
|---|
| 258 | $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'"; |
|---|
| 259 | } else { |
|---|
| 260 | $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'"; |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | // セレクトボックスPOST値 |
|---|
| 264 | if($arrVal[$list_id] == "") { |
|---|
| 265 | $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'"; |
|---|
| 266 | } else { |
|---|
| 267 | $arrVal[$list_id].= ", '".$classcat_id2."'"; |
|---|
| 268 | } |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | $arrList[$list_id].=");\n"; |
|---|
| 272 | $arrVal[$list_id].=");\n"; |
|---|
| 273 | |
|---|
| 274 | // 規格1 |
|---|
| 275 | $this->arrClassCat1[$product_id] = $arrSele; |
|---|
| 276 | |
|---|
| 277 | $lists = "\tlists".$product_id. " = new Array("; |
|---|
| 278 | $no = 0; |
|---|
| 279 | foreach($arrList as $val) { |
|---|
| 280 | $this->tpl_javascript.= $val; |
|---|
| 281 | if ($no != 0) { |
|---|
| 282 | $lists.= ",list". $product_id. "_". $no; |
|---|
| 283 | } else { |
|---|
| 284 | $lists.= "list". $product_id. "_". $no; |
|---|
| 285 | } |
|---|
| 286 | $no++; |
|---|
| 287 | } |
|---|
| 288 | $this->tpl_javascript.= $lists.");\n"; |
|---|
| 289 | |
|---|
| 290 | $vals = "\tvals".$product_id. " = new Array("; |
|---|
| 291 | $no = 0; |
|---|
| 292 | foreach($arrVal as $val) { |
|---|
| 293 | $this->tpl_javascript.= $val; |
|---|
| 294 | if ($no != 0) { |
|---|
| 295 | $vals.= ",val". $product_id. "_". $no; |
|---|
| 296 | } else { |
|---|
| 297 | $vals.= "val". $product_id. "_". $no; |
|---|
| 298 | } |
|---|
| 299 | $no++; |
|---|
| 300 | } |
|---|
| 301 | $this->tpl_javascript.= $vals.");\n"; |
|---|
| 302 | |
|---|
| 303 | // 選択されている規格2ID |
|---|
| 304 | $classcategory_id = "classcategory_id". $product_id; |
|---|
| 305 | $this->tpl_onload .= "lnSetSelect('".$classcategory_id."_1','".$classcategory_id."_2','".$product_id."','".$_POST[$classcategory_id."_2"]."'); "; |
|---|
| 306 | |
|---|
| 307 | // 規格1が設定されている |
|---|
| 308 | if($arrProductsClass[0]['classcategory_id1'] != '0') { |
|---|
| 309 | $classcat_find1 = true; |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | // 規格2が設定されている |
|---|
| 313 | if($arrProductsClass[0]['classcategory_id2'] != '0') { |
|---|
| 314 | $classcat_find2 = true; |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | $this->tpl_classcat_find1[$product_id] = $classcat_find1; |
|---|
| 318 | $this->tpl_classcat_find2[$product_id] = $classcat_find2; |
|---|
| 319 | $this->tpl_stock_find[$product_id] = $stock_find; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | /* 商品規格情報の取得 */ |
|---|
| 323 | function lfGetProductsClass($product_id) { |
|---|
| 324 | $arrRet = array(); |
|---|
| 325 | if(SC_Utils_Ex::sfIsInt($product_id)) { |
|---|
| 326 | // 商品規格取得 |
|---|
| 327 | $objQuery = new SC_Query(); |
|---|
| 328 | $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited"; |
|---|
| 329 | $table = "vw_product_class AS prdcls"; |
|---|
| 330 | $where = "product_id = ?"; |
|---|
| 331 | $objQuery->setOrder("rank1 DESC, rank2 DESC"); |
|---|
| 332 | $arrRet = $objQuery->select($col, $table, $where, array($product_id)); |
|---|
| 333 | } |
|---|
| 334 | return $arrRet; |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | /* 入力内容のチェック */ |
|---|
| 338 | function lfCheckError($id) { |
|---|
| 339 | |
|---|
| 340 | // 入力データを渡す。 |
|---|
| 341 | $objErr = new SC_CheckError(); |
|---|
| 342 | |
|---|
| 343 | $classcategory_id1 = "classcategory_id". $id. "_1"; |
|---|
| 344 | $classcategory_id2 = "classcategory_id". $id. "_2"; |
|---|
| 345 | $quantity = "quantity". $id; |
|---|
| 346 | // 複数項目チェック |
|---|
| 347 | if ($this->tpl_classcat_find1[$id]) { |
|---|
| 348 | $objErr->doFunc(array("規格1", $classcategory_id1, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
|---|
| 349 | } |
|---|
| 350 | if ($this->tpl_classcat_find2[$id]) { |
|---|
| 351 | $objErr->doFunc(array("規格2", $classcategory_id2, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
|---|
| 352 | } |
|---|
| 353 | $objErr->doFunc(array("個数", $quantity, INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
|---|
| 354 | |
|---|
| 355 | return $objErr->arrErr; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | // 購入制限数の設定 |
|---|
| 359 | function lfGetSaleLimit($product) { |
|---|
| 360 | //在庫が無限または購入制限値が設定値より大きい場合 |
|---|
| 361 | if($product['sale_unlimited'] == 1 || $product['sale_limit'] > SALE_LIMIT_MAX) { |
|---|
| 362 | $this->tpl_sale_limit[$product['product_id']] = SALE_LIMIT_MAX; |
|---|
| 363 | } else { |
|---|
| 364 | $this->tpl_sale_limit[$product['product_id']] = $product['sale_limit']; |
|---|
| 365 | } |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | //支払方法の取得 |
|---|
| 369 | //payment_id 1:代金引換 2:銀行振り込み 3:現金書留 |
|---|
| 370 | function lfGetPayment() { |
|---|
| 371 | $objQuery = new SC_Query; |
|---|
| 372 | $col = "payment_id, rule, payment_method"; |
|---|
| 373 | $from = "dtb_payment"; |
|---|
| 374 | $where = "del_flg = 0"; |
|---|
| 375 | $order = "payment_id"; |
|---|
| 376 | $objQuery->setOrder($order); |
|---|
| 377 | $arrRet = $objQuery->select($col, $from, $where); |
|---|
| 378 | return $arrRet; |
|---|
| 379 | } |
|---|
| 380 | } |
|---|
| 381 | ?> |
|---|