From dd857e6e487abd724a14bddae474ef730544be41 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 9 Oct 2017 16:48:51 -0400 Subject: [PATCH] Update registrant account Only if the account with the registrant is not validated. --- css/front.css | 11 +++ js/frontRegApp.js | 36 +++++++- js/models/front/account.js | 1 + js/views/front/regRequestRegistrant.js | 35 +++++++- .../AccountRestrictionsDescription.txt | 29 +++--- models/admin/ajax/account.php | 11 +-- models/admin/ajax/regFront/registrant.php | 88 ++++++++++++++++++- views/front/registrations/registration.html | 20 +++++ 8 files changed, 203 insertions(+), 28 deletions(-) diff --git a/css/front.css b/css/front.css index 347f04c..213ce44 100644 --- a/css/front.css +++ b/css/front.css @@ -224,6 +224,14 @@ div.glm-reg-register input.error { } .reg-edit-form { display: none; + background-color: white; + border: 1px solid black; + padding: 2rem; + position: absolute; + left: 1rem; + top: 0; + width: 60rem; + z-index: 999; } .reg-edit-form .reg_fname, .reg-edit-form .reg_lname, @@ -240,3 +248,6 @@ div.glm-reg-register input.error { .reg-edit-form .reg_email { width: 96%; } +.glm-registrant-edit { + cursor: pointer; +} diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 0a4faf4..2cd4511 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -10,6 +10,7 @@ app.Models.Front.Account = Backbone.Model.extend({ fname: '', lname: '', email: '', + validated: false, }, url: ajaxUrl+'&glm_action=regFront&collection=account', @@ -940,12 +941,43 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ events: { 'click .glm-reg-level-registrant-delete': 'deleteOne', 'click .glm-registrant-edit': 'editRegistrant', + 'click .update-registrant-cancel': 'cancelEdit', + 'click .update-registrant': 'update', + }, + + update: function(){ + console.log( 'updating model' ); + // Validate the model + // Have to require reg_time if app.timeSpecific is true + // Get the form values and update the model. + this.model.set({ + option: 'update', + fname: this.$('.reg_fname').val().trim(), + lname: this.$('.reg_lname').val().trim(), + addr1: this.$('.reg_addr1').val().trim(), + addr2: this.$('.reg_addr2').val().trim(), + city: this.$('.reg_city').val().trim(), + state: this.$('.reg_state').val().trim(), + zip: this.$('.reg_zip').val().trim(), + country: this.$('.reg_country').val().trim(), + reg_time: this.$('#reg-select-time').val().trim(), + }); + console.log( 'model id' ); + console.log( this.model.get( 'id' ) ); + this.model.save(); + + }, + + cancelEdit: function(){ + console.log( 'cancel edit' ); + this.$('.reg-edit-form').hide(); }, editRegistrant: function(){ - console.log( 'Edit called' ); - console.log( this.model ); this.$('.reg-edit-form').show(); + if ( app.timeSpecific === true ) { + app.initFullCalendar(); + } }, render: function(){ diff --git a/js/models/front/account.js b/js/models/front/account.js index 4603a2f..f9827a1 100644 --- a/js/models/front/account.js +++ b/js/models/front/account.js @@ -10,6 +10,7 @@ app.Models.Front.Account = Backbone.Model.extend({ fname: '', lname: '', email: '', + validated: false, }, url: ajaxUrl+'&glm_action=regFront&collection=account', diff --git a/js/views/front/regRequestRegistrant.js b/js/views/front/regRequestRegistrant.js index 7719418..4276501 100644 --- a/js/views/front/regRequestRegistrant.js +++ b/js/views/front/regRequestRegistrant.js @@ -13,12 +13,43 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ events: { 'click .glm-reg-level-registrant-delete': 'deleteOne', 'click .glm-registrant-edit': 'editRegistrant', + 'click .update-registrant-cancel': 'cancelEdit', + 'click .update-registrant': 'update', + }, + + update: function(){ + console.log( 'updating model' ); + // Validate the model + // Have to require reg_time if app.timeSpecific is true + // Get the form values and update the model. + this.model.set({ + option: 'update', + fname: this.$('.reg_fname').val().trim(), + lname: this.$('.reg_lname').val().trim(), + addr1: this.$('.reg_addr1').val().trim(), + addr2: this.$('.reg_addr2').val().trim(), + city: this.$('.reg_city').val().trim(), + state: this.$('.reg_state').val().trim(), + zip: this.$('.reg_zip').val().trim(), + country: this.$('.reg_country').val().trim(), + reg_time: this.$('#reg-select-time').val().trim(), + }); + console.log( 'model id' ); + console.log( this.model.get( 'id' ) ); + this.model.save(); + + }, + + cancelEdit: function(){ + console.log( 'cancel edit' ); + this.$('.reg-edit-form').hide(); }, editRegistrant: function(){ - console.log( 'Edit called' ); - console.log( this.model ); this.$('.reg-edit-form').show(); + if ( app.timeSpecific === true ) { + app.initFullCalendar(); + } }, render: function(){ diff --git a/misc/documentation/AccountRestrictionsDescription.txt b/misc/documentation/AccountRestrictionsDescription.txt index e300824..f14784c 100644 --- a/misc/documentation/AccountRestrictionsDescription.txt +++ b/misc/documentation/AccountRestrictionsDescription.txt @@ -6,8 +6,8 @@ Premise: * Accounts are used to store information for people who may enter a registration and/or be registered for an event. * Account data must be secured so only authorized people can obtain any information on an account other than account name. * A person trying to register someone else who does not already have an "account" should be allowed to enter their information. -* An account may or may not include an E-Mail address. -* Accounts without E-Mail addresses may be used to register minors (or similar) where the account can only be accessed by the person who created the account. +* An account may or may not include an E-Mail address. +* Accounts without E-Mail addresses may be used to register minors (or similar) where the account can only be accessed by the person who created the account. * If it does include an E-Mail address the account can be validated by the owner of that E-Mail address. * Once an account has been validated, nobody else may access any of the information in that account other than first and last name. * An account that has not be validated may only be accessed and edited by the person who first entered that account until it is validated. @@ -18,46 +18,41 @@ Processes: Create account directly using "Register" button. * This REQUIRES an E-Mail address and must be validated for the person to access anything under that account again. * Person who created an account directly may continue to enter registrations as long as the session exists. After that, the account must be validated for access. - + Add a registrant - + If an E-Mail address is entered when adding a registrant... If there's already an account matching the E-Mail address and it has been validated... * The account ID, E-Mail address, and name are provided for display but there is no other access to the account. - + If there's no matching account for that E-Mail address... - * An account is created with "registered_by" field containing the account ID of the person submitting the regsitration. + * An account is created with "registered_by" field containing the account ID of the person submitting the registration. * An E-Mail is sent to the E-Mail address to request validation. * The person submitting this registrant can access and update the account until it's validated. - + If no E-Mail address is provided (possibly registering a minor)... * The account is created anyway with "registered_by" field containing the account ID of the person submitting the registration. * No E-Mail is sent * The person submitting this registrant can access and update the account. * An E-mail may be entered into this account at a later time so it can be validated. - + Register an existing account for an event by E-Mail address If account has not been validated and the account of the person submitting the registration matches the "registered_by" field of the account... * The full account information may be displayed and/or edited and updated - + If the account has been validated or the account of the person submitting the registration DOES NOT match the "registered_by" field of the account... * Only the E_Mail and name may be displayed * The account may not be edited / updated - + Validating an account - When an account with an E-Mail address is created, or an E-Mail address is added to an existing account... * An E-Mail is sent to the E-Mail address with a validation code - + So... * Until an account is validated, only the person creating that account can see or modify the information * Accounts without an E-Mail address may be used for minors or people without an E-Mail account - * Once an account is validated, only the E-Mail address holder may access it. - - - - - + * Once an account is validated, only the E-Mail address holder may access it. diff --git a/models/admin/ajax/account.php b/models/admin/ajax/account.php index 23742fc..6fa45a3 100644 --- a/models/admin/ajax/account.php +++ b/models/admin/ajax/account.php @@ -226,7 +226,7 @@ class GlmMembersAdmin_ajax_account extends GlmDataRegistrationsAccount if ( $email = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL ) ) { $accountData = $this->wpdb->get_row( $this->wpdb->prepare( - "SELECT id,fname,lname + "SELECT id,fname,lname,validated FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "account WHERE email = %s", $email @@ -234,28 +234,29 @@ class GlmMembersAdmin_ajax_account extends GlmDataRegistrationsAccount ARRAY_A ); $accountId = $accountData['id']; - $fname = $accountData['fname']; - $lname = $accountData['lname']; if ( $accountId ) { $return = array( 'valid' => true, 'validEmail' => true, 'id' => (int)$accountId, 'email' => $email, - 'fname' => $fname, - 'lname' => $lname, + 'fname' => $accountData['fname'], + 'lname' => $accountData['lname'], + 'validated' => $accountData['validated'], ); } else { $return = array( 'valid' => false, 'validEmail' => true, 'email' => $email, + 'validated' => false, ); } } else { $return = array( 'valid' => false, 'validEmail' => false, + 'validated' => false, ); } break; diff --git a/models/admin/ajax/regFront/registrant.php b/models/admin/ajax/regFront/registrant.php index 4ef9668..11d6f5f 100644 --- a/models/admin/ajax/regFront/registrant.php +++ b/models/admin/ajax/regFront/registrant.php @@ -283,6 +283,7 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations // Here validated would be false. // Because it is new account. } + $validated = false; $validated = $this->wpdb->get_var( $this->wpdb->prepare( "SELECT validated @@ -342,7 +343,7 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations 'reg_event' => $modelData['reg_event'], 'event_name' => $modelData['event_name'], 'reg_time' => $modelData['reg_time'], - 'event_datetime' => $modelData['event_datetime'], + // 'event_datetime' => $modelData['event_datetime'], 'reg_request' => $modelData['reg_request'], 'reg_request_event' => $regRequestEventId, 'reg_request_class' => $regRequestClassId, @@ -355,7 +356,7 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations '%d', // reg_event '%s', // event_name '%s', // reg_time - '%s', // event_datetime + // '%s', // event_datetime '%d', // reg_request '%d', // reg_request_event '%d', // reg_request_class @@ -389,6 +390,89 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations break; case 'update': + $validated = false; + if ( $accountId = filter_var( $modelData['account'], FILTER_VALIDATE_INT ) ) { + $validated = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT validated + FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "account + WHERE id = %d", + $accountId + ) + ); + // If not validated go ahead and update the account data + if ( !$validated ) { + $accountData = array( + 'fname' => $modelData['fname'], + 'lname' => $modelData['lname'], + 'addr1' => $modelData['addr1'], + 'addr2' => $modelData['addr2'], + 'city' => $modelData['city'], + 'state' => $modelData['state'], + 'zip' => $modelData['zip'], + 'country' => $modelData['country'], + ); + $accountDataFormat = array( + '%s', // fname + '%s', // lname + '%s', // addr1 + '%s', // addr2 + '%s', // city + '%s', // state + '%s', // zip + '%s', // country + ); + $this->wpdb->update( + GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'account', + $accountData, + array( 'id' => $accountId ), + $accountDataFormat, + array( '%d' ) + ); + } + + } + if ( $regRequestRegistrantId = filter_var( $modelData['id'], FILTER_VALIDATE_INT ) ) { + // Check the account to see what's changed + // Check for a new reg_time + $data = array( + 'account' => $modelData['account'], + 'reg_event' => $modelData['reg_event'], + 'event_name' => $modelData['event_name'], + 'reg_time' => $modelData['reg_time'], + // 'event_datetime' => $modelData['event_datetime'], + 'reg_request' => $modelData['reg_request'], + 'reg_request_event' => $modelData['reg_request_event'], + 'reg_request_class' => $modelData['reg_request_class'], + 'reg_request_rate' => $modelData['reg_request_rate'], + 'fname' => $modelData['fname'], + 'lname' => $modelData['lname'], + ); + $dataFormat = array( + '%d', // account + '%d', // reg_event + '%s', // event_name + '%s', // reg_time + // '%s', // event_datetime + '%d', // reg_request + '%d', // reg_request_event + '%d', // reg_request_class + '%d', // reg_request_rate + '%s', // fname + '%s', // lname + ); + $this->wpdb->update( + GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_request_registrant', + $data, + array( 'id' => $regRequestRegistrantId ), + $dataFormat, + array( '%d' ) + ); + $regRequstRegistrant = $this->getEntry( $regRequestRegistrantId ); + $regRequestRegistrant['validated'] = $validated; + echo json_encode( $regRequstRegistrant, JSON_NUMERIC_CHECK ); + wp_die(); + } break; case 'delete': diff --git a/views/front/registrations/registration.html b/views/front/registrations/registration.html index d409d3d..3dfbe00 100644 --- a/views/front/registrations/registration.html +++ b/views/front/registrations/registration.html @@ -168,6 +168,16 @@ <% } else { %> <%= fname %> <%= lname %> <%= email %>
+ {/literal}{if $regEvent.time_specific.value} +
+
+
+ {/if}{literal} + {/literal}{if $regEvent.time_specific.value} +
+ {else} +
+ {/if}{literal}
{/literal}{$terms.reg_term_contact_information}{literal}
@@ -191,6 +201,16 @@
+ {/literal}{if $regEvent.time_specific.value} +
+ Selected Time: + +
+ {/if}{literal} +
+ + Cancel +
<% } %> -- 2.17.1