source: branches/eccube-donation/html/mobile/frontparts/bloc/send_point.php @ 20700

Revision 20700, 9.9 KB checked in by tao, 13 years ago (diff)

#refs モバイルも修正

  • Property svn:executable set to *
Line 
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 * 2011-03-12 Tao Sasaki (tao@xross-cube.com)
24 *
25 */
26
27// {{{ requires
28if( !defined("CLASS_PATH") ){
29    require_once("../../require.php");
30}
31require_once(CLASS_PATH . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php");
32
33// }}}
34// {{{ generate page
35class LC_Page_FrontParts_Bloc_SendPoint extends LC_Page_FrontParts_Bloc {
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init() {
46        parent::init();
47        $this->tpl_login = false;
48        $this->tpl_disable_logout = false;
49        $this->tpl_error = "";
50        $this->complete = false;
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        if(!file_exists(DATA_PATH.'downloads/donation.csv')){
60            $objQuery = new SC_Query;
61            $ret = $objQuery->getOne("SELECT php_path FROM dtb_bloc WHERE php_path = 'frontparts/bloc/send_point.php'");
62            if(!$ret){
63                $objQuery->query("INSERT INTO dtb_bloc (bloc_name,tpl_path,filename,create_date,update_date,php_path,del_flg)
64                 VALUES('東北地方太平洋沖地震ポイント寄付','','send_point',NOW(),NOW(),'frontparts/bloc/send_point.php',0)");
65                 if(!file_exists(DATA_PATH.'downloads/donation_summary.csv') AND $fp = fopen(DATA_PATH.'downloads/donation_summary.csv','a+')){
66                    fwrite($fp,'0,0,0');
67                    fclose($fp);
68                 }
69            }
70        }
71       
72       
73
74        $objCustomer = new SC_Customer();
75        $objCustomer->updateSession();
76        // クッキー管理クラス
77        $objCookie = new SC_Cookie(COOKIE_EXPIRE);
78       
79        $limit = 0;
80        if($fp2 = fopen(DATA_PATH.'downloads/donation_summary.csv','a+')){
81            flock($fp2,LOCK_EX);
82            $summary = file_get_contents(DATA_PATH.'downloads/donation_summary.csv');
83            $summary = explode(",",$summary);
84            $total = intval($summary[1]);
85            $limit = intval($summary[2]);
86            if($limit != 0 and $total == $limit){
87                $this->complete = true;
88            }
89        }
90       
91        // ログイン判定
92        if($objCustomer->isLoginSuccess() and $this->complete == false ) {
93            $this->tpl_user_point = $objCustomer->getValue('point');
94            if (strlen($this->tpl_user_point) == 0) $this->tpl_user_point = 0;
95            if(isset($_POST["sendpoint"]) and $this->isValidToken()){
96                //ポイント寄付処理
97                $point = intval(mb_convert_kana($_POST["sendpoint"],"n"));
98                if(!$point or $this->tpl_user_point < $point){
99                    $this->tpl_error = "1以上のポイントを保有ポイント内で半角数字で入力してください。";
100                }else{
101                    if(isset($summary) and $this->complete == false){
102                        if(($limit - $total) < $point){
103                            $point = $limit - $total;
104                            $this->complete = true;
105                        }
106                    }
107                    if($fp = fopen(DATA_PATH.'downloads/donation.csv','a+') and $point > 0){
108                        $objQuery = new SC_Query;
109                        $sqlval = array('point' => ($this->tpl_user_point - $point));
110                        $where = 'customer_id = ? AND del_flg = 0 AND status = 2';
111                        $rs = $objQuery->update('dtb_customer', $sqlval, $where, array($objCustomer->getValue('customer_id')));
112                        if($rs){
113                            flock($fp,LOCK_EX);
114                            fwrite($fp,date("Y-m-d G:i:s").",".$objCustomer->getValue('customer_id').",".$point."\n");
115                            $objCustomer->setValue("point", ($this->tpl_user_point - $point));
116                            $this->tpl_error = "ご協力ありがとうございます。".$point."ptを承りました。<br />寄付頂いたポイント分を、東北地方太平洋沖地震の復旧活動へ寄付いたします。";
117                            //サマリー更新
118                            if(isset($summary)){
119                                $num = intval($summary[0]) + 1;
120                                $total = $total+$point;
121                                ftruncate($fp2,0);
122                                fseek($fp2,0);
123                                fwrite($fp2,$num.','.$total.','.$limit);
124                            }else{
125                                $this->tpl_error = "正常に寄付ポイントを集計出来ませんでした。サイト管理者へご連絡願います。";
126                            }
127                        }else{
128                            $this->tpl_error = "正常に寄付ポイントを記録出来ませんでした。もう一度お願いします。";
129                        }
130                        fclose($fp);
131                    } else {
132                        $this->tpl_error = "システムエラー"; 
133                    }
134                }
135            }
136            $this->tpl_login = true;
137            $objCustomer->updateSession();
138            $this->tpl_user_point = $objCustomer->getValue('point');
139            if (strlen($this->tpl_user_point) == 0) $this->tpl_user_point = 0;
140            $this->tpl_name1 = $objCustomer->getValue('name01');
141            $this->tpl_name2 = $objCustomer->getValue('name02');
142        }
143       
144        if($fp2){
145            fclose($fp2);
146        }
147       
148        $this->transactionid = $this->getToken();
149    }
150
151    /**
152     * デストラクタ.
153     *
154     * @return void
155     */
156    function destroy() {
157        parent::destroy();
158    }
159}
160
161$objPage = new LC_Page_FrontParts_Bloc_SendPoint();
162register_shutdown_function(array($objPage, "destroy"));
163$objPage->init();
164$objPage->process();
165
166?>
167<a name="sendPoint"></a>
168<div id="sendPoint" style="border: none;background: #FFF6CF;text-align: center;overflow: auto;">
169<div id="innner" style="border: 3px solid red;margin:8px;">
170<?php if($objPage->complete === true){ ?>
171<h2><font color="red" size="3">ご協力ありがとうございました</font></h2>
172<p><font size="-2" color="#333">ポイントの東北地方太平洋沖地震の復旧活動への寄付ですが、皆様のご協力により目標ポイント数を達成する事が出来ました。</font></p>
173<p><font size="-2" color="#333">寄付して頂いたポイント分の金額を、当店がお客様に代わり東北地方太平洋沖地震の復旧活動へ寄付させて頂きます。<br />多大なご協力ありがとうございました。<br /></font></p>
174<p><font size="-2" color="#333">現金で赤十字に募金される場合は<a href="http://www.jrc.or.jp/contribution/l3/Vcms3_00002069.html" target="_blank" title="赤十字募金ページへ">コチラ</a>をご参照ください。</font></p>
175<?php }else{ ?>
176<h2><font color="red" size="3">東北地方太平洋沖地震へのポイント寄付のお願い</font></h2>
177    <?php if($objPage->tpl_login){?>
178<p><font size="-2" color="#333">現在お客様が保有している当店のポイントを東北地方太平洋沖地震の復旧活動へ寄付出来ます。</font></p>
179<p><font size="-2" color="#333">下記フォームに寄付するポイント数を入力の上、「寄付」ボタンをクリックしてください。</font></p>
180<p><font size="-2" color="#333">運営担当者が寄付されたポイントを集計し、東北地方太平洋沖地震の復旧活動に寄付させて頂きます。</font></p>
181<div id="sendForm">
182<p><font color="#FF0000"><?php echo $objPage->tpl_error; ?></font></p>
183    <form method="post" action="#sendPoint" name="sendPoint">
184        <input type="hidden" name="transactionid" value="<?php echo $objPage->transactionid ?>" />
185        <p><font size="-2" color="#333">現在お客様が保有しているポイント:<?php echo $objPage->tpl_user_point ?>pt</font></p>
186        <p>
187            <font size="-2" color="#333"><input type="text" maxlength="10" name="sendpoint" id="sendpointValue" value="" size="5" />ptを寄付<br /></font>
188            <input type="submit" value="寄付" />
189        </p>
190    </form>
191</div>
192<p><font size="-2" color="#333">直接現金で赤十字に募金される場合は<a href="http://www.jrc.or.jp/contribution/l3/Vcms3_00002069.html" target="_blank" title="赤十字募金ページへ">コチラ</a>をご参照ください。</font></p>
193    <?php }else{ ?>
194<p><font size="-2" color="#333">会員のお客様は、現在お客様が保有している当店のポイントを東北地方太平洋沖地震の復旧活動へ寄付できます。ログインしてご協力をお願いします。</font></p>
195<p><font size="3">- <a href="<?php echo URL_MYPAGE_TOP ?>">ログイン</a> -</font></p>
196<p><font size="-2" color="#333">運営担当者が寄付されたポイントを集計し、東北地方太平洋沖地震の復旧活動へ寄付させて頂きます。</font></p>
197<p><font size="-2" color="#333">直接現金で赤十字に募金される場合は<a href="http://www.jrc.or.jp/contribution/l3/Vcms3_00002069.html" target="_blank" title="赤十字募金ページへ">コチラ</a>をご参照ください。</font></p>
198    <?php } ?>
199<?php } ?>
200</div>
201</div>
Note: See TracBrowser for help on using the repository browser.