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