527b1c39cf63d5fa446246d0362a4a59762fd7e8
[clinton/MarylandElectronicPetitionSignature.git] / admin / report.php
1 <?PHP
2 include_once('security.php');
3 include_once('/var/www/secure.php'); //outside webserver
4 if (isset($_GET['override'])){
5 $id = $_GET['override'];
6 $petition->query("update signatures set signature_status = 'verified' where id = '$id' ");
7 header('Location: report.php');
8 }
9 if (isset($_GET['delete'])){
10 $id = $_GET['delete'];
11 $petition->query("update signatures set signature_status = 'deleted' where id = '$id' ");
12 header('Location: report.php');
13 }
14 if (isset($_GET['review'])){
15 $id = $_GET['review'];
16 $petition->query("update signatures set signature_status = 'review_requested' where id = '$id' ");
17 header('Location: report.php');
18 }
19 include_once('header.php');
20 slack_general('ADMIN: Reports Loaded ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
21 $group_id = $_COOKIE['group_id'];
22 $javascript='';
23 ?>
24 <script>
25 function checkAll(formname, checktoggle)
26 {
27 var checkboxes = new Array();
28 checkboxes = document[formname].getElementsByTagName('input');
29
30 for (var i=0; i<checkboxes.length; i++) {
31 if (checkboxes[i].type == 'checkbox') {
32 checkboxes[i].checked = checktoggle;
33 }
34 }
35 }
36 </script>
37 <style>
38 body { background-color:lightgrey; }
39 fieldset{ border: solid 1px lightblue; background-color:white; margin:10px; padding:10px; }
40 legend{ border: solid 1px blue; background-color:white; margin:10px; padding:10px; }
41 td{ white-space: pre; }
42 </style>
43 <?PHP
44 if($_COOKIE['level'] == 'admin'){
45 $q="SELECT * FROM petitions where admin_status = 'approved' order by admin_sort DESC ";
46 }else{
47 $q="SELECT * FROM petitions where group_id = '$group_id' and admin_status = 'approved'";
48 }
49 //echo "<li>$q</li>";
50 $r = $petition->query($q);
51 while($d = mysqli_fetch_array($r)){
52 $pID = $d['petition_id'];
53 echo "<div id=\"chartContainer$pID\" style=\"height: 400px; width: 100%; margin: 0px auto;\"></div>";
54 $chart='';
55 $chart2='';
56 $chart3='';
57 $q3 = "SELECT just_date FROM signatures where petition_id = '$pID' and just_date <> '0000-00-00' group by just_date";
58 //echo "<li>$q3</li>";
59 $r3 = $petition->query($q3);
60 $total=0;
61 $goal = $d['signature_goal'];
62 if ($goal == 0){
63 $goal = 10000;
64 }
65 while ($d3 = mysqli_fetch_array($r3)){
66 $just_date = $d3['just_date'];
67 $q2 = "SELECT * FROM signatures where petition_id = '$pID' and just_date = '$just_date' and signature_status = 'verified' ";
68 //echo "<li>$q2</li>";
69 $r2 = $petition->query($q2);
70 $count = mysqli_num_rows($r2);
71 $chart .= '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
72 $total = $total + intval($count);
73 $chart2 .= '{ label: "'.$just_date.'", y: '.intval($total).' }, ';
74 $goal = $goal - intval($count);
75 $chart3 .= '{ label: "'.$just_date.'", y: '.intval($goal).' }, ';
76 }
77 $chart = rtrim(trim($chart), ",");
78 $chart2 = rtrim(trim($chart2), ",");
79 $chart3 = rtrim(trim($chart3), ",");
80
81 ob_start(); ?>
82
83 var chart<?PHP echo $pID;?> = new CanvasJS.Chart("chartContainer<?PHP echo $pID;?>", {
84 theme:"light2",
85 animationEnabled: true,
86 exportEnabled: true,
87 title:{
88 text: "<?PHP echo $d['petition_name'];?> MD-Petition.com Signature Tracker"
89 },
90 axisY :{
91 includeZero: false,
92 title: "Number of Signatures",
93 suffix: "",
94 scaleBreaks: {
95 autoCalculate: true
96 }
97 },
98 toolTip: {
99 shared: "true"
100 },
101 legend:{
102 cursor:"pointer",
103 itemclick : toggleDataSeries
104 },
105 data: [{
106 type: "line",
107 visible: true,
108 showInLegend: true,
109 yValueFormatString: "#####",
110 name: "Total Signatures Count",
111 dataPoints: [
112 <?PHP echo $chart2; ?>
113 ]
114 },<?PHP if(1 == 2){ ?>{
115 type: "line",
116 visible: true,
117 showInLegend: true,
118 yValueFormatString: "#####",
119 name: "Signatures Remaining to Goal",
120 dataPoints: [
121 <?PHP echo $chart3; ?>
122 ]
123 },<?PHP } ?>{
124 type: "column",
125 visible: true,
126 showInLegend: true,
127 yValueFormatString: "#####",
128 name: "New Daily Signatures",
129 dataPoints: [
130 <?PHP echo $chart; ?>
131 ]
132 }]
133 }
134
135
136 );
137 chart<?PHP echo $pID;?>.render();
138
139 <?PHP $javascript .= ob_get_clean();
140 }
141 ?>
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 <form id='form3' name='form3' method='POST' action='printer.php'>
158 <?PHP
159 if($_COOKIE['level'] == 'admin'){
160 $q="SELECT * FROM petitions where admin_status = 'approved' ";
161 }else{
162 $q="SELECT * FROM petitions where group_id = '$group_id' and admin_status = 'approved'";
163 }
164 $r = $petition->query($q);
165 while($d = mysqli_fetch_array($r)){
166 echo "<fieldset style='border: solid 1px $d[web_color];'><legend style='background-color:white;'>$d[petition_name] - Unprinted</legend>
167 <a onclick=\"javascript:checkAll('form3', true);\" href=\"javascript:void();\">Check All</a>
168 <a onclick=\"javascript:checkAll('form3', false);\" href=\"javascript:void();\">Uncheck All</a>
169 <input type='submit' value='PRINT'>";
170 echo "<table border='1' cellpadding='0' cellspacing='5'>";
171 unset($hide);
172 $hide = array();
173 $pID = $d['petition_id'];
174 $q2="SELECT * FROM signatures where petition_id = '$pID' and printed_status = '' and signature_status = 'verified' order by signature_status, id desc";
175 $r2 = $petition->query($q2);
176 while($d2 = mysqli_fetch_array($r2)){
177 if ($d2['signature_status'] == 'verified'){
178 $id = $d2['id'];
179 echo "<tr>
180 <td><input type='checkbox' name='print[".$id."]'></td><td>$d2[ip_address]</td><td>$d2[date_time_signed]</td><td>$d2[signed_name_as]</td><td>$d2[signed_name_as_circulator]</td><td>$d2[contact_phone]</td><td>$d2[signature_status]-<a href='?review=$d2[id]'>Flag for Review</a></td><td>$d2[printed_status]</td></tr>";
181 }else{
182 echo "<tr>
183 <td><a href='?override=$d2[id]'>Override</a> or <a href='?delete=$d2[id]'>Delete</a></td><td>$d2[ip_address]</td><td>$d2[date_time_signed]</td><td>$d2[signed_name_as]</td><td>$d2[signed_name_as_circulator]</td><td>$d2[contact_phone]</td><td>$d2[signature_status]</td><td>$d2[printed_status]</td></tr>";
184 }
185 }
186 echo '</table></fieldset>';
187
188
189
190 }
191 ?>
192 </form>
193
194
195 <?PHP if($_COOKIE['level'] == 'admin'){ ?>
196
197 <form id='form5' name='form5' method='POST' action='printer.php'>
198 <?PHP
199 if($_COOKIE['level'] == 'admin'){
200 $q="SELECT * FROM petitions where admin_status = 'approved' ";
201 }else{
202 $q="SELECT * FROM petitions where group_id = '$group_id' and admin_status = 'approved'";
203 }
204 $r = $petition->query($q);
205 while($d = mysqli_fetch_array($r)){
206 echo "<fieldset style='border: solid 1px $d[web_color];'><legend style='background-color:white;'>$d[petition_name] - Flagged for Deletion or Override</legend>
207 <a onclick=\"javascript:checkAll('form3', true);\" href=\"javascript:void();\">Check All</a>
208 <a onclick=\"javascript:checkAll('form3', false);\" href=\"javascript:void();\">Uncheck All</a>
209 <input type='submit' value='PRINT'>";
210 echo "<table border='1' cellpadding='0' cellspacing='5'>";
211 unset($hide);
212 $hide = array();
213 $pID = $d['petition_id'];
214 $q2="SELECT * FROM signatures where petition_id = '$pID' and printed_status = '' and signature_status <> 'deleted' and signature_status <> 'verified' order by signature_status, id desc";
215 $r2 = $petition->query($q2);
216 while($d2 = mysqli_fetch_array($r2)){
217 if ($d2['signature_status'] == 'verified'){
218 echo "<tr>
219 <td><input type='checkbox' name='print[".$d2[id]."]'></td><td>$d2[ip_address]</td><td>$d2[date_time_signed]</td><td>$d2[signed_name_as]</td><td>$d2[signed_name_as_circulator]</td><td>$d2[contact_phone]</td><td>$d2[signature_status]-<a href='?review=$d2[id]'>Flag for Review</a></td><td>$d2[printed_status]</td></tr>";
220 }else{
221 echo "<tr>
222 <td><a href='?override=$d2[id]'>Override</a> or <a href='?delete=$d2[id]'>Delete</a></td><td>$d2[ip_address]</td><td>$d2[date_time_signed]</td><td>$d2[signed_name_as]</td><td>$d2[signed_name_as_circulator]</td><td>$d2[contact_phone]</td><td>$d2[signature_status]</td><td>$d2[printed_status]</td></tr>";
223 }
224 }
225 echo '</table></fieldset>';
226
227
228
229 }
230 ?>
231 </form>
232
233 <?PHP } ?>
234
235
236 <form id='form2' name='form2' method='POST' action='printer.php'>
237
238 <?PHP
239 if($_COOKIE['level'] == 'admin'){
240 $q="SELECT * FROM petitions where admin_status = 'approved' ";
241 }else{
242 $q="SELECT * FROM petitions where group_id = '$group_id' and admin_status = 'approved' ";
243 }
244 $r = $petition->query($q);
245 while($d = mysqli_fetch_array($r)){
246 echo "<fieldset style='border: solid 1px $d[web_color];'><legend style='background-color:white;'>$d[petition_name] - Printed</legend>
247 <a onclick=\"javascript:checkAll('form2', true);\" href=\"javascript:void();\">Check All</a>
248 <a onclick=\"javascript:checkAll('form2', false);\" href=\"javascript:void();\">Uncheck All</a>
249 <input type='submit' value='PRINT'>";
250 echo "<table border='1' cellpadding='0' cellspacing='5'>";
251 unset($hide);
252 $hide = array();
253 $pID = $d['petition_id'];
254 $q2="SELECT * FROM signatures where petition_id = '$pID' and printed_status <> '' and signature_status <> 'deleted' order by signature_status, id desc";
255 $r2 = $petition->query($q2);
256 while($d2 = mysqli_fetch_array($r2)){
257 if ($d2['signature_status'] == 'verified'){
258 echo "<tr><td><input type='checkbox' name='print[".$d2[id]."]'></td><td>$d2[ip_address]</td><td>$d2[date_time_signed]</td><td>$d2[signed_name_as]</td><td>$d2[signed_name_as_circulator]</td><td>$d2[contact_phone]</td><td>$d2[signature_status]-<a href='?review=$d2[id]'>Flag for Review</a></td><td>$d2[printed_status]</td></tr>";
259 }else{
260 echo "<tr><td><a href='?override=$d2[id]'>Override</a> or <a href='?delete=$d2[id]'>Delete</a></td><td>$d2[ip_address]</td><td>$d2[date_time_signed]</td><td>$d2[signed_name_as]</td><td>$d2[signed_name_as_circulator]</td><td>$d2[contact_phone]</td><td>$d2[signature_status]</td><td>$d2[printed_status]</td></tr>";
261 }
262 }
263 echo '</table></fieldset>';
264
265
266 }
267 ?>
268 </form>
269
270
271
272
273
274 <script>
275 window.onload = function () {
276
277 <?PHP echo $javascript;?>
278
279 function toggleDataSeries(e) {
280 if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible ){
281 e.dataSeries.visible = false;
282 } else {
283 e.dataSeries.visible = true;
284 }
285 chart.render();
286 }
287
288 }
289 </script>
290
291
292
293 <script src="../files/canvasjs.min.js"></script>
294 <?PHP
295 include_once('footer.php');
296 ?>