[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Calendar Plugin 1.0 | 6 // +---------------------------------------------------------------------------+ 7 // | functions.inc | 8 // | | 9 // | This file does two things: 1) it implements the necessary Geeklog Plugin | 10 // | API method and 2) implements all the common code needed by the CAlendar | 11 // | plugin' PHP files. | 12 // +---------------------------------------------------------------------------+ 13 // | Copyright (C) 2000-2006 by the following authors: | 14 // | | 15 // | Authors: Tony Bibbs - tony AT tonybibbs DOT com | 16 // | Tom Willett - twillett AT users DOT sourceforge DOT net | 17 // | Blaine Lang - langmail AT sympatico DOT ca | 18 // | Dirk Haun - dirk AT haun-online DOT de | 19 // +---------------------------------------------------------------------------+ 20 // | | 21 // | This program is free software; you can redistribute it and/or | 22 // | modify it under the terms of the GNU General Public License | 23 // | as published by the Free Software Foundation; either version 2 | 24 // | of the License, or (at your option) any later version. | 25 // | | 26 // | This program is distributed in the hope that it will be useful, | 27 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 28 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 29 // | GNU General Public License for more details. | 30 // | | 31 // | You should have received a copy of the GNU General Public License | 32 // | along with this program; if not, write to the Free Software Foundation, | 33 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 34 // | | 35 // +---------------------------------------------------------------------------+ 36 // 37 // $Id: functions.inc,v 1.61 2006/12/18 06:45:37 ospiess Exp $ 38 39 if (strpos ($_SERVER['PHP_SELF'], 'functions.inc') !== false) { 40 die ('This file can not be used on its own.'); 41 } 42 43 $langfile = $_CONF['path'] . 'plugins/calendar/language/' 44 . $_CONF['language'] . '.php'; 45 46 if (file_exists ($langfile)) { 47 require_once ($langfile); 48 } else { 49 require_once ($_CONF['path'] . 'plugins/calendar/language/english.php'); 50 } 51 52 require_once ($_CONF['path'] . 'plugins/calendar/config.php'); 53 54 55 /** 56 * Returns the items for this plugin that should appear on the main menu 57 * 58 * NOTE: this MUST return the url/value pairs in the following format 59 * $<arrayname>[<label>] = <url> 60 * 61 */ 62 function plugin_getmenuitems_calendar () 63 { 64 global $_CONF, $_USER, $_CA_CONF, $LANG_CAL_1; 65 66 $anon = (empty ($_USER['uid']) || ($_USER['uid'] <= 1)) ? true : false; 67 if (($_CA_CONF['hidecalendarmenu'] == 1) || ($anon && 68 ($_CONF['loginrequired'] || $_CA_CONF['calendarloginrequired']))) { 69 return false; 70 } 71 72 $menuitems[$LANG_CAL_1[16]] = $_CONF['site_url'] . '/calendar/index.php'; 73 74 return $menuitems; 75 } 76 77 /** 78 * Returns the upcoming events block 79 * 80 * Returns the HTML for any upcoming events in the calendar 81 * 82 * @param string $help Help file for block 83 * @param string $title Title to be used in block header 84 * @return string HTML formatted block containing events. 85 */ 86 function phpblock_calendar( $help='', $title='' ) 87 { 88 global $_CONF, $_TABLES, $_USER, $_CA_CONF, $LANG_CAL_1; 89 90 $retval = ''; 91 92 if( !$_USER['noboxes'] && $_CA_CONF['showupcomingevents'] ) { 93 $range = $_CA_CONF['upcomingeventsrange']; 94 if( $range == 0 ) { 95 $range = 14; // fallback: 14 days 96 } 97 $dateonly = $_CONF['dateonly']; 98 if( empty( $dateonly )) { 99 $dateonly = '%d-%b'; // fallback: day - abbrev. month name 100 } 101 102 if( empty( $title )) { 103 $title = DB_getItem( $_TABLES['blocks'], 'title', 104 "name = 'events_block'" ); 105 } 106 107 $eventSql = 'SELECT eid,title,url,datestart,dateend,group_id,owner_id,perm_owner,perm_group,perm_members,perm_anon ' 108 . "FROM {$_TABLES['events']} " 109 . "WHERE dateend >= NOW() AND (TO_DAYS(datestart) - TO_DAYS(NOW()) < $range) " 110 . 'ORDER BY datestart,timestart'; 111 112 if(( $_CA_CONF['personalcalendars'] == 1 ) && !empty( $_USER['uid'] )) { 113 $personaleventsql = 'SELECT eid,title,url,datestart,dateend,group_id,owner_id,perm_owner,perm_group,perm_members,perm_anon ' 114 . "FROM {$_TABLES['personal_events']} " 115 . "WHERE uid = {$_USER['uid']} AND dateend >= NOW() AND (TO_DAYS(datestart) - TO_DAYS(NOW()) < $range) " 116 . 'ORDER BY datestart, dateend'; 117 } 118 119 $allEvents = DB_query( $eventSql ); 120 $numRows = DB_numRows( $allEvents ); 121 $totalrows = $numRows; 122 123 $numDays = 0; // Without limits, I'll force them. 124 $theRow = 1; // Start with today! 125 $oldDate1 = 'no_day'; // Invalid Date! 126 $oldDate2 = 'last_d'; // Invalid Date! 127 128 if( $_CA_CONF['personalcalendars'] == 1 AND !empty( $_USER['uid'] )) { 129 $iterations = 2; 130 } else { 131 $iterations = 1; 132 } 133 134 $eventsFound = 0; 135 $skipFirstBreak = false; 136 137 for( $z = 1; $z <= $iterations; $z++ ) { 138 if( $z == 2 ) { 139 $allEvents = DB_query( $personaleventsql ); 140 $numRows = DB_numRows( $allEvents ); 141 $totalrows = $totalrows + $numRows; 142 143 $numDays = 0; // Without limits, I'll force them. 144 $theRow = 1; // Start with today! 145 $oldDate1 = 'no_day'; // Invalid Date! 146 $oldDate2 = 'last_d'; // Invalid Date! 147 $classname = 'list-new-plugins'; 148 $headline = false; 149 } else { 150 $classname = 'list-new-plugins'; 151 $headline = false; 152 } 153 if( $_CA_CONF['personalcalendars'] == 0 ) { 154 $headline = true; // no headline needed 155 $skipFirstBreak = true; 156 } 157 158 while( $theRow <= $numRows AND $numDays < $range ) { 159 // Retreive the next event, and format the start date. 160 $theEvent = DB_fetchArray( $allEvents ); 161 162 if( SEC_hasAccess( $theEvent['owner_id'], $theEvent['group_id'], 163 $theEvent['perm_owner'], $theEvent['perm_group'], 164 $theEvent['perm_members'], $theEvent['perm_anon'] ) > 0 ) { 165 $eventsFound++; 166 167 if( !$headline ) { 168 if($z == 2) { 169 if( $numRows > 0 ) { 170 $retval .= '<p><b>' . $LANG_CAL_1[23] . '</b><br>'; 171 } 172 } else { 173 if( $totalrows > 0 ) { 174 $retval .= '<b>' . $LANG_CAL_1[24] . '</b><br>'; 175 } 176 } 177 $headline = true; 178 } 179 180 // Start Date strings... 181 $startDate = $theEvent['datestart']; 182 $theTime1 = strtotime( $startDate ); 183 $dayName1 = strftime( '%A', $theTime1 ); 184 $abbrDate1 = strftime( $dateonly, $theTime1 ); 185 186 // End Date strings... 187 $endDate = $theEvent['dateend']; 188 $theTime2 = strtotime( $endDate ); 189 $dayName2 = strftime( '%A', $theTime2 ); 190 $abbrDate2 = strftime( $dateonly, $theTime2 ); 191 192 $todaysEvent = false; 193 if( date( 'Ymd', $theTime1 ) == date( 'Ymd', time())) { 194 $todaysEvent = true; 195 if( $z == 2 ) { 196 $todaysClassName = 'personal-event-today'; 197 } else { 198 $todaysClassName = 'site-event-today'; 199 } 200 } 201 202 // If either of the dates [start/end] change, then display a new header. 203 if( $oldDate1 != $abbrDate1 OR $oldDate2 != $abbrDate2 ) { 204 $oldDate1 = $abbrDate1; 205 $oldDate2 = $abbrDate2; 206 $numDays ++; 207 208 if( $numDays < $range ) { 209 if( !empty( $newevents )) { 210 $retval .= COM_makeList( $newevents, $classname ); 211 } 212 if( $skipFirstBreak ) { 213 $skipFirstBreak = false; 214 } else { 215 $retval .= '<br>'; 216 } 217 if( $todaysEvent ) { 218 $retval .= '<span class="' . $todaysClassName . '">'; 219 } 220 $retval .= '<b>' . $dayName1 . '</b> <small>' 221 . $abbrDate1 . '</small>'; 222 223 // If different start and end dates, then display end date: 224 if( $abbrDate1 != $abbrDate2 ) { 225 $retval .= ' - <br><b>' . $dayName2 . '</b> <small>' . $abbrDate2 . '</small>'; 226 } 227 if( $todaysEvent ) { 228 $retval .= '</span>'; 229 } 230 } 231 $newevents = array(); 232 } 233 234 // Now display this event record. 235 if( $numDays < $range ) { 236 // Display the url now! 237 $newevent = '<a href="' . $_CONF['site_url'] 238 . '/calendar/event.php?'; 239 240 if( $z == 2 ) { 241 $newevent .= 'mode=personal&'; 242 } 243 244 $newevent .= 'eid=' . $theEvent['eid'] . '"'; 245 if( $todaysEvent ) { 246 $newevent .= ' class="' . $todaysClassName . '"'; 247 } 248 $newevent .= '>' . stripslashes( $theEvent['title'] ) 249 . '</a>'; 250 $newevents[] = $newevent; 251 } 252 253 if( !empty( $newevents )) { 254 $retval .= COM_makeList( $newevents, $classname ); 255 $newevents = array(); 256 } 257 } 258 $theRow++; 259 } 260 } // end for z 261 262 if( $eventsFound == 0 ) { 263 // There aren't any upcoming events, show a nice message 264 $retval .= $LANG_CAL_1[25]; 265 } 266 } 267 268 return $retval; 269 } 270 271 /** 272 * 273 * Checks that the current user has the rights to moderate the 274 * plugin, returns true if this is the case, false otherwise 275 * 276 * @return boolean Returns true if moderator 277 * 278 */ 279 function plugin_ismoderator_calendar() { 280 return SEC_hasRights ('calendar.moderate'); 281 } 282 283 /** 284 * Returns SQL & Language texts to moderation.php 285 */ 286 function plugin_itemlist_calendar() 287 { 288 global $_TABLES, $LANG_CAL_1; 289 290 if (plugin_ismoderator_calendar()) { 291 $plugin = new Plugin(); 292 $plugin->submissionlabel = $LANG_CAL_1[19]; 293 $plugin->submissionhelpfile = 'cceventsubmission.html'; 294 $plugin->getsubmissionssql = "SELECT eid AS id,title,datestart as day,url " 295 . "FROM {$_TABLES['eventsubmission']} " 296 . "ORDER BY datestart ASC"; 297 $plugin->addSubmissionHeading($LANG_CAL_1[20]); 298 $plugin->addSubmissionHeading($LANG_CAL_1[21]); 299 $plugin->addSubmissionHeading($LANG_CAL_1[22]); 300 301 return $plugin; 302 } 303 } 304 305 /** 306 * returns list of moderation values 307 * 308 * The array returned contains (in order): the row 'id' label, main plugin 309 * table, moderation fields (comma seperated), and plugin submission table 310 * 311 * @return array Returns array of useful moderation values 312 * 313 */ 314 function plugin_moderationvalues_calendar() 315 { 316 global $_TABLES; 317 318 return array ( 319 'eid', 320 $_TABLES['events'], 321 "eid,title,description,location,address1,address2,city,state,zipcode,datestart,timestart,dateend,timeend,url", 322 $_TABLES['eventsubmission'] 323 ); 324 } 325 326 327 /** 328 * Performs plugin exclusive work for items approved by moderation 329 * 330 * While moderation.php handles the actual move from linkssubmission 331 * to links tables, within the function we handle all other approval 332 * relate tasks 333 * 334 * @param string $id Identifying string 335 * @return string Any wanted HTML output 336 * 337 */ 338 function plugin_moderationapprove_calendar ($id) 339 { 340 global $_CA_CONF, $_GROUPS, $_TABLES, $_USER; 341 342 $A = array (); 343 SEC_setDefaultPermissions ($A, $_CA_CONF['default_permissions']); 344 345 // Since the eventsubmission table does not contain fields for the owner 346 // and group, we set those to the current user. Also set the default 347 // permissions as specified in the plugin's config.php 348 if (isset ($_GROUPS['Calendar Admin'])) { 349 $group_id = $_GROUPS['Calendar Admin']; 350 } else { 351 $group_id = SEC_getFeatureGroup ('calendar.moderate'); 352 } 353 DB_query ("UPDATE {$_TABLES['events']} SET owner_id = '{$_USER['uid']}'," 354 ."group_id = '$group_id',perm_owner = {$A['perm_owner']}, " 355 ."perm_group = {$A['perm_group']}, perm_members = {$A['perm_members']}," 356 ."perm_anon = {$A['perm_anon']} WHERE eid = $id"); 357 } 358 359 /** 360 * Performs plugin exclusive work for items deleted by moderation 361 * 362 * While moderation.php handles the actual removal from <plugin>submission 363 * table, within this function we handle all other deletion 364 * relate tasks 365 * 366 * @param string $id Identifying string 367 * @return string Any wanted HTML output 368 * 369 */ 370 function plugin_moderationdelete_calendar($id) 371 { 372 global $_TABLES; 373 374 // these tables should not contain any rows with ml_id = $id 375 // this is done 'just in case' 376 DB_delete ($_TABLES['eventsubmission'], 'eid', $id); 377 378 return ''; 379 } 380 381 /** 382 * Check calendar submission form for missing fields 383 * and Saves a calendar submission 384 * 385 * @param array $A Data for that submission 386 * @return string HTML redirect 387 * 388 */ 389 function plugin_savesubmission_calendar($A) 390 { 391 global $_CONF, $_CA_CONF, $_TABLES, $_USER, $LANG12, $LANG_CAL_1; 392 393 $A['title'] = strip_tags (COM_checkWords ($A['title'])); 394 $A['start_year'] = COM_applyFilter ($A['start_year'], true); 395 $A['start_month'] = COM_applyFilter ($A['start_month'], true); 396 $A['start_day'] = COM_applyFilter ($A['start_day'], true); 397 398 // check for missing textfields 399 if (empty ($A['title']) || empty ($A['start_month']) || empty ($A['start_day']) || empty ($A['start_year'])) { 400 $retval .= COM_siteHeader ('menu', $LANG_CAL_1[27]) 401 . COM_startBlock ($LANG12[22], '', 402 COM_getBlockTemplate ('_msg_block', 'header')) 403 . $LANG12[23] 404 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')) 405 . plugin_submit_calendar ($A['calendar_type']) 406 . COM_siteFooter (); 407 408 return $retval; 409 } 410 // check ok, proceed to saving 411 $A['end_year'] = COM_applyFilter ($A['end_year'], true); 412 $A['end_month'] = COM_applyFilter ($A['end_month'], true); 413 $A['end_day'] = COM_applyFilter ($A['end_day'], true); 414 415 $A['datestart'] = sprintf ('%4d-%02d-%02d', 416 $A['start_year'], $A['start_month'], $A['start_day']); 417 if (empty ($A['end_year']) || empty ($A['end_month']) || 418 empty ($A['end_day'])) { 419 $A['dateend'] = $A['datestart']; 420 } else { 421 $A['dateend'] = sprintf ('%4d-%02d-%02d', 422 $A['end_year'], $A['end_month'], $A['end_day']); 423 } 424 425 // for the quickadd form, which doesn't have end date/time fields 426 if (!isset ($A['end_hour'])) { 427 $A['end_hour'] = $A['start_hour']; 428 } 429 if (!isset ($A['end_minute'])) { 430 $A['end_minute'] = $A['start_minute']; 431 } 432 433 // pseudo-formatted event description for the spam check 434 $spamcheck = '<p><a href="' . $A['url'] . '">' . $A['title'] . '</a><br>' 435 . $A['location'] . '<br>' . $A['address1'] . '<br>' 436 . $A['address2'] . '<br>' . $A['city'] . ', ' . $A['zipcode'] 437 . '<br>' . $A['description'] . '</p>'; 438 $result = PLG_checkforSpam ($spamcheck, $_CONF['spamx']); 439 if ($result > 0) { 440 COM_updateSpeedlimit ('submit'); 441 COM_displayMessageAndAbort ($result, 'spamx', 403, 'Forbidden'); 442 } 443 444 $A['description'] = addslashes (htmlspecialchars (COM_checkWords ($A['description']))); 445 $A['address1'] = addslashes (strip_tags (COM_checkWords ($A['address1']))); 446 $A['address2'] = addslashes (strip_tags (COM_checkWords ($A['address2']))); 447 $A['city'] = addslashes (strip_tags (COM_checkWords ($A['city']))); 448 $A['zipcode'] = addslashes (strip_tags (COM_checkWords ($A['zipcode']))); 449 $A['state'] = addslashes (strip_tags (COM_checkWords ($A['state']))); 450 $A['location'] = addslashes (strip_tags (COM_checkWords ($A['location']))); 451 $A['event_type'] = addslashes (strip_tags (COM_checkWords ($A['event_type']))); 452 $A['title'] = addslashes ($A['title']); 453 454 $A['url'] = addslashes (COM_sanitizeUrl ($A['url'])); 455 if ($A['url'] == 'http://') { 456 $A['url'] = ''; 457 } 458 459 if (!empty ($A['eid'])) { 460 $A['eid'] = addslashes (COM_applyFilter ($A['eid'])); 461 } 462 if (empty ($A['eid'])) { 463 $A['eid'] = addslashes (COM_makeSid ()); 464 } 465 466 COM_updateSpeedlimit ('submit'); 467 468 if (isset ($A['allday']) && ($A['allday'] == 'on')) { 469 $A['allday'] = 1; 470 } else { 471 $A['allday'] = 0; 472 } 473 474 if (isset ($A['hour_mode']) && ($A['hour_mode'] == 24)) { 475 $start_hour = COM_applyFilter ($A['start_hour'], true); 476 if ($start_hour >= 12) { 477 $A['start_ampm'] = 'pm'; 478 $A['start_hour'] = $start_hour - 12; 479 } else { 480 $A['start_ampm'] = 'am'; 481 $A['start_hour'] = $start_hour; 482 } 483 if ($A['start_hour'] == 0) { 484 $A['start_hour'] = 12; 485 } 486 $end_hour = COM_applyFilter ($A['end_hour'], true); 487 if ($end_hour >= 12) { 488 $A['end_ampm'] = 'pm'; 489 $A['end_hour'] = $end_hour - 12; 490 } else { 491 $A['end_ampm'] = 'am'; 492 $A['end_hour'] = $end_hour; 493 } 494 if ($A['end_hour'] == 0) { 495 $A['end_hour'] = 12; 496 } 497 } 498 if (!isset ($A['end_ampm'])) { 499 $A['end_ampm'] = $A['start_ampm']; 500 } 501 502 $A['start_hour'] = COM_applyFilter ($A['start_hour'], true); 503 $A['start_minute'] = COM_applyFilter ($A['start_minute'], true); 504 $A['end_hour'] = COM_applyFilter ($A['end_hour'], true); 505 $A['end_minute'] = COM_applyFilter ($A['end_minute'], true); 506 507 if ($A['start_ampm'] == 'pm' AND $A['start_hour'] <> 12) { 508 $A['start_hour'] = $A['start_hour'] + 12; 509 } 510 if ($A['start_ampm'] == 'am' AND $A['start_hour'] == 12) { 511 $A['start_hour'] = '00'; 512 } 513 if ($A['end_ampm'] == 'pm' AND $A['end_hour'] <> 12) { 514 $A['end_hour'] = $A['end_hour'] + 12; 515 } 516 if ($A['end_ampm'] == 'am' AND $A['end_hour'] == 12) { 517 $A['end_hour'] = '00'; 518 } 519 $A['timestart'] = $A['start_hour'] . ':' . $A['start_minute'] . ':00'; 520 $A['timeend'] = $A['end_hour'] . ':' . $A['end_minute'] . ':00'; 521 if ($A['calendar_type'] == 'master') { // add to site calendar 522 523 if (($_CA_CONF['eventsubmission'] == 1) && 524 !SEC_hasRights ('calendar.submit')) { 525 DB_save ($_TABLES['eventsubmission'], 526 'eid,title,event_type,url,datestart,timestart,dateend,timeend,allday,location,address1,address2,city,state,zipcode,description', 527 "{$A['eid']},'{$A['title']}','{$A['event_type']}','{$A['url']}','{$A['datestart']}','{$A['timestart']}','{$A['dateend']}','{$A['timeend']}',{$A['allday']},'{$A['location']}','{$A['address1']}','{$A['address2']}','{$A['city']}','{$A['state']}','{$A['zipcode']}','{$A['description']}'"); 528 529 if (isset ($_CA_CONF['notification']) && 530 ($_CA_CONF['notification'] == 1)) { 531 CALENDAR_sendNotification ($_TABLES['eventsubmission'], $A); 532 } 533 534 $retval = COM_refresh ($_CONF['site_url'] . '/calendar/index.php?msg=4'); 535 } else { 536 if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) { 537 $owner_id = $_USER['uid']; 538 } else { 539 $owner_id = 1; // anonymous user 540 } 541 542 DB_save ($_TABLES['events'], 543 'eid,title,event_type,url,datestart,timestart,dateend,timeend,allday,location,address1,address2,city,state,zipcode,description,owner_id', 544 "{$A['eid']},'{$A['title']}','{$A['event_type']}','{$A['url']}','{$A['datestart']}','{$A['timestart']}','{$A['dateend']}','{$A['timeend']}',{$A['allday']},'{$A['location']}','{$A['address1']}','{$A['address2']}','{$A['city']}','{$A['state']}','{$A['zipcode']}','{$A['description']}',$owner_id"); 545 if (isset ($_CA_CONF['notification']) && 546 ($_CA_CONF['notification'] == 1)) { 547 CALENDAR_sendNotification ($_TABLES['events'], $A); 548 } 549 COM_rdfUpToDateCheck (); 550 551 $retval = COM_refresh ($_CONF['site_url'] . '/calendar/index.php'); 552 } 553 554 } else if ($_CA_CONF['personalcalendars'] == 1) { // add to personal calendar 555 if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) { 556 DB_save ($_TABLES['personal_events'], 557 'uid,eid,title,event_type,url,datestart,timestart,dateend,timeend,allday,location,address1,address2,city,state,zipcode,description', 558 "{$_USER['uid']},'{$A['eid']}','{$A['title']}','{$A['event_type']}','{$A['url']}','{$A['datestart']}','{$A['timestart']}','{$A['dateend']}','{$A['timeend']}',{$A['allday']},'{$A['location']}','{$A['address1']}','{$A['address2']}','{$A['city']}','{$A['state']}','{$A['zipcode']}','{$A['description']}'"); 559 $retval = COM_refresh ($_CONF['site_url'] 560 . '/calendar/index.php?mode=personal&msg=17'); 561 } else { 562 // anonymous users don't have personal calendars - bail 563 COM_accessLog ("Attempt to write to the personal calendar of user '{$A['uid']}'."); 564 565 $retval = COM_refresh ($_CONF['site_url'] . '/calendar/index.php'); 566 } 567 568 } else { // personal calendars are disabled 569 $retval = COM_refresh ($_CONF['site_url'] . '/calendar/index.php'); 570 } 571 572 return $retval; 573 } 574 575 function plugin_getheadercode_calendar() 576 { 577 global $_CONF; 578 579 $str = null; 580 581 // use the CSS only if we are on the plugin's pages 582 if (substr_count ($_SERVER['PHP_SELF'], '/calendar/') > 0) { 583 $str = '<link rel="stylesheet" type="text/css" href="' 584 . $_CONF['site_url'] . '/calendar/style.css">'; 585 } 586 587 return $str; 588 } 589 590 /** 591 * Shows event submission form or diverts to event editor if admin calls in 592 * 593 */ 594 function plugin_submit_calendar($mode = 'master') 595 { 596 global $_CONF, $_USER, $_CA_CONF, $LANG_CAL_1; 597 598 if (isset ($_POST['calendar_type'])) { 599 $mode = $_POST['calendar_type']; 600 } 601 602 if (($_CA_CONF['personalcalendars'] == 1) && ($mode == 'quickadd')) { 603 // quick add form, just save it. 604 $display = plugin_savesubmission_calendar ($_POST); 605 return $display; 606 } else if (SEC_hasRights('calendar.edit') && ($mode != 'personal')) { 607 // admin posts non-personal, go to editor 608 if (isset ($_REQUEST['year'])) { 609 $year = COM_applyFilter ($_REQUEST['year'], true); 610 } else { 611 $year = date ('Y', time ()); 612 } 613 if (isset ($_REQUEST['month'])) { 614 $month = COM_applyFilter ($_REQUEST['month'], true); 615 } else { 616 $month = date ('m', time ()); 617 } 618 if (isset ($_REQUEST['day'])) { 619 $day = COM_applyFilter ($_REQUEST['day'], true); 620 } else { 621 $day = date ('d', time ()); 622 } 623 if (isset ($_REQUEST['hour'])) { 624 $hour = COM_applyFilter ($_REQUEST['hour'], true); 625 } else { 626 $hour = date ('H', time ()); 627 } 628 $startat = ''; 629 if ($year > 0) { 630 $startat = '&datestart=' 631 . urlencode (sprintf ('%04d-%02d-%02d', $year, 632 $month, $day)) 633 . '×tart=' . urlencode (sprintf ('%02d:00:00', 634 $hour)); 635 } 636 637 echo COM_refresh ($_CONF['site_admin_url'] 638 . '/plugins/calendar/index.php?mode=edit' . $startat); 639 exit; 640 } 641 // otherwise non-admin or admin-personal. do personal form or public submission. 642 643 $retval = ''; 644 645 $retval .= COM_startBlock ($LANG_CAL_1[26], 'submitevent.html'); 646 $eventform = new Template ($_CONF['path'] . 'plugins/calendar/templates/'); 647 $eventform->set_file ('eventform', 'submitevent.thtml'); 648 if ($mode != 'personal') { 649 $eventform->set_var ('explanation', $LANG_CAL_1[27]); 650 $eventform->set_var ('submit_url', '/submit.php'); 651 } else { 652 $eventform->set_var ('explanation', ''); 653 $eventform->set_var ('submit_url', '/calendar/index.php?view=savepersonal'); 654 } 655 if (isset ($_CA_CONF['hour_mode']) && ($_CA_CONF['hour_mode'] == 24)) { 656 $eventform->set_var ('hour_mode', 24); 657 } else { 658 $eventform->set_var ('hour_mode', 12); 659 } 660 $eventform->set_var ('site_url', $_CONF['site_url']); 661 $eventform->set_var ('site_admin_url', $_CONF['site_admin_url']); 662 $eventform->set_var ('layout_url', $_CONF['layout_url']); 663 $eventform->set_var ('lang_title', $LANG_CAL_1[28]); 664 665 $eventform->set_var('lang_eventtype', $LANG_CAL_1[37]); 666 $eventform->set_var('lang_editeventtypes', $LANG_CAL_1[38]); 667 $eventform->set_var('type_options', CALENDAR_eventTypeList ()); 668 669 $eventform->set_var('lang_link', $LANG_CAL_1[43]); 670 $eventform->set_var('max_url_length', 255); 671 $eventform->set_var('lang_startdate', $LANG_CAL_1[21]); 672 $eventform->set_var('lang_starttime', $LANG_CAL_1[30]); 673 if (empty ($month)) { 674 $month = date ('m', time ()); 675 } 676 if (empty ($day)) { 677 $day = date ('d', time ()); 678 } 679 if (empty ($year)) { 680 $year = date ('Y', time ()); 681 } 682 $eventform->set_var ('month_options', COM_getMonthFormOptions ($month)); 683 $eventform->set_var ('day_options', COM_getDayFormOptions ($day)); 684 $eventform->set_var ('year_options', COM_getYearFormOptions ($year)); 685 686 if (empty ($hour) || ($hour < 0)) { 687 $cur_hour = date ('H', time ()); 688 } else { 689 $cur_hour = $hour; 690 } 691 $cur_hour_24 = $cur_hour % 24; 692 if ($cur_hour >= 12) { 693 $ampm = 'pm'; 694 } else { 695 $ampm = 'am'; 696 } 697 698 $eventform->set_var ('startampm_selection', 699 COM_getAmPmFormSelection ('start_ampm', $ampm)); 700 $eventform->set_var ('endampm_selection', 701 COM_getAmPmFormSelection ('end_ampm', $ampm)); 702 703 if ($cur_hour > 12) { 704 $cur_hour = $cur_hour - 12; 705 } else if ($cur_hour == 0) { 706 $cur_hour = 12; 707 } 708 709 if (isset ($_CA_CONF['hour_mode']) && ($_CA_CONF['hour_mode'] == 24)) { 710 $eventform->set_var ('hour_options', 711 COM_getHourFormOptions ($cur_hour_24, 24)); 712 } else { 713 $eventform->set_var ('hour_options', 714 COM_getHourFormOptions ($cur_hour)); 715 } 716 $cur_min = intval (date ('i') / 15) * 15; 717 $eventform->set_var ('minute_options', 718 COM_getMinuteFormOptions ($cur_min, 15)); 719 720 $eventform->set_var('lang_enddate', $LANG_CAL_1[18]); 721 $eventform->set_var('lang_endtime', $LANG_CAL_1[29]); 722 $eventform->set_var('lang_alldayevent',$LANG_CAL_1[31]); 723 $eventform->set_var('lang_addressline1',$LANG_CAL_1[32]); 724 $eventform->set_var('lang_addressline2',$LANG_CAL_1[33]); 725 $eventform->set_var('lang_city',$LANG_CAL_1[34]); 726 $eventform->set_var('lang_state',$LANG_CAL_1[35]); 727 $eventform->set_var('state_options', CALENDAR_stateList ()); 728 $eventform->set_var('lang_zipcode',$LANG_CAL_1[36]); 729 $eventform->set_var('lang_location', $LANG_CAL_1[39]); 730 $eventform->set_var('lang_description', $LANG_CAL_1[5]); 731 $eventform->set_var('lang_htmnotallowed', $LANG_CAL_1[44]); 732 $eventform->set_var('lang_submit', $LANG_CAL_1[45]); 733 $eventform->set_var('mode', $mode); 734 $eventform->parse('theform', 'eventform'); 735 $retval .= $eventform->finish($eventform->get_var('theform')); 736 $retval .= COM_endBlock(); 737 738 return $retval; 739 } 740 741 /** 742 * Delete an event 743 * 744 * @param string $eid id of event to delete 745 * @param string HTML redirect 746 */ 747 function CALENDAR_deleteEvent ($eid) 748 { 749 global $_CONF, $_TABLES, $_USER; 750 751 $result = DB_query ("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon " 752 ."FROM {$_TABLES['events']} WHERE eid = '$eid'"); 753 $A = DB_fetchArray ($result); 754 $access = SEC_hasAccess ($A['owner_id'], $A['group_id'], $A['perm_owner'], 755 $A['perm_group'], $A['perm_members'], $A['perm_anon']); 756 if ($access < 3) { 757 COM_accessLog ("User {$_USER['username']} tried to illegally delete event $eid."); 758 return COM_refresh ($_CONF['site_admin_url'] . '/plugins/calendar/index.php'); 759 } 760 761 DB_delete ($_TABLES['events'], 'eid', $eid); 762 DB_delete ($_TABLES['personal_events'], 'eid', $eid); 763 COM_rdfUpToDateCheck ('geeklog', 'calendar', $eid); 764 765 return COM_refresh ($_CONF['site_admin_url'] . '/plugins/calendar/index.php?msg=18'); 766 } 767 768 function CALENDAR_listevents() 769 { 770 global $_CONF, $_TABLES, $LANG_ADMIN, $LANG_CAL_ADMIN, $LANG_ACCESS, 771 $_IMAGE_TYPE; 772 773 require_once( $_CONF['path_system'] . 'lib-admin.php' ); 774 775 $retval = ''; 776 777 $header_arr = array( # dislay 'text' and use table field 'field' 778 array('text' => $LANG_ADMIN['edit'], 'field' => 'edit', 'sort' => false), 779 array('text' => $LANG_ADMIN['copy'], 'field' => 'copy', 'sort' => false), 780 array('text' => $LANG_ADMIN['title'], 'field' => 'title', 'sort' => true), 781 array('text' => $LANG_CAL_ADMIN[13], 'field' => 'username', 'sort' => true), 782 array('text' => $LANG_ACCESS['access'], 'field' => 'access', 'sort' => false), 783 array('text' => $LANG_CAL_ADMIN[14], 'field' => 'datestart', 'sort' => true), 784 array('text' => $LANG_CAL_ADMIN[15], 'field' => 'dateend', 'sort' => true) 785 ); 786 787 $defsort_arr = array('field' => 'datestart', 'direction' => 'desc'); 788 789 $menu_arr = array ( 790 array('url' => $_CONF['site_admin_url'] . '/plugins/calendar/index.php?mode=edit', 791 'text' => $LANG_ADMIN['create_new']), 792 array('url' => $_CONF['site_admin_url'], 793 'text' => $LANG_ADMIN['admin_home']) 794 ); 795 796 $text_arr = array('has_menu' => true, 797 'has_extras' => true, 798 'title' => $LANG_CAL_ADMIN[11], 799 'instructions' => $LANG_CAL_ADMIN[12], 800 'icon' => $_CONF['site_url'] . '/calendar/images/calendar.' . $_IMAGE_TYPE, 801 'form_url' => $_CONF['site_admin_url'] . "/plugins/calendar/index.php"); 802 803 $sql = "SELECT {$_TABLES['events']}.*, {$_TABLES['users']}.username, {$_TABLES['users']}.fullname " 804 ."FROM {$_TABLES['events']} " 805 ."LEFT JOIN {$_TABLES['users']} " 806 ."ON {$_TABLES['events']}.owner_id={$_TABLES['users']}.uid " 807 ."WHERE 1=1 "; 808 809 $query_arr = array('table' => 'events', 810 'sql' => $sql, 811 'query_fields' => array('title', 'datestart', 'dateend'), 812 'default_filter' => COM_getPermSQL('AND')); 813 814 $retval .= ADMIN_list ('calendar', 'plugin_getListField_calendar', 815 $header_arr, $text_arr, $query_arr, $menu_arr, 816 $defsort_arr); 817 818 return $retval; 819 } 820 821 /** 822 * Send an email notification for a new submission. 823 * 824 * @param string $table Table where the new submission can be found 825 * @param array $A submission data 826 * 827 */ 828 function CALENDAR_sendNotification ($table, $A) 829 { 830 global $_CONF, $_TABLES, $LANG01, $LANG08, $LANG09, $LANG_CAL_1, $LANG_CAL_2; 831 832 $title = stripslashes ($A['title']); 833 $description = stripslashes ($A['description']); 834 835 $mailbody = "$LANG09[16]: $title\n" 836 . "$LANG09[17]: " . strftime ($_CONF['date'], 837 strtotime ($A['datestart'] . ' ' . $A['timestart'])); 838 if ($A['allday']) { 839 $mailbody .= ' (' . $LANG_CAL_2[26] . ')'; 840 } 841 $mailbody .= "\n"; 842 if (!empty ($A['url']) && ($A['url'] != 'http://')) { 843 $mailbody .= "$LANG09[33]: <" . $A['url'] . ">\n"; 844 } 845 $mailbody .= "\n" . $description . "\n\n"; 846 if ($table == $_TABLES['eventsubmission']) { 847 $mailbody .= "$LANG01[10] <{$_CONF['site_admin_url']}/moderation.php>\n\n"; 848 } else { 849 $mailbody .= "$LANG_CAL_1[12] <{$_CONF['site_url']}/calendar/event.php?eid={$A['eid']}>\n\n"; 850 } 851 $mailsubject = $_CONF['site_name'] . ' ' . $LANG_CAL_2[43]; 852 853 $mailbody .= "\n------------------------------\n"; 854 $mailbody .= "\n$LANG08[34]\n"; 855 $mailbody .= "\n------------------------------\n"; 856 857 COM_mail ($_CONF['site_mail'], $mailsubject, $mailbody); 858 } 859 860 861 /** 862 * 863 * Counts the items that are submitted 864 * 865 */ 866 function plugin_submissioncount_calendar() 867 { 868 global $_TABLES; 869 870 $num = 0; 871 872 if( SEC_hasRights( 'calendar.moderate' )) 873 { 874 $num += DB_count( $_TABLES['eventsubmission'] ); 875 } 876 877 return $num; 878 } 879 880 /** 881 * Implements the [event:] autotag. 882 * 883 */ 884 function plugin_autotags_calendar ($op, $content = '', $autotag = '') 885 { 886 global $_CONF, $_TABLES; 887 888 if ($op == 'tagname' ) { 889 return 'event'; 890 } else if ($op == 'parse') { 891 $eid = COM_applyFilter ($autotag['parm1']); 892 $url = $_CONF['site_url'] . '/calendar/event.php?eid=' . $eid; 893 if (empty ($autotag['parm2'])) { 894 $linktext = stripslashes (DB_getItem ($_TABLES['events'], 895 'title', "eid = '$eid'")); 896 } else { 897 $linktext = $autotag['parm2']; 898 } 899 $link = '<a href="' . $url . '">' . $linktext . '</a>'; 900 $content = str_replace ($autotag['tagstr'], $link, $content); 901 902 return $content; 903 } 904 } 905 906 /* 907 * Do we support feeds? 908 */ 909 function plugin_getfeednames_calendar() 910 { 911 global $LANG_CAL_1; 912 913 $feeds = array (); 914 915 $feeds[] = array ('id' => 'calendar', 'name' => $LANG_CAL_1[16]); 916 917 return $feeds; 918 919 } 920 921 /** 922 * Get content for a feed that holds all events. 923 * 924 * @param string $limit number of entries or number of stories 925 * @param string $link link to homepage 926 * @param string $update list of story ids 927 * @return array content of the feed 928 * 929 */ 930 function plugin_getfeedcontent_calendar( $limit, &$link, &$update, $feedType, $feedVersion ) 931 { 932 global $_CONF, $_TABLES; 933 934 $where = ''; 935 if( !empty( $limit )) { 936 if( substr( $limit, -1 ) == 'h' ) {// next xx hours 937 $limitsql = ''; 938 $hours = substr( $limit, 0, -1 ); 939 $where = " AND (datestart <= DATE_ADD(NOW(), INTERVAL $hours HOUR))"; 940 } 941 else { 942 $limitsql = ' LIMIT ' . $limit; 943 } 944 } 945 else { 946 $limitsql = ' LIMIT 10'; 947 } 948 949 $sql = "SELECT eid,owner_id,title,description FROM {$_TABLES['events']} " 950 ."WHERE perm_anon > 0 AND dateend >= NOW()$where " 951 ."ORDER BY datestart,timestart $limitsql"; 952 $result = DB_query($sql); 953 954 $content = array(); 955 $eids = array(); 956 $nrows = DB_numRows( $result ); 957 958 for( $i = 1; $i <= $nrows; $i++ ) 959 { 960 $row = DB_fetchArray( $result ); 961 $eids[] = $row['eid']; 962 963 $eventtitle = stripslashes( $row['title'] ); 964 $eventtext = SYND_truncateSummary( $row['description'], MBYTE_strlen($row['description'])); 965 $eventlink = $_CONF['site_url'] . '/calendar/event.php?eid=' 966 . $row['eid']; 967 968 // Need to reparse the date from the event id 969 $myyear = substr( $row['eid'], 0, 4 ); 970 $mymonth = substr( $row['eid'], 4, 2 ); 971 $myday = substr( $row['eid'], 6, 2 ); 972 $myhour = substr( $row['eid'], 8, 2 ); 973 $mymin = substr( $row['eid'], 10, 2 ); 974 $mysec = substr( $row['eid'], 12, 2 ); 975 $newtime = "{$mymonth}/{$myday}/{$myyear} {$myhour}:{$mymin}:{$mysec}"; 976 $creationtime = strtotime( $newtime ); 977 $extensionTags = array(); // PLG_getFeedElementExtensions('calendar', $row['eid'], $feedType, $feedVersion, $eventtitle, ); 978 $content[] = array( 'title' => $eventtitle, 979 'summary' => $eventtext, 980 'link' => $eventlink, 981 'uid' => $row['owner_id'], 982 'author' => COM_getDisplayName( $row['owner_id'] ), 983 'date' => $creationtime, 984 'format' => 'plaintext', 985 'extensions' => $extensionTags 986 ); 987 } 988 989 $link = $_CONF['site_url'] . '/calendar/index.php'; 990 $update = implode( ',', $eids ); 991 992 return $content; 993 } 994 995 /** 996 * Checking if calendar feeds are up to date 997 * 998 * @param int $feed id of feed to be checked 999 * @param string $topic topic (actually: category) 1000 * @param string $update_data data describing current feed contents 1001 * @param string $limit number of entries or number of hours 1002 * @param string $updated_type (optional) type of feed to be updated 1003 * @param string $updated_topic (optional) feed's "topic" to be updated 1004 * @param string $updated_id (optional) id of entry that has changed 1005 * 1006 */ 1007 function plugin_feedupdatecheck_calendar ($feed, $topic, $update_data, $limit, 1008 $updated_type = '', $updated_topic = '', $updated_id = '') 1009 { 1010 global $_CONF, $_TABLES, $_SYND_DEBUG; 1011 1012 $where = ''; 1013 if( !empty( $limit )) 1014 { 1015 if( substr( $limit, -1 ) == 'h' ) // next xx hours 1016 { 1017 $limitsql = ''; 1018 $hours = substr( $limit, 0, -1 ); 1019 $where = " AND (datestart <= DATE_ADD(NOW(), INTERVAL $hours HOUR))"; 1020 } 1021 else 1022 { 1023 $limitsql = ' LIMIT ' . $limit; 1024 } 1025 } 1026 else 1027 { 1028 $limitsql = ' LIMIT 10'; 1029 } 1030 1031 $result = DB_query( "SELECT eid FROM {$_TABLES['events']} WHERE perm_anon > 0 AND dateend >= NOW()$where ORDER BY datestart,timestart $limitsql" ); 1032 $nrows = DB_numRows( $result ); 1033 1034 $eids = array(); 1035 for( $i = 0; $i < $nrows; $i++ ) 1036 { 1037 $A = DB_fetchArray( $result ); 1038 1039 if( $A['eid'] == $updated_id ) 1040 { 1041 // no need to look any further - this feed has to be updated 1042 return false; 1043 } 1044 1045 $eids[] = $A['eid']; 1046 } 1047 $current = implode( ',', $eids ); 1048 1049 if ($_SYND_DEBUG) { 1050 COM_errorLog ("Update check for events: comparing new list ($current) with old list ($update_info)", 1); 1051 } 1052 1053 return ( $current != $update_data ) ? false : true; 1054 } 1055 1056 1057 /** 1058 * Calendar will not use comments 1059 */ 1060 function plugin_commentsupport_calendar() 1061 { 1062 return false; 1063 } 1064 1065 1066 /** 1067 * Shows the statistics for the Calendar plugin on stats.php. 1068 * If $showsitestats is 1 then we are to only print the overall stats in the 1069 * 'site statistics box' otherwise we show the detailed stats 1070 * 1071 * @param int showsitestate Flag to let us know which stats to get 1072 */ 1073 function plugin_showstats_calendar ($showsitestats) 1074 { 1075 global $_CONF, $_TABLES, $LANG_CAL_1; 1076 1077 $display = ''; 1078 1079 // Top Ten Events 1080 $result = DB_query("SELECT eid,title,hits from {$_TABLES['events']} WHERE (hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY hits DESC LIMIT 10"); 1081 $nrows = DB_numRows($result); 1082 if ($nrows > 0) { 1083 $header_arr = array( 1084 array('text' => $LANG_CAL_1[12], 'field' => 'sid', 'header_class' => 'stats-header-title'), 1085 array('text' => $LANG_CAL_1[48], 'field' => 'hits', 'field_class' => 'stats-list-count'), 1086 ); 1087 $data_arr = array(); 1088 $text_arr = array('has_menu' => false, 1089 'title' => $LANG_CAL_1[47], 1090 ); 1091 for ($i = 0; $i < $nrows; $i++) { 1092 $A = DB_fetchArray($result); 1093 $A['title'] = stripslashes(str_replace('$','$',$A['title'])); 1094 $A['sid'] = "<a href=\"" . $_CONF['site_url'] 1095 . "/calendar/event.php?eid={$A['eid']}\">{$A['title']}</a>"; 1096 $A['hits'] = COM_NumberFormat ($A['hits']); 1097 $data_arr[$i] = $A; 1098 } 1099 $display .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr); 1100 } else { 1101 $display .= COM_startBlock($LANG_CAL_1[47]); 1102 $display .= $LANG_CAL_1[49]; 1103 $display .= COM_endBlock(); 1104 } 1105 1106 return $display; 1107 } 1108 1109 /** 1110 * New stats plugin API function for proper integration with the site stats 1111 * 1112 * @return array(item text, item count); 1113 * 1114 */ 1115 function plugin_statssummary_calendar () 1116 { 1117 global $LANG_CAL_1, $_TABLES; 1118 1119 $result = DB_query ("SELECT COUNT(*) AS count FROM {$_TABLES['events']}" . COM_getPermSQL ()); 1120 $A = DB_fetchArray ($result); 1121 return array ($LANG_CAL_1[46], COM_NumberFormat ($A['count'])); 1122 } 1123 1124 1125 /** 1126 * This will put an option for the calendar in the command and control block on 1127 * moderation.php 1128 * 1129 */ 1130 function plugin_cclabel_calendar() 1131 { 1132 global $_CONF, $LANG_CAL_1; 1133 1134 if (SEC_hasRights ('calendar.edit')) { 1135 return array ($LANG_CAL_1[16], 1136 $_CONF['site_admin_url'] . '/plugins/calendar/index.php', 1137 plugin_geticon_calendar ()); 1138 } 1139 1140 return false; 1141 } 1142 1143 1144 /** 1145 * returns the administrative option for this plugin 1146 * 1147 */ 1148 function plugin_getadminoption_calendar() 1149 { 1150 global $_CONF, $_TABLES, $LANG_CAL_1; 1151 1152 if (SEC_hasRights ('calendar.edit')) { 1153 $result = DB_query ("SELECT COUNT(*) AS cnt FROM {$_TABLES['events']}" . COM_getPermSQL ()); 1154 $A = DB_fetchArray ($result); 1155 $total_events = $A['cnt']; 1156 1157 return array ($LANG_CAL_1[16], 1158 $_CONF['site_admin_url'] . '/plugins/calendar/index.php', 1159 $total_events); 1160 } 1161 } 1162 1163 function plugin_getuseroption_calendar() 1164 { 1165 global $_CONF, $LANG_CAL_1, $_CA_CONF; 1166 1167 if( $_CA_CONF['personalcalendars'] == 1 ) { 1168 $url = $_CONF['site_url'] . '/calendar/index.php?mode=personal'; 1169 return array ($LANG_CAL_1[42], $url, ''); 1170 } 1171 } 1172 1173 1174 /** 1175 * A user is about to be deleted. Update ownership of any events owned 1176 * by that user or delete them. 1177 * 1178 * @param uid int User id of deleted user 1179 * 1180 */ 1181 function plugin_user_delete_calendar ($uid) 1182 { 1183 global $_TABLES, $_CA_CONF; 1184 1185 DB_delete ($_TABLES['personal_events'], 'owner_id', $uid); 1186 1187 if ($_CA_CONF['delete_event'] == 1) { 1188 // delete the events 1189 DB_delete ($_TABLES['events'], 'owner_id', $uid); 1190 1191 } else { 1192 // assign ownership to a user from the Root group 1193 $rootgroup = DB_getItem ($_TABLES['groups'], 'grp_id', 1194 "grp_name = 'Root'"); 1195 $result = DB_query ("SELECT DISTINCT ug_uid FROM {$_TABLES['group_assignments']} WHERE ug_main_grp_id = $rootgroup ORDER BY ug_uid LIMIT 1"); 1196 list($rootuser) = DB_fetchArray ($result); 1197 DB_query ("UPDATE {$_TABLES['events']} SET owner_id = $rootuser WHERE owner_id = $uid"); 1198 } 1199 } 1200 1201 /** 1202 * Return the current version of code. 1203 * Used in the Plugin Editor to show the registered version and code version 1204 */ 1205 function plugin_chkVersion_calendar() 1206 { 1207 global $_CA_CONF; 1208 1209 return $_CA_CONF['version']; 1210 } 1211 1212 /** 1213 * Update the Calendar plugin 1214 * 1215 * @return int Number of message to display (true = generic success msg) 1216 * 1217 */ 1218 function plugin_upgrade_calendar() 1219 { 1220 global $_TABLES, $_CA_CONF; 1221 1222 // the plugin needs this function so complain when it doesn't exist 1223 if (!function_exists ('MBYTE_strpos')) { 1224 return 3002; 1225 } 1226 1227 // no db changes - just update the version numbers 1228 DB_query ("UPDATE {$_TABLES['plugins']} SET pi_version = '{$_CA_CONF['version']}', pi_gl_version = '" . VERSION . "' WHERE pi_name = 'calendar'"); 1229 1230 return true; 1231 } 1232 1233 /** 1234 * Geeklog informs us that we're about to be enabled or disabled 1235 * 1236 * @param boolean $enabled true = we're being enabled, false = disabled 1237 * @return void 1238 */ 1239 function plugin_enablestatechange_calendar ($enable) 1240 { 1241 global $_TABLES; 1242 1243 $is_enabled = $enable ? 1 : 0; 1244 1245 // toggle calendar feeds 1246 DB_query ("UPDATE {$_TABLES['syndication']} SET is_enabled = $is_enabled WHERE type = 'calendar'"); 1247 1248 // toggle upcoming events block 1249 DB_query ("UPDATE {$_TABLES['blocks']} SET is_enabled = $is_enabled WHERE (type = 'phpblock') AND (phpblockfn = 'phpblock_calendar')"); 1250 } 1251 1252 /** 1253 * Removes the datastructures for this plugin from the Geeklog database 1254 * 1255 * This may get called by the install routine to undo anything done to this 1256 * point. To do that, $steps will have a list of steps to undo 1257 * 1258 * @steps Array Holds all the steps that have been completed by the install 1259 * 1260 */ 1261 function plugin_uninstall_calendar ($steps = '') 1262 { 1263 global $_TABLES; 1264 1265 // Uninstalls the calendar plugin 1266 1267 COM_errorLog('Dropping events table', 1); 1268 DB_query("DROP TABLE {$_TABLES['events']}"); 1269 COM_errorLog('...success', 1); 1270 COM_errorLog('Dropping event submission table', 1); 1271 DB_query("DROP TABLE {$_TABLES['eventsubmission']}"); 1272 COM_errorLog('...success', 1); 1273 COM_errorLog('Dropping personal events table', 1); 1274 DB_query("DROP TABLE {$_TABLES['personal_events']}"); 1275 COM_errorLog('...success', 1); 1276 1277 // Remove Upcoming Events block 1278 DB_delete ($_TABLES['blocks'], array ('type', 'phpblockfn'), 1279 array ('phpblock', 'phpblock_calendar')); 1280 1281 // Remove security for this plugin 1282 1283 // Remove the calendar admin group 1284 $grp_id = DB_getItem ($_TABLES['groups'], 'grp_id', 1285 "grp_name = 'Calendar Admin'"); 1286 1287 // Remove Calendar Admin group from all other groups 1288 if (!empty ($grp_id)) { 1289 COM_errorLog ('Attempting to remove Calendar Admin group from all groups' , 1); 1290 DB_query("DELETE FROM {$_TABLES['group_assignments']} WHERE ug_main_grp_id = $grp_id"); 1291 COM_errorLog ('...success', 1); 1292 1293 COM_errorLog('Attempting to remove the Calendar Admin Group', 1); 1294 DB_query("DELETE FROM {$_TABLES['groups']} WHERE grp_id = $grp_id"); 1295 COM_errorLog('...success', 1); 1296 } 1297 1298 // Remove related features 1299 $features = array ('calendar.edit', 'calendar.moderate', 'calendar.submit'); 1300 1301 foreach ($features as $f) { 1302 $feat_id = DB_getItem ($_TABLES['features'], 'ft_id', "ft_name = '$f'"); 1303 if (!empty ($feat_id)) { 1304 COM_errorLog ("Attempting to remove $f rights from all groups", 1); 1305 DB_query ("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $feat_id"); 1306 COM_errorLog ('...success', 1); 1307 1308 COM_errorLog ("Attempting to remove the $f feature", 1); 1309 DB_query ("DELETE FROM {$_TABLES['features']} WHERE ft_id = $feat_id"); 1310 COM_errorLog ('...success', 1); 1311 } 1312 } 1313 1314 // Unregister the plugin with Geeklog 1315 // Always attempt to remove this entry or lib-common.php would still 1316 // try and read our functions.inc file ... 1317 COM_errorLog('Attempting to unregister the calendar plugin from Geeklog', 1); 1318 DB_query("DELETE FROM {$_TABLES['plugins']} WHERE pi_name = 'calendar'"); 1319 COM_errorLog('...success', 1); 1320 1321 COM_errorLog ('Finished uninstalling the Calendar plugin.', 1); 1322 1323 return true; 1324 } 1325 1326 /** 1327 * Get path for the template files. 1328 * 1329 * @param string $path subdirectory within the base template path 1330 * @return string full path to template directory 1331 * 1332 */ 1333 function calendar_templatePath ($path = '') 1334 { 1335 global $_CONF; 1336 1337 if (empty ($path)) { 1338 $layout_path = $_CONF['path_layout'] . calendar; 1339 } else { 1340 $layout_path = $_CONF['path_layout'] . calendar . '/' . $path; 1341 } 1342 1343 if (is_dir ($layout_path)) { 1344 $retval = $layout_path; 1345 } else { 1346 $retval = $_CONF['path'] . 'plugins/calendar/templates'; 1347 if (!empty ($path)) { 1348 $retval .= '/' . $path; 1349 } 1350 } 1351 1352 return $retval; 1353 } 1354 1355 /** 1356 * Returns the URL of the plugin's icon 1357 * 1358 * @return string URL of the icon 1359 * 1360 */ 1361 function plugin_geticon_calendar () 1362 { 1363 global $_CONF; 1364 1365 return $_CONF['site_url'] . '/calendar/images/calendar.png'; 1366 } 1367 1368 /** 1369 * Geeklog is asking us to provide any items that show up in the type 1370 * drop-down on search.php. Let's users search for events. 1371 * 1372 * @return array (plugin name/entry title) pair for the dropdown 1373 * 1374 */ 1375 function plugin_searchtypes_calendar() 1376 { 1377 global $LANG_CAL_1; 1378 1379 $tmp['calendar'] = $LANG_CAL_1[50]; 1380 1381 return $tmp; 1382 } 1383 1384 /** 1385 * This searches for events matching the user query and returns an array for the 1386 * header and table rows back to search.php where it will be formated and printed 1387 * 1388 * @param string $query Keywords user is looking for 1389 * @param date $datestart Start date to get results for 1390 * @param date $dateend End date to get results for 1391 * @param string $topic The topic they were searching in 1392 * @param string $type Type of items they are searching, or 'all' 1393 * @param int $author Get all results by this author 1394 * @param string $keyType search key type: 'all', 'phrase', 'any' 1395 * @param int $page page number of current search 1396 * @param int $perpage number of results per page 1397 * @return object search result object 1398 * 1399 */ 1400 function plugin_dopluginsearch_calendar($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage) 1401 { 1402 global $_CONF, $_TABLES, $LANG09, $LANG_CAL_1, $_LANG_CAL_SEARCH; 1403 1404 if (empty ($type)) { 1405 $type = 'all'; 1406 } 1407 1408 // Bail if we aren't supppose to do our search 1409 if ($type <> 'all' AND $type <> 'calendar') { 1410 $event_results = new Plugin(); 1411 $event_results->plugin_name = 'calendar'; 1412 $event_results->num_itemssearched = 0; 1413 $event_results->searchlabel = $_LANG_CAL_SEARCH['results']; 1414 1415 return $event_results; 1416 } 1417 1418 $select = "SELECT eid,title,location,event_type,datestart,dateend,timestart,timeend,allday,UNIX_TIMESTAMP(datestart) AS day"; 1419 $sql = " FROM {$_TABLES['events']} WHERE "; 1420 1421 if($keyType == 'phrase') { 1422 // do an exact phrase search (default) 1423 $mywords[] = $query; 1424 $mysearchterm = addslashes ($query); 1425 $sql .= "(location LIKE '%$mysearchterm%' "; 1426 $sql .= "OR description LIKE '%$mysearchterm%' "; 1427 $sql .= "OR title LIKE '%$mysearchterm%') "; 1428 } elseif ($keyType == 'all') { 1429 //must contain ALL of the keywords 1430 $mywords = explode(' ', $query); 1431 $tmp = ''; 1432 foreach ($mywords AS $mysearchterm) { 1433 $mysearchterm = addslashes (trim ($mysearchterm)); 1434 $tmp .= "(location LIKE '%$mysearchterm%' OR "; 1435 $tmp .= "description LIKE '%$mysearchterm%' OR "; 1436 $tmp .= "title LIKE '%$mysearchterm%') AND "; 1437 } 1438 $tmp = substr($tmp, 0, strlen($tmp) - 4); 1439 $sql .= $tmp; 1440 } elseif ($keyType == 'any') { 1441 //must contain ANY of the keywords 1442 $mywords = explode(' ', $query); 1443 $tmp = ''; 1444 foreach ($mywords AS $mysearchterm) { 1445 $mysearchterm = addslashes (trim ($mysearchterm)); 1446 $tmp .= "(location LIKE '%$mysearchterm%' OR "; 1447 $tmp .= "description LIKE '%$mysearchterm%' OR "; 1448 $tmp .= "title LIKE '%$mysearchterm%') OR "; 1449 } 1450 $tmp = substr($tmp, 0, strlen($tmp) - 3); 1451 $sql .= "($tmp)"; 1452 } else { 1453 $mywords[] = $query; 1454 $mysearchterm = addslashes ($query); 1455 $sql .= "(location LIKE '%$mysearchterm%' "; 1456 $sql .= "OR description LIKE '%$mysearchterm%' "; 1457 $sql .= "OR title LIKE '%$mysearchterm%') "; 1458 } 1459 1460 if (!empty($dateStart) AND !empty($dateEnd)) { 1461 $delim = substr($dateStart, 4, 1); 1462 if (!empty($delim)) { 1463 $DS = explode($delim, $dateStart); 1464 $DE = explode($delim, $dateEnd); 1465 $startdate = mktime(0, 0, 0, $DS[1], $DS[2], $DS[0]); 1466 $enddate = mktime(23, 59, 59, $DE[1], $DE[2], $DE[0]); 1467 $sql .= "AND (UNIX_TIMESTAMP(datestart) BETWEEN '$startdate' AND '$enddate') "; 1468 } 1469 } 1470 $sql .= COM_getPermSQL ('AND'); 1471 $sql .= ' GROUP BY datestart, eid, title, description, location, dateend, timestart, timeend, allday, event_type ORDER BY datestart DESC '; 1472 $l = ($perpage * $page) - $perpage; 1473 $sql .= 'LIMIT ' . $l . ',' . $perpage; 1474 1475 $result_events = DB_query ($select . $sql); 1476 $result_count = DB_query ('SELECT COUNT(*)' . $sql); 1477 $B = DB_fetchArray ($result_count, true); 1478 1479 $event_results = new Plugin(); 1480 $event_results->searchresults = array(); 1481 $event_results->searchlabel = $_LANG_CAL_SEARCH['results']; 1482 $event_results->addSearchHeading ($_LANG_CAL_SEARCH['title']); 1483 $event_results->addSearchHeading ($_LANG_CAL_SEARCH['date_time']); 1484 if (empty ($_LANG_CAL_SEARCH['event_type'])) { 1485 $event_results->addSearchHeading ($LANG_CAL_1[37]); 1486 } else { 1487 $event_results->addSearchHeading ($_LANG_CAL_SEARCH['event_type']); 1488 } 1489 $event_results->num_searchresults = 0; 1490 $event_results->num_itemssearched = $B[0]; 1491 $event_results->supports_paging = true; 1492 1493 // NOTE if any of your data items need to be events then add them 1494 // here! Make sure data elements are in an array and in the same 1495 // order as your headings above! 1496 while ($A = DB_fetchArray ($result_events)) { 1497 if ($A['allday'] == 0) { 1498 if ($A['datestart'] == $A['dateend']) { 1499 $fulldate = $A['datestart'] . ' ' . $A['timestart']; 1500 if ($A['timestart'] != $A['timeend']) { 1501 $fulldate .= ' - ' . $A['timeend']; 1502 } 1503 } else { 1504 $fulldate = $A['datestart'] . ' ' . $A['timestart'] . ' - ' 1505 . $A['dateend'] . ' ' . $A['timeend']; 1506 } 1507 } else { 1508 if ($A['datestart'] <> $A['dateend']) { 1509 $fulldate = $A['datestart'] . ' - ' . $A['dateend'] 1510 . ' ' . $LANG09[35]; 1511 } else { 1512 $fulldate = $A['datestart'] . ' ' . $LANG09[35]; 1513 } 1514 } 1515 $thetime = COM_getUserDateTimeFormat ($A['day']); 1516 $A['title'] = stripslashes ($A['title']); 1517 $A['title'] = str_replace ('$', '$', $A['title']); 1518 $row = array ('<a href="' . $_CONF['site_url'] 1519 . '/calendar/event.php?eid=' . $A['eid'] . '">' 1520 . $A['title'] . '</a>', $fulldate, 1521 stripslashes ($A['event_type'])); 1522 $event_results->addSearchResult($row); 1523 $event_results->num_searchresults++; 1524 } 1525 return $event_results; 1526 } 1527 1528 1529 /** 1530 * Set template variables 1531 * 1532 * @param string $templatename name of template, e.g. 'header' 1533 * @param ref $template reference of actual template 1534 * @return void 1535 * 1536 * Note: A plugin should use its name as a prefix for the names of its 1537 * template variables, e.g. 'calendar_xxx' and 'lang_calendar_xxx'. 1538 * 'button_calendar' is an exception, as such a variable existed for header.thtml 1539 * in Geeklog 1.4.0 and earlier, where the Calendar was an integral part 1540 * of Geeklog. It is added here for backward-compatibility. 1541 * 1542 */ 1543 function plugin_templatesetvars_calendar ($templatename, &$template) 1544 { 1545 global $LANG_CAL_1; 1546 1547 if ($templatename == 'header') { 1548 $template->set_var ('button_calendar', $LANG_CAL_1[16]); 1549 } 1550 } 1551 1552 function plugin_getListField_calendar($fieldname, $fieldvalue, $A, $icon_arr) 1553 { 1554 global $_CONF, $LANG_ACCESS, $LANG_ADMIN; 1555 1556 $retval = ''; 1557 1558 $access = SEC_hasAccess($A['owner_id'],$A['group_id'],$A['perm_owner'], 1559 $A['perm_group'],$A['perm_members'],$A['perm_anon']); 1560 1561 switch($fieldname) { 1562 case "edit": 1563 if ($access == 3) { 1564 $retval = "<a href=\"{$_CONF['site_admin_url']}" 1565 . "/plugins/calendar/index.php?mode=edit&eid=" 1566 . "{$A['eid']}\">{$icon_arr['edit']}</a>"; 1567 } 1568 break; 1569 case "copy": 1570 if ($access == 3) { 1571 $retval = "<a href=\"{$_CONF['site_admin_url']}" 1572 . "/plugins/calendar/index.php?mode=clone&eid=" 1573 . "{$A['eid']}\">{$icon_arr['copy']}</a>"; 1574 } 1575 break; 1576 case 'access': 1577 if ($access == 3) { 1578 $retval = $LANG_ACCESS['edit']; 1579 } else { 1580 $retval = $LANG_ACCESS['readonly']; 1581 } 1582 break; 1583 case 'title': 1584 $retval = stripslashes ($A['title']); 1585 $retval = "<a href=\"{$_CONF['site_url']}/calendar/event.php?eid=" 1586 . "{$A['eid']}\">$retval</a>"; 1587 break; 1588 case 'username': 1589 $retval = COM_getDisplayName ($A['owner_id'], $A['username'], $A['fullname']); 1590 break; 1591 default: 1592 $retval = $fieldvalue; 1593 break; 1594 } 1595 return $retval; 1596 } 1597 1598 /** 1599 * Creates a dropdown list of all the states 1600 * 1601 * @param string $currstate current state (to preselect in the list) 1602 * @return string <option> list of states 1603 * 1604 */ 1605 function CALENDAR_stateList ($currstate = '') 1606 { 1607 global $_STATES; 1608 1609 $retval = ''; 1610 1611 foreach ($_STATES as $statekey => $state) { 1612 $retval .= '<option value="' . $statekey . '"'; 1613 if ($statekey == $currstate) { 1614 $retval .= ' selected="selected"'; 1615 } 1616 $retval .= '>' . $state . '</option>'; 1617 } 1618 1619 return $retval; 1620 } 1621 1622 /** 1623 * Creates a dropdown list of all the event types 1624 * 1625 * @param string $currtype current event type (to preselect in the list) 1626 * @return string <option> list of event types 1627 * 1628 */ 1629 function CALENDAR_eventTypeList ($currtype = '') 1630 { 1631 global $_CA_CONF; 1632 1633 $retval = ''; 1634 1635 $event_types = explode (',', $_CA_CONF['event_types']); 1636 asort ($event_types); 1637 1638 foreach ($event_types as $type) { 1639 $retval .= '<option value="' . $type . '"'; 1640 if ($currtype == $type) { 1641 $retval .= ' selected="selected"'; 1642 } 1643 $retval .= '>' . $type . '</option>'; 1644 } 1645 1646 return $retval; 1647 } 1648 1649 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |