Adding custom fields into export. And use select for state and country
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 3 Jan 2018 17:04:47 +0000 (12:04 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 3 Jan 2018 17:06:51 +0000 (12:06 -0500)
For the add and edit attend form on front registration page adding
state and country drop down selects.
Adding custom fields into the export.

12 files changed:
classes/data/dataRegRequestRegistrant.php
js/frontRegApp.js
js/views/front/regRequestRegistrant.js
js/views/front/registrantForm.js
models/admin/ajax/account.php
models/admin/ajax/registrantsListExport.php
models/admin/registrations/events.php
models/front/registrations/registration.php
views/admin/ajax/registrantsListExport.html
views/admin/ajax/registrantsListExportCsv.html
views/admin/registrations/eventRegistrants.html
views/front/registrations/registration.html

index d3fdeb2..10d325b 100644 (file)
@@ -359,9 +359,7 @@ class GlmDataRegistrationsRequestRegistrant extends GlmDataAbstract
                 if ( isset( $customData ) && is_array( $customData ) && !empty( $customData ) ) {
                     $fields = $customData['form'];
                     foreach ( $fields as $cField ) {
-                        $custom_data[] = array(
-                            $cField['field_name'] => $cField['stored']
-                        );
+                        $custom_data[$cField['field_name']] = $cField['stored'];
                     }
                     $registrants[$registrantKey]['custom_data'] = $custom_data;
                 }
index b6670e3..2cb20e3 100644 (file)
@@ -859,18 +859,15 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
 
     // render the view
     render: function(){
-        // console.log( 'regReguestRegistrantView.render called' );
-
         this.$el.html( this.template( this.model.toJSON() ) );
         this.$emailInput = this.$('.editEmail');
         this.$('.reg-edit-form').hide();
+        // setup the state and country select
+        this.$('.reg_state').val(this.model.get('state'));
+        this.$('.reg_country').val(this.model.get('country'));
 
         // Call the custom fields ajax
         app.setCustomFieldsForm(this.model.get('reg_event'), this.model.id, '.attendee-cf-' + this.model.id);
-        // console.log('call setCustomFieldsForm' );
-        // if ( this.customFieldFormData ) {
-        //     this.$('.attendee-cf-' + this.model.get('id')).html( this.customFieldFormData );
-        // }
         return this;
     },
 
@@ -1138,6 +1135,12 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
                     // They should not be able to edit the record.
                     this.$('.add_reg_fname').val(account.fname);
                     this.$('.add_reg_lname').val(account.lname);
+                    this.$('.add_reg_addr1').val(account.addr1);
+                    this.$('.add_reg_addr2').val(account.addr2);
+                    this.$('.add_reg_city').val(account.city);
+                    this.$('.add_reg_state').val(account.state);
+                    this.$('.add_reg_zip').val(account.zip);
+                    this.$('.add_reg_country').val(account.country);
 
                     // lock the form
                     // this.lockForm();
index d3dc7d7..f3c6bfb 100644 (file)
@@ -113,18 +113,15 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
 
     // render the view
     render: function(){
-        // console.log( 'regReguestRegistrantView.render called' );
-
         this.$el.html( this.template( this.model.toJSON() ) );
         this.$emailInput = this.$('.editEmail');
         this.$('.reg-edit-form').hide();
+        // setup the state and country select
+        this.$('.reg_state').val(this.model.get('state'));
+        this.$('.reg_country').val(this.model.get('country'));
 
         // Call the custom fields ajax
         app.setCustomFieldsForm(this.model.get('reg_event'), this.model.id, '.attendee-cf-' + this.model.id);
-        // console.log('call setCustomFieldsForm' );
-        // if ( this.customFieldFormData ) {
-        //     this.$('.attendee-cf-' + this.model.get('id')).html( this.customFieldFormData );
-        // }
         return this;
     },
 
index 2b2e115..85c9fb7 100644 (file)
@@ -60,6 +60,12 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
                     // They should not be able to edit the record.
                     this.$('.add_reg_fname').val(account.fname);
                     this.$('.add_reg_lname').val(account.lname);
+                    this.$('.add_reg_addr1').val(account.addr1);
+                    this.$('.add_reg_addr2').val(account.addr2);
+                    this.$('.add_reg_city').val(account.city);
+                    this.$('.add_reg_state').val(account.state);
+                    this.$('.add_reg_zip').val(account.zip);
+                    this.$('.add_reg_country').val(account.country);
 
                     // lock the form
                     // this.lockForm();
index faf80a1..3762262 100644 (file)
@@ -233,7 +233,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,validated
+                        "SELECT id,fname,lname,addr1,addr2,city,state,zip,country,validated
                           FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "account
                          WHERE email = %s",
                         $email
@@ -249,6 +249,12 @@ class GlmMembersAdmin_ajax_account extends GlmDataRegistrationsAccount
                         'email'      => $email,
                         'fname'      => $accountData['fname'],
                         'lname'      => $accountData['lname'],
+                        'addr1'      => $accountData['addr1'],
+                        'addr2'      => $accountData['addr2'],
+                        'city'       => $accountData['city'],
+                        'state'      => $accountData['state'],
+                        'zip'        => $accountData['zip'],
+                        'country'    => $accountData['country'],
                         'validated'  => $accountData['validated'],
                     );
                 } else {
index 7599e07..f969327 100644 (file)
@@ -81,22 +81,23 @@ class GlmMembersAdmin_ajax_registrantsListExport extends GlmDataRegistrationsReq
         // When processing registrant info records, also get primary contact data
         $this->postProcessPrimaryContact = true;
 
-        $where           = ' true ';
-        $categories      = false;
-        $haveRegistrants = false;
-        $list            = false;
-        $success         = false;
-        $filterPending   = false;
-        $filterArchived  = false;
-        $haveFilter      = false;
-        $numbDisplayed   = false;
-        $lastDisplayed   = false;
-        $paging          = true;
-        $prevStart       = false;
-        $nextStart       = false;
-        $start           = 1;
-        $limit           = 20;        // Set to the number of listings per page
-        $namesList       = false;
+        $where              = ' true ';
+        $categories         = false;
+        $haveRegistrants    = false;
+        $list               = false;
+        $success            = false;
+        $filterPending      = false;
+        $filterArchived     = false;
+        $haveFilter         = false;
+        $numbDisplayed      = false;
+        $lastDisplayed      = false;
+        $paging             = true;
+        $prevStart          = false;
+        $nextStart          = false;
+        $start              = 1;
+        $limit              = 20;        // Set to the number of listings per page
+        $namesList          = false;
+        $customFieldHeaders = false;
 
         // Check selected fields
         $select = array(
@@ -114,6 +115,7 @@ class GlmMembersAdmin_ajax_registrantsListExport extends GlmDataRegistrationsReq
             'exportTime'       => $this->checkFlag('exportTime'),
             'exportRate'       => $this->checkFlag('exportRate'),
             'exportStatus'     => $this->checkFlag('exportStatus'),
+            'exportCustom'     => $this->checkFlag('exportCustom'),
         );
 
         // Get registration event ID if supplied
@@ -157,8 +159,23 @@ class GlmMembersAdmin_ajax_registrantsListExport extends GlmDataRegistrationsReq
         $where = implode( ' AND ', $whereParts );
 
         // $list = $this->getList($where, "lname");
-        $listResult = $this->getFullRegistrantsData($regEventID, $where, 1, false);
+        $listResult = $this->getFullRegistrantsData($regEventID, $where, false, false);
         $list = $listResult['list'];
+        $customFieldsPluginActive = apply_filters( 'glm-members-customfields-plugin-active', false );
+        $customFieldHeaders = false;
+        // Go through the $listResult to pull out the custom fields if available and if plugin is on
+        if ( $customFieldsPluginActive && $listResult['list'] ) {
+            $index = 1;
+            foreach ( $list as $attendee ) {
+                if ( $attendee['custom_data'] ) {
+                    if ( $index === 1 ) {
+                        $customFieldHeaders = array_keys( $attendee['custom_data'] );
+                    }
+                }
+                break;
+            }
+        }
+        // echo '<pre>$customFieldHeaders: ' . print_r( $customFieldHeaders, true ) . '</pre>';
         // echo '<pre>$list: ' . print_r( $list, true ) . '</pre>';
         // exit;
 
@@ -177,20 +194,21 @@ class GlmMembersAdmin_ajax_registrantsListExport extends GlmDataRegistrationsReq
 
         // Compile template data
         $templateData = array(
-            'select'          => $select,
-            'haveRegistrants' => $haveRegistrants,
-            'registrants'     => $list,
-            'registrantCount' => $registrantCount,
-            'categories'      => $categories,
-            'haveFilter'      => $haveFilter,
-            'numbDisplayed'   => $numbDisplayed,
-            'lastDisplayed'   => $lastDisplayed,
-            'paging'          => $paging,
-            'prevStart'       => $prevStart,
-            'nextStart'       => $nextStart,
-            'start'           => $start,
-            'limit'           => $limit,
-            'namesList'       => $namesList
+            'select'             => $select,
+            'haveRegistrants'    => $haveRegistrants,
+            'registrants'        => $list,
+            'registrantCount'    => $registrantCount,
+            'categories'         => $categories,
+            'haveFilter'         => $haveFilter,
+            'numbDisplayed'      => $numbDisplayed,
+            'lastDisplayed'      => $lastDisplayed,
+            'paging'             => $paging,
+            'prevStart'          => $prevStart,
+            'nextStart'          => $nextStart,
+            'start'              => $start,
+            'limit'              => $limit,
+            'namesList'          => $namesList,
+            'customFieldHeaders' => $customFieldHeaders,
         );
 
         $view = 'admin/ajax/registrantsListExport.html';
index ef98636..e789738 100644 (file)
@@ -288,23 +288,8 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
                 $listResult = $Registrants->getFullRegistrantsData($regEventID, $where, $start, $limit);
                 // echo '<pre>$listResult: ' . print_r( $listResult['list'], true ) . '</pre>';
 
-                $customFields = false;
-                // Go through the $listResult to pull out the custom fields if available and if plugin is on
-                if ( $customFieldsPluginActive && $listResult['list'] ) {
-                    foreach ( $listResult['list'] as $row ) {
-                        if ( $row['custom_data'] ) {
-                            foreach ( $row['custom_data'] as $cFields ) {
-                                $customFields[] = array_keys( $cFields );
-                            }
-                        }
-                        break;
-                    }
-                }
-                // echo '<pre>$customFields: ' . print_r( $customFields, true ) . '</pre>';
-
-
                 // Get count of registrants listed
-                $registrantCount = $listResult['totalCount'];;
+                $registrantCount = $listResult['totalCount'];
 
                 // If the number of registrants is less than a page, don't do paging
                 if ($registrantCount <= $limit) {
index c552671..d3fe1f7 100644 (file)
             } // - End loop through events.
         }
 
+
         // Compile template data
         $templateData = array(
             'customfieldActive' => apply_filters( 'glm-members-customfields-plugin-active', false ),
             'regUrl'            => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/',
             'loggedIn'          => ( isset( $_SESSION['LoginAccount'] ) ) ? $_SESSION['LoginAccount']: false,
             'assetUrl'          => GLM_MEMBERS_REGISTRATIONS_PLUGIN_ASSETS_URL,
-            'reg_bulletin'      => $misc['reg_bulletin']
+            'reg_bulletin'      => $misc['reg_bulletin'],
+            'states_list'       => $this->config['states'],
+            'country_list'      => $this->config['countries'],
         );
 
         // echo "<pre>".print_r($templateData,1)."</pre>";
index 3235479..b1d7a40 100644 (file)
                     {if $select.exportTime}<th align="left">Date/Time</th>{/if}
                     {if $select.exportRate}<th align="left">Rate</th>{/if}
                     {if $select.exportStatus}<th align="left">Status</th>{/if}
+                    {if $select.exportCustom && $customFieldHeaders}
+                        {foreach $customFieldHeaders as $header}
+                            <th align="left">{$header}</th>
+                        {/foreach}
+                    {/if}
                 </tr>
             </thead>
             <tbody>
                     {if $select.exportTime}<td>{$m.event_time_reformatted}</td>{/if}
                     {if $select.exportRate}<td>{$m.rate_name}</td>{/if}
                     {if $select.exportStatus}<td>{$m.request_status_name}</td>{/if}
+                    {if $select.exportCustom && $customFieldHeaders}
+                        {foreach $m.custom_data as $cData}
+                            <td>{$cData}</td>
+                        {/foreach}
+                    {/if}
 
                 </tr>
         {/foreach}
index 5594ecb..a60ba03 100644 (file)
@@ -12,6 +12,7 @@
 {if $select.exportTime}"Date/Time",{/if}
 {if $select.exportRate}"Rate",{/if}
 {if $select.exportStatus}"Status"{/if}
+{if $select.exportCustom && $customFieldHeaders}{foreach $customFieldHeaders as $header},"{$header}"{/foreach}{/if}
 
 {foreach $registrants as $m}
 {if $select.exportId}"{$m.id}",{/if}
@@ -27,5 +28,6 @@
 {if $select.exportTime}"{$m.event_time_reformatted}",{/if}
 {if $select.exportRate}"{$m.rate_name}",{/if}
 {if $select.exportStatus}"{$m.request_status_name}"{/if}
+{if $select.exportCustom && $customFieldHeaders}{foreach $m.custom_data as $cData},"{$cData}"{/foreach}{/if}
 {/foreach}
 {else}No {$terms.reg_term_attendee_plur_cap} Selected{/if}
index 16000b6..ced4aaa 100644 (file)
                                 <input type="checkbox" name="exportTime" checked> Date/Time <br>
                                 <input type="checkbox" name="exportRate" checked> Rate <br>
                                 <input type="checkbox" name="exportStatus" checked> Status <br>
+                                {if apply_filters('glm-members-customfields-plugin-active', false)}
+                                    <input type="checkbox" name="exportCustom" checked> Custom Fields <br>
+                                {/if}
 
                             </td>
                         </tr>
index 4c23429..81b85fc 100644 (file)
@@ -45,7 +45,7 @@
                             {/if}
 
 
-                        {if $regEvent.locations.name || $regEvent.locations.address}
+                        {if isset( $regEvent.locations ) && ( $regEvent.locations.name || $regEvent.locations.address )}
                             <div class="small-12 columns glm-reg-event-profile-details glm-reg-location glm-reg-has-icon">
                                 <a href="https://maps.google.com/maps?daddr={$regEvent.locations.name|escape}%40{$regEvent.locations.lat},{$regEvent.locations.lon}" target="_blank">{$regEvent.locations.name}</a>
                                 {if $regEvent.locations.address}
@@ -62,7 +62,7 @@
                                 {if $regEvent.contact_email}<div class="small-12 columns glm-reg-event-profile-details glm-reg-contact-email glm-reg-contact-details"> Email: {$regEvent.contact_email}</div>{/if}
                             </div>
                         {/if}
-                        {if $regEvent.locations.lat && $regEvent.locations.lon}
+                        {if isset( $regEvent.locations ) && ( $regEvent.locations.lat && $regEvent.locations.lon )}
                             <div class="small-12 columns glm-reg-event-profile-map-container">
                                 <div id="glm-reg-map-container">
                                     <div id="glm-reg-map" class="glm-reg-map">(map loads here)</div>
                     <h4> Event Description </h4>
                     <div id="glm-reg-event-descr" class="glm-reg-event-descr">
                         {$regEvent.eventDescr}
-                    </div> 
+                    </div>
                     {if $regEvent.eventDescr|count_characters:true > 280}
                         <div data-descr="glm-reg-event-descr" class="glm-reg-read-more small-12 columns">Read More</div>
                     {/if}
                 </div>
-                
+
             {/if}
             {if $regEvent.descr}
                 <div class="small-12 columns glm-reg-event-profile-details glm-reg-event-descr-container">
                     <h4> Registration Details </h4>
                     <div id="glm-reg-descr" class="glm-reg-event-descr">
                         {$regEvent.descr}
-                    </div>   
+                    </div>
                     {if $regEvent.descr|count_characters:true > 280}
                         <div data-descr="glm-reg-descr" class="glm-reg-read-more small-12 columns">Read More</div>
                     {/if}
                 </div>
-                
+
             {/if}
             {if $regEvent.terms}
                 <div class="small-12 columns glm-reg-event-profile-details glm-reg-event-descr-container">
                     <h4> Terms &amp; Condtions </h4>
                     <div id="glm-reg-event-terms" class="glm-reg-event-descr">
                         {$regEvent.terms}
-                    </div> 
+                    </div>
                     {if $regEvent.terms|count_characters:true > 280}
                         <div data-descr="glm-reg-event-terms" class="glm-reg-read-more small-12 columns">Read More </div>
                     {/if}
                 </div>
-                
+
             {/if}
         </div>
         {literal}
                 </div>
                 <div class="row ereg-addr">
                     <div class="columns large-4 small-12 text-right">State</div>
-                    <div class="columns large-8 small-12"><input class="add_reg_state" value="<%- state %>"></div>
+                    <div class="columns large-8 small-12">
+                        <select class="add_reg_state">
+                            <option value=""></option>
+                            {/literal}
+                            {foreach $states_list as $stateAbbr => $stateName}
+                                <option value="{$stateAbbr}">{$stateName}</option>
+                            {/foreach}
+                            {literal}
+                        </select>
+                    </div>
                 </div>
                 <div class="row ereg-addr">
                     <div class="columns large-4 small-12 text-right">Zip/Postal Code</div>
                 </div>
                 <div class="row ereg-addr">
                     <div class="columns large-4 small-12 text-right">Country</div>
-                    <div class="columns large-8 small-12"><input class="add_reg_country" value="<%- country %>"></div>
+                    <div class="columns large-8 small-12">
+                        <select class="add_reg_country">
+                            <option value=""></option>
+                            {/literal}
+                            {foreach $country_list as $countryKey => $countryValue}
+                                <option value="{$countryKey}">{$countryValue}</option>
+                            {/foreach}
+                            {literal}
+                        </select>
+                    </div>
                 </div>
                 {/literal}{if $regEvent.time_specific.value}
                     <input type="hidden" id="add_reg-select-time">
                     </div>
                     <div class="row ereg-addr">
                         <div class="columns large-4 small-12 text-right">State</div>
-                        <div class="columns large-8 small-12"><input class="reg_state" value="<%- state %>"></div>
+                        <div class="columns large-8 small-12">
+                            <select class="reg_state">
+                                <option value=""></option>
+                                {/literal}
+                                {foreach $states_list as $stateAbbr => $stateName}
+                                    <option value="{$stateAbbr}">{$stateName}</option>
+                                {/foreach}
+                                {literal}
+                            </select>
+                        </div>
                     </div>
                     <div class="row ereg-addr">
                         <div class="columns large-4 small-12 text-right">Zip/Postal Code</div>
                     </div>
                     <div class="row ereg-addr">
                         <div class="columns large-4 small-12 text-right">Country</div>
-                        <div class="columns large-8 small-12"><input class="reg_country" value="<%- country %>"></div>
+                        <div class="columns large-8 small-12">
+                            <select class="reg_country">
+                                <option value=""></option>
+                                {/literal}
+                                {foreach $country_list as $countryKey => $countryValue}
+                                    <option value="{$countryKey}">{$countryValue}</option>
+                                {/foreach}
+                                {literal}
+                            </select>
+                        </div>
                     </div>
                 </div>
             {/literal}{if $regEvent.time_specific.value}
@@ -458,53 +494,55 @@ jQuery(function($){
     regEvent.setClassRegistrants( {$regJSON} );
     var glmApp = new app.Views.Front.App();
 
-    $("#glm-reg-detail-map-button").click(function() {
-        var map_container   = "#glm-reg-map-container";
-        var map             = "#glm-reg-map";
-        var mapNewH         = 0;
-        var mapOverflow     = 'hidden';
-        var mapBtnTxt       = 'view map';
+    {if $regEvent.locations}
+        $("#glm-reg-detail-map-button").click(function() {
+            var map_container   = "#glm-reg-map-container";
+            var map             = "#glm-reg-map";
+            var mapNewH         = 0;
+            var mapOverflow     = 'hidden';
+            var mapBtnTxt       = 'view map';
 
-        if ($(map_container).height() == 0) {
-            mapNewH = 250;
-            mapV = 'visible';
-            mapBtnTxt = 'hide map'
-        }
-        $(map_container).animate({
-            overflow: mapOverflow,
-            height: mapNewH
-        }, 250, "swing", function() {
+            if ($(map_container).height() == 0) {
+                mapNewH = 250;
+                mapV = 'visible';
+                mapBtnTxt = 'hide map'
+            }
+            $(map_container).animate({
+                overflow: mapOverflow,
+                height: mapNewH
+            }, 250, "swing", function() {
 
+            });
+            $(this).html(mapBtnTxt);
         });
-        $(this).html(mapBtnTxt);
-    });
-    {if $regEvent.locations.lat !=0 && $regEvent.locations.lon != 0}
-        var eventlocation = new google.maps.LatLng({$regEvent.locations.lat}, {$regEvent.locations.lon});
-    {else}
-        var eventlocation = new google.maps.LatLng({$settings.maps_default_lat}, {$settings.maps_default_lon});
-    {/if}
-    function initMap() {
-        // Set default - Need to make this configurable
-        var map = new google.maps.Map(document.getElementById('glm-reg-map'), {
-            zoom: {$settings.maps_default_zoom},
-            center: eventlocation,
-            disableDefaultUI: false,
-            mapTypeId: google.maps.MapTypeId.MAP,
-        });
-
-        // Create a marker for this event
         {if $regEvent.locations.lat !=0 && $regEvent.locations.lon != 0}
-                var marker = new google.maps.Marker({
-                    map: map,
-                    position: new google.maps.LatLng({$regEvent.locations.lat}, {$regEvent.locations.lon}),
-                    draggable: false,
-                    animation: google.maps.Animation.DROP,
-                    title: ''
-                });
-             {/if}
+            var eventlocation = new google.maps.LatLng({$regEvent.locations.lat}, {$regEvent.locations.lon});
+        {else}
+            var eventlocation = new google.maps.LatLng({$settings.maps_default_lat}, {$settings.maps_default_lon});
+        {/if}
+        function initMap() {
+            // Set default - Need to make this configurable
+            var map = new google.maps.Map(document.getElementById('glm-reg-map'), {
+                zoom: {$settings.maps_default_zoom},
+                center: eventlocation,
+                disableDefaultUI: false,
+                mapTypeId: google.maps.MapTypeId.MAP,
+            });
+
+            // Create a marker for this event
+            {if $regEvent.locations.lat !=0 && $regEvent.locations.lon != 0}
+                    var marker = new google.maps.Marker({
+                        map: map,
+                        position: new google.maps.LatLng({$regEvent.locations.lat}, {$regEvent.locations.lon}),
+                        draggable: false,
+                        animation: google.maps.Animation.DROP,
+                        title: ''
+                    });
+                 {/if}
 
-    }
-    google.maps.event.addDomListener(window, 'load', initMap);
+        }
+        google.maps.event.addDomListener(window, 'load', initMap);
+    {/if}
     jQuery("#MemberDrivingDirectionsForm").submit(function(){
         var place = jQuery("#MemberLocation").val().replace( new RegExp( " ", "g" ), '+' );
         var lat = jQuery("#MemberLat").val();
@@ -537,7 +575,7 @@ jQuery(function($){
                 $(descr).css("overflow", "hidden");
             })
         }
-        
+
     });
 });
 </script>