Added PayPal support to checkout and updated database
authorChuck Scott <cscott@gaslightmedia.com>
Mon, 4 Jun 2018 20:25:24 +0000 (16:25 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Mon, 4 Jun 2018 20:25:24 +0000 (16:25 -0400)
Updated text displayed in alert when trying to register more attendees per submission than permitted.
Updated database to version 1.0.0 in prep for first release.
Added PayPal sandbox id/secret fields to database and management.
Fixed problem with payment types not properly selected for checkout in checkout.php
Fixed problem with checkout button after adding PayPal.

21 files changed:
classes/data/dataManagement.php
classes/regCartSupport.php
config/plugin.ini
index.php
js/frontRegApp.js
models/admin/ajax/regPayPal.php [new file with mode: 0644]
models/front/registrations/checkout.php
models/front/registrations/checkoutProcess.php
setup/databaseScripts/create_database_V0.0.31.sql [deleted file]
setup/databaseScripts/create_database_V1.0.0.sql [new file with mode: 0644]
setup/databaseScripts/dbVersions.php
setup/databaseScripts/drop_database_V0.0.31.sql [deleted file]
setup/databaseScripts/drop_database_V1.0.0.sql [new file with mode: 0644]
setup/databaseScripts/update_database_V0.0.31.sql
setup/databaseScripts/update_database_V0.0.32.sql [new file with mode: 0644]
setup/databaseScripts/update_database_V1.0.0.sql [new file with mode: 0644]
setup/validActions.php
views/admin/management/registrations.html
views/front/registrations/checkout.html
views/front/registrations/registration.html
views/front/registrations/summaryStore.html

index 1aa84ae..8616293 100644 (file)
@@ -293,8 +293,8 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
             'reg_merchant_solutions_test' => array (
                 'field' => 'reg_merchant_solutions_test',
                 'type' => 'list',
-                'list' => $this->config['proc_test_mode'],
-                'default' => $this->config['proc_test_mode_numb']['Local Approval Test'],
+                    'list' => $this->config['proc_test_mode'],
+                    'default' => $this->config['proc_test_mode_numb']['Local Approval Test'],
                 'use' => 'a'
             ),
 
@@ -313,6 +313,43 @@ class GlmDataRegistrationsManagement extends GlmDataAbstract
                 'use' => 'a'
             ),
 
+            // PayPal Client ID
+            'reg_paypal_clientid' => array (
+                'field' => 'reg_paypal_clientid',
+                'type' => 'text',
+                'use' => 'a'
+            ),
+
+            // PayPal Secret
+            'reg_paypal_secret' => array (
+                'field' => 'reg_paypal_secret',
+                'type' => 'text',
+                'use' => 'a'
+            ),
+
+            // PayPal Sandbox Client ID
+            'reg_paypal_sandbox_clientid' => array (
+                'field' => 'reg_paypal_sandbox_clientid',
+                'type' => 'text',
+                'use' => 'a'
+            ),
+
+            // PayPal Sandbox Secret
+            'reg_paypal_sandbox_secret' => array (
+                'field' => 'reg_paypal_sandbox_secret',
+                'type' => 'text',
+                'use' => 'a'
+            ),
+
+            // PayPal Test Mode
+            'reg_paypal_test' => array (
+                'field' => 'reg_paypal_test',
+                'type' => 'list',
+                    'list' => $this->config['paypal_test_mode'],
+                    'default' => $this->config['paypal_test_mode_numb']['Sandbox'],
+                'use' => 'a'
+            ),
+
             // Always Use Full Billing Info
             'reg_full_billing_info' => array (
                 'field' => 'reg_full_billing_info',
index a77d150..939b1db 100644 (file)
@@ -398,6 +398,9 @@ class GlmRegCartSupport
         $grandTotal             = 0;
         $haveEvents             = false;
 
+        // Build separate array of charges to use for payment processors
+        $this->cart['chargeItems']            = array();
+
         // If we have a cart and a good request array
         if ($this->cart && is_array($this->cart['request'])) {
 
@@ -562,6 +565,15 @@ class GlmRegCartSupport
                                                     $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['registrantRate']      = $registrantCharges;
                                                     $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['registrantDiscounts'] = $registrantDiscounts;
 
+                                                    // Add to charges summary array
+                                                    $this->cart['chargeItems'][] = array(
+                                                        'quantity' => 1,
+                                                        'name' =>
+                                                            $this->config['terms']['reg_term_event_cap'].': '.$event['event_name'].', '.
+                                                            $this->config['terms']['reg_term_attendee_cap'].': '.$registrant['fname'].' '.$registrant['lname'],
+                                                        'price' => $rateRegistrantCharges
+                                                    );
+
                                                 }
 
                                                 // Add a more familiar date/time
@@ -609,6 +621,14 @@ class GlmRegCartSupport
                                         $classCharges       += ( $rateBaseCharge + $rateRegistrantCharges);
                                         $classDiscounts     += $rateDiscounts;
 
+                                        // Add to charges summary array
+                                        $this->cart['chargeItems'][] = array(
+                                            'quantity' => 1,
+                                            'name' =>
+                                                $this->config['terms']['reg_term_level_cap'].': '.$rate['rate_name'],
+                                            'price' => $rateBaseCharge + $rateDisconts
+                                        );
+
                                     }
 
                                     if ($deleteRateNow) {
@@ -727,6 +747,15 @@ class GlmRegCartSupport
                         $totalCharges       += $eventCharges;
                         $totalDiscounts     += $eventDiscounts;
 
+                        // Add to charges summary array
+                        if ($eventDiscounts != 0) {
+                            $this->cart['chargeItems'][] = array(
+                                'quantity' => 1,
+                                'name' => $event['event_name'].' Discounts',
+                                'price' => -$eventDiscounts
+                            );
+                        }
+
                     }
 
                     if ($deleteEventNow) {
@@ -760,6 +789,14 @@ class GlmRegCartSupport
 
                             $code['thisDiscount'] = $thisDiscount;
                             $this->cart['globalPayCodes'][$code['id']] = $code;
+
+                            // Add to charges summary array
+                            $this->cart['chargeItems'][] = array(
+                                'quantity' => 1,
+                                'name' => 'Payment Code: '.$code['code'],
+                                'price' => -$thisDiscount
+                            );
+
                         }
 
                     }
index f63c94a..c73bb20 100644 (file)
@@ -36,7 +36,7 @@ payment_method[3]                               = 'Cash'
 payment_method[4]                               = 'Check'
 ; payment_method[5]                               = 'Call from Merchant'
 payment_method[6]                               = 'Credit Card'
-payment_method[7]                               = 'PayPal'
+payment_method[7]                               = 'PayPal'
 payment_method [10]                             = 'Payment Pending'
 
 payment_method_numb['NoCharge']                 = 1
@@ -45,7 +45,7 @@ payment_method_numb['Cash']                     = 3
 payment_method_numb['Check']                    = 4
 ; payment_method_numb['CallFromMerchant']         = 5
 payment_method_numb['CreditCard']               = 6
-payment_method_numb['PayPal']                   = 7
+payment_method_numb['PayPal']                   = 7
 payment_method_numb['Pending']                  = 10
 
 ; Default payment method is Credit Card
index 10137cc..a1fc56c 100644 (file)
--- a/index.php
+++ b/index.php
@@ -44,7 +44,7 @@ if (!defined('ABSPATH')) {
  *  version from this plugin.
  */
 define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION', '0.0.1');
-define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_VERSION', '0.0.31');
+define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_VERSION', '1.0.0');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
 define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.10.27');
index c7bc321..e946ffb 100644 (file)
@@ -944,7 +944,7 @@ app.Views.Front.RegTime = Backbone.View.extend({
     // add new account
     addNewAccount: function(){
         if ( app.checkForMaxAttendees() === true ) {
-            alert( 'You\'re only allowed to have ' + app.attendeeMaxPerReg + ' ' + app.attendeePlurCapTerm + ' per Registration!' );
+            alert( app.attendeePlurCapTerm + ' are currently limited to ' + app.attendeeMaxPerReg + ' per submission for this ' + app.eventCapTerm + '!');
             return;
         }
         // check for the lock
diff --git a/models/admin/ajax/regPayPal.php b/models/admin/ajax/regPayPal.php
new file mode 100644 (file)
index 0000000..c03b3a7
--- /dev/null
@@ -0,0 +1,238 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Registration add-on PayPal payment AJAX processor
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+// Load PayPal Payment CLass
+require_once GLM_MEMBERS_PLUGIN_LIB_PATH . '/paymentProcessors/PayPal/paymentGateway.php';
+
+// Load Registrations Support
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/regCartSupport.php';
+
+
+/**
+ * This class processes AJAX requests for the PayPal payment actions
+ */
+class GlmMembersAdmin_ajax_regPayPal extends GlmRegCartSupport
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * PayPal Account Data
+     *
+     * @var $account
+     * @access public
+     */
+    public $account = false;
+    /**
+     * PayPal Payment Data
+     *
+     * @var $payment
+     * @access public
+     */
+    public $payment = false;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for data class
+        // parent::__construct(false, false);
+
+        // Build Account Array
+
+
+        // Build Payment Array
+        $this->account = array(
+            'clientID' => $this->config['settings']['reg_paypal_clientid'],
+            'secret' => $this->config['settings']['reg_paypal_secret'],
+            'returnURL' => GLM_MEMBERS_PLUGIN_ADMIN_AJAX_URL.'?PayPalAction=Approved',
+            'cancelURL' => GLM_MEMBERS_PLUGIN_ADMIN_AJAX_URL.'?PayPalAction=Canceled',
+            'test' => $this->config['settings']['reg_paypal_test']
+        );
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This model performs the various PayPal request and call back actions
+     *
+     * This model action does not return, it simply does it's work then calls wp_die();
+     *
+     * @param $actionData
+     *
+     */
+    public function modelAction( $actionData = false )
+    {
+
+        // Add cart ID and check value to URLs
+        $cartId = false;
+        if (isset($_SESSION['cartID'])) {
+            $cartId = $_SESSION['cartID'];
+        } elseif (isset($_REQUEST['cart'])) {
+            $cartId = $_REQUEST['cart'] - 0;
+        }
+        $cartCheck = false;
+        if (isset($_SESSION['cartCheck'])) {
+            $cartCheck = $_SESSION['cartCheck'];
+        } elseif (isset($_REQUEST['cartCheck'])) {
+            $cartCheck = $_REQUEST['cartCheck'];
+        }
+
+        // Make sure we have good cart ID and Cart Check
+        $cartCheckExpected = md5($cartId.GLM_MEMBERS_REGISTRATIONS_PLUGIN_SECRET);
+        if (!$cartId || $cartId <= 0 || !$cartCheck || $cartCheck != $cartCheckExpected ) {
+            wp_die('Invalid Cart');
+        }
+
+        // Save Cart ID and CartCheck
+        $_SESSION['cartID'] = $cartId;
+        $_SESSION['cartCheck'] = $cartCheck;
+
+        // Get Cart Data
+        $this->getRegistrationCart($cartId);
+        if (!$this->cart['status']) {
+            wp_die('Cart Not Found');
+        }
+
+        // Build Payment Array
+        $this->payment = array(
+            'name'          => $this->config['settings']['reg_org_name'],
+            'charge'        => substr($this->cart['request']['total'], 1, -1),
+            'invoice'       => $cartId,
+            'description'   => $this->config['terms']['reg_term_registrations_name'],
+            'items'         => array()
+        );
+
+        // Add items
+        foreach ($this->cart['events'] as $event) {
+            $this->payment['items'][] = array(
+                'quantity'      => 1,
+                'name'          => 'Total for all requested '.$this->config['terms']['reg_term_registration_plur_cap'],
+                'price'         => substr($this->cart['request']['total'], 1, -1)
+            );
+        }
+
+// echo "<pre>".print_r($this->account,1).print_r($this->payment,1)."</pre>";
+// echo "<pre>".print_r($this->cart,1)."</pre>";
+// echo "REQUEST = $request";
+
+        // Set default action and try to get any requested action
+        $request = false;
+        if (isset($_REQUEST) && isset($_REQUEST) && isset($_REQUEST['PayPalAction']) && trim($_REQUEST['PayPalAction']) != '') {
+            $request = $_REQUEST['PayPalAction'];
+        }
+
+        // Check for certain actions related to sending user to PayPal site for approval
+        switch ($request) {
+
+            case 'Approved':
+
+                echo "Return link followed.<P>";
+
+                // Save Payer ID
+                $_SESSION['payerID'] = $_REQUEST['PayerID']; // NEED TO FILTER THIS FOR PRODUCTION
+
+                // Create PayPal object with existing access object from the session
+                $PayPal = new PaymentGateway($this->account, $_SESSION['access'], $_SESSION['trans']);
+
+                // Execute the PayPal payment
+                $r = $PayPal->executePayment($_SESSION['payerID']);
+
+                echo "<p>Payment Executed Successfully</p><pre>".print_r($r,1)."</pre>";
+
+                exit;
+
+                break;
+
+            case 'Canceled':
+
+                echo "Payment Cancelled<P>";
+                exit;
+                break;
+
+            // Display PayPal login and get approval
+            default:
+
+                // Clear any existing PayPal transaction data in session
+                unset($_SESSION['trans']);
+
+                // Create the PayPal object (note no previous access object)
+                $PayPal = new PaymentGateway($this->account, false, false);
+
+                // Was there an error?
+                if (!$PayPal->status) {
+                    echo "Received an error: ".$PayPal->error;
+                    exit;
+                }
+
+                // Store access information
+// Do we need this?                $_SESSION['access'] = $PayPal->access;
+
+                // Try to enter Payment
+                $PayPal->processPayment($this->payment, $contact);
+
+                // Was there an error?
+                if (!$PayPal->status) {
+                    echo "Received an error: ".$PayPal->error."<br><ul>";
+                    foreach($PayPal->trans->details as $detail) {
+                        echo "<li>".$detail->issue."</li>";
+                    }
+                    echo "</ul>";
+
+                    exit;
+                }
+
+                // Store Transaction data to session
+                $_SESSION['trans'] = $PayPal->trans;
+
+                // Get Approval for this transaction from PayPal
+                $trans = $_SESSION['trans'];
+
+                header('Location: '.$trans->urls->approval_url->href);
+
+                exit;
+
+                break;
+        }
+
+    }
+}
index f03805d..f032264 100644 (file)
@@ -137,7 +137,11 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport
             $this->checkRegistrationRequest($cartId);
 
             // Check if cart has been successfully checked out or has been marked canceled.
-            if ($this->cart['request']['status']['value'] > 0) {
+            $statusCheck = array(
+                $this->config['submission_status_numb']['CART'],
+                $this->config['submission_status_numb']['PAYMENT_PEND']
+            );
+            if (!in_array($this->cart['request']['status']['value'], $statusCheck)) {
 
                 $messages[] = "This request has already been submitted!<br>The information below is a summary of your submitted request.";
 
@@ -318,15 +322,16 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport
 
         $view = 'checkout';
 
-
         require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataManagement.php';
         $Management = new GlmDataRegistrationsManagement($this->wpdb, $this->config);
         $management = $Management->getEntry(1);
 
-        // Get all payment methods and assume they might all be available
-        $availPaymentMethods = $management['reg_payment_methods']['bitmap'];
-        foreach ($availPaymentMethods as $methKey=>$methVal) {
-            $availPaymentMethods[$methKey]['default'] = true;
+        // Get all payment methods and select the ones that are enabled in managemnt
+        $availPaymentMethods = array();
+        foreach ($management['reg_payment_methods']['bitmap'] as $methKey=>$methVal) {
+            if ($methVal['default']) {
+                $availPaymentMethods[$methKey] = $methVal;
+            }
         }
 
         // For each event in cart, check each payment method. Only methods enabled in all events are available.
@@ -338,6 +343,7 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport
                 if (!$payMethodVal['default'] && isset($availPaymentMethods[$payMethodKey])) {
                     unset($availPaymentMethods[$payMethodKey]);
                 }
+
             }
         }
 
@@ -362,28 +368,32 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport
 
         // Compile template data
         $templateData = array(
-            'page'          => 'checkout',
-            'regAccountId'  => $this->cart['request']['account'],
-            'regAccount'    => $regAccount,
-            'cartId'        => $cartId,
-            'haveCart'      => $haveCart,
-            'cart'          => $this->cart,
-            'checkoutUrl'   => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/',
-            'loggedIn'      => $loggedIn,
-            'regUrl'        => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/',
-            'assetUrl'      => GLM_MEMBERS_REGISTRATIONS_PLUGIN_ASSETS_URL,
-            'haveMessages'  => count($messages) > 0,
-            'messages'      => $messages,
-            'defaultPayMethod'     => $payMethod,
-            'payMethods'    => $availPaymentMethods,
-            'payMethodsNumb' => $this->config['payment_method_numb'],
-            'misc'          => $misc,
-            'checkoutPageText'  => $misc['checkout_page_text'],
-            'globalTerms'   => $misc['reg_terms'],
-            'eventCustomFieldsFidPrefix'    => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG.'-customfields-reg-event-'
+            'page'                          => 'checkout',
+            'regAccountId'                  => $this->cart['request']['account'],
+            'regAccount'                    => $regAccount,
+            'cartId'                        => $cartId,
+            'cartCheck'                     => md5($cartId.GLM_MEMBERS_REGISTRATIONS_PLUGIN_SECRET),
+            'haveCart'                      => $haveCart,
+            'cart'                          => $this->cart,
+            'checkoutUrl'                   => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/',
+            'loggedIn'                      => $loggedIn,
+            'regUrl'                        => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/',
+            'assetUrl'                      => GLM_MEMBERS_REGISTRATIONS_PLUGIN_ASSETS_URL,
+            'haveMessages'                  => count($messages) > 0,
+            'messages'                      => $messages,
+            'defaultPayMethod'              => $payMethod,
+            'payMethods'                    => $availPaymentMethods,
+            'payMethodsNumb'                => $this->config['payment_method_numb'],
+            'misc'                          => $misc,
+            'checkoutPageText'              => $misc['checkout_page_text'],
+            'globalTerms'                   => $misc['reg_terms'],
+            'eventCustomFieldsFidPrefix'    => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG.'-customfields-reg-event-',
+            'payPalClientId'                => $this->config['settings']['reg_paypal_clientid'],
+            'payPalSandboxClientId'         => $this->config['settings']['reg_paypal_sandbox_clientid'],
+            'payPalMode'                    => $this->config['settings']['reg_paypal_test']
         );
 
-        // echo "<pre>".print_r($templateData,1)."</pre>";
+        // echo "payMethods<pre>".print_r($availPaymentMethods,1)."</pre>";
 
         // Return status, any suggested view, and any data to controller
         return array(
index 7fb2e45..8b51c2c 100644 (file)
@@ -268,12 +268,6 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport
 
         }
 
-        /*
-         * Process any Custom Fields
-         */
-
-// ******* NEED TO DO THIS ??? ********
-
         /*
          * Process Payment?
          */
@@ -560,8 +554,40 @@ class GlmMembersFront_registrations_checkoutProcess extends GlmRegCartSupport
                 break;
 
             // Pay Pal
-//            case $this->config['payment_method_numb']['PayPal']:
-//                break;
+            case $this->config['payment_method_numb']['PayPal']:
+
+                // Check for valid PayPal payment
+                $payPalPaymentID = filter_input(INPUT_POST, 'payPalPaymentID', FILTER_SANITIZE_STRING);
+                $payPalPaymentTime = filter_input(INPUT_POST, 'payPalPaymentTime', FILTER_SANITIZE_STRING);
+                $payPalPaymentState = filter_input(INPUT_POST, 'payPalPaymentState', FILTER_SANITIZE_STRING);
+
+                // If we don't have a valid payment, add to messages array
+                if (!$payPalPaymentID || !$payPalPaymentTime || !$payPalPaymentState || $payPalPaymentState != "completed") {
+                    $messages[] = 'Sorry, we were unable to determine the status of your PayPal payment. Please check your PayPal account to see if the amount has been paid and if so, call us for assitance.';
+                } else {
+
+                    // We have a valid payment
+                    $cartStatus = $this->config['submission_status_numb']['COMPLETE'];
+
+                    // Store PayPal confirmation information in the CreditCard related fields.
+                    $reqData = array_merge(
+                        $reqData,
+                        array(
+                            'cc_name' => 'PayPal',
+                            'cc_conf' => $payPalPaymentID.' - '.$payPalPaymentTime
+                        )
+                    );
+                    $reqFormat = array_merge(
+                        $reqFormat,
+                        array(
+                            '%s',
+                            '%s',
+                        )
+                    );
+
+                }
+
+                break;
 
             // Payment Method unknown
             default:
diff --git a/setup/databaseScripts/create_database_V0.0.31.sql b/setup/databaseScripts/create_database_V0.0.31.sql
deleted file mode 100644 (file)
index 1b0abac..0000000
+++ /dev/null
@@ -1,806 +0,0 @@
--- Gaslight Media Registration Database
--- File Created: 01/18/2017 14:40:00
--- Database Version: 0.0.19
--- Database Creation Script
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
---
-/*
- * General Database Organization
- * -----------------------------
- *
- * management - General options and configuration - Site manager access only
- *
- * misc - Misc settings and text - Site owner may update
- *
- * payment codes - Promotional payment codes - Used with various things
- *      --> Event, Submission, Event Registration, Event Registrant, Account or global
- *
- * reg_event - Describes registration for that event
- *      reg_time - One record for each date/time this event has people registered - Primarily tracks attendee counts and charge totals
- *      reg_class - Type of registration for this event (one or more)
- *          reg_rates - Date range / rate for a reg class (one or more)
- *
- * reg_account - Describes someone who submits / pays for a registration
- * Make these two things the same table....
- * registrant - A person who is registered for an event
- *
- * reg_request - Information on a specific request for registrations
- *      reg_request_event - Event selected (one or more)
- *          reg_request_class - Class of registration (one or more)
- *              reg_request_rate - Specific registration date/rate (one or more)
- *                  reg_request_registrant - Registrant (one or more)
- *
- * NOTE: additional fields and added fields data will be coming from the Custom Fields add-on
- *
- * Overall Flow
- * ------------
- *
- * User selects an event
- * If the event has available registrations
- *  User selects a date for the registration (or if only one that's selected automatically)
- *    User can log back into registrations at this point if they've been there before and have a password, create an ccount, or continue as guest ???
- *      User selects an available rate type and adds one or more registrants for that rate type
- *      User may loop back to select additional rate type(s) and registrants
- *    User may go back to date selection and request additional rate types and registrants for the addional dates
- *  User may go back to select additional dates and do registrations for those dates as above
- * User may go back to select other events and do registrations for them as above
- * User may select the "Cart" and deselect something added to it
- * User may checkout
- *
- */
-
-/*
- * NOTE: Anything below here may not be completed or accurate yet. I'm still working though this
- * Lines commented out are selected for possible deletion.
- * The INSERT statements are not up-to-date with the tables.
- * The "config/plugin.ini" file in this plugin is also a work in progress.
- */
-
--- Management Options
--- General configurationm parameters for the Registrations application
--- Only one entry in this table!
-CREATE TABLE {prefix}management (
-    id INT NOT NULL AUTO_INCREMENT,
-    canonical_reg_page TINYTEXT NULL,                              -- Canonical page slug for registrations
-    -- System Owner Information
-    reg_org_name TINYTEXT NULL,                                     -- Customer Information - Name of Organization
-    reg_org_short TINYTEXT NULL,
-    reg_org_address TINYTEXT NULL,
-    reg_org_city TINYTEXT NULL,
-    reg_org_state TINYTEXT NULL,
-    reg_org_zip TINYTEXT NULL,
-    reg_org_phone TINYTEXT NULL,
-    reg_org_toll_free TINYTEXT NULL,
-    reg_org_internal_email TINYTEXT NULL,
-    reg_org_from_email TINYTEXT NULL,
-    reg_payment_methods SMALLINT NULL,                              -- Payment methods available for all registrations - Bitmap - see payment_method in plugin.ini
-    reg_proc_methods SMALLINT NULL,                                 -- Credit Cart payment processing methods available - Bitmap - see proc_method in plugin.ini
-    reg_cc_accepts SMALLINT NULL,                                   -- Credit Cards Accepted - Bitmap - See credit_card in plugin.ini
-    -- Authorize.net Credentials
-    reg_authorize_net_login TINYTEXT NULL,
-    reg_authorize_net_key TINYTEXT NULL,
-    reg_authorize_net_test TINYINT NULL,                            -- Authorize.net test mode - List - see proc_test_mode in plugin.ini
-    reg_authorize_net_conf BOOLEAN NULL,                            -- Flag to send payment confirmation Email from Authorize.net
-    reg_authorize_net_merchant_email TINYTEXT NULL,                 -- E-Mail Authorize.net will send copy of confirmation E-Mail
-    reg_authorize_net_merchant_seal TEXT NULL,                      -- Authorize.net Verified Merchant Seal code
-    -- Merchant Solutions Credentials
-    reg_merchant_solutions_acctid TINYTEXT NULL,                    -- Merchant Solutions credentials
-    reg_merchant_solutions_merchantpin TINYTEXT NULL,
-    reg_merchant_solutions_test TINYINT NULL,                       -- Merchant Solutions test mode - List - see proc_test_mode in plugin.ini
-    reg_merchant_solutions_conf BOOLEAN NULL,                       -- Flag to send payment confirmation Email
-    reg_merchant_solutions_merchant_email TINYTEXT NULL,            -- Merchant Solutions will send copy of confirmation E-Mail
-    -- Billing settings
-    reg_full_billing_info BOOLEAN NULL,                             -- Always request full billing information in checkout page regardless of the following settings
-    reg_bill_info_req_no_charge SMALLINT NULL,                      -- Bitmap of fields to use in checkout for these types of payments - See billing_field in plugin.conf
-    reg_bill_info_req_comp_code SMALLINT NULL,
-    reg_bill_info_req_cash SMALLINT NULL,
-    reg_bill_info_req_check SMALLINT NULL,
-    reg_bill_info_req_credit_card SMALLINT NULL,
-    reg_bill_info_req_merchant_call SMALLINT NULL,
-    -- Misc Options
-    reg_request_hold_days SMALLINT NULL,                            -- Number of days past last update that a request will be retained in "CART" status.
-    req_account_hold_days SMALLINT NULL,                            -- Number of days past last update that an account will be retained when there are no requests or registrants referring to it.
-    reg_not_submitted_dialog BOOLEAN NULL,                          -- Flag to show page not submitted dialog boxes
-    reg_medical_info BOOLEAN NULL,                                  -- This site can ask for "Medical Info" - set in main category of an event
-    reg_show_navigation_aids BOOLEAN NULL,                          -- No, not marine navigational aids, this enables additional text, arrows, etc to direct a user to do something specific that would not normally be required.
-    PRIMARY KEY (id)
-);
-
-----
-
--- Terms used in site modifiable on Management page in admin - Only 1 entry in this table
--- Terms in this table should be all self-explanatory
-CREATE TABLE {prefix}settings_terms (
-    id INT NOT NULL AUTO_INCREMENT,
-    reg_term_registrations_name TINYTEXT NULL,                      -- Term "Event Registration"
-    reg_term_registration TINYTEXT NULL,
-    reg_term_registration_cap TINYTEXT NULL,
-    reg_term_registration_plur TINYTEXT NULL,
-    reg_term_registration_plur_cap TINYTEXT NULL,
-    reg_term_register TINYTEXT NULL,
-    reg_term_register_cap TINYTEXT NULL,
-    reg_term_registers TINYTEXT NULL,                               -- Intransitive verb of register
-    reg_term_registering TINYTEXT NULL,
-    reg_term_registering_cap TINYTEXT NULL,
-    reg_term_registered TINYTEXT NULL,
-    reg_term_registered_cap TINYTEXT NULL,
-    reg_term_attendee TINYTEXT NULL,
-    reg_term_attendee_cap TINYTEXT NULL,
-    reg_term_attendee_plur TINYTEXT NULL,
-    reg_term_attendee_plur_cap TINYTEXT NULL,
-    reg_term_attending TINYTEXT NULL,
-    reg_term_attended TINYTEXT NULL,
-    reg_term_registered_user TINYTEXT NULL,
-    reg_term_registered_user_cap TINYTEXT NULL,
-    reg_term_registered_user_plur TINYTEXT NULL,
-    reg_term_registered_user_plur_cap TINYTEXT NULL,
-    reg_term_event TINYTEXT NULL,
-    reg_term_event_cap TINYTEXT NULL,
-    reg_term_event_plur TINYTEXT NULL,
-    reg_term_event_plur_cap TINYTEXT NULL,
-    reg_term_id TINYTEXT NULL,
-    reg_term_id_cap TINYTEXT NULL,
-    reg_term_id_plur TINYTEXT NULL,
-    reg_term_id_plur_cap TINYTEXT NULL,
-    reg_term_level TINYTEXT NULL,
-    reg_term_level_cap TINYTEXT NULL,
-    reg_term_level_plur TINYTEXT NULL,
-    reg_term_level_plur_cap TINYTEXT NULL,
-    reg_term_password TINYTEXT NULL,
-    reg_term_password_cap TINYTEXT NULL,
-    reg_term_password_plur TINYTEXT NULL,
-    reg_term_password_plur_cap TINYTEXT NULL,
-    reg_term_instructor TINYTEXT NULL,
-    reg_term_instructor_cap TINYTEXT NULL,
-    reg_term_instructor_plur TINYTEXT NULL,
-    reg_term_instructor_plur_cap TINYTEXT NULL,
-    reg_term_payment_code TINYTEXT NULL,
-    reg_term_payment_code_cap TINYTEXT NULL,
-    reg_term_payment_code_plur TINYTEXT NULL,
-    reg_term_payment_code_plur_cap TINYTEXT NULL,
-    reg_term_registration_button TINYTEXT NULL,
-    reg_term_contact_information TINYTEXT NULL,
-    reg_term_button_event_list TINYTEXT NULL,
-    reg_term_button_login_or_create TINYTEXT NULL,
-    reg_term_button_create_account TINYTEXT NULL,
-    reg_term_button_login TINYTEXT NULL,
-    reg_term_button_logout TINYTEXT NULL,
-    reg_term_button_add_attendee TINYTEXT NULL,
-    reg_term_button_save_attendee TINYTEXT NULL,
-    reg_term_button_attendee_page_continue TINYTEXT NULL,
-    reg_term_button_apply_comp_code TINYTEXT NULL,
-    reg_term_button_cart_page_continue TINYTEXT NULL,
-    reg_term_button_checkout_page_submit TINYTEXT NULL,
-    PRIMARY KEY (id)
-);
-
-----
-
--- Misc system-wide customer configurable configuration
--- Various text and flags to be configured by customer
--- Only one entry in this table!
-CREATE TABLE {prefix}misc (
-    id INT NOT NULL AUTO_INCREMENT,
-    reg_bulletin TEXT NULL,                                     -- Text to display at top of first registration page
-    cart_page_text TEXT NULL,                                   -- Text to display at top of cart page
-    checkout_page_text TEXT NULL,                               -- Text to display at top of checkout page
-    summary_page_text TEXT NULL,                                -- Text to display at top of summary page (after checkout)
-    reg_terms TEXT NULL,                                        -- Registration terms and conditions
-    notify_subject TEXT NULL,                                   -- Subject of notification E-Mail to site owner
-    notify_text TEXT NULL,                                      -- Notification E-Mail text for site owner
-    instr_notify_subject TEXT NULL,                             -- Subject of notification E-Mail to instructor
-    instr_notify_text TEXT NULL,                                -- Notification E-Mail text for instructor
-    submission_notify_subject TEXT NULL,                        -- Subject of notification E-Mail to person submitting the registrations
-    submission_notify_text TEXT NULL,                           -- Notification E-Mail text to person submitting the registrations
-    registrant_notify_subject TEXT NULL,                        -- Subject of notification E-Mail to registrant
-    registrant_notify_text TEXT NULL,                           -- Text of notification E-Mail to registrant
-    submission_ack_subject TEXT NULL,                           -- Subject of acknowledgement E-Mail to person submitting the registrations
-    submission_ack_text TEXT NULL,                              -- Text of acknowledgement E-Mail text to person submitting the registrations
-    registrant_ack_subject TEXT NULL,                           -- Subject of acknowledgement E-Mail to registrant
-    registrant_ack_text TEXT NULL,                              -- Text of acknowledgement E-Mail to registrant
-    PRIMARY KEY (id)
-);
-
-----
-
--- Payment Codes
--- Promotional payment codes for free/discounted payment
-CREATE TABLE {prefix}payment_code (
-    id INT NOT NULL AUTO_INCREMENT,
-    code_type TINYINT NULL,                                     -- Type of adjustment - Free only to start with - See pay_code_type in plugin.ini
-    ref_type TINYINT NULL,                                      -- See payment_ref_type in plugin.ini
-    ref_dest INT NULL,                                          -- Pointer to the specific entity of ref_type
-    code TINYTEXT NULL,                                         -- Text code user must enter to use
-    amount FLOAT,                                               -- Amount of discount if not type "Free" - Either $ amount or percent
-    expire_date DATE NULL,                                      -- Expiration Date
-    
-    descr TEXT NULL,
-    PRIMARY KEY (id),
-    INDEX (ref_dest),
-    INDEX (code(10))
-);
-
-----
-
--- Registration event specific information
--- One record for each event in Events add-on
--- Only created when an event is selected to offer registrations
-CREATE TABLE {prefix}reg_event (
-    id INT NOT NULL AUTO_INCREMENT,
-    event INT NULL,                                             -- Pointer to event in Events add-on - False if event record in Events add-on no longer exists
-    event_name TINYTEXT NULL,                                   -- Name of Event so it will always be in the cart data
-    event_code TINYTEXT NULL,                                   -- A short code used to reference this event - can be used to directly select an event to register for
-    notify_email TINYTEXT NULL,                                 -- E-Mail addresses to receive notification of a registration other than org_internal_email in management, comma separated
-    admin_active BOOLEAN NULL,                                  -- Active flag for admin from Events - If logged in Admin user for this event and this is true then admin user may enter registrations even if active is off.
-    active BOOLEAN NULL,                                        -- Active flag to indicate that this event is available for registrations and notifications
-    time_specific BOOLEAN NULL,                                 -- Registration for this event is not date/time specific. Can attend any date/time of event.
-    attendees BOOLEAN NULL,                                     -- Registration requires attendees - Otherwise the person submitting the registration is the registrant
-    attendee_max MEDIUMINT NULL,                                -- Attendee limit - 0 = unlimited
-    attendee_max_per_reg TINYINT NULL,                          -- Maximum attendees per registration submission - 0 = unlimited
-    reg_hold_minutes MEDIUMINT NULL,                            -- Number of minutes hold time for an inactive cart before registrant count hold expires (after which cart attempts to hold again on next access)
-    cart_hold_days MEDIUMINT NULL,                              -- NO LONGER IN USE - Number of days hold time for inactive cart before cart is purged
-    reg_hours_before MEDIUMINT NULL,                            -- Number of hours before an event that is the latest a registration may be submitted.
-    registration_account_options SMALLINT NULL,                 -- Bitmap of how user accounts may be used for this event - See registration_account_option in plugin.ini
-    payment_methods SMALLINT NULL,                              -- Bitmap of payment methods available to users for this event - See payment_method in plugin.ini
-    restricted_payment_methods SMALLINT NULL,                   -- Bitmap of restricted (admin use only) payment methods for this event - see payment_method
-    descr TEXT NULL,                                            -- Registrations specific description field for this event
-    terms TEXT NULL,                                            -- Terms and Conditions for registration
-    first_datetime DATETIME NULL,                               -- Start of first listed date/time for this event
-    last_datetime DATETIME NULL,                                -- Start of last listed date/time for this event
-    reg_file TINYTEXT NULL,                                     -- Name of a downloadable file
-    reg_file_title TINYTEXT NULL,                               -- Title for downloadable file
-    form_revision SMALLINT NULL,                                -- Current MagicForm form revision
-    notes TEXT NULL,                                            -- System operator's notes for this event - Not visible to users
-    PRIMARY KEY (id),
-    INDEX (event),
-    INDEX (event_code(10))
-);
-
-----
-
--- Registration Event Time - Information and summary data for a specific event instance (relates to a particular time record in events)
--- A pseudo entry is created if registration is not date/time sensitive for this event. The pseudo entry does not point to an event time.
--- These are created the first time a person tries to register for an event instance (time)
--- One or more for each event
-CREATE TABLE {prefix}reg_time (
-    id INT NOT NULL AUTO_INCREMENT,
-    active BOOLEAN NULL,                                        -- Flag. True if registrations is available for this time
-    non_time_specific BOOLEAN NULL,                             -- Flag. True if this is a pseudo time for non-time-specific events - Other informational times for the event will have this flag off
-    reg_event INT NULL,                                         -- Pointer to reg_event table
-    event_time INT NULL,                                        -- ID of events times table entry in Events add-on - If false (0), then this is a pseudo entry to use for all registrations (non-date/time specific)
-    start_datetime DATETIME NULL,                               -- Date and time when event instance starts
-    end_datetime DATETIME NULL,                                 -- Date and time when event instance ends
-    all_day BOOLEAN NULL,                                       -- All Day flag - Informational
-    attendees BOOLEAN NULL,                                     -- Flag if tracking attendees or if only one per registration submission (registers account submitting) - get from reg_event
-    attendee_max MEDIUMINT NULL,                                -- Attendee count limit - 0 = unlimited - get from reg_event record
-    attendee_count MEDIUMINT NULL,                              -- Current attendee count - calculated on the fly and stored here for reference
-    attendees_pending MEDIUMINT NULL,                           -- Current number of attendees for this time in active pending carts (Not checked out and attendees slots held)
-    attendees_available MEDIUMINT NULL,                         -- Currently available attendee count (limit - current - pending)
-    total_base_charge DOUBLE NULL,                              -- Total base charges
-    total_per_attendee DOUBLE NULL,                             -- Total per-attendee charges
-    total_other DOUBLE NULL,                                    -- Total other charges (meals, extras, fees, ...)
-    total_taxes DOUBLE NULL,                                    -- Total taxes charged
-    total_charges DOUBLE NULL,                                  -- Total charges (sum of all above)
-    total_discounts DOUBLE NULL,                                -- Total discounts of all types (applied payment codes, etc...)
-    total_payments DOUBLE NULL,                                 -- Total net payments (total charges - total discounts)
-    descr TEXT NULL,                                            -- Optional description field for this time entry
-    PRIMARY KEY (id),
-    INDEX (reg_event),
-    INDEX (event_time),
-    INDEX (start_datetime)
-);
-
-----
-
--- Pending Attendees - In carts but not checked out
--- Attendee counts may be held for a particular reg_time entry for carts that have not been checked out
--- These are held for reg_event reg_hold_minutes, afterwhich they are timed out and removed from this table
--- Cart entries are given the ID's for these entries when a hold is requested, if the entry is gone, the hold has expired
-CREATE TABLE {prefix}reg_time_pending (
-    id INT NOT NULL AUTO_INCREMENT,
-    reg_event INT NULL,                                         -- Pointer to reg_event table
-    reg_time INT NULL,                                          -- ID of time record
-    registrant INT NULL,                                        -- ID of reg_request_registrant record                                                  --
-    expire_time DATETIME NULL,                                  -- Time at which this hold expires
-    PRIMARY KEY (id),
-    INDEX (reg_event),
-    INDEX (reg_time)
-);
-
-----
-
--- Registration Class - Type of registration for a specific event - Equates to "Rate Options" in the old system
--- One or more for each event
-CREATE TABLE {prefix}reg_class (
-    id INT NOT NULL AUTO_INCREMENT,
-    reg_event INT NULL,                                         -- Pointer to reg_event table
-    name TINYTEXT NULL,                                         -- Name of this registration type
-    descr TEXT NULL,                                            -- Description
-    PRIMARY KEY (id),
-    INDEX (reg_event)
-);
-
-----
-
--- Rates and dates for a particular reg_class
--- One or more per reg_class - **** Days should not overlap for a particular reg_class
-CREATE TABLE {prefix}reg_rate (
-    id INT NOT NULL AUTO_INCREMENT,
-    reg_event INT NULL,                                         -- Pointer to reg_event table
-    reg_class INT NULL,                                         -- Pointer to reg_class table
-    name TINYTEXT NULL,                                         -- Name of this rate
-    start_days INT NULL,                                        -- # of days before event time rate becomes available - may be selected as a date then converted for storage
-    end_days INT NULL,                                          -- # of days before event time rate becomes unavailable
-    base_rate FLOAT,                                            -- Base rate to register
-    per_registrant FLOAT,                                       -- Rate per registrant
-    registrant_credits TINYINT NULL,                            -- Number of registrants included in base rate
-    PRIMARY KEY (id),
-    INDEX (reg_event),
-    INDEX (reg_class)
-);
-
-----
-
--- Notifications
--- None or more for each reg event
-CREATE TABLE {prefix}reg_notification (
-    id INT NOT NULL AUTO_INCREMENT,
-    reg_event INT NULL,                                         -- Pointer to reg_event table
-    name TINYTEXT NULL,                                         -- Name of this notification
-    notification_days INT NULL,                                 -- # of days before or after event that notification takes place (- before, + after)
-    message TEXT NULL,                                          -- Content of message (uses template parameters to merge event/attendee data)
-    PRIMARY KEY (id),
-    INDEX (reg_event)
-);
-
-----
-
--- Notification Queue
-CREATE TABLE {prefix}notification_queue (
-    id INT NOT NULL AUTO_INCREMENT,
-    reg_notification INT NOT NULL,                              -- Pointer to the reg_notification table
-    account INT NOT NULL,                                       -- Pointer to the account table
-    queued_time DATETIME NOT NULL,                              -- Creation time
-    processed_time DATETIME NULL,                               -- The time this queue was processed. (sent out)
-    to_email TINYTEXT NOT NULL,                                 -- The To email address
-    from_email TINYTEXT NOT NULL,                               -- The From email address
-    subject TINYTEXT NOT NULL,                                  -- The subject
-    html_message TEXT NOT NULL,                                 -- The complete html message
-    PRIMARY KEY (id)
-);
-
-----
-
--- An account for a person submitting a registration or a registrant for an event
--- Depending on the use of these entries may not have all data included
--- A single account may be referenced as a person submitting registrations and/or a person registered for an event
-CREATE TABLE {prefix}account (
-    id INT NOT NULL AUTO_INCREMENT,
-    active BOOLEAN NULL,                                        -- Is active flag (may be accessed or used) - default is true
-    validated BOOLEAN NULL,                                     -- Flag indicating that the account has been validated - Set to false when recovering password
-    validation_code TINYTEXT NULL,                              -- Validation code and timestamp ("{validation code}-{timestamp}) - Clear this after validation
-    registered_by INT NULL,                                     -- Account
-    member_id TINYTEXT NULL,                                    -- Free-form field for a member ID (not a GLM Associate member ID - See "contact_member_id" below)
-    fname TINYTEXT NULL,                                        -- Account primary address
-    lname TINYTEXT NULL,
-    org TINYTEXT NULL,
-    title TINYTEXT NULL,
-    addr1 TINYTEXT NULL,
-    addr2 TINYTEXT NULL,
-    city TINYTEXT NULL,
-    state TINYTEXT NULL,
-    zip TINYTEXT NULL,
-    country TINYTEXT NULL,
-    phone TINYTEXT NULL,
-    fax TINYTEXT NULL,
-    bill_fname TINYTEXT NULL,                                   -- Last used billing infodeletermation - Also stored in each registration request
-    bill_lname TINYTEXT NULL,
-    bill_org TINYTEXT NULL,
-    bill_title TINYTEXT NULL,
-    bill_addr1 TINYTEXT NULL,
-    bill_addr2 TINYTEXT NULL,
-    bill_city TINYTEXT NULL,
-    bill_state TINYTEXT NULL,
-    bill_zip TINYTEXT NULL,
-    bill_country TINYTEXT NULL,
-    bill_phone TINYTEXT NULL,
-    bill_fax TINYTEXT NULL,
-    email TINYTEXT NULL,
-    password TINYTEXT NULL,                                     -- Crypted password for login back into this account
-    email_ok BOOLEAN NULL,
-    is_member BOOLEAN NULL,                                     -- Is a member of the entity that owns the site
-    customer_profile_id TINYTEXT NULL,                          -- Stored Credit Card customer profile ID
-    payment_profile_id TINYTEXT NULL,                           -- Stored Credit Card payment profile ID
-    payment_profile_card TINYTEXT NULL,                         -- Stored Credit Card last card digits
-    contact_id INT NULL,                                        -- Pointer to GLM Associate member contact record if account is for a member contact
-    contact_member_id INT NULL,                                 -- Pointer to GLM Associate Member for this contact
-    contact_fname TINYTEXT NULL,
-    contact_lname TINYTEXT NULL,
-    contact_org TINYTEXT NULL,
-    contact_title TINYTEXT NULL,
-    contact_addr1 TINYTEXT NULL,
-    contact_addr2 TINYTEXT NULL,
-    contact_city TINYTEXT NULL,
-    contact_state TINYTEXT NULL,
-    contact_zip TINYTEXT NULL,
-    contact_country TINYTEXT NULL,
-    contact_phone TINYTEXT NULL,
-    contact_fax TINYTEXT NULL,
-    contact_email TINYTEXT NULL,
-    contact_email_ok BOOLEAN NULL,
-    guardian TINYTEXT NULL,
-    emer_contact TINYTEXT NULL,
-    emer_phone TINYTEXT NULL,
-    med_history TINYTEXT NULL,
-    allergy_med TINYTEXT NULL,
-    date_created DATE NULL,
-    notes TEXT NULL,                                            -- System operator's notes for this account - not visible to account owner
-    user_trace_info TINYTEXT NULL,                              -- IP Address of user computer and timestamp of last update
-    PRIMARY KEY (id),
-    INDEX (registered_by),
-    INDEX (member_id(10)),
-    INDEX (fname(10)),
-    INDEX (lname(10)),
-    INDEX (org(10)),
-    INDEX (city(10)),
-    INDEX (state(5)),
-    INDEX (zip(5)),
-    INDEX (email(10)),
-    INDEX (contact_id)
-);
-
-----
-
--- A request for registration
--- Has one or more reg_detail records associated with it
-CREATE TABLE {prefix}reg_request (
-    id INT NOT NULL AUTO_INCREMENT,
-    account INT NULL,                                           -- Pointer to user account (reg_account) who submitted the registrations. If 0 then guest request (prior to checkout)
-    validated BOOLEAN NULL,                                     -- Flag that indicates if request passed last validation with checkRegistrationRequest()
-    validation_message TEXT NULL,                               -- Reasons that request did not pass validation with checkRegistrationRequest() - Serialized array
-    bill_fname TINYTEXT NULL,                                   -- Billing information used for this registration submission - Updates account billing address - Kept here for each request
-    bill_lname TINYTEXT NULL,
-    bill_org TINYTEXT NULL,
-    bill_title TINYTEXT NULL,
-    bill_addr1 TINYTEXT NULL,
-    bill_addr2 TINYTEXT NULL,
-    bill_city TINYTEXT NULL,
-    bill_state TINYTEXT NULL,
-    bill_zip TINYTEXT NULL,
-    bill_country TINYTEXT NULL,
-    bill_phone TINYTEXT NULL,
-    bill_email TINYTEXT NULL,
-    date_submitted DATE NULL,                                   -- Date of final submission (checkout complete)
-    pay_method INT NULL,                                        -- See payment_method in plugin.ini
-    payment_code TINYTEXT NULL,                                 -- Payment_code text (comp code) - if submitted and validated
-    status SMALLINT NULL,                                       -- See submission_status in plugin.ini
-    total DOUBLE PRECISION NULL,                                -- Total charge including all fees and taxes
-    total_discounts DOUBLE PRECISION NULL,                      -- Total of all comps and discounts
-    registrants SMALLINT NULL,                                  -- Total number of registrants in this cart
-    cc_type TINYINT NULL,                                       -- Credit Card type (if used) - See credit_card in plugin.ini
-    cc_name TINYTEXT NULL,                                      -- Name on Credit Card or Name on Check
-    cc_numb TINYTEXT NULL,                                      -- Credit Card Number or Check Number
-    cc_exp TINYTEXT NULL,
-    cc_cvv TINYTEXT NULL,
-    cc_conf TINYTEXT NULL,                                      -- Confirmation code back from card processor
-    cc_proc_mesg TINYTEXT NULL,                                 -- Message received from payment processor
-    summary TEXT NULL,                                          -- HTML summary of cart contents, costs and payment - Use same HTML displayed to user
-    mf_data TEXT NULL,                                          -- Any MagicForm data associated with registrant
-    notes TEXT NULL,                                            -- System operator's notes for this registration request
-    user_trace_info TEXT NULL,                                  -- IP Address of user computer and timestamp
-    date_created DATETIME NULL,                                 -- Date request was first created
-    last_update DATETIME NULL,                                  -- Last update date/time - Used for timing out pending carts and attendee counts
-    PRIMARY KEY (id),
-    INDEX (account),
-    INDEX (date_submitted)
-);
-
-----
-
--- Registration for a specific event
--- Has one or more reg_selected_rate records associated with it
-CREATE TABLE {prefix}reg_request_event (
-    id INT NOT NULL AUTO_INCREMENT,
-    reg_request INT NULL,                                       -- Pointer to reg_request table
-    reg_event INT NULL,                                         -- Pointer to reg_event
-    event_name TINYTEXT NULL,                                   -- Name of Event so it will always be in the cart data
-    notes TEXT NULL,                                            -- System operator's notes for this registration request
-    PRIMARY KEY (id),
-    INDEX (reg_request),
-    INDEX (reg_event)
-);
-
-----
-
---  A particular reg_class selected
---  Has one or more reg_request_rate records associated with it
-CREATE TABLE {prefix}reg_request_class (
-    id INT NOT NULL AUTO_INCREMENT,
-    reg_event INT NULL,                                         -- Pointer to reg_event entry
-    reg_request INT NULL,                                       -- Pointer to the registration request record
-    reg_request_event INT NULL,                                 -- Pointer to reg_request_event table entry
-    class INT NULL,                                             -- Pointer to event reg_class table - False (0) if registration class no longer exits
-    class_name TINYTEXT NULL,                                   -- Name of event class at the time selected
-    notes TEXT NULL,                                            -- System operator's notes for this registration request
-    PRIMARY KEY (id),
-    INDEX (reg_event),
-    INDEX (reg_request_event)
-);
-
-----
-
---  A particular reg_rate selected
---  Has one or more reg_request_registrant records associated with it
-CREATE TABLE {prefix}reg_request_rate (
-    id INT NOT NULL AUTO_INCREMENT,
-    reg_event INT NULL,                                         -- Pointer to reg_event entry
-    reg_request INT NULL,                                       -- Pointer to the registration request record
-    reg_request_event INT NULL,                                 -- Pointer to reg_request_event table entry
-    reg_request_class INT NULL,                                 -- Pointer to reg_request_class table entry
-    rate INT NULL,                                              -- Pointer to event reg_rate table - False (0) if registration rate no longer exists
-    rate_name TINYTEXT NULL,                                    -- Name of event class rate at the time selected
-    base_rate FLOAT,                                            -- Base rate at time of registration
-    per_registrant FLOAT,                                       -- Per Registrant Rate at time of registration
-    registrant_credits TINYINT NULL,                            -- Number of registrants included in base rate at time of registration
-    notes TEXT NULL,                                            -- System operator's notes for this registration request
-    PRIMARY KEY (id),
-    INDEX (reg_event),
-    INDEX (reg_request_event),
-    INDEX (reg_request_class)
-);
-
-----
-
---  A specific registrant for a selected registration rate
-CREATE TABLE {prefix}reg_request_registrant (
-    id INT NOT NULL AUTO_INCREMENT,
-    account INT NULL,                                           -- Pointer to the account entry for the person being registered - False (0) if account no longer exists or registrant account not needed
-    reg_event INT NULL,                                         -- Pointer to reg_event entry
-    reg_time INT NULL,                                          -- Pointer reg_time entry
-    event_datetime DATETIME NULL,                               -- Date and time of event time selected so it will always be in the cart
-    reg_request INT NULL,                                       -- Pointer to the registration request record
-    reg_request_event INT NULL,                                 -- Pointer to reg_request_event table entry
-    reg_request_class INT NULL,                                 -- Pointer to reg_request_class table entry
-    reg_request_rate INT NULL,                                  -- Pointer to reg_request_rate table entry
-    not_attending BOOLEAN DEFAULT false,                        -- Flag to say if registrant is not attending - set to true when not attending
-    fname TINYTEXT NULL,                                        -- First name of registrant at the time of selection
-    lname TINYTEXT NULL,                                        -- Last name of registrant at the time of selection
-    notes TEXT NULL,                                            -- System operator's notes for this registration request
-    PRIMARY KEY (id),
-    INDEX (account),
-    INDEX (reg_event),
-    INDEX (reg_time),
-    INDEX (reg_request),
-    INDEX (reg_request_event),
-    INDEX (reg_request_class),
-    INDEX (reg_request_rate)
-);
-
-----
-
---  A specific use of a payment code in this request
-CREATE TABLE {prefix}reg_request_pay_code (
-    id INT NOT NULL AUTO_INCREMENT,
-    payment_code INT NULL,                                      -- Pointer to payment code
-    code TINYTEXT NULL,                                         -- Copy of Payment Code text in case payment code is deleted or changed
-    reg_request INT NULL,                                       -- Pointer to the registration request record
-    credit DOUBLE PRECISION NULL,                               -- Total credit for this payment code
-    expire_date DATE NULL,                                      -- Expiration Date - NOT USING NOW - Getting from payment_code table always
-    PRIMARY KEY (id),
-    INDEX (payment_code),
-    INDEX (reg_request)
-);
-
-----
-
--- Insert into management table
-INSERT INTO {prefix}management
-    (
-    canonical_reg_page,
-    reg_org_name,
-    reg_org_short,
-    reg_org_address,
-    reg_org_city,
-    reg_org_state,
-    reg_org_zip,
-    reg_org_phone,
-    reg_org_toll_free,
-    reg_org_internal_email,
-    reg_org_from_email,
-    reg_payment_methods,
-    reg_proc_methods,
-    reg_cc_accepts,
-    reg_authorize_net_login,
-    reg_authorize_net_key,
-    reg_authorize_net_test,
-    reg_authorize_net_conf,
-    reg_authorize_net_merchant_email,
-    reg_merchant_solutions_acctid,
-    reg_merchant_solutions_merchantpin,
-    reg_merchant_solutions_test,
-    reg_full_billing_info,
-    reg_bill_info_req_no_charge,
-    reg_bill_info_req_comp_code,
-    reg_bill_info_req_cash,
-    reg_bill_info_req_check,
-    reg_bill_info_req_credit_card,
-    reg_bill_info_req_merchant_call,
-    reg_medical_info
-    )
-    VALUES
-    (
-    'registrations',                                            -- reg_canonical_reg_page,
-    'Gaslight Media',                                           -- reg_org_name,
-    'GLM',                                                      -- reg_org_short,
-    '120 E. Lake St.',                                          -- reg_org_address,
-    'Petoskey',                                                 -- reg_org_city,
-    'MI',                                                       -- reg_org_state,
-    '49770',                                                    -- reg_org_zip,
-    '231-487-0692',                                             -- reg_org_phone,
-    '800-123-1234',                                             -- reg_org_toll_free,
-    'internal@gaslightmedia.com',                               -- reg_org_internal_email,
-    'info@gaslightmedia.com',                                   -- reg_org_from_email,
-    0,                                                          -- reg_payment_methods,
-    0,                                                          -- reg_proc_methods,
-    0,                                                          -- reg_cc_accepts,
-    '',                                                         -- reg_authorize_net_login,
-    '',                                                         -- reg_authorize_net_key,
-    1,                                                          -- reg_authorize_net_test,
-    true,                                                       -- reg_authorize_net_conf
-    '',                                                         -- reg_authorize_net_merchant_email,
-    '',                                                         -- reg_merchant_solutions_acctid,
-    '',                                                         -- reg_merchant_solutions_merchantpin,
-    1,                                                          -- reg_merchant_solutions_test,
-    true,                                                       -- reg_full_billing_info,
-    0,                                                          -- reg_bill_info_req_no_charge,
-    0,                                                          -- reg_bill_info_req_comp_code,
-    0,                                                          -- reg_bill_info_req_cash,
-    0,                                                          -- reg_bill_info_req_check,
-    0,                                                          -- reg_bill_info_req_credit_card,
-    0,                                                          -- reg_bill_info_req_merchant_call,
-    true                                                        -- reg_medical_info,
-    );
-
-----
-
--- Insert into settings_terms table
-INSERT INTO {prefix}settings_terms
-    (
-    reg_term_registrations_name,
-    reg_term_registration,
-    reg_term_registration_cap,
-    reg_term_registration_plur,
-    reg_term_registration_plur_cap,
-    reg_term_register,
-    reg_term_register_cap,
-    reg_term_registers,
-    reg_term_registering,
-    reg_term_registering_cap,
-    reg_term_registered,
-    reg_term_registered_cap,
-    reg_term_attendee,
-    reg_term_attendee_cap,
-    reg_term_attendee_plur,
-    reg_term_attendee_plur_cap,
-    reg_term_attending,
-    reg_term_attended,
-    reg_term_registered_user,
-    reg_term_registered_user_cap,
-    reg_term_registered_user_plur,
-    reg_term_registered_user_plur_cap,
-    reg_term_event,
-    reg_term_event_cap,
-    reg_term_event_plur,
-    reg_term_event_plur_cap,
-    reg_term_id,
-    reg_term_id_cap,
-    reg_term_id_plur,
-    reg_term_id_plur_cap,
-    reg_term_password,
-    reg_term_password_cap,
-    reg_term_password_plur,
-    reg_term_password_plur_cap,
-    reg_term_instructor,
-    reg_term_instructor_cap,
-    reg_term_instructor_plur,
-    reg_term_instructor_plur_cap,
-    reg_term_payment_code,
-    reg_term_payment_code_cap,
-    reg_term_payment_code_plur,
-    reg_term_payment_code_plur_cap,
-    reg_term_registration_button,
-    reg_term_contact_information
-    )
-    VALUES
-    (
-    'Event Registrations',                                      -- reg_term_registrations_name
-    'registration',                                             -- reg_term_registration
-    'Registration',                                             -- reg_term_registration_cap
-    'registrations',                                            -- reg_term_registration_plur
-    'Registrations',                                            -- reg_term_registration_plur_cap
-    'register',                                                 -- reg_term_registe
-    'Register',                                                 -- reg_term_register_cap
-    'registers',                                                -- reg_term_registers
-    'registering',                                              -- reg_term_registering
-    'Registering',                                              -- reg_term_registering_cap
-    'registered',                                               -- reg_term_registered
-    'Registered',                                               -- reg_term_registered_cap
-    'attendee',                                                 -- reg_term_attendee
-    'Attendee',                                                 -- reg_term_attendee_cap
-    'attendees',                                                -- reg_term_attendee_plur
-    'Attendees',                                                -- reg_term_attendee_plur_cap
-    'attending',                                                -- reg_term_attending
-    'attended',                                                 -- reg_term_attended
-    'user',                                                     -- reg_term_registered_user
-    'User',                                                     -- reg_term_registered_user_cap
-    'users',                                                    -- reg_term_registered_user_plur
-    'Users',                                                    -- reg_term_registered_user_plur_cap
-    'event',                                                    -- reg_term_event
-    'Event',                                                    -- reg_term_event_cap
-    'events',                                                   -- reg_term_event_plur
-    'Events',                                                   -- reg_term_event_plur_cap
-    'ID',                                                       -- reg_term_id
-    'ID',                                                       -- reg_term_id_cap
-    'IDs',                                                      -- reg_term_id_plur
-    'IDs',                                                      -- reg_term_id_plur_cap
-    'password',                                                 -- reg_term_password
-    'passwords',                                                -- reg_term_password_cap
-    'Password',                                                 -- reg_term_password_plur
-    'Passwords',                                                -- reg_term_password_plur_cap
-    'instructor',                                               -- reg_term_instructor
-    'Instructor',                                               -- reg_term_instructor_cap
-    'instructors',                                              -- reg_term_instructor_plur
-    'Instructors',                                              -- reg_term_instructor_plur_cap
-    'payment code',                                             -- reg_term_payment_code
-    'Payment code',                                             -- reg_term_payment_code_cap
-    'payment codes',                                            -- reg_term_payment_code_plur
-    'Payment codes',                                            -- reg_term_payment_code_plur_cap
-    'Register for Event',                                       -- reg_term_registration_button
-    'Contact Information'                                       -- reg_term_contact_information
-    );
-
-----
-
--- Insert into misc table
-INSERT INTO {prefix}misc
-    (
-    reg_bulletin,
-    cart_page_text,
-    checkout_page_text,
-    summary_page_text,
-    reg_terms,
-    notify_subject,
-    notify_text,
-    instr_notify_subject,
-    instr_notify_text,
-    submission_notify_subject,
-    submission_notify_text,
-    registrant_notify_subject,
-    registrant_notify_text,
-    submission_ack_subject,
-    submission_ack_text,
-    registrant_ack_subject,
-    registrant_ack_text
-    )
-    VALUES
-    (
-    'Registration Bulletin Text',
-    'Text for top of Cart Page',
-    'Text for top of Checkout Page',
-    'Text for top of Summary Page',
-    'Terms and Conditions',
-    'Subject of notification to site owner of a registration',
-    'Text of notification to site owner of a registration',
-    'Subject of notification to instructor of registration',
-    'Text for notification to instructor of registration',
-    'Subject of notification to person submitting registration',
-    'Text of notification to person submitting registration',
-    'Subject for notification to registrant',
-    'Text for notification to registrant',
-    'Subject of acknowledgement to person submitting registration',
-    'Text of acknowledgement to person submitting registration',
-    'Subject of acknowledgement to registrant',
-    'Text of acknowledgement to registrant'
-    );
diff --git a/setup/databaseScripts/create_database_V1.0.0.sql b/setup/databaseScripts/create_database_V1.0.0.sql
new file mode 100644 (file)
index 0000000..1f1382c
--- /dev/null
@@ -0,0 +1,812 @@
+-- Gaslight Media Registration Database
+-- File Created: 01/18/2017 14:40:00
+-- Database Version: 0.0.19
+-- Database Creation Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+--
+/*
+ * General Database Organization
+ * -----------------------------
+ *
+ * management - General options and configuration - Site manager access only
+ *
+ * misc - Misc settings and text - Site owner may update
+ *
+ * payment codes - Promotional payment codes - Used with various things
+ *      --> Event, Submission, Event Registration, Event Registrant, Account or global
+ *
+ * reg_event - Describes registration for that event
+ *      reg_time - One record for each date/time this event has people registered - Primarily tracks attendee counts and charge totals
+ *      reg_class - Type of registration for this event (one or more)
+ *          reg_rates - Date range / rate for a reg class (one or more)
+ *
+ * reg_account - Describes someone who submits / pays for a registration
+ * Make these two things the same table....
+ * registrant - A person who is registered for an event
+ *
+ * reg_request - Information on a specific request for registrations
+ *      reg_request_event - Event selected (one or more)
+ *          reg_request_class - Class of registration (one or more)
+ *              reg_request_rate - Specific registration date/rate (one or more)
+ *                  reg_request_registrant - Registrant (one or more)
+ *
+ * NOTE: additional fields and added fields data will be coming from the Custom Fields add-on
+ *
+ * Overall Flow
+ * ------------
+ *
+ * User selects an event
+ * If the event has available registrations
+ *  User selects a date for the registration (or if only one that's selected automatically)
+ *    User can log back into registrations at this point if they've been there before and have a password, create an ccount, or continue as guest ???
+ *      User selects an available rate type and adds one or more registrants for that rate type
+ *      User may loop back to select additional rate type(s) and registrants
+ *    User may go back to date selection and request additional rate types and registrants for the addional dates
+ *  User may go back to select additional dates and do registrations for those dates as above
+ * User may go back to select other events and do registrations for them as above
+ * User may select the "Cart" and deselect something added to it
+ * User may checkout
+ *
+ */
+
+/*
+ * NOTE: Anything below here may not be completed or accurate yet. I'm still working though this
+ * Lines commented out are selected for possible deletion.
+ * The INSERT statements are not up-to-date with the tables.
+ * The "config/plugin.ini" file in this plugin is also a work in progress.
+ */
+
+-- Management Options
+-- General configurationm parameters for the Registrations application
+-- Only one entry in this table!
+CREATE TABLE {prefix}management (
+    id INT NOT NULL AUTO_INCREMENT,
+    canonical_reg_page TINYTEXT NULL,                              -- Canonical page slug for registrations
+    -- System Owner Information
+    reg_org_name TINYTEXT NULL,                                     -- Customer Information - Name of Organization
+    reg_org_short TINYTEXT NULL,
+    reg_org_address TINYTEXT NULL,
+    reg_org_city TINYTEXT NULL,
+    reg_org_state TINYTEXT NULL,
+    reg_org_zip TINYTEXT NULL,
+    reg_org_phone TINYTEXT NULL,
+    reg_org_toll_free TINYTEXT NULL,
+    reg_org_internal_email TINYTEXT NULL,
+    reg_org_from_email TINYTEXT NULL,
+    reg_payment_methods SMALLINT NULL,                              -- Payment methods available for all registrations - Bitmap - see payment_method in plugin.ini
+    reg_proc_methods SMALLINT NULL,                                 -- Credit Cart payment processing methods available - Bitmap - see proc_method in plugin.ini
+    reg_cc_accepts SMALLINT NULL,                                   -- Credit Cards Accepted - Bitmap - See credit_card in plugin.ini
+    -- Authorize.net Credentials
+    reg_authorize_net_login TINYTEXT NULL,
+    reg_authorize_net_key TINYTEXT NULL,
+    reg_authorize_net_test TINYINT NULL,                            -- Authorize.net test mode - List - see proc_test_mode in plugin.ini
+    reg_authorize_net_conf BOOLEAN NULL,                            -- Flag to send payment confirmation Email from Authorize.net
+    reg_authorize_net_merchant_email TINYTEXT NULL,                 -- E-Mail Authorize.net will send copy of confirmation E-Mail
+    reg_authorize_net_merchant_seal TEXT NULL,                      -- Authorize.net Verified Merchant Seal code
+    -- Merchant Solutions Credentials
+    reg_merchant_solutions_acctid TINYTEXT NULL,                    -- Merchant Solutions credentials
+    reg_merchant_solutions_merchantpin TINYTEXT NULL,
+    reg_merchant_solutions_test TINYINT NULL,                       -- Merchant Solutions test mode - List - see proc_test_mode in plugin.ini
+    reg_merchant_solutions_conf BOOLEAN NULL,                       -- Flag to send payment confirmation Email
+    reg_merchant_solutions_merchant_email TINYTEXT NULL,            -- Merchant Solutions will send copy of confirmation E-Mail
+    -- PayPal Credentials
+    reg_paypal_clientid TINYTEXT NULL,                              -- PayPal Client ID
+    reg_paypal_secret TINYTEXT NULL,                                -- PayPal Secret
+    reg_paypal_sandbox_clientid TINYTEXT NULL,                      -- PayPal Client ID
+    reg_paypal_sandbox_secret TINYTEXT NULL,                        -- PayPal Secret
+    reg_paypal_test TINYINT NULL,                                   -- PayPal test mode - List - see 
+    -- Billing settings
+    reg_full_billing_info BOOLEAN NULL,                             -- Always request full billing information in checkout page regardless of the following settings
+    reg_bill_info_req_no_charge SMALLINT NULL,                      -- Bitmap of fields to use in checkout for these types of payments - See billing_field in plugin.conf
+    reg_bill_info_req_comp_code SMALLINT NULL,
+    reg_bill_info_req_cash SMALLINT NULL,
+    reg_bill_info_req_check SMALLINT NULL,
+    reg_bill_info_req_credit_card SMALLINT NULL,
+    reg_bill_info_req_merchant_call SMALLINT NULL,
+    -- Misc Options
+    reg_request_hold_days SMALLINT NULL,                            -- Number of days past last update that a request will be retained in "CART" status.
+    req_account_hold_days SMALLINT NULL,                            -- Number of days past last update that an account will be retained when there are no requests or registrants referring to it.
+    reg_not_submitted_dialog BOOLEAN NULL,                          -- Flag to show page not submitted dialog boxes
+    reg_medical_info BOOLEAN NULL,                                  -- This site can ask for "Medical Info" - set in main category of an event
+    reg_show_navigation_aids BOOLEAN NULL,                          -- No, not marine navigational aids, this enables additional text, arrows, etc to direct a user to do something specific that would not normally be required.
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Terms used in site modifiable on Management page in admin - Only 1 entry in this table
+-- Terms in this table should be all self-explanatory
+CREATE TABLE {prefix}settings_terms (
+    id INT NOT NULL AUTO_INCREMENT,
+    reg_term_registrations_name TINYTEXT NULL,                      -- Term "Event Registration"
+    reg_term_registration TINYTEXT NULL,
+    reg_term_registration_cap TINYTEXT NULL,
+    reg_term_registration_plur TINYTEXT NULL,
+    reg_term_registration_plur_cap TINYTEXT NULL,
+    reg_term_register TINYTEXT NULL,
+    reg_term_register_cap TINYTEXT NULL,
+    reg_term_registers TINYTEXT NULL,                               -- Intransitive verb of register
+    reg_term_registering TINYTEXT NULL,
+    reg_term_registering_cap TINYTEXT NULL,
+    reg_term_registered TINYTEXT NULL,
+    reg_term_registered_cap TINYTEXT NULL,
+    reg_term_attendee TINYTEXT NULL,
+    reg_term_attendee_cap TINYTEXT NULL,
+    reg_term_attendee_plur TINYTEXT NULL,
+    reg_term_attendee_plur_cap TINYTEXT NULL,
+    reg_term_attending TINYTEXT NULL,
+    reg_term_attended TINYTEXT NULL,
+    reg_term_registered_user TINYTEXT NULL,
+    reg_term_registered_user_cap TINYTEXT NULL,
+    reg_term_registered_user_plur TINYTEXT NULL,
+    reg_term_registered_user_plur_cap TINYTEXT NULL,
+    reg_term_event TINYTEXT NULL,
+    reg_term_event_cap TINYTEXT NULL,
+    reg_term_event_plur TINYTEXT NULL,
+    reg_term_event_plur_cap TINYTEXT NULL,
+    reg_term_id TINYTEXT NULL,
+    reg_term_id_cap TINYTEXT NULL,
+    reg_term_id_plur TINYTEXT NULL,
+    reg_term_id_plur_cap TINYTEXT NULL,
+    reg_term_level TINYTEXT NULL,
+    reg_term_level_cap TINYTEXT NULL,
+    reg_term_level_plur TINYTEXT NULL,
+    reg_term_level_plur_cap TINYTEXT NULL,
+    reg_term_password TINYTEXT NULL,
+    reg_term_password_cap TINYTEXT NULL,
+    reg_term_password_plur TINYTEXT NULL,
+    reg_term_password_plur_cap TINYTEXT NULL,
+    reg_term_instructor TINYTEXT NULL,
+    reg_term_instructor_cap TINYTEXT NULL,
+    reg_term_instructor_plur TINYTEXT NULL,
+    reg_term_instructor_plur_cap TINYTEXT NULL,
+    reg_term_payment_code TINYTEXT NULL,
+    reg_term_payment_code_cap TINYTEXT NULL,
+    reg_term_payment_code_plur TINYTEXT NULL,
+    reg_term_payment_code_plur_cap TINYTEXT NULL,
+    reg_term_registration_button TINYTEXT NULL,
+    reg_term_contact_information TINYTEXT NULL,
+    reg_term_button_event_list TINYTEXT NULL,
+    reg_term_button_login_or_create TINYTEXT NULL,
+    reg_term_button_create_account TINYTEXT NULL,
+    reg_term_button_login TINYTEXT NULL,
+    reg_term_button_logout TINYTEXT NULL,
+    reg_term_button_add_attendee TINYTEXT NULL,
+    reg_term_button_save_attendee TINYTEXT NULL,
+    reg_term_button_attendee_page_continue TINYTEXT NULL,
+    reg_term_button_apply_comp_code TINYTEXT NULL,
+    reg_term_button_cart_page_continue TINYTEXT NULL,
+    reg_term_button_checkout_page_submit TINYTEXT NULL,
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Misc system-wide customer configurable configuration
+-- Various text and flags to be configured by customer
+-- Only one entry in this table!
+CREATE TABLE {prefix}misc (
+    id INT NOT NULL AUTO_INCREMENT,
+    reg_bulletin TEXT NULL,                                     -- Text to display at top of first registration page
+    cart_page_text TEXT NULL,                                   -- Text to display at top of cart page
+    checkout_page_text TEXT NULL,                               -- Text to display at top of checkout page
+    summary_page_text TEXT NULL,                                -- Text to display at top of summary page (after checkout)
+    reg_terms TEXT NULL,                                        -- Registration terms and conditions
+    notify_subject TEXT NULL,                                   -- Subject of notification E-Mail to site owner
+    notify_text TEXT NULL,                                      -- Notification E-Mail text for site owner
+    instr_notify_subject TEXT NULL,                             -- Subject of notification E-Mail to instructor
+    instr_notify_text TEXT NULL,                                -- Notification E-Mail text for instructor
+    submission_notify_subject TEXT NULL,                        -- Subject of notification E-Mail to person submitting the registrations
+    submission_notify_text TEXT NULL,                           -- Notification E-Mail text to person submitting the registrations
+    registrant_notify_subject TEXT NULL,                        -- Subject of notification E-Mail to registrant
+    registrant_notify_text TEXT NULL,                           -- Text of notification E-Mail to registrant
+    submission_ack_subject TEXT NULL,                           -- Subject of acknowledgement E-Mail to person submitting the registrations
+    submission_ack_text TEXT NULL,                              -- Text of acknowledgement E-Mail text to person submitting the registrations
+    registrant_ack_subject TEXT NULL,                           -- Subject of acknowledgement E-Mail to registrant
+    registrant_ack_text TEXT NULL,                              -- Text of acknowledgement E-Mail to registrant
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Payment Codes
+-- Promotional payment codes for free/discounted payment
+CREATE TABLE {prefix}payment_code (
+    id INT NOT NULL AUTO_INCREMENT,
+    code_type TINYINT NULL,                                     -- Type of adjustment - Free only to start with - See pay_code_type in plugin.ini
+    ref_type TINYINT NULL,                                      -- See payment_ref_type in plugin.ini
+    ref_dest INT NULL,                                          -- Pointer to the specific entity of ref_type
+    code TINYTEXT NULL,                                         -- Text code user must enter to use
+    amount FLOAT,                                               -- Amount of discount if not type "Free" - Either $ amount or percent
+    expire_date DATE NULL,                                      -- Expiration Date
+    
+    descr TEXT NULL,
+    PRIMARY KEY (id),
+    INDEX (ref_dest),
+    INDEX (code(10))
+);
+
+----
+
+-- Registration event specific information
+-- One record for each event in Events add-on
+-- Only created when an event is selected to offer registrations
+CREATE TABLE {prefix}reg_event (
+    id INT NOT NULL AUTO_INCREMENT,
+    event INT NULL,                                             -- Pointer to event in Events add-on - False if event record in Events add-on no longer exists
+    event_name TINYTEXT NULL,                                   -- Name of Event so it will always be in the cart data
+    event_code TINYTEXT NULL,                                   -- A short code used to reference this event - can be used to directly select an event to register for
+    notify_email TINYTEXT NULL,                                 -- E-Mail addresses to receive notification of a registration other than org_internal_email in management, comma separated
+    admin_active BOOLEAN NULL,                                  -- Active flag for admin from Events - If logged in Admin user for this event and this is true then admin user may enter registrations even if active is off.
+    active BOOLEAN NULL,                                        -- Active flag to indicate that this event is available for registrations and notifications
+    time_specific BOOLEAN NULL,                                 -- Registration for this event is not date/time specific. Can attend any date/time of event.
+    attendees BOOLEAN NULL,                                     -- Registration requires attendees - Otherwise the person submitting the registration is the registrant
+    attendee_max MEDIUMINT NULL,                                -- Attendee limit - 0 = unlimited
+    attendee_max_per_reg TINYINT NULL,                          -- Maximum attendees per registration submission - 0 = unlimited
+    reg_hold_minutes MEDIUMINT NULL,                            -- Number of minutes hold time for an inactive cart before registrant count hold expires (after which cart attempts to hold again on next access)
+    cart_hold_days MEDIUMINT NULL,                              -- NO LONGER IN USE - Number of days hold time for inactive cart before cart is purged
+    reg_hours_before MEDIUMINT NULL,                            -- Number of hours before an event that is the latest a registration may be submitted.
+    registration_account_options SMALLINT NULL,                 -- Bitmap of how user accounts may be used for this event - See registration_account_option in plugin.ini
+    payment_methods SMALLINT NULL,                              -- Bitmap of payment methods available to users for this event - See payment_method in plugin.ini
+    restricted_payment_methods SMALLINT NULL,                   -- Bitmap of restricted (admin use only) payment methods for this event - see payment_method
+    descr TEXT NULL,                                            -- Registrations specific description field for this event
+    terms TEXT NULL,                                            -- Terms and Conditions for registration
+    first_datetime DATETIME NULL,                               -- Start of first listed date/time for this event
+    last_datetime DATETIME NULL,                                -- Start of last listed date/time for this event
+    reg_file TINYTEXT NULL,                                     -- Name of a downloadable file
+    reg_file_title TINYTEXT NULL,                               -- Title for downloadable file
+    form_revision SMALLINT NULL,                                -- Current MagicForm form revision
+    notes TEXT NULL,                                            -- System operator's notes for this event - Not visible to users
+    PRIMARY KEY (id),
+    INDEX (event),
+    INDEX (event_code(10))
+);
+
+----
+
+-- Registration Event Time - Information and summary data for a specific event instance (relates to a particular time record in events)
+-- A pseudo entry is created if registration is not date/time sensitive for this event. The pseudo entry does not point to an event time.
+-- These are created the first time a person tries to register for an event instance (time)
+-- One or more for each event
+CREATE TABLE {prefix}reg_time (
+    id INT NOT NULL AUTO_INCREMENT,
+    active BOOLEAN NULL,                                        -- Flag. True if registrations is available for this time
+    non_time_specific BOOLEAN NULL,                             -- Flag. True if this is a pseudo time for non-time-specific events - Other informational times for the event will have this flag off
+    reg_event INT NULL,                                         -- Pointer to reg_event table
+    event_time INT NULL,                                        -- ID of events times table entry in Events add-on - If false (0), then this is a pseudo entry to use for all registrations (non-date/time specific)
+    start_datetime DATETIME NULL,                               -- Date and time when event instance starts
+    end_datetime DATETIME NULL,                                 -- Date and time when event instance ends
+    all_day BOOLEAN NULL,                                       -- All Day flag - Informational
+    attendees BOOLEAN NULL,                                     -- Flag if tracking attendees or if only one per registration submission (registers account submitting) - get from reg_event
+    attendee_max MEDIUMINT NULL,                                -- Attendee count limit - 0 = unlimited - get from reg_event record
+    attendee_count MEDIUMINT NULL,                              -- Current attendee count - calculated on the fly and stored here for reference
+    attendees_pending MEDIUMINT NULL,                           -- Current number of attendees for this time in active pending carts (Not checked out and attendees slots held)
+    attendees_available MEDIUMINT NULL,                         -- Currently available attendee count (limit - current - pending)
+    total_base_charge DOUBLE NULL,                              -- Total base charges
+    total_per_attendee DOUBLE NULL,                             -- Total per-attendee charges
+    total_other DOUBLE NULL,                                    -- Total other charges (meals, extras, fees, ...)
+    total_taxes DOUBLE NULL,                                    -- Total taxes charged
+    total_charges DOUBLE NULL,                                  -- Total charges (sum of all above)
+    total_discounts DOUBLE NULL,                                -- Total discounts of all types (applied payment codes, etc...)
+    total_payments DOUBLE NULL,                                 -- Total net payments (total charges - total discounts)
+    descr TEXT NULL,                                            -- Optional description field for this time entry
+    PRIMARY KEY (id),
+    INDEX (reg_event),
+    INDEX (event_time),
+    INDEX (start_datetime)
+);
+
+----
+
+-- Pending Attendees - In carts but not checked out
+-- Attendee counts may be held for a particular reg_time entry for carts that have not been checked out
+-- These are held for reg_event reg_hold_minutes, afterwhich they are timed out and removed from this table
+-- Cart entries are given the ID's for these entries when a hold is requested, if the entry is gone, the hold has expired
+CREATE TABLE {prefix}reg_time_pending (
+    id INT NOT NULL AUTO_INCREMENT,
+    reg_event INT NULL,                                         -- Pointer to reg_event table
+    reg_time INT NULL,                                          -- ID of time record
+    registrant INT NULL,                                        -- ID of reg_request_registrant record                                                  --
+    expire_time DATETIME NULL,                                  -- Time at which this hold expires
+    PRIMARY KEY (id),
+    INDEX (reg_event),
+    INDEX (reg_time)
+);
+
+----
+
+-- Registration Class - Type of registration for a specific event - Equates to "Rate Options" in the old system
+-- One or more for each event
+CREATE TABLE {prefix}reg_class (
+    id INT NOT NULL AUTO_INCREMENT,
+    reg_event INT NULL,                                         -- Pointer to reg_event table
+    name TINYTEXT NULL,                                         -- Name of this registration type
+    descr TEXT NULL,                                            -- Description
+    PRIMARY KEY (id),
+    INDEX (reg_event)
+);
+
+----
+
+-- Rates and dates for a particular reg_class
+-- One or more per reg_class - **** Days should not overlap for a particular reg_class
+CREATE TABLE {prefix}reg_rate (
+    id INT NOT NULL AUTO_INCREMENT,
+    reg_event INT NULL,                                         -- Pointer to reg_event table
+    reg_class INT NULL,                                         -- Pointer to reg_class table
+    name TINYTEXT NULL,                                         -- Name of this rate
+    start_days INT NULL,                                        -- # of days before event time rate becomes available - may be selected as a date then converted for storage
+    end_days INT NULL,                                          -- # of days before event time rate becomes unavailable
+    base_rate FLOAT,                                            -- Base rate to register
+    per_registrant FLOAT,                                       -- Rate per registrant
+    registrant_credits TINYINT NULL,                            -- Number of registrants included in base rate
+    PRIMARY KEY (id),
+    INDEX (reg_event),
+    INDEX (reg_class)
+);
+
+----
+
+-- Notifications
+-- None or more for each reg event
+CREATE TABLE {prefix}reg_notification (
+    id INT NOT NULL AUTO_INCREMENT,
+    reg_event INT NULL,                                         -- Pointer to reg_event table
+    name TINYTEXT NULL,                                         -- Name of this notification
+    notification_days INT NULL,                                 -- # of days before or after event that notification takes place (- before, + after)
+    message TEXT NULL,                                          -- Content of message (uses template parameters to merge event/attendee data)
+    PRIMARY KEY (id),
+    INDEX (reg_event)
+);
+
+----
+
+-- Notification Queue
+CREATE TABLE {prefix}notification_queue (
+    id INT NOT NULL AUTO_INCREMENT,
+    reg_notification INT NOT NULL,                              -- Pointer to the reg_notification table
+    account INT NOT NULL,                                       -- Pointer to the account table
+    queued_time DATETIME NOT NULL,                              -- Creation time
+    processed_time DATETIME NULL,                               -- The time this queue was processed. (sent out)
+    to_email TINYTEXT NOT NULL,                                 -- The To email address
+    from_email TINYTEXT NOT NULL,                               -- The From email address
+    subject TINYTEXT NOT NULL,                                  -- The subject
+    html_message TEXT NOT NULL,                                 -- The complete html message
+    PRIMARY KEY (id)
+);
+
+----
+
+-- An account for a person submitting a registration or a registrant for an event
+-- Depending on the use of these entries may not have all data included
+-- A single account may be referenced as a person submitting registrations and/or a person registered for an event
+CREATE TABLE {prefix}account (
+    id INT NOT NULL AUTO_INCREMENT,
+    active BOOLEAN NULL,                                        -- Is active flag (may be accessed or used) - default is true
+    validated BOOLEAN NULL,                                     -- Flag indicating that the account has been validated - Set to false when recovering password
+    validation_code TINYTEXT NULL,                              -- Validation code and timestamp ("{validation code}-{timestamp}) - Clear this after validation
+    registered_by INT NULL,                                     -- Account
+    member_id TINYTEXT NULL,                                    -- Free-form field for a member ID (not a GLM Associate member ID - See "contact_member_id" below)
+    fname TINYTEXT NULL,                                        -- Account primary address
+    lname TINYTEXT NULL,
+    org TINYTEXT NULL,
+    title TINYTEXT NULL,
+    addr1 TINYTEXT NULL,
+    addr2 TINYTEXT NULL,
+    city TINYTEXT NULL,
+    state TINYTEXT NULL,
+    zip TINYTEXT NULL,
+    country TINYTEXT NULL,
+    phone TINYTEXT NULL,
+    fax TINYTEXT NULL,
+    bill_fname TINYTEXT NULL,                                   -- Last used billing infodeletermation - Also stored in each registration request
+    bill_lname TINYTEXT NULL,
+    bill_org TINYTEXT NULL,
+    bill_title TINYTEXT NULL,
+    bill_addr1 TINYTEXT NULL,
+    bill_addr2 TINYTEXT NULL,
+    bill_city TINYTEXT NULL,
+    bill_state TINYTEXT NULL,
+    bill_zip TINYTEXT NULL,
+    bill_country TINYTEXT NULL,
+    bill_phone TINYTEXT NULL,
+    bill_fax TINYTEXT NULL,
+    email TINYTEXT NULL,
+    password TINYTEXT NULL,                                     -- Crypted password for login back into this account
+    email_ok BOOLEAN NULL,
+    is_member BOOLEAN NULL,                                     -- Is a member of the entity that owns the site
+    customer_profile_id TINYTEXT NULL,                          -- Stored Credit Card customer profile ID
+    payment_profile_id TINYTEXT NULL,                           -- Stored Credit Card payment profile ID
+    payment_profile_card TINYTEXT NULL,                         -- Stored Credit Card last card digits
+    contact_id INT NULL,                                        -- Pointer to GLM Associate member contact record if account is for a member contact
+    contact_member_id INT NULL,                                 -- Pointer to GLM Associate Member for this contact
+    contact_fname TINYTEXT NULL,
+    contact_lname TINYTEXT NULL,
+    contact_org TINYTEXT NULL,
+    contact_title TINYTEXT NULL,
+    contact_addr1 TINYTEXT NULL,
+    contact_addr2 TINYTEXT NULL,
+    contact_city TINYTEXT NULL,
+    contact_state TINYTEXT NULL,
+    contact_zip TINYTEXT NULL,
+    contact_country TINYTEXT NULL,
+    contact_phone TINYTEXT NULL,
+    contact_fax TINYTEXT NULL,
+    contact_email TINYTEXT NULL,
+    contact_email_ok BOOLEAN NULL,
+    guardian TINYTEXT NULL,
+    emer_contact TINYTEXT NULL,
+    emer_phone TINYTEXT NULL,
+    med_history TINYTEXT NULL,
+    allergy_med TINYTEXT NULL,
+    date_created DATE NULL,
+    notes TEXT NULL,                                            -- System operator's notes for this account - not visible to account owner
+    user_trace_info TINYTEXT NULL,                              -- IP Address of user computer and timestamp of last update
+    PRIMARY KEY (id),
+    INDEX (registered_by),
+    INDEX (member_id(10)),
+    INDEX (fname(10)),
+    INDEX (lname(10)),
+    INDEX (org(10)),
+    INDEX (city(10)),
+    INDEX (state(5)),
+    INDEX (zip(5)),
+    INDEX (email(10)),
+    INDEX (contact_id)
+);
+
+----
+
+-- A request for registration
+-- Has one or more reg_detail records associated with it
+CREATE TABLE {prefix}reg_request (
+    id INT NOT NULL AUTO_INCREMENT,
+    account INT NULL,                                           -- Pointer to user account (reg_account) who submitted the registrations. If 0 then guest request (prior to checkout)
+    validated BOOLEAN NULL,                                     -- Flag that indicates if request passed last validation with checkRegistrationRequest()
+    validation_message TEXT NULL,                               -- Reasons that request did not pass validation with checkRegistrationRequest() - Serialized array
+    bill_fname TINYTEXT NULL,                                   -- Billing information used for this registration submission - Updates account billing address - Kept here for each request
+    bill_lname TINYTEXT NULL,
+    bill_org TINYTEXT NULL,
+    bill_title TINYTEXT NULL,
+    bill_addr1 TINYTEXT NULL,
+    bill_addr2 TINYTEXT NULL,
+    bill_city TINYTEXT NULL,
+    bill_state TINYTEXT NULL,
+    bill_zip TINYTEXT NULL,
+    bill_country TINYTEXT NULL,
+    bill_phone TINYTEXT NULL,
+    bill_email TINYTEXT NULL,
+    date_submitted DATE NULL,                                   -- Date of final submission (checkout complete)
+    pay_method INT NULL,                                        -- See payment_method in plugin.ini
+    payment_code TINYTEXT NULL,                                 -- Payment_code text (comp code) - if submitted and validated
+    status SMALLINT NULL,                                       -- See submission_status in plugin.ini
+    total DOUBLE PRECISION NULL,                                -- Total charge including all fees and taxes
+    total_discounts DOUBLE PRECISION NULL,                      -- Total of all comps and discounts
+    registrants SMALLINT NULL,                                  -- Total number of registrants in this cart
+    cc_type TINYINT NULL,                                       -- Credit Card type (if used) - See credit_card in plugin.ini
+    cc_name TINYTEXT NULL,                                      -- Name on Credit Card or Name on Check
+    cc_numb TINYTEXT NULL,                                      -- Credit Card Number or Check Number
+    cc_exp TINYTEXT NULL,
+    cc_cvv TINYTEXT NULL,
+    cc_conf TINYTEXT NULL,                                      -- Confirmation code back from card processor
+    cc_proc_mesg TINYTEXT NULL,                                 -- Message received from payment processor
+    summary TEXT NULL,                                          -- HTML summary of cart contents, costs and payment - Use same HTML displayed to user
+    mf_data TEXT NULL,                                          -- Any MagicForm data associated with registrant
+    notes TEXT NULL,                                            -- System operator's notes for this registration request
+    user_trace_info TEXT NULL,                                  -- IP Address of user computer and timestamp
+    date_created DATETIME NULL,                                 -- Date request was first created
+    last_update DATETIME NULL,                                  -- Last update date/time - Used for timing out pending carts and attendee counts
+    PRIMARY KEY (id),
+    INDEX (account),
+    INDEX (date_submitted)
+);
+
+----
+
+-- Registration for a specific event
+-- Has one or more reg_selected_rate records associated with it
+CREATE TABLE {prefix}reg_request_event (
+    id INT NOT NULL AUTO_INCREMENT,
+    reg_request INT NULL,                                       -- Pointer to reg_request table
+    reg_event INT NULL,                                         -- Pointer to reg_event
+    event_name TINYTEXT NULL,                                   -- Name of Event so it will always be in the cart data
+    notes TEXT NULL,                                            -- System operator's notes for this registration request
+    PRIMARY KEY (id),
+    INDEX (reg_request),
+    INDEX (reg_event)
+);
+
+----
+
+--  A particular reg_class selected
+--  Has one or more reg_request_rate records associated with it
+CREATE TABLE {prefix}reg_request_class (
+    id INT NOT NULL AUTO_INCREMENT,
+    reg_event INT NULL,                                         -- Pointer to reg_event entry
+    reg_request INT NULL,                                       -- Pointer to the registration request record
+    reg_request_event INT NULL,                                 -- Pointer to reg_request_event table entry
+    class INT NULL,                                             -- Pointer to event reg_class table - False (0) if registration class no longer exits
+    class_name TINYTEXT NULL,                                   -- Name of event class at the time selected
+    notes TEXT NULL,                                            -- System operator's notes for this registration request
+    PRIMARY KEY (id),
+    INDEX (reg_event),
+    INDEX (reg_request_event)
+);
+
+----
+
+--  A particular reg_rate selected
+--  Has one or more reg_request_registrant records associated with it
+CREATE TABLE {prefix}reg_request_rate (
+    id INT NOT NULL AUTO_INCREMENT,
+    reg_event INT NULL,                                         -- Pointer to reg_event entry
+    reg_request INT NULL,                                       -- Pointer to the registration request record
+    reg_request_event INT NULL,                                 -- Pointer to reg_request_event table entry
+    reg_request_class INT NULL,                                 -- Pointer to reg_request_class table entry
+    rate INT NULL,                                              -- Pointer to event reg_rate table - False (0) if registration rate no longer exists
+    rate_name TINYTEXT NULL,                                    -- Name of event class rate at the time selected
+    base_rate FLOAT,                                            -- Base rate at time of registration
+    per_registrant FLOAT,                                       -- Per Registrant Rate at time of registration
+    registrant_credits TINYINT NULL,                            -- Number of registrants included in base rate at time of registration
+    notes TEXT NULL,                                            -- System operator's notes for this registration request
+    PRIMARY KEY (id),
+    INDEX (reg_event),
+    INDEX (reg_request_event),
+    INDEX (reg_request_class)
+);
+
+----
+
+--  A specific registrant for a selected registration rate
+CREATE TABLE {prefix}reg_request_registrant (
+    id INT NOT NULL AUTO_INCREMENT,
+    account INT NULL,                                           -- Pointer to the account entry for the person being registered - False (0) if account no longer exists or registrant account not needed
+    reg_event INT NULL,                                         -- Pointer to reg_event entry
+    reg_time INT NULL,                                          -- Pointer reg_time entry
+    event_datetime DATETIME NULL,                               -- Date and time of event time selected so it will always be in the cart
+    reg_request INT NULL,                                       -- Pointer to the registration request record
+    reg_request_event INT NULL,                                 -- Pointer to reg_request_event table entry
+    reg_request_class INT NULL,                                 -- Pointer to reg_request_class table entry
+    reg_request_rate INT NULL,                                  -- Pointer to reg_request_rate table entry
+    not_attending BOOLEAN DEFAULT false,                        -- Flag to say if registrant is not attending - set to true when not attending
+    fname TINYTEXT NULL,                                        -- First name of registrant at the time of selection
+    lname TINYTEXT NULL,                                        -- Last name of registrant at the time of selection
+    notes TEXT NULL,                                            -- System operator's notes for this registration request
+    PRIMARY KEY (id),
+    INDEX (account),
+    INDEX (reg_event),
+    INDEX (reg_time),
+    INDEX (reg_request),
+    INDEX (reg_request_event),
+    INDEX (reg_request_class),
+    INDEX (reg_request_rate)
+);
+
+----
+
+--  A specific use of a payment code in this request
+CREATE TABLE {prefix}reg_request_pay_code (
+    id INT NOT NULL AUTO_INCREMENT,
+    payment_code INT NULL,                                      -- Pointer to payment code
+    code TINYTEXT NULL,                                         -- Copy of Payment Code text in case payment code is deleted or changed
+    reg_request INT NULL,                                       -- Pointer to the registration request record
+    credit DOUBLE PRECISION NULL,                               -- Total credit for this payment code
+    expire_date DATE NULL,                                      -- Expiration Date - NOT USING NOW - Getting from payment_code table always
+    PRIMARY KEY (id),
+    INDEX (payment_code),
+    INDEX (reg_request)
+);
+
+----
+
+-- Insert into management table
+INSERT INTO {prefix}management
+    (
+    canonical_reg_page,
+    reg_org_name,
+    reg_org_short,
+    reg_org_address,
+    reg_org_city,
+    reg_org_state,
+    reg_org_zip,
+    reg_org_phone,
+    reg_org_toll_free,
+    reg_org_internal_email,
+    reg_org_from_email,
+    reg_payment_methods,
+    reg_proc_methods,
+    reg_cc_accepts,
+    reg_authorize_net_login,
+    reg_authorize_net_key,
+    reg_authorize_net_test,
+    reg_authorize_net_conf,
+    reg_authorize_net_merchant_email,
+    reg_merchant_solutions_acctid,
+    reg_merchant_solutions_merchantpin,
+    reg_merchant_solutions_test,
+    reg_full_billing_info,
+    reg_bill_info_req_no_charge,
+    reg_bill_info_req_comp_code,
+    reg_bill_info_req_cash,
+    reg_bill_info_req_check,
+    reg_bill_info_req_credit_card,
+    reg_bill_info_req_merchant_call,
+    reg_medical_info
+    )
+    VALUES
+    (
+    'registrations',                                            -- reg_canonical_reg_page,
+    'Gaslight Media',                                           -- reg_org_name,
+    'GLM',                                                      -- reg_org_short,
+    '120 E. Lake St.',                                          -- reg_org_address,
+    'Petoskey',                                                 -- reg_org_city,
+    'MI',                                                       -- reg_org_state,
+    '49770',                                                    -- reg_org_zip,
+    '231-487-0692',                                             -- reg_org_phone,
+    '800-123-1234',                                             -- reg_org_toll_free,
+    'internal@gaslightmedia.com',                               -- reg_org_internal_email,
+    'info@gaslightmedia.com',                                   -- reg_org_from_email,
+    0,                                                          -- reg_payment_methods,
+    0,                                                          -- reg_proc_methods,
+    0,                                                          -- reg_cc_accepts,
+    '',                                                         -- reg_authorize_net_login,
+    '',                                                         -- reg_authorize_net_key,
+    1,                                                          -- reg_authorize_net_test,
+    true,                                                       -- reg_authorize_net_conf
+    '',                                                         -- reg_authorize_net_merchant_email,
+    '',                                                         -- reg_merchant_solutions_acctid,
+    '',                                                         -- reg_merchant_solutions_merchantpin,
+    1,                                                          -- reg_merchant_solutions_test,
+    true,                                                       -- reg_full_billing_info,
+    0,                                                          -- reg_bill_info_req_no_charge,
+    0,                                                          -- reg_bill_info_req_comp_code,
+    0,                                                          -- reg_bill_info_req_cash,
+    0,                                                          -- reg_bill_info_req_check,
+    0,                                                          -- reg_bill_info_req_credit_card,
+    0,                                                          -- reg_bill_info_req_merchant_call,
+    true                                                        -- reg_medical_info,
+    );
+
+----
+
+-- Insert into settings_terms table
+INSERT INTO {prefix}settings_terms
+    (
+    reg_term_registrations_name,
+    reg_term_registration,
+    reg_term_registration_cap,
+    reg_term_registration_plur,
+    reg_term_registration_plur_cap,
+    reg_term_register,
+    reg_term_register_cap,
+    reg_term_registers,
+    reg_term_registering,
+    reg_term_registering_cap,
+    reg_term_registered,
+    reg_term_registered_cap,
+    reg_term_attendee,
+    reg_term_attendee_cap,
+    reg_term_attendee_plur,
+    reg_term_attendee_plur_cap,
+    reg_term_attending,
+    reg_term_attended,
+    reg_term_registered_user,
+    reg_term_registered_user_cap,
+    reg_term_registered_user_plur,
+    reg_term_registered_user_plur_cap,
+    reg_term_event,
+    reg_term_event_cap,
+    reg_term_event_plur,
+    reg_term_event_plur_cap,
+    reg_term_id,
+    reg_term_id_cap,
+    reg_term_id_plur,
+    reg_term_id_plur_cap,
+    reg_term_password,
+    reg_term_password_cap,
+    reg_term_password_plur,
+    reg_term_password_plur_cap,
+    reg_term_instructor,
+    reg_term_instructor_cap,
+    reg_term_instructor_plur,
+    reg_term_instructor_plur_cap,
+    reg_term_payment_code,
+    reg_term_payment_code_cap,
+    reg_term_payment_code_plur,
+    reg_term_payment_code_plur_cap,
+    reg_term_registration_button,
+    reg_term_contact_information
+    )
+    VALUES
+    (
+    'Event Registrations',                                      -- reg_term_registrations_name
+    'registration',                                             -- reg_term_registration
+    'Registration',                                             -- reg_term_registration_cap
+    'registrations',                                            -- reg_term_registration_plur
+    'Registrations',                                            -- reg_term_registration_plur_cap
+    'register',                                                 -- reg_term_registe
+    'Register',                                                 -- reg_term_register_cap
+    'registers',                                                -- reg_term_registers
+    'registering',                                              -- reg_term_registering
+    'Registering',                                              -- reg_term_registering_cap
+    'registered',                                               -- reg_term_registered
+    'Registered',                                               -- reg_term_registered_cap
+    'attendee',                                                 -- reg_term_attendee
+    'Attendee',                                                 -- reg_term_attendee_cap
+    'attendees',                                                -- reg_term_attendee_plur
+    'Attendees',                                                -- reg_term_attendee_plur_cap
+    'attending',                                                -- reg_term_attending
+    'attended',                                                 -- reg_term_attended
+    'user',                                                     -- reg_term_registered_user
+    'User',                                                     -- reg_term_registered_user_cap
+    'users',                                                    -- reg_term_registered_user_plur
+    'Users',                                                    -- reg_term_registered_user_plur_cap
+    'event',                                                    -- reg_term_event
+    'Event',                                                    -- reg_term_event_cap
+    'events',                                                   -- reg_term_event_plur
+    'Events',                                                   -- reg_term_event_plur_cap
+    'ID',                                                       -- reg_term_id
+    'ID',                                                       -- reg_term_id_cap
+    'IDs',                                                      -- reg_term_id_plur
+    'IDs',                                                      -- reg_term_id_plur_cap
+    'password',                                                 -- reg_term_password
+    'passwords',                                                -- reg_term_password_cap
+    'Password',                                                 -- reg_term_password_plur
+    'Passwords',                                                -- reg_term_password_plur_cap
+    'instructor',                                               -- reg_term_instructor
+    'Instructor',                                               -- reg_term_instructor_cap
+    'instructors',                                              -- reg_term_instructor_plur
+    'Instructors',                                              -- reg_term_instructor_plur_cap
+    'payment code',                                             -- reg_term_payment_code
+    'Payment code',                                             -- reg_term_payment_code_cap
+    'payment codes',                                            -- reg_term_payment_code_plur
+    'Payment codes',                                            -- reg_term_payment_code_plur_cap
+    'Register for Event',                                       -- reg_term_registration_button
+    'Contact Information'                                       -- reg_term_contact_information
+    );
+
+----
+
+-- Insert into misc table
+INSERT INTO {prefix}misc
+    (
+    reg_bulletin,
+    cart_page_text,
+    checkout_page_text,
+    summary_page_text,
+    reg_terms,
+    notify_subject,
+    notify_text,
+    instr_notify_subject,
+    instr_notify_text,
+    submission_notify_subject,
+    submission_notify_text,
+    registrant_notify_subject,
+    registrant_notify_text,
+    submission_ack_subject,
+    submission_ack_text,
+    registrant_ack_subject,
+    registrant_ack_text
+    )
+    VALUES
+    (
+    'Registration Bulletin Text',
+    'Text for top of Cart Page',
+    'Text for top of Checkout Page',
+    'Text for top of Summary Page',
+    'Terms and Conditions',
+    'Subject of notification to site owner of a registration',
+    'Text of notification to site owner of a registration',
+    'Subject of notification to instructor of registration',
+    'Text for notification to instructor of registration',
+    'Subject of notification to person submitting registration',
+    'Text of notification to person submitting registration',
+    'Subject for notification to registrant',
+    'Text for notification to registrant',
+    'Subject of acknowledgement to person submitting registration',
+    'Text of acknowledgement to person submitting registration',
+    'Subject of acknowledgement to registrant',
+    'Text of acknowledgement to registrant'
+    );
index 8775429..863ef9e 100644 (file)
@@ -44,7 +44,10 @@ $glmMembersRegistrationsDbVersions = array(
     '0.0.28' => array('version' => '0.0.28', 'tables' => 18, 'date' => '04/12/2018'),
     '0.0.29' => array('version' => '0.0.29', 'tables' => 18, 'date' => '05/04/2018'),
     '0.0.30' => array('version' => '0.0.30', 'tables' => 18, 'date' => '05/14/2018'),
-    '0.0.31' => array('version' => '0.0.31', 'tables' => 18, 'date' => '05/15/2018')
+    '0.0.31' => array('version' => '0.0.31', 'tables' => 18, 'date' => '05/15/2018'),
+    '0.0.32' => array('version' => '0.0.32', 'tables' => 18, 'date' => '05/22/2018'),
+
+    '1.0.0' => array('version' => '1.0.0', 'tables' => 18, 'date' => '06/04/2018')
 );
 
 
diff --git a/setup/databaseScripts/drop_database_V0.0.31.sql b/setup/databaseScripts/drop_database_V0.0.31.sql
deleted file mode 100644 (file)
index 2ac0fe3..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
--- Gaslight Media Members Database
--- File Created: 12/09/14 15:27:15
--- Database Version: 0.0.19
--- Database Deletion Script
--- Note: Tables with DELETE CASCADE must appear before referenced table
-
-DROP TABLE IF EXISTS
-    {prefix}management,
-    {prefix}settings_terms,
-    {prefix}misc,
-    {prefix}payment_code,
-    {prefix}reg_event,
-    {prefix}reg_time,
-    {prefix}reg_time_pending,
-    {prefix}reg_class,
-    {prefix}reg_rate,
-    {prefix}reg_notification,
-    {prefix}account,
-    {prefix}reg_request,
-    {prefix}reg_request_event,
-    {prefix}reg_request_class,
-    {prefix}reg_request_rate,
-    {prefix}reg_request_registrant,
-    {prefix}reg_request_pay_code
-;
-
diff --git a/setup/databaseScripts/drop_database_V1.0.0.sql b/setup/databaseScripts/drop_database_V1.0.0.sql
new file mode 100644 (file)
index 0000000..2ac0fe3
--- /dev/null
@@ -0,0 +1,26 @@
+-- Gaslight Media Members Database
+-- File Created: 12/09/14 15:27:15
+-- Database Version: 0.0.19
+-- Database Deletion Script
+-- Note: Tables with DELETE CASCADE must appear before referenced table
+
+DROP TABLE IF EXISTS
+    {prefix}management,
+    {prefix}settings_terms,
+    {prefix}misc,
+    {prefix}payment_code,
+    {prefix}reg_event,
+    {prefix}reg_time,
+    {prefix}reg_time_pending,
+    {prefix}reg_class,
+    {prefix}reg_rate,
+    {prefix}reg_notification,
+    {prefix}account,
+    {prefix}reg_request,
+    {prefix}reg_request_event,
+    {prefix}reg_request_class,
+    {prefix}reg_request_rate,
+    {prefix}reg_request_registrant,
+    {prefix}reg_request_pay_code
+;
+
index 7029af4..72dc01c 100644 (file)
@@ -1,6 +1,6 @@
 -- Gaslight Media Members Database  - Registratiuons Add-On
 -- File Updated: 2018-04-12
--- Database Version: 0.0.30
+-- Database Version: 0.0.31
 -- Database Update From Previous Version Script
 --
 -- To permit each query below to be executed separately,
diff --git a/setup/databaseScripts/update_database_V0.0.32.sql b/setup/databaseScripts/update_database_V0.0.32.sql
new file mode 100644 (file)
index 0000000..b8ca636
--- /dev/null
@@ -0,0 +1,27 @@
+-- Gaslight Media Members Database  - Registratiuons Add-On
+-- File Updated: 2018-05-22
+-- Database Version: 0.0.32
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+ALTER TABLE {prefix}management ADD COLUMN reg_paypal_clientid TINYTEXT;
+
+----
+
+ALTER TABLE {prefix}management ADD COLUMN reg_paypal_secret TINYTEXT;
+
+----
+
+ALTER TABLE {prefix}management ADD COLUMN reg_paypal_test TINYINT;
+
+----
+
+UPDATE {prefix}management 
+   SET reg_paypal_clientid = '',
+       reg_paypal_secret = '',
+       reg_paypal_test = 3
+;
+
+
diff --git a/setup/databaseScripts/update_database_V1.0.0.sql b/setup/databaseScripts/update_database_V1.0.0.sql
new file mode 100644 (file)
index 0000000..ce99b41
--- /dev/null
@@ -0,0 +1,20 @@
+-- Gaslight Media Members Database  - Registratiuons Add-On
+-- File Updated: 2018-05-22
+-- Database Version: 0.0.32
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+ALTER TABLE {prefix}management ADD COLUMN reg_paypal_sandbox_clientid TINYTEXT;
+
+----
+
+ALTER TABLE {prefix}management ADD COLUMN reg_paypal_sandbox_secret TINYTEXT;
+
+----
+
+UPDATE {prefix}management 
+   SET reg_paypal_sandbox_clientid = '',
+       reg_paypal_sandbox_secret = ''
+;
index 689fff3..14cae63 100644 (file)
@@ -69,7 +69,8 @@ $glmMembersRegistrationsAddOnValidActions = array(
             'registrantsListExport'     => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
             'setupEventRegQueue'        => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
             'runEventRegQueue'          => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
-            'getAuthorizeNetSeal'       => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG
+            'getAuthorizeNetSeal'       => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
+            'regPayPal'                 => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG
         ),
         'registrations' => array(
             'index'                     => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
index 30371b1..c9067d5 100644 (file)
                             </select>
                         </td>
                     </tr>
+                    
+                    <!-- Authorize.net -->
+                    
                     <tr class="authorize-net">
                         <td></td>
                         <th><p>Authorize.net</p></th>
                             </td>
                         </tr>
                     </tr>
+                    
+                    <!-- Merchant Solutions -->
 
                     <tr class="merchant-solutions">
                         <td></td>
                             {if $regSettings.fieldFail.reg_merchant_solutions_merchant_email}<p>{$regSettings.fieldFail.reg_merchant_solutions_merchant_email}</p>{/if}
                         </td>
                     </tr>
+                    
+                    <!-- PayPal -->
+                    
+                    <tr class="paypal">
+                        <td></td>
+                        <th><p>PayPal</p></th>
+                    </tr>
+                    <tr class="paypal">
+                        <th class="glm-nowrap-left-align{if $regSettings.fieldRequired.reg_paypal_clientid} glm-required{/if}"> Production Client ID:</th>
+                        <td {if $regSettings.fieldFail.reg_paypal_clientid}class="glm-form-bad-input"{/if}>
+                            <input type="text" name="reg_paypal_clientid" value="{$regSettings.fieldData.reg_paypal_clientid}" class="glm-form-text-input-medium-long">
+                            {if $regSettings.fieldFail.reg_paypal_clientid}<p>{$regSettings.fieldFail.reg_paypal_clientid}</p>{/if}
+                        </td>
+                    </tr>
+                    <tr class="paypal">
+                        <th class="glm-nowrap-left-align{if $regSettings.fieldRequired.reg_paypal_secret} glm-required{/if}"> Production Secret:</th>
+                        <td {if $regSettings.fieldFail.reg_paypal_secret}class="glm-form-bad-input"{/if}>
+                            <input type="text" name="reg_paypal_secret" value="{$regSettings.fieldData.reg_paypal_secret}" class="glm-form-text-input-medium-long">
+                            {if $regSettings.fieldFail.reg_paypal_secret}<p>{$regSettings.fieldFail.reg_paypal_secret}</p>{/if}
+                        </td>
+                    </tr>
+                    <tr class="paypal">
+                        <th class="glm-nowrap-left-align{if $regSettings.fieldRequired.reg_paypal_sandbox_clientid} glm-required{/if}"> Sandbox Client ID:</th>
+                        <td {if $regSettings.fieldFail.reg_paypal_sandbox_clientid}class="glm-form-bad-input"{/if}>
+                            <input type="text" name="reg_paypal_sandbox_clientid" value="{$regSettings.fieldData.reg_paypal_sandbox_clientid}" class="glm-form-text-input-medium-long">
+                            {if $regSettings.fieldFail.reg_paypal_sandbox_clientid}<p>{$regSettings.fieldFail.reg_paypal_sandbox_clientid}</p>{/if}
+                        </td>
+                    </tr>
+                    <tr class="paypal">
+                        <th class="glm-nowrap-left-align{if $regSettings.fieldRequired.reg_paypal_sandbox_secret} glm-required{/if}"> Sandbox Secret:</th>
+                        <td {if $regSettings.fieldFail.reg_paypal_sandbox_secret}class="glm-form-bad-input"{/if}>
+                            <input type="text" name="reg_paypal_sandbox_secret" value="{$regSettings.fieldData.reg_paypal_sandbox_secret}" class="glm-form-text-input-medium-long">
+                            {if $regSettings.fieldFail.reg_paypal_sandbox_secret}<p>{$regSettings.fieldFail.reg_paypal_sandbox_secret}</p>{/if}
+                        </td>
+                    </tr>
+                    <tr class="paypal">
+                        <th>Test Mode:</th>
+                        <td>
+                            <select id="default-paypal-test" data-id="reg_paypal_test" name="reg_paypal_test">
+                                <option value=""></option>
+                                {foreach from=$regSettings.fieldData.reg_paypal_test.list item=v}
+                                <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
+                                    {$v.name}
+                                </option>
+                                {/foreach}
+                            </select>
+                        </td>
+                    </tr>
+                    
+                    <!-- General Options -->                    
+                    
                     <tr>
                         <td></td>
                         <th><p>Other General Options</p></th>
index 0bea245..de6a044 100644 (file)
 
   {if $cart.grandTotal > 0}
               <div class="glm-row">
-                  <div class="glm-large-6 glm-small-12 glm-columns">
+                  <div id="RegPaymentForm" class="glm-large-6 glm-small-12 glm-columns">
                       <h4>Payment Information</h4>
                           <div id="payMethodSelectors" data-paymethod="" style="white-space: nowrap;">
     {foreach $payMethods as $payMethod}
             {else if $pmName == "Cash"} 
                 {* Nothing here for now *}
             {else if $pmName == "Check"} 
-                        <div id="payMethod_{$pmNumb}" class="payMethodSelection glm-hidden">
+                        <div class="payMethod_{$pmNumb} payMethodSelection glm-hidden">
                             <div class="glm-reg-row">
                                 <div class="glm-reg-checkout-field-label glm-small-12 glm-large-3 glm-columns glm-reg-nowrap{if $regAccount.fieldRequired.cc_name} glm-reg-required{/if}">Name on Check{if $regAccount.fieldRequired.cc_name} *{/if}</div>
                                 <div class="glm-reg-checkout-field-data glm-small-12 glm-large-9 glm-columns{if $regAccount.fieldFail.cc_name} glm-reg-fail{/if}">
                         </div>
             {else if $pmName == "CreditCard"}
             
-                        <div id="payMethod_{$pmNumb}" class="payMethodSelection glm-hidden">
+                        <div class="payMethod_{$pmNumb} payMethodSelection glm-hidden">
                 {if $settings.reg_proc_methods == 2 && $regAccount.fieldData.customer_profile_id != ''} {* If using Authorize.net and have a stored credit card profile *}
                             <div class="glm-reg-row">
                                 <div class="glm-reg-checkout-field-data glm-small-12 glm-large-12 glm-columns">
                             </div>                        
                 {/if}
                         </div>
+            {else if $pmName == "PayPal"}
+                        <div class="payMethod_{$pmNumb} payMethodSelection glm-hidden">
+                            <div class="glm-reg-row">
+                                <div class="glm-small-1 glm-large-1 glm-columns">
+                                    &nbsp;
+                                </div>
+                                <div class="glm-reg-checkout-field-data glm-small-11 glm-large-11 glm-columns">
+                                    PayPal payment information will be requested when you select the "Pay with PayPal" button below.
+                                </div>
+                            </div>
+                        </div>
+                                    
             {else}
-                        <div id="payMethod_{$pmNumb}" class="payMethodSelection glm-hidden">
+                        <div class="payMethod_{$pmNumb} payMethodSelection glm-hidden">
 
                         </div>
             {/if}
             <div class="glm-right" style="white-space; nowrap;">
                 <!--<span class="glm-reg-warning">You have one more step to complete your {$terms.reg_term_registration}!</span> <img src="{$assetUrl}/fingerRightRed.svg" style="height: 2em;">--> 
     {if $settings.reg_show_navigation_aids}
-                <div class="glm-reg-warning">Your {$terms.reg_term_registration} is not complete until you click here! <img src="{$assetUrl}/fingerRightRed.svg" style="height: 2em;"> 
+                <div class="glm-reg-warning">Your {$terms.reg_term_registration} is not complete until you click here! <img src="{$assetUrl}/fingerRightRed.svg" style="height: 2em;"></div>
     {/if}
-                <input id="regSubmitButton" type="submit" value="{$terms.reg_term_button_checkout_page_submit}" class="button glm-reg-button">
+                <input id="payPalPayButton" type="submit" value="Pay with PayPal" class="button glm-reg-button glm-hidden" disabled>
+                <input id="regSubmitButton" type="submit" value="{$terms.reg_term_button_checkout_page_submit}" class="button glm-reg-button">                
             </div>
         </form>
     
+       
         <div id="regSubmitDialog" title="Please wait...">Please wait while we process your {$terms.reg_term_registration} request. If you don't see a new page, your {$terms.reg_term_registration} request may not have been processed.</div>
         <div id="regSubmitFailDialog" title="Oops!">
             <h3>Something may have gone wrong.</h3>
     </div>
 </div>
 
-
-   
-
+<script src="https://www.paypalobjects.com/api/checkout.js"></script>
+<div id="payPalPaymentDialog" style="width: 100% !important">
+    <center>
+        <div id="paypal-button-container"></div>
+    </center>
+    <br>
+    <span class="glm-reg-warning">NOTE:</span> Your {$terms.reg_term_registration_plur} are not complete until you accept the PayPal payment and see the checkout summary page! 
+    <br>
+    <div id="payPalPaymentWarningMessage" class="glm-reg-warning"></div>
+    <div id="payPalPaymentMessage"></div>
+</div>
 
 {/if} {* / if have cart *}
 
             $('.payMethodInput').attr('disabled', true);
 
             // Show the selected pay method inputs and enable just those
-            $('#payMethod_' + payMethodNumb).removeClass('glm-hidden');
+            $('.payMethod_' + payMethodNumb).removeClass('glm-hidden');
             $('.payMethodInput_' + payMethodNumb).removeAttr('disabled');
+
+            if (payMethodNumb == {$payMethodsNumb.PayPal}) {
+                $('#regSubmitButton').addClass('glm-hidden');
+                $('#payPalPayButton').removeClass('glm-hidden');
+                $('#payPalPayButton').removeAttr('disabled');
+            } else {
+                $('#regSubmitButton').removeClass('glm-hidden');
+                $('#payPalPayButton').addClass('glm-hidden');
+                $('#payPalPayButton').attr('disabled','disabled');
+            }
             
         }
 
         // Dissable checkout button when first clicked to prevent multiple attempts
+        var payPalSubmitOK = false;
         $("#checkoutForm").submit(function(e){
 
+            // Check if this is a PayPal payment request
+            if (!$('#payPalPayButton').attr('disabled')) {
+
+                // Check if this is a re-submit by our PayPal payment code below
+                if (payPalSubmitOK) {
+                    return true;
+                }
+
+                // Display our PayPal payment dialog box and fix some CSS
+                $( "#payPalPaymentDialog" ).dialog("open");
+                $( "#payPalPaymentDialog" ).css({
+                    "width": "100%"
+                });
+
+                // Display the Pay by PayPal button in our dialog box
+                displayPayPalButton();
+
+                // Don't actually do a submit yet
+                return false;
+            }
+            
             // If something else is preventing submission, stop here. Use this with custom fields when there are required fields.
             if (e.isDefaultPrevented()) {
                 return false;
 
         // Start with all pay method inputs dissabled
         $( document ).ready(function() {
-
+            
             // Dialog box to show when submitting checkout page
             $( "#regSubmitDialog" ).dialog({
                 autoOpen: false,
                 width: 600
             });
 
+            // Dialog box to show a PayPal payment button
+            $( "#payPalPaymentDialog" ).dialog({
+                autoOpen: false,
+                width: 600,
+                modal: true,
+                'buttons': {
+                    'I don\'t wish to pay with PayPal': function(event) {
+                        $(this).dialog("close");
+                    }
+                }
+            });
+            
             // Start with all payment method sections hidden
             $('.payMethodInput').attr('disabled', true);
 
         $(".expire-input").mask("00/00");
         $(".cvv-input").mask("000#");
 
-
         // Registration not submitted Dialog actions
         {if $settings.reg_not_submitted_dialog}    
 
 
         {/if}  
 
+        // When the checkout button is clicked and a PayPal payment is requested, this code is called to create a PayPal button inside of the dialog box 
+        var payPalButtonGenerated = false;
+        function displayPayPalButton() {
+
+            if (payPalButtonGenerated) {
+                return;
+            }
+            payPalButtonGenerated = true;
+
+            
+            // PayPal button actions
+            paypal.Button.render({
+    
+                // Set your environment
+    
+        {if $payPalMode}
+                env: 'sandbox',
+        {else}
+                env: 'production',
+        {/if}
+    
+                // Specify the style of the button
+                style: {
+                    label: 'pay',
+                    size:  'large', // small | medium | large | responsive
+                    shape: 'rect',   // pill | rect
+                    color: 'blue'   // gold | blue | silver | black
+                },
+    
+                // To create a PayPal see app: https://developer.paypal.com/developer/applications/create
+                client: {
+                    sandbox:    '{$payPalSandboxClientId}',
+                    production: '{$payPalClientId}'
+                },
+    
+                // Wait for the PayPal button to be clicked
+                payment: function(data, actions) {
+                    return actions.payment.create({
+                        invoice_number: '{$cartId}', 
+                        payment: {
+                            payer: {
+                                payer_info: {
+                                    first_name: '{$cart.request.bill_fname}',
+                                    last_name: '{$cart.request.bill_lname}',
+                                    email: '{$cart.request.bill_email}'
+                                }
+                            },
+                            transactions: [
+                                {
+                                    description: '{$settings.reg_org_name} {$reg.term.registration_plur_cap}',
+                                    invoice_number: '{$cartId}',
+                                    amount: { 
+                                        total: '{$cart.grandTotal}', 
+                                        currency: 'USD' 
+                                    },
+                                    item_list: {
+                                        items: [
+            {foreach $cart.chargeItems as $item}                                        
+                                            { 
+                                                name: '{$item.name}',
+                                                quantity: {$item.quantity},
+                                                price: {$item.price},
+                                                currency: 'USD'
+                                            },
+            {/foreach}
+                                        ]
+                                    } 
+                                }
+                            ]
+                        }
+                    });
+                },
+                onCancel: function(data, actions) {
+                        $('#payPalPaymentWarningMessage').html('You canceled the PayPal Payment. Payment is required to submit your {$terms.reg_term_registration_plur}. If you don\'t wish to pay with PayPal, click the button below and select another payment method.');
+                },
+                onError: function(err) {
+                    $('#payPalPaymentWarningMessage').html('There was a problem with your PayPal Payment. Payment is required to submit your {$terms.reg_term_registration_plur}. If you\'re unable to pay with PayPal, click the button below and select another payment method.');
+                },
+                // Wait for the payment to be authorized by the customer
+                onAuthorize: function(data, actions) {
+                    return actions.payment.execute().then(function(data) {
+
+                        var sale = data.transactions[0].related_resources[0].sale;
+
+                        // Notify submit code above that it's OK to checkout
+                        payPalSubmitOK = true;
+                        
+                        $( "#payPalPaymentDialog" ).dialog("close");
+
+                        // Add PayPal payment details to form
+                        $("#checkoutForm").append(
+                                '<input type="hidden" name="payPalPaymentID" value="' + sale.id + '">'
+                               +'<input type="hidden" name="payPalPaymentTime" value="' + sale.create_time + '">'
+                               +'<input type="hidden" name="payPalPaymentState" value="' + sale.state +'">'
+                        );
+                        // Now try to submit the form again
+                        $("#checkoutForm").submit();
+                    });
+                }
+    
+            }, '#paypal-button-container');
+                
+        }
+
+        
     });
 </script>
index f8b06bc..0ea3c75 100644 (file)
@@ -492,6 +492,8 @@ var app = {
     attendeeCount: 0,
     attendeeMaxPerReg: parseInt( {$regEvent.attendee_max_per_reg} ),
     attendeePlurCapTerm: '{$terms.reg_term_attendee_plur_cap}',
+    attendeeCapTerm: '{$terms.reg_term_attendee_cap}',
+    eventCapTerm: '{$terms.reg_term_event_cap}',
     checkForMaxAttendees: function(){
         if ( app.attendeeMaxPerReg ) {
             // Here we need to see how many registrants total in each class.
index 5c664e6..60482e1 100644 (file)
                     
                     <table class="info-table" width="100%">
                         <tbody>
-                    {if $request.pay_method.value == $payMethodsNumb.CreditCard}
+                    {if $request.pay_method.value == $payMethodsNumb.NoCharge}
                             <tr><th class="glm-reg-c1">Payment Method:</th><td>{$request.pay_method.name}</td></tr>
-                            <tr><th class="glm-reg-c1">Credit Card:</th><td>{$request.cc_type.name}</td></tr>
-                            <tr><th class="glm-reg-c1">Name on Card:</th><td>{$request.cc_name}</td></tr>
-                            <tr><th class="glm-reg-c1">Card Number:</th><td>{$request.cc_numb}</td></tr>
-                            <tr><th class="glm-reg-c1">Expiration:</th><td>{$request.cc_exp}</td></tr>
-                            <tr><th class="glm-reg-c1">Confirmation Code:</th><td>{$request.cc_conf}</td></tr>
-                            <tr><th class="glm-reg-c1">Total Charged:</th><td>{$request.total}</td></tr>
+                    {/if}
+                    {if $request.pay_method.value == $payMethodsNumb.OnArrival}
+                            <tr><th class="glm-reg-c1">Payment Method:</th><td>{$request.pay_method.name}</td></tr>
+                            <tr><th class="glm-reg-c1">To be paid on arrival:</th><td>{$request.total}</td></tr>
+                    {/if}
+                    {if $request.pay_method.value == $payMethodsNumb.Cash}
+                            <tr><th class="glm-reg-c1">Payment Method:</th><td>{$request.pay_method.name}</td></tr>
+                            <tr><th class="glm-reg-c1">Total Paid:</th><td>{$request.total}</td></tr>
                     {/if}
                     {if $request.pay_method.value == $payMethodsNumb.Check}
                             <tr><th class="glm-reg-c1">Payment Method:</th><td>{$request.pay_method.name}</td></tr>
                             <tr><th class="glm-reg-c1">Check Number:</th><td>{$request.cc_numb}</td></tr>
                             <tr><th class="glm-reg-c1">Total Paid:</th><td>{$request.total}</td></tr>
                     {/if}
-                    {if $request.pay_method.value == $payMethodsNumb.Cash}
+                    {if $request.pay_method.value == $payMethodsNumb.CreditCard}
                             <tr><th class="glm-reg-c1">Payment Method:</th><td>{$request.pay_method.name}</td></tr>
-                            <tr><th class="glm-reg-c1">Total Paid:</th><td>{$request.total}</td></tr>
+                            <tr><th class="glm-reg-c1">Credit Card:</th><td>{$request.cc_type.name}</td></tr>
+                            <tr><th class="glm-reg-c1">Name on Card:</th><td>{$request.cc_name}</td></tr>
+                            <tr><th class="glm-reg-c1">Card Number:</th><td>{$request.cc_numb}</td></tr>
+                            <tr><th class="glm-reg-c1">Expiration:</th><td>{$request.cc_exp}</td></tr>
+                            <tr><th class="glm-reg-c1">Confirmation Code:</th><td>{$request.cc_conf}</td></tr>
+                            <tr><th class="glm-reg-c1">Total Charged:</th><td>{$request.total}</td></tr>
                     {/if}
-                    {if $request.pay_method.value == $payMethodsNumb.OnArrival}
+                    {if $request.pay_method.value == $payMethodsNumb.PayPal}
                             <tr><th class="glm-reg-c1">Payment Method:</th><td>{$request.pay_method.name}</td></tr>
-                            <tr><th class="glm-reg-c1">To be paid on arrival:</th><td>{$request.total}</td></tr>
+                            <tr><th class="glm-reg-c1">Total Paid:</th><td>{$request.total}</td></tr>
+                            <tr><th class="glm-reg-c1">Confirmation code:</th><td>{$request.cc_conf}</td></tr>
                     {/if}
                     {if $request.pay_method.value == $payMethodsNumb.Pending}
                             <tr><th class="glm-reg-c1">Payment Method:</th><td>{$request.pay_method.name}</td></tr>