Update index.php
[clinton/MarylandElectronicPetitionSignature.git] / admin / index.php
CommitLineData
756271d6 1<?PHP
f628bd2d 2include_once('../slack.php');
756271d6 3include_once('security.php');
f628bd2d
PM
4if ($_COOKIE['level'] == 'user'){
5 slack_general('ADMIN: Redirect User Home ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
50f53cd0 6 header('Location: user_home.php');
f628bd2d
PM
7}
8if ($_COOKIE['level'] == 'manager'){
9 slack_general('ADMIN: Redirect Manager Home ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
50f53cd0 10 header('Location: manager_home.php');
f628bd2d 11}
756271d6 12include_once('header.php');
6621d202 13if ($_POST['name']){
65583de7
PM
14 $name = $petition->real_escape_string($_POST['name']);
15 $email = $petition->real_escape_string($_POST['email']);
16 $sec_level = $petition->real_escape_string($_POST['sec_level']);
17 $group_id = $petition->real_escape_string($_POST['group_id']);
18 $petition_id = $petition->real_escape_string($_POST['petition_id']);
19 $q = "insert into users (name, email, sec_level, group_id, petition_id) values ('$name','$email','$sec_level','$group_id','$petition_id') ";
20 $petition->query($q);
6621d202
PM
21 slack_general_admin('SQL: '.$q,'md-petition-signed');
22 include_once('../email.php');
23 $pass = rand(1000,9999);
24 $salt = md5(rand(1000,9999));
25 $hash = md5($pass.$salt);
26 $encrypted = $hash.':'.$salt;
27 $subject = 'MD Petition Login';
28 $body = 'Login with '.$email.' and your new password '.$pass.' at https://www.md-petition.com/admin/login.php';
29 meps_mail($email,$body,$subject);
30 $petition->query("update users set pass = '$encrypted' WHERE email = '$email'");
31 echo "<h1>Password has been Sent.</h1>";
32 slack_general_admin('DEBUG: '.$body,'md-petition-signed');
65583de7 33}
3e0665a6
PM
34if(isset($_GET['approve'])){
35 $id = $_GET['approve'];
36 $petition->query("update petitions set admin_status = 'approved' where petition_id = '$id' ");
37}
56d09719 38slack_general('ADMIN: Home Page Loaded ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
756271d6
PM
39?>
40
2f29676b 41<h1>Admin Home</h1>
d5f7c1e8 42<div id="chartContainer1" style="height: 400px; width: 100%; margin: 0px auto;"></div>
171693e1 43<div id="chartContainer2" style="height: 400px; width: 100%; margin: 0px auto;"></div>
35b8e3c4 44
54915493 45<table><tr><td valign='top'>
35b8e3c4
PM
46<h2>Admin Sessions</h2>
47<div>Last 50</div><ol>
48<?PHP
4e6e0b55 49$q="SELECT * FROM admin_sessions where username <> 'Patrick McGuire' ORDER BY id DESC LIMIT 50";
35b8e3c4
PM
50$r = $petition->query($q);
51while($d = mysqli_fetch_array($r)){
9caa594a 52 echo "<li title='$d[action_on]'>$d[ip] $d[username] $d[php_page]</li>";
35b8e3c4
PM
53}
54?></ol>
55
54915493 56 </td><td valign='top'>
35b8e3c4
PM
57
58 <h2>User Sessions</h2>
59<div>Last 50</div><ol>
60<?PHP
61$q="SELECT * FROM presign ORDER BY id DESC LIMIT 50";
62$r = $petition->query($q);
63while($d = mysqli_fetch_array($r)){
54915493 64 echo "<li title='$d[action_on]'>$d[php_page] $d[browser_string]</li>";
35b8e3c4
PM
65}
66?></ol>
67
68 </td></tr></table>
69
70
ccb1ab4b 71<h1>Users</h1>
0f0f2090
PM
72<form method='post'>
73 <table>
74 <tr><td>Name</td><td><input name='name' required></td></tr>
75 <tr><td>E-Mail</td><td><input name='email' required></td></tr>
76 <tr><td>Security Level</td><td><input name='sec_level' required></td></tr>
77 <tr><td>Group ID</td><td><input name='group_id' required></td></tr>
78 <tr><td>Petition ID</td><td><input name='petition_id' required></td></tr>
79 <tr><td></td><td><input type='submit' value='New User'></td></tr>
80 </table>
81</form>
f628bd2d
PM
82<?PHP
83$q="SELECT * FROM users";
84$r = $petition->query($q);
85while($d = mysqli_fetch_array($r)){
7240cd63
PM
86 $alert='';
87 if ($d[pass] == ''){
88 $alert='NEEDS PASSWORD RESET';
89 }
0f0f2090 90 echo "<li>ID $d[id] EM $d[email] NM $d[name] GI $d[group_id] PI $d[petition_id] SL $d[sec_level] $alert</li>";
f628bd2d
PM
91}
92?>
ccb1ab4b 93
3e0665a6 94<h1>New Petitions</h1>
ccb1ab4b 95<?PHP
3e0665a6 96$q="SELECT * FROM petitions where admin_status='new'";
ccb1ab4b
PM
97$r = $petition->query($q);
98while($d = mysqli_fetch_array($r)){
3e0665a6 99 echo "<li><a href='?approve=$d[petition_id]'>$d[petition_id] $d[web_short_name] $d[web_color] $d[group_id] $d[petition_name] $d[eligibleVoterListField] $d[eligibleVoterListEquals] $d[eligibleVoterListEnforce]</a></li>";
ccb1ab4b
PM
100}
101?>
102
3e0665a6
PM
103
104<h1>Approved Petitions</h1>
ccb1ab4b 105<?PHP
3e0665a6 106$q="SELECT * FROM petitions where admin_status = 'approved'";
ccb1ab4b
PM
107$r = $petition->query($q);
108while($d = mysqli_fetch_array($r)){
109 echo "<li>$d[petition_id] $d[web_short_name] $d[web_color] $d[group_id] $d[petition_name] $d[eligibleVoterListField] $d[eligibleVoterListEquals] $d[eligibleVoterListEnforce]</li>";
110}
111?>
112
113
3e0665a6
PM
114<h1>Groups</h1>
115<?PHP
116$q="SELECT * FROM groups";
117$r = $petition->query($q);
118while($d = mysqli_fetch_array($r)){
119 echo "<li>$d[id] $d[name]</li>";
120}
121?>
122
123
124
125
ccb1ab4b
PM
126<h1>Website</h1>
127<?PHP
128$q="SELECT * FROM website_text";
129$r = $petition->query($q);
130while($d = mysqli_fetch_array($r)){
131 echo "<li>$d[id] $d[text_title]</li>";
132}
133?>
756271d6 134
d5f7c1e8
PM
135<?PHP
136 $pID = 1;
137 //echo "<div id=\"chartContainer$pID\" style=\"height: 400px; width: 100%; margin: 0px auto;\"></div>";
138 $chart='';
139 $chart2='';
140 $chart3='';
141 $q3 = "SELECT just_date FROM signatures where just_date <> '0000-00-00' group by just_date";
142 //echo "<li>$q3</li>";
143 $r3 = $petition->query($q3);
144 $total=0;
37ae64f8 145 $total2=0;
d5f7c1e8
PM
146 $goal = $d['signature_goal'];
147 if ($goal == 0){
148 $goal = 10000;
149 }
6b41a778 150 $trader_sma_timePeriod=0;
d5f7c1e8
PM
151 while ($d3 = mysqli_fetch_array($r3)){
152 $just_date = $d3['just_date'];
153 $q2 = "SELECT * FROM signatures where just_date = '$just_date' and signature_status = 'verified' ";
154 //echo "<li>$q2</li>";
155 $r2 = $petition->query($q2);
156 $count = mysqli_num_rows($r2);
157 $chart .= '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
158 $total = $total + intval($count);
159 $chart2 .= '{ label: "'.$just_date.'", y: '.intval($total).' }, ';
160 $goal = $goal - intval($count);
161 $chart3 .= '{ label: "'.$just_date.'", y: '.intval($goal).' }, ';
24ceb221
PM
162 $q2 = "SELECT * FROM follow_up where date_sent = '$just_date' ";
163 $r2 = $petition->query($q2);
164 $count = mysqli_num_rows($r2);
bce57d72 165 $chart4 .= '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
37ae64f8
PM
166 $total2 = $total2 + $count;
167 $chart5 .= '{ label: "'.$just_date.'", y: '.intval($total2).' }, ';
5c829bcc 168
9ebbe0da
PM
169 $q2 = "SELECT * FROM presign where only_date = '$just_date' ";
170 $r2 = $petition->query($q2);
171 $count = mysqli_num_rows($r2);
5c829bcc
PM
172 if($count > 0){ // start this graph when there is data
173 $chart6 .= '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
174 // graph latest sma
175 $trader_sma_real[] = intval($count);
176 $trader_sma_timePeriod++;
c9ebe9b0 177 $trader_sma = trader_sma($trader_sma_real,7);
5c829bcc
PM
178 //print_r($trader_sma);
179 $the_index = $trader_sma_timePeriod - 1;
180 $this_sma = $trader_sma[$the_index]; // should be last value?
181 $chart7 .= '{ label: "'.$just_date.'", y: '.intval($this_sma).' }, ';
182 }
d5f7c1e8 183 }
7989abcb 184
d5f7c1e8
PM
185 $chart = rtrim(trim($chart), ",");
186 $chart2 = rtrim(trim($chart2), ",");
187 $chart3 = rtrim(trim($chart3), ",");
24ceb221 188 $chart4 = rtrim(trim($chart4), ",");
37ae64f8 189 $chart5 = rtrim(trim($chart5), ",");
6b41a778 190 $chart6 = rtrim(trim($chart6), ",");
a3764856 191 $chart7 = rtrim(trim($chart7), ",");
6b41a778 192
d5f7c1e8 193
6b41a778 194
d5f7c1e8
PM
195 ob_start(); ?>
196
197 var chart<?PHP echo $pID;?> = new CanvasJS.Chart("chartContainer<?PHP echo $pID;?>", {
198 theme:"light2",
199 animationEnabled: true,
200 exportEnabled: true,
201 title:{
202 text: "MD-Petition.com Signature Tracker"
203 },
204 axisY :{
205 includeZero: false,
206 title: "Number of Signatures",
207 suffix: "",
208 scaleBreaks: {
209 autoCalculate: true
210 }
211 },
212 toolTip: {
213 shared: "true"
214 },
215 legend:{
216 cursor:"pointer",
217 itemclick : toggleDataSeries
218 },
219 data: [{
220 type: "line",
221 visible: true,
222 showInLegend: true,
223 yValueFormatString: "#####",
224 name: "Total Signatures Count",
225 dataPoints: [
226 <?PHP echo $chart2; ?>
227 ]
37ae64f8
PM
228 },{
229 type: "line",
230 visible: true,
231 showInLegend: true,
232 yValueFormatString: "#####",
233 name: "Total Follow Up Count",
234 dataPoints: [
235 <?PHP echo $chart5; ?>
236 ]
d5f7c1e8
PM
237 },{
238 type: "column",
239 visible: true,
240 showInLegend: true,
241 yValueFormatString: "#####",
242 name: "New Daily Signatures",
243 dataPoints: [
244 <?PHP echo $chart; ?>
245 ]
24ceb221
PM
246 },{
247 type: "column",
248 visible: true,
249 showInLegend: true,
250 yValueFormatString: "#####",
37ae64f8 251 name: "Follow Up Sent",
24ceb221
PM
252 dataPoints: [
253 <?PHP echo $chart4; ?>
254 ]
9a99240a
PM
255 }]
256 }
257
258
259 );
260 chart<?PHP echo $pID; $pID = $pID + 1; ?>.render();
261
262 var chart<?PHP echo $pID;?> = new CanvasJS.Chart("chartContainer<?PHP echo $pID;?>", {
263 theme:"light2",
264 animationEnabled: true,
265 exportEnabled: true,
266 title:{
267 text: "MD-Petition.com Web Monitor"
268 },
269 axisY :{
270 includeZero: false,
271 title: "Number of Pages Loaded",
272 suffix: "",
273 scaleBreaks: {
274 autoCalculate: true
275 }
276 },
277 toolTip: {
278 shared: "true"
279 },
280 legend:{
281 cursor:"pointer",
282 itemclick : toggleDataSeries
283 },
284 data: [{
9ebbe0da
PM
285 type: "line",
286 visible: true,
287 showInLegend: true,
288 yValueFormatString: "#####",
289 name: "Web Activity",
290 dataPoints: [
291 <?PHP echo $chart6; ?>
292 ]
14e92e33
PM
293 },{
294 type: "line",
295 visible: true,
296 showInLegend: true,
297 yValueFormatString: "#####",
c9ebe9b0 298 name: "7 Day Simple Moving Average",
14e92e33
PM
299 dataPoints: [
300 <?PHP echo $chart7; ?>
301 ]
d5f7c1e8
PM
302 }]
303 }
304
305
306 );
307 chart<?PHP echo $pID;?>.render();
308
309 <?PHP $javascript .= ob_get_clean(); ?>
310
311
312
3d1d8f71
PM
313<script>
314window.onload = function () {
315
316<?PHP echo $javascript;?>
317
318function toggleDataSeries(e) {
319 if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible ){
320 e.dataSeries.visible = false;
321 } else {
322 e.dataSeries.visible = true;
323 }
324 chart.render();
325}
326
327}
328</script>
28ac92e6 329<script src="../files/canvasjs.min.js"></script>
756271d6 330<?PHP
3d1d8f71 331
d5f7c1e8 332
756271d6
PM
333include_once('footer.php');
334?>