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