merged in branch for banners and new member search into trunk
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 26 Dec 2013 14:58:26 +0000 (14:58 +0000)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 26 Dec 2013 14:58:26 +0000 (14:58 +0000)
13 files changed:
Toolkit/Banners/Banner.php
Toolkit/Banners/BannersIterator.php
Toolkit/Banners/Database/tables/banners2counties.sql [new file with mode: 0644]
Toolkit/Banners/Forms/EditBanner.php
Toolkit/Members/SearchDisplay.php
Toolkit/Members/SearchQueryGenerator.php
Toolkit/Members/UserSearchForm.php
Toolkit/Members/formAjax.php
Toolkit/Members/templates/userSearchForm.html
Toolkit/Page.php
config/server.ini
libjs/findATrail.js [new file with mode: 0644]
templates/template.html

index bef0010..757ce12 100644 (file)
@@ -121,6 +121,13 @@ class Toolkit_Banners_Banner
      */
        private $_memberCategories;
 
+    /**
+     * member counties the banner is assigned to
+     * @var    type
+     * @access private
+     */
+    private $_memberCounties;
+
     //  }}}
     //  {{{ __construct()
 
@@ -152,24 +159,26 @@ class Toolkit_Banners_Banner
                $business = null,
                array $toolboxPages = null,
                Toolkit_Members_CategoriesIterator $memberCategories = null,
+        array $memberCounties = null,
                $description = null,
                $id = null,
         $embedcode = false
        ) {
-                       $this->_image = $image;
-                       $this->_position = $position;
-                       $this->_url = $url;
-                       $this->_active = $active;
-                       $this->_external = $external;
-                       $this->_business = $business;
-                       $this->_campaign = $campaign;
-                       $this->_campaignId = $campaign->getId();
-                       $this->_toolboxPages = $toolboxPages;
-                       $this->_memberCategories = $memberCategories;
-                       $this->_description = $description;
-                       $this->_id = $id;
-            $this->_embedcode = $embedcode;
-       }
+        $this->_image            = $image;
+        $this->_position         = $position;
+        $this->_url              = $url;
+        $this->_active           = $active;
+        $this->_external         = $external;
+        $this->_business         = $business;
+        $this->_campaign         = $campaign;
+        $this->_campaignId       = $campaign->getId();
+        $this->_toolboxPages     = $toolboxPages;
+        $this->_memberCategories = $memberCategories;
+        $this->_memberCounties   = $memberCounties;
+        $this->_description      = $description;
+        $this->_id               = $id;
+        $this->_embedcode        = $embedcode;
+    }
 
     //  }}}
     // {{{     create()
@@ -205,6 +214,7 @@ class Toolkit_Banners_Banner
                $business = null,
                array $toolboxPages = null,
                Toolkit_Members_CategoriesIterator $memberCategories = null,
+        array $memberCounties = null,
                $description = null,
                $id = null,
         $embedcode = false
@@ -229,6 +239,7 @@ class Toolkit_Banners_Banner
                        $business,
                        $toolboxPages,
                        $memberCategories,
+            $memberCounties,
                        $description,
                        $id,
             $embedcode
@@ -349,6 +360,7 @@ class Toolkit_Banners_Banner
                                $row['business'],
                                self::_fetchToolboxPages($dbh, $id),
                                $memberCategories,
+                self::_fetchMemberCounties($dbh, $id),
                                $row['description'],
                                $id,
                 $row['embedcode']
@@ -371,7 +383,7 @@ class Toolkit_Banners_Banner
      * @return object  Return description (if any) ...
      * @access private
      */
-       private function _fetchMemberCategories(PDO $dbh, $id)
+       static private function _fetchMemberCategories(PDO $dbh, $id)
        {
                $memberCategoriesIterator = Toolkit_Members_CategoriesIterator::create();
                $sql = "
@@ -409,12 +421,12 @@ class Toolkit_Banners_Banner
      * @return array toolbox page ids
      * @access private
      */
-       private function _fetchToolboxPages(PDO $dbh, $id)
+       static private function _fetchToolboxPages(PDO $dbh, $id)
        {
                $sql = "
-                       SELECT *
-                         FROM banners2navpages
-                        WHERE bid = :bid";
+        SELECT *
+          FROM banners2navpages
+         WHERE bid = :bid";
 
                $stmt = $dbh->prepare($sql);
                $stmt->bindParam(':bid', $id, PDO::PARAM_INT);
@@ -428,6 +440,26 @@ class Toolkit_Banners_Banner
 
     //  }}}
 
+    static private function _fetchMemberCounties(PDO $dbh, $banner)
+    {
+        $counties = array();
+        try {
+            $sql = "
+            SELECT *
+              FROM members.banners2counties
+             WHERE banner = :banner";
+            $stmt = $dbh->prepare($sql);
+            $stmt->bindParam(':banner', $banner, PDO::PARAM_INT);
+            $stmt->execute();
+            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $counties[] = $row['county'];
+            }
+        } catch (PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        return $counties;
+    }
+
     //  {{{ getActive()
 
 
@@ -575,6 +607,10 @@ class Toolkit_Banners_Banner
        }
 
     //  }}}
+    public function getMemberCounties()
+    {
+        return $this->_memberCounties;
+    }
     //  {{{ getPosition()
 
 
@@ -994,6 +1030,10 @@ class Toolkit_Banners_Banner
                                        $this->_id
                                );
                        }
+            $this->_removeMemberCounties($dbh, $this->_id);
+            $this->_updateMemberCounties(
+                $dbh, $this->_id, $this->_memberCounties
+            );
 
                        return $dbh->commit();
                } catch (PDOException $e) {
@@ -1037,6 +1077,27 @@ class Toolkit_Banners_Banner
        }
 
     //  }}}
+    private function _updateMemberCounties(
+        PDO $dbh,
+        $banner,
+        $counties
+    ) {
+        if (!empty($counties)) {
+                       $sql = Toolkit_Common::createSQLInsert(
+                               'banners2counties',
+                               array('banner', 'county')
+                       );
+                       $stmt = $dbh->prepare($sql);
+                       $stmt->bindParam(':banner', $banner, PDO::PARAM_INT);
+                       foreach ($counties as $i) {
+                               //      make sure we have an integer
+                               if (filter_var($i, FILTER_VALIDATE_INT)) {
+                                       $stmt->bindParam(':county', $i, PDO::PARAM_INT);
+                                       $stmt->execute();
+                               }
+                       }
+               }
+    }
     //  {{{ _updateBannerCategories()
 
     /**
@@ -1096,6 +1157,17 @@ class Toolkit_Banners_Banner
 
        //      }}}
 
+    private function _removeMemberCounties(PDO $dbh, $banner)
+    {
+        $sql = "
+                       DELETE FROM banners2counties
+                        WHERE banner = :banner";
+
+               $stmt = $dbh->prepare($sql);
+               $stmt->bindParam(':banner', $banner, PDO::PARAM_INT);
+               $stmt->execute();
+    }
+
        //      {{{     _removeBannerCategories()
 
     /**
index fce121c..9c511ff 100644 (file)
@@ -337,6 +337,16 @@ class Toolkit_Banners_BannersIterator implements IteratorAggregate
                   FROM banners2navpages
                  WHERE catid = :pageCatid";
 
+            if ($county = filter_var($_REQUEST['countyId'], FILTER_VALIDATE_INT)) {
+                $selectBannersAssignedToCounties = "
+                 UNION
+                SELECT banner
+                  FROM banners2counties
+                 WHERE county = {$county}";
+            } else {
+                $selectBannersAssignedToCounties = '';
+            }
+
             $memberCatsOnPage = $this->_getMemberCatsAvailableOnPage(
                 $pdo,
                 $categoriesIterator,
@@ -368,7 +378,8 @@ class Toolkit_Banners_BannersIterator implements IteratorAggregate
                         INTERSECT
                                        ($selectBannersAssignedToPage
                                UNION
-                                       $selectBannersAssignedToMemberCatsOnPage)
+                                       $selectBannersAssignedToMemberCatsOnPage
+                    $selectBannersAssignedToCounties)
                         INTERSECT
                                ($bannersWithinRunDate)";
 
diff --git a/Toolkit/Banners/Database/tables/banners2counties.sql b/Toolkit/Banners/Database/tables/banners2counties.sql
new file mode 100644 (file)
index 0000000..22f93fe
--- /dev/null
@@ -0,0 +1,8 @@
+DROP TABLE IF EXISTS members.banners2counties CASCADE;
+
+CREATE TABLE members.banners2counties(
+    banner INTEGER NOT NULL,
+    county INTEGER NOT NULL
+);
+
+GRANT ALL ON members.banners2counties TO nobody;
index 22c1c3b..82cb554 100644 (file)
@@ -189,6 +189,7 @@ class Toolkit_Banners_Forms_EditBanner extends Toolkit_FormBuilder
                     'contact_email'    => $banner->getCampaign()->getContact()->getEmail(),
                     'report_frequency' => $banner->getCampaign()->getReportFrequency(),
                     'pages'            => $banner->getToolboxPages(),
+                    'member_counties'  => $banner->getMemberCounties(),
                     'sdate' => array(
                         'm' => $banner->getCampaign()->getSDate()->getMonth(),
                         'd' => $banner->getCampaign()->getSDate()->getDay(),
@@ -374,6 +375,20 @@ class Toolkit_Banners_Forms_EditBanner extends Toolkit_FormBuilder
                                )
             );
                }
+        $e[] = array(
+            'type'    => 'select',
+            'req'     => false,
+            'name'    => 'member_counties',
+            'display' => 'Member Counties',
+            'opts' => array(
+                '' => '-- None --'
+            ) + $this->getMemberCounties($dbh),
+            'att' => array(
+                'multiple' => 'multiple',
+                'id'       => 'member_counties',
+                'size'     => 10
+            )
+        );
                $e[] = array(
             'type'    => 'date',
             'req'     => true,
@@ -706,6 +721,24 @@ class Toolkit_Banners_Forms_EditBanner extends Toolkit_FormBuilder
 
        //      }}}
 
+    protected function getMemberCounties(PDO $dbh)
+    {
+        $counties = array();
+        try {
+            $sql = "
+              SELECT county_id,county_name
+                FROM members.county
+            ORDER BY county_name";
+            $stmt = $dbh->query($sql);
+            while ($county = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $counties[$county['county_id']] = $county['county_name'];
+            }
+        } catch (PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        return $counties;
+    }
+
     //  {{{ getMemberCategories()
 
        /**
@@ -828,6 +861,8 @@ class Toolkit_Banners_Forms_EditBanner extends Toolkit_FormBuilder
                }
 
                $values['pages'] = (array) $values['pages'];
+        $values['member_counties']
+            = (array) $values['member_counties'];
 
                $sdateStr        = implode('/', $values['sdate']);
                $values['sdate'] = new Date(strtotime($sdateStr));
@@ -922,10 +957,13 @@ class Toolkit_Banners_Forms_EditBanner extends Toolkit_FormBuilder
                        $values['business'],
                        $values['pages'],
                        $memberCategories,
+            $values['member_counties'],
                        $values['description'],
                        $_GET['id'],
             $values['embedcode']
                );
+//        echo '<pre>'.print_r($banner, true).'</pre>';
+//        exit;
 
                return ctype_digit((string)$_GET['id'])
                        ? $banner->update($dbh, $config)
index 6e86342..e986558 100644 (file)
@@ -37,12 +37,13 @@ class Toolkit_Members_SearchDisplay
         $posted = filter_var_array(
             $_REQUEST,
             array(
-                'member_name' => FILTER_SANITIZE_STRING,
-                'activityId'  => FILTER_VALIDATE_INT,
-                'parkId'      => FILTER_VALIDATE_INT,
-                'regionId'    => FILTER_VALIDATE_INT,
-                'countyId'    => FILTER_VALIDATE_INT,
-                'amenity'     => array(
+                'member_name'   => FILTER_SANITIZE_STRING,
+                'activityId'    => FILTER_VALIDATE_INT,
+                'destinationId' => FILTER_VALIDATE_INT,
+                'parkId'        => FILTER_VALIDATE_INT,
+                'regionId'      => FILTER_VALIDATE_INT,
+                'countyId'      => FILTER_VALIDATE_INT,
+                'amenity'       => array(
                     'filter' => FILTER_VALIDATE_INT,
                     'flags'  => FILTER_FORCE_ARRAY
                 )
@@ -60,6 +61,10 @@ class Toolkit_Members_SearchDisplay
             $parkName = $this->getCategoryName($dbh, $parkId);
             $this->_searchTerms->offsetSet('park', $parkName);
         }
+        if ($destinationId) {
+            $destinationName = $this->getCategoryName($dbh, $destinationId);
+            $this->_searchTerms->offsetSet('destination', $destinationName);
+        }
         if ($regionId) {
             $regionName = $this->getRegionName($dbh, $regionId);
             $this->_searchTerms->offsetSet('region', $regionName);
@@ -107,6 +112,10 @@ class Toolkit_Members_SearchDisplay
                     $html .= 'Parks ';
                 }
             }
+            if ($this->_searchTerms->offsetExists('destination')) {
+                $dest = $this->_searchTerms->offsetGet('destination');
+                $html .= 'in ' . $dest . ' ';
+            }
             if ($this->_searchTerms->offsetExists('region')) {
                 $html .= 'in ' . $this->_searchTerms->offsetGet('region')
                     . ' Region ';
index 720f6d7..ba5197e 100644 (file)
@@ -233,6 +233,7 @@ class Toolkit_Members_SearchQueryGenerator
                 'sub_category_id' => FILTER_VALIDATE_INT,
                 'activityId'      => FILTER_VALIDATE_INT,
                 'parkId'          => FILTER_VALIDATE_INT,
+                'destinationId'   => FILTER_VALIDATE_INT,
                 'regionId'        => FILTER_VALIDATE_INT,
                 'countyId'        => FILTER_VALIDATE_INT,
                 'activity'        => array(
@@ -276,6 +277,12 @@ class Toolkit_Members_SearchQueryGenerator
                   FROM member_category
                  WHERE category_id = {$parkId})";
         }
+        if ($destinationId) {
+            $params[] = "m.member_id IN (
+                SELECT member_id
+                  FROM member_category
+                 WHERE category_id = {$destinationId})";
+        }
 //        if ($regionId) {
 //            $params[] = "m.region = {$regionId}";
 //        }
index 06cce2e..f844a47 100644 (file)
@@ -113,8 +113,9 @@ class Toolkit_Members_UserSearchForm
      */
     protected $dbh;
 
-    const PARENT_CATEGORY_ACTIVITIES = 7;
-    const PARENT_CATEGORY_PARKS      = 8;
+    const PARENT_CATEGORY_ACTIVITIES   = 7;
+    const PARENT_CATEGORY_PARKS        = 8;
+    const PARENT_CATEGORY_DESTINATIONS = 19;
 
        //      }}}
 
@@ -576,13 +577,14 @@ class Toolkit_Members_UserSearchForm
         $tpl = new HTML_Template_Flexy($flexyOpts);
         $tpl->compile($this->formTemplate);
 
-        $activity  = $this->getActivities();
-        $amenities = $this->getMemberAmenities($this->dbh);
-        $parks     = $this->getParks();
-        $regions   = $this->getAvailableRegions($this->dbh);
-        $counties  = $this->getCounties();
+        $activity     = $this->getActivities();
+        $amenities    = $this->getMemberAmenities($this->dbh);
+        $parks        = $this->getParks();
+        $destinations = $this->getDestinations();
+        $regions      = $this->getAvailableRegions($this->dbh);
+        $counties     = $this->getCounties();
 
-        $page          = new stdClass();
+        $page         = new stdClass();
         $page->formURL
             = BASE_URL
             . 'index.php?_qf__SearchForm=&catid=' . $this->_catid
@@ -595,6 +597,10 @@ class Toolkit_Members_UserSearchForm
             = (!empty($parks) && count($parks) > 1)
             ? $parks
             : null;
+        $page->destinations
+            = (!empty($destinations) && count($destinations) > 1)
+            ? $destinations
+            : null;
         $page->regions
             = (!empty($regions) && count($regions) >= 1)
             ? $regions
@@ -670,6 +676,36 @@ class Toolkit_Members_UserSearchForm
         return $parks;
     }
 
+    protected function getDestinations()
+    {
+        $destinatons = array();
+        try {
+            $cats
+                = ($this->memberCatsAssignedToPage)
+                ? " AND (category_id IN ("
+                    .implode(',', $this->memberCatsAssignedToPage).")
+                    OR parent_id IN (".implode(',', $this->memberCatsAssignedToPage)."))"
+                : '';
+            $sql = "
+            SELECT *
+              FROM category
+             WHERE parent_id = "
+                . self::PARENT_CATEGORY_DESTINATIONS
+                . $cats
+                . " AND category_id IN (
+                    SELECT category_id
+                      FROM member_category)"
+                . " ORDER BY name";
+            $stmt = $this->dbh->query($sql);
+            while ($category = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $destinatons[$category['category_id']] = $category['name'];
+            }
+        } catch (PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        return $destinatons;
+    }
+
        //      {{{     setCatId()
 
     /**
index 63fd987..fa6948e 100644 (file)
 <?php
 require_once '../../setup.phtml';
-define('PARENT_CATEGORY_ACTIVITIES', 7);
-define('PARENT_CATEGORY_PARKS', 8);
 
-$activityId = filter_var($_REQUEST['activityId'], FILTER_VALIDATE_INT);
-$parkId     = filter_var($_REQUEST['parkId'], FILTER_VALIDATE_INT);
-$regionId   = filter_var($_REQUEST['regionId'], FILTER_VALIDATE_INT);
-$countyId   = filter_var($_REQUEST['countyId'], FILTER_VALIDATE_INT);
+$searchBy      = filter_var($_REQUEST['search'], FILTER_SANITIZE_STRING);
+$activityId    = filter_var($_REQUEST['activityId'], FILTER_VALIDATE_INT);
+$parkId        = filter_var($_REQUEST['parkId'], FILTER_VALIDATE_INT);
+$destinationId = filter_var($_REQUEST['destinationId'], FILTER_VALIDATE_INT);
+$regionId      = filter_var($_REQUEST['regionId'], FILTER_VALIDATE_INT);
+$countyId      = filter_var($_REQUEST['countyId'], FILTER_VALIDATE_INT);
 
 try {
     $dbh = Toolkit_Database::getInstance();
-
-    if ($activityId) {
+    if ($searchBy == 'counties') {
+        $otherIds
+            = array(
+                Toolkit_Members_UserSearchForm::PARENT_CATEGORY_ACTIVITIES,
+                Toolkit_Members_UserSearchForm::PARENT_CATEGORY_PARKS,
+                Toolkit_Members_UserSearchForm::PARENT_CATEGORY_DESTINATIONS
+            );
+        if ($activityId && $parkId && $destinationId) {
+            $searchIds = array($activityId, $parkId, $destinationId);
+        } else if ($activityId && $parkId) {
+            $searchIds = array($activityId, $parkId);
+        } else if ($activityId) {
+            $searchIds = array($activityId);
+        } else if ($parkId) {
+            $searchIds = array($parkId);
+        } else if ($destinationId) {
+            $searchIds = array($destinationId);
+        }
+        if ($searchIds) {
+            $num = count($searchIds);
+            switch ($num) {
+            case 3:
+                $whereCategory = "WHERE category_id = " . $searchIds[0];
+                $whereCategory .= " AND category_id = " . $searchIds[1];
+                $whereCategory .= " AND category_id = " . $searchIds[2];
+                break;
+            case 2:
+                $whereCategory = "WHERE category_id = " . $searchIds[0];
+                $whereCategory .= " AND category_id = " . $searchIds[1];
+                break;
+            case 1:
+                $whereCategory = "WHERE category_id = " . $searchIds[0];
+                break;
+            }
+        }
+        $sql = "
+        SELECT *
+          FROM members.county
+         WHERE county_id IN (
+               SELECT county
+                 FROM members.member
+                WHERE active = '1'
+                  AND new_member <> true
+                  AND member_id IN (
+                             SELECT member_id
+                               FROM members.member_category
+                             {$whereCategory})
+                      )";
+        $stmt = $dbh->prepare($sql);
+        $stmt->execute();
+        echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
+        exit;
+    }
+    switch ($searchBy) {
+    case 'parks':
+        $searchById
+            = "AND parent_id = "
+            . Toolkit_Members_UserSearchForm::PARENT_CATEGORY_PARKS;
+        $otherIds
+            = array(
+                Toolkit_Members_UserSearchForm::PARENT_CATEGORY_ACTIVITIES,
+                Toolkit_Members_UserSearchForm::PARENT_CATEGORY_DESTINATIONS
+            );
+        if ($activityId && $destinationId) {
+            $searchIds = array($activityId, $destinationId);
+        } else if ($activityId) {
+            $searchIds = array($activityId);
+        } else if ($destinationId) {
+            $searchIds = array($destinationId);
+        }
+        break;
+    case 'activity':
+        $searchById
+            = "AND parent_id = "
+            . Toolkit_Members_UserSearchForm::PARENT_CATEGORY_ACTIVITIES;
+        $otherIds
+            = array(
+                Toolkit_Members_UserSearchForm::PARENT_CATEGORY_PARKS,
+                Toolkit_Members_UserSearchForm::PARENT_CATEGORY_DESTINATIONS
+            );
+        if ($parkId && $destinationId) {
+            $searchIds = array($parkId, $destinationId);
+        } else if ($parkId) {
+            $searchIds = array($parkId);
+        } else if ($destinationId) {
+            $searchIds = array($destinationId);
+        }
+        break;
+    case 'destination':
+        $searchById
+            = "AND parent_id = "
+            . Toolkit_Members_UserSearchForm::PARENT_CATEGORY_DESTINATIONS;
+        $otherIds
+            = array(
+                Toolkit_Members_UserSearchForm::PARENT_CATEGORY_ACTIVITIES,
+                Toolkit_Members_UserSearchForm::PARENT_CATEGORY_PARKS
+            );
+        if ($activityId && $parkId) {
+            $searchIds = array($activityId, $parkId);
+        } else if ($activityId) {
+            $searchIds = array($activityId);
+        } else if ($parkId) {
+            $searchIds = array($parkId);
+        }
+        break;
+    default:
+        return false;
+        break;
+    }
+    $countySearch
+        = ($countyId)
+        ? "AND county = {$countyId}"
+        : '';
+    if ($searchIds) {
+        if (count($searchIds) > 1) {
+            $whereCategory = "category_id = " . $searchIds[0];
+            $whereCategory .= " AND category_id = " . $searchIds[1];
+        } else {
+            $whereCategory = "category_id = " . $searchIds[0];
+        }
         $sql = "
           SELECT category_id,name
             FROM members.category
@@ -21,15 +139,22 @@ try {
                   WHERE member_id IN (
                         SELECT member_id
                           FROM members.member_category
-                         WHERE category_id = :category))
-             AND parent_id = " . PARENT_CATEGORY_PARKS . "
+                         WHERE {$whereCategory}
+                        )
+                    AND member_id IN (
+                                     SELECT member_id
+                                       FROM member
+                                      WHERE active = '1'
+                                        AND new_member <> true
+                                        $countySearch
+                                    )
+                 )
+                 {$searchById}
         ORDER BY name";
-        $stmt = $dbh->prepare($sql);
-        $stmt->bindParam(':category', $activityId, PDO::PARAM_INT);
+        $stmt = $dbh->query($sql);
         $stmt->execute();
         echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
-    }
-    if (isset($_REQUEST['activityId']) && !$activityId) {
+    } else {
         $sql = "
           SELECT category_id,name
             FROM members.category
@@ -42,8 +167,19 @@ try {
                          WHERE category_id IN (
                                SELECT category_id
                                  FROM members.category
-                                WHERE parent_id = " . PARENT_CATEGORY_ACTIVITIES . ")))
-             AND parent_id = " . PARENT_CATEGORY_PARKS . "
+                                WHERE parent_id IN (
+                                " . implode(',', $otherIds) . ")
+                          )
+                    AND member_id IN (
+                                      SELECT member_id
+                                        FROM member
+                                       WHERE active = '1'
+                                         AND new_member <> true
+                                         $countySearch
+                                      )
+                      )
+                  )
+                 {$searchById}
         ORDER BY name";
         $stmt = $dbh->prepare($sql);
         $stmt->execute();
index 3e7df1e..e96e258 100644 (file)
         <input type="hidden" name="search" value="1">
         <input type="hidden" name="catid" value="<?php echo $_REQUEST['catid'];?>">
         <div id="col2">
-            <div>Search by Activities &amp; Parks:</div>
-            <div flexy:if="counties" class="fieldcontain">
+            <div>Search by:</div>
+            <div flexy:if="activities" class="fieldcontain">
                 <select name="activityId" id="advSearchActivities">
                     <option value="">Activities</option>
                     {foreach:activities,id,name}
                     {end:}
                 </select>
             </div>
-            <div flexy:if="counties" class="fieldcontain">
+            <div flexy:if="parks" class="fieldcontain">
                 <select name="parkId" id="advSearchParks">
                     <option value="">Parks</option>
                     {foreach:parks,id,name}
                     ?>
                     {end:}
                 </select>
+            </div>
+            <div flexy:if="destinations" class="fieldcontain">
+                <select name="destinationId" id="advSearchDest">
+                    <option value="">Destinations</option>
+                    {foreach:destinations,id,name}
+                    <?php
+                    echo '<option value="'.$id.'"
+                    '.(($id == $_REQUEST['destinationId'])?'selected':'')
+                    .'>'.$name.'</option>';
+                    ?>
+                    {end:}
+                </select>
                 <input
                 type="submit"
                 id="trail-search-form-ap"
         if ($("#advSearchRegions").val()) {
             updateCountySelect();
         }
+        // update when activities changes
         $("#advSearchActivities").change(function(){
             updateParksSelect();
+            updateDestinationSelect();
         });
         if ($("#advSearchActivities").val()) {
             updateParksSelect();
+            updateDestinationSelect();
+        }
+        //update when parks changes
+        $("#advSearchParks").change(function(){
+            updateActivitySelect();
+            updateDestinationSelect();
+        });
+        if ($("#advSearchParks").val()) {
+            updateActivitySelect();
+            updateDestinationSelect();
+        }
+        // update when destination changes
+        $("#advSearchDest").change(function(){
+            updateParksSelect();
+            updateActivitySelect();
+        });
+        if ($("#advSearchDest").val()) {
+            updateParksSelect();
+            updateActivitySelect();
         }
     });
     function updateParksSelect() {
         $.ajax({
             dataType: 'json',
             url: 'ajax/form.json',
-            data: {'activityId': $("#advSearchActivities").val()},
+            data: {
+                'search': 'parks',
+                'activityId': $("#advSearchActivities").val(),
+                'destinationId': $("#advSearchDest").val()
+            },
             success: function(data) {
                 var currentVal = $("#advSearchParks").val();
                 $("#advSearchParks").html('<option value="">Parks</option>');
                 $.each(data, function(index, park) {
-                    //console.log(park);
                     var sel
                         = (currentVal == park.category_id)
                         ? ' selected'
                     $("#advSearchParks").append('<option value="' + park.category_id
                             + '" '+sel+'>'
                             + park.name + '</option>');
-                    //console.log('park: ' + park.name);
                 });
             }
         });
     }
+    function updateActivitySelect() {
+        $.ajax({
+            dataType: 'json',
+            url: 'ajax/form.json',
+            data: {
+                'search': 'activity',
+                'parkId': $("#advSearchParks").val(),
+                'destinationId': $("#advSearchDest").val()
+            },
+            success: function(data) {
+                var currentVal = $("#advSearchActivities").val();
+                $("#advSearchActivities").html('<option value="">Activities</option>');
+                $.each(data, function(index, activity) {
+                    var sel
+                        = (currentVal == activity.category_id)
+                        ? ' selected'
+                        : '';
+                    $("#advSearchActivities").append('<option value="' + activity.category_id
+                            + '" '+sel+'>'
+                            + activity.name + '</option>');
+                });
+            }
+        });
+    }
+    function updateDestinationSelect() {
+        $.ajax({
+            dataType: 'json',
+            url: 'ajax/form.json',
+            data: {
+                'search': 'destination',
+                'activityId': $("#advSearchActivities").val(),
+                'parkId': $("#advSearchParks").val()
+            },
+            success: function(data) {
+                var currentVal = $("#advSearchDest").val();
+                $("#advSearchDest").html('<option value="">Destinations</option>');
+                if (data != null) {
+                    $.each(data, function(index, destination) {
+                        var sel
+                            = (currentVal == destination.category_id)
+                            ? ' selected'
+                            : '';
+                        $("#advSearchDest").append('<option value="' + destination.category_id
+                                + '" '+sel+'>'
+                                + destination.name + '</option>');
+                    });
+                }
+            }
+        });
+    }
     function updateCountySelect() {
         $.ajax({
             dataType: 'json',
             url: 'ajax/form.json',
-            data: {'regionId': $("#advSearchRegions").val()},
+            data: {'search': 'counties','regionId': $("#advSearchRegions").val()},
             success: function(data) {
                 var currentVal = $("#advSearchCounties").val();
                 $("#advSearchCounties").html('<option value="">Counties</option>');
                     $("#advSearchCounties").append('<option value="' + county.county_id
                             + '" '+sel+'>'
                             + county.county_name + '</option>');
-                    //console.log(county.county_id);
                 });
             }
         });
index f88e29c..2e0ebd3 100755 (executable)
@@ -154,6 +154,7 @@ class Toolkit_Page
         $GLOBALS['bottomScripts'][] = $this->baseURL . "fancybox/jquery.fancybox.js";
         $GLOBALS['bottomScripts'][] = $this->glmAppBaseURL . 'libjs/external.js';
         $GLOBALS['bottomScripts'][] = $this->baseURL . "libjs/pagefunctions.js";
+        $GLOBALS['bottomScripts'][] = $this->baseURL . "libjs/findATrail.js";
     }
 
     /**
@@ -532,15 +533,19 @@ class Toolkit_Page
         $this->reviewedCount  = 0;
         try {
             $dbh = Toolkit_Database::getInstance();
+
+            // get count for reviewed trails
             $sql = "
             SELECT count(member_id)
               FROM member
              WHERE reviewed = true";
             $this->reviewedCount = $dbh->query($sql)->fetchColumn();
+
+            // get activitySearch array
             $sql = "
               SELECT category_id,name
                 FROM members.category
-               WHERE parent_id = 7
+               WHERE parent_id = " . Toolkit_Members_UserSearchForm::PARENT_CATEGORY_ACTIVITIES . "
                  AND category_id IN (
                      SELECT category_id
                        FROM members.member_category
@@ -554,10 +559,12 @@ class Toolkit_Page
                 $this->activitySearch[$category['category_id']]
                     = $category['name'];
             }
+
+            // get parkSearch array
             $sql = "
               SELECT category_id,name
                 FROM members.category
-               WHERE parent_id = 8
+               WHERE parent_id = " . Toolkit_Members_UserSearchForm::PARENT_CATEGORY_PARKS . "
                  AND category_id IN (
                      SELECT category_id
                        FROM members.member_category
@@ -571,6 +578,27 @@ class Toolkit_Page
                 $this->parkSearch[$park['category_id']]
                     = $park['name'];
             }
+
+            // get destinationSearch array
+            $sql = "
+              SELECT category_id,name
+                FROM members.category
+               WHERE parent_id = " . Toolkit_Members_UserSearchForm::PARENT_CATEGORY_DESTINATIONS . "
+                 AND category_id IN (
+                     SELECT category_id
+                       FROM members.member_category
+                      WHERE member_id IN
+                            (SELECT member_id
+                             FROM members.member
+                             WHERE active = 't'))
+            ORDER BY name";
+            $stmt = $dbh->query($sql);
+            while ($dest = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $this->destinationSearch[$dest['category_id']]
+                    = $dest['name'];
+            }
+
+            // get regionSearch array
             $sql = "
               SELECT region_id,region_name
                 FROM members.region
@@ -585,6 +613,8 @@ class Toolkit_Page
                 $this->regionSearch[$region['region_id']]
                     = $region['region_name'];
             }
+
+            // get countSearch array
             $sql = "
               SELECT county_id,county_name
                 FROM members.county
index 6fe0998..0482fd6 100644 (file)
@@ -274,11 +274,11 @@ google.maps.key   = "ABQIAAAAFEik3hTZkksVQYtPm0OFmRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ
 
 app.base_url = "http://localhost/app.gaslightmedia.com/"
 
-database.params.host = "devdb"
+database.params.host = "localhost"
 
 error.reporting[] = E_ALL
 error.reporting[] = E_NOTICE
-error.reporting[] = E_STRICT
+;error.reporting[] = E_STRICT
 
 email.owner                                 = "steve+owner@localhost"
 email.contact                               = "steve+contact@localhost"
diff --git a/libjs/findATrail.js b/libjs/findATrail.js
new file mode 100644 (file)
index 0000000..58d4477
--- /dev/null
@@ -0,0 +1,171 @@
+var findATrailSearch = {
+    activitySelect: $("#activity"),
+    parksSelect: $("#park"),
+    countySelect: $("#county"),
+    destinationSelect: $("#destination"),
+
+    init: function(){
+        // update when activities changes
+        $("#activity").change(function(){
+            findATrailSearch.updateParksSelect();
+            findATrailSearch.updateCountySelect();
+            findATrailSearch.updateDestinationSelect();
+        });
+        if ($("#activity").val()) {
+            findATrailSearch.updateParksSelect();
+            findATrailSearch.updateCountySelect();
+            findATrailSearch.updateDestinationSelect();
+        }
+        //update when parks changes
+        $("#park").change(function(){
+            findATrailSearch.updateActivitySelect();
+
+            findATrailSearch.updateCountySelect();
+            findATrailSearch.updateDestinationSelect();
+        });
+        if ($("#park").val()) {
+            findATrailSearch.updateActivitySelect();
+            findATrailSearch.updateCountySelect();
+            findATrailSearch.updateDestinationSelect();
+        }
+        // update when destination changes
+        $("#destination").change(function(){
+            findATrailSearch.updateActivitySelect();
+            findATrailSearch.updateParksSelect();
+            findATrailSearch.updateCountySelect();
+        });
+        if ($("#destination").val()) {
+            findATrailSearch.updateActivitySelect();
+            findATrailSearch.updateParksSelect();
+            findATrailSearch.updateCountySelect();
+        }
+        // update when destination changes
+        $("#county").change(function(){
+            findATrailSearch.updateActivitySelect();
+            findATrailSearch.updateParksSelect();
+            findATrailSearch.updateDestinationSelect();
+        });
+        if ($("#county").val()) {
+            findATrailSearch.updateActivitySelect();
+            findATrailSearch.updateParksSelect();
+            findATrailSearch.updateDestinationSelect();
+        }
+    },
+    updateParksSelect: function(){
+        $.ajax({
+            dataType: 'json',
+            url: 'ajax/form.json',
+            data: {
+                'search': 'parks',
+                'activityId': $("#activity").val(),
+                'destinationId': $("#destination").val(),
+                'countyId': $("#county").val()
+            },
+            success: function(data) {
+                var currentVal = $("#park").val();
+                $("#park").html('<option value="">Parks</option>');
+                if (data != null) {
+                    //console.info(data);
+                    $.each(data, function(index, park) {
+                        var sel
+                            = (currentVal == park.category_id)
+                            ? ' selected'
+                            : '';
+                        $("#park").append('<option value="' + park.category_id
+                                + '" '+sel+'>'
+                                + park.name + '</option>');
+                    });
+                }
+            }
+        });
+    },
+    updateActivitySelect: function(){
+        $.ajax({
+            dataType: 'json',
+            url: 'ajax/form.json',
+            data: {
+                'search': 'activity',
+                'parkId': $("#park").val(),
+                'destinationId': $("#destination").val(),
+                'countyId': $("#county").val()
+            },
+            success: function(data) {
+                var currentVal = $("#activity").val();
+                $("#activity").html('<option value="">Activities</option>');
+                if (data != null) {
+                    //console.info(data);
+                    $.each(data, function(index, activity) {
+                        var sel
+                            = (currentVal == activity.category_id)
+                            ? ' selected'
+                            : '';
+                        $("#activity").append('<option value="' + activity.category_id
+                                + '" '+sel+'>'
+                                + activity.name + '</option>');
+                    });
+                }
+
+            }
+        });
+    },
+    updateDestinationSelect: function(){
+        $.ajax({
+            dataType: 'json',
+            url: 'ajax/form.json',
+            data: {
+                'search': 'destination',
+                'activityId': $("#activity").val(),
+                'parkId': $("#park").val(),
+                'countyId': $("#county").val()
+            },
+            success: function(data) {
+                var currentVal = $("#destination").val();
+                $("#destination").html('<option value="">Destinations</option>');
+                if (data != null) {
+                    //console.info(data);
+                    $.each(data, function(index, destination) {
+                        var sel
+                            = (currentVal == destination.category_id)
+                            ? ' selected'
+                            : '';
+                        $("#destination").append('<option value="' + destination.category_id
+                                + '" '+sel+'>'
+                                + destination.name + '</option>');
+                    });
+                }
+            }
+        });
+    },
+    updateCountySelect: function(){
+        $.ajax({
+            dataType: 'json',
+            url: 'ajax/form.json',
+            data: {
+                'search': 'counties',
+                'activityId': $("#activity").val(),
+                'parkId': $("#park").val(),
+                'destinationId': $("#destination").val()
+            },
+            success: function(data) {
+                var currentVal = $("#county").val();
+                $("#county").html('<option value="">County</option>');
+                if (data != null) {
+                    //console.info(data);
+                    $.each(data, function(index, county) {
+                        var sel
+                            = (currentVal == county.county_id)
+                            ? ' selected'
+                            : '';
+                        $("#county").append('<option value="' + county.county_id
+                                + '" '+sel+'>'
+                                + county.county_name + '</option>');
+                    });
+                }
+            }
+        });
+    }
+}
+
+$(function(){
+    findATrailSearch.init();
+});
index 3aef542..e034c71 100755 (executable)
                                 '.$label.'</option>';
                             }?>
                                                </select>
+                        <select
+                            name="destinationId"
+                            id="destination"
+                            flexy:if="destinationSearch">
+                            <option value="">Destinations</option>
+                            <?php foreach($t->destinationSearch as $id => $label) {
+                                echo '<option
+                                value="'.$id.'">
+                                '.$label.'</option>';
+                            }?>
+                                               </select>
                         <input type="submit" name="submit" value="submit">
                                        </form>
                                </div><!--/#findatrail-->