Update analytics.php
[clinton/MarylandElectronicPetitionSignature.git] / admin / analytics.php
index ec026b1..fa27394 100644 (file)
@@ -1,14 +1,56 @@
 <?PHP 
-include_once('../slack.php');
-include_once('security.php');
-include_once('/var/www/secure.php'); //outside webserver
-include_once('functions.php');
+global $order;
+$order = 'ASC';
+if (isset($_COOKIE['order'])){
+  $order = $_COOKIE['order'];
+}
+
+if (empty($_GET['run'])){
+  if ($_COOKIE['name'] == ''){
+    die('no name');
+  }
+  include_once('bots.php');
+  include_once('../slack.php');
+  include_once('security.php');
+  include_once('/var/www/secure.php'); //outside webserver
+  include_once('functions.php');
+}else{
+  include_once('../slack.php');
+  include_once('/var/www/secure.php'); //outside webserver
+  include_once('functions.php');
+}
+ob_start();
 
-function js_redirect($page){
+$sign_email = $_COOKIE['sign_email'];
+if (isset($_GET['sign_email'])){
+  // here we use it, if it shows up next run, we block
+  $sign_email = $_GET['sign_email'];
+  $_COOKIE['sign_email'] = $sign_email;
+  setcookie("sign_email", $sign_email);
+  
+}
+
+function js_redirect($page){ // now header - prep for full auto
   $base = 'https://www.md-petition.com/admin/';
-  $url = $base.$page;
-  echo "<script>window.location.href = \"$url\";</script>";
-  die(); 
+  $url = $base.$page.'&run=1';
+  $pos = strpos($page, $_COOKIE['sign_email']);
+  global $order;
+  if ($pos === false) {
+    // email not found - good to redirect
+    //echo "<script>window.location.href = \"$url\";</script>";
+    slack_general('js_redirect('.$page.')','automation');
+    header('Location: '.$url);
+    //slack_general('CHECK COOKIE ('.$_COOKIE['sign_email'].') PAGE ('.$page.')','md-petition-admin');
+    $order = 'ASC';
+    setcookie("order", $order);
+    die(); 
+  } else {
+    slack_general('Loop Detected for '.$_COOKIE['sign_email'],'automation');
+    echo "<h1>Automated Loop Detected - Skip Setting - Reverse Sort (DESC)</h1>";
+    $order = 'DESC';
+    setcookie("order", $order);
+  }
+  
 }
 
 if ($_COOKIE['level'] == 'user'){
@@ -136,7 +178,7 @@ if (isset($_GET['ip_address'])){
 }elseif(isset($_GET['php_session_id']) && empty($_GET['follow_up'])){ 
   $php_session_id = $_GET['php_session_id']; 
   echo "<h1>Review $php_session_id</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";    
-  $q = "SELECT * FROM presign where php_session_id = '$php_session_id' order by id desc ";
+  $q = "SELECT * FROM presign where php_session_id = '$php_session_id' and email_for_follow_up <> '$_COOKIE[sign_email]' order by id DESC ";
   $r = $petition->query($q);
   while($d = mysqli_fetch_array($r)){
     $color = 'white';
@@ -289,7 +331,10 @@ while($d = mysqli_fetch_array($r)){
 <div>Follow up requested - never signed.</div>
 <form method='GET'><input name='email'><input type='submit' value='SEARCH E-MAIL'></form><table>
 <?PHP
-$q="SELECT distinct php_session_id FROM presign where presign_status = 'NEW' and email_for_follow_up <> '' order by id";
+  
+
+  
+$q="SELECT distinct php_session_id FROM presign where presign_status = 'NEW' and email_for_follow_up <> '' order by id $order";
 $r = $petition->query($q);
 while($d = mysqli_fetch_array($r)){ 
   $q2="SELECT * FROM presign where php_session_id = '$d[php_session_id]' order by id desc";
@@ -334,7 +379,29 @@ while($d = mysqli_fetch_array($r)){
   if( $presig == '' && $invite_error == '' && $sig == '' ){
     if ($d2['invite'] == 'Ivey'){
       js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=8");
+      die();
+    }
+    if ($d2['invite'] == 'mlp'){
+      js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=2");
+      die();
+    }
+    if ($d2['invite'] == 'BTEC'){
+      js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=3");
+      die();
     }
+    if ($d2['invite'] == 'RestorePGTermLimits'){
+      js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=7");
+      die();
+    }
+    if (id2petition($d2['petition']) == 'RESTORE TWO TERM (8 YEAR) TERM LIMITS IN PRINCE GEORGE'){
+      js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=7");
+      die();
+    }
+    if ($d2['invite'] == 'mgp'){
+      js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=1");
+      die();
+    }
+    js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=X"); // no invite found no petition found - send general follow/up
   }
 }
 ?></table>
@@ -351,6 +418,7 @@ while($d = mysqli_fetch_array($r)){
     echo "<li>$d[date_time_signed] ".id2petition($d['petition_id'])." $d[signed_name_as]</li>"; 
 }
 ?></ol>
+
   </td>
 
   </tr>
@@ -414,5 +482,9 @@ while($d = mysqli_fetch_array($r)){
 
 
 <?PHP
+// allow headers to be sent...
+$html = ob_get_clean();
+echo $html; // run javascript
+
 include_once('footer.php');
 ?>