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