Changeset 1057 for trunk/include/functions_calendar.inc.php
- Timestamp:
- Feb 24, 2006, 6:58:48 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_calendar.inc.php
r1056 r1057 28 28 define('CAL_VIEW_CALENDAR', 'c'); 29 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 } 48 30 49 function initialize_calendar() 31 50 { … … 74 93 //-------------------------------------- initialize the calendar parameters --- 75 94 pwg_debug('start initialize_calendar'); 76 77 $cal_styles = array( 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 101 $fields = array( 102 // Created 103 'created' => array( 104 // TODO change next line when calendar_datefield disapears 105 'default_link' => ( $conf['calendar_datefield']=='date_creation' ? '' : 'created-' ), 106 'label' => l10n('Creation date'), 107 'db_field' => 'date_creation', 108 ), 109 // Posted 110 'posted' => array( 111 // TODO change next line when calendar_datefield disapears 112 'default_link' => ( $conf['calendar_datefield']=='date_available' ? '' : 'posted-' ), 113 'label' => l10n('Availability date'), 114 'db_field' => 'date_available', 115 ), 116 ); 117 118 $styles = array( 78 119 // Monthly style 79 array( 80 'link' => 'm', 120 'monthly' => array( 81 121 'default_link' => '', 82 ' name' => l10n('Monthly'),122 'label' => l10n('Monthly'), 83 123 'include' => 'calendar_monthly.class.php', 84 124 'view_calendar' => true, 85 125 ), 86 126 // Weekly style 87 array( 88 'link' => 'w', 89 'default_link' => 'w-', 90 'name' => l10n('Weekly'), 127 'weekly' => array( 128 'default_link' => 'weekly-', 129 'label' => l10n('Weekly'), 91 130 'include' => 'calendar_weekly.class.php', 92 131 'view_calendar' => false, … … 94 133 ); 95 134 135 $views = array( 136 // list view 137 CAL_VIEW_LIST => array( 138 'default_link' => '', 139 'label' => l10n('List') 140 ), 141 // calendar view 142 CAL_VIEW_CALENDAR => array( 143 'default_link' => CAL_VIEW_CALENDAR.'-', 144 'label' => l10n('calendar') 145 ), 146 ); 147 96 148 $requested = explode('-', $_GET['calendar']); 97 $calendar = null; 98 foreach ($cal_styles as $cal_style) 99 { 100 if ($requested[0] == $cal_style['link']) 101 { 102 include(PHPWG_ROOT_PATH.'include/'.$cal_style['include']); 103 $calendar = new Calendar(); 104 array_shift($requested); 105 break; 106 } 107 } 108 109 if (!isset($calendar)) 110 { 111 foreach($cal_styles as $cal_style) 112 { 113 if ('' == $cal_style['default_link']) 114 { 115 break; 116 } 117 } 118 include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']); 119 $calendar = new Calendar(); 120 } 121 122 $view_type = CAL_VIEW_LIST; 123 if ($requested[0] == CAL_VIEW_LIST) 124 { 125 array_shift($requested); 126 } 127 elseif ($requested[0] == CAL_VIEW_CALENDAR) 128 { 129 if ($cal_style['view_calendar']) 130 { 131 $view_type = CAL_VIEW_CALENDAR; 132 } 133 array_shift($requested); 134 } 149 150 // Retrieve calendar field 151 $cal_field = get_calendar_parameter($fields, $requested); 152 153 // Retrieve style 154 $cal_style = get_calendar_parameter($styles, $requested); 155 include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']); 156 $calendar = new Calendar(); 157 158 // Retrieve view 159 $cal_view = get_calendar_parameter($views, $requested); 160 if ( CAL_VIEW_CALENDAR==$cal_view and !$styles[$cal_style]['view_calendar'] ) 161 { 162 $cal_view=CAL_VIEW_LIST; 163 } 164 135 165 // perform a sanity check on $requested 136 166 while (count($requested) > 3) … … 144 174 if ($requested[$i] == 'any') 145 175 { 146 if ($ view_type== CAL_VIEW_CALENDAR)176 if ($cal_view == CAL_VIEW_CALENDAR) 147 177 {// we dont allow any in calendar view 148 178 while ($i < count($requested)) … … 166 196 array_pop($requested); 167 197 } 168 169 $calendar->initialize($conf['calendar_datefield'], $inner_sql); 170 //echo ('<pre>'. var_export($requested, true) . '</pre>'); 171 //echo ('<pre>'. var_export($calendar, true) . '</pre>'); 172 173 // TODO: what makes the list view required? 174 $must_show_list = true; 175 198 199 $calendar->initialize($fields[$cal_field]['db_field'], $inner_sql, $requested); 200 201 //echo ('<pre>'. var_export($fields, true) . '</pre>'); 202 203 $url_base = 204 PHPWG_ROOT_PATH.'category.php' 205 .get_query_string_diff(array('start', 'calendar')) 206 .(empty($url_base) ? '?' : '&') 207 .'calendar='.$cal_field.'-' 208 ; 209 210 $must_show_list = true; // true until calendar generates its own display 176 211 if (basename($_SERVER["PHP_SELF"]) == 'category.php') 177 212 { 178 213 $template->assign_block_vars('calendar', array()); 179 214 180 $url_base =181 PHPWG_ROOT_PATH.'category.php'182 .get_query_string_diff(array('start', 'calendar'))183 .(empty($url_base) ? '?' : '&')184 .'calendar='185 ;186 187 215 if ($calendar->generate_category_content( 188 $url_base.$cal_style['default_link'], 189 $view_type, 190 $requested 216 $url_base.$cal_style.'-'.$cal_view.'-', 217 $cal_view 191 218 ) 192 219 ) … … 200 227 $must_show_list = false; 201 228 } 202 203 if ($cal_style['view_calendar']) 204 { // Build bar for views (List/Calendar) 205 $views = array( 206 // list view 207 array( 208 'type' => CAL_VIEW_LIST, 209 'label' => l10n('List') 210 ), 211 // calendar view 212 array( 213 'type' => CAL_VIEW_CALENDAR, 214 'label' => l10n('calendar') 215 ), 216 ); 217 218 $views_bar = ''; 219 220 foreach ($views as $view) 229 230 $template->assign_block_vars( 'calendar.views', array() ); 231 foreach ($styles as $style => $style_data) 232 { 233 foreach ($views as $view => $view_data) 221 234 { 222 if ( $view_type != $view['type'])235 if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR) 223 236 { 224 $views_bar.= 225 '<a href="' 226 .$url_base.$cal_style['default_link'].$view['type'].'-' 227 .implode('-', $requested) 228 .'">'.$view['label'].'</a> '; 237 $selected = ''; 238 $url = $url_base.$style.'-'.$view; 239 if ($style==$cal_style) 240 { 241 $url .= '-'.implode('-', $calendar->date_components); 242 if ( $view==$cal_view ) 243 { 244 $selected = 'SELECTED'; 245 } 246 } 247 else 248 { 249 if (isset($calendar->date_components[0])) 250 { 251 $url .= '-' . $calendar->date_components[0]; 252 } 253 } 254 $template->assign_block_vars( 255 'calendar.views.view', 256 array( 257 'VALUE' => $url, 258 'CONTENT' => $style_data['label'].' ('.$view_data['label'].')', 259 'SELECTED' => $selected, 260 ) 261 ); 229 262 } 230 else231 {232 $views_bar.= $view['label'].' ';233 }234 235 $views_bar.= ' ';236 263 } 237 238 $template->assign_block_vars( 239 'calendar.views', 240 array( 241 'BAR' => $views_bar, 242 ) 243 ); 244 } 245 246 // Build bar for calendar styles (Monthly, Weekly) 247 $styles_bar = ''; 248 foreach ($cal_styles as $style) 249 { 250 if ($cal_style['link'] != $style['link']) 251 { 252 $url = $url_base.$style['default_link']; 253 $url .= $view_type; 254 if (isset($requested[0])) 255 { 256 $url .= '-' . $requested[0]; 257 } 258 $styles_bar .= '<a href="'. $url . '">'.$style['name'].'</a> '; 259 } 260 else 261 { 262 $styles_bar .= $style['name'].' '; 263 } 264 } 265 $template->assign_block_vars( 266 'calendar.styles', 267 array( 268 'BAR' => $styles_bar, 269 ) 270 ); 264 } 271 265 } // end category calling 272 266 267 $calendar_title = 268 '<a href="'.$url_base.$cal_style.'-'.$cal_view.'">' 269 .$fields[$cal_field]['label'].'</a>'; 270 $calendar_title.= $calendar->get_display_name(); 271 $template->assign_block_vars( 272 'calendar', 273 array( 274 'TITLE' => $calendar_title, 275 ) 276 ); 277 273 278 if ($must_show_list) 274 279 { 275 280 $query = 'SELECT DISTINCT(id)'; 276 281 $query .= $calendar->inner_sql; 277 $query .= $calendar->get_date_where( $requested);282 $query .= $calendar->get_date_where(); 278 283 if ( isset($page['super_order_by']) ) 279 284 {
Note: See TracChangeset
for help on using the changeset viewer.