Updating the management options
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 16 Mar 2017 14:44:08 +0000 (10:44 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 16 Mar 2017 14:44:08 +0000 (10:44 -0400)
Also working more on the drop down schedule.

models/admin/ajax/schedule.php
models/admin/management/apis.php
models/front/apis/schedule.php
views/admin/management/apis.html
views/front/apis/schedule.html

index 47559fd..b91f625 100644 (file)
@@ -84,7 +84,12 @@ class GlmMembersAdmin_ajax_schedule
     public function modelAction($actionData = false)
     {
         if ( isset( $_REQUEST['schedule_id'] ) && preg_match( '/sel([0-9]*)/', $_REQUEST['schedule_id'] ) ) {
-            $url = get_option( GLM_MEMBERS_APIS_STARLINE_OPTION_NAME ) . 'schedule-' . $_REQUEST['schedule_id'] . '.js';
+            // Get the options for starline
+            $starlineOptions  = unserialize( get_option( GLM_MEMBERS_APIS_STARLINE_OPTION_NAME ) );
+            $starlineUrl      = ( isset( $starlineOptions['ticketUrl'] ) ) ? $starlineOptions['ticketUrl'] : '';
+            $starlinePageSlug = ( isset( $starlineOptions['pageSlug'] ) ) ? $starlineOptions['pageSlug'] : '';
+
+            $url = $starlineUrl . 'schedule-' . $_REQUEST['schedule_id'] . '.js';
             $curl = curl_init( $url );
             curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
            curl_setopt( $curl, CURLOPT_USERPWD, 'dev55:Glm15Keep!' );
index 92ffd20..52d8918 100644 (file)
@@ -92,6 +92,8 @@ class GlmMembersAdmin_management_apis
         $settings_update_error = false;
         $api_settings          = false;
         $option2               = false;
+        $starlineUrl           = false;
+        $starlinePageSlug      = false;
         $starlineOptionName    = GLM_MEMBERS_APIS_STARLINE_OPTION_NAME;
 
         if (isset($_REQUEST['option'])) {
@@ -127,14 +129,18 @@ class GlmMembersAdmin_management_apis
             // Update the settings and redisplay the form
             case 'submit':
                 $settings_updated = true;
-                update_option( $starlineOptionName, $_REQUEST[$starlineOptionName] );
-                $starlineUrl = get_option( $starlineOptionName );
+                update_option( $starlineOptionName, serialize( $_REQUEST[$starlineOptionName] ) );
+                $starlineOptions  = unserialize( get_option( $starlineOptionName ) );
+                $starlineUrl      = ( isset( $starlineOptions['ticketUrl'] ) ) ? $starlineOptions['ticketUrl'] : '';
+                $starlinePageSlug = ( isset( $starlineOptions['pageSlug'] ) ) ? $starlineOptions['pageSlug'] : '';
 
                 break;
 
             // Default is to get the current settings and display the form
             default:
-                $starlineUrl = get_option( $starlineOptionName );
+                $starlineOptions  = unserialize( get_option( $starlineOptionName ) );
+                $starlineUrl      = ( isset( $starlineOptions['ticketUrl'] ) ) ? $starlineOptions['ticketUrl'] : '';
+                $starlinePageSlug = ( isset( $starlineOptions['pageSlug'] ) ) ? $starlineOptions['pageSlug'] : '';
 
                 break;
             }
@@ -144,7 +150,8 @@ class GlmMembersAdmin_management_apis
         // Compile template data
         $template_data = array(
             'option'              => $option,
-            'starlineUrl'        => $starlineUrl,
+            'starlineUrl'         => $starlineUrl,
+            'starlinePageSlug'    => $starlinePageSlug,
             'starlineOptionName'  => $starlineOptionName,
             'settingsUpdated'     => $settings_updated,
             'settingsUpdateError' => $settings_update_error,
index f5f838c..2c2ea87 100644 (file)
@@ -49,15 +49,35 @@ class GlmMembersFront_apis_schedule
      */
     public function modelAction($actionData = false)
     {
+        echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
         //echo '<pre>$actionData: ' . print_r( $actionData, true ) . '</pre>';
         $view     = 'schedule';
         $settings = array();
         $content  = '';
 
-        // Get the schedule from starline
-        $url = get_option( GLM_MEMBERS_APIS_STARLINE_OPTION_NAME ) . 'ferrySchedule.php';
-        if ( isset( $actionData['request']['in_dropdown'] ) && $inDropDown = filter_var( $actionData['request']['in_dropdown'], FILTER_VALIDATE_BOOLEAN) ) {
-            $url .= '?dropdown=1';
+        // Get the options for starline
+        $starlineOptions  = unserialize( get_option( GLM_MEMBERS_APIS_STARLINE_OPTION_NAME ) );
+        $starlineUrl      = ( isset( $starlineOptions['ticketUrl'] ) ) ? $starlineOptions['ticketUrl'] : '';
+        $starlinePageSlug = ( isset( $starlineOptions['pageSlug'] ) ) ? $starlineOptions['pageSlug'] : '';
+
+        // Setup the url.
+        $url = $starlineUrl . 'ferrySchedule.php';
+        $inDropDown = filter_var( $actionData['request']['in_dropdown'], FILTER_VALIDATE_BOOLEAN );
+        $urlParams = array();
+        if ( isset( $actionData['request']['in_dropdown'] ) && $inDropDown ) {
+            $urlParams[] = 'dropdown=1';
+        }
+        if ( isset( $_REQUEST['mapLink'] ) && $inDropDown ) {
+            $urlParams[] = 'mapLink=' . $_REQUEST['mapLink'];
+        }
+        if ( isset( $_REQUEST['dockId'] ) && !$inDropDown ) {
+            $urlParams[] = 'dockId=' . $_REQUEST['dockId'];
+        }
+        if ( isset( $_REQUEST['scheduleId'] ) && !$inDropDown ) {
+            $urlParams[] = 'scheduleId=' . $_REQUEST['scheduleId'];
+        }
+        if ( !empty( $urlParams ) ) {
+            $url .= '?' . implode( '&', $urlParams );
         }
         $curl = curl_init( $url );
         curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
@@ -68,7 +88,7 @@ class GlmMembersFront_apis_schedule
         $templateData = array(
             'content'      => $content,
             'inDropDown'   => $inDropDown,
-            'schedulePage' => 'schedule-test-page'
+            'schedulePage' => get_home_url(null, '/' ) . $starlinePageSlug . '/',
         );
 
         error_reporting(E_ALL ^ E_NOTICE);
index 8fd4930..cc81a61 100644 (file)
@@ -9,26 +9,37 @@
             <td colspan="2">
                 {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
                 {if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
-                <h2>Management Settings</h2>
             </td>
         </tr>
         <tr>
             <td>
+                <h3>Starline API</h3>
                 <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
                     <input type="hidden" name="glm_action" value="apis">
                     <input type="hidden" name="option" value="settings">
                     <input type="hidden" name="option2" value="submit">
                     <table class="glm-admin-table">
                         <tr>
-                            <th class="emailLabel"> URL for ticketing system (Starline) [include ending slash]</th>
+                            <th> URL for ticketing system (Starline) [include ending slash] </th>
                             <td>
                                 <input
                                     class="glm-form-text-input-medium"
-                                    name="{$starlineOptionName}"
+                                    name="{$starlineOptionName}[ticketUrl]"
                                     id="ticketUrl"
                                     type="text"
                                     value="{$starlineUrl}">
                             </td>
+                        </tr
+                        <tr>
+                            <th> Page slug for the Schedule </th>
+                            <td>
+                                <input
+                                    class="glm-form-text-input-medium"
+                                    name="{$starlineOptionName}[pageSlug]"
+                                    id="ticketUrl"
+                                    type="text"
+                                    value="{$starlinePageSlug}">
+                            </td>
                         </tr>
                     </table>
                     <input type="submit" value="Update Settings" class="button-primary">
index 09815ae..3c4e53b 100644 (file)
@@ -1,71 +1,83 @@
 <div id="inside_schedule_wrapper">
+    {if $inDropDown}
+        <form
+            id="dockForm"
+            name="dockForm"
+            action="{$schedulePage}"
+            method="get">
+            <input type="hidden" id="formDockId" name="dockId">
+            <input type="hidden" id="formSchedId" name="scheduleId">
+{/if}
     {$content}
+    {if $inDropDown}
+        </form>
+    {/if}
 </div>
 
 <script>
-function get_schedule( scheduleId )
-{
-    {if !$inDropDown}
-        {literal}
-            $.get(
-                {/literal}'{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=schedule&schedule_id=' + scheduleId{literal}
-                ).done(
-                    function(data){
-                        $('#edit-divy').html(data);
-                    }
-                );
-        {/literal}
-    {else}
-        // For the drop down docks schedules
-        var dropdown_dockForm = $("#dockForm");
-        var dropdown_formDockId = $("#formDockId");
-        var dropdown_formSchedId = $("#formSchedId");
-        var dropdown_dock1Sel = $('#dd-sched-1');
-        dropdown_dock1Sel.change(function(){
-            formSchedId.val(1);
-            formDockId.val(dock1Sel.val());
-            dockForm.submit();
-        });
-        var dropdown_dock2Sel = $('#dd-sched-2');
-        dropdown_dock2Sel.change(function(){
-            formSchedId.val(2);
-            formDockId.val(dock2Sel.val());
-            dockForm.submit();
-        });
-        var dropdown_dock3Sel = $('#dd-sched-3');
-        dropdown_dock3Sel.change(function(){
-            formSchedId.val(3);
-            formDockId.val(dock3Sel.val());
-            dockForm.submit();
-        });
-        var dropdown_dock4Sel = $('#dd-sched-4');
-        dropdown_dock4Sel.change(function(){
-            formSchedId.val(4);
-            formDockId.val(dock4Sel.val());
-            dockForm.submit();
-        });
-        var dropdown_mapLink1 = $('#dropdown-google-map-link1');
-        dropdown_mapLink1.click(function(){
-            window.location = '{$schedulePage}/?mapLink=1';
-            return false;
-        });
-        var dropdown_mapLink2 = $('#dropdown-google-map-link2');
-        dropdown_mapLink2.click(function(){
-            window.location = '{$schedulePage}/?mapLink=2';
-            return false;
-        });
-        var dropdown_mapLink3 = $('#dropdown-google-map-link3');
-        dropdown_mapLink3.click(function(){
-            console.log('test test test');
-            return false;
-            //window.location = '{$schedulePage}/?mapLink=3';
-            //return false;
-        });
-        var dropdown_mapLink4 = $('#dropdown-google-map-link4');
-        dropdown_mapLink4.click(function(){
-            window.location = '{$schedulePage}/?mapLink=4';
-            return false;
-        });
-    {/if}
-}
+jQuery(document).ready(function(){
+        {if !$inDropDown}
+            function get_schedule( scheduleId )
+            {
+                {literal}
+                $.get(
+                    {/literal}'{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=schedule&schedule_id=' + scheduleId{literal}
+                    ).done(
+                        function(data){
+                            $('#edit-divy').html(data);
+                        }
+                    );
+                {/literal}
+            }
+        {else}
+            // For the drop down docks schedules
+            var dropdown_dockForm = $("#dockForm");
+            var dropdown_formDockId = $("#formDockId");
+            var dropdown_formSchedId = $("#formSchedId");
+            var dropdown_dock1Sel = $('#dd-sched-1');
+            dropdown_dock1Sel.change(function(){
+                dropdown_formSchedId.val(1);
+                dropdown_formDockId.val(dropdown_dock1Sel.val());
+                dropdown_dockForm.submit();
+            });
+            var dropdown_dock2Sel = $('#dd-sched-2');
+            dropdown_dock2Sel.change(function(){
+                dropdown_formSchedId.val(2);
+                dropdown_formDockId.val(dropdown_dock2Sel.val());
+                dropdown_dockForm.submit();
+            });
+            var dropdown_dock3Sel = $('#dd-sched-3');
+            dropdown_dock3Sel.change(function(){
+                dropdown_formSchedId.val(3);
+                dropdown_formDockId.val(dropdown_dock3Sel.val());
+                dropdown_dockForm.submit();
+            });
+            var dropdown_dock4Sel = $('#dd-sched-4');
+            dropdown_dock4Sel.change(function(){
+                dropdown_formSchedId.val(4);
+                dropdown_formDockId.val(dropdown_dock4Sel.val());
+                dropdown_dockForm.submit();
+            });
+            var dropdown_mapLink1 = $('#dropdown-google-map-link1');
+            dropdown_mapLink1.click(function(){
+                window.location = '{$schedulePage}/?mapLink=1';
+                return false;
+            });
+            var dropdown_mapLink2 = $('#dropdown-google-map-link2');
+            dropdown_mapLink2.click(function(){
+                window.location = '{$schedulePage}/?mapLink=2';
+                return false;
+            });
+            var dropdown_mapLink3 = $('#dropdown-google-map-link3');
+            dropdown_mapLink3.click(function(){
+                window.location = '{$schedulePage}/?mapLink=3';
+                return false;
+            });
+            var dropdown_mapLink4 = $('#dropdown-google-map-link4');
+            dropdown_mapLink4.click(function(){
+                window.location = '{$schedulePage}/?mapLink=4';
+                return false;
+            });
+        {/if}
+});
 </script>