Changeset 20674


Ignore:
Timestamp:
2011/03/17 10:38:39 (13 years ago)
Author:
tao
Message:

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

Location:
branches/eccube-donation/html/frontparts/bloc
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eccube-donation/html/frontparts/bloc/index.php

    r20639 r20674  
    3636define('DONATION_VERSION', '0.0.1'); 
    3737 
     38 
     39 
    3840$objQuery = new SC_Query(); 
    3941// 全顧客取得 
     
    6365    $correct_point += $arrDn[2]; 
    6466} 
     67$limit = 0; 
     68if($fp = fopen(DATA_PATH.'downloads/donation_summary.csv','a+')){ 
     69    flock($fp2,LOCK_EX); 
     70    $summary = file_get_contents(DATA_PATH.'downloads/donation_summary.csv'); 
     71    $summary = explode(",",$summary); 
     72    $num   = intval($summary[0]); 
     73    $total = intval($summary[1]); 
     74    $limit = intval($summary[2]); 
     75     
     76    if(isset($_POST["limit"]) and isValidToken()){ 
     77        $limit = mb_convert_kana(trim($_POST["limit"]),"n"); 
     78        $limit = intval($limit); 
     79        ftruncate($fp,0); 
     80        fwrite($fp,$num.','.$total.','.$limit); 
     81    } 
     82    fclose($fp); 
     83} 
     84$token = getToken(); 
     85 
     86function getToken() { 
     87    if (empty($_SESSION[TRANSACTION_ID_NAME])) { 
     88        $_SESSION[TRANSACTION_ID_NAME] = sha1(uniqid(rand(), true)); 
     89    } 
     90    return $_SESSION[TRANSACTION_ID_NAME]; 
     91} 
     92 
     93 
     94function isValidToken() { 
     95 
     96    $checkToken = ""; 
     97 
     98    // $_POST の値を優先する 
     99    if (isset($_POST[TRANSACTION_ID_NAME])) { 
     100 
     101        $checkToken = $_POST[TRANSACTION_ID_NAME]; 
     102    } elseif (isset($_GET[TRANSACTION_ID_NAME])) { 
     103 
     104        $checkToken = $_GET[TRANSACTION_ID_NAME]; 
     105    } 
     106 
     107    $ret = false; 
     108    // token の妥当性チェック 
     109    if ($checkToken === $_SESSION[TRANSACTION_ID_NAME]) { 
     110 
     111        $ret = true; 
     112    } 
     113 
     114    unset($_SESSION[TRANSACTION_ID_NAME]); 
     115    return $ret; 
     116} 
     117 
    65118 
    66119?> 
     
    79132<h1><?php echo DONATION_TITLE; ?></h1> 
    80133<h2>現在のステータス</h2> 
     134<form method="post"> 
     135<input type="hidden" name="<?php echo TRANSACTION_ID_NAME ;?>" value="<?php echo $token; ?>" /> 
    81136<table> 
    82137  <tr> 
     
    89144    <th>顧客の保持ポイント合計</th><td><?php printf('%d', $total_point); ?>pt</td> 
    90145  </tr> 
     146  <tr> 
     147    <th>寄付ポイント上限設定</th><td><input type="text" value="<?php echo $limit; ?>" name="limit" /><input type="submit" value="設定" /><br />「0」は無制限</td> 
     148  </tr> 
    91149</table> 
     150</form> 
    92151 
    93152<p>集まった義援金総額を, 義援金として日本赤十字社などにお贈り下さい</p> 
  • branches/eccube-donation/html/frontparts/bloc/send_point.php

    r20622 r20674  
    5959        $this->tpl_disable_logout = false; 
    6060        $this->tpl_error = ""; 
     61        $this->complete = false; 
    6162    } 
    6263 
     
    7374                $objQuery->query("INSERT INTO dtb_bloc (bloc_name,tpl_path,filename,create_date,update_date,php_path,del_flg) 
    7475                 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                 } 
    7580            } 
    7681        } 
     82         
     83         
    7784 
    7885        $objCustomer = new SC_Customer(); 
     
    8087        // クッキー管理クラス 
    8188        $objCookie = new SC_Cookie(COOKIE_EXPIRE); 
    82  
     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         
    83102        // ログイン判定 
    84         if($objCustomer->isLoginSuccess()) { 
     103        if($objCustomer->isLoginSuccess() and $this->complete == false ) { 
    85104            $this->tpl_user_point = $objCustomer->getValue('point'); 
    86105            if (strlen($this->tpl_user_point) == 0) $this->tpl_user_point = 0; 
     
    91110                    $this->tpl_error = "1以上のポイントを保有ポイント内で半角数字で入力してください。"; 
    92111                }else{ 
    93                     $objQuery = new SC_Query; 
    94                     $sqlval = array('point' => ($this->tpl_user_point - $point)); 
    95                     $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; 
    96                     $rs = $objQuery->update('dtb_customer', $sqlval, $where, array($objCustomer->getValue('customer_id'))); 
    97                     if($rs){ 
    98                         $fp = fopen(DATA_PATH.'downloads/donation.csv','a+'); 
    99                         fwrite($fp,date("Y-m-d G:i:s").",".$objCustomer->getValue('customer_id').",".$point."\n"); 
    100                         $objCustomer->setValue("point", ($this->tpl_user_point - $point)); 
    101                         $this->tpl_error = "ご協力ありがとうございます。".$point."ptを承りました。<br />寄付頂いたポイント分を、東北地方太平洋沖地震の復旧活動へ寄付いたします。";  
     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); 
    102141                    } else { 
    103142                        $this->tpl_error = "システムエラー";   
     
    111150            $this->tpl_name1 = $objCustomer->getValue('name01'); 
    112151            $this->tpl_name2 = $objCustomer->getValue('name02'); 
    113         } else { 
    114             // クッキー判定 
    115             $this->tpl_login_email = $objCookie->getCookie('login_email'); 
    116             if($this->tpl_login_email != "") { 
    117                 $this->tpl_login_memory = "1"; 
    118             } 
    119  
    120             // POSTされてきたIDがある場合は優先する。 
    121             if($_POST['login_email'] != "") { 
    122                 $this->tpl_login_email = $_POST['login_email']; 
    123             } 
    124         } 
     152        } 
     153         
     154        if($fp2){ 
     155            fclose($fp2); 
     156        } 
     157         
    125158        $this->transactionid = $this->getToken(); 
    126159    } 
     
    145178<div id="sendPoint"> 
    146179<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{ ?> 
    147186<h2>東北地方太平洋沖地震へのポイント寄付のお願い</h2> 
    148 <?php if($objPage->tpl_login){?> 
     187    <?php if($objPage->tpl_login){?> 
    149188<p>現在お客様が保有している当店のポイントを東北地方太平洋沖地震の復旧活動へ寄付出来ます。</p> 
    150189<p>下記フォームに寄付するポイント数を入力の上、「寄付」ボタンをクリックしてください。</p> 
     
    161200    </form> 
    162201</div> 
    163 <?php }else{ ?> 
     202<p>直接現金で赤十字に募金される場合は<a href="http://www.jrc.or.jp/contribution/l3/Vcms3_00002069.html" target="_blank" title="赤十字募金ページへ">コチラ</a>をご参照ください。</p> 
     203    <?php }else{ ?> 
    164204<p>会員のお客様は、現在お客様が保有している当店のポイントを東北地方太平洋沖地震の復旧活動へ寄付できます。ログインしてご協力をお願いします。</p> 
    165205<p>- <a href="<?php echo URL_MYPAGE_TOP ?>">ログイン</a> -</p> 
    166206<p>運営担当者が寄付されたポイントを集計し、東北地方太平洋沖地震の復旧活動へ寄付させて頂きます。</p> 
     207<p>直接現金で赤十字に募金される場合は<a href="http://www.jrc.or.jp/contribution/l3/Vcms3_00002069.html" target="_blank" title="赤十字募金ページへ">コチラ</a>をご参照ください。</p> 
     208    <?php } ?> 
    167209<?php } ?> 
    168210</div> 
    169211</div> 
    170  
Note: See TracChangeset for help on using the changeset viewer.