Update LPMD.php
[clinton/MarylandElectronicPetitionSignature.git] / admin / index.php
1 <?PHP
2 include_once('../slack.php');
3 include_once('security.php');
4 if ($_COOKIE['level'] == 'user'){
5 slack_general('ADMIN: Redirect User Home ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
6 header('Location: user_home.php');
7 }
8 if ($_COOKIE['level'] == 'manager'){
9 slack_general('ADMIN: Redirect Manager Home ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
10 header('Location: manager_home.php');
11 }
12 include_once('header.php');
13 if ($_POST['name']){
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);
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');
33 }
34 if(isset($_GET['approve'])){
35 $id = $_GET['approve'];
36 $petition->query("update petitions set admin_status = 'approved' where petition_id = '$id' ");
37 }
38 slack_general('ADMIN: Home Page Loaded ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
39 ?>
40
41 <h1>Admin Home</h1>
42 <div id="chartContainer1" style="height: 400px; width: 100%; margin: 0px auto;"></div>
43 <div id="chartContainer2" style="height: 400px; width: 100%; margin: 0px auto;"></div>
44 <h1>Users</h1>
45 <form method='post'>
46 <table>
47 <tr><td>Name</td><td><input name='name' required></td></tr>
48 <tr><td>E-Mail</td><td><input name='email' required></td></tr>
49 <tr><td>Security Level</td><td><input name='sec_level' required></td></tr>
50 <tr><td>Group ID</td><td><input name='group_id' required></td></tr>
51 <tr><td>Petition ID</td><td><input name='petition_id' required></td></tr>
52 <tr><td></td><td><input type='submit' value='New User'></td></tr>
53 </table>
54 </form>
55 <?PHP
56 $q="SELECT * FROM users";
57 $r = $petition->query($q);
58 while($d = mysqli_fetch_array($r)){
59 $alert='';
60 if ($d[pass] == ''){
61 $alert='NEEDS PASSWORD RESET';
62 }
63 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>";
64 }
65 ?>
66
67 <h1>New Petitions</h1>
68 <?PHP
69 $q="SELECT * FROM petitions where admin_status='new'";
70 $r = $petition->query($q);
71 while($d = mysqli_fetch_array($r)){
72 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>";
73 }
74 ?>
75
76
77 <h1>Approved Petitions</h1>
78 <?PHP
79 $q="SELECT * FROM petitions where admin_status = 'approved'";
80 $r = $petition->query($q);
81 while($d = mysqli_fetch_array($r)){
82 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>";
83 }
84 ?>
85
86
87 <h1>Groups</h1>
88 <?PHP
89 $q="SELECT * FROM groups";
90 $r = $petition->query($q);
91 while($d = mysqli_fetch_array($r)){
92 echo "<li>$d[id] $d[name]</li>";
93 }
94 ?>
95
96
97
98
99 <h1>Website</h1>
100 <?PHP
101 $q="SELECT * FROM website_text";
102 $r = $petition->query($q);
103 while($d = mysqli_fetch_array($r)){
104 echo "<li>$d[id] $d[text_title]</li>";
105 }
106 ?>
107
108 <?PHP
109 $pID = 1;
110 //echo "<div id=\"chartContainer$pID\" style=\"height: 400px; width: 100%; margin: 0px auto;\"></div>";
111 $chart='';
112 $chart2='';
113 $chart3='';
114 $q3 = "SELECT just_date FROM signatures where just_date <> '0000-00-00' group by just_date";
115 //echo "<li>$q3</li>";
116 $r3 = $petition->query($q3);
117 $total=0;
118 $total2=0;
119 $goal = $d['signature_goal'];
120 if ($goal == 0){
121 $goal = 10000;
122 }
123 $trader_sma_timePeriod=0;
124 while ($d3 = mysqli_fetch_array($r3)){
125 $just_date = $d3['just_date'];
126 $q2 = "SELECT * FROM signatures where just_date = '$just_date' and signature_status = 'verified' ";
127 //echo "<li>$q2</li>";
128 $r2 = $petition->query($q2);
129 $count = mysqli_num_rows($r2);
130 $chart .= '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
131 $total = $total + intval($count);
132 $chart2 .= '{ label: "'.$just_date.'", y: '.intval($total).' }, ';
133 $goal = $goal - intval($count);
134 $chart3 .= '{ label: "'.$just_date.'", y: '.intval($goal).' }, ';
135 $q2 = "SELECT * FROM follow_up where date_sent = '$just_date' ";
136 $r2 = $petition->query($q2);
137 $count = mysqli_num_rows($r2);
138 $chart4 .= '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
139 $total2 = $total2 + $count;
140 $chart5 .= '{ label: "'.$just_date.'", y: '.intval($total2).' }, ';
141
142 $q2 = "SELECT * FROM presign where only_date = '$just_date' ";
143 $r2 = $petition->query($q2);
144 $count = mysqli_num_rows($r2);
145 if($count > 0){ // start this graph when there is data
146 $chart6 .= '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
147 // graph latest sma
148 $trader_sma_real[] = intval($count);
149 $trader_sma_timePeriod++;
150 $trader_sma = trader_sma($trader_sma_real,$trader_sma_timePeriod);
151 //print_r($trader_sma);
152 $the_index = $trader_sma_timePeriod - 1;
153 $this_sma = $trader_sma[$the_index]; // should be last value?
154 $chart7 .= '{ label: "'.$just_date.'", y: '.intval($this_sma).' }, ';
155 }
156 }
157
158 $chart = rtrim(trim($chart), ",");
159 $chart2 = rtrim(trim($chart2), ",");
160 $chart3 = rtrim(trim($chart3), ",");
161 $chart4 = rtrim(trim($chart4), ",");
162 $chart5 = rtrim(trim($chart5), ",");
163 $chart6 = rtrim(trim($chart6), ",");
164 $chart7 = rtrim(trim($chart7), ",");
165
166
167
168 ob_start(); ?>
169
170 var chart<?PHP echo $pID;?> = new CanvasJS.Chart("chartContainer<?PHP echo $pID;?>", {
171 theme:"light2",
172 animationEnabled: true,
173 exportEnabled: true,
174 title:{
175 text: "MD-Petition.com Signature Tracker"
176 },
177 axisY :{
178 includeZero: false,
179 title: "Number of Signatures",
180 suffix: "",
181 scaleBreaks: {
182 autoCalculate: true
183 }
184 },
185 toolTip: {
186 shared: "true"
187 },
188 legend:{
189 cursor:"pointer",
190 itemclick : toggleDataSeries
191 },
192 data: [{
193 type: "line",
194 visible: true,
195 showInLegend: true,
196 yValueFormatString: "#####",
197 name: "Total Signatures Count",
198 dataPoints: [
199 <?PHP echo $chart2; ?>
200 ]
201 },{
202 type: "line",
203 visible: true,
204 showInLegend: true,
205 yValueFormatString: "#####",
206 name: "Total Follow Up Count",
207 dataPoints: [
208 <?PHP echo $chart5; ?>
209 ]
210 },{
211 type: "column",
212 visible: true,
213 showInLegend: true,
214 yValueFormatString: "#####",
215 name: "New Daily Signatures",
216 dataPoints: [
217 <?PHP echo $chart; ?>
218 ]
219 },{
220 type: "column",
221 visible: true,
222 showInLegend: true,
223 yValueFormatString: "#####",
224 name: "Follow Up Sent",
225 dataPoints: [
226 <?PHP echo $chart4; ?>
227 ]
228 }]
229 }
230
231
232 );
233 chart<?PHP echo $pID; $pID = $pID + 1; ?>.render();
234
235 var chart<?PHP echo $pID;?> = new CanvasJS.Chart("chartContainer<?PHP echo $pID;?>", {
236 theme:"light2",
237 animationEnabled: true,
238 exportEnabled: true,
239 title:{
240 text: "MD-Petition.com Web Monitor"
241 },
242 axisY :{
243 includeZero: false,
244 title: "Number of Pages Loaded",
245 suffix: "",
246 scaleBreaks: {
247 autoCalculate: true
248 }
249 },
250 toolTip: {
251 shared: "true"
252 },
253 legend:{
254 cursor:"pointer",
255 itemclick : toggleDataSeries
256 },
257 data: [{
258 type: "line",
259 visible: true,
260 showInLegend: true,
261 yValueFormatString: "#####",
262 name: "Web Activity",
263 dataPoints: [
264 <?PHP echo $chart6; ?>
265 ]
266 },{
267 type: "line",
268 visible: true,
269 showInLegend: true,
270 yValueFormatString: "#####",
271 name: "Simple Moving Average",
272 dataPoints: [
273 <?PHP echo $chart7; ?>
274 ]
275 }]
276 }
277
278
279 );
280 chart<?PHP echo $pID;?>.render();
281
282 <?PHP $javascript .= ob_get_clean(); ?>
283
284
285
286 <script>
287 window.onload = function () {
288
289 <?PHP echo $javascript;?>
290
291 function toggleDataSeries(e) {
292 if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible ){
293 e.dataSeries.visible = false;
294 } else {
295 e.dataSeries.visible = true;
296 }
297 chart.render();
298 }
299
300 }
301 </script>
302 <script src="../files/canvasjs.min.js"></script>
303 <?PHP
304
305
306 include_once('footer.php');
307 ?>