source: branches/eccube-donation/html/frontparts/bloc/index.php @ 20698

Revision 20698, 5.1 KB checked in by tao, 13 years ago (diff)

#refs fseek() を追加

  • 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
24// html/admin/require.php を require
25if( !defined("CLASS_PATH") ){
26    require_once("../../admin/require.php");
27}
28
29
30// 管理画面認証
31SC_Utils_Ex::sfIsSuccess(new SC_Session());
32
33// 定数
34define('DONATION_TITLE', 'EC-CUBE Donation');
35define('DONATION_DATA', DATA_PATH . 'downloads/donation.csv');
36define('DONATION_VERSION', '0.0.1');
37
38
39
40$objQuery = new SC_Query();
41// 全顧客取得
42$arrCustomerTemp = $objQuery->getAll('SELECT customer_id, name01, name02, point FROM dtb_customer WHERE del_flg = 0');
43
44// ポイント合計
45$arrPoints = $objQuery->getAll('SELECT SUM(point) as totall_point FROM dtb_customer WHERE del_flg = 0');
46$total_point = 0;
47if (!is_null($arrPoints[0]["totall_point"])) {
48    $total_point = $arrPoints[0]["totall_point"];
49
50}
51// 顧客IDごとの配列
52$arrCustomers = array();
53
54foreach ($arrCustomerTemp as $customer) {
55    $arrCustomers[$customer['customer_id']] = $customer;
56}
57
58// 寄付一覧
59$arrDnTemp = file(DONATION_DATA);
60$arrDonations = array();
61$correct_point = 0;
62foreach ($arrDnTemp as $dn) {
63    $arrDn = explode(",", $dn);
64    $arrDonations[] = $arrDn;
65    $correct_point += $arrDn[2];
66}
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        fseek($fp,0);
81        fwrite($fp,$num.','.$total.','.$limit);
82    }
83    fclose($fp);
84}
85$token = getToken();
86
87function getToken() {
88    if (empty($_SESSION[TRANSACTION_ID_NAME])) {
89        $_SESSION[TRANSACTION_ID_NAME] = sha1(uniqid(rand(), true));
90    }
91    return $_SESSION[TRANSACTION_ID_NAME];
92}
93
94
95function isValidToken() {
96
97    $checkToken = "";
98
99    // $_POST の値を優先する
100    if (isset($_POST[TRANSACTION_ID_NAME])) {
101
102        $checkToken = $_POST[TRANSACTION_ID_NAME];
103    } elseif (isset($_GET[TRANSACTION_ID_NAME])) {
104
105        $checkToken = $_GET[TRANSACTION_ID_NAME];
106    }
107
108    $ret = false;
109    // token の妥当性チェック
110    if ($checkToken === $_SESSION[TRANSACTION_ID_NAME]) {
111
112        $ret = true;
113    }
114
115    unset($_SESSION[TRANSACTION_ID_NAME]);
116    return $ret;
117}
118
119
120?>
121<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
122<head>
123<title><?php echo DONATION_TITLE; ?> <?php echo DONATION_VERSION; ?></title>
124<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHAR_CODE; ?>" />
125<meta http-equiv="content-script-type" content="text/javascript" />
126<meta http-equiv="content-style-type" content="text/css" />
127<meta name="robots" content="noindex,nofollow" />
128<link rel="stylesheet" href="./dn.css" type="text/css" media="all" />
129</head>
130<body>
131<div id="container">
132<div id="contents">
133<h1><?php echo DONATION_TITLE; ?></h1>
134<h2>現在のステータス</h2>
135<form method="post">
136<input type="hidden" name="<?php echo TRANSACTION_ID_NAME ;?>" value="<?php echo $token; ?>" />
137<table>
138  <tr>
139    <th>集まったポイント</th><td><?php printf('%d', $correct_point); ?>pt</td>
140  </tr>
141  <tr>
142    <th>義援金総額</th><td><?php printf('%d', $correct_point * POINT_VALUE); ?>円</td>
143  </tr>
144  <tr>
145    <th>顧客の保持ポイント合計</th><td><?php printf('%d', $total_point); ?>pt</td>
146  </tr>
147  <tr>
148    <th>寄付ポイント上限設定</th><td><input type="text" value="<?php echo $limit; ?>" name="limit" /><input type="submit" value="設定" /><br />「0」は無制限</td>
149  </tr>
150</table>
151</form>
152
153<p>集まった義援金総額を, 義援金として日本赤十字社などにお贈り下さい</p>
154
155<h2>寄付いただいた顧客一覧</h2>
156<table>
157  <tr>
158    <th>寄付日時</th><th>顧客ID</th><th>お名前</th><th>寄付ポイント</th>
159  </tr>
160  <?php foreach ($arrDonations as $donation) { ?>
161  <tr>
162    <td><?php echo $donation[0]; ?></td>
163    <td><?php echo $donation[1]; ?></td>
164    <td><?php echo $arrCustomers[$donation[1]]['name01']; ?> <?php echo $arrCustomers[$donation[1]]['name02']; ?></td>
165    <td><?php echo $donation[2]; ?>pt</td>
166  </tr>
167  <?php } ?>
168</table>
169</div>
170</div>
171</body>
172</html>
Note: See TracBrowser for help on using the repository browser.