[20622] | 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 |
---|
| 25 | if( !defined("CLASS_PATH") ){ |
---|
| 26 | require_once("../../admin/require.php"); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | // 管理画面認証 |
---|
| 31 | SC_Utils_Ex::sfIsSuccess(new SC_Session()); |
---|
| 32 | |
---|
| 33 | // 定数 |
---|
| 34 | define('DONATION_TITLE', 'EC-CUBE Donation'); |
---|
| 35 | define('DONATION_DATA', DATA_PATH . 'downloads/donation.csv'); |
---|
| 36 | define('DONATION_VERSION', '0.0.1'); |
---|
| 37 | |
---|
[20674] | 38 | |
---|
| 39 | |
---|
[20622] | 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 | // ポイント合計 |
---|
[20639] | 45 | $arrPoints = $objQuery->getAll('SELECT SUM(point) as totall_point FROM dtb_customer WHERE del_flg = 0'); |
---|
[20622] | 46 | $total_point = 0; |
---|
[20639] | 47 | if (!is_null($arrPoints[0]["totall_point"])) { |
---|
| 48 | $total_point = $arrPoints[0]["totall_point"]; |
---|
[20622] | 49 | |
---|
| 50 | } |
---|
| 51 | // 顧客IDごとの配列 |
---|
| 52 | $arrCustomers = array(); |
---|
| 53 | |
---|
| 54 | foreach ($arrCustomerTemp as $customer) { |
---|
| 55 | $arrCustomers[$customer['customer_id']] = $customer; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | // 寄付一覧 |
---|
| 59 | $arrDnTemp = file(DONATION_DATA); |
---|
| 60 | $arrDonations = array(); |
---|
| 61 | $correct_point = 0; |
---|
| 62 | foreach ($arrDnTemp as $dn) { |
---|
| 63 | $arrDn = explode(",", $dn); |
---|
| 64 | $arrDonations[] = $arrDn; |
---|
| 65 | $correct_point += $arrDn[2]; |
---|
| 66 | } |
---|
[20674] | 67 | $limit = 0; |
---|
| 68 | if($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(); |
---|
[20622] | 85 | |
---|
[20674] | 86 | function 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 | |
---|
| 94 | function 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 | |
---|
| 118 | |
---|
[20622] | 119 | ?> |
---|
| 120 | <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> |
---|
| 121 | <head> |
---|
| 122 | <title><?php echo DONATION_TITLE; ?> <?php echo DONATION_VERSION; ?></title> |
---|
| 123 | <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHAR_CODE; ?>" /> |
---|
| 124 | <meta http-equiv="content-script-type" content="text/javascript" /> |
---|
| 125 | <meta http-equiv="content-style-type" content="text/css" /> |
---|
| 126 | <meta name="robots" content="noindex,nofollow" /> |
---|
| 127 | <link rel="stylesheet" href="./dn.css" type="text/css" media="all" /> |
---|
| 128 | </head> |
---|
| 129 | <body> |
---|
| 130 | <div id="container"> |
---|
| 131 | <div id="contents"> |
---|
| 132 | <h1><?php echo DONATION_TITLE; ?></h1> |
---|
| 133 | <h2>現在のステータス</h2> |
---|
[20674] | 134 | <form method="post"> |
---|
| 135 | <input type="hidden" name="<?php echo TRANSACTION_ID_NAME ;?>" value="<?php echo $token; ?>" /> |
---|
[20622] | 136 | <table> |
---|
| 137 | <tr> |
---|
| 138 | <th>集まったポイント</th><td><?php printf('%d', $correct_point); ?>pt</td> |
---|
| 139 | </tr> |
---|
| 140 | <tr> |
---|
| 141 | <th>義援金総額</th><td><?php printf('%d', $correct_point * POINT_VALUE); ?>円</td> |
---|
| 142 | </tr> |
---|
| 143 | <tr> |
---|
| 144 | <th>顧客の保持ポイント合計</th><td><?php printf('%d', $total_point); ?>pt</td> |
---|
| 145 | </tr> |
---|
[20674] | 146 | <tr> |
---|
| 147 | <th>寄付ポイント上限設定</th><td><input type="text" value="<?php echo $limit; ?>" name="limit" /><input type="submit" value="設定" /><br />「0」は無制限</td> |
---|
| 148 | </tr> |
---|
[20622] | 149 | </table> |
---|
[20674] | 150 | </form> |
---|
[20622] | 151 | |
---|
| 152 | <p>集まった義援金総額を, 義援金として日本赤十字社などにお贈り下さい</p> |
---|
| 153 | |
---|
| 154 | <h2>寄付いただいた顧客一覧</h2> |
---|
| 155 | <table> |
---|
| 156 | <tr> |
---|
| 157 | <th>寄付日時</th><th>顧客ID</th><th>お名前</th><th>寄付ポイント</th> |
---|
| 158 | </tr> |
---|
| 159 | <?php foreach ($arrDonations as $donation) { ?> |
---|
| 160 | <tr> |
---|
| 161 | <td><?php echo $donation[0]; ?></td> |
---|
| 162 | <td><?php echo $donation[1]; ?></td> |
---|
| 163 | <td><?php echo $arrCustomers[$donation[1]]['name01']; ?> <?php echo $arrCustomers[$donation[1]]['name02']; ?></td> |
---|
| 164 | <td><?php echo $donation[2]; ?>pt</td> |
---|
| 165 | </tr> |
---|
| 166 | <?php } ?> |
---|
| 167 | </table> |
---|
| 168 | </div> |
---|
| 169 | </div> |
---|
| 170 | </body> |
---|
| 171 | </html> |
---|