Connection import ready for final testing.
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 7 May 2015 19:19:36 +0000 (15:19 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 7 May 2015 19:19:36 +0000 (15:19 -0400)
classes/glmMemberImportFromConnections.php
classes/glmPluginSupport.php
css/admin.css
glm-member-db.php
misc/smarty/templates_c/4c287ca0e4946b3d644e61950c851e98e8906d49.file.list.html.php
models/admin/configure/development.php
views/admin/configure/development.html

index 009b218..411f025 100644 (file)
@@ -64,6 +64,7 @@ class GlmMemberImportFromConnections
      */
     public function checkConnections()
     {
+
         // Check if Connections plugin is installed
         if (!is_plugin_active('connections/connections.php')) {
             return false;
@@ -138,18 +139,328 @@ class GlmMemberImportFromConnections
             $a = unserialize($v['options']);
             $list[$k]['options'] = $a;
 
+        }
+        return $list;
 
 
+    }
 
+    /*
+     * Import all members not marked as "Skip"
+     *
+     * Looks at "skip" POST parameter (array) for ID's that should be skipped.
+     *
+     * @return boolean
+     * @access public
+     */
+    public function doImport()
+    {
 
+        $list = $this->getList();
 
+        /*
+         * Create default member type
+         */
+        $memberTypeName = sanitize_text_field($_REQUEST['memberType']);
+        $sql = "
+            INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_type
+                (
+                name,
+                descr
+                )
+            VALUES
+                (
+                '$memberTypeName',
+                ''
+                )
+        ;";
+        $this->wpdb->query($sql);
+        $membTypeID = $this->wpdb->insert_id;
+        $queryError = $this->wpdb->last_error;
+        if ($queryError) {
+            glmMembersAdmin::addNotice('<b>Error when adding the default member type: Check following message.</b><br><pre>'.$queryError.'</pre>', 'AdminError');
+        }
 
+        /*
+         * Create default region
+         */
+        $regionName = sanitize_text_field($_REQUEST['region']);
+        $sql = "
+            INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."regions
+                (
+                name,
+                descr,
+                short_descr
+                )
+            VALUES
+                (
+                '$memberTypeName',
+                '',
+                ''
+                )
+        ;";
+        $this->wpdb->query($sql);
+        $regionID = $this->wpdb->insert_id;
+        $queryError = $this->wpdb->last_error;
+        if ($queryError) {
+            glmMembersAdmin::addNotice('<b>Error when adding the default region: Check following message.</b><br><pre>'.$queryError.'</pre>', 'AdminError');
         }
-        return $list;
 
+        /*
+         * For each member in listing
+         */
+        $membersImported = 0;
+        $cities = array();
+        foreach ($list as $m) {
+
+            // If we're not skipping this entry
+            if (!isset($_REQUEST['skip'][$m['id']])) {
+
+                echo "123  ".$m['id'];
+
+
+                /*
+                 * Create base Member Record
+                 */
+                $sql = "
+                    INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members
+                        (
+                        access,
+                        member_type,
+                        created,
+                        name
+                        )
+                    VALUES
+                        (
+                        ".$this->config['memb_access_numb']['Moderated'].",
+                        $membTypeID,
+                        '".$m['ts']."',
+                        '".$m['organization']."'
+                        )
+                ;";
+                $this->wpdb->query($sql);
+                $membID = $this->wpdb->insert_id;
+                $queryError = $this->wpdb->last_error;
+                if ($queryError) {
+                    glmMembersAdmin::addNotice('<b>Error when creating member: Check following message.</b><br><pre>'.$queryError.'</pre>', 'AdminError');
+                }
+
+                /*
+                 * Add a member information record
+                 */
+
+                // Get address data
+                reset($m['addresses']);
+                $addr = current($m['addresses']);
+
+                // Check if city has been created yet
+                if (!isset($cities[$addr['city']])) {
+
+                    // Create City
+                    /*
+                     * Create default region
+                     */
+                    $sql = "
+                        INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."cities
+                            (
+                            name
+                            )
+                        VALUES
+                            (
+                            '".$addr['city']."'
+                            )
+                    ;";
+                    $this->wpdb->query($sql);
+                    $cityID = $this->wpdb->insert_id;
+                    $queryError = $this->wpdb->last_error;
+                    if ($queryError) {
+                        glmMembersAdmin::addNotice('<b>Error when adding the default region: Check following message.</b><br><pre>'.$queryError.'</pre>', 'AdminError');
+                    }
+                    $cities[$addr['city']]  = $cityID;
+
+                }
+
+                // Get first link as URL
+                reset($m['links']);
+                $link = current($m['links']);
+                $url = $link['url'];
+
+                // Get phone numbers
+                $phone = '';
+                $toll_free = '';
+                foreach ($m['phone_numbers'] as $ph) {
+                    switch($ph['type']) {
+                        case 'workphone':
+                            $phone = $ph['number'];
+                            break;
+                        case 'homephone':
+                            $toll_free = $ph['number'];
+                            break;
+                        case 'workfax':
+                        case 'homefax':
+                        case 'cellphone':
+                            break;
+                    }
+                }
+
+                // Check for Logo
+                $logo = '';
+                if (isset($m['options']['logo'])) {
+                    $logoPath = $m['options']['logo']['meta']['path'];
+                    $logo = $this->storeImage($logoPath);
+                    if ($logo === false) {
+                        $logo = '';
+                    }
+                }
+
+                $t = date('Y-m-d H:i:s', time());
+                $sql = "
+                    INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info
+                        (
+                        member,
+                        member_name,
+                        status,
+                        reference_name,
+                        descr,
+                        short_descr,
+                        addr1,
+                        addr2,
+                        city,
+                        state,
+                        country,
+                        zip,
+                        lat,
+                        lon,
+                        region,
+                        phone,
+                        toll_free,
+                        url,
+                        logo,
+                        cc_type,
+                        notes,
+                        create_time,
+                        modify_time
+                        )
+                    VALUES
+                        (
+                        $membID,
+                        '".$m['organization']."',
+                        ".($m['status'] == 'approved' ?
+                                $this->config['status_numb']['Active'] :
+                                $this->config['status_numb']['Inactive']
+                        ).",
+                        'Imported from Connections Business Listing',
+                        '".$m['bio']."',
+                        '',
+                        '".$addr['line_1']."',
+                        '".$addr['line_2']."',
+                        $cityID,
+                        '".$addr['state']."',
+                        '".$addr['country']."',
+                        '".$addr['zipcode']."',
+                        ".$addr['latitude'].",
+                        ".$addr['longitude'].",
+                        $regionID,
+                        '$phone',
+                        '$toll_free',
+                        '$url',
+                        '$logo',
+                        0,
+                        '',
+                        '$t',
+                        '$t'
+                        )
+                ;";
+                $this->wpdb->query($sql);
+                $membID = $this->wpdb->insert_id;
+                $queryError = $this->wpdb->last_error;
+                if ($queryError) {
+                    glmMembersAdmin::addNotice('<b>Error when creating member: Check following message.</b><br><pre>'.$queryError.'</pre>', 'AdminError');
+                }
+
+                // Check for additional image
+/*
+                $image = '';
+                if (isset($m['options']['image'])) {
+                    $imagePath = $m['options']['image']['meta']['path'];
+                    $image = $this->storeImage($imagePath);
+                    if ($image === false) {
+                        $image = '';
+                    }
+                }
+*/
+
+                $membersImported++;
+            }
+
+        }
+
+        return $membersImported;
+    }
+
+    /*
+     * Store image and return image name
+     *
+     * @var string $image Source image location (not deleted)
+     *
+     * @return string Image name
+     * @access public
+     */
+
+    // If we have a good image
+    public function storeImage($image)
+    {
+
+        // Get new image using temporary file name
+        $newImage = wp_get_image_editor($image);
+
+        // If we have a good image
+        if ( ! is_wp_error( $newImage ) ) {
+
+            // Get the desired file name and add a timestamp to it to ensure that it's unique
+            $fInfo = pathinfo($image);
+            $newFilename = $fInfo['filename'].'_'.time().'.'.$fInfo['extension'];
+
+            // Get image temp file name - Not currently using, but should be using to check for resizing sanity
+            $size = $newImage->get_size();
+
+            // Try to store the image using that file name in the 'original' directory
+            $storedImage = $newImage->save( GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename );
+
+            // Now resize the images using $sizeArray
+            $sizes = $newImage->multi_resize($this->config['imageSizes']);
+
+            // Finally, move the files to the various size directories and rename them back to the correct name
+            while (list($k, $v) = each($this->config['imageSizes'])) {
+
+                // Check if size directory needs to be made
+                if (!file_exists(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k)) {
+                    mkdir(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k);
+                }
+
+                // If there's an entry in the $sizes array, it means that the image resized to this size
+                if (isset($sizes[$k])) {
+
+                    // Move resized file to desired direectory
+                    rename(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$sizes[$k]['file'], GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename);
+
+                } else {
+
+                    // Image didn't resize to this size, probably because it was smaller than the destination size (silly WP Image Editor class) - so just use the original
+                    copy(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename, GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename);
+
+                }
+            }
+
+        } else {
+            return false;
+        }
+
+        return $newFilename;
 
     }
 
+
 }
 
 ?>
\ No newline at end of file
index 7be41a5..71e599e 100644 (file)
@@ -62,6 +62,30 @@ class GlmPluginSupport
                 update_option('glmMembersAdminNoticeDataBlocks', $dataBlocks);
                 break;
 
+            case 'AdminNotice':
+                echo '
+                    <div class="updated">
+                        <p>'.$message.'</p>
+                    </div>
+                ';
+                break;
+
+            case 'AdminError':
+                echo '
+                    <div class="error">
+                        <p>'.$message.'</p>
+                    </div>
+                ';
+                break;
+
+            case 'AdminNag':
+                echo '
+                    <div class="update-nag">
+                        <p>'.$message.'</p>
+                    </div>
+                ';
+                break;
+
             default;
                 $notices = get_option('glmMembersAdminNotices');
                 $notices[] = $message;
index 66cba49..d8b629a 100644 (file)
@@ -11,7 +11,7 @@
     color: red;
 }
 .glm-notice {
-    color: red;
+    color: green;
 }
 .glm-active {
     color: blue;
@@ -23,7 +23,7 @@
     float: left;    
 }
 .glm-indent {
-    padding-left: 2em;    
+    margin-left: 2em;    
 }
 .glm-center {
     text-align: center;
index ee289df..81195ef 100644 (file)
@@ -273,7 +273,7 @@ if (isset($_REQUEST['glmDebugWindow']) && $_REQUEST['glmDebugWindow'] == true) {
  * @return void
  * @access public
  */
-function glmMembersAdminNotices($windowed = false)
+function glmMembersAdminNotices($windowed = true)
 {
 
     $output  = '';
index 92fce18..249f6b5 100644 (file)
@@ -1,4 +1,4 @@
-<?php /* Smarty version Smarty-3.1.21-dev, created on 2015-03-15 10:14:45
+<?php /* Smarty version Smarty-3.1.21-dev, created on 2015-05-06 17:03:14
          compiled from "/var/www/server/wordpress/wp-content/plugins/glm-member-db/views/admin/members/list.html" */ ?>
 <?php /*%%SmartyHeaderCode:33593880254c05ab8e362a8-88978550%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
 $_valid = $_smarty_tpl->decodeProperties(array (
@@ -7,7 +7,7 @@ $_valid = $_smarty_tpl->decodeProperties(array (
     '4c287ca0e4946b3d644e61950c851e98e8906d49' => 
     array (
       0 => '/var/www/server/wordpress/wp-content/plugins/glm-member-db/views/admin/members/list.html',
-      1 => 1426428835,
+      1 => 1430858868,
       2 => 'file',
     ),
   ),
@@ -45,7 +45,7 @@ $_valid = $_smarty_tpl->decodeProperties(array (
     
     <h2>List of Members</h2>
     
-    <table class="wp-list-table widefat fixed posts glm-admin-table"">
+    <table class="wp-list-table widefat fixed posts glm-admin-table">
         <thead>
             <tr>
                 <th>ID</th>
@@ -59,7 +59,9 @@ $_valid = $_smarty_tpl->decodeProperties(array (
         </thead>
         <tbody>
 <?php if ($_smarty_tpl->tpl_vars['haveMembers']->value) {?>
-    <?php $_smarty_tpl->tpl_vars["i"] = new Smarty_variable("0", null, 0);?>
+    <?php if (isset($_smarty_tpl->tpl_vars["i"])) {$_smarty_tpl->tpl_vars["i"] = clone $_smarty_tpl->tpl_vars["i"];
+$_smarty_tpl->tpl_vars["i"]->value = "0"; $_smarty_tpl->tpl_vars["i"]->nocache = null; $_smarty_tpl->tpl_vars["i"]->scope = 0;
+} else $_smarty_tpl->tpl_vars["i"] = new Smarty_variable("0", null, 0);?>
     <?php  $_smarty_tpl->tpl_vars['m'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['m']->_loop = false;
  $_from = $_smarty_tpl->tpl_vars['members']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
 foreach ($_from as $_smarty_tpl->tpl_vars['m']->key => $_smarty_tpl->tpl_vars['m']->value) {
index a338fa7..edf68dc 100644 (file)
@@ -97,14 +97,14 @@ class GlmMembersAdmin_configure_development
         $dbVersion = GLM_MEMBERS_PLUGIN_DB_VERSION;
         settype($dbVersion, 'string');
 
-        $resultMessage = '';
-        $importData = array(
-            'success' => false,
-            'haveNotices' => false,
-            'notices' => array(),
-            'haveMembers' => false,
-            'members' => false
-        );
+        $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');
@@ -123,107 +123,77 @@ class GlmMembersAdmin_configure_development
                 require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/glmMemberImportFromConnections.php');
                 $Connections = new GlmMemberImportFromConnections($this->wpdb, $this->config);
 
-                // Check if Connections is not installed or not active. If active, gets count of entries.
-                $c = $Connections->checkConnections();
-                if ($c === false) {
-                    $importaData['notices'][] = 'Connections Business Directory plugin is not installed or not active!<br>'.print_r($c,1);
-                    break;
-                }
-                $importData['numbEntries'] = $c;
-                $importData['notices'][] = 'Connections Business Directory plugin is active.<br>Number of businesses listed: '.$c.'<br>';
+                if (isset($_REQUEST['import']) && $_REQUEST['import'] == 'now') {
 
-                // Get the basic business data for review.
-                $importData['members'] = $Connections->getList();
-                if ($importData['members'] === false) {
-                    $importaData['notices'][] = 'No businesses were retieved.';
-                    break;
-                }
+                    // Reset the database
+                    if (!$this->deleteDataTables($dbVersion)) {
+                        glmMembersAdmin::addNotice('<b>Unable to delete the database tables while resetting the database.</b><br>', 'AdminError');
+                        break;
+                    }
+                    if (!$this->createDataTables($dbVersion)) {
+                        glmMembersAdmin::addNotice('<b>Unable to create the database tables while resetting the database.</b><br>', 'AdminError');
+                        break;
+                    }
+                    glmMembersAdmin::addNotice('<b>Database tables have been reset in preparation importing members.</b><br>', 'AdminNotice');
 
-                $importData['haveMembers'] = true;
+                    $templateData['import'] = true;
+                    $templateData['membersImported'] = $Connections->doImport();
 
-                if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
-                    glmMembersAdmin::addNotice($importData['members'], 'DataBlock', 'Base Members Data');
-                }
+                } else {
 
+                    // Check if Connections is not installed or not active. If active, gets count of entries.
+                    $c = $Connections->checkConnections();
+                    if ($c === false) {
+                        glmMembersAdmin::addNotice('<b>Connections Business Directory plugin is not installed or not active!</b><br>'.print_r($c,1), 'AdminError');
+                        break;
+                    }
+                    $templateData['numbEntries'] = $c;
+                    $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.';
+                        break;
+                    }
+
+                    $templateData['haveMembers'] = true;
+
+                    if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+                        glmMembersAdmin::addNotice($templateData['members'], 'DataBlock', 'Base Members Data');
+                    }
+
+                }
 
                 break;
 
             case 'drop':
             case 'reset':
 
-                // Read in Database deletion script - assumes the current db version.
-                $sqlFile = GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/drop_database_V'.$dbVersion.'.sql';
-                $sql = file_get_contents($sqlFile);
-
-                // Replace {prefix} with table name prefix
-                $sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql);
+                $del = $this->deleteDataTables($dbVersion);
 
-                if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
-                    glmMembersAdmin::addNotice('Dropping all database tables', 'Process');
-                    glmMembersAdmin::addNotice($sql, 'DataBlock', 'Drop Tables SQL');
-                }
+                if ($del) {
+                    glmMembersAdmin::addNotice('New database tables for the '.GLM_MEMBERS_PLUGIN_NAME.' plugin have been deleted.', 'AdminNotice');
 
-                // Removing the tables using the script
-                $this->wpdb->query($sql);
-
-                // If there's been an error, display in debug Alert
-                $queryError = $this->wpdb->last_error;
-                if ($queryError) {
-                    if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
-                        glmMembersAdmin::addNotice('<b>Error when deleting database:</b><br>'.$queryError, 'Alert');
-                    }
                 }
 
-                $resultMessage .= 'Database deleted<br>';
-
                 if ($option != 'reset') {
                     break;
                 }
 
             case 'create':
 
-                // Read in Database creation script
-                $sqlFile = GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/create_database_V'.$dbVersion.'.sql';
-                $sql = file_get_contents($sqlFile);
-
-                // Replace {prefix} with table name prefix
-                $sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql);
-
-                // Split script into separate queries by looking for lines with only "---"
-                $queries = preg_split('/^----$/m', $sql);
-
-                // Try executing all queries to build database
-                $qForDebug = '';
-                do {
-                    $q = current($queries);
-                    $this->wpdb->query($q);
-                    $queryError = $this->wpdb->last_error;
-
-                    if ($queryError) {
-                        glmMembersAdmin::addNotice('<b>Error when creating database:</b> <br>'.$queryError, 'Alert');
-                    }
-                    $qForDebug .= $queryError.$q;
-
-                } while ($queryError == '' && next($queries));
-
-                if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
-                    glmMembersAdmin::addNotice('Creating database tables', 'Process');
-                    glmMembersAdmin::addNotice($qForDebug, 'DataBlock', 'Create Tables SQL');
-                }
+                $create = $this->createDataTables($dbVersion);
 
                 // If there were no errors
-                if (trim($queryError) == '') {
+                if ($create) {
 
                     // Notify the user that the database has been installed
-                    $resultMessage .= 'New database tables installed for the '.GLM_MEMBERS_PLUGIN_NAME.' plugin.<br>';
+                    glmMembersAdmin::addNotice('New database tables installed for the '.GLM_MEMBERS_PLUGIN_NAME.' plugin.', 'AdminNotice');
 
                     // Save the version of the installed database
                     update_option('glmMembersDatabaseDbVersion', $dbVersion);
 
-
-                } else {
-                    $resultMessage .= 'Failure installing database tables for the '.GLM_MEMBERS_PLUGIN_NAME.' plugin.<br>';
-                    $resultMessage .= '<b>Database Installation Error:</b> '.$queryError.'<br>';
                 }
 
                 break;
@@ -247,6 +217,10 @@ class GlmMembersAdmin_configure_development
                     ", ARRAY_A);
 
                     if (is_array($existingTables)) {
+
+                        $
+
+
                         $resultMessage .= '<b>Current database tables</b><br><ul>';
                         foreach($existingTables as $t){
                             $resultMessage .= "<li>".$t['table_name'].'</li><br>';
@@ -264,16 +238,6 @@ class GlmMembersAdmin_configure_development
 
         }
 
-
-        if (count($importData['notices'] > 0)) {
-            $importData['haveNotices'] = true;
-        }
-
-        $templateData = array(
-            'resultMessage' => $resultMessage,
-            'importData' => $importData
-        );
-
         // Return status, suggested view, and data to controller
         return array(
             'status' => true,
@@ -285,6 +249,88 @@ class GlmMembersAdmin_configure_development
 
     }
 
+    /*
+     * Delete Members Database Tables
+     *
+     * @param string $dbVersion Current version of Members Database
+     *
+     * @return boolean
+     * @access public
+     */
+    public function deleteDataTables($dbVersion)
+    {
+
+        // Read in Database deletion script - assumes the current db version.
+        $sqlFile = GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/drop_database_V'.$dbVersion.'.sql';
+        $sql = file_get_contents($sqlFile);
+
+        // Replace {prefix} with table name prefix
+        $sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql);
+
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+            glmMembersAdmin::addNotice('Dropping all database tables', 'Process');
+            glmMembersAdmin::addNotice($sql, 'DataBlock', 'Drop Tables SQL');
+        }
+
+        // Removing the tables using the script
+        $this->wpdb->query($sql);
+
+        // If there's been an error, display in debug Alert
+        $queryError = $this->wpdb->last_error;
+        if ($queryError) {
+            glmMembersAdmin::addNotice('<b>Error when deleting database: Database tables may not have existed.</b><br>Check following message.<br>'.$queryError, 'AdminError');
+            return false;
+        }
+
+        return true;
+
+    }
+
+    /*
+     * Create Members Database Tables
+     *
+     * @param string $dbVersion Current version of Members Database
+     *
+     * @return boolean
+     * @access public
+     */
+    public function createDataTables($dbVersion)
+    {
+
+        // Read in Database creation script
+        $sqlFile = GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/create_database_V'.$dbVersion.'.sql';
+        $sql = file_get_contents($sqlFile);
+
+        // Replace {prefix} with table name prefix
+        $sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql);
+
+        // Split script into separate queries by looking for lines with only "---"
+        $queries = preg_split('/^----$/m', $sql);
+
+        // Try executing all queries to build database
+        $qForDebug = '';
+        do {
+            $q = current($queries);
+            $this->wpdb->query($q);
+            $queryError = $this->wpdb->last_error;
+
+            if ($queryError) {
+                glmMembersAdmin::addNotice('<b>Error when creating database: Database tables may already exist.</b><br>Check following message.<br>'.$queryError, 'AdminError');
+                return false;
+            }
+            $qForDebug .= $queryError.$q;
+
+        } while ($queryError == '' && next($queries));
+
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+            glmMembersAdmin::addNotice('Creating database tables', 'Process');
+            glmMembersAdmin::addNotice($qForDebug, 'DataBlock', 'Create Tables SQL');
+        }
+
+        return true;
+
+    }
+
 }
 
 ?>
\ No newline at end of file
index 35be617..75e6421 100644 (file)
@@ -9,19 +9,40 @@
             <H3>Import</H3>
             <ul>
                 <li>
-                    <a href="{$thisURL}?page={$thisPage}&glm_action=development&option=import_connections">Import data from "Connections" business directory</a>
-{if $importData.haveNotices} 
-    {foreach $importData.notices as $n}
-                    <p style="color: red; margin-left: 2em;">{$n}</p>
-    {/foreach}
-{/if}
-{if $importData.haveMembers}
-                    <h3>Please review list of members that will be imported.</h3>
                     <p>
-                        <span id="skipAll" class="button-primary">Skip All</span>&nbsp;&nbsp;
-                        <span id="skipNone" class="button-primary">Import All</span>
+                        <a href="{$thisURL}?page={$thisPage}&glm_action=development&option=import_connections">Import data from "Connections" business directory</a>
+
+    {if $importNotice} 
+                        <div class="glm-indent glm-notice">{$importNotice}</div>
+    {/if}
                     </p>
-                    <form action="{$thisURL}?page={$thisPage}&glm_action=development&option=import_commit" method="post">
+
+    {if $import}
+
+                    <h3 style="margin-left: 2em;">Members imported: {$membersImported}</h3>
+                    
+    {else}
+        {if $haveMembers}
+                    <form action="{$thisURL}?page={$thisPage}&glm_action=development&option=import_connections" method="POST">
+                        <div class="glm-item-container">
+                            <b>Default data to use when importing members.</b>
+                            <table>
+                                <tr><td>Default member type: </td><td><input type="text" name="memberType" value="Standard"></td></tr>
+                                <tr><td>Default region name: </td><td><input type="text" name="region" value="Region"></td></tr>
+                            </table>
+                        </div>
+                        <p>
+                            <input class="glm-right" type="submit" value="Click here to import all members not marked as Skip">
+                            <span id="skipAll" class="button-primary">Skip All</span>&nbsp;&nbsp;
+                            <span id="skipNone" class="button-primary">Import All</span>
+                        </p>
+                        <div class="glm-nitice glm-indent">
+                            <ul class="glm-required glm-indent">
+                                <li>*** THIS ACTION WILL FULLY RESET YOUR MEMBERS DATABASE ***</li>
+                                <li>This action does not check for duplicate members!</li>
+                            </ul>
+                        </div>
+                        <input type="hidden" name="import" value="now">
                         <table class="wp-list-table widefat fixed posts glm-admin-table">
                             <thead>
                                 <tr>
                                 </tr>
                             </thead>
                             <tbody>
-        {foreach $importData.members as $m}
+            {foreach $members as $m}
                                 <tr class="alternate">
-                                    <td><input type="checkbox" value="{$m.id}" class="skip"></td>
+                                    <td><input type="checkbox" name="skip[{$m.id}]" class="skip">{$m.id}</td>
                                     <td>{$m.organization}</td>
-            {assign var="i" value="0"}                        
-            {foreach $m.addresses as $a}
-                {if $i++ gt 1}
+                {assign var="i" value="0"}                        
+                {foreach $m.addresses as $a}
+                    {if $i++ gt 1}
                                 <tr>
                                     <td>&nbsp;</td>
                                     <td>&nbsp;</td>
-                {/if}                                
+                    {/if}                                
                                     <td>{$a.line_1}</td>
                                     <td>{$a.line_2}</td>
                                     <td>{$a.line_3}</td>
                                     <td>{$a.country}</td>
                                     <td>{$a.latitude|number_format:3:".":","}/{$a.longitude|number_format:3:".":","}</td>
                                 </tr>
-            {/foreach}
-        {/foreach}               
+                {/foreach}
+            {/foreach}               
                             </tbody>         
                         </table>
                     </form>
-{/if}
+        {/if}
+    {/if}
                 </li>
             </ul>
             <H3>Database</H3>
     </div>
 {/if}    
     
-{if $importData.haveMembers}
+{if $haveMembers}
     <script type="text/javascript">
         jQuery(document).ready(function($) {