source: branches/version-2/data/class/pages/campaign/LC_Page_CampaignApplication.php @ 18561

Revision 18561, 9.4 KB checked in by kajiwara, 14 years ago (diff)

Ver2.4.3にアップデート

  • 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_CampaignApplication 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/application.tpl';
47        $this->allowClientCache();
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
55    function process() {
56        global $objCampaignSess;
57
58        $objView = new SC_SiteView(false);
59        $objQuery = new SC_Query();
60        $objCustomer = new SC_Customer();
61        $objCampaignSess = new SC_CampaignSession();
62        // クッキー管理クラス
63        $objCookie = new SC_Cookie(COOKIE_EXPIRE);
64
65        $objLoginFormParam = new SC_FormParam();    // ログインフォーム用
66        $this->lfInitLoginFormParam($objLoginFormParam); // 初期設定
67        $objLoginFormParam->setParam($_POST);       // POST値の取得
68
69        // ディレクトリ名を取得
70        $dir_name = dirname($_SERVER['PHP_SELF']);
71        $arrDir = split('/', $dir_name);
72        $dir_name = $arrDir[count($arrDir) -1];
73
74        /* セッションにキャンペーンデータを書き込む */
75        // キャンペーンからの遷移という情報を保持
76        $objCampaignSess->setIsCampaign();
77        // キャンペーンIDを保持
78        $campaign_id = $objQuery->get("dtb_campaign", "campaign_id", "directory_name = ? AND del_flg = 0", array($dir_name));
79        $objCampaignSess->setCampaignId($campaign_id);
80        // キャンペーンディレクトリ名を保持
81        $objCampaignSess->setCampaignDir($dir_name);
82
83        // キャンペーンが開催中かをチェック
84        if($this->lfCheckActive($dir_name, $objQuery)) {
85            $status = CAMPAIGN_TEMPLATE_ACTIVE;
86            $this->is_active = true;
87        } else {
88            $status = CAMPAIGN_TEMPLATE_END;
89            $this->is_active = false;
90        }
91
92        switch($_POST['mode']) {
93            // ログインチェック
94        case 'login':
95            $objLoginFormParam->toLower('login_email');
96            $this->arrErr = $objLoginFormParam->checkError();
97            $arrForm =  $objLoginFormParam->getHashArray();
98            // クッキー保存判定
99            if($arrForm['login_memory'] == "1" && $arrForm['login_email'] != "") {
100                $objCookie->setCookie('login_email', $_POST['login_email']);
101            } else {
102                $objCookie->setCookie('login_email', '');
103            }
104
105            if(count($this->arrErr) == 0) {
106                // ログイン判定
107                if(!$objCustomer->getCustomerDataFromEmailPass($arrForm['login_pass'], $arrForm['login_email'])) {
108                    // 仮登録の判定
109                    $where = "email = ? AND status = 1 AND del_flg = 0";
110                    $ret = $objQuery->count("dtb_customer", $where, array($arrForm['login_email']));
111
112                    if($ret > 0) {
113                        SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
114                    } else {
115                        SC_Utils_Ex::sfDispSiteError(SITE_LOGIN_ERROR);
116                    }
117                } else {
118                    // 重複申込チェック
119                    $orverlapping_flg = $objQuery->get("dtb_campaign", "orverlapping_flg", "campaign_id = ?", array($objCampaignSess->getCampaignId()));
120
121                    if($orverlapping_flg) {
122                        if($this->lfOverlappingCheck($objCustomer->getValue('customer_id'), $objCampaignSess->getCampaignId(), $objQuery)) {
123                            $this->arrErr['login_email'] = "※ 複数回ご応募することは出来ません。";
124                        }
125                    }
126
127                    if(count($this->arrErr) == 0) {
128                        // 申込情報を登録
129                        $this->lfRegistCampaignOrder($objCustomer->getValue('customer_id'), $objQuery);
130                        // 完了ページへリダイレクト
131                        $this->sendRedirect($this->getLocation(CAMPAIGN_URL . "$dir_name/complete.php"));
132                        exit;
133                    }
134                }
135            }
136            break;
137        default :
138            break;
139        }
140        // 入力情報を渡す
141        $this->arrForm = $_POST;
142        $this->dir_name = $dir_name;
143        $this->tpl_dir_name = CAMPAIGN_TEMPLATE_PATH . $dir_name  . "/" . $status;
144
145        //---- ページ表示
146        $objView->assignobj($this);
147        $objView->display($this->tpl_mainpage);
148    }
149
150    /**
151     * デストラクタ.
152     *
153     * @return void
154     */
155    function destroy() {
156        parent::destroy();
157    }
158
159    /*
160     * 関数名:lfInitLoginFormParam()
161     * 説明  :ログインフォームを初期化
162     * 戻り値:無し
163     */
164    function lfInitLoginFormParam(&$objLoginFormParam) {
165
166        $objLoginFormParam->addParam("記憶する", "login_memory", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
167        $objLoginFormParam->addParam("メールアドレス", "login_email", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
168        $objLoginFormParam->addParam("パスワード", "login_pass", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
169    }
170
171    /*
172     * 関数名:lfCheckActive()
173     * 引数1 :ディレクトリ名
174     * 説明 :キャンペーン中かチェック
175     * 戻り値:キャンペーン中なら true 終了なら false
176     */
177    function lfCheckActive($directory_name, &$objQuery) {
178
179        $is_active = false;
180
181        $col = "limit_count, total_count, start_date, end_date";
182        $arrRet = $objQuery->select($col, "dtb_campaign", "directory_name = ? AND del_flg = 0", array($directory_name));
183
184        // 開始日時・停止日時を成型
185        $start_date = (date("YmdHis", strtotime($arrRet[0]['start_date'])));
186        $end_date = (date("YmdHis", strtotime($arrRet[0]['end_date'])));
187        $now_date = (date("YmdHis"));
188
189        // キャンペーンが開催期間で、かつ申込制限内である
190        if($now_date > $start_date && $now_date < $end_date
191           && ($arrRet[0]['limit_count'] > $arrRet[0]['total_count'] || $arrRet[0]['limit_count'] < 1)) {
192            $is_active = true;
193        }
194
195        return $is_active;
196    }
197
198    /*
199     * 関数名:lfRegistCampaignOrder()
200     * 説明 :キャンペーン受注情報を保存
201     * 引数1 :顧客ID
202     * 戻り値:無し
203     */
204    function lfRegistCampaignOrder($customer_id, &$objQuery) {
205        global $objCampaignSess;
206
207        $campaign_id = $objCampaignSess->getCampaignId();
208
209        // 受注データを取得
210        $cols = "
211            customer_id,
212            name01 as order_name01,
213            name02 as order_name02,
214            kana01 as order_kana01,
215            kana02 as order_kana02,
216            zip01 as order_zip01,
217            zip02 as order_zip02,
218            pref as order_pref,
219            addr01 as order_addr01,
220            addr02 as order_addr02,
221            email as order_email,
222            tel01 as order_tel01,
223            tel02 as order_tel02,
224            tel03 as order_tel03,
225            fax01 as order_fax01,
226            fax02 as order_fax02,
227            fax03 as order_fax03,
228            sex as order_sex,
229            job as order_job,
230            birth as order_birth
231            ";
232
233        $arrCustomer = $objQuery->select($cols, "dtb_customer", "customer_id = ?", array($customer_id));
234
235        $sqlval = $arrCustomer[0];
236        $sqlval['campaign_id'] = $campaign_id;
237        $sqlval['create_date'] = 'now()';
238
239        // INSERTの実行
240        $objQuery->insert("dtb_campaign_order", $sqlval);
241
242        // 申し込み数の更新
243        $total_count = $objQuery->get("dtb_campaign", "total_count", "campaign_id = ?", array($campaign_id));
244        $arrCampaign['total_count'] = $total_count += 1;
245        $objQuery->update("dtb_campaign", $arrCampaign, "campaign_id = ?", array($campaign_id));
246
247    }
248
249    /*
250     * 関数名:lfOverlappingCheck()
251     * 説明 :重複応募チェック
252     * 引数1 :顧客ID
253     * 戻り値:フラグ (重複があったら true 重複がなかったら false)
254     */
255    function lfOverlappingCheck($customer_id, $campaign_id, &$objQuery) {
256        $count = $objQuery->count("dtb_campaign_order", "customer_id = ? AND campaign_id = ?", array($customer_id, $campaign_id));
257        if($count > 0) {
258            return true;
259        }
260
261        return false;
262    }
263}
264?>
Note: See TracBrowser for help on using the repository browser.