Changeset View
Changeset View
Standalone View
Standalone View
community/donations/previousdonations.php
Show All 18 Lines | |||||
19 | 19 | | |||
20 | <p>Note this list does not include campaign specific donations like:</p> | 20 | <p>Note this list does not include campaign specific donations like:</p> | ||
21 | <ul> | 21 | <ul> | ||
22 | <li><a href="/fundraisers/randameetings2014/">Randa Meetings 2014 Fundraising</a></li> | 22 | <li><a href="/fundraisers/randameetings2014/">Randa Meetings 2014 Fundraising</a></li> | ||
23 | <li><a href="/fundraisers/yearend2014/">KDE End of Year 2014 Fundraising</a></li> | 23 | <li><a href="/fundraisers/yearend2014/">KDE End of Year 2014 Fundraising</a></li> | ||
24 | <li><a href="/fundraisers/kdesprints2015/">KDE Sprints 2015 Fundraising</a></li> | 24 | <li><a href="/fundraisers/kdesprints2015/">KDE Sprints 2015 Fundraising</a></li> | ||
25 | <li><a href="/fundraisers/yearend2016/">KDE End of Year 2016 Fundraising</a></li> | 25 | <li><a href="/fundraisers/yearend2016/">KDE End of Year 2016 Fundraising</a></li> | ||
26 | </ul> | 26 | </ul> | ||
27 | <script src="https://cdn.kde.org/aether-devel/charjs.js"></script> | ||||
aacid: Are we fine loading stuff form some random domain? | |||||
ognarb: Use https://cdn.kde.org/aether-devel/charjs.js now | |||||
27 | 28 | | |||
28 | <?php | 29 | <?php | ||
29 | require("donations_auth.inc"); | 30 | require("www_config.php"); | ||
31 | function display_graph(int $year, $dbConnection) | ||||
32 | { | ||||
33 | for ($i = 1; $i <= 12; $i++) { | ||||
34 | $i < 10 ? $i_s = "0".$i : $i_s = $i; | ||||
35 | $data[ $year."-".$i_s ] = 0; | ||||
36 | } | ||||
37 | $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"); | ||||
38 | | ||||
39 | $stmt->execute([ | ||||
40 | 'year' => $year, | ||||
41 | ]); | ||||
42 | | ||||
43 | while ($row = $stmt->fetch()) { | ||||
44 | $data[ $row["month"] ] = $row["don"]; | ||||
45 | } ?> | ||||
46 | <div class="col-12 col-md-6 offset-md-3"> | ||||
47 | <canvas id="myChart<?= $year ?>" width="400" height="200"></canvas> | ||||
48 | </div> | ||||
49 | <script> | ||||
50 | let ctx<?= $year ?> = document.getElementById('myChart<?= $year ?>'); | ||||
51 | new Chart(ctx<?= $year ?>, { | ||||
52 | type: 'bar', | ||||
53 | data: { | ||||
54 | labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], | ||||
55 | datasets: [{ | ||||
56 | label: "Donation for the year <?= $year ?>", | ||||
57 | data: [<?php foreach ($data as $month) { echo($month . ","); } ?>], | ||||
58 | fill: false, | ||||
59 | }], | ||||
60 | }, | ||||
61 | options: { scales: { yAxes: [{ ticks: { beginAtZero: true } }] } } | ||||
62 | }); | ||||
63 | </script> | ||||
64 | <?php | ||||
65 | } | ||||
30 | 66 | | |||
67 | $query = $dbConnection->prepare("SELECT *, UNIX_TIMESTAMP(date) AS date_t FROM donations WHERE date >= ':year-:month_s-01' AND date <= ':year-:month_s-31 23:59:59' ORDER BY date DESC;"); | ||||
68 | $count = $dbConnection->prepare("SELECT COUNT(*) WHERE date >= ':year-:month_s-01' AND date <= ':year-:month_s-31 23:59:59';"); | ||||
31 | 69 | | |||
32 | for ($year = date("Y", time()); $year > 2001; $year--) { | 70 | for ($year = date("Y", time()); $year > 2001; $year--) { | ||
33 | echo "<h3>$year</h3>"; | 71 | echo "<h3>$year</h3>"; | ||
34 | echo "<figure style='text-align: center'>"; | 72 | echo "<figure class='text-center'>"; | ||
35 | echo "<img src=\"graph.php?year=$year\">"; | 73 | display_graph($year, $dbConnection); | ||
36 | echo "</figure>"; | 74 | echo "</figure>"; | ||
37 | echo "<br><br>"; | 75 | echo "<br><br>"; | ||
38 | for ($month = 12; $month >=1 ; $month--) { | 76 | for ($month = 12; $month >=1 ; $month--) { | ||
39 | $month < 10 ? $month_s = "0".$month : $month_s = $month; | | |||
40 | $query = "select *,unix_timestamp(date) as date_t from donations "; | | |||
41 | $query .= "where date >= '".$year."-".$month_s."-01' and "; | | |||
42 | $query .= "date <= '".$year."-".$month_s."-31 23:59:59' order by date desc"; | | |||
43 | # echo "<br>".$query."<br><Br>"; | 77 | # echo "<br>".$query."<br><Br>"; | ||
44 | $q = mysql_query($query,$sq); | 78 | $month < 10 ? $month_s = "0".$month : $month_s = $month; | ||
45 | echo mysql_error(); | 79 | $count->execute([ | ||
46 | if (mysql_num_rows($q) == 0) { | 80 | 'year' => $year, | ||
81 | 'month_s' => $month_s, | ||||
82 | ]); | ||||
83 | if ($count->fetchColumn() === 0) { | ||||
47 | continue; | 84 | continue; | ||
48 | } | 85 | } | ||
86 | $query->execute([ | ||||
87 | 'year' => $year, | ||||
88 | 'month_s' => $month_s, | ||||
89 | ]); | ||||
49 | $total = 0; | 90 | $total = 0; | ||
50 | echo "<table border=1 width=\"600\">"; | 91 | echo "<table border=1 width=\"600\">"; | ||
51 | echo "<tr><th colspan=3>".date("Y - F", mktime(0,0,0,$month,1,$year))."</th></tr>"; | 92 | echo "<tr><th colspan=3>".date("Y - F", mktime(0,0,0,$month,1,$year))."</th></tr>"; | ||
52 | echo "<tr><th width=100>Date</th><th width=100>Amount</th><th width=400>Message</th></tr>"; | 93 | echo "<tr><th width=100>Date</th><th width=100>Amount</th><th width=400>Message</th></tr>"; | ||
53 | while ($row = mysql_fetch_array($q)) { | 94 | while ($row = $query->fetch()) { | ||
54 | $msg = htmlentities($row["message"]); | 95 | $msg = htmlentities($row["message"]); | ||
55 | if ($msg == "") { | 96 | if ($msg == "") { | ||
56 | $msg = "<i>Anonymous donation</i>"; | 97 | $msg = "<i>Anonymous donation</i>"; | ||
57 | } | 98 | } | ||
58 | $total += $row["amount"]; | 99 | $total += $row["amount"]; | ||
59 | 100 | | |||
60 | echo "<tr>"; | 101 | echo "<tr>"; | ||
61 | echo "<td>".date("jS H:i", $row["date_t"])."</td>"; | 102 | echo "<td>".date("jS H:i", $row["date_t"])."</td>"; | ||
Show All 16 Lines |
Are we fine loading stuff form some random domain?