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