Changeset 1086 for trunk/include/functions_calendar.inc.php
- Timestamp:
- Mar 17, 2006, 5:13:19 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_calendar.inc.php
r1062 r1086 25 25 // +-----------------------------------------------------------------------+ 26 26 27 define('CAL_VIEW_LIST', 'l'); 28 define('CAL_VIEW_CALENDAR', 'c'); 29 30 function get_calendar_parameter($options, &$parameters ) 31 { 32 if ( count($parameters) and isset($options[$parameters[0]]) ) 33 { 34 return array_shift($parameters); 35 } 36 else 37 { 38 foreach ($options as $option => $data) 39 { 40 if ( empty( $data['default_link'] ) ) 41 { 42 break; 43 } 44 } 45 return $option; 46 } 47 } 27 define('CAL_VIEW_LIST', 'list'); 28 define('CAL_VIEW_CALENDAR', 'calendar'); 48 29 49 30 function initialize_calendar() … … 54 35 $inner_sql = ' FROM ' . IMAGES_TABLE; 55 36 56 if (!isset($page['cat ']) or is_numeric($page['cat']))37 if (!isset($page['category']) or is_numeric($page['category'])) 57 38 { // we will regenerate the items by including subcats elements 58 39 $page['cat_nb_images'] = 0; … … 61 42 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; 62 43 63 if (isset($page['cat ']) and is_numeric($page['cat']))44 if (isset($page['category']) and is_numeric($page['category'])) 64 45 { 65 46 $sub_ids = array_diff( 66 get_subcat_ids(array($page['cat '])),47 get_subcat_ids(array($page['category'])), 67 48 explode(',', $user['forbidden_categories']) 68 49 ); … … 93 74 //-------------------------------------- initialize the calendar parameters --- 94 75 pwg_debug('start initialize_calendar'); 95 // the parameters look like (FIELD)?(STYLE)?(VIEW)?(DATE COMPONENTS)?96 // FIELD = (created-|posted-)97 // STYLE = (m-|w-)98 // VIEW = (l-|c-)99 // DATE COMPONENTS= YEAR(-MONTH/WEEK)?(-DAY)?100 76 101 77 $fields = array( 102 78 // Created 103 79 'created' => array( 104 'default_link' => 'created-',105 80 'label' => l10n('Creation date'), 106 'db_field' => 'date_creation',107 81 ), 108 82 // Posted 109 83 'posted' => array( 110 'default_link' => 'posted-',111 84 'label' => l10n('Post date'), 112 'db_field' => 'date_available',113 85 ), 114 86 ); … … 117 89 // Monthly style 118 90 'monthly' => array( 119 'default_link' => '',120 91 'include' => 'calendar_monthly.class.php', 121 92 'view_calendar' => true, … … 123 94 // Weekly style 124 95 'weekly' => array( 125 'default_link' => 'weekly-',126 96 'include' => 'calendar_weekly.class.php', 127 97 'view_calendar' => false, … … 129 99 ); 130 100 131 $views = array( 132 // list view 133 CAL_VIEW_LIST => array( 134 'default_link' => '', 135 ), 136 // calendar view 137 CAL_VIEW_CALENDAR => array( 138 'default_link' => CAL_VIEW_CALENDAR.'-', 139 ), 140 ); 141 142 $requested = explode('-', $_GET['calendar']); 101 $views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR); 143 102 144 103 // Retrieve calendar field 145 $cal_field = get_calendar_parameter($fields, $requested); 104 if ( !isset( $fields[ $page['chronology']['field'] ] ) ) 105 { 106 die('bad field'); 107 } 146 108 147 109 // Retrieve style 148 $cal_style = get_calendar_parameter($styles, $requested); 110 if ( !isset( $styles[ $page['chronology']['style'] ] ) ) 111 { 112 $page['chronology']['style'] = 'monthly'; 113 } 114 $cal_style = $page['chronology']['style']; 149 115 include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']); 150 116 $calendar = new Calendar(); 151 117 152 118 // Retrieve view 153 $cal_view = get_calendar_parameter($views, $requested); 154 if ( CAL_VIEW_CALENDAR==$cal_view and !$styles[$cal_style]['view_calendar'] ) 155 { 156 $cal_view=CAL_VIEW_LIST; 157 } 119 120 if ( !isset($page['chronology']['view']) or 121 !in_array( $page['chronology']['view'], $views ) ) 122 { 123 $page['chronology']['view'] = CAL_VIEW_LIST; 124 } 125 126 if ( CAL_VIEW_CALENDAR==$page['chronology']['view'] and 127 !$styles[$cal_style]['view_calendar'] ) 128 { 129 130 $page['chronology']['view'] = CAL_VIEW_LIST; 131 } 132 $cal_view = $page['chronology']['view']; 158 133 159 134 // perform a sanity check on $requested 160 while (count($requested) > 3) 161 { 162 array_pop($requested); 135 if (!isset($page['chronology_date'])) 136 { 137 $page['chronology_date'] = array(); 138 } 139 while ( count($page['chronology_date']) > 3) 140 { 141 array_pop($page['chronology_date']); 163 142 } 164 143 165 144 $any_count = 0; 166 for ($i = 0; $i < count($ requested); $i++)167 { 168 if ($ requested[$i] == 'any')145 for ($i = 0; $i < count($page['chronology_date']); $i++) 146 { 147 if ($page['chronology_date'][$i] == 'any') 169 148 { 170 149 if ($cal_view == CAL_VIEW_CALENDAR) 171 150 {// we dont allow any in calendar view 172 while ($i < count($ requested))151 while ($i < count($page['chronology_date'])) 173 152 { 174 array_pop($ requested);153 array_pop($page['chronology_date']); 175 154 } 176 155 break; … … 178 157 $any_count++; 179 158 } 180 elseif ($ requested[$i] == '')181 { 182 while ($i < count($ requested))159 elseif ($page['chronology_date'][$i] == '') 160 { 161 while ($i < count($page['chronology_date'])) 183 162 { 184 array_pop($ requested);163 array_pop($page['chronology_date']); 185 164 } 186 165 } 187 166 else 188 167 { 189 $ requested[$i] = (int)$requested[$i];168 $page['chronology_date'][$i] = (int)$page['chronology_date'][$i]; 190 169 } 191 170 } 192 171 if ($any_count == 3) 193 172 { 194 array_pop($ requested);195 } 196 197 $calendar->initialize($ fields[$cal_field]['db_field'], $inner_sql, $requested);173 array_pop($page['chronology_date']); 174 } 175 176 $calendar->initialize($inner_sql); 198 177 199 178 //echo ('<pre>'. var_export($calendar, true) . '</pre>'); 200 179 201 $url_base = get_query_string_diff(array('start', 'calendar'));180 /* $url_base = get_query_string_diff(array('start', 'calendar')); 202 181 $url_base = 203 182 PHPWG_ROOT_PATH.'category.php' … … 205 184 .(empty($url_base) ? '?' : '&') 206 185 .'calendar='.$cal_field.'-' 207 ; 186 ;*/ 208 187 $must_show_list = true; // true until calendar generates its own display 209 188 if (basename($_SERVER["PHP_SELF"]) == 'category.php') … … 211 190 $template->assign_block_vars('calendar', array()); 212 191 213 if ($calendar->generate_category_content( 214 $url_base.$cal_style.'-'.$cal_view.'-', 215 $cal_view 216 ) 217 ) 192 if ($calendar->generate_category_content()) 218 193 { 219 194 unset( … … 229 204 foreach ($styles as $style => $style_data) 230 205 { 231 foreach ($views as $view => $view_data)206 foreach ($views as $view) 232 207 { 233 208 if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR) 234 209 { 235 210 $selected = ''; 236 $url = $url_base.$style.'-'.$view; 237 if ($style==$cal_style) 211 $chronology = $page['chronology']; 212 $chronology['style'] = $style; 213 $chronology['view'] = $view; 214 215 if ($style!=$cal_style) 238 216 { 239 $ url .= '-'.implode('-', $calendar->date_components);240 if ( $view==$cal_view)217 $chronology_date = array(); 218 if ( isset($page['chronology_date'][0]) ) 241 219 { 242 $selected = 'SELECTED';220 array_push($chronology_date, $page['chronology_date'][0]); 243 221 } 244 222 } 245 223 else 246 224 { 247 if (isset($calendar->date_components[0])) 248 { 249 $url .= '-' . $calendar->date_components[0]; 250 } 225 $chronology_date = $page['chronology_date']; 251 226 } 227 $url = duplicate_index_url( 228 array( 229 'chronology' => $chronology, 230 'chronology_date' => $chronology_date, 231 ) 232 ); 233 234 if ($style==$cal_style and $view==$cal_view ) 235 { 236 $selected = 'SELECTED'; 237 } 238 252 239 $template->assign_block_vars( 253 240 'calendar.views.view', … … 261 248 } 262 249 } 263 $calendar_title = 264 '<a href="'.$url_base.$cal_style.'-'.$cal_view.'">' 265 .$fields[$cal_field]['label'].'</a>'; 250 $url = duplicate_index_url( 251 array('chronology_date'=>array()), array('start') 252 ); 253 $calendar_title = '<a href="'.$url.'">' 254 .$fields[$chronology['field']]['label'].'</a>'; 266 255 $calendar_title.= $calendar->get_display_name(); 267 256 //this should be an assign_block_vars, but I need to assign 'calendar'
Note: See TracChangeset
for help on using the changeset viewer.