| [ Index ] |
krapohl.info |
[Summary view] [Print] [Text view]
1 <?php 2 @define('__POSTCALENDAR__','PostCalendar'); 3 /** 4 * $Id: calendar.php,v 1.3 2004/02/29 14:08:12 larsneo Exp $ 5 * 6 * PostCalendar::PostNuke Events Calendar Module 7 * Copyright (C) 2002 The PostCalendar Team 8 * http://postcalendar.tv 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU 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 USA 23 * 24 * To read the license please read the docs/license.txt or visit 25 * http://www.gnu.org/copyleft/gpl.html 26 * 27 */ 28 // load the user api functions 29 pnModAPILoad(__POSTCALENDAR__,'user'); 30 31 /** 32 * initialise block 33 */ 34 function postcalendar_calendarblock_init() 35 { 36 // Security 37 pnSecAddSchema('PostCalendar:calendarblock:', 'Block title::'); 38 } 39 40 /** 41 * get information on block 42 */ 43 function postcalendar_calendarblock_info() 44 { 45 // Values 46 return array('text_type' => __POSTCALENDAR__, 47 'module' => __POSTCALENDAR__, 48 'text_type_long' => 'Calendar Block', 49 'allow_multiple' => true, 50 'form_content' => false, 51 'form_refresh' => false, 52 'show_preview' => true); 53 } 54 55 /** 56 * display block 57 */ 58 function postcalendar_calendarblock_display($blockinfo) 59 { 60 // You supposed to be here? 61 if (!pnSecAuthAction(0,'PostCalendar:calendarblock:', "$blockinfo[title]::", ACCESS_OVERVIEW)) { 62 return false; 63 } 64 65 // find out what view we're using 66 $template_view = pnVarCleanFromInput('tplview'); 67 if(!isset($template_view)) { 68 $template_view ='default'; 69 } 70 71 // find out what template we're using 72 $template_name = _SETTING_TEMPLATE; 73 if(!isset($template_name) || empty($template_name)) { 74 $template_name ='default'; 75 } 76 77 // What is today's correct date 78 $Date =& postcalendar_getDate(); 79 80 // Get variables from content block 81 $vars = unserialize($blockinfo['content']); 82 $showcalendar = $vars['pcbshowcalendar']; 83 $showevents = $vars['pcbeventoverview']; 84 $eventslimit = $vars['pcbeventslimit']; 85 $nextevents = $vars['pcbnextevents']; 86 $pcbshowsslinks = $vars['pcbshowsslinks']; 87 $pcbeventsrange = $vars['pcbeventsrange']; 88 89 // Let's setup the info to build this sucka! 90 $the_year = substr($Date,0,4); 91 $the_month = substr($Date,4,2); 92 $the_day = substr($Date,6,2); 93 $uid = pnUserGetVar('uid'); 94 95 $cacheid1 = $cacheid2 = $cacheid3 = ''; 96 $theme = pnUserGetTheme(); 97 98 pnThemeLoad($theme); 99 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5; 100 global $textcolor1, $textcolor2; 101 102 // 20021125 - rraymond :: we have to do this to make it work with envolution 103 $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__)); 104 $pcDir = pnVarPrepForOS($pcModInfo['directory']); 105 if(!pnModAvailable('pnRender')){ 106 require_once("modules/$pcDir/pnincludes/Smarty/Config_File.class.php"); 107 } 108 unset($pcModInfo); 109 110 // set up Smarty 111 $tpl =& new pcSmarty(); 112 113 // setup the Smarty cache id 114 $templates_cached = true; 115 if($showcalendar) { 116 $cacheid1 = md5($Date.'M'.$template_view.$template_name.$showcalendar.$showevents.$nextevents.$uid.$theme); 117 if(!$tpl->is_cached($template_name.'/views/calendarblock/month_view.html',$cacheid1)) { 118 $templates_cached = false; 119 } 120 } 121 if($showevents) { 122 $cacheid2 = md5($Date.'T'.$template_view.$template_name.$showcalendar.$showevents.$nextevents.$uid.$theme); 123 if(!$tpl->is_cached($template_name.'/views/calendarblock/todays_events.html',$cacheid2)) { 124 $templates_cached = false; 125 } 126 } 127 if($nextevents) { 128 $cacheid3 = md5($Date.'U'.$template_view.$template_name.$showcalendar.$showevents.$nextevents.$uid.$theme); 129 if(!$tpl->is_cached($template_name.'/views/calendarblock/upcoming_events.html',$cacheid3)) { 130 $templates_cached = false; 131 } 132 } 133 134 // start the output container 135 $output = pnModAPIFunc(__POSTCALENDAR__,'user','pageSetup'); 136 137 // if one of the templates is not cached, we need to run the following 138 if(!$templates_cached) { 139 // set up the next and previous months to move to 140 $prev_month = Date_Calc::beginOfPrevMonth(1,$the_month,$the_year,'%Y%m%d'); 141 $next_month = Date_Calc::beginOfNextMonth(1,$the_month,$the_year,'%Y%m%d'); 142 $last_day = Date_Calc::daysInMonth($the_month,$the_year); 143 $pc_prev = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__,'user','view',array('tplview'=>$template_view,'viewtype'=>'month','Date'=>$prev_month))); 144 $pc_next = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__,'user','view',array('tplview'=>$template_view,'viewtype'=>'month','Date'=>$next_month))); 145 $pc_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname', array('Date'=>mktime(0,0,0,$the_month,$the_day,$the_year))); 146 $month_link_url = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__, 'user', 'view', array('tplview'=>$template_view,'viewtype'=>'month','Date'=>date('Ymd',mktime(0,0,0,$the_month,1,$the_year))))); 147 $month_link_text = $pc_month_name.' '.$the_year; 148 //******************************************************************* 149 // Here we get the events for the current month view 150 //******************************************************************* 151 $day_of_week = 1; 152 $pc_month_names = array(_CALJAN,_CALFEB,_CALMAR,_CALAPR,_CALMAY,_CALJUN, 153 _CALJUL,_CALAUG,_CALSEP,_CALOCT,_CALNOV,_CALDEC); 154 155 $pc_short_day_names = array(_CALSUNDAYSHORT, _CALMONDAYSHORT, 156 _CALTUESDAYSHORT, _CALWEDNESDAYSHORT, 157 _CALTHURSDAYSHORT, _CALFRIDAYSHORT, 158 _CALSATURDAYSHORT); 159 160 $pc_long_day_names = array(_CALSUNDAY, _CALMONDAY, 161 _CALTUESDAY, _CALWEDNESDAY, 162 _CALTHURSDAY, _CALFRIDAY, 163 _CALSATURDAY); 164 switch (_SETTING_FIRST_DAY_WEEK) 165 { 166 case _IS_MONDAY: 167 $pc_array_pos = 1; 168 $first_day = date('w',mktime(0,0,0,$the_month,0,$the_year)); 169 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year)); 170 if($end_dow != 0) { 171 $the_last_day = $last_day+(7-$end_dow); 172 } else { 173 $the_last_day = $last_day; 174 } 175 break; 176 case _IS_SATURDAY: 177 $pc_array_pos = 6; 178 $first_day = date('w',mktime(0,0,0,$the_month,2,$the_year)); 179 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year)); 180 if($end_dow == 6) { 181 $the_last_day = $last_day+6; 182 } elseif($end_dow != 5) { 183 $the_last_day = $last_day+(5-$end_dow); 184 } else { 185 $the_last_day = $last_day; 186 } 187 break; 188 case _IS_SUNDAY: 189 default: 190 $pc_array_pos = 0; 191 $first_day = date('w',mktime(0,0,0,$the_month,1,$the_year)); 192 $end_dow = date('w',mktime(0,0,0,$the_month,$last_day,$the_year)); 193 if($end_dow != 6) { 194 $the_last_day = $last_day+(6-$end_dow); 195 } else { 196 $the_last_day = $last_day; 197 } 198 break; 199 } 200 201 $month_view_start = date('Y-m-d',mktime(0,0,0,$the_month,1,$the_year)); 202 $month_view_end = date('Y-m-t',mktime(0,0,0,$the_month,1,$the_year)); 203 $today_date = postcalendar_today('%Y-%m-%d'); 204 $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,1-$first_day,$the_year)); 205 $ending_date = date('m/t/Y',mktime(0,0,0,$the_month+$pcbeventsrange,1,$the_year)); 206 207 $eventsByDate =& pnModAPIFunc(__POSTCALENDAR__,'user','pcGetEvents', array('start'=>$starting_date,'end'=>$ending_date)); 208 $calendarView = Date_Calc::getCalendarMonth($the_month, $the_year, '%Y-%m-%d'); 209 210 $sdaynames = array(); 211 $numDays = count($pc_short_day_names); 212 for($i=0; $i < $numDays; $i++) 213 { if($pc_array_pos >= $numDays) { 214 $pc_array_pos = 0; 215 } 216 array_push($sdaynames,$pc_short_day_names[$pc_array_pos]); 217 $pc_array_pos++; 218 } 219 $daynames = array(); 220 $numDays = count($pc_long_day_names); 221 for($i=0; $i < $numDays; $i++) 222 { if($pc_array_pos >= $numDays) { 223 $pc_array_pos = 0; 224 } 225 array_push($daynames,$pc_long_day_names[$pc_array_pos]); 226 $pc_array_pos++; 227 } 228 229 $dates = array(); 230 while($starting_date <= $ending_date) { 231 array_push($dates,$starting_date); 232 list($m,$d,$y) = explode('/',$starting_date); 233 $starting_date = Date_Calc::nextDay($d,$m,$y,'%m/%d/%Y'); 234 } 235 236 $categories =& pnModAPIFunc(__POSTCALENDAR__,'user','getCategories'); 237 if(isset($calendarView)) { 238 $tpl->assign_by_ref('CAL_FORMAT',$calendarView); 239 } 240 $tpl->assign_by_ref('A_MONTH_NAMES',$pc_month_names); 241 $tpl->assign_by_ref('A_LONG_DAY_NAMES',$pc_long_day_names); 242 $tpl->assign_by_ref('A_SHORT_DAY_NAMES',$pc_short_day_names); 243 $tpl->assign_by_ref('S_LONG_DAY_NAMES',$daynames); 244 $tpl->assign_by_ref('S_SHORT_DAY_NAMES',$sdaynames); 245 $tpl->assign_by_ref('A_EVENTS',$eventsByDate); 246 $tpl->assign_by_ref('A_CATEGORY',$categories); 247 $tpl->assign_by_ref('PREV_MONTH_URL',$pc_prev); 248 $tpl->assign_by_ref('NEXT_MONTH_URL',$pc_next); 249 $tpl->assign_by_ref('MONTH_START_DATE',$month_view_start); 250 $tpl->assign_by_ref('MONTH_END_DATE',$month_view_end); 251 $tpl->assign_by_ref('TODAY_DATE',$today_date); 252 $tpl->assign_by_ref('DATE',$Date); 253 $tpl->assign_by_ref('DISPLAY_LIMIT',$eventslimit); 254 $tpl->assign('TODAYS_EVENTS_TITLE',_PC_TODAYS_EVENTS); 255 $tpl->assign('UPCOMING_EVENTS_TITLE',_PC_UPCOMING_EVENTS); 256 $tpl->assign('NO_EVENTS',_PC_BLOCK_NO_EVENTS); 257 } 258 259 if($showcalendar) { 260 // we need to create a unique ID for caching purposes 261 $output .= $tpl->fetch($template_name.'/views/calendarblock/month_view.html',$cacheid1); 262 } 263 264 if($showevents) { 265 if($showcalendar) { 266 $tpl->assign('SHOW_TITLE',1); 267 } else { 268 $tpl->assign('SHOW_TITLE',0); 269 } 270 // we need to create a unique ID for caching purposes 271 $output .= $tpl->fetch($template_name.'/views/calendarblock/todays_events.html',$cacheid2); 272 } 273 274 if($nextevents) { 275 if($showcalendar || $showevents) { 276 $tpl->assign('SHOW_TITLE',1); 277 } else { 278 $tpl->assign('SHOW_TITLE',0); 279 } 280 // we need to create a unique ID for caching purposes 281 $output .= $tpl->fetch($template_name.'/views/calendarblock/upcoming_events.html',$cacheid3); 282 } 283 284 if($pcbshowsslinks) { 285 $output .= '<br /><br />'; 286 $submit_event_url = pnModURL(__POSTCALENDAR__,'user','submit'); 287 $search_event_url = pnModURL(__POSTCALENDAR__,'user','search'); 288 $output .= '<center>'; 289 if(PC_ACCESS_ADD) { 290 $output .= '[ <a href="'.$submit_event_url.'">'._PC_SUBMIT_EVENT.'</a> ] '; 291 } 292 $output .= '[ <a href="'.$search_event_url.'">'._PC_SEARCH_EVENT.'</a> ]'; 293 $output .= '</center>'; 294 } 295 // Populate block info and pass to theme 296 297 $blockinfo['content'] = $output; 298 return themesideblock($blockinfo); 299 } 300 301 302 /** 303 * modify block settings .. 304 */ 305 function postcalendar_calendarblock_modify($blockinfo) 306 { 307 if (!pnSecAuthAction(0,'PostCalendar:calendarblock:',"$blockinfo[title]::",ACCESS_ADMIN)) { 308 return false; 309 } 310 311 // Create output object 312 $output =& new pnHTML(); 313 // Get variables from content block 314 $vars = unserialize($blockinfo['content']); 315 $i=0; 316 $output->SetOutputMode(_PNH_RETURNOUTPUT); 317 318 $settings[$i][] = $output->Text(_PC_BLOCK_SHOW_CALENDAR); 319 $settings[$i++][] = $output->FormCheckBox('pcbshowcalendar', @$vars['pcbshowcalendar']); 320 321 $settings[$i][] = $output->Text(_PC_BLOCK_EVENT_OVERVIEW); 322 $settings[$i++][] = $output->FormCheckBox('pcbeventoverview', @$vars['pcbeventoverview']); 323 324 $settings[$i][] = $output->Text(_PC_BLOCK_UPCOMING_EVENTS); 325 $settings[$i++][] = $output->FormCheckBox('pcbnextevents', @$vars['pcbnextevents']); 326 327 $settings[$i][] = $output->Text(_PC_SHOW_SS_LINKS); 328 $settings[$i++][] = $output->FormCheckBox('pcbshowsslinks', @$vars['pcbshowsslinks']); 329 330 $settings[$i][] = $output->Text(_PC_BLOCK_EVENTS_DISPLAY_LIMIT); 331 $settings[$i++][] = $output->FormText('pcbeventslimit', @$vars['pcbeventslimit'],5); 332 333 $settings[$i][] = $output->Text(_PC_BLOCK_EVENTS_DISPLAY_RANGE); 334 $settings[$i++][] = $output->FormText('pcbeventsrange', @$vars['pcbeventsrange'],5); 335 336 $output->SetOutputMode(_PNH_KEEPOUTPUT); 337 338 // Add row 339 $output->SetInputMode(_PNH_VERBATIMINPUT); 340 for($i=0; $i<count($settings); $i++) { 341 $output->TableAddRow($settings[$i], 'left'); 342 } 343 $output->SetInputMode(_PNH_PARSEINPUT); 344 345 // Return output 346 return $output->GetOutput(); 347 } 348 349 /** 350 * update block settings 351 */ 352 function postcalendar_calendarblock_update($blockinfo) 353 { 354 // Security check 355 if (!pnSecAuthAction(0,'PostCalendar:calendarblock:',"$blockinfo[title]::",ACCESS_ADMIN)) { 356 return false; 357 } 358 359 list($vars['pcbshowcalendar'], 360 $vars['pcbeventslimit'], 361 $vars['pcbeventoverview'], 362 $vars['pcbnextevents'], 363 $vars['pcbeventsrange'], 364 $vars['pcbshowsslinks']) = pnVarCleanFromInput('pcbshowcalendar', 365 'pcbeventslimit', 366 'pcbeventoverview', 367 'pcbnextevents', 368 'pcbeventsrange', 369 'pcbshowsslinks'); 370 // set up defaults if not defined 371 if(!isset($vars['pcbshowcalendar'])) { $vars['pcbshowcalendar'] = 0; } 372 if(!isset($vars['pcbeventslimit'])) { $vars['pcbeventslimit'] = 5; } 373 if(!isset($vars['pcbeventoverview'])) { $vars['pcbeventoverview'] = 0; } 374 if(!isset($vars['pcbnextevents'])) { $vars['pcbnextevents'] = 0; } 375 if(!isset($vars['pcbeventsrange'])) { $vars['pcbeventsrange'] = 6; } 376 if(!isset($vars['pcbshowsslinks'])) { $vars['pcbshowsslinks'] = 0; } 377 378 $tpl =& new pcSmarty(); 379 $tpl->clear_all_cache(); 380 $blockinfo['content'] = serialize($vars); 381 return $blockinfo; 382 } 383 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Feb 16 22:40:07 2005 | Cross-referenced by PHPXref 0.6 |