source: branches/feature-module-update/data/class/pages/campaign/LC_Page_Campaign.php @ 16582

Revision 16582, 13.4 KB checked in by nanasess, 16 years ago (diff)

ライセンス表記変更

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