Started updating the front/cart.php to have it grab and validate cart data.
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 26 Sep 2017 12:18:27 +0000 (08:18 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 26 Sep 2017 12:18:27 +0000 (08:18 -0400)
Result of checRegistrationRequest() is essentially the same array as returned by getRegistrationCart() but will addition information inserted.
Initial comments are in the regCartSupport class on how cart will be validated and some code is in place.
Some additional debugging and fixes to admin reg setup for classes and rates and user interface updates.

12 files changed:
classes/regCartSupport.php
js/adminRegApp.js
js/views/admin/regClass.js
js/views/admin/regRate.js
models/admin/ajax/regAdmin.php
models/admin/ajax/regAdmin/regClasses.php
models/admin/ajax/regAdmin/regRates.php
models/admin/registrations/events.php
models/front/registrations/cart.php
models/front/registrations/registration.php
views/admin/registrations/eventEdit.html
views/admin/registrations/eventEditLevels.html

index 4d5eb30..b014da4 100644 (file)
@@ -245,7 +245,7 @@ class GlmRegCartSupport
     /*
      * Checks validity of a request (cart) and sets new update time (for holds)
      *
-     * This function loads the entire cart using the supplied request ID then checks it for any issues.
+     * This function checks the currently loaded cart for any issues and recalculates totals.
      *
      *  Checks links to referenced events and event times records in the Event Add-on tables and notes if either are missing.
      *  Checks all referenced Accounts for non-guest carts and notes if any are missing.
@@ -257,15 +257,18 @@ class GlmRegCartSupport
      *  Updates all totals
      *  Updates request last accessed time
      *
-     * @param integer $requestId    If false then check the currently loaded cart
-     *
      * @return array Array of request and all associated information or false
      * @access public
      */
-    public function checkRegistrationRequest($requestId = false)
+    public function checkRegistrationRequest(
     {
 
         $messages[] = '';
+        $totalCharges = 0;
+        $totalRegistrants = 0;
+        $totalDiscounts = 0;
+        $grandTotal = 0;
+        
 
         // If request ID is not false, get the cart first
         if ($requestId !== false) {
@@ -283,14 +286,85 @@ class GlmRegCartSupport
 
         // Check if there's no events listed
         if (is_array($this->cart['events']) && count($this->cart['events']) > 0) {
-            $messages[] .= 'Cart is empty.';
+            $messages[] = 'Cart is empty.';
         } else {
 
             // Loop through all events in the cart
-            foreach ($this->cart['events'] as $event) {
-
-                // Check if Event exists in Events add-on
+            foreach ($this->cart['events'] as $eventKey => $event) {
 
+                $this->cart['events'][$eventKey]['charges'] = 0;
+                $this->cart['events'][$eventKey]['credits'] = 0;
+                $this->cart['events'][$eventKey]['discounts'] = 0;
+                $this->cart['events'][$eventKey]['total'] = 0;
+                $this->cart['events'][$eventKey]['numbRegistrants'] = 0;
+                
+                // Check if Event exists in Events add-on and is active in registrations or if doing admin (admin_active)
+                $regEvent = $RegEvent->getEntry($event['reg_event']);
+                if (!$regEvent) {
+                    $messages[] = 'Event in cart is not currently available for registratiosn.';
+                }
+                
+                // Check if the event is time-specific and if there's a list of times for this event - If not, should be a default
+                
+                // Check if there's a list of classes (levels) for this event - If not, add as a problem
+                
+                    // Loop though all classes - Might be multiple classes (levels) that are the same but for different reg_times.
+
+                        // [this class]['charges'] = 0;
+                        // [this class]['credits'] = 0;
+                        // [this class]['discounts'] = 0;
+                        // [this class]['total'] = 0;
+                        // [this class]['numbRegistrants'] = 0;
+                
+
+                        // Check if there's a list of rates - if not, add as a problem
+                            
+                        // loop through all rates
+            
+                            // [this rate]['charges'] = 0;
+                            // [this rate]['credits'] = 0;
+                            // [this rate]['discounts'] = 0;
+                            // [this rate]['total'] = 0;
+                            // [this rate]['numbRegistrants'] = 0;
+                            
+                            // Check if listed rate is currently available - If not, add as a problem
+                            
+                            // Check if there's a list of registrants for this class (level) - If not, add as a problem
+                            
+                            // Loop through all registrants
+                            
+                                // [this registrant]['charges'] = 0;
+                                // [this registrant]['credits'] = 0;
+                                // [this registrant]['discounts'] = 0;
+                                // [this registrant]['total'] = 0;
+                                
+                                // Check that registrant has an account that's active - If not, add as a problem
+                                
+                                // Check if limited registration
+                                
+                                    // Check for a current hold - If expired or not listed
+                                    
+                                        // If no current hold, try to get new hold - If not, add as a problem
+                                        
+                                // If no problems, then calculate charges
+                                
+                                    // If there's not already a charge for this class (level) - Add base rate to charges
+                                    
+                                    // If the number of registrants is less than the registrant credits - Add the per-registrant rate
+                                    
+                                    // Check if there's a comp or discount code - if so add add discount
+                                    
+                                    // Calculate net charge for this registrant and put it in registrant data
+                                    
+                                // Add charges, credits, discounts, totals to the current rate
+                                
+                            // Add charges, credits, discounts, totals for this rate to the current class (level)
+                             
+                    // Add charges, credits, discounts, totals for class (level) to the current event
+                    
+                // Add charges, credits, discounts, totals for this event to the grand totals
+                
+                                
             }
 
         } // have events
@@ -391,358 +465,4 @@ class GlmRegCartSupport
 
     }
 
-    /*
-     *  Add temporary test data
-     *
-     *  This builds a completed registration request and adds it to the appropriate
-     *  database tables.
-     *
-     *  This function builds the following data
-     *
-     *  1 reg_event
-     *      1 reg_class
-     *          1 reg_rates
-     *
-     *  1 account - Account also used as registrant
-     *
-     *  1 reg_request
-     *      1 reg_request_event
-     *          1 reg_request_class
-     *              1 reg_request_rate
-     *                  1 reg_request_registrant
-     *
-     */
-    public function addTestData()
-    {
-
-        // Grab the first event from the events database
-        $sql = "SELECT id, name FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."events LIMIT 1";
-        $event = $this->wpdb->get_results($sql, ARRAY_A);
-        $eventId = $event[0]['id'];
-        $eventName = $event[0]['name'];
-
-        // Grab the first time from this event
-        $sql = "SELECT id, start_time FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."times WHERE event = $eventId LIMIT 1";
-        $time = $this->wpdb->get_results($sql, ARRAY_A);
-        $timeId = $event[0]['id'];
-        $eventTime = $time[0]['start_time'];
-
-        // Event
-        $sql = "
-            INSERT INTO ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_event
-                (
-                event,
-                event_name,
-                event_code,
-                active
-                )
-                VALUES
-                (
-                $eventId,
-                '$eventName',
-                'TEST-EVENT',
-                true
-                )
-        ;";
-        $this->wpdb->query($sql);
-        $regEventID = $this->wpdb->insert_id;
-
-        // Event Registration Class
-        $sql = "
-            INSERT INTO ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_class
-                (
-                reg_event,
-                name,
-                descr
-                )
-                VALUES
-                (
-                $regEventID,
-                'Admiral Class',
-                'This is our Admiral Class registration level.'
-                )
-        ;";
-        $this->wpdb->query($sql);
-        $regClassID = $this->wpdb->insert_id;
-
-        // Event Registration Rate
-        $sql = "
-            INSERT INTO ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_rate
-                (
-                reg_event,
-                reg_class,
-                name,
-                start_days,
-                end_days,
-                base_rate,
-                per_registrant,
-                registrant_credits
-                )
-                VALUES
-                (
-                $regEventID,
-                $regClassID,
-                'Rate Name',
-                100,
-                50,
-                20,
-                10,
-                1
-                )
-        ;";
-        $this->wpdb->query($sql);
-        $regRateID = $this->wpdb->insert_id;
-
-
-        // Account
-        $sql = "
-            INSERT INTO ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."account
-                (
-                active,
-                fname
-                )
-                VALUES
-                (
-                true,
-                'Chuck'
-                )
-        ;";
-        $this->wpdb->query($sql);
-        $accountID = $this->wpdb->insert_id;
-
-
-        // Registration Request
-        $sql = "
-            INSERT INTO ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request
-                (
-                account,
-                bill_fname,
-                bill_lname,
-                bill_org,
-                bill_title,
-                bill_addr1,
-                bill_addr2,
-                bill_city,
-                bill_state,
-                bill_zip,
-                bill_country,
-                date_submitted,
-                pay_method,
-                payment_code,
-                status,
-                total,
-                cc_type,
-                cc_name,
-                cc_numb,
-                cc_exp,
-                cc_cvv,
-                cc_conf,
-                summary,
-                mf_data,
-                notes
-                )
-                VALUES
-                (
-                ".$accountID.",
-                'Chuck',
-                'Scott',
-                'Gaslight Media',
-                'Vice President',
-                '120 E. Lake St.',
-                '3rd Floor',
-                'Petoskey',
-                'MI',
-                '49770',
-                'US',
-                '".date('Y-m-d')."',
-                ".$this->config['payment_method_numb']['Not Yet Defined'].",
-                'NULL',
-                ".$this->config['submission_status_numb']['CART'].",
-                100,
-                'NULL',
-                'NULL',
-                'NULL',
-                'NULL',
-                'NULL',
-                'NULL',
-                '<P>HTML SUMMARY</P>',
-                'NULL',
-                'Notes go here'
-                )
-        ;";
-        $this->wpdb->query($sql);
-        $requestID = $this->wpdb->insert_id;
-
-        // Registration Request Event
-        $sql = "
-            INSERT INTO ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_event
-                (
-                account,
-                reg_request,
-                event,
-                event_name,
-                event_time,
-                event_datetime,
-                total_charge,
-                mf_data,
-                notes
-                )
-                VALUES
-                (
-                $accountID,
-                $requestID,
-                $regEventID,
-                '$eventName',
-                $timeId,
-                '$eventTime',
-                100,
-                '',
-                ''
-                )
-        ;";
-        $this->wpdb->query($sql);
-        $requestEventID = $this->wpdb->insert_id;
-
-        // Registration Request class
-        $sql = "
-            INSERT INTO ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_class
-                (
-                account,
-                event,
-                event_name,
-                event_time,
-                event_datetime,
-                reg_request,
-                reg_request_event,
-                class,
-                class_name,
-                total_class_charge,
-                mf_data,
-                notes
-                )
-                VALUES
-                (
-                $accountID,
-                $regEventID,
-                '$eventName',
-                $timeId,
-                '$eventTime',
-                $requestID,
-                $requestEventID,
-                0,
-                'Class Name',
-                100,
-                '',
-                ''
-                )
-        ;";
-        $this->wpdb->query($sql);
-        $requestClassID = $this->wpdb->insert_id;
-
-
-        // Registration Request Rate
-        $sql = "
-            INSERT INTO ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_rate
-                (
-                account,
-                event,
-                event_name,
-                event_time,
-                event_datetime,
-                reg_request,
-                reg_request_event,
-                reg_request_class,
-                rate,
-                rate_name,
-                base_rate,
-                per_registrant,
-                registrant_credits,
-                numb_registrants,
-                total_registrant_charges,
-                mf_data,
-                notes
-                )
-                VALUES
-                (
-                $accountID,
-                $regEventID,
-                '$eventName',
-                $timeId,
-                '$eventTime',
-                $requestID,
-                $requestEventID,
-                $requestClassID,
-                0,
-                'Rate Name',
-                100,
-                10,
-                1,
-                1,
-                100,
-                '',
-                ''
-                )
-        ;";
-        $this->wpdb->query($sql);
-        $requestRateID = $this->wpdb->insert_id;
-
-
-        // Registration Request Registrant
-        $sql = "
-            INSERT INTO ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_registrant
-                (
-                account,
-                event,
-                event_name,
-                event_time,
-                event_datetime,
-                reg_request,
-                reg_request_event,
-                reg_request_class,
-                reg_request_rate,
-                reg_request_registrant,
-                fname,
-                lname,
-                mf_data,
-                notes
-                )
-                VALUES
-                (
-                $accountID,
-                $regEventID,
-                '$eventName',
-                $timeId,
-                '$eventTime',
-                $requestID,
-                $requestEventID,
-                $requestClassID,
-                $requestRateID,
-                $accountID,
-                'First',
-                'Last',
-                '',
-                ''
-                )
-        ;";
-        $this->wpdb->query($sql);
-        $requestRegistrantID = $this->wpdb->insert_id;
-
-        return;
-
-    }
-
-    public function removeRegistrationRequestData()
-    {
-        $this->wpdb->query("DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_event;");
-        $this->wpdb->query("DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_class;");
-        $this->wpdb->query("DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_rate;");
-        $this->wpdb->query("DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."account;");
-        $this->wpdb->query("DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request;");
-        $this->wpdb->query("DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_event;");
-        $this->wpdb->query("DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_class;");
-        $this->wpdb->query("DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_rate;");
-        $this->wpdb->query("DELETE FROM ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_request_registrant;");
-
-    }
-
 }
index 0ac0c01..08a8191 100644 (file)
@@ -130,7 +130,9 @@ app.Views.Admin.RegClass = Backbone.View.extend({
         this.listenTo( this.model, 'change', this.render );
         
         // Use the reg rates sent as an attribute to the class to create the rates models
-        this.model.setRates(this.model.attributes.reg_rate);
+        if (this.model.attributes.reg_rate) {        
+            this.model.setRates(this.model.attributes.reg_rate);
+        }
         return this;
     },
 
@@ -179,6 +181,7 @@ app.Views.Admin.RegClass = Backbone.View.extend({
                 myself.$('.class-edit-template').hide();
                 myself.$('.class-update').hide();
                 myself.$('.class-add').hide();
+                myself.$('.class-delete').show();
                 myself.$('.class-edit').show();
                 myself.newClass = false;
             } else {
@@ -197,17 +200,16 @@ app.Views.Admin.RegClass = Backbone.View.extend({
 
     delete: function(){
         console.log('deleteLevel called');
-        if (this.model.attributes.reg_rate) {
-            alert('Please remove all rate entries below before deleting this level.');
-            return false;
-        }
-    
+
         if (glmSubmitRequired) {
             alert('Please complete your other edit first.');
             return false;
         }
 
-        if (!confirm('Are you sure you want to delete this? ( *** need to check for rates *** )')) {
+        if (!confirm(
+                'Are you sure you want to delete this? ' +
+                'Deleting this level will also remove all associated rates!'
+            )) {
             return false;
         }
 
@@ -236,6 +238,7 @@ app.Views.Admin.RegClass = Backbone.View.extend({
         this.$('.class-edit-template').show();
         this.$('.class-update').show();
         this.$('.class-edit').hide();
+        this.$('.class-delete').hide();
         this.$('.class-name').focus();
         glmSubmitRequired += 1;               
     },
@@ -253,6 +256,7 @@ app.Views.Admin.RegClass = Backbone.View.extend({
         this.$('.class-edit-template').hide();
         this.$('.class-update').hide();
         this.$('.class-edit').show();
+        this.$('.class-delete').show();
         glmSubmitRequired -= 1;  
     },
 
@@ -307,6 +311,7 @@ app.Views.Admin.RegClass = Backbone.View.extend({
             this.$('.class-update').hide();
             this.$('.class-edit').show();
             this.$('.class-add').show();
+            this.$('.class-delete').hide();
             this.$('.class-name').focus();
             this.newClass = true;
             glmSubmitRequired += 1;
@@ -395,21 +400,34 @@ app.Views.Admin.RegRate = Backbone.View.extend({
     },
 
     getInputData: function() {
+        
         var input = {
             name:               this.$('.rate-name').val().trim(),
             start_days:         this.$('.rate-start-days').val().trim(),
             end_days:           this.$('.rate-end-days').val().trim(),
-            base_rate:          this.$('.rate-base-rate').val().trim(),
-            per_registrant:     this.$('.rate-per-registrant').val().trim(),
-            registrant_credits: this.$('.rate-registrant-credits').val().trim()
+            base_rate:          this.currency(this.$('.rate-base-rate').val().trim()),
+            per_registrant:     this.currency(this.$('.rate-per-registrant').val().trim()),
+            registrant_credits: Number(this.$('.rate-registrant-credits').val().trim())
         };
         return input;
     },
     
+    currency: function (v) {
+        v = v.trim().replace ( /[^0-9.]/g, '' );
+        if (v == '')  {
+            v = 0;
+        }
+        v = '$' + Number(v).toFixed(2);
+        return v;
+    },
+
     add: function(){
 
         console.log('add called');
         
+        // Get parent for id to send to backend for new rate
+        var parentClass = this.model.get( 'parent' ); 
+
         var formData = this.getInputData();
 
         // Check for required data -- NEED TO MOVE THIS TO getInputData function 
@@ -420,24 +438,23 @@ app.Views.Admin.RegRate = Backbone.View.extend({
 
         this.model.set(formData);
         
-        // Get parent for id to send to backend for new rate
-        var parentClass = this.model.get( 'parent' ); 
-
         // Try to save the registration rate
         var newID = false;
         myself = this;
         formData.wait = true;
         formData.option = 'add';
+        formData.reg_event = parentClass.attributes.reg_event;
                 
         this.model.save(
             formData
-        ).success(function(data){       
+        ).success(function(data){    
             if (data > 0) {
                 console.log('AJAX Rate Save Successful: ID = '+data);
                 myself.model.set({id: data});
                 myself.$('.rate-display-template').show();
                 myself.$('.rate-edit-template').hide();
                 myself.$('.rate-update').hide();
+                myself.$('.rate-delete').show();
                 myself.$('.rate-add').hide();
                 myself.newRate = false;
             } else {
@@ -460,14 +477,20 @@ app.Views.Admin.RegRate = Backbone.View.extend({
             return false;
         }
         
+        if (!confirm('Are you sure you want to delete this?')) {
+            return false;
+        }
+
         // Remove rate here
         var x = this.model.get('id');
+        
         this.model.destroy({data: { 
             id: x,
             option: 'delete'
         }});
-
+        
         this.remove();
+        
     },
     
     edit: function() {
@@ -478,6 +501,8 @@ app.Views.Admin.RegRate = Backbone.View.extend({
         console.log('edit called');
         this.$('.rate-display-template').hide();
         this.$('.rate-edit-template').show();
+        this.$('.rate-update').show();
+        this.$('.rate-delete').hide();
         this.$('.rate-name').focus();
         glmSubmitRequired += 1;
         
@@ -498,6 +523,7 @@ app.Views.Admin.RegRate = Backbone.View.extend({
         }
         this.$('.rate-display-template').show();
         this.$('.rate-edit-template').hide();
+        this.$('.rate-delete').show();
         glmSubmitRequired -= 1;       
 
     },
@@ -519,6 +545,7 @@ app.Views.Admin.RegRate = Backbone.View.extend({
             this.$('.rate-edit-template').show();
             this.$('.rate-update').hide();
             this.$('.rate-add').show();
+            this.$('.rate-delete').hide();
             this.$('.rate-name').focus();
             this.newRate = true;
             glmSubmitRequired += 1;
index b7d2247..13f3deb 100644 (file)
@@ -11,7 +11,9 @@ app.Views.Admin.RegClass = Backbone.View.extend({
         this.listenTo( this.model, 'change', this.render );
         
         // Use the reg rates sent as an attribute to the class to create the rates models
-        this.model.setRates(this.model.attributes.reg_rate);
+        if (this.model.attributes.reg_rate) {        
+            this.model.setRates(this.model.attributes.reg_rate);
+        }
         return this;
     },
 
@@ -60,6 +62,7 @@ app.Views.Admin.RegClass = Backbone.View.extend({
                 myself.$('.class-edit-template').hide();
                 myself.$('.class-update').hide();
                 myself.$('.class-add').hide();
+                myself.$('.class-delete').show();
                 myself.$('.class-edit').show();
                 myself.newClass = false;
             } else {
@@ -78,17 +81,16 @@ app.Views.Admin.RegClass = Backbone.View.extend({
 
     delete: function(){
         console.log('deleteLevel called');
-        if (this.model.attributes.reg_rate) {
-            alert('Please remove all rate entries below before deleting this level.');
-            return false;
-        }
-    
+
         if (glmSubmitRequired) {
             alert('Please complete your other edit first.');
             return false;
         }
 
-        if (!confirm('Are you sure you want to delete this? ( *** need to check for rates *** )')) {
+        if (!confirm(
+                'Are you sure you want to delete this? ' +
+                'Deleting this level will also remove all associated rates!'
+            )) {
             return false;
         }
 
@@ -117,6 +119,7 @@ app.Views.Admin.RegClass = Backbone.View.extend({
         this.$('.class-edit-template').show();
         this.$('.class-update').show();
         this.$('.class-edit').hide();
+        this.$('.class-delete').hide();
         this.$('.class-name').focus();
         glmSubmitRequired += 1;               
     },
@@ -134,6 +137,7 @@ app.Views.Admin.RegClass = Backbone.View.extend({
         this.$('.class-edit-template').hide();
         this.$('.class-update').hide();
         this.$('.class-edit').show();
+        this.$('.class-delete').show();
         glmSubmitRequired -= 1;  
     },
 
@@ -188,6 +192,7 @@ app.Views.Admin.RegClass = Backbone.View.extend({
             this.$('.class-update').hide();
             this.$('.class-edit').show();
             this.$('.class-add').show();
+            this.$('.class-delete').hide();
             this.$('.class-name').focus();
             this.newClass = true;
             glmSubmitRequired += 1;
index bf9f7a0..6efa350 100644 (file)
@@ -21,21 +21,34 @@ app.Views.Admin.RegRate = Backbone.View.extend({
     },
 
     getInputData: function() {
+        
         var input = {
             name:               this.$('.rate-name').val().trim(),
             start_days:         this.$('.rate-start-days').val().trim(),
             end_days:           this.$('.rate-end-days').val().trim(),
-            base_rate:          this.$('.rate-base-rate').val().trim(),
-            per_registrant:     this.$('.rate-per-registrant').val().trim(),
-            registrant_credits: this.$('.rate-registrant-credits').val().trim()
+            base_rate:          this.currency(this.$('.rate-base-rate').val().trim()),
+            per_registrant:     this.currency(this.$('.rate-per-registrant').val().trim()),
+            registrant_credits: Number(this.$('.rate-registrant-credits').val().trim())
         };
         return input;
     },
     
+    currency: function (v) {
+        v = v.trim().replace ( /[^0-9.]/g, '' );
+        if (v == '')  {
+            v = 0;
+        }
+        v = '$' + Number(v).toFixed(2);
+        return v;
+    },
+
     add: function(){
 
         console.log('add called');
         
+        // Get parent for id to send to backend for new rate
+        var parentClass = this.model.get( 'parent' ); 
+
         var formData = this.getInputData();
 
         // Check for required data -- NEED TO MOVE THIS TO getInputData function 
@@ -46,24 +59,23 @@ app.Views.Admin.RegRate = Backbone.View.extend({
 
         this.model.set(formData);
         
-        // Get parent for id to send to backend for new rate
-        var parentClass = this.model.get( 'parent' ); 
-
         // Try to save the registration rate
         var newID = false;
         myself = this;
         formData.wait = true;
         formData.option = 'add';
+        formData.reg_event = parentClass.attributes.reg_event;
                 
         this.model.save(
             formData
-        ).success(function(data){       
+        ).success(function(data){    
             if (data > 0) {
                 console.log('AJAX Rate Save Successful: ID = '+data);
                 myself.model.set({id: data});
                 myself.$('.rate-display-template').show();
                 myself.$('.rate-edit-template').hide();
                 myself.$('.rate-update').hide();
+                myself.$('.rate-delete').show();
                 myself.$('.rate-add').hide();
                 myself.newRate = false;
             } else {
@@ -86,14 +98,20 @@ app.Views.Admin.RegRate = Backbone.View.extend({
             return false;
         }
         
+        if (!confirm('Are you sure you want to delete this?')) {
+            return false;
+        }
+
         // Remove rate here
         var x = this.model.get('id');
+        
         this.model.destroy({data: { 
             id: x,
             option: 'delete'
         }});
-
+        
         this.remove();
+        
     },
     
     edit: function() {
@@ -104,6 +122,8 @@ app.Views.Admin.RegRate = Backbone.View.extend({
         console.log('edit called');
         this.$('.rate-display-template').hide();
         this.$('.rate-edit-template').show();
+        this.$('.rate-update').show();
+        this.$('.rate-delete').hide();
         this.$('.rate-name').focus();
         glmSubmitRequired += 1;
         
@@ -124,6 +144,7 @@ app.Views.Admin.RegRate = Backbone.View.extend({
         }
         this.$('.rate-display-template').show();
         this.$('.rate-edit-template').hide();
+        this.$('.rate-delete').show();
         glmSubmitRequired -= 1;       
 
     },
@@ -145,6 +166,7 @@ app.Views.Admin.RegRate = Backbone.View.extend({
             this.$('.rate-edit-template').show();
             this.$('.rate-update').hide();
             this.$('.rate-add').show();
+            this.$('.rate-delete').hide();
             this.$('.rate-name').focus();
             this.newRate = true;
             glmSubmitRequired += 1;
index 0a2b06a..bc9b813 100644 (file)
@@ -70,7 +70,7 @@ class GlmMembersAdmin_ajax_regAdmin
      */
     public function modelAction( $actionData = false )
     {
+
         // Get Backbone collection we're talking with
         $collection = filter_var( $_REQUEST['collection'], FILTER_SANITIZE_STRING );
    
@@ -96,9 +96,6 @@ class GlmMembersAdmin_ajax_regAdmin
             trigger_error ( "ERROR: The specified model file doesn't exist. ($modelName)", E_USER_ERROR);
             wp_die();
         }
-        
-        ini_set('display_errors', 1);
-        error_reporting(E_ALL);
        
         // Load the model file
         require_once $modelName;
@@ -111,7 +108,7 @@ class GlmMembersAdmin_ajax_regAdmin
         
         // Instantiate the model and ask it to perform the work
         $model = new $className($this->wpdb, $this->config);
-        
+
         $results = $model->modelAction($modelData);
         
         
index 5a7c43f..9cae7e0 100644 (file)
@@ -89,7 +89,7 @@ class GlmMembersAdmin_registrations_ajax_regClasses extends GlmDataRegistrations
             case 'add':
                                 
                 // Make sure we got a parent ID with the data
-                if (isset($modelData['parent']) || (modelData['parent']-0) > 0) {
+                if (isset($modelData['parent']) || ($modelData['parent']-0) > 0) {
                     
                     // Try to insert the class (level) data
                     $res = $this->wpdb->insert(
@@ -157,6 +157,7 @@ class GlmMembersAdmin_registrations_ajax_regClasses extends GlmDataRegistrations
                 
                 $classID = ($modelData['id'] - 0);
                 if ($classID > 0) {
+                    $this->wpdb->delete( GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_rate', array( 'reg_class' => $classID ), array( '%d' ) );
                     $this->wpdb->delete( $this->table, array( 'id' => $classID ), array( '%d' ) );
                 }
                 
index b8fd90b..f1932ff 100644 (file)
@@ -81,9 +81,31 @@ class GlmMembersAdmin_registrations_ajax_regRates extends GlmDataRegistrationsRe
     public function modelAction($modelData)
     {
 
+        $ratesFields = array(
+            'reg_event'             => $modelData['reg_event'],
+            'reg_class'             => $modelData['reg_class'],
+            'name'                  => $modelData['name'],
+            'start_days'            => $modelData['start_days'],
+            'end_days'              => $modelData['end_days'],
+            'base_rate'             => str_replace('$', '', $modelData['base_rate']),
+            'per_registrant'        => str_replace('$', '', $modelData['per_registrant']),
+            'registrant_credits'    => $modelData['registrant_credits']
+        );
+
+        $ratesFieldTypes = array(
+            '%d',
+            '%d',
+            '%s',
+            '%d',
+            '%d',
+            '%f',
+            '%f',
+            '%d'
+        );
+
         // Perform specified action
         switch ($modelData['option']) {
-            
+
             case 'add':
                                 
                 // Make sure we got a parent ID with the data
@@ -92,20 +114,8 @@ class GlmMembersAdmin_registrations_ajax_regRates extends GlmDataRegistrationsRe
                     // Try to insert the rate (level) data
                     $res = $this->wpdb->insert(
                         $this->table,
-                        array(
-                            'reg_event' => $modelData['reg_event'],
-                            'reg_class' => $modelData['reg_class'],
-                            'name'  => $modelData['name'],
-                            'start_days' => $modelData['start_days'],
-                            'end_days' => $modelData['end_days']
-                        ),
-                        array(
-                            '%d',
-                            '%d',
-                            '%s',
-                            '%d',
-                            '%d'
-                        )
+                        $ratesFields,
+                        $ratesFieldTypes
                     );
                     
                     if ($res != 1) {
@@ -139,17 +149,9 @@ class GlmMembersAdmin_registrations_ajax_regRates extends GlmDataRegistrationsRe
                     // Try to update the class (level) data
                     $this->wpdb->update(
                         $this->table,
-                        array(
-                            'name'  => $modelData['name'],
-                            'start_days' => $modelData['start_days'],
-                            'end_days' => $modelData['end_days']
-                        ),
+                        $ratesFields,
                         array('id' => $rateID),
-                        array(
-                            '%s',
-                            '%d',
-                            '%d'
-                        ),
+                        $ratesFieldTypes,
                         array( '%d' )
                     );
                     
index 371adf6..a64774a 100644 (file)
@@ -179,7 +179,6 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
                 // Separate Event, Classes, and Times and send those as separate JSONs
                 $regClassesJSON = json_encode($regEvent['reg_class']);
                 $regTimesJSON = json_encode($regEvent['reg_time']);
-// echo "<pre>".print_r($regEvent['reg_class'],1)."</pre>";
                 
                 // Get rid of class and time arrays so we just have the event data
                 unset($regEvent['reg_class']);
index ada99c0..fe18985 100644 (file)
@@ -1,7 +1,23 @@
 <?php
- require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegEvent.php';
+/**
+ * Gaslight Media Members Database
+ * Admin Registrations Cart 
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  cart.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
 
- class GlmMembersFront_registrations_cart extends GlmDataRegistrationsRegEvent {
+// Load Registrations Support
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/regCartSupport.php';
+
+class GlmMembersFront_registrations_cart extends GlmRegCartSupport
+{
     /**
     * WordPress Database Object
     *
      *
      * @return array Array containing status, suggested view, and any data
      */
+    public function __construct ($wpdb, $config)
+    {
+        
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+        
+        // Save plugin configuration object
+        $this->config = $config;
+        
+        /*
+         * Run constructor for the REgistrations data class
+         *
+         * Note, the third parameter is a flag that indicates to the Contacts
+         * data class that it should flag a group of fields as 'view_only'.
+         */
+        parent::__construct(false, false, true);
+        
+    }
+    
 
     public function modelAction($actionData = false)
     {
 
+        $cartID = false;
+        $haveCart = false;
+        
+        
         // Get any provided option
         if (isset($_REQUEST['option'])) {
             $option = $_REQUEST['option'];
             }
         }
 
+        // Get cart ID if supplied
+        if (isset($_REQUEST['cart'])) {
+            
+            // Make sure it's numeric
+            $cartID = ($_REQUEST['cart'] - 0);
+            
+            if ($cartID <= 0) {
+                $cartID = false;
+            } else {
+                $cart = $this->getRegistrationCart($cartID);
+                if ($cart) {
+                    $haveCart = true;
+                }
+            }
+        }
+        
+        
+        
         $view = 'cart';
 
         switch ( $option ) {
+            
+            
+            case 'showCart':
+            default:
+                
+                    
+                
+                break;
 
         }
 
         );
 
     }
- }
+}
index a417836..b21088d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
  require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegEvent.php';
-
  class GlmMembersFront_registrations_registration extends GlmDataRegistrationsRegEvent {
     /**
     * WordPress Database Object
 
         switch ( $option ) {
         default:
+            
             // Get the RegEvent entry
             $regEvent = $this->getEntry( $eventRegID );
             //echo '<pre>$regEvent: ' . print_r( $regEvent, true ) . '</pre>';
index 73c6fef..fae1abe 100644 (file)
@@ -51,6 +51,7 @@ NEED TO ADD TESTS FOR CHANGES IN INPUT<br>
                 <th {if $regEvent.fieldRequired.notify_email}class="glm-required-nowrap-left-align"{else}class="glm-nowrap-left-align"{/if}>Notify E-Mail Address</th>
                 <td {if $regEvent.fieldFail.notify_email}class="glm-form-bad-input" data-tabid="glm-notify_email"{/if}>
                     <input type="text" name="notify_email" value="{$regEvent.fieldData.notify_email}" class="glm-form-text-input-medium">
+                    <br>You may enter up to 5 E-Mail addresses separated by commas. Administrative notifications will go out to all of those addresses. 
                 {if $regEvent.fieldFail.notify_email}<p>{$regEvent.fieldFail.notify_email}</p>{/if}<br>
                 </td>
             </tr>
@@ -153,19 +154,33 @@ NEED TO ADD TESTS FOR CHANGES IN INPUT<br>
             <tr>
                 <th {if $regEvent.fieldRequired.descr}class="glm-required-nowrap-left-align"{else}class="glm-nowrap-left-align"{/if}>Description (optional)</th>
                 <td {if $regEvent.fieldFail.descr}class="glm-form-bad-input" data-tabid="glm-descr"{/if}>
-                    <textarea name="descr" class="glm-form-textarea">{$regEvent.fieldData.descr}</textarea>
-                {if $regEvent.fieldFail.descr}
-                    <p>{$regEvent.fieldFail.descr}</p>
-                {/if}<br>
+                    {php}
+                        wp_editor('{$regEvent.fieldData.descr|escape:quotes}', 'glm_descr', array(
+                            'media_buttons' => false,
+                            // 'quicktags' => false,
+                            // 'wpautop' => false,  NOTE: Dont use. Problem when numerous spaces before text.
+                            'textarea_name' => 'descr',
+                            'editor_height' => 200,     // Height in px, overrides editor_rows
+                                // 'textarea_rows' => 8
+                        ));
+                    {/php}
+                    {if $regEvent.fieldFail.descr}<p>{$regEvent.fieldFail.descr}</p>{/if}
                 </td>
             </tr>
             <tr>
                 <th {if $regEvent.fieldRequired.terms}class="glm-required-nowrap-left-align"{else}class="glm-nowrap-left-align"{/if}>Terms and Conditions for Registration</th>
                 <td {if $regEvent.fieldFail.terms}class="glm-form-bad-input" data-tabid="glm-terms"{/if}>
-                    <textarea name="terms" class="glm-form-textarea">{$regEvent.fieldData.terms}</textarea>
-                {if $regEvent.fieldFail.terms}
-                    <p>{$regEvent.fieldFail.terms}</p>
-                {/if}<br>
+                    {php}
+                        wp_editor('{$regEvent.fieldData.terms|escape:quotes}', 'glm_terms', array(
+                            'media_buttons' => false,
+                            // 'quicktags' => false,
+                            // 'wpautop' => false,  NOTE: Dont use. Problem when numerous spaces before text.
+                            'textarea_name' => 'terms',
+                            'editor_height' => 200,     // Height in px, overrides editor_rows
+                                // 'textarea_rows' => 8
+                        ));
+                    {/php}
+                    {if $regEvent.fieldFail.terms}<p>{$regEvent.fieldFail.terms}</p>{/if}
                 </td>
             </tr>
             <tr>
index f5430d9..a1fa14a 100644 (file)
                     </div>
                 </div>
             </div>
-            <div class="rate-edit-template" style="display: none;">
+            <div class="rate-edit-template" style="display: none; border: 1px solid black; padding: 1em; margin: 1em;">
                 <div class="glm-rate-header">
                     <div class="glm-right">
                         <a class="rate-update button glm-button-small-highlighted">Update</a>
                         <a class="rate-add button glm-button-small-highlighted" style="display: none;">Add</a>
                         <a class="rate-delete button button-secondary glm-button-small">Delete</a>
                     </div>
+                    <h3>Rate Days and Costs</h3>
                     <div class="glm-rate-label" style="padding-bottom: .3em;">
                         <table class="glm-admin-table">
                             <tr>
                             <tr>
                                 <th style="white-space: nowrap;">Cost:</th>
                                 <td>
-                                    Base <input class="rate-base-rate glm-form-text-input-veryshort" type="text" name="base_rate_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (base_rate) { %><%- base_rate %><% } %>">
-                                    Per-Registrant <input class="rate-per-registrant glm-form-text-input-veryshort" type="text" name="per_registrant_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (per_registrant) { %><%- per_registrant %><% } %>">
-                                    Registrant Credits <input class="rate-registrant-credits glm-form-text-input-veryshort" type="text" name="registrant_credits_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (registrant_credits) { %><%- registrant_credits %><% } %>">
+                                    <span class="glm-nowrap">Base <input class="rate-base-rate glm-form-text-input-veryshort" type="text" name="base_rate_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (base_rate) { %><%- base_rate %><% } %>"></span>
+                                    <span class="glm-nowrap">Per-Registrant <input class="rate-per-registrant glm-form-text-input-veryshort" type="text" name="per_registrant_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (per_registrant) { %><%- per_registrant %><% } %>"></span>
+                                    <span class="glm-nowrap">Registrant Credits <input class="rate-registrant-credits glm-form-text-input-veryshort" type="text" name="registrant_credits_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (registrant_credits) { %><%- registrant_credits %><% } %>"></span>
                                     <br>
                                     
                                 </td>
 
     <div class="glm-reg-event-list" id="regApp">
     </div>
-
-    <div style="border: 1px black solid; padding: .3em; background-color: white; margin-top: 4em;">
-        <h3>Things that need to be fixed</h3>
-        <ul>
-            <li>* Fields do not get focus when adding or editing.</li>
-            <li>* Need to complete edit on new entry before it's possible to delete.</li>
-        </ul>
-    </div>
-
     
     {* Bootstrap the models needed on page load *}
     {* Need to have RegEvent model created *}
                     return true;
                 }
             });
-
+            
         });
     </script>