Fixed a collection of notices and warnings.
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 7 Dec 2018 17:36:32 +0000 (12:36 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 7 Dec 2018 17:36:32 +0000 (12:36 -0500)
Connection warning still shows if unable to connect to the specified database.

classes/serverBandwidthSupport.php
models/adminServerStats.php
models/ajaxServerBandwidthGraphs.php
views/adminServerStatsConfig.html

index 9dde346..5ea9cc0 100755 (executable)
@@ -127,22 +127,17 @@ class glmServerStatsBandwidthSupport
             return false;
         }
 
+        if (!$website) {
+            $website = $config['website'];
+        }
+
         // Connect to MySQL
-        $res = $this->bwdb->real_connect(
+        if ($this->bwdb->real_connect(
             $config['db_host'],
             $config['db_user'],
             $config['db_pass'],
             $config['db_name']
-        );
-
-        if (!$website) {
-            $website = $config['website'];
-        }
-
-        // If there was an error connecting
-        if (!$res) {
-            $this->connectError = mysqli_connect_error();
-        } else {
+        )) {
             $this->connected = true;
 
             // Get Website Settings
@@ -155,7 +150,8 @@ class glmServerStatsBandwidthSupport
             $this->disk_target  = $settings['disk_target'];
             $this->glm_contact  = $settings['glm_contact'];
             $this->cust_contact = $settings['cust_contact'];
-
+        } else {
+            $this->connectError = mysqli_connect_error();
         }
 
         return $this->connected;
index 2315704..668fc5c 100755 (executable)
@@ -30,13 +30,24 @@ require_once GLM_SERVERSTATS_PLUGIN_CLASS_PATH.'/serverBandwidthSupport.php';
 class adminServerStats extends glmServerStatsBandwidthSupport
 {
 
+
+    /**
+     * Config data
+     *
+     * @var $sortBy
+     * @access public
+     */
+    public $config = false;
+
     /*
      * Constructor
-     *
+
      * No work is performed by this contructor
     */
     public function __construct()
     {
+        $this->config = $this->getConfig();
+
         $websiteSelected = false;
 
         if (current_user_can('administrator')) {
@@ -44,7 +55,7 @@ class adminServerStats extends glmServerStatsBandwidthSupport
         }
 
         // Connect to Bandwidth Database selected in the Configure page
-        $this->bandwidthDataConnect($websiteSelected);
+        $this->connected = $this->bandwidthDataConnect($websiteSelected);
 
     }
 
@@ -59,6 +70,8 @@ class adminServerStats extends glmServerStatsBandwidthSupport
     {
 
         $haveStats     = false;
+        $stats         = false;
+        $site_sort     = false;
         $thisDate      = false;
         $thisDateTime  = false;
         $thisMonth     = false;
@@ -73,21 +86,26 @@ class adminServerStats extends glmServerStatsBandwidthSupport
         }
 
         // Check for a selected site or use website in config
-        $config = $this->getConfig();
         $selectedSite = filter_input(INPUT_GET, 'selected_site', FILTER_SANITIZE_STRING);
         if (!$selectedSite) {
-            $selectedSite = $config['website'];
+            $selectedSite = $this->config['website'];
         }
 
-        $this->siteId = $this->bandwidthGetWebsiteID($selectedSite);
-
         if ($this->connected) {
 
+            $this->siteId = $this->bandwidthGetWebsiteID($selectedSite);
+
             // If user is an admin, then get a list of Websites with Bandwidth Stats
             if ($this->isProvider()) {
 
+                // Get submitted parameters
+                $site_sort = 'default';
+                if (isset($_REQUEST['site_sort'])) {
+                    $site_sort = $_REQUEST['site_sort'];
+                }
+
                 // Get sort order
-                switch ($_REQUEST['site_sort']) {
+                switch ($site_sort) {
                     case 'site_name':
                         $sortBy = 'name';
                         $site_sort = 'site_name';
@@ -135,7 +153,7 @@ class adminServerStats extends glmServerStatsBandwidthSupport
                 }
 
                 // Get sort order
-                switch ($_REQUEST['site_sort']) {
+                switch ($site_sort) {
                     case 'site_name':
                         $sortBy = 'name';
                         $site_sort = 'site_name';
index 7b90c79..a888883 100755 (executable)
@@ -108,6 +108,10 @@ class ajaxServerBandwidthGraphs  extends glmServerStatsBandwidthSupport
         // Get bandwidth data for today
         $data = $this->bandwidthGetGraphData($graphType, $this->siteId, $refDate);
 
+        if (!$data || !is_array($data) || count($data) == 0) {
+            die("Unable to get data. Is connection configured?");
+        }
+
         // Load PHPGraphLib
         require_once GLM_SERVERSTATS_PLUGIN_LIB_PATH.'/phpgraphlib-master/phpgraphlib.php';
 
@@ -131,7 +135,7 @@ class ajaxServerBandwidthGraphs  extends glmServerStatsBandwidthSupport
         $graph->addData($data['data_in']);
         $graph->addData($data['data_out']);
 
-        if ($graphType != 'oneDay') {
+        if (isset($data['disk_space'])) {
             $graph->addData($data['disk_space']);
         }
 
index b5b8b82..43698d7 100755 (executable)
@@ -3,10 +3,10 @@
 
     <style>
         .pseudoPick {
-            
-            height: 150px; 
-            padding-left: 2px; 
-            overflow-y: auto; 
+
+            height: 150px;
+            padding-left: 2px;
+            overflow-y: auto;
             overflow-x: hidden;
             display: inline-block;
             margin-top: 1em;
         <h2>Server Usage Statistics Configuration</h2>
         <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
             <input type="hidden" name="option" value="update_connection">
-            <input type="hidden" name="selected_site" value="{$selectedSite}">
 
             <table class="glm-admin-table" style="width: 95%">
                 <tr>
-                    <td>
-                        {if $connectionUpdated}<h2 class="glm-notice glm-flash-updated">Settings Updated</h2>{/if}
-                        
+                    <td colspan="2">
+                        <span class="glm-notice glm-flash-updated" style="font-size: 1.5em;">Settings Updated</span>
                     </td>
-                    <th>
-                        <h2>Database Connection</h2>
-                        {if $connectionUpdateError}<br><span class="glm-error">Error {$connectionUpdateError}{/if}
+                </tr>
+                <tr>
+                    <th colspan="2">
+                        {if $connectError}<br><span class="glm-error" style="font-size: 1.5em; border: 1px solid black; padding: 5px; margin-bottom: 4em;">Error {$connectError}</span>{/if}
                     </th>
                 </tr>
                 <tr>
             </table>
 {if $connectError}
             <h2 class="glm-error">Unable to connect to database! Please check connection settings.</h2>
-{/if}            
+{/if}
             <input type="submit" value="Update Database Connection" class="button-primary">
         </form>
-        
+
     </div>
     <script type="text/javascript">
 
@@ -95,8 +94,8 @@
                 location.href='#glmPageTop';
             }, 500);
 
-            
-                
+
+
         });
     </script>