[1047] | 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$ |
---|
[1050] | 8 | // | last update : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $ |
---|
| 9 | // | last modifier : $Author: rvelices $ |
---|
| 10 | // | revision : $Revision: 1014 $ |
---|
[1047] | 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 | |
---|
[1050] | 27 | define('CAL_VIEW_LIST','l'); |
---|
| 28 | define('CAL_VIEW_CALENDAR','c'); |
---|
| 29 | |
---|
| 30 | function initialize_calendar() |
---|
[1047] | 31 | { |
---|
[1050] | 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 | } |
---|
[1047] | 59 | } |
---|
[1050] | 60 | else |
---|
[1047] | 61 | { |
---|
[1050] | 62 | if ( empty($page['items']) ) |
---|
[1047] | 63 | { |
---|
[1050] | 64 | return; // nothing to do |
---|
[1047] | 65 | } |
---|
[1050] | 66 | $inner_sql .= ' |
---|
| 67 | WHERE id IN (' . implode(',',$page['items']) .')'; |
---|
[1047] | 68 | } |
---|
| 69 | |
---|
[1050] | 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 | ); |
---|
[1047] | 78 | |
---|
[1050] | 79 | $requested = explode('-', $_GET['calendar']); |
---|
| 80 | $calendar = null; |
---|
| 81 | foreach( $cal_styles as $cal_style) |
---|
[1047] | 82 | { |
---|
[1050] | 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 | } |
---|
[1047] | 90 | } |
---|
[1050] | 91 | if ( !isset($calendar) ) |
---|
[1047] | 92 | { |
---|
[1050] | 93 | foreach( $cal_styles as $cal_style) |
---|
[1047] | 94 | { |
---|
[1050] | 95 | if (''==$cal_style['default_link']) |
---|
| 96 | break; |
---|
[1047] | 97 | } |
---|
[1050] | 98 | include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']); |
---|
| 99 | $calendar = new Calendar(); |
---|
[1047] | 100 | } |
---|
| 101 | |
---|
[1050] | 102 | $view_type=CAL_VIEW_LIST; |
---|
| 103 | if ($requested[0]==CAL_VIEW_LIST) |
---|
[1047] | 104 | { |
---|
[1050] | 105 | array_shift($requested); |
---|
[1047] | 106 | } |
---|
[1050] | 107 | elseif ($requested[0]==CAL_VIEW_CALENDAR) |
---|
[1047] | 108 | { |
---|
[1050] | 109 | if ($cal_style['view_calendar']) |
---|
[1047] | 110 | { |
---|
[1050] | 111 | $view_type=CAL_VIEW_CALENDAR; |
---|
[1047] | 112 | } |
---|
[1050] | 113 | array_shift($requested); |
---|
[1047] | 114 | } |
---|
| 115 | // perform a sanity check on $requested |
---|
[1050] | 116 | while (count($requested)>3) |
---|
[1047] | 117 | { |
---|
| 118 | array_pop($requested); |
---|
| 119 | } |
---|
[1050] | 120 | |
---|
[1047] | 121 | $any_count = 0; |
---|
| 122 | for ($i=0; $i<count($requested); $i++) |
---|
| 123 | { |
---|
| 124 | if ($requested[$i]=='any') |
---|
| 125 | { |
---|
[1050] | 126 | if ($view_type==CAL_VIEW_CALENDAR) |
---|
| 127 | {// we dont allow any in calendar view |
---|
[1047] | 128 | while ($i<count($requested)) |
---|
| 129 | { |
---|
| 130 | array_pop( $requested ); |
---|
| 131 | } |
---|
| 132 | break; |
---|
| 133 | } |
---|
| 134 | $any_count++; |
---|
| 135 | } |
---|
[1050] | 136 | elseif ( $requested[$i]=='' ) |
---|
[1047] | 137 | { |
---|
| 138 | while ($i<count($requested)) |
---|
| 139 | { |
---|
| 140 | array_pop( $requested ); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | } |
---|
[1050] | 144 | if ($any_count==3) |
---|
[1047] | 145 | { |
---|
| 146 | array_pop($requested); |
---|
| 147 | } |
---|
| 148 | |
---|
[1050] | 149 | $calendar->initialize($conf['calendar_datefield'], $inner_sql); |
---|
| 150 | //echo ('<pre>'. var_export($requested, true) . '</pre>'); |
---|
| 151 | //echo ('<pre>'. var_export($calendar, true) . '</pre>'); |
---|
[1047] | 152 | |
---|
| 153 | $category_calling = false; |
---|
| 154 | if (basename($_SERVER["PHP_SELF"]) == 'category.php') |
---|
| 155 | { |
---|
| 156 | $category_calling = true; |
---|
| 157 | } |
---|
[1050] | 158 | |
---|
| 159 | $must_show_list = true; |
---|
[1047] | 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; |
---|
[1050] | 168 | |
---|
| 169 | if ( $calendar->generate_category_content( |
---|
| 170 | $url_base.$cal_style['default_link'], $view_type, $requested) ) |
---|
[1047] | 171 | { |
---|
[1050] | 172 | unset( $page['thumbnails_include'] ); |
---|
| 173 | unset( $page['items'] ); |
---|
| 174 | unset( $page['cat_nb_images'] ); |
---|
| 175 | $must_show_list = false; |
---|
[1047] | 176 | } |
---|
| 177 | |
---|
[1050] | 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 ) |
---|
[1047] | 186 | { |
---|
[1050] | 187 | $v = $view[1]; |
---|
| 188 | if ( $view_type!=$view[0] ) |
---|
[1047] | 189 | { |
---|
[1050] | 190 | $url = $url_base.$cal_style['default_link'].$view[0].'-'; |
---|
| 191 | $url .= implode('-', $requested); |
---|
| 192 | $v = '<a href="'.$url.'">'.$v.'</a> '; |
---|
[1047] | 193 | } |
---|
| 194 | else |
---|
| 195 | { |
---|
[1050] | 196 | $v = $v.' '; |
---|
[1047] | 197 | } |
---|
[1050] | 198 | $views_bar .= $v . ' '; |
---|
[1047] | 199 | } |
---|
[1050] | 200 | $template->assign_block_vars('calendar.views', array( |
---|
| 201 | 'BAR'=>$views_bar |
---|
| 202 | )); |
---|
| 203 | } |
---|
[1047] | 204 | |
---|
[1050] | 205 | // Build bar for calendar styles (Monthly, Weekly) |
---|
| 206 | $styles_bar = ''; |
---|
| 207 | foreach ( $cal_styles as $style) |
---|
[1047] | 208 | { |
---|
[1050] | 209 | if ($cal_style['link']!=$style['link']) |
---|
[1047] | 210 | { |
---|
[1050] | 211 | $url = $url_base.$style['default_link']; |
---|
| 212 | $url .= $view_type; |
---|
| 213 | if (isset($requested[0])) |
---|
[1047] | 214 | { |
---|
[1050] | 215 | $url .= '-' . $requested[0]; |
---|
[1047] | 216 | } |
---|
[1050] | 217 | $styles_bar .= '<a href="'. $url . '">'.$style['name'].'</a> '; |
---|
[1047] | 218 | } |
---|
[1050] | 219 | else |
---|
| 220 | { |
---|
| 221 | $styles_bar .= $style['name'].' '; |
---|
| 222 | } |
---|
[1047] | 223 | } |
---|
[1050] | 224 | $template->assign_block_vars( 'calendar.styles', |
---|
| 225 | array( 'BAR' => $styles_bar) |
---|
| 226 | ); |
---|
| 227 | } // end category calling |
---|
| 228 | |
---|
| 229 | if ($must_show_list) |
---|
[1047] | 230 | { |
---|
[1050] | 231 | $query = 'SELECT DISTINCT(id)'; |
---|
| 232 | $query .= $calendar->inner_sql; |
---|
| 233 | $query .= $calendar->get_date_where($requested); |
---|
[1047] | 234 | |
---|
| 235 | $page['items'] = array_from_query($query, 'id'); |
---|
| 236 | $page['cat_nb_images'] = count($page['items']); |
---|
| 237 | $page['thumbnails_include'] = 'include/category_default.inc.php'; |
---|
| 238 | } |
---|
| 239 | pwg_debug('end initialize_calendar'); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | ?> |
---|