From 22cc714486c792152c4a0a9d3d5bd9fd7a5769c1 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Sat, 10 Nov 2012 23:35:32 -0500
Subject: [PATCH] Fix bug on staff group stats Autosubmit form on load -
 refresh is called on submit giving it form object Validate start/stop
 timeframe in the backend

---
 include/ajax.reports.php | 32 ++++++++++++++++++++++----------
 scp/js/dashboard.inc.js  | 15 +++++++++------
 2 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/include/ajax.reports.php b/include/ajax.reports.php
index 7fbe19c89..0ad0640a3 100644
--- a/include/ajax.reports.php
+++ b/include/ajax.reports.php
@@ -37,10 +37,15 @@ class OverviewReportAjaxAPI extends AjaxController {
     function getData() {
         global $thisstaff;
 
-        $start = $this->get('start', 'last month');
-        $stop = $this->get('stop', 'now');
-        if (substr($stop, 0, 1) == '+')
-            $stop = $start . $stop;
+        if(($start = $this->get('start', 'last month'))) {
+            $stop = $this->get('stop', 'now');
+            if (substr($stop, 0, 1) == '+')
+                $stop = $start . $stop;
+        } else {
+            $start = 'last month';
+            $stop = 'now';
+        }
+
         $start = 'FROM_UNIXTIME('.strtotime($start).')';
         $stop = 'FROM_UNIXTIME('.strtotime($stop).')';
 
@@ -72,9 +77,9 @@ class OverviewReportAjaxAPI extends AjaxController {
                 "filter" =>
                     ('T1.staff_id=S1.staff_id
                       AND 
-                      (T1.staff_id='.db_input($thisstaff->getDeptId())
+                      (T1.staff_id='.db_input($thisstaff->getId())
                         .(($depts=$thisstaff->getManagedDepartments())?
-                            (' OR T1.staff_id IN('.implode(',', db_input($depts)).')'):'')
+                            (' OR T1.dept_id IN('.implode(',', db_input($depts)).')'):'')
                      .')'
                      ) 
             )
@@ -166,10 +171,17 @@ class OverviewReportAjaxAPI extends AjaxController {
     }
 
     function getPlotData() {
-        $start = $this->get('start', 'last month');
-        $stop = $this->get('stop', 'now');
-        if (substr($stop, 0, 1) == '+')
-            $stop = $start . $stop;
+
+                
+        if(($start = $this->get('start', 'last month'))) {
+            $stop = $this->get('stop', 'now');
+            if (substr($stop, 0, 1) == '+')
+                $stop = $start . $stop;
+        } else {
+            $start = 'last month';
+            $stop = 'now';
+        }
+
         $start = strtotime($start);
         $stop = strtotime($stop);
 
diff --git a/scp/js/dashboard.inc.js b/scp/js/dashboard.inc.js
index 0f9e31a54..ba19235f1 100644
--- a/scp/js/dashboard.inc.js
+++ b/scp/js/dashboard.inc.js
@@ -9,9 +9,7 @@
         $.ajax({
             method:     'GET',
             url:        'ajax.php/report/overview/graph',
-            data:       ((this.start && this.start.value) ? {
-                'start': this.start.value,
-                'stop': this.period.value} : {}),
+            data:       $(this).serialize(),
             dataType:   'json',
             success:    function(json) {
                 var times = [],
@@ -136,6 +134,7 @@
             start = this.start.value || 'last month';
             stop = this.period.value || 'now';
         }
+
         var group = current_tab.attr('table-group');
         $.ajax({
             method:     'GET',
@@ -250,7 +249,7 @@
 
                 // ------------------------> Export <-----------------------
                 $('<a>').attr({'href':'ajax.php/report/overview/table/export?group='
-                        +group}).append('Export')
+                        +group+'&start='+start+'&stop='+stop}).append('Export')
                     .appendTo($('<li>')
                     .appendTo(p));
 
@@ -259,6 +258,10 @@
         });
         return false;
     }
-    $(refresh);
-    $(function() { $('#timeframe-form').submit(refresh); });
+   
+    $(function() { 
+        $('#timeframe-form').submit(refresh);
+        //Trigger submit now...init.
+        $('#timeframe-form').submit(); 
+        });
 })(window.jQuery);
-- 
GitLab