source: trunk/include/filter.inc.php @ 1730

Last change on this file since 1730 was 1723, checked in by rub, 18 years ago

Fixed: Missing information "recent" in URL filter start parameter

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Rev Revision URL
File size: 5.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2006-2007 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | branch        : BSF (Best So Far)
7// | file          : $Id: filter.inc.php 1723 2007-01-15 22:28:15Z rub $
8// | last update   : $Date: 2007-01-15 22:28:15 +0000 (Mon, 15 Jan 2007) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 1723 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27// global variable for filter
28$filter = array();
29
30// $filter['enabled']: Filter is enabled
31// $filter['check_key']: Check key to valitade computed filter data
32// $filter['recent_period']: Recent period used to computed filter data
33// $filter['categories']: Computed data of filtered categories
34// $filter['visible_categories']:
35//  List of visible categories (count(visible) < count(forbidden) more often)
36// $filter['visible_images']: List of visible images
37
38if (!get_filter_page_value('cancel'))
39{
40  if (isset($_GET['filter']))
41  {
42    $filter['matches'] = array();
43    $filter['enabled'] = 
44      preg_match('/^start-recent-(\d+)$/', $_GET['filter'], $filter['matches']) === 1;
45  }
46  else
47  {
48    $filter['enabled'] = pwg_get_session_var('filter_enabled', false);
49  }
50}
51else
52{
53  $filter['enabled'] = false;
54}
55
56if ($filter['enabled'])
57{
58  if (isset($filter['matches']))
59  {
60    $filter['recent_period'] = $filter['matches'][1];
61  }
62  else
63  {
64    $filter['recent_period'] = pwg_get_session_var('filter_recent_period', $user['recent_period']);
65  }
66
67  if (
68      // New filter
69      !pwg_get_session_var('filter_enabled', false) or
70      // Cache data updated
71      $user['need_update_done'] or
72      // Date, period, user are changed
73      (pwg_get_session_var('filter_check_key', '') != get_filter_check_key())
74    )
75  {
76    // Need to compute dats
77    $filter['check_key'] = get_filter_check_key();
78    $filter['categories'] = get_computed_categories($user['id'], $user['forbidden_categories'], true, $filter['recent_period']);
79
80    $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
81    if (empty($filter['visible_categories']))
82    {
83      // Must be not empty
84      $filter['visible_categories'] = -1;
85    }
86
87    $query ='
88SELECT
89  distinct image_id
90FROM '.
91  IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
92WHERE ';
93    if (!empty($filter['visible_categories']))
94    {
95    $query.= '
96  category_id  IN ('.$filter['visible_categories'].') and';
97    }
98  $query.= '
99    date_available  > SUBDATE(
100      CURRENT_DATE,INTERVAL '.$filter['recent_period'].' DAY)';
101
102    $filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));
103
104    if (empty($filter['visible_images']))
105    {
106      // Must be not empty
107      $filter['visible_images'] = -1;
108    }
109
110    // Save filter data on session
111    pwg_set_session_var('filter_enabled', $filter['enabled']);
112    pwg_set_session_var('filter_check_key', $filter['check_key']);
113    pwg_set_session_var('filter_recent_period', $filter['recent_period']);
114    pwg_set_session_var('filter_categories', serialize($filter['categories']));
115    pwg_set_session_var('filter_visible_categories', $filter['visible_categories']);
116    pwg_set_session_var('filter_visible_images', $filter['visible_images']);
117
118  }
119  else
120  {
121    // Read only data
122    $filter['check_key'] = pwg_get_session_var('filter_check_key', '');
123    $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array())));
124    $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', '');
125    $filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');
126  }
127
128  if (get_filter_page_value('add_notes'))
129  {
130    $header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $filter['recent_period']);
131  }
132}
133else
134{
135  if (pwg_get_session_var('filter_enabled', false))
136  {
137    pwg_unset_session_var('filter_enabled');
138    pwg_unset_session_var('filter_check_key');
139    pwg_unset_session_var('filter_recent_period');
140    pwg_unset_session_var('filter_categories');
141    pwg_unset_session_var('filter_visible_categories');
142    pwg_unset_session_var('filter_visible_images');
143  }
144}
145
146
147?>
Note: See TracBrowser for help on using the repository browser.