From: Chuck Scott Date: Mon, 22 Aug 2016 18:36:32 +0000 (-0400) Subject: Finished development of Server Stats initial features. X-Git-Tag: v1.0.0^2~4 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c08d4b9493633910066dcdd839c01f3e4c5d4e08;p=WP-Plugins%2Fglm-member-db-serverstats.git Finished development of Server Stats initial features. Added management features for Server Stats. Added more tests and failure messages for access to server stats database. --- diff --git a/classes/data/dataManagement.php b/classes/data/dataManagement.php new file mode 100644 index 0000000..68a4f3c --- /dev/null +++ b/classes/data/dataManagement.php @@ -0,0 +1,171 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataSearchManagement.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataServerStatsManagement class + * + * PHP version 5 + * + * @category Data + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataSearchManagement.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmDataServerStatsManagement extends GlmDataAbstract +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Data Table Name + * + * @var $table + * @access public + */ + public $table; + /** + * Field definitions + * + * 'type' is type of field as defined by the application + * text Regular text field + * pointer Pointer to an entry in another table + * 'filters' is the filter name for a particular filter ID in PHP filter + * functions + * See PHP filter_id() + * + * 'use' is when to use the field + * l = List + * g = Get + * n = New + * i = Insert + * e = Edit + * u = Update + * d = Delete + * a = All + * + * @var $ini + * @access public + */ + public $fields = false; + + /** + * Constructor + * + * @param object $d database connection + * @param array $config Configuration array + * @param bool $limitedEdit Flag to say indicate limited edit requested + * + * @return void + * @access public + */ + public function __construct($wpdb, $config, $limitedEdit = false) + { + + // If this class is not being extended along with existing $wpdb and $config + if (!$this->wpdb) { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + } + + /* + * Table Name + */ + $this->table = GLM_MEMBERS_SERVERSTATS_PLUGIN_DB_PREFIX . 'management'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Enabled + 'enabled' => array( + 'field' => 'enabled', + 'type' => 'checkbox', + 'use' => 'a' + ), + + // Database Name + 'db_name' => array ( + 'field' => 'db_name', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // Database Hostname + 'db_host' => array ( + 'field' => 'db_host', + 'type' => 'text', + 'use' => 'a' + ), + + // Database User + 'db_user' => array ( + 'field' => 'db_user', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // Database Password + 'db_pass' => array ( + 'field' => 'db_pass', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // Website + 'website' => array ( + 'field' => 'website', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ) + + ); + + } + + +} + +?> \ No newline at end of file diff --git a/classes/data/dataServerStats.php b/classes/data/dataServerStats.php deleted file mode 100644 index f373fb3..0000000 --- a/classes/data/dataServerStats.php +++ /dev/null @@ -1,143 +0,0 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: dataServerStats.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ - */ - -/** - * GlmDataServerStats class - * - * PHP version 5 - * - * @category Data - * @package GLM Member DB - * @author Chuck Scott - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott - * Exp $ - */ -class GlmDataServerStats extends GlmDataAbstract -{ - - /** - * WordPress Database Object - * - * @var $wpdb - * @access public - */ - public $wpdb; - /** - * Plugin Configuration Data - * - * @var $config - * @access public - */ - public $config; - /** - * Data Table Name - * - * @var $table - * @access public - */ - public $table; - /** - * Field definitions - * - * 'type' is type of field as defined by the application - * text Regular text field - * pointer Pointer to an entry in another table - * 'filters' is the filter name for a particular filter ID in PHP filter - * functions - * See PHP filter_id() - * - * 'use' is when to use the field - * l = List - * g = Get - * n = New - * i = Insert - * e = Edit - * u = Update - * d = Delete - * a = All - * - * @var $ini - * @access public - */ - public $fields = false; - - /** - * Constructor - * - * @param object $d database connection - * @param array $config Configuration array - * @param bool $limitedEdit Flag to say indicate limited edit requested - * - * @return void - * @access public - */ - public function __construct($wpdb, $config, $limitedEdit = false) - { - - // If this class is not being extended along with existing $wpdb and $config - if (!$this->wpdb) { - - // Save WordPress Database object - $this->wpdb = $wpdb; - - // Save plugin configuration object - $this->config = $config; - - } - - /* - * Table Name - */ - $this->table = GLM_MEMBERS_SERVERSTATS_PLUGIN_DB_PREFIX . 'serverstats'; - - /* - * Table Data Fields - */ - - $this->fields = array ( - - 'id' => array ( - 'field' => 'id', - 'type' => 'integer', - 'view_only' => true, - 'use' => 'a' - ), - - ); - - } - - /* - * Entry Post Processing Call-Back Method - * - * Perform post-processing for all result entries. - * - * In this case we're using it to append an array of category - * data to each row result and also sort by name. - * - * @param array $r Array of field result data for a single entry - * @param string $a Action being performed (l, i, g, ...) - * - * @return object Class object - * - */ - public function entryPostProcessing($r, $a) - { - return $r; - } - -} - -?> \ No newline at end of file diff --git a/classes/serverBandwidthSupport.php b/classes/serverBandwidthSupport.php new file mode 100644 index 0000000..24f4637 --- /dev/null +++ b/classes/serverBandwidthSupport.php @@ -0,0 +1,268 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release serverBandwidthSupport.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * This class provides support for the reporting of server bandwidth stats + * for simple day and month values as well as detailed lists of values for + * a day (by 10 min intervals), month (by days), or 2 years (by months). + * + */ +class GlmServerBandwidthSupport +{ + + /** + * Bandwidth database object + * + * @var $bwdb + * @access public + */ + public $bwdb = false; + /** + * Web site ID + * + * @var $siteId + * @access public + */ + public $siteId = false; + + public function __construct() + { + } + + /* + * Connect to desired database or trigger error if unable to connect. + * + * @param string $host Hostname of database server + * @param string $user Username for database + * @param string $pass Password for database + * @param string $database Name of database + * @param string $website Website name in database + * + * @return string Error message. If blank, then no error. + */ + public function bandwidthDataConnect($host, $user, $pass, $database, $website) + { + + // Connect to MySQL + $this->bwdb = mysqli_connect($host, $user, $pass, $database); + + if (!$this->bwdb) { + $this->bwdb = false; + return mysqli_connect_error(); + } + + // Get index for this site (site ID) + $this->bandwidthGetWebsiteID($website); + + if (!$this->siteId) { + $this->bwdb = false; + return "Website Name not found: ".$website; + } + + return ''; + + } + + /* + * Get Web site ID from Web site name. + * + * The Website ID is the index used to find bandwidth data for a + * particular Web site + */ + public function bandwidthGetWebsiteID($website) + { + + // Get Website ID + $sql = " + SELECT websitepk + FROM website + WHERE name = '$website' + ;"; + $websiteResult = $this->bwdb->query($sql); + if (!$websiteResult) { + trigger_error("Website ID query failed: " . mysqli_error($bwdb) ); + } + $row = mysqli_fetch_assoc($websiteResult); + if (!$row){ + trigger_error("Website '$website' not found."); + } + $this->siteId = $row['websitepk']; + + } + + /* + * Get bandwidth stats for the current day, and month + */ + public function bandwidthGetStats() + { + $stats = array(); + + // Check for good database connection + if ($this->bwdb == false) { + return false; + } + + // Get stats so far for today in Megabytes + $today = date('Y-m-d 0:0:0.0'); + $tomorrow = date('Y-m-d 0:0:0.0', strtotime(date('Y-m-d')." + 1day")); + $sql = " + SELECT + COALESCE ( SUM(bytesin)/1000000, 0 ) as data_in, + COALESCE ( SUM(bytesout)/1000000, 0 ) as data_out, + COALESCE ( SUM(total)/1000000, 0 ) as data_total + FROM bytes + WHERE websitefk = ".$this->siteId." + AND time BETWEEN '$today' AND '$tomorrow' + ;"; + $todayStats = $this->bwdb->query($sql); + $stats['today'] = $todayStats->fetch_array(MYSQLI_ASSOC); + + // Get stats for this month in Gigabytes + $firstDayOfMonth = date('Y-m-01'); + $lastDayOfMonth = date('Y-m-t'); + $sql = " + SELECT + COALESCE ( SUM(bytesin)/1000000000, 0 ) as data_in, + COALESCE ( SUM(bytesout)/1000000000, 0 ) as data_out, + COALESCE ( SUM(total)/1000000000, 0 ) as data_total + FROM rollup + WHERE websitefk = ".$this->siteId." + AND date BETWEEN '$firstDayOfMonth' AND '$lastDayOfMonth' + ;"; + $thisMonthStats = $this->bwdb->query($sql); + $stats['thisMonth'] = $thisMonthStats->fetch_array(MYSQLI_ASSOC); + + // Get stats for last month in Gigabytes + $firstDayOfMonth = date('Y-m-01', strtotime(date('Y-m-01').' -1 month')); + $lastDayOfMonth = date('Y-m-t', strtotime($firstDayOfMonth)); + $sql = " + SELECT + COALESCE ( SUM(bytesin)/1000000000, 0 ) as data_in, + COALESCE ( SUM(bytesout)/1000000000, 0 ) as data_out, + COALESCE ( SUM(total)/1000000000, 0 ) as data_total + FROM rollup + WHERE websitefk = ".$this->siteId." + AND date BETWEEN '$firstDayOfMonth' AND '$lastDayOfMonth' + ;"; + $lastMonthStats = $this->bwdb->query($sql); + $stats['lastMonth'] = $lastMonthStats->fetch_array(MYSQLI_ASSOC); + + return $stats; + + } + + /* + * Get bandwidth graph data for Today, This month, Two years + */ + public function bandwidthGetGraphData($graphType = false) + { + $bandwidth = array('data_in' => array(), 'data_out' => array(), 'data_total' => array()); + + // Produce data for specified intervals + switch ($graphType) { + + case 'twoDay': + + // Get data for today in Megabytes (10 min intervals) + $startOfToday = date('Y-m-d 0:0:0.0', strtotime('today - 1day')); + $endOfToday = date('Y-m-d 23:59:59.9999'); + $sql = " + SELECT time, + bytesin/1000000 as data_in, + bytesout/1000000 as data_out, + total/1000000 as data_total + FROM bytes + WHERE websitefk = ".$this->siteId." + AND time BETWEEN '$startOfToday' AND '$endOfToday' + ORDER BY time ASC + ;"; + $dayData = $this->bwdb->query($sql); + $dayData->data_seek(0); + while ($row = $dayData->fetch_assoc()) { + $time = date('d-H:i', strtotime($row['time'])); + $bandwidth['data_in'][$time] = $row['data_in']; + $bandwidth['data_out'][$time] = $row['data_out']; + $bandwidth['data_total'][$time] = $row['data_total']; + } + + break; + + case 'twoMonth': + + // Get data for this month in Gigabytes (1 day intervals) + $firstDayOfMonth = date('Y-m-01', strtotime('today - 1month')); + $lastDayOfMonth = date('Y-m-t'); + $sql = " + SELECT date as time, + bytesin/1000000000 as data_in, + bytesout/1000000000 as data_out, + total/1000000000 as data_total + FROM rollup + WHERE websitefk = ".$this->siteId." + AND date BETWEEN '$firstDayOfMonth' AND '$lastDayOfMonth' + ORDER BY date ASC + ;"; + $monthData = $this->bwdb->query($sql); + $monthData->data_seek(0); + while ($row = $monthData->fetch_assoc()) { + $time = date('m-d', strtotime($row['time'])); + $bandwidth['data_in'][$time] = $row['data_in']; + $bandwidth['data_out'][$time] = $row['data_out']; + $bandwidth['data_total'][$time] = $row['data_total']; + } + + break; + + case 'twoYear': + + // Get stats for this year and last year in Gigabytes + $firstMonth = date('Y-01-01', strtotime('today -1 year')); + $lastMonth = date('Y-12-31'); + $sql = " + SELECT date as time, + COALESCE ( SUM(bytesin)/1000000000, 0 ) as data_in, + COALESCE ( SUM(bytesout)/1000000000, 0 ) as data_out, + COALESCE ( SUM(total)/1000000000, 0 ) as data_total + FROM rollup + WHERE websitefk = ".$this->siteId." + AND date BETWEEN '$firstMonth' AND '$lastMonth' + GROUP BY MONTH(date) + ORDER BY date ASC + ;"; + $twoYearData = $this->bwdb->query($sql); + $twoYearData->data_seek(0); + while ($row = $twoYearData->fetch_assoc()) { + $time = date('Y-m', strtotime($row['time'])); + $bandwidth['data_in'][$time] = $row['data_in']; + $bandwidth['data_out'][$time] = $row['data_out']; + $bandwidth['data_total'][$time] = $row['data_total']; + } + + break; + + default: + + die("Graph Type not specified or valid."); + break; + + } + + return $bandwidth; + + } + + + +} \ No newline at end of file diff --git a/index.php b/index.php index cdd3866..cccb1b9 100644 --- a/index.php +++ b/index.php @@ -41,7 +41,7 @@ define('GLM_MEMBERS_SERVERSTATS_PLUGIN_VERSION', '0.0.1'); define('GLM_MEMBERS_SERVERSTATS_PLUGIN_DB_VERSION', '0.0.1'); // This is the minimum version of the GLM Members DB plugin require for this plugin. -define('GLM_MEMBERS_SERVERSTATS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.57'); +define('GLM_MEMBERS_SERVERSTATS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.5.0'); // Check if plugin version is not current in WordPress option and if needed updated it if (GLM_MEMBERS_SERVERSTATS_PLUGIN_VERSION != get_option('glmMembersDatabaseServerStatsPluginVersion')) { diff --git a/models/admin/ajax/serverBandwidthGraphs.php b/models/admin/ajax/serverBandwidthGraphs.php new file mode 100644 index 0000000..a845f7e --- /dev/null +++ b/models/admin/ajax/serverBandwidthGraphs.php @@ -0,0 +1,136 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +// Load Members Data Class +require_once(GLM_MEMBERS_SERVERSTATS_PLUGIN_CLASS_PATH.'/serverBandwidthSupport.php'); + +/* + * This class exports the currently selected members list + * to a printable HTML file, to a CSV file, or otherwise. + */ +class GlmMembersAdmin_ajax_serverBandwidthGraphs extends GlmServerBandwidthSupport +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Get Server Stats database access information and connect to database + require_once(GLM_MEMBERS_SERVERSTATS_PLUGIN_CLASS_PATH.'/data/dataManagement.php'); + $DataManagement = new GlmDataServerStatsManagement($this->wpdb, $this->config); + $dbData= $DataManagement->getEntry(1); + $this->bandwidthDataConnect( + $dbData['db_host'], + $dbData['db_user'], + $dbData['db_pass'], + $dbData['db_name'], + $dbData['website'] + ); + + } + + /* + * Perform Model Action + * + * This modelAction takes an AJAX request to produce a bandwidth graph and + * output it. + * + * This model action does not return, it simply does it's work then calls die(); + * + * @param $actionData + * + * Echos JSON string as response and does not return + */ + public function modelAction () + { + $graphType = $_REQUEST['graphType']; + + $interval = 1; + switch($graphType) { + case 'twoDay': + $interval = 8; + break; + case 'twoMonth': + $interval = 2; + break; + case 'twoYear': + $interval = 1; + break; + default: + die("Invalid bandwidth graph type: $graphType"); + break; + } + + // Get bandwidth data for today + $data = $this->bandwidthGetGraphData($graphType); + + // Load PHPGraphLib + require_once(GLM_MEMBERS_PLUGIN_LIB_PATH.'/phpgraphlib-master/phpgraphlib.php'); + + // Create graph object + $graph = new PHPGraphLib(1200,300); + $graph->setXValues(true); + $graph->setYValues(true); + $graph->setXValuesInterval($interval); + $graph->setXValuesHorizontal(false); + $graph->setLineColor("blue", "red", "green"); + $graph->setDataPointSize(4); + $graph->setTextColor("blue"); + $graph->setBackgroundColor('245,245,245'); + $graph->setLine(true); + $graph->setBars(false); + $graph->setDataPoints(false); + + $graph->addData($data['data_total']); + $graph->addData($data['data_in']); + $graph->addData($data['data_out']); + + // $graph->setTitle($graphTitle); - In this case the graph title is on the pop-up dialog box. + $graph->createGraph(); + + + wp_die(); + + } + +} diff --git a/models/admin/dashboardWidget/serverStats.php b/models/admin/dashboardWidget/serverStats.php new file mode 100644 index 0000000..d3528ca --- /dev/null +++ b/models/admin/dashboardWidget/serverStats.php @@ -0,0 +1,161 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Members Data Class +require_once(GLM_MEMBERS_SERVERSTATS_PLUGIN_CLASS_PATH.'/serverBandwidthSupport.php'); + + +class GlmMembersAdmin_dashboardWidget_serverStats extends GlmServerBandwidthSupport +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Server Stats Database Connection Error + * + * @var $dbError + * @access public + */ + public $dbError = ''; + /** + * Server Stats Database Connection Enabled + * + * @var $enabled + * @access public + */ + public $enabled = true; + + /* + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + * @wpdb object WordPress database object + * @config array Current config array + * @host string Database server host for bandiwdth stats data + * @user string Database user + * @pass string Database password + * @database string Name of Database + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Get Server Stats database access information and connect to database + require_once(GLM_MEMBERS_SERVERSTATS_PLUGIN_CLASS_PATH.'/data/dataManagement.php'); + $DataManagement = new GlmDataServerStatsManagement($this->wpdb, $this->config); + $dbData= $DataManagement->getEntry(1); + + // Check if Server Stats is enabled + if (!$dbData['enabled']['value']) { + $this->enabled = false; + return false; + } + + // Connect to server stats database + $this->bandwidthDataConnect( + $dbData['db_host'], + $dbData['db_user'], + $dbData['db_pass'], + $dbData['db_name'], + $dbData['website'] + ); + + } + + public function modelAction($actionData = false) + { + + $thisDate = false; + $thisDateTime = false; + $thisMonth = false; + $thisMonthTime = false; + $websiteId = false; + $stats = false; + + // Check for good database connection + if ($this->bwdb != false) { + + // Get current summary stats + $stats = $this->bandwidthGetStats(); + + // Build summary info + $thisDate = date('m/d/Y'); + $thisDateTime = strtotime($thisDate); + $thisMonth = date('m/Y'); + $thisMonthTime = strtotime(date('m/01/Y')); + $websiteId = $this->siteId; + + } + + // Compile template data + $templateData = array( + 'serverStatsEnabled' => $this->enabled, + 'serverStats' => $stats, + 'thisDate' => $thisDate, + 'thisDateTime' => $thisDateTime, + 'thisMonth' => $thisMonth, + 'thisMonthTime' => $thisMonthTime, + 'websiteId' => $this->siteId, + 'location' => $actionData['location'] // Indicates where this is being used (members, widget) + ); + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/dashboardWidget/serverStats.html', + 'data' => $templateData + ); + + } + +} diff --git a/models/admin/info/index.php b/models/admin/info/index.php deleted file mode 100644 index 4c61edb..0000000 --- a/models/admin/info/index.php +++ /dev/null @@ -1,125 +0,0 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ - * @link http://dev.gaslightmedia.com/ - */ - -// Load Contacts data abstract -//require_once(GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataContacts.php'); - -class GlmMembersAdmin_info_index // extends GlmDataContacts -{ - - /** - * WordPress Database Object - * - * @var $wpdb - * @access public - */ - public $wpdb; - /** - * Plugin Configuration Data - * - * @var $config - * @access public - */ - public $config; - /** - * Contact Info - * - * @var $contactInfo - * @access public - */ - public $contactInfo = false; - /** - * Member ID - * - * @var $memberID - * @access public - */ - public $memberID = false; - /** - * Contact ID - * - * @var $contactID - * @access public - */ - public $contactID = false; - - - /* - * Constructor - * - * This contructor performs the work for this model. This model returns - * an array containing the following. - * - * 'status' - * - * True if successfull and false if there was a fatal failure. - * - * 'view' - * - * A suggested view name that the contoller should use instead of the - * default view for this model or false to indicate that the default view - * should be used. - * - * 'data' - * - * Data that the model is returning for use in merging with the view to - * produce output. - * - * @wpdb object WordPress database object - * - * @return array Array containing status, suggested view, and any data - */ - public function __construct ($wpdb, $config) - { - - // Save WordPress Database object - $this->wpdb = $wpdb; - - // Save plugin configuration object - $this->config = $config; - - /* - * Run constructor for the Contacts data class - * - * Note, the third parameter is a flag that indicates to the Contacts - * data class that it should flag a group of fields as 'view_only'. - */ -// parent::__construct(false, false, true); - - - } - - public function modelAction($actionData = false) - { - - $displayData = 'This is the Sample Add-On "Info" model talking to you from inside WordPress.'; - - // Compile template data - $templateData = array( - 'displayData' => $displayData - ); - - // Return status, any suggested view, and any data to controller - return array( - 'status' => true, - 'modelRedirect' => false, - 'view' => 'admin/info/index.html', - 'data' => $templateData - ); - - } - - -} diff --git a/models/admin/management/serverStats.php b/models/admin/management/serverStats.php new file mode 100644 index 0000000..6dc8ff9 --- /dev/null +++ b/models/admin/management/serverStats.php @@ -0,0 +1,178 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release serverStats.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Management Server Stats data abstract +require_once(GLM_MEMBERS_SERVERSTATS_PLUGIN_CLASS_PATH.'/data/dataManagement.php'); + +/** + * GlmMembersAdmin_management_serverStats + * + * PHP version 5 + * + * @category Model + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: serverStats.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmMembersAdmin_management_serverStats extends GlmDataServerStatsManagement +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + + /* + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for members data class + parent::__construct(false, false); + + } + + public function modelAction($actionData = false) + { + $serverStatsSettigns = false; + $settingsUpdated = false; + $settingsUpdateError = false; + $dbError = false; + + + // Determine if current user can edit configurations + if (!current_user_can('glm_members_management')) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'User does not have rights to make configuration changes.' + ) + ); + } + + // Check for submission option + $option = ''; + if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'submit') { + $option = $_REQUEST['option']; + } + + switch($option) { + + // Update the settings and redisplay the form + case 'submit': + + // Update the server stats management settings + $serverStatsSettings = $this->updateEntry(1); + if ($serverStatsSettings['status']) { + $settingsUpdated = true; + } else { + $settingsUpdateError = true; + } + + // Test database connection and warn user if not functional + require_once(GLM_MEMBERS_SERVERSTATS_PLUGIN_CLASS_PATH.'/serverBandwidthSupport.php'); + $BandwidthStats = new GlmServerBandwidthSupport(); + $res = $BandwidthStats->bandwidthDataConnect( + $serverStatsSettings['fieldData']['db_host'], + $serverStatsSettings['fieldData']['db_user'], + $serverStatsSettings['fieldData']['db_pass'], + $serverStatsSettings['fieldData']['db_name'], + $serverStatsSettings['fieldData']['website'] + ); + + if ($res != '') { + $dbError = $res." "; + } + + break; + + // Default is to get the current settings and display the form + default: + + // Try to get the first (should be only) entry for general settings. + $serverStatsSettings = $this->editEntry(1); + + if ($serverStatsSettings === false) { + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice("  /models/admin/management/serverStats.php: Unable to load server stats management settings.", 'Alert'); + } + + } + + break; + + } + + // Compile template data + $templateData = array( + 'reason' => '', + 'serverStatsSettings' => $serverStatsSettings, + 'settingsUpdated' => $settingsUpdated, + 'settingsUpdateError' => $settingsUpdateError, + 'dbError' => $dbError + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/management/serverStats.html', + 'data' => $templateData + ); + + + } +} + +?> \ No newline at end of file diff --git a/models/admin/members/sample.php b/models/admin/members/sample.php deleted file mode 100644 index c9cd6ca..0000000 --- a/models/admin/members/sample.php +++ /dev/null @@ -1,103 +0,0 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ - * @link http://dev.gaslightmedia.com/ - */ - -// Load Sample data abstract -require_once(GLM_MEMBERS_SAMPLE_PLUGIN_CLASS_PATH.'/data/dataSample.php'); - -class GlmMembersAdmin_members_sample extends GlmDataSample -{ - - /** - * WordPress Database Object - * - * @var $wpdb - * @access public - */ - public $wpdb; - /** - * Plugin Configuration Data - * - * @var $config - * @access public - */ - public $config; - - /* - * Constructor - * - * This contructor performs the work for this model. This model returns - * an array containing the following. - * - * 'status' - * - * True if successfull and false if there was a fatal failure. - * - * 'view' - * - * A suggested view name that the contoller should use instead of the - * default view for this model or false to indicate that the default view - * should be used. - * - * 'data' - * - * Data that the model is returning for use in merging with the view to - * produce output. - * - * @wpdb object WordPress database object - * - * @return array Array containing status, suggested view, and any data - */ - public function __construct ($wpdb, $config) - { - - // Save WordPress Database object - $this->wpdb = $wpdb; - - // Save plugin configuration object - $this->config = $config; - - /* - * Run constructor for the Contacts data class - * - * Note, the third parameter is a flag that indicates to the Contacts - * data class that it should flag a group of fields as 'view_only'. - */ -// parent::__construct(false, false, true); - - - } - - public function modelAction($actionData = false) - { - - $displayData = 'This is the Sample model talking to you from inside WordPress.'; - - // Compile template data - $templateData = array( - 'displayData' => $displayData - ); - - // Return status, any suggested view, and any data to controller - return array( - 'status' => true, - 'modelRedirect' => false, - 'view' => 'admin/members/sample.html', - 'data' => $templateData - ); - - } - - -} diff --git a/models/admin/readme.txt b/models/admin/readme.txt deleted file mode 100644 index e9a199d..0000000 --- a/models/admin/readme.txt +++ /dev/null @@ -1,5 +0,0 @@ -The admin controller executes models under this directory. - -Typically you should add a directory here that matches the page where the action should take place. - -Under that directory place the model for the various actions. \ No newline at end of file diff --git a/models/admin/sample/index.php b/models/admin/sample/index.php deleted file mode 100644 index 5c321df..0000000 --- a/models/admin/sample/index.php +++ /dev/null @@ -1,125 +0,0 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ - * @link http://dev.gaslightmedia.com/ - */ - -// Load Contacts data abstract -//require_once(GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataContacts.php'); - -class GlmMembersAdmin_sample_index // extends GlmDataContacts -{ - - /** - * WordPress Database Object - * - * @var $wpdb - * @access public - */ - public $wpdb; - /** - * Plugin Configuration Data - * - * @var $config - * @access public - */ - public $config; - /** - * Contact Info - * - * @var $contactInfo - * @access public - */ - public $contactInfo = false; - /** - * Member ID - * - * @var $memberID - * @access public - */ - public $memberID = false; - /** - * Contact ID - * - * @var $contactID - * @access public - */ - public $contactID = false; - - - /* - * Constructor - * - * This contructor performs the work for this model. This model returns - * an array containing the following. - * - * 'status' - * - * True if successfull and false if there was a fatal failure. - * - * 'view' - * - * A suggested view name that the contoller should use instead of the - * default view for this model or false to indicate that the default view - * should be used. - * - * 'data' - * - * Data that the model is returning for use in merging with the view to - * produce output. - * - * @wpdb object WordPress database object - * - * @return array Array containing status, suggested view, and any data - */ - public function __construct ($wpdb, $config) - { - - // Save WordPress Database object - $this->wpdb = $wpdb; - - // Save plugin configuration object - $this->config = $config; - - /* - * Run constructor for the Contacts data class - * - * Note, the third parameter is a flag that indicates to the Contacts - * data class that it should flag a group of fields as 'view_only'. - */ -// parent::__construct(false, false, true); - - - } - - public function modelAction($actionData = false) - { - - $displayData = 'Hello, World! This is the Sample Add-On "sample" model talking to you from inside WordPress.'; - - // Compile template data - $templateData = array( - 'displayData' => $displayData - ); - - // Return status, any suggested view, and any data to controller - return array( - 'status' => true, - 'modelRedirect' => false, - 'view' => 'admin/sample/index.html', - 'data' => $templateData - ); - - } - - -} diff --git a/models/admin/sample/more.php b/models/admin/sample/more.php deleted file mode 100644 index b814759..0000000 --- a/models/admin/sample/more.php +++ /dev/null @@ -1,125 +0,0 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ - * @link http://dev.gaslightmedia.com/ - */ - -// Load Contacts data abstract -//require_once(GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataContacts.php'); - -class GlmMembersAdmin_sample_more // extends GlmDataContacts -{ - - /** - * WordPress Database Object - * - * @var $wpdb - * @access public - */ - public $wpdb; - /** - * Plugin Configuration Data - * - * @var $config - * @access public - */ - public $config; - /** - * Contact Info - * - * @var $contactInfo - * @access public - */ - public $contactInfo = false; - /** - * Member ID - * - * @var $memberID - * @access public - */ - public $memberID = false; - /** - * Contact ID - * - * @var $contactID - * @access public - */ - public $contactID = false; - - - /* - * Constructor - * - * This contructor performs the work for this model. This model returns - * an array containing the following. - * - * 'status' - * - * True if successfull and false if there was a fatal failure. - * - * 'view' - * - * A suggested view name that the contoller should use instead of the - * default view for this model or false to indicate that the default view - * should be used. - * - * 'data' - * - * Data that the model is returning for use in merging with the view to - * produce output. - * - * @wpdb object WordPress database object - * - * @return array Array containing status, suggested view, and any data - */ - public function __construct ($wpdb, $config) - { - - // Save WordPress Database object - $this->wpdb = $wpdb; - - // Save plugin configuration object - $this->config = $config; - - /* - * Run constructor for the Contacts data class - * - * Note, the third parameter is a flag that indicates to the Contacts - * data class that it should flag a group of fields as 'view_only'. - */ -// parent::__construct(false, false, true); - - - } - - public function modelAction($actionData = false) - { - - $displayData = 'Welcome to more information!
This is the Sample Add-On "sample" model with action "more" talking to you from inside WordPress.'; - - // Compile template data - $templateData = array( - 'displayData' => $displayData - ); - - // Return status, any suggested view, and any data to controller - return array( - 'status' => true, - 'modelRedirect' => false, - 'view' => 'admin/sample/more.html', - 'data' => $templateData - ); - - } - - -} diff --git a/models/front/readme.txt b/models/front/readme.txt deleted file mode 100644 index 4c54852..0000000 --- a/models/front/readme.txt +++ /dev/null @@ -1,7 +0,0 @@ -The front controller executes models under this directory. - -Typically you should add a directory here that matches the category of actions that will take place. - -Under that directory place the model for the various actions. - -Actions under this directory would normally be called due to processing of a shortcode. \ No newline at end of file diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 6e7ad8e..e81f3ea 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -25,3 +25,17 @@ * * Also note that parameters will be in the context of the main admin controller constructor. */ + + +// Add server stats summary and graphs to main dashboard widget +add_filter( 'glm-member-db-dashboard-widget-othernotices', function( $content ) { + $content .= $this->controller('dashboardWidget', 'serverStats', array('location' => 'widget')); + return $content; +}); + +// Add server stats summary and graphs to members dashboard +add_filter( 'glm-member-db-members-othernotices', function( $content ) { + $content .= $this->controller('dashboardWidget', 'serverStats', array('location' => 'members')); + return $content; +}); + diff --git a/setup/adminTabs.php b/setup/adminTabs.php index f280609..0cd596f 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -33,3 +33,18 @@ * */ +if (apply_filters('glm_members_permit_admin_members_serverStats_tab', true)) { + add_filter('glm-member-db-add-tab-for-management', + function($addOnTabs) { + $newTabs = array( + array( + 'text' => 'Server Stats', + 'menu' => 'management', + 'action' => 'serverStats' + ) + ); + $addOnTabs = array_merge($addOnTabs, $newTabs); + return $addOnTabs; + } + ); +} diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql index 2fff825..5d7fb94 100644 --- a/setup/databaseScripts/create_database_V0.0.1.sql +++ b/setup/databaseScripts/create_database_V0.0.1.sql @@ -1,19 +1,28 @@ --- Gaslight Media Members Database - ServerStats +-- Gaslight Media Members Database - Search -- File Created: 12/02/15 15:27:15 -- Database Version: 0.0.1 -- Database Creation Script -- --- This file is called to create a new set of tables for this --- add-on for the most receint database version for this add-on. --- --- There should only be one such file in this directory --- -- To permit each query below to be executed separately, -- all queries must be separated by a line with four dashes --- ServerStats Table -CREATE TABLE {prefix}serverstats ( +-- Server Stats Management Settings +CREATE TABLE {prefix}management ( id INT NOT NULL AUTO_INCREMENT, - somefield TINYTEXT NULL, + enabled BOOLEAN NULL, -- Server Stats Enabled flag + db_name TINYTEXT NULL, -- Name of database with bandwidth data + db_host TINYTEXT NULL, -- Host name of database server + db_user TINYTEXT NULL, -- User name for database + db_pass TINYTEXT NULL, -- Password for access to database + website TINYTEXT NULL, -- Website name as used in database PRIMARY KEY (id) ); + +---- + +-- Set default Server Stats entry +INSERT INTO {prefix}management + ( id, enabled, db_name, db_host, db_user, db_pass, website ) + VALUES + ( 1, true, 'bandwidth', 'angelia.gaslightmedia.com', 'bandwidthRO', ',Wv4W*~^bL_vF3F4PbGsS', '' ) +; diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index a81daa9..adefd76 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -1,7 +1,7 @@ array('version' => '0.0.1', 'tables' => 1, 'date' => '7/26/2016') + '0.0.1' => array('version' => '0.0.1', 'tables' => 1, 'date' => '8/19/16'), ); diff --git a/setup/databaseScripts/drop_database_V0.0.1.sql b/setup/databaseScripts/drop_database_V0.0.1.sql deleted file mode 100644 index f04ce11..0000000 --- a/setup/databaseScripts/drop_database_V0.0.1.sql +++ /dev/null @@ -1,12 +0,0 @@ --- Gaslight Media Members Database --- File Created: 12/09/14 15:27:15 --- Database Version: 1.1.5 --- Database Deletion Script --- Note: Tables with DELETE CASCADE must appear before referenced table --- --- Multiple tables may be separated by ",". - -DROP TABLE IF EXISTS - {prefix}sometablename -; - diff --git a/setup/validActions.php b/setup/validActions.php index 4940241..d143015 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -32,6 +32,15 @@ $glmMembersServerStatsAddOnValidActions = array( 'adminActions' => array( + 'ajax' => array( + 'serverBandwidthGraphs' => GLM_MEMBERS_SERVERSTATS_PLUGIN_SLUG + ), + 'dashboardWidget' => array( + 'serverStats' => GLM_MEMBERS_SERVERSTATS_PLUGIN_SLUG + ), + 'management' => array( + 'serverStats' => GLM_MEMBERS_SERVERSTATS_PLUGIN_SLUG + ), ), 'frontActions' => array( ) diff --git a/views/admin/dashboardWidget/serverStats.html b/views/admin/dashboardWidget/serverStats.html new file mode 100644 index 0000000..07502d7 --- /dev/null +++ b/views/admin/dashboardWidget/serverStats.html @@ -0,0 +1,119 @@ +{if $serverStatsEnabled} +{if $serverStats} + +{if $location == 'widget'} +

+ Server Bandwidth + +

+ + + + + + + + + + + + + + +
Today: + {$serverStats.today.data_total|round:3} Megabytes
+
This Month: + {$serverStats.thisMonth.data_total|round:3} Gigabytes
+
Last Month: + {$serverStats.lastMonth.data_total|round:3} Gigabytes +
+{else} + + + + + + + + + + +
+ Server Bandwidth + + Today: + {$serverStats.today.data_total|round:3} Megabytes
+
This Month: + {$serverStats.thisMonth.data_total|round:3} Gigabytes
+
Last Month: + {$serverStats.lastMonth.data_total|round:3} Gigabytes +
+{/if} + + +
+
+

{$glmSiteTitle}

+

+ {$thisDate} + Server Bandwidth Stats for Today - Megabytes +

+ +

+ {$thisDate} + Server Bandwidth Stats for this Month - Gigabytes +

+ +

+ {$thisDate} + Server Bandwidth Stats for 2 Years - Gigabytes +

+ +
Color Key: Incoming, Outgoing, Total
+
+
Print
+
+ + + + +{else} +

NOTE: Unable to connect to server stats database!

+Check Server Stats Management setting
+{/if} +{/if} \ No newline at end of file diff --git a/views/admin/info/index.html b/views/admin/info/index.html deleted file mode 100644 index eab9b97..0000000 --- a/views/admin/info/index.html +++ /dev/null @@ -1,6 +0,0 @@ -
-
-

Info Sub-menu Model

-

{$displayData}

-
-
\ No newline at end of file diff --git a/views/admin/management/serverStats.html b/views/admin/management/serverStats.html new file mode 100644 index 0000000..7fdd3c8 --- /dev/null +++ b/views/admin/management/serverStats.html @@ -0,0 +1,78 @@ +{include file='admin/management/header.html'} + + {if $dbError != ''} +

Unable to test database connection!

+

Error reported: {$dbError}

+ {/if} +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {if $settingsUpdated}

Settings Updated

{/if} + {if $settingsUpdateError}Settings Update Error{/if} +

General Server Stats Settings

+
Enabled: + +
Database Name: + + {if $serverStatsSettings.fieldFail.db_name}

{$serverStatsSettings.fieldFail.db_name}

{/if} +
Database Server Hostname: + + {if $serverStatsSettings.fieldFail.db_host}

{$serverStatsSettings.fieldFail.db_host}

{/if} +
Database Username: + + {if $serverStatsSettings.fieldFail.db_user}

{$serverStatsSettings.fieldFail.db_user}

{/if} +
Database Password: + + {if $serverStatsSettings.fieldFail.db_pass}

{$serverStatsSettings.fieldFail.db_pass}

{/if} +
Website Name: + +
This is the name of the Website as it's listed in the server stats database. Normally does not include 'www'. + {if $serverStatsSettings.fieldFail.website}

{$serverStatsSettings.fieldFail.website}

{/if} +
+ +
+ + + +{include file='admin/footer.html'} diff --git a/views/admin/members/sample.html b/views/admin/members/sample.html deleted file mode 100644 index cb7795a..0000000 --- a/views/admin/members/sample.html +++ /dev/null @@ -1,6 +0,0 @@ -{include file='admin/members/header.html'} - -

{$terms.term_member_plur_cap} Sample Tab

-

{$displayData}

- -{include file='admin/footer.html'} \ No newline at end of file diff --git a/views/admin/readme.txt b/views/admin/readme.txt deleted file mode 100644 index 5a9d7ea..0000000 --- a/views/admin/readme.txt +++ /dev/null @@ -1,5 +0,0 @@ -The admin controller uses views (templates) under this directory to generate final output. - -Typically you should add a directory here that matches the page where the view is used. - -Under that directory place the view (template) for the various actions. \ No newline at end of file diff --git a/views/admin/sample/index.html b/views/admin/sample/index.html deleted file mode 100644 index 4185932..0000000 --- a/views/admin/sample/index.html +++ /dev/null @@ -1,7 +0,0 @@ -
-
-

Sample Model

-

{$displayData}

- Click me to see more! -
-
\ No newline at end of file diff --git a/views/admin/sample/more.html b/views/admin/sample/more.html deleted file mode 100644 index 5e1c19a..0000000 --- a/views/admin/sample/more.html +++ /dev/null @@ -1,6 +0,0 @@ -
-
-

Sample Model - More Information

-

{$displayData}

-
-
\ No newline at end of file diff --git a/views/front/readme.txt b/views/front/readme.txt deleted file mode 100644 index 1138d90..0000000 --- a/views/front/readme.txt +++ /dev/null @@ -1,7 +0,0 @@ -The front controller uses views (templates) under this directory to generate final output. - -Typically you should add a directory here that matches the category of actions that will use these views. - -Under that directory place the view (template) for the various actions. - -Views under this directory would normally be called due to processing of a shortcode. \ No newline at end of file