source: tmp/version-2_5-test/data/class/pages/campaign/LC_Page_CampaignApplication.php @ 18609

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