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>
ccb1ab4b 44<h1>Users</h1>
0f0f2090
PM
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>
f628bd2d
PM
55<?PHP
56$q="SELECT * FROM users";
57$r = $petition->query($q);
58while($d = mysqli_fetch_array($r)){
7240cd63
PM
59 $alert='';
60 if ($d[pass] == ''){
61 $alert='NEEDS PASSWORD RESET';
62 }
0f0f2090 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>";
f628bd2d
PM
64}
65?>
ccb1ab4b 66
3e0665a6 67<h1>New Petitions</h1>
ccb1ab4b 68<?PHP
3e0665a6 69$q="SELECT * FROM petitions where admin_status='new'";
ccb1ab4b
PM
70$r = $petition->query($q);
71while($d = mysqli_fetch_array($r)){
3e0665a6 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>";
ccb1ab4b
PM
73}
74?>
75
3e0665a6
PM
76
77<h1>Approved Petitions</h1>
ccb1ab4b 78<?PHP
3e0665a6 79$q="SELECT * FROM petitions where admin_status = 'approved'";
ccb1ab4b
PM
80$r = $petition->query($q);
81while($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
3e0665a6
PM
87<h1>Groups</h1>
88<?PHP
89$q="SELECT * FROM groups";
90$r = $petition->query($q);
91while($d = mysqli_fetch_array($r)){
92 echo "<li>$d[id] $d[name]</li>";
93}
94?>
95
96
97
98
ccb1ab4b
PM
99<h1>Website</h1>
100<?PHP
101$q="SELECT * FROM website_text";
102$r = $petition->query($q);
103while($d = mysqli_fetch_array($r)){
104 echo "<li>$d[id] $d[text_title]</li>";
105}
106?>
756271d6 107
d5f7c1e8
PM
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;
37ae64f8 118 $total2=0;
d5f7c1e8
PM
119 $goal = $d['signature_goal'];
120 if ($goal == 0){
121 $goal = 10000;
122 }
6b41a778 123 $trader_sma_timePeriod=0;
d5f7c1e8
PM
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).' }, ';
24ceb221
PM
135 $q2 = "SELECT * FROM follow_up where date_sent = '$just_date' ";
136 $r2 = $petition->query($q2);
137 $count = mysqli_num_rows($r2);
bce57d72 138 $chart4 .= '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
37ae64f8
PM
139 $total2 = $total2 + $count;
140 $chart5 .= '{ label: "'.$just_date.'", y: '.intval($total2).' }, ';
9ebbe0da
PM
141 $q2 = "SELECT * FROM presign where only_date = '$just_date' ";
142 $r2 = $petition->query($q2);
143 $count = mysqli_num_rows($r2);
144 $chart6 .= '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
6b41a778
PM
145 // graph latest sma
146 $trader_sma_real[] = intval($count);
147 $trader_sma_timePeriod++;
148 $trader_sma = trader_sma($trader_sma_real,$trader_sma_timePeriod);
149 $this_sma = $trader_sma[$trader_sma_timePeriod]; // should be last value?
150 $chart7 .= '{ label: "'.$just_date.'", y: '.intval($this_sma).' }, ';
d5f7c1e8 151 }
a3764856 152 print_r($trader_sma);
d5f7c1e8
PM
153 $chart = rtrim(trim($chart), ",");
154 $chart2 = rtrim(trim($chart2), ",");
155 $chart3 = rtrim(trim($chart3), ",");
24ceb221 156 $chart4 = rtrim(trim($chart4), ",");
37ae64f8 157 $chart5 = rtrim(trim($chart5), ",");
6b41a778 158 $chart6 = rtrim(trim($chart6), ",");
a3764856 159 $chart7 = rtrim(trim($chart7), ",");
6b41a778 160
d5f7c1e8 161
6b41a778 162
d5f7c1e8
PM
163 ob_start(); ?>
164
165 var chart<?PHP echo $pID;?> = new CanvasJS.Chart("chartContainer<?PHP echo $pID;?>", {
166 theme:"light2",
167 animationEnabled: true,
168 exportEnabled: true,
169 title:{
170 text: "MD-Petition.com Signature Tracker"
171 },
172 axisY :{
173 includeZero: false,
174 title: "Number of Signatures",
175 suffix: "",
176 scaleBreaks: {
177 autoCalculate: true
178 }
179 },
180 toolTip: {
181 shared: "true"
182 },
183 legend:{
184 cursor:"pointer",
185 itemclick : toggleDataSeries
186 },
187 data: [{
188 type: "line",
189 visible: true,
190 showInLegend: true,
191 yValueFormatString: "#####",
192 name: "Total Signatures Count",
193 dataPoints: [
194 <?PHP echo $chart2; ?>
195 ]
37ae64f8
PM
196 },{
197 type: "line",
198 visible: true,
199 showInLegend: true,
200 yValueFormatString: "#####",
201 name: "Total Follow Up Count",
202 dataPoints: [
203 <?PHP echo $chart5; ?>
204 ]
d5f7c1e8
PM
205 },{
206 type: "column",
207 visible: true,
208 showInLegend: true,
209 yValueFormatString: "#####",
210 name: "New Daily Signatures",
211 dataPoints: [
212 <?PHP echo $chart; ?>
213 ]
24ceb221
PM
214 },{
215 type: "column",
216 visible: true,
217 showInLegend: true,
218 yValueFormatString: "#####",
37ae64f8 219 name: "Follow Up Sent",
24ceb221
PM
220 dataPoints: [
221 <?PHP echo $chart4; ?>
222 ]
9a99240a
PM
223 }]
224 }
225
226
227 );
228 chart<?PHP echo $pID; $pID = $pID + 1; ?>.render();
229
230 var chart<?PHP echo $pID;?> = new CanvasJS.Chart("chartContainer<?PHP echo $pID;?>", {
231 theme:"light2",
232 animationEnabled: true,
233 exportEnabled: true,
234 title:{
235 text: "MD-Petition.com Web Monitor"
236 },
237 axisY :{
238 includeZero: false,
239 title: "Number of Pages Loaded",
240 suffix: "",
241 scaleBreaks: {
242 autoCalculate: true
243 }
244 },
245 toolTip: {
246 shared: "true"
247 },
248 legend:{
249 cursor:"pointer",
250 itemclick : toggleDataSeries
251 },
252 data: [{
9ebbe0da
PM
253 type: "line",
254 visible: true,
255 showInLegend: true,
256 yValueFormatString: "#####",
257 name: "Web Activity",
258 dataPoints: [
259 <?PHP echo $chart6; ?>
260 ]
14e92e33
PM
261 },{
262 type: "line",
263 visible: true,
264 showInLegend: true,
265 yValueFormatString: "#####",
266 name: "Simple Moving Average",
267 dataPoints: [
268 <?PHP echo $chart7; ?>
269 ]
d5f7c1e8
PM
270 }]
271 }
272
273
274 );
275 chart<?PHP echo $pID;?>.render();
276
277 <?PHP $javascript .= ob_get_clean(); ?>
278
279
280
3d1d8f71
PM
281<script>
282window.onload = function () {
283
284<?PHP echo $javascript;?>
285
286function toggleDataSeries(e) {
287 if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible ){
288 e.dataSeries.visible = false;
289 } else {
290 e.dataSeries.visible = true;
291 }
292 chart.render();
293}
294
295}
296</script>
28ac92e6 297<script src="../files/canvasjs.min.js"></script>
756271d6 298<?PHP
3d1d8f71 299
d5f7c1e8 300
756271d6
PM
301include_once('footer.php');
302?>