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