Changeset View
Changeset View
Standalone View
Standalone View
community/donations/graph.php
1 | <?php | 1 | <?php | ||
---|---|---|---|---|---|
2 | 2 | | |||
3 | require("donations_auth.inc"); | 3 | require("donations_auth.inc"); | ||
4 | 4 | | |||
5 | $year = mysql_real_escape_string( $_GET["year"] ); | 5 | $year = (int)$_GET["year"]; | ||
6 | if ($year < 2001 || $year > 2020) { | 6 | if ($year < 2001 || $year > 2020) { | ||
bcooksley: Given we're in 2019 maybe we should increase the limit to something like 2030? | |||||
7 | echo "year check failed"; | 7 | echo "year check failed"; | ||
8 | exit(1); | 8 | exit(1); | ||
9 | } | 9 | } | ||
10 | 10 | | |||
11 | // initialise | 11 | // initialise | ||
12 | for ($i = 1; $i <= 12; $i++) { | 12 | for ($i = 1; $i <= 12; $i++) { | ||
13 | $i < 10 ? $i_s = "0".$i : $i_s = $i; | 13 | $i < 10 ? $i_s = "0".$i : $i_s = $i; | ||
14 | $data[ $year."-".$i_s ] = 0; | 14 | $data[ $year."-".$i_s ] = 0; | ||
15 | } | 15 | } | ||
16 | 16 | | |||
17 | $query = "select sum(amount) as don, DATE_FORMAT(date,\"%Y-%m\") as month from donations "; | 17 | $stmt = $dbConnection->prepare("SELECT SUM(amount) as don, DATE_FORMAT(date,\"%Y-%m\") as month from donations WHERE year(date) = ':year' GROUP BY month ORDER BY month DESC"; | ||
18 | $query .= "where year(date) = '".$_GET["year"]."' "; | 18 | $stmt->execute([ | ||
19 | $query .= "group by month order by month desc"; | 19 | 'year' => $year, | ||
20 | $q = mysql_query($query,$sq); | 20 | ]); | ||
21 | while ($row = mysql_fetch_array($q)) { | 21 | while ($row = $stmt->fetch()) { | ||
22 | $data[ $row["month"] ] = $row["don"]; | 22 | $data[ $row["month"] ] = $row["don"]; | ||
23 | } | 23 | } | ||
24 | 24 | | |||
25 | $keys = array_keys($data); | 25 | $keys = array_keys($data); | ||
26 | $values = array_values($data); | 26 | $values = array_values($data); | ||
27 | 27 | | |||
28 | // below is taken from http://code.web-max.ca/image_graph.php | 28 | // below is taken from http://code.web-max.ca/image_graph.php | ||
29 | // and adapted a bit. | 29 | // and adapted a bit. | ||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |
Given we're in 2019 maybe we should increase the limit to something like 2030?