Finished development of Server Stats initial features.
authorChuck Scott <cscott@gaslightmedia.com>
Mon, 22 Aug 2016 18:36:32 +0000 (14:36 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Mon, 22 Aug 2016 18:36:32 +0000 (14:36 -0400)
Added management features for Server Stats.
Added more tests and failure messages for access to server stats database.

27 files changed:
classes/data/dataManagement.php [new file with mode: 0644]
classes/data/dataServerStats.php [deleted file]
classes/serverBandwidthSupport.php [new file with mode: 0644]
index.php
models/admin/ajax/serverBandwidthGraphs.php [new file with mode: 0644]
models/admin/dashboardWidget/serverStats.php [new file with mode: 0644]
models/admin/info/index.php [deleted file]
models/admin/management/serverStats.php [new file with mode: 0644]
models/admin/members/sample.php [deleted file]
models/admin/readme.txt [deleted file]
models/admin/sample/index.php [deleted file]
models/admin/sample/more.php [deleted file]
models/front/readme.txt [deleted file]
setup/adminHooks.php
setup/adminTabs.php
setup/databaseScripts/create_database_V0.0.1.sql
setup/databaseScripts/dbVersions.php
setup/databaseScripts/drop_database_V0.0.1.sql [deleted file]
setup/validActions.php
views/admin/dashboardWidget/serverStats.html [new file with mode: 0644]
views/admin/info/index.html [deleted file]
views/admin/management/serverStats.html [new file with mode: 0644]
views/admin/members/sample.html [deleted file]
views/admin/readme.txt [deleted file]
views/admin/sample/index.html [deleted file]
views/admin/sample/more.html [deleted file]
views/front/readme.txt [deleted file]

diff --git a/classes/data/dataManagement.php b/classes/data/dataManagement.php
new file mode 100644 (file)
index 0000000..68a4f3c
--- /dev/null
@@ -0,0 +1,171 @@
+<?php
+/**
+ * GLM Member-DB WordPress Add-On Plugin
+ * Server Stats Management data class
+ *
+ * PHP version 5.3
+ *
+ * @category Data
+ * @package  GLM Member-DB
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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 <cscott@gaslightmedia.com>
+ * @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 (file)
index f373fb3..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-<?php
-/**
- * GLM Member-DB WordPress Add-On Plugin
- * Data Class ServerStats
- *
- * PHP version 5.3
- *
- * @category Data
- * @package  GLM Member-DB
- * @author   Chuck Scott <cscott@gaslightmedia.com>
- * @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 <cscott@gaslightmedia.com>
- * @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 (file)
index 0000000..24f4637
--- /dev/null
@@ -0,0 +1,268 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Server Bandwidth Support Abstract
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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
index cdd3866..cccb1b9 100644 (file)
--- 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 (file)
index 0000000..a845f7e
--- /dev/null
@@ -0,0 +1,136 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Server Bandwidth Stats by AJAX
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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 (file)
index 0000000..d3528ca
--- /dev/null
@@ -0,0 +1,161 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Member Server Stats for Member Dashboard Page
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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 (file)
index 4c61edb..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-<?php
-/**
- * Gaslight Media Members Database
- * Admin Member User Profile
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package  glmMembersDatabase
- * @author   Chuck Scott <cscott@gaslightmedia.com>
- * @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 (file)
index 0000000..6dc8ff9
--- /dev/null
@@ -0,0 +1,178 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Server Stats Add-on - Management Server Stats Tab
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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 <cscott@gaslightmedia.com>
+ * @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("<b>&nbsp;&nbsp;/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 (file)
index c9cd6ca..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-/**
- * Gaslight Media Members Database
- * Admin Member User Profile
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package  glmMembersDatabase
- * @author   Chuck Scott <cscott@gaslightmedia.com>
- * @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 (file)
index e9a199d..0000000
+++ /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 (file)
index 5c321df..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-<?php
-/**
- * Gaslight Media Members Database
- * Admin Member User Profile
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package  glmMembersDatabase
- * @author   Chuck Scott <cscott@gaslightmedia.com>
- * @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 (file)
index b814759..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-<?php
-/**
- * Gaslight Media Members Database
- * Admin Member User Profile
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package  glmMembersDatabase
- * @author   Chuck Scott <cscott@gaslightmedia.com>
- * @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!<br>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 (file)
index 4c54852..0000000
+++ /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
index 6e7ad8e..e81f3ea 100644 (file)
  *
  *  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;
+});
+
index f280609..0cd596f 100644 (file)
  *
  */
 
+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;
+        }
+    );
+}
index 2fff825..5d7fb94 100644 (file)
@@ -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', '' )
+;
index a81daa9..adefd76 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * Gaslight Media Members Database
- * GLM Members ServerStats DB Versions
+ * GLM Members Server Stats DB Versions
  *
  * PHP version 5.5
  *
@@ -14,6 +14,6 @@
  */
 
 $glmMembersServerStatsDbVersions = array(
-            '0.0.1' => 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 (file)
index f04ce11..0000000
+++ /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
-;
-
index 4940241..d143015 100644 (file)
 
 $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 (file)
index 0000000..07502d7
--- /dev/null
@@ -0,0 +1,119 @@
+{if $serverStatsEnabled}
+{if $serverStats}
+
+{if $location == 'widget'}  
+<h3>
+    Server Bandwidth
+    <a style="margin-left: 2em;" data-type="serverStats" class="dialog-button" href=""><img src="{$assetsUrl}/graph.png"></a>
+</h3>   
+
+<table class="glm-admin-table">
+    <tr>
+        <th>Today: </th>
+        <td>
+            {$serverStats.today.data_total|round:3} Megabytes<br>
+        </td>
+    </tr>
+    <tr>
+        <th>This Month: </th>
+        <td>
+            {$serverStats.thisMonth.data_total|round:3} Gigabytes<br>
+        </td>
+    </tr>
+    <tr>
+        <th>Last Month: </th>
+        <td>
+            {$serverStats.lastMonth.data_total|round:3} Gigabytes
+        </td>
+    </tr>
+</table>
+{else}
+<table class="glm-admin-table">
+    <tr>
+        <th>
+                Server Bandwidth
+                <a style="margin-left: 2em;" data-type="serverStats" class="dialog-button" href=""><img src="{$assetsUrl}/graph.png"></a>
+        </th>
+        <th>Today: </th>
+        <td>
+            {$serverStats.today.data_total|round:3} Megabytes<br>
+        </td>
+        <th>This Month: </th>
+        <td>
+            {$serverStats.thisMonth.data_total|round:3} Gigabytes<br>
+        </td>
+        <th>Last Month: </th>
+        <td>
+            {$serverStats.lastMonth.data_total|round:3} Gigabytes
+        </td>
+    </tr>
+</table>
+{/if}
+
+<!-- Server Bandwidth Stats One Day Graph -->
+<div id="serverStats" class="graph-dialog glm-dialog-box" title="Server Bandwidth">
+    <div id="StatsPrintArea" class="PrintArea" style="padding: 10px;">
+        <center><h3>{$glmSiteTitle}</h3></center>
+        <p>
+            <span class="glm-right">{$thisDate}</span>
+            <span class="glm-left">Server Bandwidth Stats for Today - Megabytes</span>
+        </p>
+        <img src="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=serverBandwidthGraphs&graphType=twoDay">
+        <p>
+            <span class="glm-right">{$thisDate}</span>
+            <span class="glm-left">Server Bandwidth Stats for this Month - Gigabytes</span>
+        </p>
+        <img src="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=serverBandwidthGraphs&graphType=twoMonth">
+        <p>
+            <span class="glm-right">{$thisDate}</span>
+            <span class="glm-left">Server Bandwidth Stats for 2 Years - Gigabytes</span>
+        </p>
+        <img src="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=serverBandwidthGraphs&graphType=twoYear">
+        <center>Color Key: <span style="color: red;">Incoming</span>, <span style="color: green;">Outgoing</span>, <span style="color: blue;">Total</span></center>
+    </div>
+    <div class="button button-secondary graph-print glm-right" data-areaToPrint="StatsPrintArea">Print</div>
+</div>
+
+<script src="{$jsUrl}/PrintArea/jquery.PrintArea.js" type="text/JavaScript" language="javascript"></script>
+
+<script type="text/javascript">
+    jQuery(document).ready(function($) {
+
+        // Create graph dialog boxes
+        $(".graph-dialog").dialog({
+            autoOpen: false,
+            minWidth: 1200
+        });
+
+        $("div.graph-print").click(function(){
+            var areaToPrint = $(this).attr('data-areaToPrint');
+            var position = $(this).offset();
+            $('#' + areaToPrint).printArea({
+                mode:       'popup',        //printable window is either iframe or browser popup
+                popHt:      500,            // popup window height
+                popWd:      1200,            // popup window width
+                popX:       200,            // popup window screen X position
+                popY:       200,            //popup window screen Y position
+                popTitle:   'Graph Print Window',   // popup window title element
+                popClose:   true,           // popup window close after printing
+                extraCss:   '',             // Comma separated list of extra css to include
+                extraHead:  '',             // Comma separated list of extra elements to be appended to head tag
+                strict:     false           // strict or looseTransitional html 4.01 document standard or undefined to not include at all only for popup option
+            });
+       });
+
+        // Display selected graph dialog box
+        $('.dialog-button').click( function() {
+            $(".graph-dialog").dialog("close");
+            var graph = $(this).attr('data-type');
+            $('#' + graph).dialog("open");
+            return false;
+        });
+
+    });
+</script>
+{else}
+<h3><span class="glm-error">NOTE:</span> Unable to connect to server stats database!</h3>
+Check Server Stats Management setting<br>
+{/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 (file)
index eab9b97..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<div class="wrap">
-    <div id="glm-admin-content-container">
-        <h3>Info Sub-menu Model</h3>
-        <p>{$displayData}</p>
-    </div>
-</div>
\ No newline at end of file
diff --git a/views/admin/management/serverStats.html b/views/admin/management/serverStats.html
new file mode 100644 (file)
index 0000000..7fdd3c8
--- /dev/null
@@ -0,0 +1,78 @@
+{include file='admin/management/header.html'}
+
+    {if $dbError != ''}
+    <h2 class="glm-error">Unable to test database connection!</h2>
+    <p><b>Error reported:</b> {$dbError}</p>
+    {/if}    
+    <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+        <input type="hidden" name="glm_action" value="serverStats">
+        <input type="hidden" name="option" value="submit">
+        
+        <table class="glm-admin-table">
+        
+            <!-- Settings for talking with the Bandwidth Database -->
+        
+            <tr>
+                <td colspan="2">
+                    {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
+                    {if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
+                    <h2>General Server Stats Settings</h2>
+                </td>
+            </tr>
+            <tr>
+                <th>Enabled:</th>
+                <td>
+                    <input type="checkbox" name="enabled"{if $serverStatsSettings.fieldData.enabled.value} checked="checked"{/if}>
+                </td>
+            </tr>
+            <tr>
+                <th {if $serverStatsSettings.fieldRequired.db_name}class="glm-required"{/if}>Database Name:</th>
+                <td {if $serverStatsSettings.fieldFail.db_name}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
+                    <input type="text" name="db_name" value="{$serverStatsSettings.fieldData.db_name}" class="glm-form-text-input-medium">
+                    {if $serverStatsSettings.fieldFail.db_name}<p>{$serverStatsSettings.fieldFail.db_name}</p>{/if}
+                </td>
+            </tr>
+            <tr>
+                <th {if $serverStatsSettings.fieldRequired.db_host}class="glm-required"{/if}>Database Server Hostname:</th>
+                <td {if $serverStatsSettings.fieldFail.db_host}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
+                    <input type="text" name="db_host" value="{$serverStatsSettings.fieldData.db_host}" class="glm-form-text-input-medium">
+                    {if $serverStatsSettings.fieldFail.db_host}<p>{$serverStatsSettings.fieldFail.db_host}</p>{/if}
+                </td>
+            </tr>
+            <tr>
+                <th {if $serverStatsSettings.fieldRequired.db_user}class="glm-required"{/if}>Database Username:</th>
+                <td {if $serverStatsSettings.fieldFail.db_user}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
+                    <input type="text" name="db_user" value="{$serverStatsSettings.fieldData.db_user}" class="glm-form-text-input-medium">
+                    {if $serverStatsSettings.fieldFail.db_user}<p>{$serverStatsSettings.fieldFail.db_user}</p>{/if}
+                </td>
+            </tr>
+            <tr>
+                <th {if $serverStatsSettings.fieldRequired.db_pass}class="glm-required"{/if}>Database Password:</th>
+                <td {if $serverStatsSettings.fieldFail.db_pass}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
+                    <input type="text" name="db_pass" value="{$serverStatsSettings.fieldData.db_pass}" class="glm-form-text-input-medium">
+                    {if $serverStatsSettings.fieldFail.db_pass}<p>{$serverStatsSettings.fieldFail.db_pass}</p>{/if}
+                </td>
+            </tr>
+            <tr>
+                <th {if $serverStatsSettings.fieldRequired.website}class="glm-required"{/if}>Website Name:</th>
+                <td {if $serverStatsSettings.fieldFail.website}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
+                    <input type="text" name="website" value="{$serverStatsSettings.fieldData.website}" class="glm-form-text-input-medium">
+                    <br>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}<p>{$serverStatsSettings.fieldFail.website}</p>{/if}
+                </td>
+            </tr>
+        </table>
+        <input type="submit" value="Update Settings" class="button-primary">
+    </form>
+    
+    <script type="text/javascript">
+        
+        jQuery(document).ready(function($) {
+
+            // Flash certain elements for a short time after display      
+            $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+                    
+        });
+    </script>
+
+{include file='admin/footer.html'}
diff --git a/views/admin/members/sample.html b/views/admin/members/sample.html
deleted file mode 100644 (file)
index cb7795a..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-{include file='admin/members/header.html'}
-    
-    <h3>{$terms.term_member_plur_cap} Sample Tab</h3>
-    <p>{$displayData}</p>
-        
-{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 (file)
index 5a9d7ea..0000000
+++ /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 (file)
index 4185932..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<div class="wrap">
-    <div id="glm-admin-content-container">
-        <h3>Sample Model</h3>
-        <p>{$displayData}</p>
-        <a href="{$thisUrl}?page={$thisPage}&glm_action=more">Click me to see more!</a>
-    </div>
-</div>
\ No newline at end of file
diff --git a/views/admin/sample/more.html b/views/admin/sample/more.html
deleted file mode 100644 (file)
index 5e1c19a..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<div class="wrap">
-    <div id="glm-admin-content-container">
-        <h3>Sample Model - More Information</h3>
-        <p>{$displayData}</p>
-    </div>
-</div>
\ No newline at end of file
diff --git a/views/front/readme.txt b/views/front/readme.txt
deleted file mode 100644 (file)
index 1138d90..0000000
+++ /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