Update registrant account
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 9 Oct 2017 20:48:51 +0000 (16:48 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 9 Oct 2017 20:48:51 +0000 (16:48 -0400)
Only if the account with the registrant is not validated.

css/front.css
js/frontRegApp.js
js/models/front/account.js
js/views/front/regRequestRegistrant.js
misc/documentation/AccountRestrictionsDescription.txt
models/admin/ajax/account.php
models/admin/ajax/regFront/registrant.php
views/front/registrations/registration.html

index 347f04c..213ce44 100644 (file)
@@ -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;
+}
index 0a4faf4..2cd4511 100644 (file)
@@ -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(){
index 4603a2f..f9827a1 100644 (file)
@@ -10,6 +10,7 @@ app.Models.Front.Account = Backbone.Model.extend({
         fname: '',
         lname: '',
         email: '',
+        validated: false,
     },
 
     url: ajaxUrl+'&glm_action=regFront&collection=account',
index 7719418..4276501 100644 (file)
@@ -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(){
index e300824..f14784c 100644 (file)
@@ -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.
index 23742fc..6fa45a3 100644 (file)
@@ -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;
index 4ef9668..11d6f5f 100644 (file)
@@ -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':
index d409d3d..3dfbe00 100644 (file)
     <% } else { %>
         <span class="glm-registrant-edit"><%= fname %> <%= lname %> <%= email %></span>
         <div class="reg-edit-form">
+            {/literal}{if $regEvent.time_specific.value}
+                <div style="float: right; width: 48%;">
+                    <div id="eventCalendar" style="width: 90%;"></div>
+                </div>
+            {/if}{literal}
+            {/literal}{if $regEvent.time_specific.value}
+                <div style="width: 48%;">
+                {else}
+                <div>
+            {/if}{literal}
             <div>
                 {/literal}{$terms.reg_term_contact_information}{literal}
             </div>
                 <input class="reg_zip" placeholder="Zip/Postal Code" value="<%- zip %>">
                 <input class="reg_country" placeholder="Country" value="<%- country %>">
             </div>
+            {/literal}{if $regEvent.time_specific.value}
+                <div>
+                    Selected Time: <span id="reg-select-time-display"></span>
+                    <input type="hidden" id="reg-select-time">
+                </div>
+            {/if}{literal}
+            <div>
+                <input class="update-registrant button tiny" value="Update {/literal}{$terms.reg_term_attendee_cap}{literal}" type="submit">
+                <a class="update-registrant-cancel">Cancel</a>
+            </div>
         </div>
     <% } %>
 </script>