Database list enhancement in Management sub-menu
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 14 Jan 2016 19:48:17 +0000 (14:48 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 14 Jan 2016 19:48:17 +0000 (14:48 -0500)
activate.php
classes/glmPluginSupport.php
config.php
controllers/admin.php
controllers/front.php
deactivate.php
defines.php
glm-member-db.php
models/admin/management/development.php
uninstall.php
views/admin/management/development.html

index db36506..d02f2f0 100644 (file)
@@ -276,8 +276,4 @@ class glmMembersPluginActivate extends glmPluginSupport
 
     }
 
-
-
 }
-
-?>
index b8039ae..9bf0d45 100644 (file)
@@ -204,7 +204,7 @@ class GlmPluginSupport
                     $existingTables = $this->wpdb->get_var("
                         SELECT COUNT(*)
                           FROM information_schema.tables
-                         WHERE  table_schema = '".DB_NAME."'
+                         WHERE table_schema = '".DB_NAME."'
                            AND table_name like '$prefixEscaped%';
                     ");
 
@@ -359,7 +359,9 @@ class GlmPluginSupport
                     }
 
                 } else {
-                    $this->addNotice('The '.GLM_MEMBERS_PLUGIN_NAME.' has been reactivated using the existing database tables.');
+                    if ($option == 'install') {
+                        $this->addNotice('The '.$a['name'].' plugin/add-on has been reactivated using the existing database tables.');
+                    }
                     $db_setup_status = true;
                 }
 
@@ -378,5 +380,3 @@ class GlmPluginSupport
     }
 
 }
-
-?>
\ No newline at end of file
index 7284d12..f10cd48 100644 (file)
@@ -44,5 +44,3 @@ if (file_exists($currentThemeDirectory.'/glm-member-db/plugin.ini')) {
     $config = array_replace($config, $themeIni);
 
 }
-
-?>
index 905423a..7c1f010 100644 (file)
@@ -129,7 +129,7 @@ class glmMembersAdmin extends GlmPluginSupport
         $this->config = $config;
 
         // Check the database - allow installation of tables for a new add-on
-        if (!$this->checkDatabase('install')) {
+        if (!$this->checkDatabase()) {
             die('Database check failure');
         }
 
@@ -857,5 +857,3 @@ class glmMembersAdmin extends GlmPluginSupport
     }
 
 }
-
-
index 0f6daed..b123947 100644 (file)
@@ -53,7 +53,7 @@ class glmMembersFront extends GlmPluginSupport
         $this->config = $config;
 
         // Check the database - allow installation of tables for a new add-on
-        if (!$this->checkDatabase('install')) {
+        if (!$this->checkDatabase()) {
             die('Database check failure');
         }
 
@@ -488,4 +488,3 @@ class glmMembersFront extends GlmPluginSupport
 
     }
 }
-?>
\ No newline at end of file
index 6d62b89..dd5e3ec 100644 (file)
@@ -103,5 +103,3 @@ class glmMembersPluginDeactivate extends glmPluginSupport
         }
     }
 }
-
-?>
\ No newline at end of file
index de45129..17fce4c 100644 (file)
@@ -61,4 +61,3 @@ global $wpdb;
 define('GLM_MEMBERS_PLUGIN_DB_PREFIX', $wpdb->prefix.'glm_members_');
 define('GLM_MEMBERS_PLUGIN_ACTIVE_DB_OPTION', 'glmMembersDatabaseDbVersion');
 
-?>
index 3cdce83..77a5b0d 100644 (file)
@@ -200,6 +200,11 @@ $startupNotices = '';
 // Get standard defined parameters
 require_once('defines.php');
 
+// Check if plugin version is not current in WordPress option and if needed updated it
+if (GLM_MEMBERS_PLUGIN_VERSION != get_option('glmMembersDatabasePluginVersion')) {
+    update_option('glmMembersDatabasePluginVersion', GLM_MEMBERS_PLUGIN_VERSION);
+}
+
 // Get configuration
 require_once('config.php');
 
@@ -389,12 +394,14 @@ if (function_exists('is_user_logged_in')) {
  *
  * Determine which controller to load
  *
- * The first is for displaying notices in another window, possibly for debug output.
- *
  */
+
+// If the call to this code is to display a separate debug window
 if (isset($_REQUEST['glmDebugWindow']) && $_REQUEST['glmDebugWindow'] == true) {
     glmMembersAdminNotices(true);
     exit;
+
+// Otherwise select appropriate controller
 } elseif (is_admin()) {
     require_once (GLM_MEMBERS_PLUGIN_PATH . '/controllers/admin.php');
     new glmMembersAdmin($wpdb, $config);
@@ -519,16 +526,6 @@ function glmMembersAdminNotices($windowed = true)
 
 }
 
-/*
- * If not doing debug, then just keep all of the debug messages cleared
- */
-if (!GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
-    delete_option('glmMembersAdminNoticeAlerts');
-    delete_option('glmMembersAdminNotices');
-    delete_option('glmMembersAdminNoticeProcess');
-    delete_option('glmMembersAdminNoticeDataBlocks');
-}
-
 /*
  * Check if there's any startup notices in this file. (stuff that happens before we get all setup)
  *
@@ -539,7 +536,7 @@ function glmMembersStartupNotices() {
     echo '<div class="updated"><h3>'.GLM_MEMBERS_PLUGIN_NAME.' Plugin Warning</h3><p>'.$startupNotices.'</p></div>';
 }
 if ($startupNotices != '') {
-    add_action('admin_notices','glmMembersStartupNotices');
+    //add_action('admin_notices','glmMembersStartupNotices');
 }
 
 /*
@@ -552,12 +549,20 @@ if ($startupNotices != '') {
  * addNotice() function in the classes/glmPluginSupport.php file. Should have addNotice()
  * function be able to add to another option specifically for doing this.
  */
-$notices = get_option('glmMembersAdminNotices');
-if (is_admin() && $notices && !GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
 
-    // Add action to output the notices
+// Check for any notices that need to display at the top of an admin screen
+$notices = get_option('glmMembersAdminNotices');
+if (is_admin() && $notices) {
     add_action('admin_notices','glmMembersAdminNotices');
+}
 
+/*
+ * If not doing debug, then just keep all of the debug messages cleared
+ */
+if (!GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+    delete_option('glmMembersAdminNoticeAlerts');
+//    delete_option('glmMembersAdminNotices');
+    delete_option('glmMembersAdminNoticeProcess');
+    delete_option('glmMembersAdminNoticeDataBlocks');
 }
 
-?>
index 23a2a76..c0f7b15 100644 (file)
@@ -93,19 +93,18 @@ class GlmMembersAdmin_management_development
     public function modelAction ($actionData = false)
     {
 
+        $resultMessage = '';
+        $success = false;
+        $haveMembers = false;
+        $import = false;
+        $importNotice = '';
+        $haveDatabaseTableList = false;
+        $databaseList = false;
+
         // Get current database version
         $dbVersion = GLM_MEMBERS_PLUGIN_DB_VERSION;
         settype($dbVersion, 'string');
 
-        $templateData['resultMessage'] = '';
-        $templateData['success'] = false;
-        $templateData['haveNotices'] = false;
-        $notices = array();
-        $templateData['haveMembers'] = false;
-        $templateData['import'] = false;
-        $templateData['importNotice'] = false;
-        $templateData['haveDatabaseTableList'] = false;
-
         // Load database activation class to get access to database version information
         require_once (GLM_MEMBERS_PLUGIN_PATH . '/activate.php');
         $activate = new glmMembersPluginActivate($this->wpdb, $this->config, true);
@@ -145,7 +144,7 @@ class GlmMembersAdmin_management_development
                             }
                         }
 
-                    $templateData['import'] = true;
+                    $import = true;
                     $templateData['membersImported'] = $Connections->doImport();
 
                 } else {
@@ -157,12 +156,12 @@ class GlmMembersAdmin_management_development
                         break;
                     }
                     $templateData['numbEntries'] = $c;
-                    $importNotice = 'Connections Business Directory plugin is active.<br>Number of businesses listed: '.$c.'<br>';
+                    $importNotice .= 'Connections Business Directory plugin is active.<br>Number of businesses listed: '.$c.'<br>';
 
                     // Get the basic business data for review.
                     $templateData['members'] = $Connections->getList();
                     if ($templateData['members'] === false) {
-                        $importNotice = 'No businesses were retieved.';
+                        $importNotice .= 'No businesses were retieved.<br>';
                         break;
                     }
 
@@ -210,13 +209,22 @@ class GlmMembersAdmin_management_development
 */
             case 'list':
 
+                $databaseList = array();
+
                 // For each plug-in in the registered add-on array (includes the main plugin) - Updated for plug-able database tables
                 foreach ($this->config['addOns'] as $a) {
 
-                    $templateData['resultMessage'] .= '<b>Current database tables for: '.$a['name'].'</b><br><div style="margin-left: 2em; margin-bottom: 2em;">';
+                    $databaseList[$a['name']] = array(
+                        'addonName' => $a['name'],
+                        'haveDatabase' => false
+                    );
 
                     if ($a['database'] ) {
 
+                        // Add add-on database info to list
+                        $databaseList[$a['name']] = array_merge_recursive($databaseList[$a['name']], $a['database']);
+                        $databaseList[$a['name']]['haveDatabase'] = true;
+
                         // Since MYSQL considers an underscore (_) to be a single character wild-card, we need to escape them.
                         $prefixEscaped = str_replace('_', '\_', $a['database']['dbPrefix']);
 
@@ -224,21 +232,33 @@ class GlmMembersAdmin_management_development
                         $existingTables = $this->wpdb->get_results("
                             SELECT table_name
                               FROM information_schema.tables
-                             WHERE table_name like '".$prefixEscaped."%';
+                             WHERE table_schema = '".DB_NAME."'
+                               AND table_name like '".$prefixEscaped."%';
                         ", ARRAY_A);
 
+                        // If we have a good list of tables
                         if (is_array($existingTables)) {
-                            foreach($existingTables as $t){
-                                $templateData['resultMessage'] .= $t['table_name'].'<br>';
+
+                            // Check for request to list a table's fields
+                            if (isset($_REQUEST['descTable'])) {
+                                while (list ($k, $v) = each ($existingTables)) {
+                                   if ($_REQUEST['descTable'] == $v['table_name']) {
+                                       $existingTables[$k]['desctable'] = true;
+                                            $fields = $this->wpdb->get_results("
+                                                DESCRIBE ".$v['table_name']."
+                                            ", ARRAY_A);
+                                            $existingTables[$k]['tablefields'] = $fields;
+                                   }
+                                }
                             }
+
+                            $databaseList[$a['name']]['tables'] = $existingTables;
+
                         } else {
-                            $templateData['resultMessage'] .= '<b>No tables currently exist</b><br>';
+                            $databaseList[$a['name']]['tables'] = false;
                         }
-                    } else {
-                        $templateData['resultMessage'] .= '(This plugin/add-on does not have database tables.)<br>';
                     }
 
-                     $templateData['resultMessage'] .= '</div>';
                 }
 /*
                 // Check if the database version set for this plugin is invalid.
@@ -259,6 +279,14 @@ class GlmMembersAdmin_management_development
 
         }
 
+        $templateData['resultMessage'] = $resultMessage;
+        $templateData['success'] = $success;
+        $templateData['haveMembers'] = $haveMembers;
+        $templateData['importNotice'] = $importNotice;
+        $templateData['haveDatabaseTableList'] = $haveDatabaseTableList;
+        $templateData['databaseList'] = $databaseList;
+
+
         // Return status, suggested view, and data to controller
         return array(
             'status' => true,
@@ -363,5 +391,3 @@ class GlmMembersAdmin_management_development
     }
 
 }
-
-?>
\ No newline at end of file
index 49ffa27..273e378 100644 (file)
@@ -53,5 +53,3 @@ $sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql);
 // Removing the tables using the script
 global $wpdb;
 $wpdb->query($sql);
-
-?>
index b69636b..9687cbb 100644 (file)
         {$resultMessage}
     </div>
 {/if}    
+
+{if $databaseList}
+    <div>
+        <hr>
+        <h3>List of Database Tables</h3>
+  {foreach $databaseList as $d}
+        <div style="margin-left: 2em !important;">
+            <h4>{$d.addonName}</h4>
+            <div style="margin-left: 2em !important;">
+    {if $d.haveDatabase}
+                <table style="font-size: .9em;">
+                    <tr><th align="left">Prefix: </th><td>{$d.dbPrefix}</td></tr>
+                    <tr><th align="left">Current Version: </th><td>{$d.dbCurrentVersion}</td></tr>
+                    <tr>
+                        <th align="left" valign="top">Versions: </th>
+                        <td>
+                            <table style="font-size: .9em;">
+      {foreach $d.dbVersions as $v}
+                                <tr><th align="left">{$v.version}</th><td>Number of tables: {$v.tables}</td></tr>
+      {/foreach}                                
+                            </table>
+                        </td>
+                    </tr>
+                    <tr>
+                        <th align="left" valign="top">Tables: </th>
+                        <td>
+                            <table style="font-size: .9em;">
+      {foreach $d.tables as $t}
+                                <tr>
+                                    <td align="left"><a href="{$thisURL}?page={$thisPage}&glm_action=development&option=list&descTable={$t.table_name}">{$t.table_name}</a></td>
+                                </tr>
+        {if isset($t.desctable)}
+                                <tr><td>
+                                    <table style="margin-left: 2em;">
+          {foreach $t.tablefields as $f}
+                                        <tr><td>{$f.Field}</td><td>{$f.Type}</td></tr>
+          {/foreach}                                    
+                                    </table>
+                                </td></tr>
+        {/if}                                    
+      {/foreach}                                
+                            </table>
+                        </td>
+                    </tr>
+                </table>
+    {else}
+                (No database tables)
+    {/if}
+            </div>
+        </div>
+  {/foreach}
+    </div>
+{/if}
     
 {if $haveMembers}
     <script type="text/javascript">