| [ Index ] |
krapohl.info |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * $Id: common.api.php,v 1.5 2004/08/19 19:17:44 larsneo Exp $ 4 * 5 * PostCalendar::PostNuke Events Calendar Module 6 * Copyright (C) 2002 The PostCalendar Team 7 * http://postcalendar.tv 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * 23 * To read the license please read the docs/license.txt or visit 24 * http://www.gnu.org/copyleft/gpl.html 25 * 26 */ 27 28 //================================================================= 29 // define constants used to make the code more readable 30 //================================================================= 31 define('_IS_SUNDAY', 0); 32 define('_IS_MONDAY', 1); 33 define('_IS_SATURDAY', 6); 34 define('_AM_VAL', 1); 35 define('_PM_VAL', 2); 36 define('_ACTION_DELETE', 4); 37 define('_ACTION_EDIT', 2); 38 define('_EVENT_APPROVED', 1); 39 define('_EVENT_QUEUED', 0); 40 define('_EVENT_HIDDEN', -1); 41 // $event_repeat 42 define('NO_REPEAT', 0); 43 define('REPEAT', 1); 44 define('REPEAT_ON', 2); 45 // $event_repeat_freq 46 define('REPEAT_EVERY', 1); 47 define('REPEAT_EVERY_OTHER', 2); 48 define('REPEAT_EVERY_THIRD', 3); 49 define('REPEAT_EVERY_FOURTH', 4); 50 // $event_repeat_freq_type 51 define('REPEAT_EVERY_DAY', 0); 52 define('REPEAT_EVERY_WEEK', 1); 53 define('REPEAT_EVERY_MONTH', 2); 54 define('REPEAT_EVERY_YEAR', 3); 55 // $event_repeat_on_num 56 define('REPEAT_ON_1ST', 1); 57 define('REPEAT_ON_2ND', 2); 58 define('REPEAT_ON_3RD', 3); 59 define('REPEAT_ON_4TH', 4); 60 define('REPEAT_ON_LAST', 5); 61 // $event_repeat_on_day 62 define('REPEAT_ON_SUN', 0); 63 define('REPEAT_ON_MON', 1); 64 define('REPEAT_ON_TUE', 2); 65 define('REPEAT_ON_WED', 3); 66 define('REPEAT_ON_THU', 4); 67 define('REPEAT_ON_FRI', 5); 68 define('REPEAT_ON_SAT', 6); 69 // $event_repeat_on_freq 70 define('REPEAT_ON_MONTH', 1); 71 define('REPEAT_ON_2MONTH', 2); 72 define('REPEAT_ON_3MONTH', 3); 73 define('REPEAT_ON_4MONTH', 4); 74 define('REPEAT_ON_6MONTH', 6); 75 define('REPEAT_ON_YEAR', 12); 76 // event sharing values 77 define('SHARING_PRIVATE', 0); 78 define('SHARING_PUBLIC', 1); 79 define('SHARING_BUSY', 2); 80 define('SHARING_GLOBAL', 3); 81 // admin defines 82 define('_ADMIN_ACTION_APPROVE', 0); 83 define('_ADMIN_ACTION_HIDE', 1); 84 define('_ADMIN_ACTION_EDIT', 2); 85 define('_ADMIN_ACTION_VIEW', 3); 86 define('_ADMIN_ACTION_DELETE', 4); 87 //================================================================= 88 // Get the global PostCalendar config settings 89 // This will save us a lot of time and DB queries later 90 //================================================================= 91 define('_SETTING_USE_POPUPS', pnModGetVar(__POSTCALENDAR__,'pcUsePopups')); 92 define('_SETTING_USE_INT_DATES', pnModGetVar(__POSTCALENDAR__,'pcUseInternationalDates')); 93 define('_SETTING_OPEN_NEW_WINDOW', pnModGetVar(__POSTCALENDAR__,'pcEventsOpenInNewWindow')); 94 define('_SETTING_DAY_HICOLOR', pnModGetVar(__POSTCALENDAR__,'pcDayHighlightColor')); 95 define('_SETTING_FIRST_DAY_WEEK', pnModGetVar(__POSTCALENDAR__,'pcFirstDayOfWeek')); 96 define('_SETTING_DATE_FORMAT', pnModGetVar(__POSTCALENDAR__,'pcEventDateFormat')); 97 define('_SETTING_TIME_24HOUR', pnModGetVar(__POSTCALENDAR__,'pcTime24Hours')); 98 define('_SETTING_DIRECT_SUBMIT', pnModGetVar(__POSTCALENDAR__,'pcAllowDirectSubmit')); 99 define('_SETTING_DISPLAY_TOPICS', pnModGetVar(__POSTCALENDAR__,'pcDisplayTopics')); 100 define('_SETTING_ALLOW_GLOBAL', pnModGetVar(__POSTCALENDAR__,'pcAllowSiteWide')); 101 define('_SETTING_ALLOW_USER_CAL', pnModGetVar(__POSTCALENDAR__,'pcAllowUserCalendar')); 102 define('_SETTING_TIME_INCREMENT', pnModGetVar(__POSTCALENDAR__,'pcTimeIncrement')); 103 define('_SETTING_HOW_MANY_EVENTS', pnModGetVar(__POSTCALENDAR__,'pcListHowManyEvents')); 104 define('_SETTING_TEMPLATE', pnModGetVar(__POSTCALENDAR__,'pcTemplate')); 105 define('_SETTING_EVENTS_IN_YEAR', pnModGetVar(__POSTCALENDAR__,'pcShowEventsInYear')); 106 define('_SETTING_USE_CACHE', pnModGetVar(__POSTCALENDAR__,'pcUseCache')); 107 define('_SETTING_CACHE_LIFETIME', pnModGetVar(__POSTCALENDAR__,'pcCacheLifetime')); 108 define('_SETTING_DEFAULT_VIEW', pnModGetVar(__POSTCALENDAR__,'pcDefaultView')); 109 define('_SETTING_SAFE_MODE', pnModGetVar(__POSTCALENDAR__,'pcSafeMode')); 110 define('_SETTING_NOTIFY_ADMIN', pnModGetVar(__POSTCALENDAR__,'pcNotifyAdmin')); 111 define('_SETTING_NOTIFY_EMAIL', pnModGetVar(__POSTCALENDAR__,'pcNotifyEmail')); 112 //================================================================= 113 // Make checking basic permissions easier 114 //================================================================= 115 define('PC_ACCESS_ADMIN', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_ADMIN)); 116 define('PC_ACCESS_DELETE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_DELETE)); 117 define('PC_ACCESS_ADD', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_ADD)); 118 define('PC_ACCESS_EDIT', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_EDIT)); 119 define('PC_ACCESS_MODERATE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_MODERATE)); 120 define('PC_ACCESS_COMMENT', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_COMMENT)); 121 define('PC_ACCESS_READ', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_READ)); 122 define('PC_ACCESS_OVERVIEW', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_OVERVIEW)); 123 define('PC_ACCESS_NONE', pnSecAuthAction(0, 'PostCalendar::', 'null::null', ACCESS_NONE)); 124 //========================================================================= 125 // Require and Setup utility classes and functions 126 //========================================================================= 127 define('DATE_CALC_BEGIN_WEEKDAY', _SETTING_FIRST_DAY_WEEK); 128 require_once("modules/$pcDir/pnincludes/Date/Calc.php"); 129 //========================================================================= 130 // grab the global language file 131 //========================================================================= 132 $userlang = pnUserGetLang(); 133 if(file_exists("modules/$pcDir/pnlang/$userlang/global.php")) { 134 require_once("modules/$pcDir/pnlang/$userlang/global.php"); 135 } else { 136 require_once("modules/$pcDir/pnlang/eng/global.php"); 137 } 138 unset($userlang); 139 //========================================================================= 140 // Setup Smarty defines 141 //========================================================================= 142 if(!class_exists('Smarty')) { 143 define('_PC_SMARTY_LOADED',true); 144 define('SMARTY_DIR',"modules/$pcDir/pnincludes/Smarty/"); 145 require_once(SMARTY_DIR.'/Smarty.class.php'); 146 } 147 require_once("modules/$pcDir/pcSmarty.class.php"); 148 //========================================================================= 149 // utility functions for postcalendar 150 //========================================================================= 151 function pcDebugVar($in) 152 { 153 echo '<pre>'; 154 if(is_array($in)) print_r($in); 155 else echo $in; 156 echo '</pre>'; 157 } 158 function &pcVarPrepForDisplay($s) { 159 $s = nl2br(pnVarPrepForDisplay(postcalendar_removeScriptTags($s))); 160 $s = preg_replace('/&(#)?([0-9a-z]+);/i','&\\1\\2;',$s); 161 return $s; 162 } 163 function &pcVarPrepHTMLDisplay($s) { 164 return pnVarPrepHTMLDisplay(postcalendar_removeScriptTags($s)); 165 } 166 function pcGetTopicName($topicid) 167 { 168 list($dbconn) = pnDBGetConn(); 169 $pntable = pnDBGetTables(); 170 171 $topics_table = $pntable['topics']; 172 $topics_column = &$pntable['topics_column']; 173 $sql = "SELECT $topics_column[topicname] 174 FROM $topics_table 175 WHERE $topics_column[topicid] = '".(int)pnVarPrepForStore($topicid)."'"; 176 $result = $dbconn->Execute($sql); 177 if($result === false) return ''; 178 else return $result->fields[0]; 179 } 180 function &postcalendar_makeValidURL($s) 181 { 182 if(empty($s)) return ''; 183 if(!preg_match('|^http[s]?:\/\/|i',$s)) { 184 $s = 'http://'.$s; 185 } 186 return $s; 187 } 188 function postcalendar_removeScriptTags($in) 189 { 190 return preg_replace("/<script.*?>(.*?)<\/script>/","",$in); 191 } 192 function &postcalendar_getDate($format='%Y%m%d') 193 { 194 list($Date,$jumpday,$jumpmonth,$jumpyear) = pnVarCleanFromInput('Date','jumpday','jumpmonth','jumpyear'); 195 if(!isset($Date)) { 196 // if we still don't have a date then calculate it 197 $time = time(); 198 if (pnUserLoggedIn()) { 199 $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600; 200 } 201 // check the jump menu 202 if(!isset($jumpday)) $jumpday = strftime('%d',$time); 203 if(!isset($jumpmonth)) $jumpmonth = strftime('%m',$time); 204 if(!isset($jumpyear)) $jumpyear = strftime('%Y',$time); 205 // create the correct date string 206 $Date = (int) "$jumpyear$jumpmonth$jumpday"; 207 } 208 $y = substr($Date,0,4); 209 $m = substr($Date,4,2); 210 $d = substr($Date,6,2); 211 return strftime($format,mktime(0,0,0,$m,$d,$y)); 212 } 213 214 function &postcalendar_today($format='%Y%m%d') 215 { 216 $time = time(); 217 if (pnUserLoggedIn()) { 218 $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600; 219 } 220 return strftime($format,$time); 221 } 222 223 /** 224 * postcalendar_adminapi_pageSetup() 225 * 226 * sets up any necessary javascript for the page 227 * @return string javascript to insert into the page 228 */ 229 function postcalendar_adminapi_pageSetup() { return postcalendar_userapi_pageSetup(); } 230 /** 231 * postcalendar_userapi_pageSetup() 232 * 233 * sets up any necessary javascript for the page 234 * @return string javascript to insert into the page 235 */ 236 function postcalendar_userapi_pageSetup() 237 { 238 $output = ''; 239 // load the DHTML JavaScript code and insert it into the page 240 if(_SETTING_USE_POPUPS) { $output .= postcalendar_userapi_loadPopups(); } 241 // insert the js popup code into the page (find better code) 242 if(_SETTING_OPEN_NEW_WINDOW) { $output .= postcalendar_userapi_jsPopup(); } 243 return $output; 244 } 245 /** 246 * postcalendar_userapi_jsPopup 247 * Creates the necessary javascript code for a popup window 248 */ 249 function postcalendar_userapi_jsPopup() 250 { if(defined('_POSTCALENDAR_JSPOPUPS_LOADED')) { 251 // only put the script on the page once 252 return false; 253 } 254 define('_POSTCALENDAR_JSPOPUPS_LOADED',true); 255 256 // build the correct link 257 $js_link = "'index.php?module=".__POSTCALENDAR__."&type=user&func=view&viewtype=details&eid='+eid+'&Date='+date+'&popup=1'"; 258 $js_window_options = 'toolbar=no,' 259 . 'location=no,' 260 . 'directories=no,' 261 . 'status=no,' 262 . 'menubar=no,' 263 . 'scrollbars=yes,' 264 . 'resizable=no,' 265 . 'width=600,' 266 . 'height=300'; 267 268 $output = <<<EOF 269 270 <script type="text/javascript" language="JavaScript"> 271 <!-- 272 function opencal(eid,date) { 273 window.name='csCalendar'; 274 w = window.open($js_link,'PostCalendarEvents','$js_window_options'); 275 } 276 // --> 277 </script> 278 279 EOF; 280 return $output; 281 } 282 283 /** 284 * postcalendar_userapi_loadPopups 285 * Creates the necessary javascript code for mouseover dHTML popups 286 */ 287 function postcalendar_userapi_loadPopups() 288 { if(defined('_POSTCALENDAR_LOADPOPUPS_LOADED')) { 289 // only put the script on the page once 290 return false; 291 } 292 define('_POSTCALENDAR_LOADPOPUPS_LOADED',true); 293 294 // get the theme globals :: is there a better way to do this? 295 global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5; 296 global $textcolor1, $textcolor2; 297 298 // lets get the module's information 299 $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__)); 300 $pcDir = pnVarPrepForOS($modinfo['directory']); 301 unset($modinfo); 302 $capicon = ''; 303 $close = _PC_OL_CLOSE; 304 305 $output = <<<EOF 306 307 <script type="text/javascript" language="JavaScript"> 308 <!-- overLIB configuration --> 309 ol_fgcolor = "$bgcolor1"; 310 ol_bgcolor = "$bgcolor2"; 311 ol_textcolor = "$textcolor2"; 312 ol_capcolor = "$textcolor2"; 313 ol_closecolor = "$textcolor2"; 314 ol_textfont = "Verdana,Arial,Helvetica"; 315 ol_captionfont = "Verdana,Arial,Helvetica"; 316 ol_captionsize = 2; 317 ol_textsize = 2; 318 ol_border = 2; 319 ol_width = 350; 320 ol_offsetx = 10; 321 ol_offsety = 10; 322 ol_sticky = 0; 323 ol_close = "$close"; 324 ol_closeclick = 0; 325 ol_autostatus = 2; 326 ol_snapx = 0; 327 ol_snapy = 0; 328 ol_fixx = -1; 329 ol_fixy = -1; 330 ol_background = ""; 331 ol_fgbackground = ""; 332 ol_bgbackground = ""; 333 ol_padxl = 1; 334 ol_padxr = 1; 335 ol_padyt = 1; 336 ol_padyb = 1; 337 ol_capicon = "$capicon"; 338 ol_hauto = 1; 339 ol_vauto = 1; 340 </script> 341 <div id="overDiv" style="position:absolute; top:0px; left:0px; visibility:hidden; z-index:1000;"></div> 342 <script type="text/javascript" language="JavaScript" src="modules/$pcDir/pnincludes/overlib_mini.js"> 343 <!-- overLIB (c) Erik Bosrup --> 344 </script> 345 346 EOF; 347 return $output; 348 } 349 350 /** 351 * postcalendar_adminapi_getmonthname() 352 * 353 * Returns the month name translated for the user's current language 354 * 355 * @param array $args['Date'] number of month to return 356 * @return string month name in user's language 357 */ 358 function postcalendar_adminapi_getmonthname($args) { return postcalendar_userapi_getmonthname($args); } 359 /** 360 * postcalendar_userapi_getmonthname() 361 * 362 * Returns the month name translated for the user's current language 363 * 364 * @param array $args['Date'] date to return month name of 365 * @return string month name in user's language 366 */ 367 function postcalendar_userapi_getmonthname($args) 368 { 369 extract($args); unset($args); 370 if(!isset($Date)) { return false; } 371 $month_name = array('01' => _CALJAN, '02' => _CALFEB, '03' => _CALMAR, 372 '04' => _CALAPR, '05' => _CALMAY, '06' => _CALJUN, 373 '07' => _CALJUL, '08' => _CALAUG, '09' => _CALSEP, 374 '10' => _CALOCT, '11' => _CALNOV, '12' => _CALDEC); 375 return $month_name[date('m',$Date)]; 376 } 377 /** 378 * Returns an array of form data for FormSelectMultiple 379 */ 380 function postcalendar_adminapi_buildTimeSelect($args) { return postcalendar_userapi_buildTimeSelect($args); } 381 function postcalendar_userapi_buildTimeSelect($args) 382 { 383 $inc = _SETTING_TIME_INCREMENT; 384 extract($args); unset($args); 385 $output = array('h'=>array(),'m'=>array()); 386 if((bool)_SETTING_TIME_24HOUR) { 387 $start=0; $end=23; 388 } else { 389 $start=1; $end=12; 390 $hselected = $hselected > 12 ? $hselected-=12 : $hselected; 391 } 392 393 for($c=0,$h=$start; $h<=$end; $h++,$c++) { 394 $hour = sprintf('%02d',$h); 395 $output['h'][$c]['id'] = pnVarPrepForStore($h); 396 $output['h'][$c]['selected'] = $hselected == $hour; 397 $output['h'][$c]['name'] = pnVarPrepForDisplay($hour); 398 } 399 400 for($c=0,$m=0; $m<=(60-$inc);$m+=$inc,$c++) { 401 $min = sprintf('%02d',$m); 402 $output['m'][$c]['id'] = pnVarPrepForStore($m); 403 $output['m'][$c]['selected'] = $mselected == $min; 404 $output['m'][$c]['name'] = pnVarPrepForDisplay($min); 405 } 406 return $output; 407 } 408 /** 409 * Returns an array of form data for FormSelectMultiple 410 */ 411 function postcalendar_adminapi_buildMonthSelect($args) { return postcalendar_userapi_buildMonthSelect($args); } 412 function postcalendar_userapi_buildMonthSelect($args) 413 { 414 extract($args); unset($args); 415 if(!isset($pc_month)) { $pc_month = Date_Calc::getMonth(); } 416 // create the return object to be inserted into the form 417 $output = array(); 418 if(!isset($selected)) $selected = ''; 419 for ($c=0,$i=1;$i<=12;$i++,$c++) { 420 if ($selected) { $sel = $selected == $i ? true : false; } 421 elseif ($i == $pc_month) { $sel = true; } 422 else { $sel = false; } 423 $output[$c]['id'] = sprintf('%02d',$i); 424 $output[$c]['selected'] = $sel; 425 $output[$c]['name'] = postcalendar_userapi_getmonthname(array('Date'=>mktime(0,0,0,$i,15))); 426 } 427 return $output; 428 } 429 430 /** 431 * Returns an array of form data for FormSelectMultiple 432 */ 433 function postcalendar_adminapi_buildDaySelect($args) { return postcalendar_userapi_buildDaySelect($args); } 434 function postcalendar_userapi_buildDaySelect($args) 435 { 436 extract($args); unset($args); 437 if(!isset($pc_day)) { $pc_day = Date_Calc::getDay(); } 438 // create the return object to be inserted into the form 439 $output = array(); 440 if(!isset($selected)) $selected = ''; 441 for($c=0,$i=1; $i<=31; $i++,$c++) { 442 if ($selected) { $sel = $selected == $i ? true : false; } 443 elseif ($i == $pc_day) { $sel = true; } 444 else { $sel = false; } 445 $output[$c]['id'] = sprintf('%02d',$i); 446 $output[$c]['selected'] = $sel; 447 $output[$c]['name'] = sprintf('%02d',$i); 448 } 449 return $output; 450 } 451 452 /** 453 * Returns an array of form data for FormSelectMultiple