Update admin event list model
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 21 Feb 2019 21:38:33 +0000 (16:38 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 21 Feb 2019 21:38:33 +0000 (16:38 -0500)
Correcting indent.
comment out call for sort parent child method of categories when that is
already done after the category update function. Besides there's no
$this->categories setup.

models/admin/events/list.php

index f3510ee..7a8f865 100644 (file)
@@ -423,454 +423,453 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
                 $view = 'edit';
                 break;
 
-            case 'update':
-
-                // Get the original Event Status. Before the update.
-                $old_event_status = $this->wpdb->get_var(
-                    $this->wpdb->prepare(
-                        "SELECT status
-                           FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
-                          WHERE id = %d",
-                       $this->eventID
-                    )
-                );
+        case 'update':
+
+            // Get the original Event Status. Before the update.
+            $old_event_status = $this->wpdb->get_var(
+                $this->wpdb->prepare(
+                    "SELECT status
+                       FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
+                      WHERE id = %d",
+                   $this->eventID
+                )
+            );
 
-                $this->updateCategories();
-                $categories = $Categories->getListSortedParentChild(false);
+            $this->updateCategories();
+            $categories = $Categories->getListSortedParentChild(false);
 
-                if ( $this->config['settings']['use_event_amenities'] ) {
-                    $this->updateAmenities();
-                    $amenities = $Amenities->getList(false);
-                }
+            if ( $this->config['settings']['use_event_amenities'] ) {
+                $this->updateAmenities();
+                $amenities = $Amenities->getList(false);
+            }
 
-                // Try to update this event
-                $event = $this->updateEntry($this->eventID);
-
-                // Check if that was successful
-                if ($event['status']) {
-                    $eventUpdated = true;
-                    $new_status = $event['fieldData']['status']['value'];
-
-                    // Check if the event is being approved
-                    if ( $event['fieldData']['status']['value'] && $old_event_status ) {
-                        if ( $old_event_status == 20 && $new_status == 10 ) {
-                            // Update approved timestamp.
-                            $this->updateTimestamp('approved', $this->eventID);
-                            if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest'] ) ) {
-                                $notification->sendMemberNotice( $member_id, $event );
-                            }
-                        } else if ( $isModerated && $old_event_status == 10 && $new_status == 20 ) {
-                            if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest'] ) ) {
-                                $notification->sendAdminNotice( $member_id, $event );
-                            }
+            // Try to update this event
+            $event = $this->updateEntry($this->eventID);
+
+            // Check if that was successful
+            if ($event['status']) {
+                $eventUpdated = true;
+                $new_status = $event['fieldData']['status']['value'];
+
+                // Check if the event is being approved
+                if ( $event['fieldData']['status']['value'] && $old_event_status ) {
+                    if ( $old_event_status == 20 && $new_status == 10 ) {
+                        // Update approved timestamp.
+                        $this->updateTimestamp('approved', $this->eventID);
+                        if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest'] ) ) {
+                            $notification->sendMemberNotice( $member_id, $event );
+                        }
+                    } else if ( $isModerated && $old_event_status == 10 && $new_status == 20 ) {
+                        if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest'] ) ) {
+                            $notification->sendAdminNotice( $member_id, $event );
                         }
                     }
+                }
 
-                    // Update updated timestamp and name slug for URLs
-                    $this->updateTimestamp('updated', $this->eventID);
-                    $this->updateSlug($this->eventID);
-
-                    $event = $this->editEntry($this->eventID);
+                // Update updated timestamp and name slug for URLs
+                $this->updateTimestamp('updated', $this->eventID);
+                $this->updateSlug($this->eventID);
 
-                    // Check for status change for any search engine requests.
-                    $statusActive = $this->config['event_status_numb']['Active'];
-                    $eventSlug = $event['fieldData']['name_slug'];
-                    if ($new_status == $statusActive) {
-                        $indexEvent = true;
-                    } elseif ($old_event_status == $statusActive && $new_status != $statusActive) {
-                        $removeEventIndex = true;
-                    }
+                $event = $this->editEntry($this->eventID);
 
-                } else {
-                    $eventUpdateError = true;
+                // Check for status change for any search engine requests.
+                $statusActive = $this->config['event_status_numb']['Active'];
+                $eventSlug = $event['fieldData']['name_slug'];
+                if ($new_status == $statusActive) {
+                    $indexEvent = true;
+                } elseif ($old_event_status == $statusActive && $new_status != $statusActive) {
+                    $removeEventIndex = true;
                 }
 
-                // Look for location deletes
-                if (isset($_REQUEST['deleteLocation']) && count($_REQUEST['deleteLocation'] > 0)) {
-                    foreach ($_REQUEST['deleteLocation'] as $d) {
+            } else {
+                $eventUpdateError = true;
+            }
 
-                        // If this was not a new entry that was deleted (in which case it was never added)
-                        if ($d[0] != 'n') {
-                            $Locations->deleteEntry($d, true);
-                        }
+            // Look for location deletes
+            if (isset($_REQUEST['deleteLocation']) && count($_REQUEST['deleteLocation'] > 0)) {
+                foreach ($_REQUEST['deleteLocation'] as $d) {
 
+                    // If this was not a new entry that was deleted (in which case it was never added)
+                    if ($d[0] != 'n') {
+                        $Locations->deleteEntry($d, true);
                     }
+
                 }
+            }
 
-                // Look for location data
-                if (isset($_REQUEST['locID'])) {
+            // Look for location data
+            if (isset($_REQUEST['locID'])) {
 
-                    // For each location
-                    foreach ( $_REQUEST['locID'] as $id => $locID ) {
+                // For each location
+                foreach ( $_REQUEST['locID'] as $id => $locID ) {
 
-                        // Check for new cities in this location and if so use the new city real ID
-                        if (isset($_REQUEST[$ocID.'_city']) && $_REQUEST[$locID.'_city'][0] == 'n') {
-                            $_REQUEST[$locID.'_city'] = $newCityID[$_REQUEST[$locID.'_city']];
-                        }
+                    // Check for new cities in this location and if so use the new city real ID
+                    if (isset($_REQUEST[$locID.'_city']) && $_REQUEST[$locID.'_city'][0] == 'n') {
+                        $_REQUEST[$locID.'_city'] = $newCityID[$_REQUEST[$locID.'_city']];
+                    }
 
-                        // Check if it's a new Location
-                        if ($locID[0] == 'n') {
+                    // Check if it's a new Location
+                    if ($locID[0] == 'n') {
 
-                            // Add the new location
-                            $x = $Locations->insertEntry(true, $locID.'_');
-
-                        // Otherwise it's an existing location
-                        } else {
-                           $Locations->updateEntry($id, 'id', true, $locID.'_');
-                        }
+                        // Add the new location
+                        $x = $Locations->insertEntry(true, $locID.'_');
 
+                    // Otherwise it's an existing location
+                    } else {
+                       $Locations->updateEntry($id, 'id', true, $locID.'_');
                     }
 
                 }
 
-                // Look for recurrence deletes
-                if (isset($_REQUEST['deleteRecur']) && count($_REQUEST['deleteRecur'] > 0)) {
-                    foreach ($_REQUEST['deleteRecur'] as $d) {
+            }
 
-                        // If this was not a new entry that was deleted (in which case it was never added)
-                        if ($d[0] != 'n') {
-                            $Recurrences->deleteTimeEntriesForRecurrance($d, true);
-                            $Recurrences->deleteEntry($d, true);
-                        }
+            // Look for recurrence deletes
+            if (isset($_REQUEST['deleteRecur']) && count($_REQUEST['deleteRecur'] > 0)) {
+                foreach ($_REQUEST['deleteRecur'] as $d) {
 
+                    // If this was not a new entry that was deleted (in which case it was never added)
+                    if ($d[0] != 'n') {
+                        $Recurrences->deleteTimeEntriesForRecurrance($d, true);
+                        $Recurrences->deleteEntry($d, true);
                     }
-                }
 
-                // Look for recurrence data
-                if (isset($_REQUEST['recurID'])) {
+                }
+            }
 
-                    // For each recurrence
-                    foreach ($_REQUEST['recurID'] as $recurID) {
+            // Look for recurrence data
+            if (isset($_REQUEST['recurID'])) {
 
-                        // first check if the event is an all-day event
-                        if (isset($_REQUEST[$recurID.'_all_day'])) {
+                // For each recurrence
+                foreach ($_REQUEST['recurID'] as $recurID) {
 
-                            // Then take the start date (date only) and stick it into the start time
-                            $red = explode(' ', $_REQUEST[$recurID.'_start_date']);
-                            $_REQUEST[$recurID.'_start_time'] = $red[0]." 00:00";
-                            $_REQUEST[$recurID.'_end_time'] = $red[0]." 00:00";
+                    // first check if the event is an all-day event
+                    if (isset($_REQUEST[$recurID.'_all_day'])) {
 
-                        }
+                        // Then take the start date (date only) and stick it into the start time
+                        $red = explode(' ', $_REQUEST[$recurID.'_start_date']);
+                        $_REQUEST[$recurID.'_start_time'] = $red[0]." 00:00";
+                        $_REQUEST[$recurID.'_end_time'] = $red[0]." 00:00";
 
-                        // Check if it's a new Recurrence
-                        if ($recurID[0] == 'n') {
+                    }
 
-                            // Add the new recurrence
-                            $r = $Recurrences->insertEntry(true, $recurID.'_');
-                            $thisRecurID = $r['fieldData']['id'];
+                    // Check if it's a new Recurrence
+                    if ($recurID[0] == 'n') {
 
-                            // And create time entries
-                            $Recurrences->createRecurrenceTimesEntries($thisRecurID, true, true);
+                        // Add the new recurrence
+                        $r = $Recurrences->insertEntry(true, $recurID.'_');
+                        $thisRecurID = $r['fieldData']['id'];
 
-                        // Otherwise it's an existing recurrence
-                        } else {
-                           $r = $Recurrences->updateEntry($recurID, 'id', true, 'Recur'.$recurID.'_');
-                           $thisRecurID = $recurID;
-                        }
+                        // And create time entries
+                        $Recurrences->createRecurrenceTimesEntries($thisRecurID, true, true);
 
-                        // Check for any specific dates and if so serialize the array sorted by date
-                        $specDates = serialize(array());
-                        if (isset($_REQUEST['Recur'.$recurID.'_specDate'])) {
-                            asort($_REQUEST['Recur'.$recurID.'_specDate']);
-                            $specDates = serialize($_REQUEST['Recur'.$recurID.'_specDate']);
-                        }
+                    // Otherwise it's an existing recurrence
+                    } else {
+                       $r = $Recurrences->updateEntry($recurID, 'id', true, 'Recur'.$recurID.'_');
+                       $thisRecurID = $recurID;
+                    }
 
-                        // If there's any difference, then update the specific_dates field
-                        if ($specDates != $r['fieldData']['specified_dates_unserialized']) {
-                            $this->wpdb->query("
-                                UPDATE ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences
-                                   SET specific_dates = '$specDates'
-                                 WHERE id = $thisRecurID;
-                            ");
-                        }
+                    // Check for any specific dates and if so serialize the array sorted by date
+                    $specDates = serialize(array());
+                    if (isset($_REQUEST['Recur'.$recurID.'_specDate'])) {
+                        asort($_REQUEST['Recur'.$recurID.'_specDate']);
+                        $specDates = serialize($_REQUEST['Recur'.$recurID.'_specDate']);
+                    }
 
+                    // If there's any difference, then update the specific_dates field
+                    if ($specDates != $r['fieldData']['specified_dates_unserialized']) {
+                        $this->wpdb->query("
+                            UPDATE ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences
+                               SET specific_dates = '$specDates'
+                             WHERE id = $thisRecurID;
+                        ");
                     }
 
-                    // Update our recurrences
-                    $recurrences = $Recurrences->getList("T.event = ".$this->eventID);
+                }
 
-                    // Check for any updated recurrences
-                    if (isset($_REQUEST['recurUpdated']) && count($_REQUEST['recurUpdated']) > 0) {
-                        foreach ($_REQUEST['recurUpdated'] as $r) {
+                // Update our recurrences
+                $recurrences = $Recurrences->getList("T.event = ".$this->eventID);
 
-                            // If we have a recurID as a value, then update this recurrence times
-                            if ($r) {
-                                $Recurrences->createRecurrenceTimesEntries($r, true, true);
-                            }
+                // Check for any updated recurrences
+                if (isset($_REQUEST['recurUpdated']) && count($_REQUEST['recurUpdated']) > 0) {
+                    foreach ($_REQUEST['recurUpdated'] as $r) {
+
+                        // If we have a recurID as a value, then update this recurrence times
+                        if ($r) {
+                            $Recurrences->createRecurrenceTimesEntries($r, true, true);
                         }
                     }
-
                 }
 
-                $haveEvent = true;
-                $view = 'edit';
+            }
 
-                glmClearShortcodeCache();
+            $haveEvent = true;
+            $view = 'edit';
 
-                break;
+            glmClearShortcodeCache();
 
-            case 'clone':
-                //echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
-                //exit;
-                // Load Event Clone Class
-                require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/glmEventClone.php';
-                $ClonedEvent = new GlmEventClone( $this->wpdb, $this->config );
+            break;
 
-                // Clone the current event
-                $this->eventID = $ClonedEvent->cloneEvent( $this->eventID );
+        case 'clone':
+            //echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+            //exit;
+            // Load Event Clone Class
+            require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/glmEventClone.php';
+            $ClonedEvent = new GlmEventClone( $this->wpdb, $this->config );
 
-                // Update the name slug for this event
-                $this->updateSlug( $this->eventID );
+            // Clone the current event
+            $this->eventID = $ClonedEvent->cloneEvent( $this->eventID );
 
-                // Reset the editEntry for this new event
-                $event = $this->editEntry( $this->eventID );
+            // Update the name slug for this event
+            $this->updateSlug( $this->eventID );
 
-                // Set the view file
-                $view = 'edit';
-                $haveEvent = true;
-                break;
+            // Reset the editEntry for this new event
+            $event = $this->editEntry( $this->eventID );
 
-            case 'delete':
+            // Set the view file
+            $view = 'edit';
+            $haveEvent = true;
+            break;
 
-                $event = $this->deleteEvent($this->eventID);
+        case 'delete':
 
-                if ($event) {
-                    $eventDeleted = true;
+            $event = $this->deleteEvent($this->eventID);
 
-                    // Also ask to have event removed from search engine
-                    $removeEventIndex = true;
-                    $eventSlug = $event['name_slug'];
+            if ($event) {
+                $eventDeleted = true;
 
-                    glmClearShortcodeCache();
-                } else {
-                    $eventDeleteError = true;
-                }
+                // Also ask to have event removed from search engine
+                $removeEventIndex = true;
+                $eventSlug = $event['name_slug'];
 
-            case 'list':
-            default:
+                glmClearShortcodeCache();
+            } else {
+                $eventDeleteError = true;
+            }
 
+        case 'list':
+        default:
 
-                $where = 'true';
+            $where = 'true';
 
-                // If we have a back request then go through the PHP_SESSION
-                // and extract them into the REQUEST array.
-                if ( isset( $_REQUEST['back'] ) && filter_var( $_REQUEST['back'], FILTER_VALIDATE_BOOLEAN ) ) {
-                    if ( isset( $_SESSION['search'] ) && is_array( $_SESSION['search'] ) ) {
-                        foreach ( $_SESSION['search'] as $varName => $sessValue ) {
-                            $_REQUEST[$varName] = $sessValue;
-                        }
+            // If we have a back request then go through the PHP_SESSION
+            // and extract them into the REQUEST array.
+            if ( isset( $_REQUEST['back'] ) && filter_var( $_REQUEST['back'], FILTER_VALIDATE_BOOLEAN ) ) {
+                if ( isset( $_SESSION['search'] ) && is_array( $_SESSION['search'] ) ) {
+                    foreach ( $_SESSION['search'] as $varName => $sessValue ) {
+                        $_REQUEST[$varName] = $sessValue;
                     }
                 }
+            }
 
-                // Check for paging
-                if ( isset( $_REQUEST['pageSelect'] ) ) {
-                    $_SESSION['search']['pageSelect'] = $_REQUEST['pageSelect'];
-                } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['pageSelect'] ) ) {
-                    unset( $_SESSION['search']['pageSelect'] );
-                }
-                if ( isset( $_REQUEST['nextStart'] ) ) {
-                    $_SESSION['search']['nextStart'] = $_REQUEST['nextStart'];
-                } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['nextStart'] ) ) {
-                    unset( $_SESSION['search']['nextStart'] );
-                }
-                if ( isset( $_REQUEST['prevStart'] ) ) {
-                    $_SESSION['search']['prevStart'] = $_REQUEST['prevStart'];
-                } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['prevStart'] ) ) {
-                    unset( $_SESSION['search']['prevStart'] );
-                }
-
-                // Check for Archived filter
-                if (isset($_REQUEST['filterArchived']) && $_REQUEST['filterArchived'] == 'on') {
-                    $filterArchived = true;
-                    $_SESSION['search']['archived'] = true;
-                    $where .= " AND status = " . $this->config['status_numb']['Archived'];
-                } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['filterArchived'] ) ) {
-                    unset( $_SESSION['search']['archived'] );
-                }
+            // Check for paging
+            if ( isset( $_REQUEST['pageSelect'] ) ) {
+                $_SESSION['search']['pageSelect'] = $_REQUEST['pageSelect'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['pageSelect'] ) ) {
+                unset( $_SESSION['search']['pageSelect'] );
+            }
+            if ( isset( $_REQUEST['nextStart'] ) ) {
+                $_SESSION['search']['nextStart'] = $_REQUEST['nextStart'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['nextStart'] ) ) {
+                unset( $_SESSION['search']['nextStart'] );
+            }
+            if ( isset( $_REQUEST['prevStart'] ) ) {
+                $_SESSION['search']['prevStart'] = $_REQUEST['prevStart'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['prevStart'] ) ) {
+                unset( $_SESSION['search']['prevStart'] );
+            }
 
-                // Check for Pending filter
-                if (isset($_REQUEST['filterPending']) && $_REQUEST['filterPending'] == 'on') {
-                    $filterPending = true;
-                    $_SESSION['search']['pending'] = true;
-                    $where .= " AND status = " . $this->config['status_numb']['Pending'];
-                } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['filterPending'] ) ) {
-                    unset( $_SESSION['search']['pending'] );
-                }
+            // Check for Archived filter
+            if (isset($_REQUEST['filterArchived']) && $_REQUEST['filterArchived'] == 'on') {
+                $filterArchived = true;
+                $_SESSION['search']['archived'] = true;
+                $where .= " AND status = " . $this->config['status_numb']['Archived'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['filterArchived'] ) ) {
+                unset( $_SESSION['search']['archived'] );
+            }
 
-                // Check for Featured filter
-                if (isset($_REQUEST['filterFeatured']) && $_REQUEST['filterFeatured'] == 'on') {
-                    $filterFeatured = true;
-                    $_SESSION['search']['featured'] = true;
-                    $where .= " AND featured = true";
-                } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['filterFeatured'] ) ) {
-                    unset( $_SESSION['search']['featured'] );
-                }
+            // Check for Pending filter
+            if (isset($_REQUEST['filterPending']) && $_REQUEST['filterPending'] == 'on') {
+                $filterPending = true;
+                $_SESSION['search']['pending'] = true;
+                $where .= " AND status = " . $this->config['status_numb']['Pending'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['filterPending'] ) ) {
+                unset( $_SESSION['search']['pending'] );
+            }
 
-                // Add "selected" element default false;
-                reset($categories);
-                foreach ( $categories as $k => $v ) {
-                    $categories[$k]['selected'] = false;
-                }
+            // Check for Featured filter
+            if (isset($_REQUEST['filterFeatured']) && $_REQUEST['filterFeatured'] == 'on') {
+                $filterFeatured = true;
+                $_SESSION['search']['featured'] = true;
+                $where .= " AND featured = true";
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['filterFeatured'] ) ) {
+                unset( $_SESSION['search']['featured'] );
+            }
 
-                // Check if there is a category filter (multi-select)
-                if (isset($_REQUEST['filterCategories']) && count($_REQUEST['filterCategories']) > 0) {
+            // Add "selected" element default false;
+            reset($categories);
+            foreach ( $categories as $k => $v ) {
+                $categories[$k]['selected'] = false;
+            }
 
-                    $cats = '';
-                    $catsSep = '';
+            // Check if there is a category filter (multi-select)
+            if (isset($_REQUEST['filterCategories']) && count($_REQUEST['filterCategories']) > 0) {
 
-                    // For each selected category
-                    foreach($_REQUEST['filterCategories'] as $c) {
-                        $cats .= $catsSep.$c;
-                        $catsSep = ',';
-                        $categories[$c]['selected'] = true;
-                    }
-                    $_SESSION['search']['cats'] = $cats;
-
-                    $where .= " AND id in (
-                            SELECT DISTINCT(EC.event)
-                              FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."event_categories EC,
-                                   ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories C
-                             WHERE (
-                                   EC.category in ($cats)
-                                   OR (C.parent in ($cats) AND EC.category = C.id)
-                                   )
-                    )";
-                } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['filterCategories'] ) ) {
-                    unset( $_SESSION['search']['cats'] );
-                }
+                $cats = '';
+                $catsSep = '';
 
-                // Check if we have a Text Search string
-                if (isset($_REQUEST['textSearch']) && trim($_REQUEST['textSearch']) != '') {
-                    $textSearch = trim($_REQUEST['textSearch']);
-                    $where .= " AND name LIKE '%$textSearch%'";
-                    $_SESSION['search']['textSearch'] = $textSearch;
-                } else if ( isset( $_REQUEST['searched'] ) && trim($_REQUEST['textSearch']) == '' ) {
-                    unset( $_SESSION['search']['textSearch'] );
+                // For each selected category
+                foreach($_REQUEST['filterCategories'] as $c) {
+                    $cats .= $catsSep.$c;
+                    $catsSep = ',';
+                    $categories[$c]['selected'] = true;
                 }
+                $_SESSION['search']['cats'] = $cats;
+
+                $where .= " AND id in (
+                        SELECT DISTINCT(EC.event)
+                          FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."event_categories EC,
+                               ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories C
+                         WHERE (
+                               EC.category in ($cats)
+                               OR (C.parent in ($cats) AND EC.category = C.id)
+                               )
+                )";
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['filterCategories'] ) ) {
+                unset( $_SESSION['search']['cats'] );
+            }
 
+            // Check if we have a Text Search string
+            if (isset($_REQUEST['textSearch']) && trim($_REQUEST['textSearch']) != '') {
+                $textSearch = trim($_REQUEST['textSearch']);
+                $where .= " AND name LIKE '%$textSearch%'";
+                $_SESSION['search']['textSearch'] = $textSearch;
+            } else if ( isset( $_REQUEST['searched'] ) && trim($_REQUEST['textSearch']) == '' ) {
+                unset( $_SESSION['search']['textSearch'] );
+            }
 
-                // If we have a From date
-                $dateWhere = '';
-                if (isset($_REQUEST['fromDate']) && trim($_REQUEST['fromDate']) != '') {
-                    $fromDate = date('m/d/Y', strtotime($_REQUEST['fromDate']));
-                    $fromMYSQL = date('Y-m-d', strtotime($fromDate));
-                    $dateWhere = " end_time >= '$fromMYSQL' ";
-                    $_SESSION['search']['fromDate'] = $fromDate;
-                } else if ( !isset( $_REQUEST['searched'] ) ) {
-                    $fromDate = date('m/d/Y');
-                    $fromMYSQL = date('Y-m-d', strtotime($fromDate));
-                    $dateWhere = " end_time >= '$fromMYSQL' ";
-                } else if ( isset( $_REQUEST['searched'] ) && trim($_REQUEST['fromDate']) == '' ) {
-                    unset( $_SESSION['search']['fromDate'] );
-                }
-
-                // If we have a to Date
-                if (isset($_REQUEST['toDate']) && trim($_REQUEST['toDate']) != '') {
 
-                    $toDate = date('m/d/Y', strtotime($_REQUEST['toDate']));
-                    $toMYSQL = date('Y-m-d', strtotime($toDate." +1 day"));
+            // If we have a From date
+            $dateWhere = '';
+            if (isset($_REQUEST['fromDate']) && trim($_REQUEST['fromDate']) != '') {
+                $fromDate = date('m/d/Y', strtotime($_REQUEST['fromDate']));
+                $fromMYSQL = date('Y-m-d', strtotime($fromDate));
+                $dateWhere = " end_time >= '$fromMYSQL' ";
+                $_SESSION['search']['fromDate'] = $fromDate;
+            } else if ( !isset( $_REQUEST['searched'] ) ) {
+                $fromDate = date('m/d/Y');
+                $fromMYSQL = date('Y-m-d', strtotime($fromDate));
+                $dateWhere = " end_time >= '$fromMYSQL' ";
+            } else if ( isset( $_REQUEST['searched'] ) && trim($_REQUEST['fromDate']) == '' ) {
+                unset( $_SESSION['search']['fromDate'] );
+            }
 
-                    // If we have a from date then we need Parens and AND
-                    if ($dateWhere != '') {
-                        $dateWhere = "( ".$dateWhere." AND start_time <= '$toMYSQL' )";
+            // If we have a to Date
+            if (isset($_REQUEST['toDate']) && trim($_REQUEST['toDate']) != '') {
 
-                    // Otherwise we don't
-                    } else {
-                        $dateWhere = " start_time <= '$toMYSQL' ";
-                    }
-                    $_SESSION['search']['toDate'] = $toDate;
-                } else if ( isset( $_REQUEST['searched'] ) && trim($_REQUEST['toDate']) == '' ) {
-                    unset( $_SESSION['search']['toDate'] );
-                }
+                $toDate = date('m/d/Y', strtotime($_REQUEST['toDate']));
+                $toMYSQL = date('Y-m-d', strtotime($toDate." +1 day"));
 
-                // If we have from and to dates, do search for those inclusive
+                // If we have a from date then we need Parens and AND
                 if ($dateWhere != '') {
-                    $where .= "
-                        AND id in (
-                            SELECT DISTINCT(event)
-                              FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."times
-                             WHERE $dateWhere
-                               AND active
-                        )
-                    ";
-                }
+                    $dateWhere = "( ".$dateWhere." AND start_time <= '$toMYSQL' )";
 
-                // Check if the list is for a specific member
-                if (defined('GLM_EVENTS_MEMBER_MENU') || $memberID) {
-                    $where .= " AND ref_dest = $memberID";
-                    $_SESSION['search']['memberID'] = $memberID;
+                // Otherwise we don't
+                } else {
+                    $dateWhere = " start_time <= '$toMYSQL' ";
                 }
+                $_SESSION['search']['toDate'] = $toDate;
+            } else if ( isset( $_REQUEST['searched'] ) && trim($_REQUEST['toDate']) == '' ) {
+                unset( $_SESSION['search']['toDate'] );
+            }
 
-                // Get the total number of events listed
-                $numbEvents = $this->getStats($where);
+            // If we have from and to dates, do search for those inclusive
+            if ($dateWhere != '') {
+                $where .= "
+                    AND id in (
+                        SELECT DISTINCT(event)
+                          FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."times
+                         WHERE $dateWhere
+                           AND active
+                    )
+                ";
+            }
 
-                // If the number of events is less than a page, don't do paging
-                if ($numbEvents <= $limit) {
-                    $paging = false;
-                }
+            // Check if the list is for a specific member
+            if (defined('GLM_EVENTS_MEMBER_MENU') || $memberID) {
+                $where .= " AND ref_dest = $memberID";
+                $_SESSION['search']['memberID'] = $memberID;
+            }
+
+            // Get the total number of events listed
+            $numbEvents = $this->getStats($where);
 
-                // Get full list of names matching this where clause for search box
-                $namesList = $this->getIdName($where);
+            // If the number of events is less than a page, don't do paging
+            if ($numbEvents <= $limit) {
+                $paging = false;
+            }
 
-                // Check if we're doing paging
-                if (isset($_REQUEST['pageSelect'])) {
-                    // If request is for Next
-                    if ($_REQUEST['pageSelect'][0] == 'N') {
-                        $newStart = $_REQUEST['nextStart'] - 0;
+            // Get full list of names matching this where clause for search box
+            $namesList = $this->getIdName($where);
 
-                    // Otherwise it must be Previous
-                    } else {
-                        $newStart = $_REQUEST['prevStart'] - 0;
-                    }
+            // Check if we're doing paging
+            if (isset($_REQUEST['pageSelect'])) {
+                // If request is for Next
+                if ($_REQUEST['pageSelect'][0] == 'N') {
+                    $newStart = $_REQUEST['nextStart'] - 0;
 
-                    if ($newStart > 0) {
-                        $start = $newStart;
-                    }
+                // Otherwise it must be Previous
+                } else {
+                    $newStart = $_REQUEST['prevStart'] - 0;
                 }
 
-                if( isset($_SESSION['search']['pageSelect']) ){
-                     // If request is for Next
-                    if ($_SESSION['search']['pageSelect'][0] == 'N') {
-                        $newStart = $_SESSION['search']['nextStart'] - 0;
-
-                    // Otherwise it must be Previous
-                    } else {
-                        $newStart = $_SESSION['search']['prevStart'] - 0;
-                    }
-                    if ($newStart > 0) {
-                        $start = $newStart;
-                    }
+                if ($newStart > 0) {
+                    $start = $newStart;
                 }
+            }
+
+            if( isset($_SESSION['search']['pageSelect']) ){
+                 // If request is for Next
+                if ($_SESSION['search']['pageSelect'][0] == 'N') {
+                    $newStart = $_SESSION['search']['nextStart'] - 0;
 
-                // Get the list of events and determine number of events in list
-                $saveFLT = $this->postFirstAndLastTimes;
-                $this->postFirstAndLastTimes = true;
-                $orderBy = 'name';
-                $orderBy = "(select min(start_time) FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE T.id = event),name";
-                $eventsResult = $this->getList($where, $orderBy, true, 'id', $start, $limit);
-                $this->postFirstAndLastTimes = $saveFLT;
-
-                // Get paging results
-                $numbDisplayed = $eventsResult['returned'];
-                $lastDisplayed = $eventsResult['last'];
-                if ($start == 1) {
-                    $prevStart = false;
+                // Otherwise it must be Previous
                 } else {
-                    $prevStart = $start - $limit;
-                    if ($start < 1) {
-                        $start = 1;
-                    }
+                    $newStart = $_SESSION['search']['prevStart'] - 0;
                 }
-                if ($eventsResult['returned'] == $limit) {
-                    $nextStart = $start + $limit;
+                if ($newStart > 0) {
+                    $start = $newStart;
                 }
+            }
 
-                // since we're doing paging, we have to break out just the events data
-                $events = $eventsResult['list'];
-                if ( is_array( $events ) && !empty( $events ) && count($events) > 0 ) {
-                    $haveEvents = true;
+            // Get the list of events and determine number of events in list
+            $saveFLT = $this->postFirstAndLastTimes;
+            $this->postFirstAndLastTimes = true;
+            $orderBy = 'name';
+            $orderBy = "(select min(start_time) FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE T.id = event),name";
+            $eventsResult = $this->getList($where, $orderBy, true, 'id', $start, $limit);
+            $this->postFirstAndLastTimes = $saveFLT;
+
+            // Get paging results
+            $numbDisplayed = $eventsResult['returned'];
+            $lastDisplayed = $eventsResult['last'];
+            if ($start == 1) {
+                $prevStart = false;
+            } else {
+                $prevStart = $start - $limit;
+                if ($start < 1) {
+                    $start = 1;
                 }
-                unset($eventsResult);
+            }
+            if ($eventsResult['returned'] == $limit) {
+                $nextStart = $start + $limit;
+            }
+
+            // since we're doing paging, we have to break out just the events data
+            $events = $eventsResult['list'];
+            if ( is_array( $events ) && !empty( $events ) && count($events) > 0 ) {
+                $haveEvents = true;
+            }
+            unset($eventsResult);
 
                 break;
 
@@ -1130,7 +1129,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
                 if ($newCategory) {
 
                     // Get the full category list again
-                    $this->categories = $Categories->getListSortedParentChild();
+                    // $this->categories = $Categories->getListSortedParentChild();
 
                 }