Add city drop down for add event form.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 5 Apr 2018 15:47:59 +0000 (11:47 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 5 Apr 2018 15:47:59 +0000 (11:47 -0400)
Use the city list to generate a select for cities.
Too many cities end up getting created.

models/front/events/frontAdd.php
views/front/events/frontAdd.html

index a71d939..43a5614 100644 (file)
@@ -12,6 +12,7 @@ require_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/front/events/baseAction.p
 require_once GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php';
 require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php';
 require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataManagement.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCities.php';
 
 /**
  * GLmMembersFront_event_fontAdd
@@ -194,24 +195,25 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
         wp_enqueue_script('glm-members-front-maskedinput');
 
         // Set initial values for variables.
-        $fromDate       = '';
-        $permalink      = '';
-        $title          = '';
-        $errorMsg       = '';
-        $days           =
-        $lastDayOfMonth =
-        $startTime      =
-        $endTime        = 0;
-        $status         = false;
-        $memberOnly     = false;
-        $memberContact  = false;
-        $memberManager  = false;
-        $members        = false;
-        $venues         = false;
-        $eventAmenities = array();
-        $venues         = false;
-        $startTimeOnly  = 0;
+        $fromDate        = '';
+        $permalink       = '';
+        $title           = '';
+        $errorMsg        = '';
+        $days            =
+        $lastDayOfMonth  =
+        $startTime       =
+        $endTime         = 0;
+        $status          = false;
+        $memberOnly      = false;
+        $memberContact   = false;
+        $memberManager   = false;
+        $members         = false;
+        $venues          = false;
+        $eventAmenities  = array();
+        $venues          = false;
+        $startTimeOnly   = 0;
         $eventCategories = [];
+        $cities          = array();
 
         if ( isset( $actionData['request']['member_only'] )
             && $memberOnly = filter_var( $actionData['request']['member_only'], FILTER_VALIDATE_BOOLEAN ) ) {
@@ -236,6 +238,12 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
 //            wp_enqueue_script('front-js', GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/js/front.js');
         }
         $view = 'frontAdd';
+        // populate cities dropdown
+        $cityData = new GlmDataCities( $this->wpdb, $this->config );
+        $cityVals = $cityData->getList();
+        foreach ( $cityVals as $city ) {
+            $cities[$city['id']] = $city['name'];
+        }
         // populate category dropdown
         $categories = new GlmDataEventsCategories( $this->wpdb, $this->config );
         //$emailInfo  = new GlmDataEventsManagement( $this->wpdb, $this->config );
@@ -339,7 +347,7 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
                 $admin_name   = $this->filterInput( $_REQUEST['admin_name'] );
                 $admin_org    = $this->filterInput( $_REQUEST['admin_org'] );
                 $adminPhone   = $this->filterInput( $_REQUEST['admin_phone'] );
-                $userEmail   = $this->filterInput( $_REQUEST['admin_email'] );
+                $userEmail    = $this->filterInput( $_REQUEST['admin_email'] );
                 $contactFirst = $this->filterInput( $_REQUEST['contact_fname'] );
                 $contactLast  = $this->filterInput( $_REQUEST['contact_lname'] );
                 $place        = $this->filterInput( $_REQUEST['place'] );
@@ -352,7 +360,7 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
                 $fileDescr    = $this->filterInput( $_REQUEST['fileDescription'] );
 
                 // get lat lon
-                $latLon = $this->getGeoLocation( array($address, $city, $state) );
+                $latLon = $this->getGeoLocation( array($address, $cities[$city], $state) );
                 if ($latLon) {
                    $lat = $latLon[0];
                    $lon = $latLon[1];
@@ -398,7 +406,7 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
                     }
                 }
 
-                $city =  $this->getCityId($city);
+                // $city =  $this->getCityId($city);
                 // image upload settings
                 $image = $_FILES['image_new'];
                 $imageName = $image['name'];
@@ -729,7 +737,8 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
             'from_email'        => $fromEmail,
             'notification'      => $emailNotification,
             'confirmation_page' => $redirect_url,
-            'mainImgUrl'     => GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/large/'
+            'mainImgUrl'        => GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/large/',
+            'cities'            => $cities,
         );
 
         //error_reporting(E_ALL ^ E_NOTICE);
@@ -739,7 +748,7 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
             'modelRedirect'    => false,
             'view'             => 'front/events/'.$view.'.html',
             'data'             => $templateData,
-            //'settings'         => $settings
+            //'settings'       => $settings
         );
     }
 }
index f60a4d7..f018adf 100644 (file)
             </div>
         </div>
         <div class="glm-add-event-form-item" id="glm-front-event-image">
-            
+
             <div class="glm-add-event-form-label{if $event.fieldRequired.image} glm-required{/if}"><label>Image:</label></div>
             <div class="glm-add-event-form-data{if $event.fieldFail.image} glm-form-bad-input{/if}">
-                
+
                 <table class="glm-admin-image-edit-table">
                     {if $event.fieldData.image}
                         <div>
                                 <input type="checkbox" name="image_delete"> Delete Image<br>
                                 {$event.fieldData.image}<br>
                             </div>
-                            
+
                         </div>
                     {/if}
                     <div><div colspan="2"><b>New image:</b> <input type="file" name="image_new" class="glm-event-front-end-image"></div></div>
                 </table>
                 <p class="glm-front-event-image-text">Best image size to provide is between 800 and 1000 pixels wide and stored as a JPG or JPEG file. Also try to supply images that have a reasonable aspect ratio (not too tall, not too wide). Files provided like this should have a file size of 100 to 250 KB. Images will be automatically resized for use in the Web site. Images that are too large will be rejected</p>
             </div>
-            
+
         </div>
         {if $memberOnly}
             <div class="glm-add-event-form-item">
                     <label style="color: red;">City</label>
                 </div>
                 <div class="glm-add-event-form-data">
-                    <input name="city" maxlength="100" type="text" class="glm-required" pattern=".*\S+.*" title="This field is required"  required>
+                    <select name="city" class="glm-required" required>
+                        <option value="">Choose City</option>
+                    {foreach $cities as $city_id => $city_name}
+                        <option value="{$city_id}">{$city_name}</option>
+                    {/foreach}
+                    </select>
                 </div>
             </div>
             <div class="glm-add-event-form-item">
@@ -489,7 +494,7 @@ jQuery(document).ready(function($) {
             $('#' + msgArea).html('Characters remaining: ' + rem);
         }
     }
-    
+
     // check image upload type
     $(".glm-event-front-end-image").change(function () {
         var ext = this.value.match(/\.(.+)$/)[1];