From: Chuck Scott Date: Tue, 26 Sep 2017 12:18:27 +0000 (-0400) Subject: Started updating the front/cart.php to have it grab and validate cart data. X-Git-Tag: v1.0.0^2~385 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=19ee813aced792fefd6a7f2adc6af413d08b8408;p=WP-Plugins%2Fglm-member-db-registrations.git Started updating the front/cart.php to have it grab and validate cart data. 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. --- diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php index 4d5eb30..b014da4 100644 --- a/classes/regCartSupport.php +++ b/classes/regCartSupport.php @@ -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', - '

HTML SUMMARY

', - '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;"); - - } - } diff --git a/js/adminRegApp.js b/js/adminRegApp.js index 0ac0c01..08a8191 100644 --- a/js/adminRegApp.js +++ b/js/adminRegApp.js @@ -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; diff --git a/js/views/admin/regClass.js b/js/views/admin/regClass.js index b7d2247..13f3deb 100644 --- a/js/views/admin/regClass.js +++ b/js/views/admin/regClass.js @@ -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; diff --git a/js/views/admin/regRate.js b/js/views/admin/regRate.js index bf9f7a0..6efa350 100644 --- a/js/views/admin/regRate.js +++ b/js/views/admin/regRate.js @@ -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; diff --git a/models/admin/ajax/regAdmin.php b/models/admin/ajax/regAdmin.php index 0a2b06a..bc9b813 100644 --- a/models/admin/ajax/regAdmin.php +++ b/models/admin/ajax/regAdmin.php @@ -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); diff --git a/models/admin/ajax/regAdmin/regClasses.php b/models/admin/ajax/regAdmin/regClasses.php index 5a7c43f..9cae7e0 100644 --- a/models/admin/ajax/regAdmin/regClasses.php +++ b/models/admin/ajax/regAdmin/regClasses.php @@ -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' ) ); } diff --git a/models/admin/ajax/regAdmin/regRates.php b/models/admin/ajax/regAdmin/regRates.php index b8fd90b..f1932ff 100644 --- a/models/admin/ajax/regAdmin/regRates.php +++ b/models/admin/ajax/regAdmin/regRates.php @@ -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' ) ); diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php index 371adf6..a64774a 100644 --- a/models/admin/registrations/events.php +++ b/models/admin/registrations/events.php @@ -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 "
".print_r($regEvent['reg_class'],1)."
"; // Get rid of class and time arrays so we just have the event data unset($regEvent['reg_class']); diff --git a/models/front/registrations/cart.php b/models/front/registrations/cart.php index ada99c0..fe18985 100644 --- a/models/front/registrations/cart.php +++ b/models/front/registrations/cart.php @@ -1,7 +1,23 @@ + * @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 * @@ -41,10 +57,33 @@ * * @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']; @@ -61,9 +100,35 @@ } } + // 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; } @@ -80,4 +145,4 @@ ); } - } +} diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index a417836..b21088d 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -1,6 +1,6 @@ getEntry( $eventRegID ); //echo '
$regEvent: ' . print_r( $regEvent, true ) . '
'; diff --git a/views/admin/registrations/eventEdit.html b/views/admin/registrations/eventEdit.html index 73c6fef..fae1abe 100644 --- a/views/admin/registrations/eventEdit.html +++ b/views/admin/registrations/eventEdit.html @@ -51,6 +51,7 @@ NEED TO ADD TESTS FOR CHANGES IN INPUT
Notify E-Mail Address +
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}

{$regEvent.fieldFail.notify_email}

{/if}
@@ -153,19 +154,33 @@ NEED TO ADD TESTS FOR CHANGES IN INPUT
Description (optional) - - {if $regEvent.fieldFail.descr} -

{$regEvent.fieldFail.descr}

- {/if}
+ {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}

{$regEvent.fieldFail.descr}

{/if} Terms and Conditions for Registration - - {if $regEvent.fieldFail.terms} -

{$regEvent.fieldFail.terms}

- {/if}
+ {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}

{$regEvent.fieldFail.terms}

{/if} diff --git a/views/admin/registrations/eventEditLevels.html b/views/admin/registrations/eventEditLevels.html index f5430d9..a1fa14a 100644 --- a/views/admin/registrations/eventEditLevels.html +++ b/views/admin/registrations/eventEditLevels.html @@ -79,13 +79,14 @@ -