Updates for counties.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 14 Feb 2019 15:04:43 +0000 (10:04 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 14 Feb 2019 15:04:43 +0000 (10:04 -0500)
Add event form updates:
Switch over to using nominatim for the lat lon (geocoding).
Move county field between city and state.

models/front/events/frontAdd.php
views/admin/events/editLocation.html
views/admin/management/events.html
views/front/events/frontAdd.html

index aaae766..4197800 100644 (file)
@@ -13,6 +13,7 @@ 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';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCounties.php';
 
 /**
  * GLmMembersFront_event_fontAdd
@@ -65,19 +66,12 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
         foreach ($address as $key => &$part) {
             $part = urlencode($part);
         }
-        $addressString = implode( ',', $address);
-        $url = "//maps.googleapis.com/maps/api/geocode/json?address={$addressString}";
-        $ch = curl_init($url);
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-        $return = json_decode(curl_exec($ch));
-        curl_close($ch);
-        if (isset($return->results)) {
-            $location = $return->results[0]->geometry->location;
-
-            return array(
-                $location->lat,
-                $location->lng
-            );;
+        $addressString = $address[0] . ',+' . $address[1] . '+' . $address[2];
+
+        $url = "https://nominatim.openstreetmap.org/search/?format=json&addressdetails=1&q={$addressString}&limit=1";
+        $return = json_decode( wp_remote_retrieve_body( wp_remote_get( $url ) ) );
+        if ( $return[0]->lat && $return[0]->lon ) {
+            return array( $return[0]->lat,  $return[0]->lon);
         } else {
             return false;
         }
@@ -212,8 +206,9 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
         $eventAmenities  = array();
         $venues          = false;
         $startTimeOnly   = 0;
-        $eventCategories = [];
+        $eventCategories = array();
         $cities          = array();
+        $counties        = array();
 
         if ( isset( $actionData['request']['member_only'] )
             && $memberOnly = filter_var( $actionData['request']['member_only'], FILTER_VALIDATE_BOOLEAN ) ) {
@@ -241,8 +236,18 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
         // populate cities dropdown
         $cityData = new GlmDataCities( $this->wpdb, $this->config );
         $cityVals = $cityData->getList( null, 'name' );
-        foreach ( $cityVals as $city ) {
-            $cities[$city['id']] = $city['name'];
+        if ( isset( $cityVals ) && is_array( $cityVals ) && !empty( $cityVals ) ) {
+            foreach ( $cityVals as $city ) {
+                $cities[$city['id']] = $city['name'];
+            }
+        }
+        // populate counties dropdown
+        $countyData = new GlmDataCounties( $this->wpdb, $this->config );
+        $countyVals = $countyData->getList( null, 'name' );
+        if ( isset( $countyVals ) && is_array( $countyVals ) && !empty( $countyVals ) ) {
+            foreach ( $countyVals as $county ) {
+                $counties[$county['id']] = $county['name'];
+            }
         }
         // populate category dropdown
         $categories = new GlmDataEventsCategories( $this->wpdb, $this->config );
@@ -353,6 +358,7 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
                 $place        = $this->filterInput( $_REQUEST['place'] );
                 $address      = $this->filterInput( $_REQUEST['address'] );
                 $city         = $this->filterInput( $_REQUEST['city'] );
+                $county       = $this->filterInput( $_REQUEST['county'] );
                 $state        = $this->filterInput( $_REQUEST['state'] );
                 $zip          = $this->filterInput( $_REQUEST['zip'] );
                 $contactEmail = $this->filterInput( $_REQUEST['contact_email'] );
@@ -531,29 +537,31 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
                         'name'          => $place,
                         'address'       => $address,
                         'city'          => $city,
+                        'county'        => $county,
                         'state'         => $state,
                         'zip'           => $zip,
                         'phone'         => $contactPhone,
                         'contact_fname' => $contactFirst,
                         'contact_lname' => $contactLast,
-                        'email'         => $contactEmail
+                        'email'         => $contactEmail,
 
                     );
                     $locationDataFormat = array(
-                         '%d',
-                         '%s',
-                         '%s',
-                         '%d',
-                         '%s',
-                         '%s',
-                         '%s',
-                         '%s',
-                         '%s',
-                         '%s'
+                         '%d', // eventID
+                         '%s', // place
+                         '%s', // address
+                         '%d', // city
+                         '%d', // county
+                         '%s', // state
+                         '%s', // zip
+                         '%s', // contactPhone
+                         '%s', // contactFirst
+                         '%s', // contactLast
+                         '%s', // contactEmail
                     );
                     if ( isset( $lat ) && isset( $lon ) && $lat && $lon) {
-                        $locationData['lat'] = $lat;
-                        $locationData['lon'] = $lon;
+                        $locationData['lat']  = $lat;
+                        $locationData['lon']  = $lon;
                         $locationDataFormat[] = '%s';
                         $locationDataFormat[] = '%s';
                     }
@@ -739,6 +747,7 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents
             'confirmation_page' => $redirect_url,
             'mainImgUrl'        => GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/large/',
             'cities'            => $cities,
+            'counties'          => $counties,
         );
 
         //error_reporting(E_ALL ^ E_NOTICE);
index f2dede9..0ac0930 100755 (executable)
                                             </select>
                                         </td>
                                     </tr>
+                                    {if $settings.enable_counties}
+                                        <tr>
+                                            <th>County:</th>
+                                            <td>
+                                                <select id="county_{$loc.id}" data-id="{$loc.id}" name="Loc{$loc.id}_county">
+                                                    <option value="0"></option>
+                                                    {foreach from=$loc.county.list item=v}
+                                                        <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
+                                                            {$v.name}
+                                                        </option>
+                                                    {/foreach}
+                                                </select>
+                                            </td>
+                                        </tr>
+                                    {/if}
                                     <tr>
                                         <th{if $settings.michigan_org_requirements && $lockedToMember} class="glm-required"{/if}>State:</th>
                                         <td>
                                             <input id="zip_{$loc.id}" data-id="{$loc.id}" type="text" name="Loc{$loc.id}_zip" value="{$loc.zip}" class="glm-form-text-input-medium zipcode-input">
                                         </td>
                                     </tr>
-                                    <tr>
-                                        <th>County:</th>
-                                        <td>
-                                            <select id="county_{$loc.id}" data-id="{$loc.id}" name="Loc{$loc.id}_county">
-                                                <option value="0"></option>
-                                                {foreach from=$loc.county.list item=v}
-                                                    <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
-                                                        {$v.name}
-                                                    </option>
-                                                {/foreach}
-                                            </select>
-                                        </td>
-                                    </tr>
                                     <tr>
                                         <th>Country:</th>
                                         <td>
                         </select>
                     </td>
                 </tr>
+                {if $settings.enable_counties}
+                    <tr>
+                        <th>County:</th>
+                        <td>
+                            <select id="county_{ newLocID }" data-id="{ newLocID }" name="{ newLocID }_county">
+                                <option value="0"></option>
+                                {foreach from=$newLocation.fieldData.county.list item=v}
+                                    <option value="{$v.value}"{if $v.default} selected="selected"{/if}>{$v.name}</option>
+                                {/foreach}
+                            </select>
+                        </td>
+                    </tr>
+                {/if}
                 <tr>
                     <th{if $settings.michigan_org_requirements && $lockedToMember} class="glm-required"{/if}>State:</th>
                     <td>
                         <input id="zip_{ newLocID }" data-id="{ newLocID }" type="text" name="{ newLocID }_zip" value="{$newLocation.fieldData.zip}" class="glm-form-text-input-medium zipcode-input">
                     </td>
                 </tr>
-                <tr>
-                    <th>County:</th>
-                    <td>
-                        <select id="county_{ newLocID }" data-id="{ newLocID }" name="{ newLocID }_county">
-                            <option value="0"></option>
-                            {foreach from=$newLocation.fieldData.county.list item=v}
-                                <option value="{$v.value}"{if $v.default} selected="selected"{/if}>{$v.name}</option>
-                            {/foreach}
-                        </select>
-                    </td>
-                </tr>
                 <tr>
                     <th>Country:</th>
                     <td>
index c7cdbc6..167d16f 100644 (file)
                                 <label> <input type="checkbox" name="show_search_category" {if $eventsSettings.fieldData.show_search_category.value}checked{/if}> Show Category Search</label><br><br>
                                 <label> <input type="checkbox" name="show_search_city" {if $eventsSettings.fieldData.show_search_city.value}checked{/if}> Show City Search</label><br><br>
                                 <label> <input type="checkbox" name="show_search_region" {if $eventsSettings.fieldData.show_search_region.value}checked{/if}> Show Region Search</label><br><br>
-                                <label> <input type="checkbox" name="show_search_county" {if $eventsSettings.fieldData.show_search_county.value}checked{/if}> Show County Search</label><br><br>
+                                <label>
+                                    <input type="checkbox" name="show_search_county" {if $eventsSettings.fieldData.show_search_county.value}checked{/if}{if !$settings.enable_counties} disabled{/if}>
+                                    Show County Search
+                                    {if !$settings.enable_counties} <span style="color: red;">(Counties must be enabled in members)</span>{/if}
+                                </label><br><br>
                             </td>
                         </tr>
                         <tr>
index bacd2f3..3fa0322 100644 (file)
                 <div class="glm-add-event-form-data">
                     <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}
+                        {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">
+                <div class="glm-add-event-form-label">
+                    <label>County</label>
+                </div>
+                <div class="glm-add-event-form-data">
+                    <select name="county">
+                        <option value="">Choose County</option>
+                        {foreach $counties as $county_id => $county_name}
+                            <option value="{$county_id}">{$county_name}</option>
+                        {/foreach}
                     </select>
                 </div>
             </div>
                     <select id="state_30" name="state" required>
                         {foreach $states as $stateAbbr => $stateName}
                             <option value="{$stateAbbr}"{if $state_def == $stateAbbr} selected{/if}>
-                        {$stateName}
-                        </option>
+                                {$stateName}
+                            </option>
                         {/foreach}
                     </select>
                 </div>