Fixed dataManagement, added dummy files
authorLaury GvR <laury@gaslightmedia.com>
Mon, 6 Feb 2017 21:49:09 +0000 (16:49 -0500)
committerLaury GvR <laury@gaslightmedia.com>
Mon, 6 Feb 2017 21:49:09 +0000 (16:49 -0500)
Fixed the datamanagement class and added files to get started on
adding the management tabs.

classes/data/dataManagement.php
models/admin/management/general.php [new file with mode: 0644]
models/admin/management/terms.php [new file with mode: 0644]
setup/adminTabs.php
setup/validActions.php
views/admin/management/footer.html [new file with mode: 0644]
views/admin/management/general.html [new file with mode: 0644]
views/admin/management/header.html [new file with mode: 0644]

index ea9ac66..5d8eb6a 100644 (file)
@@ -114,90 +114,97 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
                 'view_only' => true,
                 'use' => 'a'
             ),
+            
+            'canonical_reg_page' => array (
+                'field' => 'canonical_reg_page',
+                'type' => 'text',
+                'required' => true,
+                'use' => 'a'
+            ),
 
             // Site Owner Organization Name
-            'org_name' => array (
-                'field' => 'org_name',
+            'reg_org_name' => array (
+                'field' => 'reg_org_name',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Site Owner Organization Short Name
-            'org_short' => array (
-                'field' => 'org_short',
+            'reg_org_short' => array (
+                'field' => 'reg_org_short',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Site Owner Organization Address
-            'org_address' => array (
-                'field' => 'org_address',
+            'reg_org_address' => array (
+                'field' => 'reg_org_address',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Site Owner Organization City
-            'org_city' => array (
-                'field' => 'org_city',
+            'reg_org_city' => array (
+                'field' => 'reg_org_city',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Site Owner Organization State
-            'org_state' => array (
-                'field' => 'org_state',
+            'reg_org_state' => array (
+                'field' => 'reg_org_state',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Site Owner Organization ZIP/Postal Code
-            'org_zip' => array (
-                'field' => 'org_zip',
+            'reg_org_zip' => array (
+                'field' => 'reg_org_zip',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Site Owner Organization Phone
-            'org_phone' => array (
-                'field' => 'org_phone',
+            'reg_org_phone' => array (
+                'field' => 'reg_org_phone',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Site Owner Organization Toll Free
-            'org_toll_free' => array (
-                'field' => 'org_toll_free',
+            'reg_org_toll_free' => array (
+                'field' => 'reg_org_toll_free',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Site Owner Organization Internal E-Mail Address
-            'org_internal_email' => array (
-                'field' => 'org_internal_email',
+            'reg_org_internal_email' => array (
+                'field' => 'reg_org_internal_email',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Site Owner Organization E-Mail From Address
-            'org_from_email' => array (
-                'field' => 'org_from_email',
+            'reg_org_from_email' => array (
+                'field' => 'reg_org_from_email',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Payment Methods Selected - Bitmap
-            'payment_methods' => array (
-                'field' => 'payment_methods',
+            'reg_payment_methods' => array (
+                'field' => 'reg_payment_methods',
                 'type'     => 'bitmap',
                 'bitmap'    => $this->config['payment_method'],
                 'default'  => 0, // none selected
@@ -205,8 +212,8 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             ),
 
             // Processing Methods Selected - Bitmap
-            'proc_methods' => array (
-                'field' => 'proc_methods',
+            'reg_proc_methods' => array (
+                'field' => 'reg_proc_methods',
                 'type'     => 'bitmap',
                 'bitmap'    => $this->config['proc_method'],
                 'default'  => 0, // none selected
@@ -214,8 +221,8 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             ),
 
             // Credit Cards Accepted Selected - Bitmap
-            'cc_accepts' => array (
-                'field' => 'cc_accepts',
+            'reg_cc_accepts' => array (
+                'field' => 'reg_cc_accepts',
                 'type'     => 'bitmap',
                 'bitmap'    => $this->config['credit_card'],
                 'default'  => 0, // none selected
@@ -223,58 +230,66 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             ),
 
             // Authorize.net Login
-            'authorize_net_login' => array (
-                'field' => 'authorize_net_login',
+            'reg_authorize_net_login' => array (
+                'field' => 'reg_authorize_net_login',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Authorize.net Key
-            'authorize_net_key' => array (
-                'field' => 'authorize_net_key',
+            'reg_authorize_net_key' => array (
+                'field' => 'reg_authorize_net_key',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Authorize.net Test Mode
-            'authorize_net_test' => array (
-                'field' => 'authorize_net_test',
+            'reg_authorize_net_test' => array (
+                'field' => 'reg_authorize_net_test',
                 'type' => 'list',
                 'list' => $this->config['proc_test_mode'],
                 'required' => true,
                 'default' => $this->config['proc_test_mode_numb']['Local Approval Test'],
                 'use' => 'a'
             ),
+            
+            // Always Use Full Billing Info
+            'reg_authorize_net_conf' => array (
+                'field' => 'reg_authorize_net_conf',
+                'type' => 'checkbox',
+                'use' => 'a',
+                'default'  => 0,
+            ),
 
             // Authorize.net Merchant Email
-            'authorize_net_merchant_email' => array (
-                'field' => 'authorize_net_merchant_email',
+            'reg_authorize_net_merchant_email' => array (
+                'field' => 'reg_authorize_net_merchant_email',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Merchant Solutions Account ID
-            'merchant_solutions_acctid' => array (
-                'field' => 'merchant_solutions_acctid',
+            'reg_merchant_solutions_acctid' => array (
+                'field' => 'reg_merchant_solutions_acctid',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Merchant Solutions Merchant PIN
-            'merchant_solutions_merchantpin' => array (
-                'field' => 'merchant_solutions_merchantpin',
+            'reg_merchant_solutions_merchantpin' => array (
+                'field' => 'reg_merchant_solutions_merchantpin',
                 'type' => 'text',
                 'required' => true,
                 'use' => 'a'
             ),
 
             // Merchant Solutions Test Mode
-            'merchant_solutions_test' => array (
-                'field' => 'merchant_solutions_test',
+            'reg_merchant_solutions_test' => array (
+                'field' => 'reg_merchant_solutions_test',
                 'type' => 'list',
                 'list' => $this->config['proc_test_mode'],
                 'required' => true,
@@ -283,16 +298,16 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             ),
 
             // Always Use Full Billing Info
-            'full_billing_info' => array (
-                'field' => 'full_billing_info',
+            'reg_full_billing_info' => array (
+                'field' => 'reg_full_billing_info',
                 'type' => 'checkbox',
                 'use' => 'a',
                 'default'  => 0,
             ),
 
             // Billing Info used for No Charge - Bitmap
-            'bill_info_req_no_charge' => array (
-                'field' => 'bill_info_req_no_charge',
+            'reg_bill_info_req_no_charge' => array (
+                'field' => 'reg_bill_info_req_no_charge',
                 'type'     => 'bitmap',
                 'bitmap'    => $this->config['billing_field'],
                 'default'  => 0, // none selected
@@ -300,17 +315,8 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             ),
 
             // Billing Info used for No Charge - Bitmap
-            'bill_info_req_comp_code' => array (
-                'field' => 'bill_info_req_comp_code',
-                'type'     => 'bitmap',
-                'bitmap'    => $this->config['billing_field'],
-                'default'  => 0, // none selected
-                'use'      => 'a'
-            ),
-
-            // Billing Info used for Comp Code - Bitmap
-            'bill_info_req_comp_code' => array (
-                'field' => 'bill_info_req_comp_code',
+            'reg_bill_info_req_comp_code' => array (
+                'field' => 'reg_bill_info_req_comp_code',
                 'type'     => 'bitmap',
                 'bitmap'    => $this->config['billing_field'],
                 'default'  => 0, // none selected
@@ -318,8 +324,8 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             ),
 
             // Billing Info used for Cash - Bitmap
-            'bill_info_req_cash' => array (
-                'field' => 'bill_info_req_cash',
+            'reg_bill_info_req_cash' => array (
+                'field' => 'reg_bill_info_req_cash',
                 'type'     => 'bitmap',
                 'bitmap'    => $this->config['billing_field'],
                 'default'  => 0, // none selected
@@ -327,8 +333,8 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             ),
 
             // Billing Info used for Check - Bitmap
-            'bill_info_req_check' => array (
-                'field' => 'bill_info_req_check',
+            'reg_bill_info_req_check' => array (
+                'field' => 'reg_bill_info_req_check',
                 'type'     => 'bitmap',
                 'bitmap'    => $this->config['billing_field'],
                 'default'  => 0, // none selected
@@ -336,8 +342,8 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             ),
 
             // Billing Info used for Credit Card - Bitmap
-            'bill_info_req_credit_card' => array (
-                'field' => 'bill_info_req_credit_card',
+            'reg_bill_info_req_credit_card' => array (
+                'field' => 'reg_bill_info_req_credit_card',
                 'type'     => 'bitmap',
                 'bitmap'    => $this->config['billing_field'],
                 'default'  => 0, // none selected
@@ -345,8 +351,8 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             ),
 
             // Billing Info used for Payment by Call From Merchant - Bitmap
-            'bill_info_req_merchant_call' => array (
-                'field' => 'bill_info_req_merchant_call',
+            'reg_bill_info_req_merchant_call' => array (
+                'field' => 'reg_bill_info_req_merchant_call',
                 'type'     => 'bitmap',
                 'bitmap'    => $this->config['billing_field'],
                 'default'  => 0, // none selected
@@ -354,8 +360,8 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             ),
 
             // Enable Request for Medical Info
-            'medical_info' => array (
-                'field' => 'medical_info',
+            'reg_medical_info' => array (
+                'field' => 'reg_medical_info',
                 'type' => 'checkbox',
                 'use' => 'a',
                 'default'  => 0
@@ -365,7 +371,6 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
 
     }
 
-
 }
 
 ?>
\ No newline at end of file
diff --git a/models/admin/management/general.php b/models/admin/management/general.php
new file mode 100644 (file)
index 0000000..696212b
--- /dev/null
@@ -0,0 +1,1703 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Registrations Add-on - Management Registrations Tab
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author     Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  registrations.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Management Registrations data abstract
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataManagement.php';
+
+/**
+ * GlmMembersAdmin_management_registrations
+ *
+ * PHP version 5
+ *
+ * @category Model
+ * @package GLM Member DB
+ * @author    Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ *            @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
+ *            Exp $
+ */
+class GlmMembersAdmin_management_registrations extends GlmDataRegistrationsManagement
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * dbh Postgres database connection
+     *
+     * @var mixed
+     * @access public
+     */
+    public $dbh;
+    /**
+     * settings used for the schema and tablenames
+     *
+     * @var mixed
+     * @access public
+     */
+    public $settings = array();
+    /**
+     * categories
+     *
+     * @var bool
+     * @access public
+     */
+    public $categories = array();
+    public $oldCatMap = array();
+    /**
+     * registrations
+     *
+     * @var bool
+     * @access public
+     */
+    public $registrations = array();
+    public $image_owner;
+
+    /**
+     * 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 importRegistrationImages()
+    {
+        require_once GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php';
+        $ImageUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
+        // get all registrations with images
+        $sql = "
+        SELECT id,image,old_registration_id
+          FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX. "registrations
+         WHERE image != '' AND image IS NOT NULL";
+        $results = $this->wpdb->get_results($sql, ARRAY_A);
+        $out = '<pre>$results: ' . print_r($results, true) . '</pre>';
+        $imgUrl = 'http://is0.gaslightmedia.com/' . $this->image_owner . '/original/';
+        foreach ( $results as $registration ) {
+            $imageFullUrl = $imgUrl . $registration['image'];
+            $res = $ImageUpload->storeImage($imageFullUrl);
+
+            if ( $res['newFileName'] ) {
+                $this->wpdb->update(
+                    GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registrations',
+                    array(
+                        'image' => $res['newFileName']
+                    ),
+                    array( 'id' => $registration['id'] ),
+                    array( '%s' ),
+                    array( '%d' )
+                );
+            }
+        }
+        return $out;
+    }
+
+    public function importRegistrationFiles()
+    {
+        // get all registrations with images
+        $sql = "
+        SELECT id,file1,file2_descr,old_registration_id
+          FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX. "registrations
+         WHERE file1 != '' AND file1 IS NOT NULL";
+        $results = $this->wpdb->get_results($sql, ARRAY_A);
+        $fileUrl = 'http://is0.gaslightmedia.com/' . $this->image_owner . '/original/';
+        $out = '<pre>$results: ' . print_r($results, true) . '</pre>';
+        foreach ( $results as $registration ) {
+            if ( $registration['image']) {
+                $fileFullUrl = $fileUrl . $registration['image'];
+                $fp = fopen( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $registration['file1'], 'w+' );
+                $ch = curl_init( $fileUrl . $registration['file1'] );
+                curl_setopt($ch, CURLOPT_TIMEOUT, 50);
+                curl_setopt($ch, CURLOPT_FILE, $fp);
+                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+                $fileData = curl_exec($ch);
+                $httpCode = curl_getinfo($ch);
+                curl_close($ch);
+                fclose($fp);
+                // Set correct file permissions
+                $oldUmask = umask(0);
+                chmod( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $registration['file1'], 0660 );
+                umask($oldUmask);
+            }
+        }
+        return $out;
+    }
+
+    /**
+     * modelAction
+     *
+     * @param bool $actionData
+     * @access public
+     * @return void
+     */
+    public function modelAction($actionData = false)
+    {
+
+        $option                = false;
+        $test_result           = false;
+        $import_result         = false;
+        $settings_updated      = false;
+        $settings_update_error = false;
+        $registration_settings        = false;
+        $icalFeedResult        = false;
+        $import_feeds          = false;
+        $option2               = false;
+
+        if (isset($_REQUEST['option'])) {
+            $option = $_REQUEST['option'];
+        }
+
+        $importFeeds = new GlmDataFeedImport( $this->wpdb, $this->config );
+
+        switch ($option) {
+
+            case 'timelyImport':
+                $import = false;
+                if (isset($_REQUEST['import'])) {
+                    $import = filter_var( $_REQUEST['import'], FILTER_VALIDATE_BOOLEAN );
+                }
+                $import_result = $this->importFromTimely();
+                break;
+
+            case 'icalfeed':
+                if ( isset( $_REQUEST['option2'] ) ) {
+                    $option2 = filter_var( $_REQUEST['option2'], FILTER_SANITIZE_STRING );
+                }
+                $icalFeedResult = '';
+                if ( $option2 === 'delete' && $feed_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
+                    $this->wpdb->delete(
+                        GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "feed_import",
+                        array( 'id' => $feed_id ),
+                        '%d'
+                    );
+                    if ( wp_next_scheduled( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) ) ) {
+                        wp_clear_scheduled_hook( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) );
+                    }
+                }
+                if ( $option2 === 'refresh'  && $feed_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
+                    //$icalFeedResult .= $this->importIcalFeed( $feed_id );
+                    // Set up the registration schedule
+                    if ( wp_next_scheduled( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) ) ) {
+                        wp_clear_scheduled_hook( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) );
+                    }
+                    wp_schedule_registration( time(), GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_RECURRANCE, GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) );
+                }
+                if ( isset( $_REQUEST['feed_url'] ) && $feed_url = filter_var( $_REQUEST['feed_url'], FILTER_VALIDATE_URL ) ) {
+                    // Add this feed url to the table
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "feed_import",
+                        array(
+                            'feed_url' => $feed_url,
+                            'created'  => current_time( 'mysql' )
+                        ),
+                        '%s'
+                    );
+                    $feed_id = $this->wpdb->insert_id;
+
+                    // Setup the registration feed to pull on schedule
+                    if ( !wp_next_scheduled( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, $feed_id ) ) {
+                        wp_schedule_registration( time(), GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_RECURRANCE, GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( $feed_id ) );
+                    }
+                }
+
+                break;
+
+            case 'registrationImagesImport':
+
+                $this->image_owner = filter_var($_REQUEST['img_owner_id'], FILTER_SANITIZE_STRING);
+
+                if ( $this->image_owner ) {
+                    $this->importRegistrationImages();
+                    $this->importRegistrationFiles();
+                    $import_result = '<p>All images and files imported</p>';
+                } else {
+                    $import_result = '<pre>Failure: Not given owner id.</pre>';
+                }
+
+                break;
+
+            case 'registrationFilesImport':
+                break;
+
+            case 'registrationimport':
+
+                $import = false;
+                if (isset($_REQUEST['import'])) {
+                    $import = filter_var( $_REQUEST['import'], FILTER_VALIDATE_BOOLEAN );
+                }
+                switch ($import) {
+                    case 'true':
+                        $import_result = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+                        $db_host      = filter_var( $_REQUEST['db_host'], FILTER_SANITIZE_STRING );
+                        $db_name      = filter_var( $_REQUEST['db_name'], FILTER_SANITIZE_STRING );
+                        $db_user      = filter_var( $_REQUEST['db_user'], FILTER_SANITIZE_STRING );
+                        $db_password  = filter_var( $_REQUEST['db_password'], FILTER_SANITIZE_STRING );
+                        $this->connectPostgresDb($db_host, $db_name, $db_user, $db_password);
+
+                        $this->settings = filter_var_array(
+                            $_REQUEST,
+                            array(
+                                'schema'       => FILTER_SANITIZE_STRING,
+                                'cattablename' => FILTER_SANITIZE_STRING,
+                                'tablename'    => FILTER_SANITIZE_STRING,
+                                'sdate'        => array(
+                                    'filter'  => FILTER_VALIDATE_REGEXP,
+                                    'options' => array(
+                                        'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%'
+                                    )
+                                )
+
+                            )
+                        );
+                        $import_result .= '<pre>$this->settings: ' . print_r($this->settings, true) . '</pre>';
+                        $this->addCategories();
+                        $import_result .= $this->addRegistrations();
+
+                        $import_result .= '<pre>$this->categories: ' . print_r($this->categories, true) . '</pre>';
+
+
+                        break;
+                    default:
+                        break;
+                }
+                $action = '';
+                if (isset($_REQUEST['action'])) {
+                    $action = $_REQUEST['action'];
+                }
+                break;
+
+            case 'settings':
+
+            default:
+
+                // Make sure option is set if default
+                $option = 'settings';
+
+                // 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
+                $option2 = '';
+                if (isset($_REQUEST['option2'])) {
+                    $option2 = $_REQUEST['option2'];
+                }
+
+                switch($option2) {
+
+                    // Update the settings and redisplay the form
+                    case 'submit':
+
+                        // Update the registration management settings
+                        $registration_settings = $this->updateEntry(1);
+                        if ($registration_settings['status']) {
+                            $settings_updated = true;
+                        } else {
+                            $settings_update_error = true;
+                        }
+
+                        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.
+                        $registration_settings = $this->editEntry(1);
+                        //echo '<pre>$registration_settings: ' . print_r( $registration_settings, true ) . '</pre>';
+
+                        if ($registration_settings === false) {
+
+                            if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+                                glmMembersAdmin::addNotice("<b>&nbsp;&nbsp;/models/admin/management/registrations.php: Unable to load registrations management settings.", 'Alert');
+                            }
+
+                        }
+
+                        break;
+
+                }
+
+                break;
+
+        }
+
+        $import_feeds = $importFeeds->getList();
+
+        if ( $import_feeds ) {
+            foreach ( $import_feeds as $key => &$feed ) {
+                // check the next run time
+                $feed['next_runtime'] = wp_next_scheduled( GLM_MEMBERS_REGISTRATIONS_PLUGIN_CRON_REGISTRATION, array( (int)$feed['id'] ) );
+            }
+        }
+
+        // Populate the state list for registration default state selection
+        $registration_settings['registration_default_state'] = $this->config['states'];
+
+        // Compile template data
+        $template_data = array(
+            'import_feeds'        => $import_feeds,
+            'option'              => $option,
+            'testResult'          => $test_result,
+            'importResult'        => $import_result,
+            'settingsUpdated'     => $settings_updated,
+            'settingsUpdateError' => $settings_update_error,
+            'registrationsSettings'      => $registration_settings,
+            'icalFeedResult'      => $icalFeedResult,
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => true,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/management/registrations.html',
+            'data'             => $template_data
+        );
+
+
+    }
+
+    /**
+     * connectPostgresDb
+     *
+     * Make a connection to the given database for the site. (postgres)
+     * Sets the $this->dbh with the postgers database connection
+     *
+     * @param mixed $db_host
+     * @param mixed $db_name
+     * @param mixed $db_user
+     * @param mixed $db_password
+     * @access public
+     * @return void
+     */
+    public function connectPostgresDb($db_host, $db_name, $db_user, $db_password)
+    {
+        $conn_str      = "pgsql:";
+        if ( $db_host ) {
+            $conn_part[] = "host={$db_host}";
+        }
+        if ( $db_name ) {
+            $conn_part[] = "dbname={$db_name}";
+        }
+        if ( $db_user ) {
+            $conn_part[] = "user={$db_user}";
+        }
+        if ( $db_password ) {
+            $conn_part[] = "password={$db_password}";
+        }
+        if ( !empty($conn_part) ) {
+             $conn_str .= implode( " ", $conn_part );
+        }
+        $driver_options = array(
+            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_BOTH,
+        );
+        try {
+            $this->dbh = new PDO($conn_str, null, null, $driver_options);
+            $this->dbh->setAttribute(
+                PDO::ATTR_ERRMODE,
+                PDO::ERRMODE_EXCEPTION
+            );
+        } catch(PDOException $e) {
+            echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+            wp_die();
+        }
+    }
+
+    public function getCategoryId( $category )
+    {
+        $category_id = $this->wpdb->get_var(
+            $this->wpdb->prepare(
+                "SELECT id
+                   FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "categories
+                  WHERE name = %d",
+                $category
+            )
+        );
+        if ( $category_id ) {
+            return $category_id;
+        } else {
+            $this->wpdb->insert(
+                GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'categories',
+                array(
+                    'name'   => $category,
+                    'parent' => 0
+                ),
+                arary(
+                    '%s',
+                    '%d'
+                )
+            );
+            $category_id = $this->wpdb->insert_id;
+            return $category_id;
+        }
+    }
+    /**
+     * addCategories
+     *
+     * Checks to see if there's an Registration Category already in the database.
+     * If not it will create the entry.
+     * Sets up the class variables
+     * $this->categories (contains all the categories that get added keyed with
+     * category id)
+     * $this->oldCatMap (map of the old category id to new category ids)
+     *
+     * @access public
+     * @return void
+     */
+    public function addCategories()
+    {
+        $category_label = ( $this->settings['tablename'] == 'registration' ) ? 'descr' : 'name';
+        $return = '';
+        $sql = "
+          SELECT *
+            FROM {$this->settings['schema']}.{$this->settings['cattablename']}
+        ORDER BY id";
+        $return .= '<pre>$sql: ' . print_r($sql, true) . '</pre>';
+        try {
+            $categories = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
+            $return .= '<pre>$categories: ' . print_r($categories, true) . '</pre>';
+            foreach ( $categories as $category ) {
+                // first check to see if the category is already there
+                $sql = "
+                SELECT id
+                  FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "categories
+                 WHERE name = '" . esc_sql( trim($category[$category_label]) ) . "'";
+                $return .= '<pre>$sql: ' . print_r($sql, true) . '</pre>';
+                $found = $this->wpdb->get_row($sql, ARRAY_A);
+                $return .= '<pre>$found: ' . print_r($found, true) . '</pre>';
+                if ( !isset($found) ) {
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'categories',
+                        array(
+                            'name'     => trim($category[$category_label]),
+                            'parent' => 0
+                        ),
+                        array(
+                            '%s',
+                            '%d'
+                        )
+                    );
+                    $catid = $this->wpdb->insert_id;
+                    $this->categories[$catid] = trim($category[$category_label]);
+                    $this->oldCatMap[$category['id']] = $catid;
+                } else {
+                     $this->categories[$found['id']] = trim($category[$category_label]);
+                    $this->oldCatMap[$category['id']] = $found['id'];
+                }
+            }
+        } catch(PDOException $e) {
+            echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+            die('end here');
+        }
+        return $return;
+    }
+
+    public function addTimelyCategories() {
+        $category_counter = 0;
+        $categories = get_terms( 'registrations_categories' );
+        foreach ( $categories as $category ) {
+            ++$category_counter;
+            // first check to see if the category is already there
+            $sql = "
+            SELECT id
+              FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "categories
+             WHERE name = '" . esc_sql( trim($category->name) ) . "'";
+            $found   = $this->wpdb->get_row($sql, ARRAY_A);
+            if ( !isset($found) ) {
+                $this->wpdb->insert(
+                    GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'categories',
+                    array(
+                        'name'     => trim($category->name),
+                        'parent' => $category->parent
+                    ),
+                    array(
+                        '%s',
+                        '%d'
+                    )
+                );
+                $catid = $this->wpdb->insert_id;
+                $this->categories[$catid] = trim($category->name);
+                $this->oldCatMap[$category->term_id] = $catid;
+            } else {
+                $this->categories[$found['id']] = trim($category->name);
+                $this->oldCatMap[$category->term_id] = $found['id'];
+            }
+        }
+        // Store the oldCatMap for the next pages.
+        update_option( 'glm-member-registration-old-cat-map', serialize( $this->oldCatMap ) );
+        return "<p>Adding $category_counter Categories</p>";
+    }
+    public function getOldCatMap()
+    {
+        return unserialize( get_option('glm-member-registration-old-cat-map') );
+    }
+    /**
+     * getTime
+     *
+     * Given a time string return the the following format of time
+     * H:i
+     * hour and minute
+     *
+     * @param mixed $time String with any time format
+     *
+     * @access public
+     * @return void
+     */
+    public function getTime($time)
+    {
+        //echo '<pre>$time: ' . print_r($time, true) . '</pre>';
+        if (!$time) {
+            return false;
+        }
+        if (!preg_match('%(\d{1,2}):?(\d{2})? ?(\w{1,2})?%', $time, $time_parts)) {
+            return false;
+        }
+        //echo '<pre>$timeParts: ' . print_r($time_parts, true) . '</pre>';
+        //$hour = (!$timeParts[3] || in_array(strtolower(trim($timeParts[3])), array('pm', 'p')))
+        //      ? ( ((int)$timeParts[1] === 12) ? 12 : (int)$timeParts[1] += 12 )
+        //      : ( ((int)$timeParts[1] === 12) ? 0 : (int)$timeParts[1] );
+        $hour = $time_parts[1];
+        if ( in_array( strtolower( $time_parts[3] ), array( 'pm', 'p' ) ) ) {
+            $hour += 12;
+        }
+        if ( in_array( strtolower( $time_parts[3] ), array( 'am', 'a' ) ) ) {
+            if ( (int)$hour === 12 ) {
+                $hour = 0;
+            }
+        }
+        $min  = ($time_parts[2]) ? $time_parts[2] : 0;
+        // parse the hour from registration
+        $dateTime = new DateTime();
+        $dateTime->setTime( $hour, $min );
+        //cho '<pre>$dateTime: ' . print_r($dateTime, true) . '</pre>';
+        return $dateTime->format('H:i');
+    }
+
+    /**
+     * getCityId
+     *
+     * Given a city name find and return the id of the city.
+     * If a city cannot be found then create city with that name.
+     *
+     * @param mixed $city_name Name of the city
+     *
+     * @access public
+     * @return id of city
+     */
+    public function getCityId($city_name)
+    {
+        if ( !$city_name ) {
+            return false;
+        }
+        $sql = "
+        SELECT id
+          FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities
+         WHERE name like '" . esc_sql( trim( $city_name ) ) . "'";
+        $cityId = $this->wpdb->get_row($sql, ARRAY_A);
+        if ( !$cityId ) {
+            // then add the city to the city table
+            $this->wpdb->insert(
+                GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities',
+                array( 'name' => trim( $city_name ) ),
+                array( '%s' )
+            );
+            return $this->wpdb->insert_id;
+        } else {
+            return $cityId['id'];
+        }
+    }
+
+    /**
+     * addRegistrations
+     *
+     * Start with a clean set of registration tables. ( delete all registration data )
+     * Grab all registrations starting with the given start date.
+     * Enter them into the new registration plugin tables.
+     *
+     * @access public
+     * @return void
+     */
+    public function addRegistrations()
+    {
+        // clear the registrations tables first
+        $this->clearData();
+        $Recurrences = new GlmDataRegistrationsRecurrences($this->wpdb, $this->config);
+        $return         = '';
+        $old_registration_format = ($this->settings['tablename'] == 'registration');
+        if ( $old_registration_format ) {
+            $sql         = "
+            SELECT *
+              FROM {$this->settings['schema']}.{$this->settings['tablename']}
+             WHERE edate >= '{$this->settings['sdate']}'::DATE";
+        } else {
+            $sql         = "
+            SELECT *
+              FROM {$this->settings['schema']}.{$this->settings['tablename']}
+             WHERE ending >= '{$this->settings['sdate']}'::DATE";
+            $prepare_sql = "
+            SELECT filename,urltext
+              FROM {$this->settings['schema']}.files
+             WHERE registration = :eid";
+            $get_file_data = $this->dbh->prepare($prepare_sql);
+        }
+        //$sql .=" AND file != '' ";
+        //$sql .= " AND id = 2838";
+        $this->wpdb->show_errors();
+        //echo '<pre>$sql: ' . print_r($sql, true) . '</pre>';
+        try {
+            $registrations = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
+            $return .= '<pre>$registrations: ' . print_r($registrations, true) . '</pre>';
+            foreach ( $registrations as $registration ) {
+                $found_member_id = $refType = null;
+                $member_id       = (isset($registration['member_id'])) ? $registration['member_id'] : $registration['member'];
+                if ( $member_id ) {
+                    // get the new member id
+                    $sql = "
+                    SELECT id
+                      FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                     WHERE old_member_id = " . esc_sql( trim($member_id) );
+                    $found_member_id = $this->wpdb->get_row($sql, ARRAY_A);
+                    if ( $found_member_id ) {
+                        $found_member_id = $found_member_id['id'];
+                        $refType = $this->config['ref_type_numb']['Member'];
+                    }
+                }
+                if ( $old_registration_format ) {
+                    $intro = substr( trip_tags( $registration['descr'] ), 0, 150 );
+                    // Remove uneeded newlines from both intro and description
+                    $intro = preg_replace( "/\s\s+/", ' ', $intro );
+                    $descr = preg_replace( "/\s\s+/", ' ', $registration['descr'] );
+                    $registration_data = array(
+                        'status'   => (($registration['visable'] == '1')
+                            ? $this->config['status_numb']['Active']
+                            : $this->config['status_numb']['Inactive']),
+                        'created'       => $registration['create_date'],
+                        'updated'       => $registration['create_date'],
+                        'approved'      => $registration['approved_date'],
+                        'name'          => $registration['header'],
+                        'intro'         => $intro,
+                        'descr'         => $descr,
+                        'image'         => $registration['img'],
+                        'file1'         => $registration['file'],
+                        'file1_descr'   => $registration['filename'],
+                        'cost'          => $registration['cost'],
+                        'url'           => $registration['url'],
+                        'old_registration_id'  => $registration['id'],
+//                        'ref_type'    => $refType,
+                        'ref_type'      => 10,
+                        'ref_dest'      => $found_member_id,
+                        'admin_name'    => $registration['admin_contact_name'],
+                        'admin_org'     => $registration['admin_org_name'],
+                        'admin_email'   => $registration['admin_email'],
+                        'admin_phone'   => $registration['admin_phone'],
+                        'contact_email' => $registration['email'],
+                        'contact_name'  => $registration['contact'],
+                        'contact_phone' => $registration['phone'],
+                        'notes'         => $registration['notes'],
+                        'hide_address'  => $registration['hide_address'],
+                    );
+                    $registration_data_format = array(
+                        '%d',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%d',
+                        '%d',
+                        '%d',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%d',
+                    );
+                } else {
+                    $get_file_data->bindParam(':eid', $registration['id'], PDO::PARAM_INT);
+                    $get_file_data->execute();
+                    $file = $filename = '';
+                    $fileData = $get_file_data->fetch(PDO::FETCH_ASSOC);
+                    if ($fileData ) {
+                        $file      = $fileData['filename'];
+                        $filename = $fileData['urltext'];
+                    }
+                    $intro = ($registration['intro'])
+                        ? substr(strip_tags($registration['intro']), 0, 150)
+                        : substr(strip_tags($registration['description']), 0, 150);
+                    // Remove uneeded newlines from both intro and description
+                    $intro = preg_replace( "/\s\s+/", ' ', $intro );
+                    $descr = preg_replace( "/\s\s+/", ' ', $registration['description'] );
+                    $registration_data = array(
+                        'status'   => (($registration['active'] == '1')
+                            ? $this->config['status_numb']['Active']
+                            : $this->config['status_numb']['Inactive']),
+                        'created'             => $registration['created'],
+                        'updated'             => $registration['updated'],
+                        'approved'            => $registration['approved'],
+                        'name'                => $registration['header'],
+                        'intro'               => $intro,
+                        'descr'               => $descr,
+                        'image'               => $registration['image'],
+                        'file1'               => $file,
+                        'file1_descr'         => $filename,
+                        'cost'                => $registration['cost'],
+                        'url'                 => $registration['website'],
+                        'old_registration_id'        => $registration['id'],
+//                        'ref_type'          => $refType,
+                        'ref_type'            => 10,
+                        'ref_dest'            => $found_member_id,
+                        'admin_name'          => $registration['admin_contact'],
+                        'admin_org'           => $registration['admin_org'],
+                        'admin_email'         => $registration['admin_email'],
+                        'admin_phone'         => $registration['admin_phone'],
+                        'contact_email'       => $registration['contact_email'],
+                        'contact_name'        => $registration['contact_name'],
+                        'contact_phone'       => $registration['contact_phone'],
+                        'notes'               => $registration['notes'],
+                        'hide_address'        => $registration['hide_address'],
+                        'use_member_location' => $registration['use_memberloc']
+                    );
+                    $registration_data_format = array(
+                        '%d',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%d',
+                        '%d',
+                        '%d',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%s',
+                        '%d',
+                        '%d',
+                    );
+                }
+                echo '</pre>';
+                $this->wpdb->insert(
+                    GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registrations',
+                    $registration_data,
+                    $registration_data_format
+                );
+                $registration_id  = $this->wpdb->insert_id;
+                var_dump( $registration_id );
+                echo '<pre>$registrationId: from insert ' . print_r($registration_id, true) . '</pre>';
+                if ( !$registration_id ) {
+                    echo '<pre>SQL Error: ' . $this->wpdb->last_error . '</pre>';
+                    echo '<pre>SQL Error: ' . $this->wpdb->print_error() . '</pre>';
+                }
+                // checking for $registrationId
+                //echo '<pre>$registrationId: ' . print_r($registrationId, true) . '</pre>';
+                if (!$registration_id) {
+                    die('something is wrong no registrationId');
+                }
+                // generate the slug name for this new registration
+                $registration_abstract = new GlmDataRegistrations($this->wpdb, $this->config);
+                $registration_abstract->updateSlug($registration_id);
+                // category for registration
+                if ( $registration['topicid'] ) {
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registration_categories',
+                        array(
+                            'registration'    => $registration_id,
+                            'category' => $this->oldCatMap[$registration['topicid']]
+                        ),
+                        array(
+                            '%d',
+                            '%d'
+                        )
+                    );
+                }
+                if ( $registration['category'] ) {
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registration_categories',
+                        array(
+                            'registration'    => $registration_id,
+                            'category' => $this->oldCatMap[$registration['category']]
+                        ),
+                        array(
+                            '%d',
+                            '%d'
+                        )
+                    );
+                }
+                // recurrences for the registration
+                if (isset($registration['reacur'])) {
+                    $recurring_registration = $registration['reacur'];
+                    if ( $recurring_registration && ( $registration['bdate'] == $registration['edate'] ) ) {
+                        $recurring_registration = 0;
+                    }
+                } else {
+                    $recurring_registration = $registration['recurr'];
+                    if ( $recurring_registration && ( $registration['starting'] == $registration['ending'] ) ) {
+                        $recurring_registration = 0;
+                    }
+                }
+                $day_of_week       =
+                $month_of_year     =
+                $week_of_month     =
+                $by_day_of_month   =
+                $last_day_of_month = null;
+                if ( $recurring_registration ) {
+                    if ( $registration['daysow'] ) {
+                        $day_of_week = $registration['daysow'];
+                    } else {
+                        $day_of_week = 127;
+                    }
+                    if ( $registration['weekom'] ) {
+                        switch ($registration['weekom']) {
+                        case '1':
+                            $week_of_month = 1;
+                            break;
+                        case '2':
+                            $week_of_month = 2;
+                            break;
+                        case '3':
+                            $week_of_month = 4;
+                            break;
+                        case '4':
+                            $week_of_month = 8;
+                            break;
+                        case '5':
+                            $week_of_month = 16;
+                            break;
+                        }
+                    } else {
+                        $week_of_month = 63;
+                    }
+                    $month_of_year = 4095;
+                } else {
+                    $day_of_week = 127;
+                    $month_of_year = 4095;
+                }
+                if ( isset($registration['btime']) ) {
+                    $btime    = $this->getTime($registration['btime']);
+                    $etime    = $this->getTime($registration['etime']);
+                } else {
+                    $btime    = $this->getTime($registration['starthour']);
+                    $etime    = $this->getTime($registration['endhour']);
+                }
+                $start_time_only = ($btime && !$etime);
+                if ( $start_time_only ) {
+                    $etime = $btime;
+                }
+                if ( isset($registration['all_day']) ) {
+                    $all_day = ( $registration['all_day'] || !$btime );
+                } else {
+                    $all_day = ( $registration['allday'] || !$btime );
+                }
+                if (isset($registration['bdate'])) {
+                    $from_date = $registration['bdate'];
+                    $to_date   = $registration['edate'];
+                } else {
+                    $from_date = $registration['starting'];
+                    $to_date   = $registration['ending'];
+                }
+                $recur_data = array(
+                    'registration'             => $registration_id,
+                    'name'              => 'Imported Registration Schedule',
+                    'start_time'        => $btime,
+                    'end_time'          => $etime,
+                    'start_time_only'   => $start_time_only,
+                    'from_date'         => $from_date,
+                    'to_date'           => $to_date,
+                    'all_day'           => $all_day,
+                    'recurring'         => $recurring_registration,
+                    'month_of_year'     => $month_of_year,
+                    'week_of_month'     => $week_of_month,
+                    'day_of_week'       => $day_of_week,
+                    'by_day_of_month'   => $by_day_of_month,
+                    'last_day_of_month' => $last_day_of_month
+                );
+                echo '<pre>' . print_r( $recurData, true) . '</pre>';
+                echo '<pre>$recurData: ' . print_r($recur_data, true) . '</pre>';
+                $this->wpdb->insert(
+                    GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'recurrences',
+                    $recur_data,
+                    array(
+                         '%d',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                    )
+                );
+                $recur_id    = $this->wpdb->insert_id;
+                $Recurrences->createRecurrenceTimesEntries( $recur_id, true, true );
+                // location for the registration
+                $has_location = ($registration['loc'] || $registration['place']);
+                if ( $has_location ) {
+                    $location_data = $location_format = array();
+                    $location_data['registration'] = $registration_id;
+                    $location_format[] = '%d';
+                    if ($registration['place']) {
+                        $location_data['name'] = $registration['place'];
+                        $location_format[] = '%s';
+                    }
+                    if ($registration['loc']) {
+                        $location_data['name'] = $registration['loc'];
+                        $location_format[] = '%s';
+                    }
+                    if ($registration['address']) {
+                        $location_data['address'] = $registration['address'];
+                        $location_format[] = '%s';
+                    }
+                    if ($registration['city']) {
+                        $location_data['city'] = $this->getCityId( $registration['city'] );
+                        $location_format[] = '%s';
+                    }
+                    if ($registration['state']) {
+                        $location_data['state'] = $registration['state'];
+                        $location_format[] = '%s';
+                    }
+                    if ($registration['zip']) {
+                        $location_data['zip'] = $registration['zip'];
+                        $location_format[] = '%s';
+                    }
+                    if ($registration['lat']) {
+                        $location_data['lat'] = $registration['lat'];
+                        $location_format[] = '%s';
+                    }
+                    if ($registration['lon']) {
+                        $location_data['lon'] = $registration['lon'];
+                        $location_format[] = '%s';
+                    }
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'locations',
+                        $location_data,
+                        $location_format
+                    );
+                    $location_id = $this->wpdb->insert_id;
+                    if ( !$location_id ) {
+                        echo '<pre>$locationData: ' . print_r($location_data, true) . '</pre>';
+                        die('no return id for location');
+                    }
+                }
+            }
+        } catch(PDOException $e) {
+            echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+            die('end here');
+        }
+        return $return;
+    }
+    public function clearData()
+    {
+        $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "registrations" );
+        $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "recurrences" );
+        $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "times" );
+        $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "registration_categories" );
+        $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "locations" );
+    }
+    public function importFromTimely() {
+        $limit = 25;
+        $debug = false;
+        if ( isset( $_REQUEST['start'] ) ) {
+            $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT );
+        } else {
+            $start = 0;
+        }
+        if ( $start === 0 ) {
+            // clear the registrations tables first.
+            $this->clearData();
+            // Add the Categories from Time.ly.
+            $return_string = $this->addTimelyCategories();
+        } else {
+            $this->oldCatMap = $this->getOldCatMap();
+        }
+
+        $yearly_registrations =
+        $daily_registrations =
+        $weekly_registrations =
+        $interval_registrations =
+        $monthly_registrations =
+        $custom_date_registrations = 0;
+
+        $Recurrences = new GlmDataRegistrationsRecurrences($this->wpdb, $this->config);
+        require_once GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php';
+        $image_upload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config);
+
+        $sql = "
+        SELECT *
+          FROM " . $this->wpdb->prefix . "posts
+         WHERE post_type = 'ai1ec_registration'
+           AND post_status = 'publish'";
+        $sql .= " LIMIT $limit OFFSET $start";
+        $results = $this->wpdb->get_results( $sql, ARRAY_A );
+
+        $registration_counter = 0;
+
+        if ( !empty( $results ) ) {
+            foreach ( $results as $post ) {
+                // Initialize some variables
+                $serialized_custom_times = null;
+                if ( $debug ) {
+                    echo '<div style="border:1px solid green;">';
+                }
+                ++$registration_counter;
+                $sql        = "
+                SELECT *
+                  FROM " . $this->wpdb->prefix . "ai1ec_registrations
+                 WHERE post_id = {$post['ID']}";
+                $registration_data = $this->wpdb->get_row( $sql, ARRAY_A );
+                $cost_data  = unserialize( $registration_data['cost'] );
+                $cost       = $cost_data['cost'];
+                $is_free    = $cost_data['is_free'];
+
+                // use the posts table data
+                $image = '';
+                if ( has_post_thumbnail( $post['ID'] ) ) {
+                    $thumbnail_id = get_post_thumbnail_id( $post['ID'] );
+                    $thumb_src    = wp_get_attachment_image_src( $thumbnail_id, 'large' );
+                    //echo '<pre>$thumb_src: ' . print_r($thumb_src, true) . '</pre>';
+                    $res          = $image_upload->storeImage($thumb_src[0]);
+                    //echo '<pre>$res: ' . print_r($res, true) . '</pre>';
+                    if ( $res['newFileName'] ) {
+                        $image = $res['newFileName'];
+                    }
+                }
+                // Insert the registration data
+                $registration_import_data = array(
+                    'status'              => $this->config['status_numb']['Active'],
+                    'created'             => $post['post_date'],
+                    'updated'             => $post['post_modified'],
+                    'approved'            => $post['post_modified'],
+                    'name'                => $post['post_title'],
+                    'name_slug'           => $post['post_name'],
+                    'intro'               => mb_substr( strip_tags( $post['post_content'] ), 0, 80 ),
+                    'descr'               => $post['post_content'],
+                    'image'               => $image,
+                    'file1'               => null,
+                    'file1_descr'         => null,
+                    'cost'                => $cost,
+                    'free'                => $is_free,
+                    'url'                 => $registration_data['contact_url'],
+                    'old_registration_id'        => $post['ID'],
+//                    'ref_type'          => null,
+                    'ref_type'            => 10,
+                    'ref_dest'            => null,
+                    'admin_name'          => $registration_data['contact_name'],
+                    'admin_org'           => null,
+                    'admin_email'         => $registration_data['contact_email'],
+                    'admin_phone'         => $registration_data['contact_phone'],
+                    'contact_email'       => $registration_data['contact_email'],
+                    'contact_name'        => $registration_data['contact_name'],
+                    'contact_phone'       => $registration_data['contact_phone'],
+                    'notes'               => null,
+                    'hide_address'        => null,
+                    'use_member_location' => 0,
+                );
+                $registration_data_format = array(
+                    '%d',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                    '%s',
+                );
+                $is_insert = $this->wpdb->insert(
+                    GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registrations',
+                    $registration_import_data,
+                    $registration_data_format
+                );
+                if ( $debug ) {
+                    var_dump( $is_insert );
+                }
+                $registration_id  = $this->wpdb->insert_id;
+                if ( $debug ) {
+                    var_dump( $registration_id );
+                }
+                if ( !$registration_id ) {
+                    $this->wpdb->print_error();
+                    echo '<pre>$registration_import_data: ' . print_r($registration_import_data, true) . '</pre>';
+                    echo '<pre>SQL Error: ' . $this->wpdb->last_error . '</pre>';
+                    echo '<pre>SQL Error: ' . $this->wpdb->print_error() . '</pre>';
+                    die('something is wrong no registration_id');
+                }
+                // get the post categories
+                $categories = array();
+                $post_terms = wp_get_post_terms( $post['ID'], 'registrations_categories', 'term_id' );
+                foreach ( $post_terms as $term ) {
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'registration_categories',
+                        array(
+                            'registration'    => $registration_id,
+                            'category' => $this->oldCatMap[$term->term_id]
+                        ),
+                        array(
+                            '%d',
+                            '%d'
+                        )
+                    );
+                }
+                if ( $debug ) {
+                    echo '<pre>$registration_data: ' . print_r($registration_data, true) . '</pre>';
+                    echo '<pre>$categories: ' . print_r($categories, true) . '</pre>';
+                }
+
+                $by_day_of_month =
+                $last_day_of_month = null;
+
+                $recurring_registration =
+                $start_time_only =
+                $recurring_registration = 0;
+
+                $weekly =
+                $daily  = false;
+
+                $day_of_week   = 127;
+                $month_of_year = 4095;
+                $week_of_month = 63;
+
+                $custom_times = array();
+                $curZone = date_default_timezone_get();
+                if ( $debug ) {
+                    echo '<pre>$curZone: ' . print_r($curZone, true) . '</pre>';
+                }
+                if ( $registration_data['timezone_name'] ) {
+                    date_default_timezone_set( $registration_data['timezone_name'] );
+                }
+                $curZone = date_default_timezone_get();
+                if ( $debug ) {
+                    echo '<pre>$curZone: ' . print_r($curZone, true) . '</pre>';
+                }
+
+                $from_date = date( 'Y-m-d', $registration_data['start'] );
+                if ( $debug ) {
+                    echo '<pre>$from_date: ' . print_r($from_date, true) . '</pre>';
+                    $from_date_time = date( 'Y-m-d H:m:s', $registration_data['start'] );
+                    echo '<pre>$from_date_time: ' . print_r($from_date_time, true) . '</pre>';
+                }
+                $to_date   = date( 'Y-m-d', $registration_data['end'] );
+                // check if the $to_date has 0 hr
+                // if the btime and etime are 00:00 then remove one day from $to_date
+                if ( date( 'H', $registration_data['end'] ) === '00' ) {
+                    $ending_datetime = new DateTime( $to_date );
+                    $ending_datetime->modify('- 1 day');
+                    $to_date = $ending_datetime->format( 'Y-m-d' );
+                }
+                if ( $debug ) {
+                    echo '<pre>$to_date: ' . print_r($to_date, true) . '</pre>';
+                    $to_date_time = date( 'Y-m-d H:m:s', $registration_data['end'] );
+                    echo '<pre>$to_date_time: ' . print_r($to_date_time, true) . '</pre>';
+                }
+                $btime     = date( 'H:i', $registration_data['start'] );
+                if ( $debug ) {
+                    echo '<pre>$btime: ' . print_r($btime, true) . '</pre>';
+                }
+                $etime     = date( 'H:i', $registration_data['end'] );
+                if ( $debug ) {
+                    echo '<pre>$etime: ' . print_r($etime, true) . '</pre>';
+                }
+
+
+                if ( $registration_data['recurrence_rules'] ) {
+                    $recurring_registration = 1;
+                    $recurrence_rules = explode( ';', $registration_data['recurrence_rules'] );
+                    if ( $debug ) {
+                        echo '<pre>$recurrence_rules: ' . print_r($recurrence_rules, true) . '</pre>';
+                    }
+                    foreach ( $recurrence_rules as $rule ) {
+                        // check for RDATE , which are the custom dates that need to be serialized
+                        if(strpos($rule, 'RDATE') !== false){
+                            $custom_date_registrations++;
+                            $rdate = $rule;
+                            $rdate = substr($rdate,6);
+                            $custom_times = explode(',', $rdate);
+                        }
+                        if ( preg_match( ';FREQ=(.*);', $rule, $matches ) ) {
+                            if ( $debug ) {
+                                echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
+                            }
+                            switch ( $matches[1] ) {
+                                case "WEEKLY":
+                                    $weekly_registrations++;
+                                    $weekly_rule = $recurrence_rules[1];
+                                    if(strpos($weekly_rule, "INTERVAL") !== false){
+                                        $weekly_interval = substr($weekly_rule, 9);
+                                        $loopLimit = floor(52 / $weekly_interval);
+                                        $interval_sum = $weekly_interval;
+                                        for($i = 0; $i < $loopLimit; $i++ ){
+                                            $date = date('Y-m-d',strtotime($from_date .'+'. $interval_sum .'weeks'));
+                                            $interval_dates[] = $date;
+                                            $interval_sum += $weekly_interval;
+                                        }
+                                        $serialized_custom_times = serialize($interval_dates);
+                                    }
+                                    $weekly = true;
+                                    // check for BYDAY
+                                    break;
+                                case "DAILY":
+                                    $daily_registrations++;
+                                    $daily = true;
+                                    if(strpos($recurrence_rules[1], "INTERVAL") === false){
+                                        $month_of_year = 4095;
+                                        $day_of_month = 2147483647;
+                                        $by_day_of_month = true;
+                                    } else {
+                                        $interval = $recurrence_rules[1];
+                                        $interval = substr($interval, 9);
+                                        $loopLimit = floor(365 / $interval);
+                                        $interval_sum = $interval;
+                                        for($i = 0; $i < $loopLimit; $i++ ){
+                                            $date = date('Y-m-d',strtotime($from_date .'+'. $interval_sum .'days'));
+                                            $interval_dates[] = $date;
+                                            $interval_sum += $interval;
+                                        }
+                                        $serialized_custom_times = serialize($interval_dates);
+                                    }
+
+                                    break;
+                                case "YEARLY":
+                                    $month_ints = $ints = $month_num = null;
+                                    if ( $recurrence_rules[1] ) {
+                                        $ints = 0;
+                                        $day_of_month = 0;
+                                        $yearly_registrations++;
+                                        $selected_from_date = substr($from_date, -2);
+                                        $selected_from_date--;
+                                        $selected_to_date = substr($to_date, -2);
+                                        $selected_to_date--;
+                                        $month_sum = 0;
+                                        $yearly = $recurrence_rules[1];
+                                        $yearly = substr($yearly,8);
+                                        $month_ints = explode(',', $yearly);
+                                        if ( $debug ) {
+                                            echo '<pre>$month_ints: ' . print_r($month_ints, true) . '</pre>';
+                                        }
+                                        foreach($month_ints as $ints){
+                                            $ints--;
+                                            $ints = pow(2, $ints);
+                                            $month_sum += $ints;
+                                        }
+                                        $month_of_year = $month_sum;
+                                        if ( $debug ) {
+                                            echo '<pre>$month_of_year: ' . print_r($month_of_year, true) . '</pre>';
+                                        }
+                                        if($selected_from_date == $selected_to_date){
+                                            $selected_to_date++;
+                                        }
+                                        $day_of_month = pow(2,$selected_from_date ) + pow(2, $selected_to_date);
+                                        if ( $debug ) {
+                                            echo '<pre>$day_of_month: ' . print_r($day_of_month, true) . '</pre>';
+                                        }
+                                        if($month_sum){
+                                            $by_day_of_month = 1;
+                                        }
+                                    } else {
+                                        $ints = 0;
+                                        $month_sum = 0;
+                                        // get the month and day of month from $from_date and $to_date
+                                        $start_month = date( 'n', strtotime( $from_date ) );
+                                        $end_month   = date( 'n', strtotime( $to_date ) );
+                                        for ( $index = ( $start_month - 1 ); $index <= ( $end_month -1 ); ++$index ) {
+                                            $ints = pow( 2, $index );
+                                            $month_sum += $ints;
+                                        }
+                                        $month_of_year = $month_sum;
+                                        // Now do the day_of_month
+                                        $ints = 0;
+                                        $day_of_month = 0;
+                                        $start_day = date( 'j', strtotime( $from_date ) );
+                                        if ( $debug ) {
+                                            echo '<pre>$start_day: ' . print_r($start_day, true) . '</pre>';
+                                        }
+                                        $end_day   = date( 'j', strtotime( $to_date ) );
+                                        if ( $debug ) {
+                                            echo '<pre>$end_day: ' . print_r($end_day, true) . '</pre>';
+                                        }
+                                        if ( $start_day == $end_day ) {
+                                            for ( $index = ( $start_day - 1); $index <= ( $end_day -1 ); ++$index ) {
+                                                $ints = pow( 2, $index );
+                                                $day_of_month += $ints;
+                                            }
+                                            if($day_of_month){
+                                                $by_day_of_month = 1;
+                                            }
+                                            $ending_datetime = new DateTime( $to_date );
+                                            $ending_date       = $ending_datetime->modify('2 years');
+                                            $to_date           = $ending_date->format( 'Y-m-d' );
+                                        } else {
+                                            $serialized_custom_times = null;
+                                            $custom_dates_array      = array();
+                                            $this_datetime           = null;
+                                            // if the dates span more than one day need to build the custom dates array
+                                            $starting_datetime = new DateTime( $from_date );
+                                            $ending_datetime   = new DateTime( $to_date );
+                                            // loop through for the next 2 years
+                                            for ( $year_index = 0; $year_index <= 2; ++$year_index ) {
+                                                if ( $year_index !== 0 ) {
+                                                    // adjust the datetimes plus one year
+                                                    $starting_datetime->modify( '+ 1 year' );
+                                                    $ending_datetime->modify( '+ 1 year' );
+                                                }
+                                                $starting_time     = $starting_datetime->format( 'U' );
+                                                $ending_time       = $ending_datetime->format( 'U' );
+                                                for ($index = $starting_time; $index <= $ending_time; $index += 86400 ) {
+                                                    $custom_dates_array[] = date( 'Y-m-d', $index );
+                                                }
+                                            }
+                                            if ( $debug ) {
+                                                echo '<pre>$custom_dates_array: ' . print_r($custom_dates_array, true) . '</pre>';
+                                            }
+                                            $serialized_custom_times = serialize( $custom_dates_array );
+                                        }
+                                    }
+                                    break;
+                                case "MONTHLY":
+                                    $monthly_registrations++;
+                                    $monthly = $recurrence_rules[1];
+                                    $byday_pos = strpos($monthly, "BYday");
+                                    $bymonthday_pos = strpos($monthly, "BYMONTHDAY");
+                                    if($byday_pos === false){
+                                        $monthly = substr($monthly, 11);
+                                        $day_ints = explode(',', $monthly);
+                                        foreach($day_ints as $day){
+                                            $day--;
+                                            $day = pow(2, $day);
+                                            $day_sum += $day;
+                                        }
+                                        $day_of_month = $day_sum;
+                                        if($day_sum){
+                                            $by_day_of_month = 1;
+                                        }
+                                    }
+                                    break;
+                            }
+                        } else if ( preg_match( ';COUNT=(.*);', $rule, $matches ) ) {
+                            if ( $debug ) {
+                                echo '<pre>$matches: ' . print_r($matches, true) . '</pre>';
+                            }
+                            // set the end date to COUNT days from start
+                            try {
+                                $number_of_days    = (int)$matches[1] - 1;
+                                $starting_datetime = new DateTime( $from_date );
+                                $add               = ( $number_of_days === 1 ) ? '1 day': $number_of_days . ' days';
+                                $ending_date       = $starting_datetime->modify($add);
+                                $to_date           = $ending_date->format( 'Y-m-d' );
+                                $recurring_registration   = 0;
+                            } catch (Exception $e) {
+                                if ( $debug ) {
+                                    echo '<pre>$e: ' . print_r($e, true) . '</pre>';
+                                }
+                                die();
+                            }
+                        } else if ( preg_match( ';UNTIL=(.*);', $rule, $matches ) ) {
+                            $to_date = date( 'Y-m-d', strtotime( $matches[1] ) );
+
+                        } else if ( preg_match( ';BYMONTH=(.*);', $rule, $matches ) ) {
+//                            $monthly = $recurrence_rules[1];
+//
+//                            $selected_from_date = substr($from_date, -2);
+//                            $selected_from_date--;
+//                            $selected_to_date = substr($to_date, -2);
+//                            $selected_to_date--;
+//
+//                            $monthly = substr($monthly, 8);
+//                            $month_ints = explode(',', $monthly);
+//                            foreach($month_ints as $day){
+//                                $day--;
+//                                $day = pow(2, $day);
+//                                $day_sum += $day;
+//                            }
+//                           $day_of_month = pow(2,$selected_from_date ) + pow(2,$selected_to_date);
+
+                        }else if ( preg_match( ';BYday=(.*);', $rule, $matches ) ) {
+
+                            if ( $debug ) {
+                                echo '<pre>1354 $matches: ' . print_r($matches, true) . '</pre>';
+                            }
+                            // check if the selection is the nth week with a selected day, if not parse the input as a list if selected days
+                            if(strpos($matches[1], ",") == false){
+                                $week_number = substr($matches[1],0, 1);
+                                $week_number = $week_number - 1;
+                                $week_of_month = pow(2, $week_number);
+                                $days[] = substr($matches[1], -2);
+                                $by_day_of_month = 0;
+                            } else {
+                                $days = explode( ',', $matches[1] );
+                            }
+                            $day_of_week = 0;
+                            foreach ( $days as $day ) {
+                                switch ( $day ) {
+                                    case "SU":
+                                        $day_of_week += pow(2, 0);
+                                        break;
+                                    case "MO":
+                                        $day_of_week += pow(2, 1);
+                                        break;
+                                    case "TU":
+                                        $day_of_week += pow(2, 2);
+                                        break;
+                                    case "WE":
+                                        $day_of_week += pow(2, 3);
+                                        break;
+                                    case "TH":
+                                        $day_of_week += pow(2, 4);
+                                        break;
+                                    case "FR":
+                                        $day_of_week += pow(2, 5);
+                                        break;
+                                    case "SA":
+                                        $day_of_week += pow(2, 6);
+                                        break;
+                                }
+                            }
+                        }
+                    }
+                    if(!empty($custom_times)){
+                        $stamp = array();
+                        date_default_timezone_set('UTC');
+                        $serialized_custom_times = serialize($custom_times);
+                        foreach($custom_times as $custom){
+
+                            $convert = date('U',strtotime($custom));
+                            $stamp[] = date('Y-m-d', $convert);
+                        }
+//                        $from_date = $to_date = $stamp[0];
+                        $serialized_custom_times = serialize($stamp);
+                    }
+                    date_default_timezone_set($curZone);
+                }
+                if ($recurring_registration && $from_date == $to_date && empty( $custom_times ) ) {
+                    // Add two years to the recurring registration if dates match
+                    $starting_datetime = new DateTime( $from_date );
+                    $ending_date       = $starting_datetime->modify('2 years');
+                    $to_date           = $ending_date->format( 'Y-m-d' );
+                }
+                $all_day       = $registration_data['allday'];
+
+                // instant registration is an registration with no end time
+                $start_time_only = $registration_data['instant_registration'];
+                if($start_time_only){
+                    $etime = $btime;
+                }
+
+                // for the recurrences part
+                $recur_data = array(
+                    'registration'                => $registration_id,
+                    'name'                 => 'Imported',
+                    'start_time'           => $btime,
+                    'end_time'             => $etime,
+                    'start_time_only'      => $start_time_only,
+                    'from_date'            => $from_date,
+                    'to_date'              => $to_date,
+                    'all_day'              => $all_day,
+                    'recurring'            => $recurring_registration,
+                    'month_of_year'        => $month_of_year,
+                    'week_of_month'        => $week_of_month,
+                    'day_of_week'          => $day_of_week,
+                    'day_of_month'         => $day_of_month,
+                    'by_day_of_month'      => $by_day_of_month,
+                    'last_day_of_month'    => $last_day_of_month,
+                    'specific_dates'       => $serialized_custom_times
+                );
+                if ( $debug ) {
+                    echo '<pre>$recur_data: ' . print_r($recur_data, true) . '</pre>';
+                }
+                $this->wpdb->insert(
+                    GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'recurrences',
+                    $recur_data,
+                    array(
+                         '%d',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%s',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%d',
+                         '%s'
+                    )
+                );
+                $recurr_id    = $this->wpdb->insert_id;
+                $Recurrences->createRecurrenceTimesEntries( $recurr_id, true, true );
+                // location for the registration
+                $has_location = ( $registration_data['address'] || $registration_data['venue'] );
+                $location_data = $location_format = array();
+                if ( $has_location ) {
+                    $location_data['registration'] = $registration_id;
+                    $location_format[] = '%d';
+                    if ($registration_data['venue']) {
+                        $location_data['name'] = $registration_data['venue'];
+                        $location_format[] = '%s';
+                    }
+                    if ($registration_data['address']) {
+                        // test the address to see if there's commas
+                        if ( strpos( $registration_data['address'], ',' ) === false) {
+                            $location_data['address'] = $registration_data['address'];
+                        } else {
+                            $location_data['address'] = substr( $registration_data['address'], 0, strpos( $registration_data['address'], ',' ) );
+                        }
+                        $location_format[] = '%s';
+                    }
+                    if ($registration_data['city']) {
+                        $location_data['city'] = $this->getCityId( $registration_data['city'] );
+                        $location_format[] = '%s';
+                    }
+                    if ($registration_data['province']) {
+                        // need to lookup the state abbreviation
+                        $state_abbr = array_search( $registration_data['province'], $this->config['states'] );
+                        if ( $state_abbr !== false ) {
+                            $location_data['state'] = $state_abbr;
+                            $location_format[] = '%s';
+                        }
+                    }
+                    if ($registration_data['postal_code']) {
+                        $location_data['zip'] = $registration_data['postal_code'];
+                        $location_format[] = '%s';
+                    }
+                    if ($registration_data['latitude']) {
+                        $location_data['lat'] = $registration_data['latitude'];
+                        $location_format[] = '%s';
+                    }
+                    if ($registration_data['longitude']) {
+                        $location_data['lon'] = $registration_data['longitude'];
+                        $location_format[] = '%s';
+                    }
+                    $this->wpdb->insert(
+                        GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'locations',
+                        $location_data,
+                        $location_format
+                    );
+                    $location_id = $this->wpdb->insert_id;
+                    if ( !$location_id ) {
+                        if ( $debug ) {
+                            echo '<pre>$location_data: ' . print_r($location_data, true) . '</pre>';
+                        }
+                        die('no return id for location');
+                    }
+                }
+                if ( $debug ) {
+                    echo '</div>';
+                }
+            }
+            $return_string .= "<p>Adding $registration_counter Registrations</p>";
+        }
+        echo $this->config['states'];
+        $return_string .= "<pre>
+            Start: $start
+        </pre>";
+        $start += $limit;
+        $return_string .= "<p><a href=\""
+            . GLM_MEMBERS_PLUGIN_CURRENT_URL
+            . "?page=glm-members-admin-menu-management&glm_action=registrations&option=timelyImport&import=true"
+            . "&start=$start\">Next</a></p>";
+        return $return_string;
+    }
+}
+
+?>
diff --git a/models/admin/management/terms.php b/models/admin/management/terms.php
new file mode 100644 (file)
index 0000000..e69de29
index 05fb0ce..64ba81f 100644 (file)
  * @link     http://dev.gaslightmedia.com/
  */
 
-/*
- * To add a new tab to an existing Member DB page use a block
- * like this and replace the {} parameters.
- *
- * add_filter('glm-member-db-add-tab-for-{menu name}',
- *     function($addOnTabs) {
- *         $newTabs = array(
- *             array(
- *                 'text' => '{text for display on tab}',
- *                 'menu' => '{menu name}',
- *                 'action' => '{action to perform}'
- *             )
- *         );
- *         $addOnTabs = array_merge($addOnTabs, $newTabs);
- *         return $addOnTabs;
- *     }
- * );
- *
- */
-
+    if (apply_filters('glm_members_permit_admin_members_registrations_tab', true)) {
+        add_filter('glm-member-db-add-tab-for-management',
+            function($addOnTabs) {
+                $newTabs = array(
+                    array(
+                        'text' => 'Registrations',
+                        'menu' => 'management',
+                        'action' => 'general'
+                    )
+                );
+                $addOnTabs = array_merge($addOnTabs, $newTabs);
+                return $addOnTabs;
+            }
+        );
+    }
\ No newline at end of file
index 1eb4eac..f55d4ff 100644 (file)
@@ -63,6 +63,9 @@ $glmMembersRegistrationsAddOnValidActions = array(
             'index' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
             'list'  => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
         ),
+        'management' => array(
+            'general' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG
+        ),
     ),
     'frontActions' => array(
     )
diff --git a/views/admin/management/footer.html b/views/admin/management/footer.html
new file mode 100644 (file)
index 0000000..14acd2f
--- /dev/null
@@ -0,0 +1,17 @@
+    <script type="text/javascript">
+
+        jQuery(document).ready(function($) {
+
+            /*
+             * Edit area tabs
+             */
+            // 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);
+
+            if('{$registrationsSettings.fieldData.calendar_view}'){
+                $("#calendar-view").val('{$registrationsSettings.fieldData.calendar_view}');
+            } else {
+                $("#calendar-view").val("agenda");
+            }
+        });
+    </script>
diff --git a/views/admin/management/general.html b/views/admin/management/general.html
new file mode 100644 (file)
index 0000000..73e52a0
--- /dev/null
@@ -0,0 +1,368 @@
+{include file='admin/management/header.html'}
+
+    <h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
+        <a id="glm-settings" data-show-table="glm-table-settings" class="glm-settings-tab nav-tab{if $option=='settings'} nav-tab-active{/if}">Settings</a>
+        <a id="glm-icalfeed" data-show-table="glm-table-icalfeed" class="glm-settings-tab nav-tab{if $option=='icalfeed'} nav-tab-active{/if}">iCal Feeds</a>
+        <a id="glm-registrationimport" data-show-table="glm-table-registrationimport" class="glm-settings-tab nav-tab{if $option=='registrationimport'} nav-tab-active{/if}">Import</a>
+        <a id="glm-timelyimport" data-show-table="glm-table-timelyimport" class="glm-settings-tab nav-tab{if $option=='timelyimport'} nav-tab-active{/if}">Timely Import</a>
+    </h2>
+
+    <!-- Management Settings -->
+
+    <table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option!='settings'} glm-hidden{/if}">
+        <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>Management Settings</h2>
+            </td>
+        </tr>
+        <tr>
+            <td>
+                <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                    <input type="hidden" name="glm_action" value="registrations">
+                    <input type="hidden" name="option" value="settings">
+                    <input type="hidden" name="option2" value="submit">
+                    <table class="glm-admin-table">
+                        <tr>
+                            <th {if $registrationsSettings.fieldRequired.canonical_registration_page}class="glm-required"{/if}>Event Detail Page Permalink Name:</th>
+                            <td {if $registrationsSettings.fieldFail.canonical_registration_page}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
+                                <input type="text" name="canonical_registration_page" value="{$registrationsSettings.fieldData.canonical_registration_page}" class="glm-form-text-input-medium">
+                                {if $registrationsSettings.fieldFail.canonical_registration_page}<p>{$registrationsSettings.fieldFail.canonical_registration_page}</p>{/if}
+                            </td>
+                        </tr>
+                        <tr>
+                            <th {if $registrationsSettings.fieldRequired.pdf_logo}class="glm-required"{/if}>Logo for Event PDF:</th>
+                            <td {if $registrationsSettings.fieldFail.pdf_logo}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
+                                    {if $registrationsSettings.fieldData.pdf_logo}
+                                        <img src="{$glmPluginMediaUrl}/images/medium/{$registrationsSettings.fieldData.pdf_logo}"><br>
+                                            <input type="checkbox" name="pdf_logo_delete">Delete PDF Logo<br><br>
+                                            {$registrationsSettings.fieldData.pdf_logo}<br>
+                                    {/if}
+                                <input type="file" name="pdf_logo_new" />
+                                <div style="color:green;">Use 800 x 114 px For the PDF logo size</div>
+                                {if $registrationsSettings.fieldFail.pdf_logo}<p>{$registrationsSettings.fieldFail.pdf_logo}</p>{/if}
+                            </td>
+                        </tr>
+                        <tr>
+                            <th {if $registrationsSettings.fieldRequired.footer_text}class="glm-required"{/if}>Footer text for PDF (no html, or the PDF will break)</th>
+                            <td {if $registrationsSettings.fieldFail.footer_text}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
+                                <textarea rows="3" cols="90" name="footer_text">{$registrationsSettings.fieldData.footer_text}</textarea>
+                                {if $registrationsSettings.fieldFail.footer_text}<p>{$registrationsSettings.fieldFail.footer_text}</p>{/if}
+                            </td>
+                        </tr>
+                        <tr>
+                            <th>Default State for Events:<br>(will use plugin default '{$settings.default_state}' for registrations if unset)</th>
+                            <td>
+                                <select id="registration-default-state" data-id="registration_default_state" class="location-address" name="registration_default_state">
+                                    <option value=""></option>
+                                    {foreach from=$registrationsSettings.fieldData.registration_default_state.list item=v}
+                                    <option value="{$v.value}"
+                                            {if ($registrationsSettings.fieldData.registration_default_state.value == NULL and $settings.default_state == $v.value)
+                                              or $registrationsSettings.fieldData.registration_default_state.value == $v.value}
+                                                selected="selected"
+                                            {/if}>
+                                        {$v.name} {if $v.value == $settings.default_state} (main plugin default) {/if}
+                                    </option>
+                                    {/foreach}
+                                </select>
+                            </td>
+                        </tr>
+                        <tr>
+                            <th>Front-End Calendar View</th>
+                            <td>
+                                <select id="calendar-view" name="calendar_view">
+                                    <option value="agenda"> Agenda </option>
+                                    <option value="calendar"> Calendar</option>
+                                </select>
+                            </td>
+                        </tr>
+                        <tr>
+                            <th></th>
+                            <td>
+                                <div class="current-calendar-view">
+                                    <label style="font-weight: bold;font-size: 16px;">&nbsp;Current View:</label><label style="font-size: 14px;"> {if $registrationsSettings.fieldData.calendar_view}{$registrationsSettings.fieldData.calendar_view}{else} agenda (default){/if} </label>
+                                </div>
+                            </td>
+                        </tr>
+                        <tr>
+                            <th></th>
+                            <td>
+                                <input type="checkbox" name="use_registration_amenities" {if $registrationsSettings.fieldData.use_registration_amenities.value}checked{/if}>Activate Event Amenities<br><br>
+                            </td>
+                        </tr>
+                        <tr>
+                            <th>Event Amenities Terms:</th>
+                            <td>
+                                <table class="glm-admin-table">
+                                    <tr>
+                                        <th {if $registrationsSettings.fieldRequired.term_registration_amenities_singular}class="glm-required"{/if}>Amenities Singular:</th>
+                                        <td {if $registrationsSettings.fieldFail.term_registration_amenities_singular}class="glm-form-bad-input"{/if}>
+                                            <input type="text" name="term_registration_amenities_singular" value="{$registrationsSettings.fieldData.term_registration_amenities_singular}" class="glm-form-text-input-medium">
+                                            {if $registrationsSettings.fieldFail.term_registration_amenities_singular}<p>{$registrationsSettings.fieldFail.term_registration_amenities_singular}</p>{/if}
+                                        </td>
+                                    </tr>
+                                    <tr>
+                                        <th {if $registrationsSettings.fieldRequired.term_registration_amenities_plural}class="glm-required"{/if}>Amenities Plural:</th>
+                                        <td {if $registrationsSettings.fieldFail.term_registration_amenities_plural}class="glm-form-bad-input"{/if}>
+                                            <input type="text" name="term_registration_amenities_plural" value="{$registrationsSettings.fieldData.term_registration_amenities_plural}" class="glm-form-text-input-medium">
+                                            {if $registrationsSettings.fieldFail.term_registration_amenities_plural}<p>{$registrationsSettings.fieldFail.term_registration_amenities_plural}</p>{/if}
+                                        </td>
+                                    </tr>
+                                </table>
+                            </td>
+                        </tr>
+                        <tr>
+                            <th>Event Venue Locations.</th>
+                            <td>
+                                <input type="checkbox" name="use_venue_locations" {if $registrationsSettings.fieldData.use_venue_locations.value}checked{/if}>Activate Member/Venue Locations<br><br>
+                            </td>
+                        </tr>
+                        <tr>
+                            <th></th>
+                            <td>
+                                <div class="">
+
+                                </div>
+                            </td>
+                        </tr>
+                        <tr>
+                            <th></th>
+                            <td>
+                                <div class="">
+
+                                </div>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <h1> E-Mail Notification Settings </h1>
+                            </td>
+                        </tr>
+                        <tr>
+                        </tr>
+                        <tr>
+                            <th class="emailLabel"> Sender Email Address </th>
+                            <td><input class="glm-form-text-input-medium" name="from_email" id="fromEmailAddress" type="text" value="{$registrationsSettings.fieldData.from_email}"></td>
+                        </tr>
+                        <tr>
+                            <th class="emailLabel"> Recipient Email Address (comma separated) </th>
+                            <td><input class="glm-form-text-input-medium" name="to_email" id="toEmailAddress" type="text" value="{$registrationsSettings.fieldData.to_email}"></td>
+                        </tr>
+                        <tr>
+                            <th>Email Notification</th>
+                            <td>
+                                <textarea rows="3" cols="90" name="email_notification" id="emailNotification">{$registrationsSettings.fieldData.email_notification} </textarea>
+                            </td>
+                        </tr>
+                        <tr>
+                    </table>
+                    <input type="submit" value="Update Settings" class="button-primary">
+                </form>
+            </td>
+        </tr>
+    </table>
+
+    <!-- Tests -->
+
+    <table id="glm-table-icalfeed" class="glm-admin-table glm-settings-table{if $option!='icalfeed'} glm-hidden{/if}">
+  {if $icalFeedResult}
+        <tr>
+            <td colspan="2">
+                {$icalFeedResult}
+            </td>
+        </tr>
+  {/if}
+        <tr>
+            <td colspan="2">
+                <form action="{$thisUrl}">
+                    <input type="hidden" name="page" value="{$thisPage}" />
+                    <input type="hidden" name="glm_action" value="registrations" />
+                    <input type="hidden" name="option" value="icalfeed" />
+                    <label for="glm_registration_feed_url">Feed Url for Import</label><br />
+                    <input type="text" id="glm_registration_feed_url" name="feed_url" value="" />
+                    <input class="button" type="submit" value="Add Feed Url" />
+                </form>
+            </td>
+        </tr>
+        <tr>
+            <td colspan="2">
+                <table >
+                    <tr>
+                        <th>&nbsp;</th>
+                        <th>Feed Url</th>
+                        <th>Created Date</th>
+                        <th>Updated Date</th>
+                        <th>Next Run</th>
+                        <th>Events</th>
+                        <th>Duration</th>
+                        <th>&nbsp;</th>
+                    </tr>
+                    {if $import_feeds}
+                        {foreach $import_feeds as $key => $feed}
+                        <tr>
+                            <td>
+                                <a href="{$thisUrl}?page={$thisPage}&glm_action=registrations&option=icalfeed&option2=refresh&id={$feed.id}" class="button">Refresh</a>
+                            </td>
+                            <td>{$feed.feed_url}</td>
+                            <td>{$feed.created}</td>
+                            <td>{$feed.updated}</td>
+                            <td>{$feed.next_runtime|date_format:"%F %T"}</td>
+                            <td>{$feed.registrations}</td>
+                            <td>{if $feed.duration}
+                                    {***************************************************************************************
+                                    Calculate the duration time in hour:min:sec
+                                    hour = time / 3600
+                                    min  = (time / 60) % 60
+                                    sec  = time % 60
+                                    The smarty way of doing things!
+                                    ****************************************************************************************}
+                                    {math assign="t_hours" equation="t_time / 3600" t_time=$feed.duration format="%d"}
+                                    {math assign="t_minutes" equation="(t_time / 60) % 60" t_time=$feed.duration format="%d"}
+                                    {math assign="t_seconds" equation="t_time % 60" t_time=$feed.duration format="%d"}
+
+                                    {$t_hours}:{$t_minutes}:{$t_seconds}
+                                {/if}</td>
+                            <td><a href="{$thisUrl}?page={$thisPage}&glm_action=registrations&option=icalfeed&option2=delete&id={$feed.id}"
+                                   onClick="return confirm('This cannot be undone!\nAre you sure?')" class="button">Delete</a></td>
+                        </tr>
+                        {/foreach}
+                    {/if}
+                </table>
+            </td>
+        </tr>
+    </table>
+
+    <!-- Import -->
+
+    <table id="glm-table-registrationimport" class="glm-admin-table glm-settings-table{if $option!='registrationimport'} glm-hidden{/if}">
+    <tr><td><a href="{$thisUrl}?page={$thisPage}&glm_action=registrations&option=registrationimport&action=redo">Redo Times</a></td></tr>
+  {if $importResult}
+        <tr><td><a href="{$thisUrl}?page={$thisPage}&glm_action=registrations&option=registrationimport">Return to Import Events</a></td></tr>
+        <tr>
+            <td colspan="2">
+                {$importResult}
+            </td>
+        </tr>
+  {else}
+        <tr>
+            <td colspan="2"><h1>Import from Gaslight Events</h1></td>
+        </tr>
+        <tr>
+            <td colspan="2">
+                <form action="{$thisUrl}">
+                    <input type="hidden" name="page" value="{$thisPage}">
+                    <input type="hidden" name="glm_action" value="registrations">
+                    <input type="hidden" name="option" value="registrationimport">
+                    <input type="hidden" name="import" value="true">
+                    <div style="float:left;width: 200px;">
+                        <fieldset>
+                            <legend>Database to import from:</legend>
+                            <label for="db_host">DB Host</label>
+                            <input id="db_host" name="db_host" />
+                            <label for="db_name">DB Name</label>
+                            <input id="db_name" name="db_name" />
+                            <label for="db_user">DB User</label>
+                            <input id="db_user" name="db_user" />
+                            <label for="db_password">DB Password</label>
+                            <input id="db_password" name="db_password" />
+                        <fieldset>
+                    </div>
+                    <div style="float:left;width: 200px;">
+                        <fieldset>
+                            <legend>Settings:</legend>
+                            <label for="schema">Schema</label>
+                            <input id="schema" name="schema" />
+                            <label for="cattablename">Category Table Name</label>
+                            <input id="cattablename" name="cattablename" />
+                            <label for="tablename">Event Table Name</label>
+                            <input id="tablename" name="tablename" />
+                            <label for="sdate">Start Date</label>
+                            <input id="sdate" name="sdate" />
+                        </fieldset>
+
+                        <input type="submit" value="Import Events" />
+                    </div>
+                </form>
+            </td>
+        </tr>
+        <tr>
+            <td colspan="2">
+                <form action="{$thisUrl}">
+                    <input type="hidden" name="page" value="{$thisPage}">
+                    <input type="hidden" name="glm_action" value="registrations">
+                    <input type="hidden" name="option" value="registrationImagesImport">
+                    <div style="float:left;width: 200px;">
+                        <fieldset>
+                            <legend>Image Style Owner:</legend>
+                            <label for="db_host">Owner Id</label>
+                            <input id="img_owner_id" name="img_owner_id" />
+                        <fieldset>
+                        <input type="submit" value="Import Files" />
+                    </div>
+                </form>
+            </td>
+        </tr>
+  {/if}
+
+    </table>
+    <table id="glm-table-timelyimport" class="glm-admin-table glm-settings-table{if $option!='timelyImport'} glm-hidden{/if}">
+  {if $importResult}
+        <tr><td><a href="{$thisUrl}?page={$thisPage}&glm_action=registrations&option=timelyImport">Return to Time.ly Import</a></td></tr>
+        <tr>
+            <td colspan="2">
+                {$importResult}
+            </td>
+        </tr>
+  {else}
+        <tr>
+            <td colspan="2"><h1>Import Time.ly Events</h1></td>
+        </tr>
+        <tr>
+            <td colspan="2">
+                <form action="{$thisUrl}">
+                    <input type="hidden" name="page" value="{$thisPage}" />
+                    <input type="hidden" name="glm_action" value="registrations" />
+                    <input type="hidden" name="option" value="timelyImport" />
+                    <input type="hidden" name="import" value="true" />
+                    <div style="float:left;width: 200px;">
+                        <input type="submit" value="Import Events" />
+                    </div>
+                </form>
+            </td>
+        </tr>
+  {/if}
+
+
+    <script type="text/javascript">
+
+        jQuery(document).ready(function($) {
+
+            /*
+             * Edit area tabs
+             */
+            $('.glm-settings-tab').click( function() {
+
+                // Clear tabl highlights and hide all tables
+                $('.glm-settings-tab').removeClass('nav-tab-active');
+                $('.glm-settings-table').addClass('glm-hidden');
+
+                // Highlight selected tab
+                $(this).addClass('nav-tab-active');
+
+                // Show selected table
+                var table = $(this).attr('data-show-table');
+                $('#' + table).removeClass('glm-hidden');
+
+            });
+
+            // 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);
+
+                if('{$registrationsSettings.fieldData.calendar_view}'){
+                    $("#calendar-view").val('{$registrationsSettings.fieldData.calendar_view}');
+                } else {
+                    $("#calendar-view").val("agenda");
+                }
+        });
+    </script>
diff --git a/views/admin/management/header.html b/views/admin/management/header.html
new file mode 100644 (file)
index 0000000..f8ac0d9
--- /dev/null
@@ -0,0 +1,15 @@
+<h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
+    <input type="hidden" name="glm_action" value="general">
+    
+    
+    <a id="glm-settings" data-show-table="glm-table-general" href="{$thisUrl}?page=registrations?glm_action=general" 
+       class="glm-settings-tab nav-tab{if $option=='general'} nav-tab-active{/if}">
+        General
+    </a>
+    
+    <a id="glm-settings" data-show-table="glm-table-terms" href="{$thisUrl}?page=registrations?glm_action=terms"  
+       class="glm-settings-tab nav-tab{if $option=='terms'  }{/if}">
+        Terms
+    </a>
+    
+</h2>
\ No newline at end of file