Create redo link to fix discover kzoo event times
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 7 Jul 2016 18:43:17 +0000 (14:43 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 7 Jul 2016 18:43:17 +0000 (14:43 -0400)
Fixing the event time function that was parsing out the hand entered
times and getting off by 12 hours.

index.php
models/admin/management/events.php
views/admin/management/events.html

index 980fa8b..040d868 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
  * Plugin Name: GLM Members Database Events
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: Gaslight Media Members Database.
- * Version: 1.2.15
+ * Version: 1.2.16
  * Author: Chuck Scott
  * Author URI: http://www.gaslightmedia.com/
  * License: GPL2
@@ -20,7 +20,7 @@
  * @package glmMembersDatabaseEventsAddOn
  * @author Chuck Scott <cscott@gaslightmedia.com>
  * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 1.2.14
+ * @version 1.2.16
  */
 
 /*
@@ -38,7 +38,7 @@
  *  so that we're sure the other add-ons see an up to date
  *  version from this plugin.
  */
-define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.2.15');
+define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.2.16');
 define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.18');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
index 1a34a9b..88a0f76 100644 (file)
@@ -283,6 +283,63 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                     default:
                         break;
                 }
+                $action = '';
+                if (isset($_REQUEST['action'])) {
+                    $action = $_REQUEST['action'];
+                }
+                switch ( $action ) {
+                case 'redo':
+                    $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
+                    $db_host      = 'ds4';
+                    $db_name      = 'discoverkalamazoo';
+                    $db_user      = 'postgres';
+                    $db_password  = '';
+                    $this->connectPostgresDb($db_host, $db_name, $db_user, $db_password);
+                    $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config);
+                    $sql         = "
+                    SELECT *
+                      FROM events.event
+                     WHERE edate >= current_date
+                       AND (btime != '' OR etime != '')";
+                    $events = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
+                    foreach ( $events as $event ) {
+                        echo '<pre>$event[btime]: ' . print_r($event['btime'], true) . '</pre>';
+                        $begining = $this->getTime( $event['btime'] );
+                        echo '<pre>$begining: ' . print_r($begining, true) . '</pre>';
+                        echo '<pre>$event[etime]: ' . print_r($event['etime'], true) . '</pre>';
+                        $ending   = $this->getTime( $event['etime'] );
+                        echo '<pre>$ending: ' . print_r($ending, true) . '</pre>';
+                        // find the event with this old_event_id
+                        $result = $this->wpdb->get_results(
+                            "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences
+                              WHERE event IN (
+                                SELECT id
+                                  FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "events
+                                 WHERE old_event_id = " . $event['id'] . ")",
+                            ARRAY_A
+                        );
+                        echo '<pre>$result: ' . print_r($result, true) . '</pre>';
+                        if ( $result[0] ) {
+                            // update the recurrence
+                            $return = $this->wpdb->update(
+                                GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
+                                array(
+                                    'start_time' => $begining,
+                                    'end_time'   => $ending
+                                ),
+                                array( 'id' => $result[0]['id'] ),
+                                array(
+                                    '%s',
+                                    '%s'
+                                ),
+                                array( '%d' )
+                            );
+                            echo '<pre>$return: ' . print_r($return, true) . '</pre>';
+                            $Recurrences->createRecurrenceTimesEntries( $result[0]['id'], true, true );
+                        }
+                    }
+                    $import_result = 'hello redo';
+                }
                 break;
 
             case 'settings':
@@ -612,23 +669,31 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
      */
     public function getTime($time)
     {
-        echo '<pre>$time: ' . print_r($time, true) . '</pre>';
+        //echo '<pre>$time: ' . print_r($time, true) . '</pre>';
         if (!$time) {
             return false;
         }
         if (!preg_match('%(\d{1,2}):?(\d{2})? ?(\w{1,2})?%', $time, $time_parts)) {
-            //die('not found');
             return false;
         }
-        echo '<pre>$timeParts: ' . print_r($time_parts, true) . '</pre>';
+        //echo '<pre>$timeParts: ' . print_r($time_parts, true) . '</pre>';
         //$hour = (!$timeParts[3] || in_array(strtolower(trim($timeParts[3])), array('pm', 'p')))
         //      ? ( ((int)$timeParts[1] === 12) ? 12 : (int)$timeParts[1] += 12 )
         //      : ( ((int)$timeParts[1] === 12) ? 0 : (int)$timeParts[1] );
         $hour = $time_parts[1];
+        if ( in_array( strtolower( $time_parts[3] ), array( 'pm', 'p' ) ) ) {
+            $hour += 12;
+        }
+        if ( in_array( strtolower( $time_parts[3] ), array( 'am', 'a' ) ) ) {
+            if ( (int)$hour === 12 ) {
+                $hour = 0;
+            }
+        }
+        $min  = ($time_parts[2]) ? $time_parts[2] : 0;
         // parse the hour from event
         $dateTime = new DateTime();
-        $dateTime->setTime($hour, (int)$time_parts[2] );
-        echo '<pre>$dateTime: ' . print_r($dateTime, true) . '</pre>';
+        $dateTime->setTime( $hour, $min );
+        //cho '<pre>$dateTime: ' . print_r($dateTime, true) . '</pre>';
         return $dateTime->format('H:i');
     }
 
@@ -728,30 +793,30 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                         'status'   => (($event['visable'] == '1')
                             ? $this->config['status_numb']['Active']
                             : $this->config['status_numb']['Inactive']),
-                        'created'        => $event['create_date'],
-                        'updated'        => $event['create_date'],
-                        'approved'        => $event['approved_date'],
-                        'name'            => $event['header'],
-                        'intro'            => $intro,
-                        'descr'            => $event['descr'],
-                        'image'            => $event['img'],
-                        'file1'            => $event['file'],
-                        'file1_descr'    => $event['filename'],
-                        'cost'            => $event['cost'],
-                        'url'            => $event['url'],
-                        'old_event_id'    => $event['id'],
-//                        'ref_type'        => $refType,
-                        'ref_type'        => 10,
-                        'ref_dest'        => $found_member_id,
+                        'created'       => $event['create_date'],
+                        'updated'       => $event['create_date'],
+                        'approved'      => $event['approved_date'],
+                        'name'          => $event['header'],
+                        'intro'         => $intro,
+                        'descr'         => $event['descr'],
+                        'image'         => $event['img'],
+                        'file1'         => $event['file'],
+                        'file1_descr'   => $event['filename'],
+                        'cost'          => $event['cost'],
+                        'url'           => $event['url'],
+                        'old_event_id'  => $event['id'],
+//                        'ref_type'    => $refType,
+                        'ref_type'      => 10,
+                        'ref_dest'      => $found_member_id,
                         'admin_name'    => $event['admin_contact_name'],
-                        'admin_org'        => $event['admin_org_name'],
-                        'admin_email'    => $event['admin_email'],
-                        'admin_phone'    => $event['admin_phone'],
+                        'admin_org'     => $event['admin_org_name'],
+                        'admin_email'   => $event['admin_email'],
+                        'admin_phone'   => $event['admin_phone'],
                         'contact_email' => $event['email'],
-                        'contact_name'    => $event['contact'],
+                        'contact_name'  => $event['contact'],
                         'contact_phone' => $event['phone'],
-                        'notes'            => $event['notes'],
-                        'hide_address'    => $event['hide_address'],
+                        'notes'         => $event['notes'],
+                        'hide_address'  => $event['hide_address'],
                     );
                     $event_data_format = array(
                         '%d',
@@ -795,30 +860,30 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                         'status'   => (($event['active'] == '1')
                             ? $this->config['status_numb']['Active']
                             : $this->config['status_numb']['Inactive']),
-                        'created'              => $event['created'],
-                        'updated'              => $event['updated'],
-                        'approved'              => $event['approved'],
-                        'name'                  => $event['header'],
-                        'intro'                  => $intro,
-                        'descr'                  => $event['description'],
-                        'image'                  => $event['image'],
-                        'file1'                  => $file,
-                        'file1_descr'          => $filename,
-                        'cost'                  => $event['cost'],
-                        'url'                  => $event['website'],
-                        'old_event_id'          => $event['id'],
-//                        'ref_type'              => $refType,
-                        'ref_type'              => 10,
-                        'ref_dest'              => $found_member_id,
+                        'created'             => $event['created'],
+                        'updated'             => $event['updated'],
+                        'approved'            => $event['approved'],
+                        'name'                => $event['header'],
+                        'intro'               => $intro,
+                        'descr'               => $event['description'],
+                        'image'               => $event['image'],
+                        'file1'               => $file,
+                        'file1_descr'         => $filename,
+                        'cost'                => $event['cost'],
+                        'url'                 => $event['website'],
+                        'old_event_id'        => $event['id'],
+//                        'ref_type'          => $refType,
+                        'ref_type'            => 10,
+                        'ref_dest'            => $found_member_id,
                         'admin_name'          => $event['admin_contact'],
-                        'admin_org'              => $event['admin_org'],
-                        'admin_email'          => $event['admin_email'],
-                        'admin_phone'          => $event['admin_phone'],
-                        'contact_email'          => $event['contact_email'],
-                        'contact_name'          => $event['contact_name'],
-                        'contact_phone'          => $event['contact_phone'],
-                        'notes'                  => $event['notes'],
-                        'hide_address'          => $event['hide_address'],
+                        'admin_org'           => $event['admin_org'],
+                        'admin_email'         => $event['admin_email'],
+                        'admin_phone'         => $event['admin_phone'],
+                        'contact_email'       => $event['contact_email'],
+                        'contact_name'        => $event['contact_name'],
+                        'contact_phone'       => $event['contact_phone'],
+                        'notes'               => $event['notes'],
+                        'hide_address'        => $event['hide_address'],
                         'use_member_location' => $event['use_memberloc']
                     );
                     $event_data_format = array(
@@ -966,20 +1031,20 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                     $from_date = $event['starting'];
                     $to_date   = $event['ending'];
                 }
-                $recur_data =array(
-                    'event'                => $event_id,
-                    'name'                => 'Imported Event Schedule',
+                $recur_data = array(
+                    'event'             => $event_id,
+                    'name'              => 'Imported Event Schedule',
                     'start_time'        => $btime,
-                    'end_time'            => $etime,
-                    'start_time_only'    => $start_time_only,
-                    'from_date'            => $from_date,
-                    'to_date'            => $to_date,
-                    'all_day'            => $all_day,
-                    'recurring'            => $recurring_event,
-                    'month_of_year'        => $month_of_year,
-                    'week_of_month'        => $week_of_month,
-                    'day_of_week'        => $day_of_week,
-                    'by_day_of_month'    => $by_day_of_month,
+                    'end_time'          => $etime,
+                    'start_time_only'   => $start_time_only,
+                    'from_date'         => $from_date,
+                    'to_date'           => $to_date,
+                    'all_day'           => $all_day,
+                    'recurring'         => $recurring_event,
+                    'month_of_year'     => $month_of_year,
+                    'week_of_month'     => $week_of_month,
+                    'day_of_week'       => $day_of_week,
+                    'by_day_of_month'   => $by_day_of_month,
                     'last_day_of_month' => $last_day_of_month
                 );
                 //echo '<pre>' . print_r( $recurData, true) . '</pre>';
@@ -1272,7 +1337,7 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement
                     echo '<pre>$from_date_time: ' . print_r($from_date_time, true) . '</pre>';
                                }
                 $to_date   = date( 'Y-m-d', $event_data['end'] );
-                // check if the $to_date has 0 hr 
+                // check if the $to_date has 0 hr
                 // if the btime and etime are 00:00 then remove one day from $to_date
                 if ( date( 'H', $event_data['end'] ) === '00' ) {
                     $ending_datetime = new DateTime( $to_date );
index 7bb77ed..7f3145a 100644 (file)
@@ -6,9 +6,9 @@
         <a id="glm-eventimport" data-show-table="glm-table-eventimport" class="glm-settings-tab nav-tab{if $option=='eventimport'} nav-tab-active{/if}">Import</a>
         <a id="glm-timelyimport" data-show-table="glm-table-timelyimport" class="glm-settings-tab nav-tab{if $option=='timelyimport'} nav-tab-active{/if}">Timely Import</a>
     </h2>
-    
+
     <!-- Management Settings -->
-    
+
     <table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option!='settings'} glm-hidden{/if}">
         <tr>
             <td colspan="2">
@@ -79,9 +79,9 @@
             </td>
         </tr>
     </table>
-    
+
     <!-- Tests -->
-    
+
     <table id="glm-table-tests" class="glm-admin-table glm-settings-table{if $option!='tests'} glm-hidden{/if}">
   {if $testResult}
         <tr><td><a href="{$thisUrl}?page={$thisPage}&glm_action=events&option=tests">Return to Test List</a></td></tr>
     </table>
 
     <!-- Import -->
-    
+
     <table id="glm-table-eventimport" class="glm-admin-table glm-settings-table{if $option!='eventimport'} glm-hidden{/if}">
+    <tr><td><a href="{$thisUrl}?page={$thisPage}&glm_action=events&option=eventimport&action=redo">Redo Times</a></td></tr>
   {if $importResult}
         <tr><td><a href="{$thisUrl}?page={$thisPage}&glm_action=events&option=eventimport">Return to Import Events</a></td></tr>
         <tr>
             </td>
         </tr>
   {/if}
-  
+
     </table>
     <table id="glm-table-timelyimport" class="glm-admin-table glm-settings-table{if $option!='timelyImport'} glm-hidden{/if}">
   {if $importResult}
         </tr>
   {/if}
     </table>
-        
+
     <script type="text/javascript">
-        
+
         jQuery(document).ready(function($) {
-            
+
             /*
              * Edit area tabs
              */
                 // Clear tabl highlights and hide all tables
                 $('.glm-settings-tab').removeClass('nav-tab-active');
                 $('.glm-settings-table').addClass('glm-hidden');
-                
+
                 // Highlight selected tab
                 $(this).addClass('nav-tab-active');
-                
+
                 // Show selected table
                 var table = $(this).attr('data-show-table');
                 $('#' + table).removeClass('glm-hidden');
-                
+
                 if (table == 'glm-table-address') {
                     initMap();
                 }
-                
+
             });
 
-            // Flash certain elements for a short time after display      
+            // Flash certain elements for a short time after display
             $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
-                    
+
         });
     </script>