From: Chuck Scott Date: Fri, 7 Dec 2018 17:36:32 +0000 (-0500) Subject: Fixed a collection of notices and warnings. X-Git-Tag: v2.2.0^2~3 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=0311db53b767352fcf7d3f58cbbde84060cda9e1;p=WP-Plugins%2Fglm-serverstats.git Fixed a collection of notices and warnings. Connection warning still shows if unable to connect to the specified database. --- diff --git a/classes/serverBandwidthSupport.php b/classes/serverBandwidthSupport.php index 9dde346..5ea9cc0 100755 --- a/classes/serverBandwidthSupport.php +++ b/classes/serverBandwidthSupport.php @@ -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; diff --git a/models/adminServerStats.php b/models/adminServerStats.php index 2315704..668fc5c 100755 --- a/models/adminServerStats.php +++ b/models/adminServerStats.php @@ -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'; diff --git a/models/ajaxServerBandwidthGraphs.php b/models/ajaxServerBandwidthGraphs.php index 7b90c79..a888883 100755 --- a/models/ajaxServerBandwidthGraphs.php +++ b/models/ajaxServerBandwidthGraphs.php @@ -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']); } diff --git a/views/adminServerStatsConfig.html b/views/adminServerStatsConfig.html index b5b8b82..43698d7 100755 --- a/views/adminServerStatsConfig.html +++ b/views/adminServerStatsConfig.html @@ -3,10 +3,10 @@