| 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 | |
| 45 | <table><tr><td valign='top'> |
| 46 | <h2>Admin Sessions</h2> |
| 47 | <div>Last 50</div><ol> |
| 48 | <?PHP |
| 49 | $q="SELECT * FROM admin_sessions where username <> 'Patrick McGuire' ORDER BY id DESC LIMIT 50"; |
| 50 | $r = $petition->query($q); |
| 51 | while($d = mysqli_fetch_array($r)){ |
| 52 | echo "<li title='$d[action_on]'>$d[ip] $d[username] $d[php_page]</li>"; |
| 53 | } |
| 54 | ?></ol> |
| 55 | |
| 56 | </td><td valign='top'> |
| 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); |
| 63 | while($d = mysqli_fetch_array($r)){ |
| 64 | echo "<li title='$d[action_on]'>$d[php_page] $d[browser_string]</li>"; |
| 65 | } |
| 66 | ?></ol> |
| 67 | |
| 68 | </td></tr></table> |
| 69 | |
| 70 | |
| 71 | <h1>Users</h1> |
| 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> |
| 82 | <?PHP |
| 83 | $q="SELECT * FROM users"; |
| 84 | $r = $petition->query($q); |
| 85 | while($d = mysqli_fetch_array($r)){ |
| 86 | $alert=''; |
| 87 | if ($d[pass] == ''){ |
| 88 | $alert='NEEDS PASSWORD RESET'; |
| 89 | } |
| 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>"; |
| 91 | } |
| 92 | ?> |
| 93 | |
| 94 | <h1>New Petitions</h1> |
| 95 | <?PHP |
| 96 | $q="SELECT * FROM petitions where admin_status='new'"; |
| 97 | $r = $petition->query($q); |
| 98 | while($d = mysqli_fetch_array($r)){ |
| 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>"; |
| 100 | } |
| 101 | ?> |
| 102 | |
| 103 | |
| 104 | <h1>Approved Petitions</h1> |
| 105 | <?PHP |
| 106 | $q="SELECT * FROM petitions where admin_status = 'approved'"; |
| 107 | $r = $petition->query($q); |
| 108 | while($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 | |
| 114 | <h1>Groups</h1> |
| 115 | <?PHP |
| 116 | $q="SELECT * FROM groups"; |
| 117 | $r = $petition->query($q); |
| 118 | while($d = mysqli_fetch_array($r)){ |
| 119 | echo "<li>$d[id] $d[name]</li>"; |
| 120 | } |
| 121 | ?> |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | <h1>Website</h1> |
| 127 | <?PHP |
| 128 | $q="SELECT * FROM website_text"; |
| 129 | $r = $petition->query($q); |
| 130 | while($d = mysqli_fetch_array($r)){ |
| 131 | echo "<li>$d[id] $d[text_title]</li>"; |
| 132 | } |
| 133 | ?> |
| 134 | |
| 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; |
| 145 | $total2=0; |
| 146 | $goal = $d['signature_goal']; |
| 147 | if ($goal == 0){ |
| 148 | $goal = 10000; |
| 149 | } |
| 150 | $trader_sma_timePeriod=0; |
| 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).' }, '; |
| 162 | $q2 = "SELECT * FROM follow_up where date_sent = '$just_date' "; |
| 163 | $r2 = $petition->query($q2); |
| 164 | $count = mysqli_num_rows($r2); |
| 165 | $chart4 .= '{ label: "'.$just_date.'", y: '.intval($count).' }, '; |
| 166 | $total2 = $total2 + $count; |
| 167 | $chart5 .= '{ label: "'.$just_date.'", y: '.intval($total2).' }, '; |
| 168 | |
| 169 | $q2 = "SELECT * FROM presign where only_date = '$just_date' "; |
| 170 | $r2 = $petition->query($q2); |
| 171 | $count = mysqli_num_rows($r2); |
| 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++; |
| 177 | $trader_sma = trader_sma($trader_sma_real,7); |
| 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 | } |
| 183 | } |
| 184 | |
| 185 | $chart = rtrim(trim($chart), ","); |
| 186 | $chart2 = rtrim(trim($chart2), ","); |
| 187 | $chart3 = rtrim(trim($chart3), ","); |
| 188 | $chart4 = rtrim(trim($chart4), ","); |
| 189 | $chart5 = rtrim(trim($chart5), ","); |
| 190 | $chart6 = rtrim(trim($chart6), ","); |
| 191 | $chart7 = rtrim(trim($chart7), ","); |
| 192 | |
| 193 | |
| 194 | |
| 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 | ] |
| 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 | ] |
| 237 | },{ |
| 238 | type: "column", |
| 239 | visible: true, |
| 240 | showInLegend: true, |
| 241 | yValueFormatString: "#####", |
| 242 | name: "New Daily Signatures", |
| 243 | dataPoints: [ |
| 244 | <?PHP echo $chart; ?> |
| 245 | ] |
| 246 | },{ |
| 247 | type: "column", |
| 248 | visible: true, |
| 249 | showInLegend: true, |
| 250 | yValueFormatString: "#####", |
| 251 | name: "Follow Up Sent", |
| 252 | dataPoints: [ |
| 253 | <?PHP echo $chart4; ?> |
| 254 | ] |
| 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: [{ |
| 285 | type: "line", |
| 286 | visible: true, |
| 287 | showInLegend: true, |
| 288 | yValueFormatString: "#####", |
| 289 | name: "Web Activity", |
| 290 | dataPoints: [ |
| 291 | <?PHP echo $chart6; ?> |
| 292 | ] |
| 293 | },{ |
| 294 | type: "line", |
| 295 | visible: true, |
| 296 | showInLegend: true, |
| 297 | yValueFormatString: "#####", |
| 298 | name: "7 Day Simple Moving Average", |
| 299 | dataPoints: [ |
| 300 | <?PHP echo $chart7; ?> |
| 301 | ] |
| 302 | }] |
| 303 | } |
| 304 | |
| 305 | |
| 306 | ); |
| 307 | chart<?PHP echo $pID;?>.render(); |
| 308 | |
| 309 | <?PHP $javascript .= ob_get_clean(); ?> |
| 310 | |
| 311 | |
| 312 | |
| 313 | <script> |
| 314 | window.onload = function () { |
| 315 | |
| 316 | <?PHP echo $javascript;?> |
| 317 | |
| 318 | function 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> |
| 329 | <script src="../files/canvasjs.min.js"></script> |
| 330 | <?PHP |
| 331 | |
| 332 | |
| 333 | include_once('footer.php'); |
| 334 | ?> |