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