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

Revision 20674, 10.1 KB checked in by tao, 13 years ago (diff)

#refs 寄付ポイント数上限設定機能、現在の寄付状況表示ブロック、csvファイルのファイルロックを追加。

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