[1053] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
[1861] | 4 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[1053] | 5 | // +-----------------------------------------------------------------------+ |
---|
[1861] | 6 | // | file : $Id: functions_calendar.inc.php 1900 2007-03-12 22:33:53Z rub $ |
---|
[1094] | 7 | // | last update : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $ |
---|
| 8 | // | last modifier : $Author: rub $ |
---|
| 9 | // | revision : $Revision: 1900 $ |
---|
[1053] | 10 | // +-----------------------------------------------------------------------+ |
---|
| 11 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 12 | // | it under the terms of the GNU General Public License as published by | |
---|
| 13 | // | the Free Software Foundation | |
---|
| 14 | // | | |
---|
| 15 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 16 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 17 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 18 | // | General Public License for more details. | |
---|
| 19 | // | | |
---|
| 20 | // | You should have received a copy of the GNU General Public License | |
---|
| 21 | // | along with this program; if not, write to the Free Software | |
---|
| 22 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 23 | // | USA. | |
---|
| 24 | // +-----------------------------------------------------------------------+ |
---|
| 25 | |
---|
[1086] | 26 | define('CAL_VIEW_LIST', 'list'); |
---|
| 27 | define('CAL_VIEW_CALENDAR', 'calendar'); |
---|
[1053] | 28 | |
---|
| 29 | function initialize_calendar() |
---|
| 30 | { |
---|
[1677] | 31 | global $page, $conf, $user, $template, $filter; |
---|
[1053] | 32 | |
---|
| 33 | //------------------ initialize the condition on items to take into account --- |
---|
| 34 | $inner_sql = ' FROM ' . IMAGES_TABLE; |
---|
[1059] | 35 | |
---|
[1861] | 36 | if ($page['section']=='categories') |
---|
[1053] | 37 | { // we will regenerate the items by including subcats elements |
---|
| 38 | $page['items'] = array(); |
---|
| 39 | $inner_sql .= ' |
---|
| 40 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
[1059] | 41 | |
---|
[1861] | 42 | if ( isset($page['category']) ) |
---|
[1053] | 43 | { |
---|
| 44 | $sub_ids = array_diff( |
---|
[1861] | 45 | get_subcat_ids(array($page['category']['id'])), |
---|
[1053] | 46 | explode(',', $user['forbidden_categories']) |
---|
| 47 | ); |
---|
[1059] | 48 | |
---|
[1053] | 49 | if (empty($sub_ids)) |
---|
| 50 | { |
---|
| 51 | return; // nothing to do |
---|
| 52 | } |
---|
| 53 | $inner_sql .= ' |
---|
| 54 | WHERE category_id IN ('.implode(',',$sub_ids).')'; |
---|
[1759] | 55 | $inner_sql .= ' |
---|
| 56 | '.get_sql_condition_FandF |
---|
| 57 | ( |
---|
| 58 | array |
---|
| 59 | ( |
---|
| 60 | 'visible_images' => 'id' |
---|
| 61 | ), |
---|
| 62 | 'AND', false |
---|
| 63 | ); |
---|
[1053] | 64 | } |
---|
| 65 | else |
---|
| 66 | { |
---|
| 67 | $inner_sql .= ' |
---|
[1677] | 68 | '.get_sql_condition_FandF |
---|
| 69 | ( |
---|
| 70 | array |
---|
| 71 | ( |
---|
| 72 | 'forbidden_categories' => 'category_id', |
---|
| 73 | 'visible_categories' => 'category_id', |
---|
[1759] | 74 | 'visible_images' => 'id' |
---|
[1677] | 75 | ), |
---|
| 76 | 'WHERE', true |
---|
| 77 | ); |
---|
[1053] | 78 | } |
---|
| 79 | } |
---|
| 80 | else |
---|
| 81 | { |
---|
| 82 | if ( empty($page['items']) ) |
---|
| 83 | { |
---|
| 84 | return; // nothing to do |
---|
| 85 | } |
---|
| 86 | $inner_sql .= ' |
---|
| 87 | WHERE id IN (' . implode(',',$page['items']) .')'; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | //-------------------------------------- initialize the calendar parameters --- |
---|
| 91 | pwg_debug('start initialize_calendar'); |
---|
[1057] | 92 | |
---|
| 93 | $fields = array( |
---|
| 94 | // Created |
---|
| 95 | 'created' => array( |
---|
| 96 | 'label' => l10n('Creation date'), |
---|
| 97 | ), |
---|
| 98 | // Posted |
---|
| 99 | 'posted' => array( |
---|
[1059] | 100 | 'label' => l10n('Post date'), |
---|
[1057] | 101 | ), |
---|
| 102 | ); |
---|
| 103 | |
---|
| 104 | $styles = array( |
---|
[1056] | 105 | // Monthly style |
---|
[1057] | 106 | 'monthly' => array( |
---|
[1053] | 107 | 'include' => 'calendar_monthly.class.php', |
---|
| 108 | 'view_calendar' => true, |
---|
| 109 | ), |
---|
[1059] | 110 | // Weekly style |
---|
[1057] | 111 | 'weekly' => array( |
---|
[1053] | 112 | 'include' => 'calendar_weekly.class.php', |
---|
[1056] | 113 | 'view_calendar' => false, |
---|
[1053] | 114 | ), |
---|
| 115 | ); |
---|
| 116 | |
---|
[1086] | 117 | $views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR); |
---|
[1057] | 118 | |
---|
| 119 | // Retrieve calendar field |
---|
[1090] | 120 | if ( !isset( $fields[ $page['chronology_field'] ] ) ) |
---|
[1086] | 121 | { |
---|
[1090] | 122 | die('bad chronology field'); |
---|
[1086] | 123 | } |
---|
[1059] | 124 | |
---|
[1057] | 125 | // Retrieve style |
---|
[1090] | 126 | if ( !isset( $styles[ $page['chronology_style'] ] ) ) |
---|
[1086] | 127 | { |
---|
[1090] | 128 | $page['chronology_style'] = 'monthly'; |
---|
[1086] | 129 | } |
---|
[1090] | 130 | $cal_style = $page['chronology_style']; |
---|
[1057] | 131 | include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']); |
---|
| 132 | $calendar = new Calendar(); |
---|
| 133 | |
---|
| 134 | // Retrieve view |
---|
[1086] | 135 | |
---|
[1090] | 136 | if ( !isset($page['chronology_view']) or |
---|
| 137 | !in_array( $page['chronology_view'], $views ) ) |
---|
[1053] | 138 | { |
---|
[1090] | 139 | $page['chronology_view'] = CAL_VIEW_LIST; |
---|
[1053] | 140 | } |
---|
| 141 | |
---|
[1090] | 142 | if ( CAL_VIEW_CALENDAR==$page['chronology_view'] and |
---|
[1086] | 143 | !$styles[$cal_style]['view_calendar'] ) |
---|
| 144 | { |
---|
| 145 | |
---|
[1090] | 146 | $page['chronology_view'] = CAL_VIEW_LIST; |
---|
[1086] | 147 | } |
---|
| 148 | |
---|
[1053] | 149 | // perform a sanity check on $requested |
---|
[1086] | 150 | if (!isset($page['chronology_date'])) |
---|
[1053] | 151 | { |
---|
[1086] | 152 | $page['chronology_date'] = array(); |
---|
[1053] | 153 | } |
---|
[1086] | 154 | while ( count($page['chronology_date']) > 3) |
---|
| 155 | { |
---|
| 156 | array_pop($page['chronology_date']); |
---|
| 157 | } |
---|
[1053] | 158 | |
---|
| 159 | $any_count = 0; |
---|
[1086] | 160 | for ($i = 0; $i < count($page['chronology_date']); $i++) |
---|
[1053] | 161 | { |
---|
[1086] | 162 | if ($page['chronology_date'][$i] == 'any') |
---|
[1053] | 163 | { |
---|
[1090] | 164 | if ($page['chronology_view'] == CAL_VIEW_CALENDAR) |
---|
[1053] | 165 | {// we dont allow any in calendar view |
---|
[1086] | 166 | while ($i < count($page['chronology_date'])) |
---|
[1053] | 167 | { |
---|
[1086] | 168 | array_pop($page['chronology_date']); |
---|
[1053] | 169 | } |
---|
| 170 | break; |
---|
| 171 | } |
---|
| 172 | $any_count++; |
---|
| 173 | } |
---|
[1086] | 174 | elseif ($page['chronology_date'][$i] == '') |
---|
[1053] | 175 | { |
---|
[1086] | 176 | while ($i < count($page['chronology_date'])) |
---|
[1053] | 177 | { |
---|
[1086] | 178 | array_pop($page['chronology_date']); |
---|
[1053] | 179 | } |
---|
| 180 | } |
---|
[1059] | 181 | else |
---|
| 182 | { |
---|
[1086] | 183 | $page['chronology_date'][$i] = (int)$page['chronology_date'][$i]; |
---|
[1059] | 184 | } |
---|
[1053] | 185 | } |
---|
| 186 | if ($any_count == 3) |
---|
| 187 | { |
---|
[1086] | 188 | array_pop($page['chronology_date']); |
---|
[1053] | 189 | } |
---|
[1059] | 190 | |
---|
[1086] | 191 | $calendar->initialize($inner_sql); |
---|
[1053] | 192 | |
---|
[1059] | 193 | //echo ('<pre>'. var_export($calendar, true) . '</pre>'); |
---|
| 194 | |
---|
[1057] | 195 | $must_show_list = true; // true until calendar generates its own display |
---|
[1690] | 196 | if (script_basename() != 'picture') // basename without file extention |
---|
[1053] | 197 | { |
---|
[1086] | 198 | if ($calendar->generate_category_content()) |
---|
[1053] | 199 | { |
---|
[1820] | 200 | $page['items'] = array(); |
---|
[1053] | 201 | $must_show_list = false; |
---|
| 202 | } |
---|
[1059] | 203 | |
---|
[1057] | 204 | foreach ($styles as $style => $style_data) |
---|
[1053] | 205 | { |
---|
[1086] | 206 | foreach ($views as $view) |
---|
[1053] | 207 | { |
---|
[1057] | 208 | if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR) |
---|
[1053] | 209 | { |
---|
[1057] | 210 | $selected = ''; |
---|
[1086] | 211 | |
---|
| 212 | if ($style!=$cal_style) |
---|
[1057] | 213 | { |
---|
[1086] | 214 | $chronology_date = array(); |
---|
| 215 | if ( isset($page['chronology_date'][0]) ) |
---|
[1057] | 216 | { |
---|
[1086] | 217 | array_push($chronology_date, $page['chronology_date'][0]); |
---|
[1057] | 218 | } |
---|
| 219 | } |
---|
| 220 | else |
---|
| 221 | { |
---|
[1086] | 222 | $chronology_date = $page['chronology_date']; |
---|
[1057] | 223 | } |
---|
[1086] | 224 | $url = duplicate_index_url( |
---|
| 225 | array( |
---|
[1090] | 226 | 'chronology_style' => $style, |
---|
| 227 | 'chronology_view' => $view, |
---|
[1086] | 228 | 'chronology_date' => $chronology_date, |
---|
| 229 | ) |
---|
| 230 | ); |
---|
| 231 | |
---|
[1090] | 232 | if ($style==$cal_style and $view==$page['chronology_view'] ) |
---|
[1086] | 233 | { |
---|
| 234 | $selected = 'SELECTED'; |
---|
| 235 | } |
---|
| 236 | |
---|
[1057] | 237 | $template->assign_block_vars( |
---|
| 238 | 'calendar.views.view', |
---|
| 239 | array( |
---|
| 240 | 'VALUE' => $url, |
---|
[1090] | 241 | 'CONTENT' => l10n('chronology_'.$style.'_'.$view), |
---|
[1057] | 242 | 'SELECTED' => $selected, |
---|
| 243 | ) |
---|
| 244 | ); |
---|
[1053] | 245 | } |
---|
| 246 | } |
---|
| 247 | } |
---|
[1086] | 248 | $url = duplicate_index_url( |
---|
[1090] | 249 | array(), array('start', 'chronology_date') |
---|
[1086] | 250 | ); |
---|
| 251 | $calendar_title = '<a href="'.$url.'">' |
---|
[1090] | 252 | .$fields[$page['chronology_field']]['label'].'</a>'; |
---|
[1062] | 253 | $calendar_title.= $calendar->get_display_name(); |
---|
[1820] | 254 | $template->merge_block_vars('calendar', |
---|
| 255 | array( |
---|
| 256 | 'TITLE' => $calendar_title |
---|
| 257 | ) |
---|
| 258 | ); |
---|
[1053] | 259 | } // end category calling |
---|
| 260 | |
---|
| 261 | if ($must_show_list) |
---|
| 262 | { |
---|
| 263 | $query = 'SELECT DISTINCT(id)'; |
---|
[1062] | 264 | $query .= $calendar->inner_sql.' |
---|
| 265 | '.$calendar->get_date_where(); |
---|
[1053] | 266 | if ( isset($page['super_order_by']) ) |
---|
| 267 | { |
---|
| 268 | $query .= ' |
---|
| 269 | '.$conf['order_by']; |
---|
| 270 | } |
---|
| 271 | else |
---|
| 272 | { |
---|
[1163] | 273 | if ( count($page['chronology_date'])==0 |
---|
| 274 | or in_array('any', $page['chronology_date']) ) |
---|
| 275 | {// selected period is very big so we show newest first |
---|
| 276 | $order = ' DESC, '; |
---|
| 277 | } |
---|
| 278 | else |
---|
| 279 | {// selected period is small (month,week) so we show oldest first |
---|
| 280 | $order = ' ASC, '; |
---|
| 281 | } |
---|
[1053] | 282 | $order_by = str_replace( |
---|
| 283 | 'ORDER BY ', |
---|
[1163] | 284 | 'ORDER BY '.$calendar->date_field.$order, $conf['order_by'] |
---|
[1053] | 285 | ); |
---|
[1062] | 286 | $query .= ' |
---|
| 287 | '.$order_by; |
---|
[1053] | 288 | } |
---|
| 289 | $page['items'] = array_from_query($query, 'id'); |
---|
| 290 | } |
---|
| 291 | pwg_debug('end initialize_calendar'); |
---|
| 292 | } |
---|
| 293 | |
---|
[1047] | 294 | ?> |
---|