forked from kakaroto/humblehomebrew
/
functions.php
181 lines (148 loc) · 4.48 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
require_once 'config.php';
function get_sgt_value()
{
global $DEFAULT_VALUES;
if (isset($_REQUEST['sgt']) && is_numeric($_REQUEST['sgt']))
return $_REQUEST['sgt'];
else
return $DEFAULT_VALUES['sgt'];
}
function get_ps3_value()
{
global $DEFAULT_VALUES;
if (isset($_REQUEST['ps3']) && is_numeric($_REQUEST['ps3']))
return $_REQUEST['ps3'];
else
return $DEFAULT_VALUES['ps3'];
}
function get_eff_value()
{
global $DEFAULT_VALUES;
if (isset($_REQUEST['eff']) && is_numeric($_REQUEST['eff']))
return $_REQUEST['eff'];
else
return $DEFAULT_VALUES['eff'];
}
function get_value($key) {
global $DEFAULT_VALUES;
if (isset($_REQUEST[$key]) && is_string($_REQUEST[$key]))
return $_REQUEST[$key];
else if (isset($DEFAULT_VALUES[$key]))
return $DEFAULT_VALUES[$key];
else
return '';
}
function get_amount_psn()
{
$paygame = get_value('paygame');
if ($paygame == '') {
$amount = get_value('amount');
$eff = get_eff_value();
if ($amount == '')
return '';
return $amount - ($amount * $eff / 100);
} else {
return $paygame;
}
}
function get_amount_rights()
{
$payrights = get_value('payrights');
if ($payrights == '') {
$amount = get_value('amount');
$eff = get_eff_value();
if ($amount == '')
return '';
return $amount * $eff / 100;
} else {
return $payrights;
}
}
function check_donated()
{
if (!isset($_REQUEST['donated']) || $_REQUEST['donated'] != "1")
return;
include "donate_thanks.html";
}
function check_signed()
{
if (!isset($_REQUEST['signed']))
return;
if ($_REQUEST['signed'] == "1")
include "sign_thanks.html";
else
include "sign_error.html";
}
function check_emailed()
{
global $CONTACT_DESTINATION;
$result_box = "<table width=\"50%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"shadow\">".
"<tr>".
"<td align=\"center\" valign=\"top\" bgcolor=\"#CCCCCC\" class=\"engrave\">".
"<p class=\"style6 style1\">".
"%s".
"</p>".
"</td>".
"</tr>".
"</table>";
if (isset($_REQUEST['email']) && is_string($_REQUEST['email'])) {
$email = filter_var($_REQUEST['email'], FILTER_SANITIZE_EMAIL);
if (filter_var($email, FILTER_VALIDATE_EMAIL) || eregi("(\r|\n)", $email)) {
if (isset($_REQUEST['message']) && is_string($_REQUEST['message']) && strlen($_REQUEST['message']) > 50) {
if (isset($_REQUEST['subject']) && is_string($_REQUEST['subject']) && strlen($_REQUEST['subject']) > 0) {
$subject = "HumbleHomebrewCollection: " . $_REQUEST['subject'];
$message = $_REQUEST['message'] . "\n\nSent from " . $_SERVER['REMOTE_ADDR'];
$message = wordwrap($message, 70);
if (mail($CONTACT_DESTINATION, $subject, $message, "From: $email" )) {
printf($result_box, "Thank you for submitting your question, we will answer you as soon as possible.");
return true;
} else {
printf($result_box, "Unable to send message, please try again");
}
} else {
printf($result_box, "Invalid subject");
}
} else {
printf($result_box, "Invalid message");
}
} else {
printf($result_box, "Invalid email address");
}
} else {
printf($result_box, "Invalid email address");
}
return false;
}
function get_short_statistics($con)
{
$result = mysql_query("SELECT SUM(amount) AS total_amount, COUNT(transaction_id) AS total_donations FROM donations", $con);
if ($result) {
$row = mysql_fetch_assoc($result);
$total_amount = sprintf("\$ %.2f USD", $row['total_amount']);
$total_donations = $row['total_donations'];
$average_donation = "\$ 0.00 USD";
if ($total_donations > 0) {
$average_donation = $row['total_amount'] / $total_donations;
$average_donation = sprintf("\$ %.2f USD", $average_donation);
}
} else {
$total_amount = $total_donations = $average_donation = "Error accessing database";
}
$result = mysql_query("SELECT COUNT(id) FROM signatures",$con);
if ($result) {
$row = mysql_fetch_row($result);
$total_signatures = $row[0];
} else {
$total_signatures = "Error accessing database";
}
$result = mysql_query("SELECT COUNT(DISTINCT ip) FROM downloads",$con);
if ($result) {
$row = mysql_fetch_row($result);
$total_downloads = $row[0];
} else {
$total_downloads = "Error accessing database";
}
return array($total_amount, $total_donations, $average_donation, $total_signatures, $total_downloads);
}
?>