1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
5 | // +-----------------------------------------------------------------------+ |
---|
6 | // | branch : BSF (Best So Far) |
---|
7 | // | file : $RCSfile$ |
---|
8 | // | last update : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $ |
---|
9 | // | last modifier : $Author: rvelices $ |
---|
10 | // | revision : $Revision: 1014 $ |
---|
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 | define('CAL_VIEW_LIST','l'); |
---|
28 | define('CAL_VIEW_CALENDAR','c'); |
---|
29 | |
---|
30 | function initialize_calendar() |
---|
31 | { |
---|
32 | global $page, $conf, $user, $template; |
---|
33 | |
---|
34 | //------------------ initialize the condition on items to take into account --- |
---|
35 | $inner_sql = ' FROM ' . IMAGES_TABLE; |
---|
36 | if ( !isset($page['cat']) or is_numeric($page['cat']) ) |
---|
37 | { // we will regenerate the items by including subcats elements |
---|
38 | $page['cat_nb_images']=0; |
---|
39 | $page['items']=array(); |
---|
40 | $inner_sql .= ' |
---|
41 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
42 | if ( is_numeric($page['cat']) ) |
---|
43 | { |
---|
44 | $sub_ids = get_subcat_ids(array($page['cat'])); |
---|
45 | $sub_ids = array_diff($sub_ids, |
---|
46 | explode(',', $user['forbidden_categories']) ); |
---|
47 | if (empty($sub_ids)) |
---|
48 | { |
---|
49 | return; // nothing to do |
---|
50 | } |
---|
51 | $inner_sql .= ' |
---|
52 | WHERE category_id IN ('.implode(',',$sub_ids).')'; |
---|
53 | } |
---|
54 | else |
---|
55 | { |
---|
56 | $inner_sql .= ' |
---|
57 | WHERE category_id NOT IN ('.$user['forbidden_categories'].')'; |
---|
58 | } |
---|
59 | } |
---|
60 | else |
---|
61 | { |
---|
62 | if ( empty($page['items']) ) |
---|
63 | { |
---|
64 | return; // nothing to do |
---|
65 | } |
---|
66 | $inner_sql .= ' |
---|
67 | WHERE id IN (' . implode(',',$page['items']) .')'; |
---|
68 | } |
---|
69 | |
---|
70 | //-------------------------------------- initialize the calendar parameters --- |
---|
71 | pwg_debug('start initialize_calendar'); |
---|
72 | $cal_styles = array( |
---|
73 | array('link'=>'m', 'default_link'=>'', 'name'=>l10n('Monthly'), |
---|
74 | 'include'=>'calendar_monthly.class.php', 'view_calendar'=>true ), |
---|
75 | array('link'=>'w', 'default_link'=>'w-', 'name'=>l10n('Weekly'), |
---|
76 | 'include'=>'calendar_weekly.class.php', ), |
---|
77 | ); |
---|
78 | |
---|
79 | $requested = explode('-', $_GET['calendar']); |
---|
80 | $calendar = null; |
---|
81 | foreach( $cal_styles as $cal_style) |
---|
82 | { |
---|
83 | if ($requested[0]==$cal_style['link']) |
---|
84 | { |
---|
85 | include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']); |
---|
86 | $calendar = new Calendar(); |
---|
87 | array_shift($requested); |
---|
88 | break; |
---|
89 | } |
---|
90 | } |
---|
91 | if ( !isset($calendar) ) |
---|
92 | { |
---|
93 | foreach( $cal_styles as $cal_style) |
---|
94 | { |
---|
95 | if (''==$cal_style['default_link']) |
---|
96 | break; |
---|
97 | } |
---|
98 | include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']); |
---|
99 | $calendar = new Calendar(); |
---|
100 | } |
---|
101 | |
---|
102 | $view_type=CAL_VIEW_LIST; |
---|
103 | if ($requested[0]==CAL_VIEW_LIST) |
---|
104 | { |
---|
105 | array_shift($requested); |
---|
106 | } |
---|
107 | elseif ($requested[0]==CAL_VIEW_CALENDAR) |
---|
108 | { |
---|
109 | if ($cal_style['view_calendar']) |
---|
110 | { |
---|
111 | $view_type=CAL_VIEW_CALENDAR; |
---|
112 | } |
---|
113 | array_shift($requested); |
---|
114 | } |
---|
115 | // perform a sanity check on $requested |
---|
116 | while (count($requested)>3) |
---|
117 | { |
---|
118 | array_pop($requested); |
---|
119 | } |
---|
120 | |
---|
121 | $any_count = 0; |
---|
122 | for ($i=0; $i<count($requested); $i++) |
---|
123 | { |
---|
124 | if ($requested[$i]=='any') |
---|
125 | { |
---|
126 | if ($view_type==CAL_VIEW_CALENDAR) |
---|
127 | {// we dont allow any in calendar view |
---|
128 | while ($i<count($requested)) |
---|
129 | { |
---|
130 | array_pop( $requested ); |
---|
131 | } |
---|
132 | break; |
---|
133 | } |
---|
134 | $any_count++; |
---|
135 | } |
---|
136 | elseif ( $requested[$i]=='' ) |
---|
137 | { |
---|
138 | while ($i<count($requested)) |
---|
139 | { |
---|
140 | array_pop( $requested ); |
---|
141 | } |
---|
142 | } |
---|
143 | } |
---|
144 | if ($any_count==3) |
---|
145 | { |
---|
146 | array_pop($requested); |
---|
147 | } |
---|
148 | |
---|
149 | $calendar->initialize($conf['calendar_datefield'], $inner_sql); |
---|
150 | //echo ('<pre>'. var_export($requested, true) . '</pre>'); |
---|
151 | //echo ('<pre>'. var_export($calendar, true) . '</pre>'); |
---|
152 | |
---|
153 | $category_calling = false; |
---|
154 | if (basename($_SERVER["PHP_SELF"]) == 'category.php') |
---|
155 | { |
---|
156 | $category_calling = true; |
---|
157 | } |
---|
158 | |
---|
159 | $must_show_list = true; |
---|
160 | if ($category_calling) |
---|
161 | { |
---|
162 | $template->assign_block_vars('calendar', array()); |
---|
163 | |
---|
164 | $url_base = get_query_string_diff(array('start','calendar')); |
---|
165 | $url_base .= empty($url_base) ? '?' : '&'; |
---|
166 | $url_base .= 'calendar='; |
---|
167 | $url_base = PHPWG_ROOT_PATH.'category.php'.$url_base; |
---|
168 | |
---|
169 | if ( $calendar->generate_category_content( |
---|
170 | $url_base.$cal_style['default_link'], $view_type, $requested) ) |
---|
171 | { |
---|
172 | unset( $page['thumbnails_include'] ); |
---|
173 | unset( $page['items'] ); |
---|
174 | unset( $page['cat_nb_images'] ); |
---|
175 | $must_show_list = false; |
---|
176 | } |
---|
177 | |
---|
178 | if ($cal_style['view_calendar']) |
---|
179 | { // Build bar for view modes (List/Calendar) |
---|
180 | $views = array( |
---|
181 | array(CAL_VIEW_LIST, l10n('List') ), |
---|
182 | array(CAL_VIEW_CALENDAR, l10n('calendar') ), |
---|
183 | ); |
---|
184 | $views_bar = ''; |
---|
185 | foreach( $views as $view ) |
---|
186 | { |
---|
187 | $v = $view[1]; |
---|
188 | if ( $view_type!=$view[0] ) |
---|
189 | { |
---|
190 | $url = $url_base.$cal_style['default_link'].$view[0].'-'; |
---|
191 | $url .= implode('-', $requested); |
---|
192 | $v = '<a href="'.$url.'">'.$v.'</a> '; |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | $v = $v.' '; |
---|
197 | } |
---|
198 | $views_bar .= $v . ' '; |
---|
199 | } |
---|
200 | $template->assign_block_vars('calendar.views', array( |
---|
201 | 'BAR'=>$views_bar |
---|
202 | )); |
---|
203 | } |
---|
204 | |
---|
205 | // Build bar for calendar styles (Monthly, Weekly) |
---|
206 | $styles_bar = ''; |
---|
207 | foreach ( $cal_styles as $style) |
---|
208 | { |
---|
209 | if ($cal_style['link']!=$style['link']) |
---|
210 | { |
---|
211 | $url = $url_base.$style['default_link']; |
---|
212 | $url .= $view_type; |
---|
213 | if (isset($requested[0])) |
---|
214 | { |
---|
215 | $url .= '-' . $requested[0]; |
---|
216 | } |
---|
217 | $styles_bar .= '<a href="'. $url . '">'.$style['name'].'</a> '; |
---|
218 | } |
---|
219 | else |
---|
220 | { |
---|
221 | $styles_bar .= $style['name'].' '; |
---|
222 | } |
---|
223 | } |
---|
224 | $template->assign_block_vars( 'calendar.styles', |
---|
225 | array( 'BAR' => $styles_bar) |
---|
226 | ); |
---|
227 | } // end category calling |
---|
228 | |
---|
229 | if ($must_show_list) |
---|
230 | { |
---|
231 | $query = 'SELECT DISTINCT(id)'; |
---|
232 | $query .= $calendar->inner_sql; |
---|
233 | $query .= $calendar->get_date_where($requested); |
---|
234 | if ( isset($page['super_order_by']) ) |
---|
235 | { |
---|
236 | $query .= ' |
---|
237 | '.$conf['order_by']; |
---|
238 | } |
---|
239 | else |
---|
240 | { |
---|
241 | $order_by = str_replace( |
---|
242 | 'ORDER BY ', |
---|
243 | 'ORDER BY '.$calendar->date_field.',', $conf['order_by'] |
---|
244 | ); |
---|
245 | $query .= $order_by; |
---|
246 | } |
---|
247 | |
---|
248 | $page['items'] = array_from_query($query, 'id'); |
---|
249 | $page['cat_nb_images'] = count($page['items']); |
---|
250 | $page['thumbnails_include'] = 'include/category_default.inc.php'; |
---|
251 | } |
---|
252 | pwg_debug('end initialize_calendar'); |
---|
253 | } |
---|
254 | |
---|
255 | ?> |
---|