aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2004-08-29 16:50:49 +0000
committerz0rglub <z0rglub@piwigo.org>2004-08-29 16:50:49 +0000
commit54c907ce9d04194cbbd5b506b8afcafe19dd6948 (patch)
treed5a945b1275e52b7d47bb349c77c28e5d0c66f17 /include
parent7aa6ab3a4fc03a80d3ab350134aa3be563825adc (diff)
search in sub-categories option is available
git-svn-id: http://piwigo.org/svn/trunk@502 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/functions_category.inc.php40
1 files changed, 36 insertions, 4 deletions
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index d4fb55aad..5cb0e727f 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -571,10 +571,42 @@ function initialize_category( $calling_page = 'category' )
if (isset($search['fields']['cat']))
{
- $local_clause = 'category_id IN (';
- $local_clause.= implode(',',$search['fields']['cat']['words']);
- $local_clause.= ')';
- array_push($clauses, $local_clause);
+ if ($search['fields']['cat']['mode'] == 'sub_inc')
+ {
+ // searching all the categories id of sub-categories
+ $search_cat_clauses = array();
+ foreach ($search['fields']['cat']['words'] as $cat_id)
+ {
+ $local_clause = 'uppercats REGEXP \'(^|,)'.$cat_id.'(,|$)\'';
+ array_push($search_cat_clauses, $local_clause);
+ }
+ array_walk($search_cat_clauses,
+ create_function('&$s', '$s = "(".$s.")";'));
+
+ $query = '
+SELECT DISTINCT(id) AS id
+ FROM '.CATEGORIES_TABLE.'
+ WHERE '.implode(' OR ', $search_cat_clauses).'
+;';
+ echo '<pre>'.$query.'</pre>';
+ $result = mysql_query($query);
+ $cat_ids = array();
+ while ($row = mysql_fetch_array($result))
+ {
+ array_push($cat_ids, $row['id']);
+ }
+ $local_clause = 'category_id IN (';
+ $local_clause.= implode(',',$cat_ids);
+ $local_clause.= ')';
+ array_push($clauses, $local_clause);
+ }
+ else
+ {
+ $local_clause = 'category_id IN (';
+ $local_clause.= implode(',',$search['fields']['cat']['words']);
+ $local_clause.= ')';
+ array_push($clauses, $local_clause);
+ }
}
// adds brackets around where clauses