Update analytics.php
[clinton/MarylandElectronicPetitionSignature.git] / admin / analytics.php
1 <?PHP
2 include_once('../slack.php');
3 include_once('security.php');
4 include_once('/var/www/secure.php'); //outside webserver
5 include_once('functions.php');
6
7 function js_redirect($page){
8 $base = 'https://www.md-petition.com/admin/';
9 $url = $base.$page;
10 echo "<script>window.location.href = \"$url\";</script>";
11 die();
12 }
13
14 if ($_COOKIE['level'] == 'user'){
15 slack_general('ADMIN: Redirect User Home ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
16 header('Location: user_home.php');
17 }
18 if (isset($_GET['clear_php_session_id'])){
19 $id = $_GET['clear_php_session_id'];
20 $petition->query("update presign set presign_status = 'DONE' where php_session_id = '$id' ");
21 header('Location: analytics.php');
22 }
23 if (isset($_GET['clear_email'])){
24 $email = $_GET['clear_email'];
25 $petition->query("update presign set presign_status = 'DONE' where email_for_follow_up = '$email' ");
26 header('Location: analytics.php');
27 }
28 if (isset($_GET['sign_email'])){
29 $email = $_GET['sign_email'];
30 $petition->query("update presign set presign_status = 'SIGNED' where email_for_follow_up = '$email' ");
31 header('Location: analytics.php');
32 }
33 if (isset($_GET['sign_php_session_id'])){
34 $id = $_GET['sign_php_session_id'];
35 $petition->query("update presign set presign_status = 'SIGNED' where php_session_id = '$id' ");
36 header('Location: analytics.php');
37 }
38 if ($_COOKIE['level'] == 'manager'){
39 slack_general('ADMIN: Redirect Manager Home ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
40 header('Location: manager_home.php');
41 }
42 if (isset($_GET['flag_invalid_signature'])){
43 $id = $_GET['flag_invalid_signature'];
44 $petition->query("update signatures set signature_status = 'flag_invalid_signature' where id = '$id' ");
45 header('Location: analytics.php');
46 }
47 if (isset($_GET['flag_duplicate'])){
48 $id = $_GET['flag_duplicate'];
49 $petition->query("update signatures set signature_status = 'flag_duplicate' where id = '$id' ");
50 header('Location: analytics.php');
51 }
52 if (isset($_GET['flag_ip_address'])){
53 $ip = $_GET['flag_ip_address'];
54 $petition->query("update signatures set signature_status = 'flag_ip_address' where ip_address = '$ip' ");
55 header('Location: analytics.php');
56 }
57 if (isset($_GET['resign_requested'])){
58 $id = $_GET['resign_requested'];
59 $petition->query("update signatures set signature_status = 'resign_requested' where id = '$id' ");
60 header('Location: analytics.php');
61 }
62 if (isset($_GET['bot'])){
63 $id = $_GET['bot'];
64 $petition->query("update signatures set signature_status = 'bot' where id = '$id' ");
65 header('Location: analytics.php');
66 }
67 if (isset($_GET['flag_VTRID'])){
68 $VTRID = $_GET['flag_VTRID'];
69 $petition->query("update signatures set signature_status = 'flag_VTRID' where VTRID = '$VTRID' ");
70 header('Location: analytics.php');
71 }
72 if (isset($_GET['flag_phone'])){
73 $flag_phone = $_GET['flag_phone'];
74 $petition->query("update signatures set signature_status = 'flag_phone' where contact_phone = '$flag_phone' ");
75 header('Location: analytics.php');
76 }
77 include_once('header.php');
78 if (isset($_GET['ip_address'])){
79 $ip = $_GET['ip_address'];
80 $petition_id = $_GET['petition_id'];
81 echo "<h1>Review $ip</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";
82 $q = "SELECT * FROM signatures where ip_address = '$ip' and signature_status = 'verified' and petition_id = '$petition_id' order by signature_status desc ";
83 $r = $petition->query($q);
84 while($d = mysqli_fetch_array($r)){
85 $color = 'white';
86 $pos = strpos($d['date_time_signed'], date('Y-m-d'));
87 if ($pos !== false) {
88 $color= 'yellow';
89 }
90 echo "<tr style='background-color:$color;'>
91 <td><b>$d[date_time_signed]</b></td>
92 <td><a href='?VTRID=$d[VTRID]'>$d[VTRID]</a></td>
93 <td>".id2petition($d['petition_id'])."</td>
94 <td>$d[signed_name_as]</td>
95 <td>$d[signed_name_as_circulator]</td>
96 <td>$d[contact_phone]</td>
97 <td>$d[printed_status]</td>
98 <td><a href='?flag_invalid_signature=$d[id]'>flag invalid signature</a></td>
99 <td><a href='?flag_VTRID=$d[VTRID]'>flag VTRID</a></td>
100 <td><a href='?flag_ip_address=$d[ip_address]'>flag ip address</a></td>
101 <td><a href='?flag_duplicate=$d[id]'>flag duplicate</a></td>
102 <td><a href='?flag_phone=$d[contact_phone]'>contact phone</a></td>
103 <td><a href='?resign_requested=$d[id]'>resign requested</a></td>
104 <td><a href='?bot=$d[id]'>bot</a></td>
105 </tr>";
106 }
107 echo "</table>";
108 }elseif(isset($_GET['email'])){
109 $email = $_GET['email'];
110 echo "<h1>Review $email</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";
111 $q = "SELECT * FROM presign where email_for_follow_up = '$email' order by id desc ";
112 $r = $petition->query($q);
113 while($d = mysqli_fetch_array($r)){
114 $color = 'white';
115 $test = date('Y-m-d',strtotime($d['action_on']));
116 $pos = strpos($test, date('Y-m-d'));
117 if ($pos !== false) {
118 $color= 'yellow';
119 }
120 echo "<tr style='background-color:$color;'>
121 <td style='white-space:pre;'><b>$d[action_on]</b></td>
122 <td style='white-space:pre;'><a href='?php_session_id=$d[php_session_id]'>$d[php_session_id]</a></td>
123 <td style='white-space:pre;'>$d[php_page]</td>
124 <td style='white-space:pre;'>".id2petition($d['petition'])."</td>
125 <td style='white-space:pre;'>$d[invite]</td>
126 <td style='white-space:pre;'>$d[invite_error]</td>
127 <td style='white-space:pre;'>$d[name]</td>
128 <td style='white-space:pre;'>$d[email_for_follow_up]</td>
129 <td style='white-space:pre;'>$d[phone_for_validation]</td>
130 <td style='white-space:pre;'>$d[presign_status]</td>
131 <td style='white-space:pre;'>$d[ip_address]</td>
132 <td style='white-space:pre;'>$d[browser_string]</td>
133 </tr>";
134 }
135 echo "</table><a href='?clear_email=$email'>CLEAR EMAIL</a> - <a href='?sign_email=$email'>SIGNATURE FOUND</a>";
136 }elseif(isset($_GET['php_session_id']) && empty($_GET['follow_up'])){
137 $php_session_id = $_GET['php_session_id'];
138 echo "<h1>Review $php_session_id</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";
139 $q = "SELECT * FROM presign where php_session_id = '$php_session_id' order by id desc ";
140 $r = $petition->query($q);
141 while($d = mysqli_fetch_array($r)){
142 $color = 'white';
143 $test = date('Y-m-d',strtotime($d['action_on']));
144 $pos = strpos($test, date('Y-m-d'));
145 if ($pos !== false) {
146 $color= 'yellow';
147 }
148 echo "<tr style='background-color:$color;'>
149 <td style='white-space:pre;'><b>$d[action_on]</b></td>
150 <td style='white-space:pre;'>$d[php_page]</td>
151 <td style='white-space:pre;'>".id2petition($d['petition'])."</td>
152 <td style='white-space:pre;'>$d[invite]</td>
153 <td style='white-space:pre;'>$d[invite_error]</td>
154 <td style='white-space:pre;'>$d[name]</td>
155 <td style='white-space:pre;'><a href='?email=$d[email_for_follow_up]'>$d[email_for_follow_up]</a></td>
156 <td style='white-space:pre;'>$d[phone_for_validation]</td>
157 <td style='white-space:pre;'>$d[presign_status]</td>
158 <td style='white-space:pre;'>$d[ip_address]</td>
159 <td style='white-space:pre;'>$d[browser_string]</td>
160 </tr>";
161 }
162 echo "</table><a href='?clear_php_session_id=$php_session_id'>CLEAR SESSION</a> -
163 <a href='?sign_php_session_id=$php_session_id'>SIGNATURE FOUND</a><br>
164 - <a href='?php_session_id=$php_session_id&follow_up=X'>ADD TO FOLLOW UP LIST Maryland General</a><br>
165 - <a href='?php_session_id=$php_session_id&follow_up=1'>ADD TO FOLLOW UP LIST MGP</a><br>
166 - <a href='?php_session_id=$php_session_id&follow_up=2'>ADD TO FOLLOW UP LIST MLP</a><br>
167 - <a href='?php_session_id=$php_session_id&follow_up=3'>ADD TO FOLLOW UP LIST BTEC</a><br>
168 - <a href='?php_session_id=$php_session_id&follow_up=7'>ADD TO FOLLOW UP LIST PG</a><br>
169 - <a href='?php_session_id=$php_session_id&follow_up=8'>ADD TO FOLLOW UP LIST Ivey</a>
170 ";
171 }elseif(isset($_GET['php_session_id']) && isset($_GET['follow_up'])){
172 $php_session_id = $_GET['php_session_id'];
173 echo "<h1>Adding Follow up for $php_session_id to $_GET[follow_up]</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";
174 $q = "SELECT * FROM presign where php_session_id = '$php_session_id' order by id desc ";
175 $r = $petition->query($q);
176 while($d = mysqli_fetch_array($r)){
177
178 $color = 'white';
179 $test = date('Y-m-d',strtotime($d['action_on']));
180 $pos = strpos($test, date('Y-m-d'));
181 if ($pos !== false) {
182 $color= 'yellow';
183 }
184 if ($d[name] != ''){
185 $name = $d[name];
186 }
187 if ($d[email_for_follow_up] != ''){
188 $email = $d[email_for_follow_up];
189 }
190 echo "<tr style='background-color:$color;'>
191 <td style='white-space:pre;'><b>$d[action_on]</b></td>
192 <td style='white-space:pre;'>$d[php_page]</td>
193 <td style='white-space:pre;'>".id2petition($d['petition'])."</td>
194 <td style='white-space:pre;'>$d[invite]</td>
195 <td style='white-space:pre;'>$d[invite_error]</td>
196 <td style='white-space:pre;'>$d[name]</td>
197 <td style='white-space:pre;'>$d[email_for_follow_up]</td>
198 <td style='white-space:pre;'>$d[phone_for_validation]</td>
199 <td style='white-space:pre;'>$d[presign_status]</td>
200 <td style='white-space:pre;'>$d[ip_address]</td>
201 <td style='white-space:pre;'>$d[browser_string]</td>
202 </tr>";
203 }
204 $petition->query("insert into follow_up (name, email, php_session, petition_id, date_sent) values ('$name','$email','$php_session_id','$_GET[follow_up]','".date('Y-m-d')."') ");
205 $petition->query("update presign set presign_status = 'DONE' where php_session_id = '$php_session_id' ");
206 $petition->query("update presign set presign_status = 'DONE' where email_for_follow_up = '$email' ");
207 echo "</table>";
208 }elseif (isset($_GET['VTRID'])){
209 $VTRID = $_GET['VTRID'];
210 $petition_id = $_GET['petition_id'];
211 echo "<h1>Review $VTRID</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";
212 $q = "SELECT * FROM signatures where VTRID = '$VTRID' and signature_status = 'verified' and petition_id = '$petition_id' order by petition_id, id DESC ";
213 $r = $petition->query($q);
214 $i=0;
215 while($d = mysqli_fetch_array($r)){
216 $color = 'white';
217 $pos = strpos($d['date_time_signed'], date('Y-m-d'));
218 if ($pos !== false) {
219 $color= 'yellow';
220 }
221 echo "<tr style='background-color:$color;'>
222 <td><b>$d[date_time_signed]</b></td>
223 <td><a href='?ip_address=$d[ip_address]'>$d[ip_address]</a></td>
224 <td>".id2petition($d['petition_id'])."</td>
225 <td>$d[signed_name_as]</td>
226 <td>$d[signed_name_as_circulator]</td>
227 <td>$d[contact_phone]</td>
228 <td>$d[printed_status]</td>
229 <td><a href='?flag_invalid_signature=$d[id]'>flag invalid signature</a></td>
230 <td><a href='?flag_VTRID=$d[VTRID]'>flag VTRID</a></td>
231 <td><a href='?flag_ip_address=$d[ip_address]'>flag ip address</a></td>
232 <td><a href='?flag_duplicate=$d[id]'>flag duplicate</a></td>
233 <td><a href='?flag_phone=$d[contact_phone]'>contact phone</a></td>
234 <td><a href='?resign_requested=$d[id]'>resign requested</a></td>
235 <td><a href='?bot=$d[id]'>bot</a></td>
236 </tr>";
237 if ($i == 0){
238 js_redirect("analytics.php?flag_duplicate=$d[id]");
239 }
240 $i++;
241 }
242 echo "</table>";
243 die();
244 }
245 ?>
246
247 <h1>Signature Analytics - Server Clock: <?PHP echo date('r');?></h1>
248 <h2>NEVER NEVER NEVER CALL OR TEXT ANYONE - ONLY EMAIL!!!</h2>
249 <h3>SysOp Says: Transparency = Trust</h3>
250 <table>
251
252 <tr>
253 <td valign="top" colspan='2'><?PHP /*
254 <h2>IP Address</h2>
255 <div>Watching for duplicates.</div><ol>
256 <?PHP
257 $q="SELECT ip_address, petition_id,VTRID, COUNT(*) as count FROM signatures where signature_status = 'verified' group by ip_address, petition_id, VTRID";
258 $r = $petition->query($q);
259 while($d = mysqli_fetch_array($r)){
260 if ($d['count'] > 1){
261 echo "<li><a href='?ip_address=$d[ip_address]&petition_id=$d[petition_id]'>$d[ip_address]</a> ".id2petition($d['petition_id'])." <b>$d[count]</b> $d[signed_name_as]</li>";
262 }
263 }
264 ?></ol>
265 </td><td valign="top"> */ ?>
266 <h2>VTRID</h2>
267 <div>Watching for duplicates.</div><ol>
268 <?PHP
269 $q="SELECT VTRID, petition_id, COUNT(*) as count FROM signatures where signature_status = 'verified' group by VTRID, petition_id";
270 $r = $petition->query($q);
271 $i=0;
272 while($d = mysqli_fetch_array($r)){
273 if ($d['count'] > 1){
274 echo "<li><a href='?VTRID=$d[VTRID]&petition_id=$d[petition_id]'>$d[VTRID]</a> ".id2petition($d['petition_id'])." <b>$d[count]</b> $d[signed_name_as]</li>";
275 if ($i == 0){
276 js_redirect("analytics.php?VTRID=$d[VTRID]&petition_id=$d[petition_id]");
277 }
278 $i++;
279 }
280
281 }
282 ?></ol>
283 </td></tr>
284
285
286 <tr>
287 <td valign="top" colspan='2'>
288 <h2>Pre-Sign</h2>
289 <div>Follow up requested - never signed.</div>
290 <form method='GET'><input name='email'><input type='submit' value='SEARCH E-MAIL'></form><table>
291 <?PHP
292 $q="SELECT distinct php_session_id FROM presign where presign_status = 'NEW' and email_for_follow_up <> '' order by id";
293 $r = $petition->query($q);
294 while($d = mysqli_fetch_array($r)){
295 $q2="SELECT * FROM presign where php_session_id = '$d[php_session_id]' order by id desc";
296 $r2 = $petition->query($q2);
297 $d2 = mysqli_fetch_array($r2);
298 $sig = '';
299 if ($d2['name'] != ''){
300 $q3 = "SELECT date_time_signed FROM signatures where signed_name_as = '$d2[name]'";
301 $r3 = $petition->query($q3);
302 $d3 = mysqli_fetch_array($r3);
303 if ($d3['date_time_signed'] != ''){
304 $sig = "<b><a href='?sign_email=$d2[email_for_follow_up]'>SIGNATURE $d3[date_time_signed]</a></b><br>";
305 js_redirect("analytics.php?sign_email=$d2[email_for_follow_up]");
306 }
307 }
308 $presig='';
309 $q4="SELECT * FROM presign where email_for_follow_up = '$d2[email_for_follow_up]' and php_page like '/sign.php%'";
310 $r4 = $petition->query($q4);
311 $d4 = mysqli_fetch_array($r4);
312 if ($d4['action_on']){
313 $presig = "<b><a href='?sign_email=$d2[email_for_follow_up]'>PRESIG $d4[action_on]</a></b><br>";
314 js_redirect("analytics.php?sign_email=$d2[email_for_follow_up]");
315 }
316 $invite_error='';
317 $q4="SELECT * FROM presign where email_for_follow_up = '$d2[email_for_follow_up]' and invite_error <> '' ";
318 $r4 = $petition->query($q4);
319 $d4 = mysqli_fetch_array($r4);
320 if ($d4['invite_error'] != ''){
321 $invite_error = "<b><a href='?clear_email=$d2[email_for_follow_up]'>$d4[invite_error]</a></b><br>";
322 js_redirect("analytics.php?clear_email=$d2[email_for_follow_up]");
323 }
324 $php_session_id = $d2['php_session_id'];
325 echo "<tr><td><a href='?php_session_id=$php_session_id'>$d2[action_on]</a></td><td>$presig $sig $invite_error</td>
326 <td>$d2[name]</td><td><a href='?email=$d2[email_for_follow_up]'>$d2[email_for_follow_up]</a></td>
327 <td>".id2petition($d2['petition'])."</td><td>$d2[invite]</td>
328 <td><a href='?php_session_id=$php_session_id&follow_up=X'>General</a>
329 - <a href='?php_session_id=$php_session_id&follow_up=1'>MGP</a>
330 - <a href='?php_session_id=$php_session_id&follow_up=2'>MLP</a>
331 - <a href='?php_session_id=$php_session_id&follow_up=3'>BTEC</a>
332 - <a href='?php_session_id=$php_session_id&follow_up=7'>PG</a>
333 - <a href='?php_session_id=$php_session_id&follow_up=8'>Ivey</a></td></tr>";
334 if( $presig == '' && $invite_error == '' && $sig == '' ){
335 if ($d2['invite'] == 'Ivey'){
336 js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=8");
337 }
338 }
339 }
340 ?></table>
341 </td>
342 </tr>
343 <tr>
344 <td valign="top" colspan='2'>
345 <h2>Signatures</h2>
346 <div>Last 10</div><ol>
347 <?PHP
348 $q="SELECT * FROM signatures where signature_status = 'verified' order by id desc limit 0, 10";
349 $r = $petition->query($q);
350 while($d = mysqli_fetch_array($r)){
351 echo "<li>$d[date_time_signed] ".id2petition($d['petition_id'])." $d[signed_name_as]</li>";
352 }
353 ?></ol>
354 </td>
355
356 </tr>
357 <tr><td valign="top">
358 <h2>VTRID Bugs</h2>
359 <div>Watching for 0</div><ol>
360 <?PHP
361 $q="SELECT * FROM signatures where VTRID = '0' and signature_status <> 'bot' and signature_status <> 'flag_invalid_signature' and signature_status <> 'resign_requested'";
362 $r = $petition->query($q);
363 while($d = mysqli_fetch_array($r)){
364 echo "<li>$d[date_time_signed] <a href='?ip_address=$d[ip_address]'>$d[ip_address]</a> <a target='_Blank' href='https://ipinfo.io/$d[ip_address]'>IP INFO</a> $d[petition_id] $d[signed_name_as]</li>";
365 }
366 ?></ol>
367 </td><td valign="top">
368 <h2>Petition ID Bugs</h2>
369 <div>Watching for 0</div><ol>
370 <?PHP
371 $q="SELECT * FROM signatures where (petition_id = '0' or petition_id = '') and signature_status <> 'bot' and signature_status <> 'flag_invalid_signature' and signature_status <> 'resign_requested'";
372 $r = $petition->query($q);
373 while($d = mysqli_fetch_array($r)){
374 echo "<li>$d[date_time_signed] <a href='?ip_address=$d[ip_address]'>$d[ip_address]</a> <a target='_Blank' href='https://ipinfo.io/$d[ip_address]'>IP INFO</a> $d[petition_id] $d[signed_name_as]</li>";
375 }
376 ?></ol>
377 </td></tr><tr><td valign="top">
378 <?PHP ob_start(); ?>
379 <h2>resign_requested</h2>
380 <div>These are most likely from early bugs</div><ol>
381 <?PHP
382 $q="SELECT * FROM signatures where signature_status = 'resign_requested' order by ip_address";
383 $r = $petition->query($q);
384 $show = 0;
385 while($d = mysqli_fetch_array($r)){
386 $show = 1;
387 echo "<li>$d[date_time_signed] <a href='?ip_address=$d[ip_address]'>$d[ip_address]</a> <a target='_Blank' href='https://ipinfo.io/$d[ip_address]'>IP INFO</a> <a href='?VTRID=$d[VTRID]'>$d[VTRID]</a> $d[petition_id] $d[signed_name_as]</li>";
388 }
389 ?></ol>
390 <?PHP $html = ob_get_clean(); if ( $show == 1 ){ echo $html; } ?>
391 </td>
392
393 <td valign="top">
394 <?PHP ob_start(); ?>
395 <h2>bots</h2>
396 <div>These are bots on the site.</div><ol>
397 <?PHP
398 $q="SELECT * FROM signatures where signature_status = 'bot' order by ip_address";
399 $r = $petition->query($q);
400 $show = 0;
401 while($d = mysqli_fetch_array($r)){
402 $show = 1;
403 echo "<li>$d[date_time_signed] <a href='?ip_address=$d[ip_address]'>$d[ip_address]</a> <a target='_Blank' href='https://ipinfo.io/$d[ip_address]'>IP INFO</a> <a href='?VTRID=$d[VTRID]'>$d[VTRID]</a> $d[petition_id] $d[signed_name_as]</li>";
404 }
405 ?></ol>
406 <?PHP $html = ob_get_clean(); if ( $show == 1 ){ echo $html; } ?>
407
408 </td>
409
410
411 </tr>
412
413 </table>
414
415
416 <?PHP
417 include_once('footer.php');
418 ?>