Update maryland_voter.php
[clinton/MarylandElectronicPetitionSignature.git] / admin / index.php
index c034200..5bbeb8a 100644 (file)
@@ -10,7 +10,7 @@ if ($_COOKIE['level'] == 'manager'){
   header('Location: manager_home.php');
 }
 include_once('header.php');
-if ($_POST['name']){
+if ($_POST['name']){   
        $name           = $petition->real_escape_string($_POST['name']);
        $email          = $petition->real_escape_string($_POST['email']);
        $sec_level      = $petition->real_escape_string($_POST['sec_level']);
@@ -18,7 +18,18 @@ if ($_POST['name']){
        $petition_id    = $petition->real_escape_string($_POST['petition_id']);
        $q = "insert into users (name, email, sec_level, group_id, petition_id) values ('$name','$email','$sec_level','$group_id','$petition_id') ";
        $petition->query($q);
-       slack_general_admin('SQL: '.$q,'md-petition');
+       slack_general_admin('SQL: '.$q,'md-petition-signed');
+         include_once('../email.php');
+         $pass = rand(1000,9999);
+          $salt = md5(rand(1000,9999));
+          $hash = md5($pass.$salt);
+          $encrypted = $hash.':'.$salt;
+         $subject = 'MD Petition Login';
+         $body = 'Login with '.$email.' and your new password '.$pass.' at https://www.md-petition.com/admin/login.php';
+          meps_mail($email,$body,$subject);
+          $petition->query("update users set pass = '$encrypted' WHERE email = '$email'");
+          echo "<h1>Password has been Sent.</h1>";
+         slack_general_admin('DEBUG: '.$body,'md-petition-signed');
 }
 if(isset($_GET['approve'])){
   $id = $_GET['approve'];
@@ -29,6 +40,34 @@ slack_general('ADMIN: Home Page Loaded ('.$_COOKIE['name'].') ('.$_COOKIE['level
 
 <h1>Admin Home</h1>
 <div id="chartContainer1" style="height: 400px; width: 100%; margin: 0px auto;"></div>
+<div id="chartContainer2" style="height: 400px; width: 100%; margin: 0px auto;"></div>
+
+<table><tr><td valign='top'>
+<h2>Admin Sessions</h2>
+<div>Last 50</div><ol>
+<?PHP
+$q="SELECT * FROM admin_sessions where username <> 'Patrick McGuire' ORDER BY id DESC LIMIT 50";
+$r = $petition->query($q);
+while($d = mysqli_fetch_array($r)){ 
+    echo "<li title='$d[action_on]'>$d[ip] $d[username] $d[php_page]</li>"; 
+}
+?></ol>        
+       
+       </td><td valign='top'>
+
+       <h2>User Sessions</h2>
+<div>Last 50</div><ol>
+<?PHP
+$q="SELECT * FROM presign ORDER BY id DESC LIMIT 50";
+$r = $petition->query($q);
+while($d = mysqli_fetch_array($r)){ 
+    echo "<li title='$d[action_on]'>$d[php_page] $d[browser_string]</li>"; 
+}
+?></ol>
+       
+       </td></tr></table>
+
+
 <h1>Users</h1>
 <form method='post'>
   <table>
@@ -103,10 +142,12 @@ while($d = mysqli_fetch_array($r)){
        //echo "<li>$q3</li>";
        $r3 = $petition->query($q3);
        $total=0;
+       $total2=0;
        $goal = $d['signature_goal'];
        if ($goal == 0){
                $goal = 10000;
        }
+       $trader_sma_timePeriod=0;
        while ($d3 = mysqli_fetch_array($r3)){
          $just_date = $d3['just_date'];
          $q2 = "SELECT * FROM signatures where just_date = '$just_date' and signature_status = 'verified'  ";
@@ -118,11 +159,39 @@ while($d = mysqli_fetch_array($r)){
          $chart2 .=  '{ label: "'.$just_date.'", y: '.intval($total).' }, ';
          $goal = $goal - intval($count);
          $chart3 .=  '{ label: "'.$just_date.'", y: '.intval($goal).' }, ';
+         $q2 = "SELECT * FROM follow_up where date_sent = '$just_date'  ";
+         $r2 = $petition->query($q2);  
+         $count  = mysqli_num_rows($r2);
+         $chart4 .=  '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
+         $total2 = $total2 + $count;
+         $chart5 .=  '{ label: "'.$just_date.'", y: '.intval($total2).' }, ';
+         
+         $q2 = "SELECT * FROM presign where only_date = '$just_date'  ";
+         $r2 = $petition->query($q2);  
+         $count  = mysqli_num_rows($r2);
+         if($count > 0){ // start this graph when there is data
+                 $chart6 .=  '{ label: "'.$just_date.'", y: '.intval($count).' }, ';
+                 // graph latest sma
+                 $trader_sma_real[] = intval($count);
+                 $trader_sma_timePeriod++;
+                 $trader_sma = trader_sma($trader_sma_real,$trader_sma_timePeriod);
+                 //print_r($trader_sma);
+                 $the_index = $trader_sma_timePeriod - 1;
+                 $this_sma = $trader_sma[$the_index]; // should be last value?
+                 $chart7 .=  '{ label: "'.$just_date.'", y: '.intval($this_sma).' }, ';
+         }
        }
+       
        $chart = rtrim(trim($chart), ",");
        $chart2 = rtrim(trim($chart2), ",");
        $chart3 = rtrim(trim($chart3), ",");
+       $chart4 = rtrim(trim($chart4), ",");
+        $chart5 = rtrim(trim($chart5), ",");
+       $chart6 = rtrim(trim($chart6), ",");
+        $chart7 = rtrim(trim($chart7), ",");
+
        
+
        ob_start(); ?>
 
        var chart<?PHP echo $pID;?> = new CanvasJS.Chart("chartContainer<?PHP echo $pID;?>", {
@@ -156,6 +225,15 @@ while($d = mysqli_fetch_array($r)){
                        dataPoints: [
                                <?PHP echo $chart2; ?>
                        ]
+               },{
+                       type: "line",
+                       visible: true,
+                       showInLegend: true,
+                       yValueFormatString: "#####",
+                       name: "Total Follow Up Count",
+                       dataPoints: [
+                               <?PHP echo $chart5; ?>
+                       ]
                },{
                        type: "column",
                        visible: true,
@@ -165,6 +243,62 @@ while($d = mysqli_fetch_array($r)){
                        dataPoints: [
                                <?PHP echo $chart; ?>
                        ]
+               },{
+                       type: "column",
+                       visible: true,
+                       showInLegend: true,
+                       yValueFormatString: "#####",
+                       name: "Follow Up Sent",
+                       dataPoints: [
+                               <?PHP echo $chart4; ?>
+                       ]
+               }]
+       }
+
+
+                                     );
+       chart<?PHP echo $pID; $pID = $pID + 1; ?>.render();
+
+         var chart<?PHP echo $pID;?> = new CanvasJS.Chart("chartContainer<?PHP echo $pID;?>", {
+               theme:"light2",
+               animationEnabled: true,
+               exportEnabled: true,
+               title:{
+                       text: "MD-Petition.com Web Monitor"
+               },
+               axisY :{
+                       includeZero: false,
+                       title: "Number of Pages Loaded",
+                       suffix: "",
+           scaleBreaks: {
+                                       autoCalculate: true
+                               }
+               },
+               toolTip: {
+                       shared: "true"
+               },
+               legend:{
+                       cursor:"pointer",
+                       itemclick : toggleDataSeries
+               },
+               data: [{
+                       type: "line",
+                       visible: true,
+                       showInLegend: true,
+                       yValueFormatString: "#####",
+                       name: "Web Activity",
+                       dataPoints: [
+                               <?PHP echo $chart6; ?>
+                       ]
+               },{
+                       type: "line",
+                       visible: true,
+                       showInLegend: true,
+                       yValueFormatString: "#####",
+                       name: "Simple Moving Average",
+                       dataPoints: [
+                               <?PHP echo $chart7; ?>
+                       ]
                }]
        }