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 while($d = mysqli_fetch_array($r)){
215 $color = 'white';
216 $pos = strpos($d['date_time_signed'], date('Y-m-d'));
217 if ($pos !== false) {
218 $color= 'yellow';
219 }
220 echo "<tr style='background-color:$color;'>
221 <td><b>$d[date_time_signed]</b></td>
222 <td><a href='?ip_address=$d[ip_address]'>$d[ip_address]</a></td>
223 <td>".id2petition($d['petition_id'])."</td>
224 <td>$d[signed_name_as]</td>
225 <td>$d[signed_name_as_circulator]</td>
226 <td>$d[contact_phone]</td>
227 <td>$d[printed_status]</td>
228 <td><a href='?flag_invalid_signature=$d[id]'>flag invalid signature</a></td>
229 <td><a href='?flag_VTRID=$d[VTRID]'>flag VTRID</a></td>
230 <td><a href='?flag_ip_address=$d[ip_address]'>flag ip address</a></td>
231 <td><a href='?flag_duplicate=$d[id]'>flag duplicate</a></td>
232 <td><a href='?flag_phone=$d[contact_phone]'>contact phone</a></td>
233 <td><a href='?resign_requested=$d[id]'>resign requested</a></td>
234 <td><a href='?bot=$d[id]'>bot</a></td>
235 </tr>";
236 }
237 echo "</table>";
238 die();
239 }
240 ?>
241
242 <h1>Signature Analytics - Server Clock: <?PHP echo date('r');?></h1>
243 <h2>NEVER NEVER NEVER CALL OR TEXT ANYONE - ONLY EMAIL!!!</h2>
244 <h3>SysOp Says: Transparency = Trust</h3>
245 <table>
246
247 <tr>
248 <td valign="top" colspan='2'><?PHP /*
249 <h2>IP Address</h2>
250 <div>Watching for duplicates.</div><ol>
251 <?PHP
252 $q="SELECT ip_address, petition_id,VTRID, COUNT(*) as count FROM signatures where signature_status = 'verified' group by ip_address, petition_id, VTRID";
253 $r = $petition->query($q);
254 while($d = mysqli_fetch_array($r)){
255 if ($d['count'] > 1){
256 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>";
257 }
258 }
259 ?></ol>
260 </td><td valign="top"> */ ?>
261 <h2>VTRID</h2>
262 <div>Watching for duplicates.</div><ol>
263 <?PHP
264 $q="SELECT VTRID, petition_id, COUNT(*) as count FROM signatures where signature_status = 'verified' group by VTRID, petition_id";
265 $r = $petition->query($q);
266 $i=0;
267 while($d = mysqli_fetch_array($r)){
268 if ($d['count'] > 1){
269 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>";
270 if ($i == 0){
271 js_redirect("analytics.php?VTRID=$d[VTRID]&petition_id=$d[petition_id]");
272 }
273 $i++;
274 }
275
276 }
277 ?></ol>
278 </td></tr>
279
280
281 <tr>
282 <td valign="top" colspan='2'>
283 <h2>Pre-Sign</h2>
284 <div>Follow up requested - never signed.</div>
285 <form method='GET'><input name='email'><input type='submit' value='SEARCH E-MAIL'></form><table>
286 <?PHP
287 $q="SELECT distinct php_session_id FROM presign where presign_status = 'NEW' and email_for_follow_up <> '' order by id";
288 $r = $petition->query($q);
289 while($d = mysqli_fetch_array($r)){
290 $q2="SELECT * FROM presign where php_session_id = '$d[php_session_id]' order by id desc";
291 $r2 = $petition->query($q2);
292 $d2 = mysqli_fetch_array($r2);
293 $sig = '';
294 if ($d2['name'] != ''){
295 $q3 = "SELECT date_time_signed FROM signatures where signed_name_as = '$d2[name]'";
296 $r3 = $petition->query($q3);
297 $d3 = mysqli_fetch_array($r3);
298 if ($d3['date_time_signed'] != ''){
299 $sig = "<b><a href='?sign_email=$d2[email_for_follow_up]'>SIGNATURE $d3[date_time_signed]</a></b><br>";
300 }
301 }
302 $presig='';
303 $q4="SELECT * FROM presign where email_for_follow_up = '$d2[email_for_follow_up]' and php_page like '/sign.php%'";
304 $r4 = $petition->query($q4);
305 $d4 = mysqli_fetch_array($r4);
306 if ($d4['action_on']){
307 $presig = "<b><a href='?sign_email=$d2[email_for_follow_up]'>PRESIG $d4[action_on]</a></b><br>";
308 }
309 $invite_error='';
310 $q4="SELECT * FROM presign where email_for_follow_up = '$d2[email_for_follow_up]' and invite_error <> '' ";
311 $r4 = $petition->query($q4);
312 $d4 = mysqli_fetch_array($r4);
313 if ($d4['invite_error'] != ''){
314 $invite_error = "<b><a href='?clear_email=$d2[email_for_follow_up]'>$d4[invite_error]</a></b><br>";
315 }
316 $php_session_id = $d2['php_session_id'];
317 echo "<tr><td><a href='?php_session_id=$php_session_id'>$d2[action_on]</a></td><td>$presig $sig $invite_error</td><td>$d2[name]</td><td><a href='?email=$d2[email_for_follow_up]'>$d2[email_for_follow_up]</a></td><td>".id2petition($d2['petition'])."</td><td>$d2[invite]</td>
318 <td><a href='?php_session_id=$php_session_id&follow_up=X'>General</a>
319 - <a href='?php_session_id=$php_session_id&follow_up=1'>MGP</a>
320 - <a href='?php_session_id=$php_session_id&follow_up=2'>MLP</a>
321 - <a href='?php_session_id=$php_session_id&follow_up=3'>BTEC</a>
322 - <a href='?php_session_id=$php_session_id&follow_up=7'>PG</a>
323 - <a href='?php_session_id=$php_session_id&follow_up=8'>Ivey</a></td></tr>";
324 }
325 ?></table>
326 </td>
327 </tr>
328 <tr>
329 <td valign="top" colspan='2'>
330 <h2>Signatures</h2>
331 <div>Last 10</div><ol>
332 <?PHP
333 $q="SELECT * FROM signatures where signature_status = 'verified' order by id desc limit 0, 10";
334 $r = $petition->query($q);
335 while($d = mysqli_fetch_array($r)){
336 echo "<li>$d[date_time_signed] ".id2petition($d['petition_id'])." $d[signed_name_as]</li>";
337 }
338 ?></ol>
339 </td>
340
341 </tr>
342 <tr><td valign="top">
343 <h2>VTRID Bugs</h2>
344 <div>Watching for 0</div><ol>
345 <?PHP
346 $q="SELECT * FROM signatures where VTRID = '0' and signature_status <> 'bot' and signature_status <> 'flag_invalid_signature' and signature_status <> 'resign_requested'";
347 $r = $petition->query($q);
348 while($d = mysqli_fetch_array($r)){
349 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>";
350 }
351 ?></ol>
352 </td><td valign="top">
353 <h2>Petition ID Bugs</h2>
354 <div>Watching for 0</div><ol>
355 <?PHP
356 $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'";
357 $r = $petition->query($q);
358 while($d = mysqli_fetch_array($r)){
359 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>";
360 }
361 ?></ol>
362 </td></tr><tr><td valign="top">
363 <?PHP ob_start(); ?>
364 <h2>resign_requested</h2>
365 <div>These are most likely from early bugs</div><ol>
366 <?PHP
367 $q="SELECT * FROM signatures where signature_status = 'resign_requested' order by ip_address";
368 $r = $petition->query($q);
369 $show = 0;
370 while($d = mysqli_fetch_array($r)){
371 $show = 1;
372 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>";
373 }
374 ?></ol>
375 <?PHP $html = ob_get_clean(); if ( $show == 1 ){ echo $html; } ?>
376 </td>
377
378 <td valign="top">
379 <?PHP ob_start(); ?>
380 <h2>bots</h2>
381 <div>These are bots on the site.</div><ol>
382 <?PHP
383 $q="SELECT * FROM signatures where signature_status = 'bot' order by ip_address";
384 $r = $petition->query($q);
385 $show = 0;
386 while($d = mysqli_fetch_array($r)){
387 $show = 1;
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> <a href='?VTRID=$d[VTRID]'>$d[VTRID]</a> $d[petition_id] $d[signed_name_as]</li>";
389 }
390 ?></ol>
391 <?PHP $html = ob_get_clean(); if ( $show == 1 ){ echo $html; } ?>
392
393 </td>
394
395
396 </tr>
397
398 </table>
399
400
401 <?PHP
402 include_once('footer.php');
403 ?>