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