[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id$ 10 */ 11 12 define("IN_MYBB", 1); 13 define('THIS_SCRIPT', 'calendar.php'); 14 15 $templatelist = "calendar_weekdayheader,calendar_weekrow_day,calendar_weekrow,calendar,calendar_addevent,calendar_move"; 16 $templatelist .= ",calendar_weekview_day,calendar_weekview_day_event,calendar_mini_weekdayheader,calendar_mini_weekrow_day,calendar_mini_weekrow,calendar_mini,calendar_weekview_month,calendar_weekview,calendar_eventbit,calendar_addeventlink"; 17 $templatelist .= ",calendar_event_editbutton,calendar_event_modoptions,calendar_event,calendar_dayview_event,calendar_dayview,codebuttons,smilieinsert,smilieinsert_getmore,calendar_editevent,calendar_dayview_birthdays_bday,calendar_dayview_birthdays,calendar_dayview_noevents"; 18 19 require_once "./global.php"; 20 21 require_once MYBB_ROOT."inc/functions_calendar.php"; 22 require_once MYBB_ROOT."inc/functions_post.php"; 23 require_once MYBB_ROOT."inc/class_parser.php"; 24 $parser = new postParser; 25 26 // Load global language phrases 27 $lang->load("calendar"); 28 29 if($mybb->settings['enablecalendar'] == 0) 30 { 31 error($lang->calendar_disabled); 32 } 33 34 if($mybb->usergroup['canviewcalendar'] == 0) 35 { 36 error_no_permission(); 37 } 38 39 $monthnames = array( 40 "offset", 41 $lang->alt_month_1, 42 $lang->alt_month_2, 43 $lang->alt_month_3, 44 $lang->alt_month_4, 45 $lang->alt_month_5, 46 $lang->alt_month_6, 47 $lang->alt_month_7, 48 $lang->alt_month_8, 49 $lang->alt_month_9, 50 $lang->alt_month_10, 51 $lang->alt_month_11, 52 $lang->alt_month_12 53 ); 54 55 // Make navigation 56 add_breadcrumb($lang->nav_calendar, "calendar.php"); 57 58 $calendar_jump = build_calendar_jump($mybb->input['calendar']); 59 60 // Add an event 61 if($mybb->input['action'] == "do_addevent" && $mybb->request_method == "post") 62 { 63 $query = $db->simple_select("calendars", "*", "cid='".intval($mybb->input['calendar'])."'"); 64 $calendar = $db->fetch_array($query); 65 66 // Invalid calendar? 67 if(!$calendar['cid']) 68 { 69 error($lang->invalid_calendar); 70 } 71 72 // Do we have permission to view this calendar or post events? 73 $calendar_permissions = get_calendar_permissions($calendar['cid']); 74 if($calendar_permissions['canviewcalendar'] != 1 || $calendar_permissions['canaddevents'] != 1) 75 { 76 error_no_permission(); 77 } 78 79 // Verify incoming POST request 80 verify_post_check($mybb->input['my_post_key']); 81 82 $plugins->run_hooks("calendar_do_addevent_start"); 83 84 // Set up event handler. 85 require_once MYBB_ROOT."inc/datahandler.php"; 86 require_once MYBB_ROOT."inc/datahandlers/event.php"; 87 $eventhandler = new EventDataHandler("insert"); 88 89 // Prepare an array for the eventhandler. 90 $event = array( 91 "cid" => $calendar['cid'], 92 "uid" => $mybb->user['uid'], 93 "name" => $mybb->input['name'], 94 "description" => $mybb->input['description'], 95 "private" => $mybb->input['private'], 96 "type" => $mybb->input['type'] 97 ); 98 99 // Now we add in our date/time info depending on the type of event 100 if($mybb->input['type'] == "single") 101 { 102 $event['start_date'] = array( 103 "day" => $mybb->input['single_day'], 104 "month" => $mybb->input['single_month'], 105 "year" => $mybb->input['single_year'] 106 ); 107 } 108 else if($mybb->input['type'] == "ranged") 109 { 110 $event['start_date'] = array( 111 "day" => $mybb->input['start_day'], 112 "month" => $mybb->input['start_month'], 113 "year" => $mybb->input['start_year'], 114 "time" => $mybb->input['start_time'] 115 ); 116 $event['end_date'] = array( 117 "day" => $mybb->input['end_day'], 118 "month" => $mybb->input['end_month'], 119 "year" => $mybb->input['end_year'], 120 "time" => $mybb->input['end_time'] 121 ); 122 $event['timezone'] = intval($mybb->input['timezone']); 123 $event['ignoretimezone'] = intval($mybb->input['ignoretimezone']); 124 $repeats = array(); 125 switch($mybb->input['repeats']) 126 { 127 case 1: 128 $repeats['repeats'] = 1; 129 $repeats['days'] = $mybb->input['repeats_1_days']; 130 break; 131 case 2: 132 $repeats['repeats'] = 2; 133 break; 134 case 3: 135 $repeats['repeats'] = 3; 136 $repeats['weeks'] = $mybb->input['repeats_3_weeks']; 137 if(!is_array($mybb->input['repeats_3_days'])) 138 { 139 $mybb->input['repeats_3_days'] = array(); 140 } 141 ksort($mybb->input['repeats_3_days']); 142 $days = array(); 143 foreach($mybb->input['repeats_3_days'] as $weekday => $value) 144 { 145 if($value != 1) continue; 146 $days[] = $weekday; 147 } 148 $repeats['days'] = $days; 149 break; 150 case 4: 151 $repeats['repeats'] = 4; 152 if($mybb->input['repeats_4_type'] == 1) 153 { 154 $repeats['day'] = $mybb->input['repeats_4_day']; 155 $repeats['months'] = $mybb->input['repeats_4_months']; 156 } 157 else 158 { 159 $repeats['months'] = $mybb->input['repeats_4_months2']; 160 $repeats['occurance'] = $mybb->input['repeats_4_occurance']; 161 $repeats['weekday'] = $mybb->input['repeats_4_weekday']; 162 } 163 break; 164 case 5: 165 $repeats['repeats'] = 5; 166 if($mybb->input['repeats_5_type'] == 1) 167 { 168 $repeats['day'] = $mybb->input['repeats_5_day']; 169 $repeats['month'] = $mybb->input['repeats_5_month']; 170 $repeats['years'] = $mybb->input['repeats_5_years']; 171 } 172 else 173 { 174 $repeats['occurance'] = $mybb->input['repeats_5_occurance']; 175 $repeats['weekday'] = $mybb->input['repeats_5_weekday']; 176 $repeats['month'] = $mybb->input['repeats_5_month2']; 177 $repeats['years'] = $mybb->input['repeats_5_years']; 178 } 179 break; 180 default: 181 $repeats['repeats'] = 0; 182 } 183 $event['repeats'] = $repeats; 184 } 185 186 $eventhandler->set_data($event); 187 188 // Now let the eventhandler do all the hard work. 189 if(!$eventhandler->validate_event()) 190 { 191 $event_errors = $eventhandler->get_friendly_errors(); 192 $event_errors = inline_error($event_errors); 193 $mybb->input['action'] = "addevent"; 194 } 195 else 196 { 197 $details = $eventhandler->insert_event(); 198 $plugins->run_hooks("calendar_do_addevent_end"); 199 if($details['visible'] == 1) 200 { 201 redirect(get_event_link($details['eid']), $lang->redirect_eventadded); 202 } 203 else 204 { 205 redirect(get_calendar_link($event['cid']), $lang->redirect_eventadded_moderation); 206 } 207 } 208 } 209 210 if($mybb->input['action'] == "addevent") 211 { 212 $query = $db->simple_select("calendars", "*", "cid='".intval($mybb->input['calendar'])."'"); 213 $calendar = $db->fetch_array($query); 214 215 // Invalid calendar? 216 if(!$calendar['cid']) 217 { 218 error($lang->invalid_calendar); 219 } 220 221 // Do we have permission to view this calendar or post events? 222 $calendar_permissions = get_calendar_permissions($calendar['cid']); 223 if($calendar_permissions['canviewcalendar'] != 1 || $calendar_permissions['canaddevents'] != 1) 224 { 225 error_no_permission(); 226 } 227 228 add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid'])); 229 add_breadcrumb($lang->nav_addevent); 230 231 $plugins->run_hooks("calendar_addevent_start"); 232 233 // If MyCode is on for this forum and the MyCode editor is enabled inthe Admin CP, draw the code buttons and smilie inserter. 234 if($mybb->settings['bbcodeinserter'] != 0 && (!$mybb->user['uid'] || $mybb->user['showcodebuttons'] != 0) && $calendar['allowmycode'] == 1) 235 { 236 $codebuttons = build_mycode_inserter(); 237 if($calendar['allowsmilies'] == 1) 238 { 239 $smilieinserter = build_clickable_smilies(); 240 } 241 } 242 243 // Previous selections 244 $name = $description = ''; 245 if(isset($mybb->input['name'])) 246 { 247 $name = htmlspecialchars_uni($mybb->input['name']); 248 } 249 250 if(isset($mybb->input['description'])) 251 { 252 $description = htmlspecialchars_uni($mybb->input['description']); 253 } 254 255 if($mybb->request_method == "post") 256 { 257 $single_day = $mybb->input['single_day']; 258 $single_month[$mybb->input['single_month']] = " selected=\"selected\""; 259 $single_year = $mybb->input['single_year']; 260 $start_day = $mybb->input['start_day']; 261 $start_month[$mybb->input['start_month']] = " selected=\"selected\""; 262 $start_year = $mybb->input['start_year']; 263 $start_time = htmlspecialchars_uni($mybb->input['start_time']); 264 $end_day = $mybb->input['end_day']; 265 $end_month[$mybb->input['end_month']] = " selected=\"selected\""; 266 $end_year = $mybb->input['end_year']; 267 $end_time = htmlspecialchars_uni($mybb->input['end_time']); 268 if($mybb->input['type'] == "single") 269 { 270 $type_single = "checked=\"checked\""; 271 $type = "single"; 272 } 273 else 274 { 275 $type_ranged = "checked=\"checked\""; 276 $type = "ranged"; 277 } 278 if($mybb->input['repeats']) 279 { 280 $repeats_sel[$mybb->input['repeats']] = " selected=\"selected\""; 281 } 282 $repeats_1_days = intval($mybb->input['repeats_1_days']); 283 $repeats_3_weeks = intval($mybb->input['repeats_3_weeks']); 284 if(is_array($mybb->input['repeats_3_days'])) 285 { 286 foreach($mybb->input['repeats_3_days'] as $day => $val) 287 { 288 if($val != 1) 289 { 290 continue; 291 } 292 $day = intval($day); 293 $repeats_3_days[$day] = " checked=\"checked\""; 294 } 295 } 296 if($mybb->input['repeats_4_type'] == 1) 297 { 298 $repeats_4_type[1] = "checked=\"checked\""; 299 } 300 else 301 { 302 $repeats_4_type[2] = "checked=\"checked\""; 303 } 304 $repeats_4_day = intval($mybb->input['repeats_4_day']); 305 $repeats_4_months = intval($mybb->input['repeats_4_months']); 306 $repeats_4_occurance[$mybb->input['repeats_4_occurance']] = "selected=\"selected\""; 307 $repeats_4_weekday[$mybb->input['repeats_4_weekday']] = "selected=\"selected\""; 308 $repeats_4_months2 = intval($mybb->input['repeats_4_months2']); 309 if($mybb->input['repeats_5_type'] == 1) 310 { 311 $repeats_5_type[1] = "checked=\"checked\""; 312 } 313 else 314 { 315 $repeats_5_type[2] = "checked=\"checked\""; 316 } 317 $repeats_5_day = intval($mybb->input['repeats_5_day']); 318 $repeats_5_month[$mybb->input['repeats_5_month']] = "selected=\"selected\""; 319 $repeats_5_years = intval($mybb->input['repeats_5_years']); 320 $repeats_5_occurance[$mybb->input['repeats_5_occurance']] = "selected=\"selected\""; 321 $repeats_5_weekday[$mybb->input['repeats_5_weekday']] = "selected=\"selected\""; 322 $repeats_5_month2[$mybb->input['repeats_5_month2']] = "selected=\"selected\""; 323 $repeats_5_years2 = intval($mybb->input['repeats_5_years2']); 324 325 $timezone = $mybb->input['timezone']; 326 } 327 else 328 { 329 if($mybb->input['day']) 330 { 331 $single_day = $start_day = $end_day = intval($mybb->input['day']); 332 } 333 else 334 { 335 $single_day = $start_day = $end_day = my_date("j"); 336 } 337 if($mybb->input['month']) 338 { 339 $month = intval($mybb->input['month']); 340 } 341 else 342 { 343 $month = my_date("n"); 344 } 345 $single_month[$month] = $start_month[$month] = $end_month[$month] = "selected=\"selected\""; 346 if($mybb->input['year']) 347 { 348 $single_year = $start_year = $end_year = intval($mybb->input['year']); 349 } 350 else 351 { 352 $single_year = $start_year = $end_year = my_date("Y"); 353 } 354 $start_time = $end_time = ""; 355 $type_single = "checked=\"checked\""; 356 $type = "single"; 357 $repeats_1_days = 1; 358 $repeats_3_weeks = 1; 359 $repeats_4_type[1] = "checked=\"checked\""; 360 $repeats_4_day = 1; 361 $repeats_4_months = 1; 362 $repeats_4_occurance[1] = "selected=\"selected\""; 363 $repeats_4_weekday[0] = "selected=\"selected\""; 364 $repeats_4_months2 = 1; 365 $repeats_5_type[1] = "checked=\"checked\""; 366 $repeats_5_day = 1; 367 $repeats_5_month[1] = "selected=\"selected\""; 368 $repeats_5_years = 1; 369 $repeats_5_occurance[1] = "selected=\"selected\""; 370 $repeats_5_weekday[0] = "selected=\"selected\""; 371 $repeats_5_months2[1] = "selected=\"selected\""; 372 $repeats_5_years2 = 1; 373 $timezone = $mybb->user['timezone']; 374 } 375 376 // Construct option list for years 377 for($i = my_date('Y'); $i < (my_date('Y') + 5); ++$i) 378 { 379 if($i == $single_year) 380 { 381 $single_years .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 382 } 383 else 384 { 385 $single_years .= "<option value=\"{$i}\">{$i}</option>\n"; 386 } 387 if($i == $start_year) 388 { 389 $start_years .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 390 } 391 else 392 { 393 $start_years .= "<option value=\"{$i}\">{$i}</option>\n"; 394 } 395 if($i == $end_year) 396 { 397 $end_years .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 398 } 399 else 400 { 401 $end_years .= "<option value=\"{$i}\">{$i}</option>\n"; 402 } 403 } 404 405 // Construct option list for days 406 for($i = 1; $i <= 31; ++$i) 407 { 408 if($i == $single_day) 409 { 410 $single_days .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 411 } 412 else 413 { 414 $single_days .= "<option value=\"{$i}\">{$i}</option>\n"; 415 } 416 if($i == $start_day) 417 { 418 $start_days .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 419 } 420 else 421 { 422 $start_days .= "<option value=\"{$i}\">{$i}</option>\n"; 423 } 424 if($i == $end_day) 425 { 426 $end_days .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 427 } 428 else 429 { 430 $end_days .= "<option value=\"{$i}\">{$i}</option>\n"; 431 } 432 } 433 434 $timezones = build_timezone_select("timezone", $timezone); 435 436 if($mybb->input['ignoretimezone'] == 1) 437 { 438 $ignore_timezone = "checked=\"checked\""; 439 } 440 441 if($mybb->input['private'] == 1) 442 { 443 $privatecheck = " checked=\"checked\""; 444 } 445 446 // Build calendar select 447 $calendar_permissions = get_calendar_permissions(); 448 $query = $db->simple_select("calendars", "*", "", array("order_by" => "name", "order_dir" => "asc")); 449 while($calendar_option = $db->fetch_array($query)) 450 { 451 if($calendar_permissions[$calendar['cid']]['canviewcalendar'] == 1) 452 { 453 $calendar_option['name'] = htmlspecialchars_uni($calendar_option['name']); 454 if($calendar_option['cid'] == $mybb->input['calendar']) 455 { 456 $calendar_select .= "<option value=\"{$calendar_option['cid']}\" selected=\"selected\">{$calendar_option['name']}</option>\n"; 457 } 458 else 459 { 460 $calendar_select .= "<option value=\"{$calendar_option['cid']}\">{$calendar_option['name']}</option>\n"; 461 } 462 } 463 } 464 465 $plugins->run_hooks("calendar_addevent_end"); 466 467 eval("\$addevent = \"".$templates->get("calendar_addevent")."\";"); 468 output_page($addevent); 469 } 470 471 // Edit an event 472 if($mybb->input['action'] == "do_editevent" && $mybb->request_method == "post") 473 { 474 $query = $db->simple_select("events", "*", "eid='".intval($mybb->input['eid'])."'"); 475 $event = $db->fetch_array($query); 476 477 if(!is_numeric($event['eid'])) 478 { 479 error($lang->error_invalidevent); 480 } 481 482 $query = $db->simple_select("calendars", "*", "cid='{$event['cid']}'"); 483 $calendar = $db->fetch_array($query); 484 485 // Invalid calendar? 486 if(!$calendar['cid']) 487 { 488 error($lang->invalid_calendar); 489 } 490 491 // Do we have permission to view this calendar or post events? 492 $calendar_permissions = get_calendar_permissions($calendar['cid']); 493 if($calendar_permissions['canviewcalendar'] != 1 || $calendar_permissions['canaddevents'] != 1) 494 { 495 error_no_permission(); 496 } 497 498 if(($event['uid'] != $mybb->user['uid'] || $mybb->user['uid'] == 0) && $calendar_permissions['canmoderateevents'] != 1) 499 { 500 error_no_permission(); 501 } 502 503 // Verify incoming POST request 504 verify_post_check($mybb->input['my_post_key']); 505 506 // Are we going to delete this event or just edit it? 507 if($mybb->input['delete'] == 1) 508 { 509 $db->delete_query("events", "eid='{$event['eid']}'"); 510 511 // Redirect back to the main calendar view. 512 redirect("calendar.php", $lang->redirect_eventdeleted); 513 } 514 515 // Have we made a private event public? 516 if(!$mybb->input['private']) 517 { 518 $mybb->input['private'] = 0; 519 } 520 521 $plugins->run_hooks("calendar_do_editevent_start"); 522 523 // Set up event handler. 524 require_once MYBB_ROOT."inc/datahandler.php"; 525 require_once MYBB_ROOT."inc/datahandlers/event.php"; 526 $eventhandler = new EventDataHandler("update"); 527 528 // Prepare an array for the eventhandler. 529 $event = array( 530 "eid" => $event['eid'], 531 "name" => $mybb->input['name'], 532 "description" => $mybb->input['description'], 533 "private" => $mybb->input['private'], 534 "type" => $mybb->input['type'] 535 ); 536 537 // Now we add in our date/time info depending on the type of event 538 if($mybb->input['type'] == "single") 539 { 540 $event['start_date'] = array( 541 "day" => $mybb->input['single_day'], 542 "month" => $mybb->input['single_month'], 543 "year" => $mybb->input['single_year'] 544 ); 545 $event['repeats'] = ''; 546 } 547 else if($mybb->input['type'] == "ranged") 548 { 549 $event['start_date'] = array( 550 "day" => $mybb->input['start_day'], 551 "month" => $mybb->input['start_month'], 552 "year" => $mybb->input['start_year'], 553 "time" => $mybb->input['start_time'] 554 ); 555 $event['end_date'] = array( 556 "day" => $mybb->input['end_day'], 557 "month" => $mybb->input['end_month'], 558 "year" => $mybb->input['end_year'], 559 "time" => $mybb->input['end_time'] 560 ); 561 $event['timezone'] = $mybb->input['timezone']; 562 $event['ignoretimezone'] = intval($mybb->input['ignoretimezone']); 563 $repeats = array(); 564 switch($mybb->input['repeats']) 565 { 566 case 1: 567 $repeats['repeats'] = 1; 568 $repeats['days'] = $mybb->input['repeats_1_days']; 569 break; 570 case 2: 571 $repeats['repeats'] = 2; 572 break; 573 case 3: 574 $repeats['repeats'] = 3; 575 $repeats['weeks'] = $mybb->input['repeats_3_weeks']; 576 if(!is_array($mybb->input['repeats_3_days'])) 577 { 578 $mybb->input['repeats_3_days'] = array(); 579 } 580 ksort($mybb->input['repeats_3_days']); 581 $days = array(); 582 foreach($mybb->input['repeats_3_days'] as $weekday => $value) 583 { 584 if($value != 1) 585 { 586 continue; 587 } 588 $days[] = $weekday; 589 } 590 $repeats['days'] = $days; 591 break; 592 case 4: 593 $repeats['repeats'] = 4; 594 if($mybb->input['repeats_4_type'] == 1) 595 { 596 $repeats['day'] = $mybb->input['repeats_4_day']; 597 $repeats['months'] = $mybb->input['repeats_4_months']; 598 } 599 else 600 { 601 $repeats['months'] = $mybb->input['repeats_4_months2']; 602 $repeats['occurance'] = $mybb->input['repeats_4_occurance']; 603 $repeats['weekday'] = $mybb->input['repeats_4_weekday']; 604 } 605 break; 606 case 5: 607 $repeats['repeats'] = 5; 608 if($mybb->input['repeats_5_type'] == 1) 609 { 610 $repeats['day'] = $mybb->input['repeats_5_day']; 611 $repeats['month'] = $mybb->input['repeats_5_month']; 612 $repeats['years'] = $mybb->input['repeats_5_years']; 613 } 614 else 615 { 616 $repeats['occurance'] = $mybb->input['repeats_5_occurance']; 617 $repeats['weekday'] = $mybb->input['repeats_5_weekday']; 618 $repeats['month'] = $mybb->input['repeats_5_month2']; 619 $repeats['years'] = $mybb->input['repeats_5_years']; 620 } 621 break; 622 default: 623 $repeats['repeats'] = 0; 624 } 625 $event['repeats'] = $repeats; 626 } 627 628 $eventhandler->set_data($event); 629 630 // Now let the eventhandler do all the hard work. 631 if(!$eventhandler->validate_event()) 632 { 633 $event_errors = $eventhandler->get_friendly_errors(); 634 $event_errors = inline_error($event_errors); 635 $mybb->input['action'] = "editevent"; 636 } 637 else 638 { 639 $details = $eventhandler->update_event(); 640 $plugins->run_hooks("calendar_do_editevent_end"); 641 redirect(get_event_link($event['eid']), $lang->redirect_eventupdated); 642 } 643 } 644 645 if($mybb->input['action'] == "editevent") 646 { 647 $query = $db->simple_select("events", "*", "eid='".intval($mybb->input['eid'])."'"); 648 $event = $db->fetch_array($query); 649 650 if(!is_numeric($event['eid'])) 651 { 652 error($lang->error_invalidevent); 653 } 654 655 $query = $db->simple_select("calendars", "*", "cid='{$event['cid']}'"); 656 $calendar = $db->fetch_array($query); 657 658 // Invalid calendar? 659 if(!$calendar['cid']) 660 { 661 error($lang->invalid_calendar); 662 } 663 664 // Do we have permission to view this calendar or post events? 665 $calendar_permissions = get_calendar_permissions($calendar['cid']); 666 if($calendar_permissions['canviewcalendar'] != 1 || $calendar_permissions['canaddevents'] != 1) 667 { 668 error_no_permission(); 669 } 670 671 if(($event['uid'] != $mybb->user['uid'] || $mybb->user['uid'] == 0) && $calendar_permissions['canmoderateevents'] != 1) 672 { 673 error_no_permission(); 674 } 675 676 $event['name'] = htmlspecialchars_uni($event['name']); 677 678 add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid'])); 679 add_breadcrumb($event['name'], get_event_link($event['eid'])); 680 add_breadcrumb($lang->nav_editevent); 681 682 $plugins->run_hooks("calendar_editevent_start"); 683 684 // If MyCode is on for this forum and the MyCode editor is enabled inthe Admin CP, draw the code buttons and smilie inserter. 685 if($mybb->settings['bbcodeinserter'] != 0 && (!$mybb->user['uid'] || $mybb->user['showcodebuttons'] != 0) && $calendar['allowmycode'] == 1) 686 { 687 $codebuttons = build_mycode_inserter(); 688 if($calendar['allowsmilies'] == 1) 689 { 690 $smilieinserter = build_clickable_smilies(); 691 } 692 } 693 694 // Previous selections 695 if($event_errors) 696 { 697 $name = htmlspecialchars_uni($mybb->input['name']); 698 $description = htmlspecialchars_uni($mybb->input['description']); 699 $single_day = $mybb->input['single_day']; 700 $single_month[$mybb->input['single_month']] = " selected=\"selected\""; 701 $single_year = $mybb->input['single_year']; 702 $start_day = $mybb->input['start_day']; 703 $start_month[$mybb->input['start_month']] = " selected=\"selected\""; 704 $start_year = $mybb->input['start_year']; 705 $start_time = htmlspecialchars_uni($mybb->input['start_time']); 706 $end_day = $mybb->input['end_day']; 707 $end_month[$mybb->input['end_month']] = " selected=\"selected\""; 708 $end_year = $mybb->input['end_year']; 709 $end_time = htmlspecialchars_uni($mybb->input['end_time']); 710 if($mybb->input['type'] == "single") 711 { 712 $type_single = "checked=\"checked\""; 713 $type = "single"; 714 } 715 else 716 { 717 $type_ranged = "checked=\"checked\""; 718 $type = "ranged"; 719 } 720 if($mybb->input['repeats']) 721 { 722 $repeats_sel[$mybb->input['repeats']] = " selected=\"selected\""; 723 } 724 $repeats_1_days = intval($mybb->input['repeats_1_days']); 725 $repeats_3_weeks = intval($mybb->input['repeats_3_weeks']); 726 if(is_array($mybb->input['repeats_3_days'])) 727 { 728 foreach($mybb->input['repeats_3_days'] as $day => $val) 729 { 730 if($val != 1) continue; 731 $day = intval($day); 732 $repeats_3_days[$day] = " checked=\"checked\""; 733 } 734 } 735 if($mybb->input['repeats_4_type'] == 1) 736 { 737 $repeats_4_type[1] = "checked=\"checked\""; 738 } 739 else 740 { 741 $repeats_4_type[2] = "checked=\"checked\""; 742 } 743 $repeats_4_day = intval($mybb->input['repeats_4_day']); 744 $repeats_4_months = intval($mybb->input['repeats_4_months']); 745 $repeats_4_occurance[$mybb->input['repeats_4_occurance']] = "selected=\"selected\""; 746 $repeats_4_weekday[$mybb->input['repeats_4_weekday']] = "selected=\"selected\""; 747 $repeats_4_months2 = intval($mybb->input['repeats_4_months2']); 748 if($mybb->input['repeats_5_type'] == 1) 749 { 750 $repeats_5_type[1] = "checked=\"checked\""; 751 } 752 else 753 { 754 $repeats_5_type[2] = "checked=\"checked\""; 755 } 756 $repeats_5_day = intval($mybb->input['repeats_5_day']); 757 $repeats_5_month[$mybb->input['repeats_5_month']] = "selected=\"selected\""; 758 $repeats_5_years = intval($mybb->input['repeats_5_years']); 759 $repeats_5_occurance[$mybb->input['repeats_5_occurance']] = "selected=\"selected\""; 760 $repeats_5_weekday[$mybb->input['repeats_5_weekday']] = "selected=\"selected\""; 761 $repeats_5_month2[$mybb->input['repeats_5_month2']] = "selected=\"selected\""; 762 $repeats_5_years2 = intval($mybb->input['repeats_5_years2']); 763 764 if($mybb->input['private'] == 1) 765 { 766 $privatecheck = " checked=\"checked\""; 767 } 768 769 if($mybb->input['ignoretimezone'] == 1) 770 { 771 $ignore_timezone = "checked=\"checked\""; 772 } 773 774 $timezone = $mybb->input['timezone']; 775 } 776 else 777 { 778 $mybb->input['calendar'] = $event['cid']; 779 $name = htmlspecialchars_uni($event['name']); 780 $description = htmlspecialchars_uni($event['description']); 781 if($event['private'] == 1) 782 { 783 $privatecheck = " checked=\"checked\""; 784 } 785 $start_date = explode("-", gmdate("j-n-Y-g:i A", $event['starttime']+$event['timezone']*3600)); 786 $single_day = $start_date[0]; 787 $single_month[$start_date[1]] = " selected=\"selected\""; 788 $single_year = $start_date[2]; 789 $start_day = $start_date[0]; 790 $start_month[$start_date[1]] = " selected=\"selected\""; 791 $start_year = $start_date[2]; 792 if($event['usingtime']) 793 { 794 $start_time = gmdate($mybb->settings['timeformat'], $event['starttime']+$event['timezone']*3600); 795 } 796 if($event['endtime']) 797 { 798 $end_date = explode("-", gmdate("j-n-Y-g:i A", $event['endtime']+$event['timezone']*3600)); 799 $end_day = $end_date[0]; 800 $end_month[$end_date[1]] = " selected=\"selected\""; 801 $end_year = $end_date[2]; 802 if($event['usingtime']) 803 { 804 $end_time = gmdate($mybb->settings['timeformat'], $event['endtime']+$event['timezone']*3600); 805 } 806 $type_ranged = "checked=\"checked\""; 807 $type = "ranged"; 808 $repeats = unserialize($event['repeats']); 809 if($repeats['repeats'] >= 0) 810 { 811 $repeats_sel[$repeats['repeats']] = " selected=\"selected\""; 812 switch($repeats['repeats']) 813 { 814 case 1: 815 $repeats_1_days = $repeats['days']; 816 $repeats_3_weeks = 1; 817 $repeats_4_type[1] = "checked=\"checked\""; 818 $repeats_4_day = 1; 819 $repeats_4_months = 1; 820 $repeats_4_months2 = 1; 821 $repeats_5_type[1] = "checked=\"checked\""; 822 $repeats_5_day = 1; 823 $repeats_5_years = $repeats_5_years2 = 1; 824 break; 825 case 3: 826 $repeats_1_days = 1; 827 $repeats_3_weeks = $repeats['weeks']; 828 if(is_array($repeats['days'])) 829 { 830 foreach($repeats['days'] as $weekday) 831 { 832 $repeats_3_days[$weekday] = " checked=\"checked\""; 833 } 834 } 835 $repeats_4_type[1] = "checked=\"checked\""; 836 $repeats_4_day = 1; 837 $repeats_4_months = 1; 838 $repeats_4_months2 = 1; 839 $repeats_5_type[1] = "checked=\"checked\""; 840 $repeats_5_day = 1; 841 $repeats_5_years = $repeats_5_years2 = 1; 842 break; 843 case 4: 844 $repeats_1_days = 1; 845 $repeats_3_weeks = 1; 846 if($repeats['day']) 847 { 848 $repeats_4_type[1] = "checked=\"checked\""; 849 $repeats_4_day = $repeats['day']; 850 $repeats_4_months = $repeats_4_months2 = $repeats['months']; 851 } 852 else 853 { 854 $repeats_4_type[2] = "checked=\"checked\""; 855 $repeats_4_day = 1; 856 $repeats_4_months2 = $repeats_4_months = $repeats['months']; 857 $repeats_4_occurance[$repeats['occurance']] = "selected=\"selected\""; 858 $repeats_4_weekday[$repeats['weekday']] = "selected=\"selected\""; 859 } 860 $repeats_5_type[1] = "checked=\"checked\""; 861 $repeats_5_day = 1; 862 $repeats_5_years = $repeats_5_years2 = 1; 863 break; 864 case 5: 865 $repeats_1_days = 1; 866 $repeats_3_weeks = 1; 867 $repeats_4_type[1] = "checked=\"checked\""; 868 $repeats_4_day = 1; 869 $repeats_4_months = 1; 870 $repeats_4_months2 = 1; 871 if($repeats['day']) 872 { 873 $repeats_5_type[1] = "checked=\"checked\""; 874 $repeats_5_day = $repeats['day']; 875 $repeats_5_month[$repeats['month']] = $repeats_5_month2[$repeats['month']] = "selected=\"selected\""; 876 $repeats_5_years = $repeats_5_years2 = $repeats['years']; 877 } 878 else 879 { 880 $repeats_5_type[2] = "checked=\"checked\""; 881 $repeats_5_occurance[$repeats['occurance']] = "selected=\"selected\""; 882 $repeats_5_weekday[$repeats['weekday']] = "selected=\"selected\""; 883 $repeats_5_month[$repeats['month']] = $repeats_5_month2[$repeats['month']] = "selected=\"selected\""; 884 $repeats_5_years = $repeats_5_years2 = $repeats['years']; 885 } 886 break; 887 } 888 } 889 if($event['ignoretimezone']) 890 { 891 $timezone = 0; 892 $ignore_timezone = "checked=\"checked\""; 893 } 894 else 895 { 896 $timezone = $event['timezone']; 897 } 898 } 899 else 900 { 901 $type_single = "checked=\"checked\""; 902 $type = "single"; 903 // set some defaults if the user wants to make a ranged event 904 $end_day = $start_day; 905 $end_month = $start_month; 906 $end_year = $start_year; 907 } 908 } 909 910 // Construct option list for years 911 for($i = my_date('Y'); $i < (my_date('Y') + 5); ++$i) 912 { 913 if($i == $single_year) 914 { 915 $single_years .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 916 } 917 else 918 { 919 $single_years .= "<option value=\"{$i}\">{$i}</option>\n"; 920 } 921 if($i == $start_year) 922 { 923 $start_years .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 924 } 925 else 926 { 927 $start_years .= "<option value=\"{$i}\">{$i}</option>\n"; 928 } 929 if($i == $end_year) 930 { 931 $end_years .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 932 } 933 else 934 { 935 $end_years .= "<option value=\"{$i}\">{$i}</option>\n"; 936 } 937 } 938 939 // Construct option list for days 940 for($i = 1; $i <= 31; ++$i) 941 { 942 if($i == $single_day) 943 { 944 $single_days .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 945 } 946 else 947 { 948 $single_days .= "<option value=\"{$i}\">{$i}</option>\n"; 949 } 950 if($i == $start_day) 951 { 952 $start_days .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 953 } 954 else 955 { 956 $start_days .= "<option value=\"{$i}\">{$i}</option>\n"; 957 } 958 if($i == $end_day) 959 { 960 $end_days .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>\n"; 961 } 962 else 963 { 964 $end_days .= "<option value=\"{$i}\">{$i}</option>\n"; 965 } 966 } 967 968 $timezones = build_timezone_select("timezone", $timezone); 969 970 $plugins->run_hooks("calendar_editevent_end"); 971 972 eval("\$editevent = \"".$templates->get("calendar_editevent")."\";"); 973 output_page($editevent); 974 } 975 976 // Move an event to another calendar 977 if($mybb->input['action'] == "move") 978 { 979 $query = $db->simple_select("events", "*", "eid='".intval($mybb->input['eid'])."'"); 980 $event = $db->fetch_array($query); 981 982 if(!is_numeric($event['eid'])) 983 { 984 error($lang->error_invalidevent); 985 } 986 987 $query = $db->simple_select("calendars", "*", "cid='{$event['cid']}'"); 988 $calendar = $db->fetch_array($query); 989 990 // Invalid calendar? 991 if(!$calendar['cid']) 992 { 993 error($lang->invalid_calendar); 994 } 995 996 // Do we have permission to view this calendar or post events? 997 $calendar_permissions = get_calendar_permissions(); 998 if($calendar_permissions[$calendar['cid']]['canviewcalendar'] != 1) 999 { 1000 error_no_permission(); 1001 } 1002 1003 if($calendar_permissions[$calendar['cid']]['canmoderateevents'] != 1) 1004 { 1005 error_no_permission(); 1006 } 1007 1008 $event['name'] = htmlspecialchars_uni($event['name']); 1009 1010 add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid'])); 1011 add_breadcrumb($event['name'], get_event_link($event['eid'])); 1012 add_breadcrumb($lang->nav_move_event); 1013 1014 $plugins->run_hooks("calendar_move_start"); 1015 1016 // Build calendar select 1017 $query = $db->simple_select("calendars", "*", "", array("order_by" => "name", "order_dir" => "asc")); 1018 while($calendar_option = $db->fetch_array($query)) 1019 { 1020 if($calendar_permissions[$calendar['cid']]['canviewcalendar'] == 1) 1021 { 1022 $calendar_option['name'] = htmlspecialchars_uni($calendar_option['name']); 1023 $calendar_select .= "<option value=\"{$calendar_option['cid']}\">{$calendar_option['name']}</option>\n"; 1024 } 1025 } 1026 1027 $plugins->run_hooks("calendar_move_end"); 1028 1029 eval("\$moveevent = \"".$templates->get("calendar_move")."\";"); 1030 output_page($moveevent); 1031 } 1032 1033 // Actually move the event 1034 if($mybb->input['action'] == "do_move" && $mybb->request_method == "post") 1035 { 1036 // Verify incoming POST request 1037 verify_post_check($mybb->input['my_post_key']); 1038 1039 $query = $db->simple_select("events", "*", "eid='".intval($mybb->input['eid'])."'"); 1040 $event = $db->fetch_array($query); 1041 1042 if(!is_numeric($event['eid'])) 1043 { 1044 error($lang->error_invalidevent); 1045 } 1046 1047 $query = $db->simple_select("calendars", "*", "cid='{$event['cid']}'"); 1048 $calendar = $db->fetch_array($query); 1049 1050 // Invalid calendar? 1051 if(!$calendar['cid']) 1052 { 1053 error($lang->invalid_calendar); 1054 } 1055 1056 // Do we have permission to view this calendar? 1057 $calendar_permissions = get_calendar_permissions(); 1058 if($calendar_permissions[$calendar['cid']]['canviewcalendar'] != 1) 1059 { 1060 error_no_permission(); 1061 } 1062 1063 if($calendar_permissions[$calendar['cid']]['canmoderateevents'] != 1) 1064 { 1065 error_no_permission(); 1066 } 1067 1068 1069 $query = $db->simple_select("calendars", "*", "cid='".intval($mybb->input['new_calendar'])."'"); 1070 $new_calendar = $db->fetch_array($query); 1071 1072 if(!$new_calendar['cid']) 1073 { 1074 error($lang->invalid_calendar); 1075 } 1076 1077 if($calendar_permissions[$mybb->input['new_calendar']]['canviewcalendar'] != 1) 1078 { 1079 error_no_permission(); 1080 } 1081 1082 $plugins->run_hooks("calendar_do_move_start"); 1083 1084 $updated_event = array( 1085 "cid" => $new_calendar['cid'] 1086 ); 1087 $db->update_query("events", $updated_event, "eid='{$event['eid']}'"); 1088 1089 $plugins->run_hooks("calendar_do_move_end"); 1090 1091 redirect(get_event_link($event['eid']), $lang->redirect_eventmoved); 1092 } 1093 1094 // Approve an event 1095 if($mybb->input['action'] == "approve") 1096 { 1097 // Verify incoming POST request 1098 verify_post_check($mybb->input['my_post_key']); 1099 1100 $query = $db->simple_select("events", "*", "eid='".intval($mybb->input['eid'])."'"); 1101 $event = $db->fetch_array($query); 1102 1103 if(!is_numeric($event['eid'])) 1104 { 1105 error($lang->error_invalidevent); 1106 } 1107 1108 $query = $db->simple_select("calendars", "*", "cid='{$event['cid']}'"); 1109 $calendar = $db->fetch_array($query); 1110 1111 // Invalid calendar? 1112 if(!$calendar['cid']) 1113 { 1114 error($lang->invalid_calendar); 1115 } 1116 1117 // Do we have permission to view this calendar? 1118 $calendar_permissions = get_calendar_permissions($calendar['cid']); 1119 if($calendar_permissions['canviewcalendar'] != 1) 1120 { 1121 error_no_permission(); 1122 } 1123 1124 if($calendar_permissions['canmoderateevents'] != 1) 1125 { 1126 error_no_permission(); 1127 } 1128 1129 $plugins->run_hooks("calendar_approve_start"); 1130 1131 $updated_event = array( 1132 "visible" => 1 1133 ); 1134 $db->update_query("events", $updated_event, "eid='{$event['eid']}'"); 1135 1136 $plugins->run_hooks("calendar_approve_end"); 1137 1138 redirect(get_event_link($event['eid']), $lang->redirect_eventapproved); 1139 } 1140 1141 // Unapprove an event 1142 if($mybb->input['action'] == "unapprove") 1143 { 1144 // Verify incoming POST request 1145 verify_post_check($mybb->input['my_post_key']); 1146 1147 $query = $db->simple_select("events", "*", "eid='".intval($mybb->input['eid'])."'"); 1148 $event = $db->fetch_array($query); 1149 1150 if(!is_numeric($event['eid'])) 1151 { 1152 error($lang->error_invalidevent); 1153 } 1154 1155 $query = $db->simple_select("calendars", "*", "cid='{$event['cid']}'"); 1156 $calendar = $db->fetch_array($query); 1157 1158 // Invalid calendar? 1159 if(!$calendar['cid']) 1160 { 1161 error($lang->invalid_calendar); 1162 } 1163 1164 // Do we have permission to view this calendar? 1165 $calendar_permissions = get_calendar_permissions($calendar['cid']); 1166 if($calendar_permissions['canviewcalendar'] != 1) 1167 { 1168 error_no_permission(); 1169 } 1170 1171 if($calendar_permissions['canmoderateevents'] != 1) 1172 { 1173 error_no_permission(); 1174 } 1175 1176 $plugins->run_hooks("calendar_unapprove_start"); 1177 1178 $updated_event = array( 1179 "visible" => 0 1180 ); 1181 $db->update_query("events", $updated_event, "eid='{$event['eid']}'"); 1182 1183 $plugins->run_hooks("calendar_unapprove_end"); 1184 1185 redirect(get_event_link($event['eid']), $lang->redirect_eventunapproved); 1186 } 1187 1188 // Showing specific event 1189 if($mybb->input['action'] == "event") 1190 { 1191 $query = $db->query(" 1192 SELECT u.*, e.* 1193 FROM ".TABLE_PREFIX."events e 1194 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=e.uid) 1195 WHERE e.eid='".intval($mybb->input['eid'])."' 1196 "); 1197 $event = $db->fetch_array($query); 1198 1199 if(!is_numeric($event['eid']) || ($event['private'] == 1 && $event['uid'] != $mybb->user['uid'])) 1200 { 1201 error($lang->error_invalidevent); 1202 } 1203 1204 $query = $db->simple_select("calendars", "*", "cid='{$event['cid']}'"); 1205 $calendar = $db->fetch_array($query); 1206 1207 // Invalid calendar? 1208 if(!$calendar['cid']) 1209 { 1210 error($lang->invalid_calendar); 1211 } 1212 1213 // Do we have permission to view this calendar? 1214 $calendar_permissions = get_calendar_permissions($calendar['cid']); 1215 if($calendar_permissions['canviewcalendar'] != 1 || ($calendar_permissions['canmoderateevents'] != 1 && $event['visible'] == 0)) 1216 { 1217 error_no_permission(); 1218 } 1219 1220 $event['name'] = htmlspecialchars_uni($event['name']); 1221 1222 add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid'])); 1223 add_breadcrumb($event['name'], get_event_link($event['eid'])); 1224 1225 $plugins->run_hooks("calendar_event_start"); 1226 1227 $event_parser_options = array( 1228 "allow_html" => $calendar['allowhtml'], 1229 "allow_mycode" => $calendar['allowmycode'], 1230 "allow_smilies" => $calendar['allowsmilies'], 1231 "allow_imgcode" => $calendar['allowimgcode'], 1232 "allow_videocode" => $calendar['allowvideocode'] 1233 ); 1234 1235 $event['description'] = $parser->parse_message($event['description'], $event_parser_options); 1236 1237 // Get the usergroup 1238 if($event['username']) 1239 { 1240 if(!$event['displaygroup']) 1241 { 1242 $event['displaygroup'] = $event['usergroup']; 1243 } 1244 $user_usergroup = $groupscache[$event['displaygroup']]; 1245 } 1246 else 1247 { 1248 $user_usergroup = $groupscache[1]; 1249 } 1250 1251 if(!is_array($titles_cache)) 1252 { 1253 // Get user titles (i guess we should improve this, maybe in version3. 1254 $query = $db->simple_select("usertitles", "*", "", array('order_by' => 'posts', 'order_dir' => 'DESC')); 1255 while($usertitle = $db->fetch_array($query)) 1256 { 1257 $titles_cache[$usertitle['posts']] = $usertitle; 1258 } 1259 unset($usertitle); 1260 } 1261 1262 // Event made by registered user 1263 if($event['uid'] > 0 && $event['username']) 1264 { 1265 $event['profilelink'] = build_profile_link(format_name($event['username'], $event['usergroup'], $event['displaygroup']), $event['uid']); 1266 1267 if(trim($event['usertitle']) != "") 1268 { 1269 $hascustomtitle = 1; 1270 } 1271 1272 if($user_usergroup['usertitle'] != "" && !$hascustomtitle) 1273 { 1274 $event['usertitle'] = $user_usergroup['usertitle']; 1275 } 1276 elseif(is_array($titles_cache) && !$user_usergroup['usertitle']) 1277 { 1278 reset($titles_cache); 1279 foreach($titles_cache as $key => $title) 1280 { 1281 if($event['postnum'] >= $key) 1282 { 1283 if(!$hascustomtitle) 1284 { 1285 $event['usertitle'] = $title['title']; 1286 } 1287 $event['stars'] = $title['stars']; 1288 $event['starimage'] = $title['starimage']; 1289 break; 1290 } 1291 } 1292 } 1293 1294 if($user_usergroup['stars']) 1295 { 1296 $event['stars'] = $user_usergroup['stars']; 1297 } 1298 1299 if(!$event['starimage']) 1300 { 1301 $event['starimage'] = $user_usergroup['starimage']; 1302 } 1303 $event['starimage'] = str_replace("{theme}", $theme['imgdir'], $event['starimage']); 1304 1305 for($i = 0; $i < $post['stars']; ++$i) 1306 { 1307 $event['userstars'] .= "<img src=\"".$event['starimage']."\" border=\"0\" alt=\"*\" />"; 1308 } 1309 1310 if($event['userstars'] && $event['starimage'] && $event['stars']) 1311 { 1312 $event['userstars'] .= "<br />"; 1313 } 1314 } 1315 // Created by a guest or an unknown user 1316 else 1317 { 1318 if(!$event['username']) 1319 { 1320 $event['username'] = $lang->guest; 1321 } 1322 1323 $event['username'] = $event['username']; 1324 $event['profilelink'] = format_name($event['username'], 1); 1325 1326 if($user_usergroup['usertitle']) 1327 { 1328 $event['usertitle'] = $user_usergroup['usertitle']; 1329 } 1330 else 1331 { 1332 $event['usertitle'] = $lang->guest; 1333 } 1334 } 1335 1336 if($event['ignoretimezone'] == 0) 1337 { 1338 $offset = $event['timezone']; 1339 } 1340 else 1341 { 1342 $offset = $mybb->user['timezone']; 1343 } 1344 1345 $event['starttime_user'] = $event['starttime']+$offset*3600; 1346 1347 // Events over more than one day 1348 $time_period = ''; 1349 if($event['endtime'] > 0 && $event['endtime'] != $event['starttime']) 1350 { 1351 $event['endtime_user'] = $event['endtime']+$offset*3600; 1352 $start_day = gmmktime(0, 0, 0, gmdate("n", $event['starttime_user']), gmdate("j", $event['starttime_user']), gmdate("Y", $event['starttime_user'])); 1353 $end_day = gmmktime(0, 0, 0, gmdate("n", $event['endtime_user']), gmdate("j", $event['endtime_user']), gmdate("Y", $event['endtime_user'])); 1354 $start_time = gmdate("Hi", $event['starttime_user']); 1355 $end_time = gmdate("Hi", $event['endtime_user']); 1356 1357 $event['repeats'] = unserialize($event['repeats']); 1358 1359 // Event only runs over one day 1360 if($start_day == $end_day && $event['repeats']['repeats'] == 0) 1361 { 1362 $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']); 1363 // Event runs all day 1364 if($start_time != 0000 && $end_time != 2359) 1365 { 1366 $time_period .= $lang->comma.gmdate($mybb->settings['timeformat'], $event['starttime_user'])." - ".gmdate($mybb->settings['timeformat'], $event['endtime_user']); 1367 } 1368 else 1369 { 1370 $time_period .= $lang->comma.$lang->all_day; 1371 } 1372 } 1373 else 1374 { 1375 $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']).", ".gmdate($mybb->settings['timeformat'], $event['starttime_user']); 1376 $time_period .= " - "; 1377 $time_period .= gmdate($mybb->settings['dateformat'], $event['endtime_user']).", ".gmdate($mybb->settings['timeformat'], $event['endtime_user']); 1378 } 1379 } 1380 else 1381 { 1382 $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']); 1383 } 1384 1385 $repeats = fetch_friendly_repetition($event); 1386 if($repeats) 1387 { 1388 $repeats = "<span class=\"smalltext\"><strong>{$lang->repeats}</strong><br />{$repeats}</span>"; 1389 } 1390 1391 if($calendar_permissions['canmoderateevents'] == 1 || ($mybb->user['uid'] > 0 && $mybb->user['uid'] == $event['uid'])) 1392 { 1393 eval("\$edit_event = \"".$templates->get("calendar_event_editbutton")."\";"); 1394 if($calendar_permissions['canmoderateevents'] == 1) 1395 { 1396 if($event['visible'] == 1) 1397 { 1398 $approve = $lang->unapprove_event; 1399 $approve_value = "unapprove"; 1400 } 1401 else 1402 { 1403 $approve = $lang->approve_event; 1404 $approve_value = "approve"; 1405 } 1406 eval("\$moderator_options = \"".$templates->get("calendar_event_modoptions")."\";"); 1407 } 1408 1409 if($event['visible'] == 0) 1410 { 1411 $event_class = " trow_shaded"; 1412 } 1413 } 1414 1415 $month = my_date("n"); 1416 1417 $yearsel = ''; 1418 for($i = my_date("Y"); $i < (my_date("Y") + 5); ++$i) 1419 { 1420 $yearsel .= "<option value=\"$i\">$i</option>\n"; 1421 } 1422 1423 if($mybb->usergroup['canaddevents'] == 1) 1424 { 1425 eval("\$addevent = \"".$templates->get("calendar_addeventlink")."\";"); 1426 } 1427 1428 // Now output the page 1429 $plugins->run_hooks("calendar_event_end"); 1430 eval("\$event = \"".$templates->get("calendar_event")."\";"); 1431 output_page($event); 1432 } 1433 1434 // View all events on a specific day. 1435 if($mybb->input['action'] == "dayview") 1436 { 1437 // Showing a particular calendar 1438 if($mybb->input['calendar']) 1439 { 1440 $query = $db->simple_select("calendars", "*", "cid='".intval($mybb->input['calendar'])."'"); 1441 $calendar = $db->fetch_array($query); 1442 } 1443 // Showing the default calendar 1444 else 1445 { 1446 $query = $db->simple_select("calendars", "*", "disporder='1'"); 1447 $calendar = $db->fetch_array($query); 1448 } 1449 1450 // Invalid calendar? 1451 if(!$calendar['cid']) 1452 { 1453 error($lang->invalid_calendar); 1454 } 1455 1456 // Do we have permission to view this calendar? 1457 $calendar_permissions = get_calendar_permissions($calendar['cid']); 1458 if($calendar_permissions['canviewcalendar'] != 1) 1459 { 1460 error_no_permission(); 1461 } 1462 1463 // Incoming year? 1464 if($mybb->input['year'] && $mybb->input['year'] <= my_date("Y")+5) 1465 { 1466 $year = intval($mybb->input['year']); 1467 } 1468 else 1469 { 1470 $year = my_date("Y"); 1471 } 1472 1473 // Then the month 1474 if($mybb->input['month'] >=1 && $mybb->input['month'] <= 12) 1475 { 1476 $month = intval($mybb->input['month']); 1477 } 1478 else 1479 { 1480 $month = my_date("n"); 1481 } 1482 1483 // And day? 1484 if($mybb->input['day'] && $mybb->input['day'] <= gmdate("t", gmmktime(0, 0, 0, $month, 1, $year))) 1485 { 1486 $day = intval($mybb->input['day']); 1487 } 1488 else 1489 { 1490 $day = my_date("j"); 1491 } 1492 1493 add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid'])); 1494 add_breadcrumb("$day $monthnames[$month] $year", get_calendar_link($calendar['cid'], $year, $month, $day)); 1495 1496 $plugins->run_hooks("calendar_dayview_start"); 1497 1498 // Load Birthdays for this day 1499 if($calendar['showbirthdays']) 1500 { 1501 $birthdays = get_birthdays($month, $day); 1502 $bdayhidden = 0; 1503 if(is_array($birthdays)) 1504 { 1505 foreach($birthdays as $birthday) 1506 { 1507 if($birthday['birthdayprivacy'] == 'all') 1508 { 1509 $bday = explode("-", $birthday['birthday']); 1510 if($bday[2] && $bday[2] < $year) 1511 { 1512 $age = $year - $bday[2]; 1513 $age = " (".$lang->sprintf($lang->years_old, $age).")"; 1514 } 1515 else 1516 { 1517 $age = ''; 1518 } 1519 1520 $birthday['username'] = format_name($birthday['username'], $birthday['usergroup'], $birthday['displaygroup']); 1521 $birthday['profilelink'] = build_profile_link($birthday['username'], $birthday['uid']); 1522 eval("\$birthday_list .= \"".$templates->get("calendar_dayview_birthdays_bday", 1, 0)."\";"); 1523 $comma = $lang->comma; 1524 } 1525 else 1526 { 1527 ++$bdayhidden; 1528 } 1529 } 1530 } 1531 if($bdayhidden > 0) 1532 { 1533 if($birthday_list) 1534 { 1535 $birthday_list .= " - "; 1536 } 1537 $birthday_list .= "{$bdayhidden} {$lang->birthdayhidden}"; 1538 } 1539 if($birthday_list) 1540 { 1541 $bdaydate = my_date($mybb->settings['dateformat'], gmmktime(0, 0, 0, $month, $day, $year), 0, 0); 1542 $lang->birthdays_on_day = $lang->sprintf($lang->birthdays_on_day, $bdaydate); 1543 eval("\$birthdays = \"".$templates->get("calendar_dayview_birthdays", 1, 0)."\";"); 1544 } 1545 } 1546 1547 // So now we fetch events for this month 1548 $start_timestamp = gmmktime(0, 0, 0, $month, $day, $year); 1549 $end_timestamp = gmmktime(23, 59, 59, $month, $day, $year); 1550 1551 $events_cache = get_events($calendar, $start_timestamp, $end_timestamp, $calendar_permissions['canmoderateevents']); 1552 1553 if(is_array($events_cache["$day-$month-$year"])) 1554 { 1555 foreach($events_cache["$day-$month-$year"] as $event) 1556 { 1557 $event['name'] = htmlspecialchars_uni($event['name']); 1558 1559 $event_parser_options = array( 1560 "allow_html" => $calendar['allowhtml'], 1561 "allow_mycode" => $calendar['allowmycode'], 1562 "allow_smilies" => $calendar['allowsmilies'], 1563 "allow_imgcode" => $calendar['allowimgcode'], 1564 "allow_videocode" => $calendar['allowvideocode'] 1565 ); 1566 1567 $event['description'] = $parser->parse_message($event['description'], $event_parser_options); 1568 1569 // Get the usergroup 1570 if($event['username']) 1571 { 1572 if(!$event['displaygroup']) 1573 { 1574 $event['displaygroup'] = $event['usergroup']; 1575 } 1576 $user_usergroup = $groupscache[$event['displaygroup']]; 1577 } 1578 else 1579 { 1580 $user_usergroup = $groupscache[1]; 1581 } 1582 1583 if(!is_array($titles_cache)) 1584 { 1585 // Get user titles (i guess we should improve this, maybe in version3. 1586 $query = $db->simple_select("usertitles", "*", "", array('order_by' => 'posts', 'order_dir' => 'DESC')); 1587 while($usertitle = $db->fetch_array($query)) 1588 { 1589 $titles_cache[$usertitle['posts']] = $usertitle; 1590 } 1591 unset($usertitle); 1592 } 1593 1594 // Event made by registered user 1595 if($event['uid'] > 0 && $event['username']) 1596 { 1597 $event['profilelink'] = build_profile_link(format_name($event['username'], $event['usergroup'], $event['displaygroup']), $event['uid']); 1598 1599 if(trim($event['usertitle']) != "") 1600 { 1601 $hascustomtitle = 1; 1602 } 1603 1604 if($user_usergroup['usertitle'] != "" && !$hascustomtitle) 1605 { 1606 $event['usertitle'] = $user_usergroup['usertitle']; 1607 } 1608 elseif(is_array($titles_cache) && !$user_usergroup['usertitle']) 1609 { 1610 reset($titles_cache); 1611 foreach($titles_cache as $key => $title) 1612 { 1613 if($event['postnum'] >= $key) 1614 { 1615 if(!$hascustomtitle) 1616 { 1617 $event['usertitle'] = $title['title']; 1618 } 1619 $event['stars'] = $title['stars']; 1620 $event['starimage'] = $title['starimage']; 1621 break; 1622 } 1623 } 1624 } 1625 1626 if($user_usergroup['stars']) 1627 { 1628 $event['stars'] = $user_usergroup['stars']; 1629 } 1630 1631 if(!$event['starimage']) 1632 { 1633 $event['starimage'] = $user_usergroup['starimage']; 1634 } 1635 1636 for($i = 0; $i < $post['stars']; ++$i) 1637 { 1638 $event['userstars'] .= "<img src=\"".$event['starimage']."\" border=\"0\" alt=\"*\" />"; 1639 } 1640 1641 if($event['userstars'] && $event['starimage'] && $event['stars']) 1642 { 1643 $event['userstars'] .= "<br />"; 1644 } 1645 } 1646 // Created by a guest or an unknown user 1647 else 1648 { 1649 if(!$event['username']) 1650 { 1651 $event['username'] = $lang->guest; 1652 } 1653 1654 $event['username'] = $event['username']; 1655 $event['profilelink'] = format_name($event['username'], 1); 1656 1657 if($user_usergroup['usertitle']) 1658 { 1659 $event['usertitle'] = $user_usergroup['usertitle']; 1660 } 1661 else 1662 { 1663 $event['usertitle'] = $lang->guest; 1664 } 1665 } 1666 1667 if($event['ignoretimezone'] == 0) 1668 { 1669 $offset = $event['timezone']; 1670 } 1671 else 1672 { 1673 $offset = $mybb->user['timezone']; 1674 } 1675 1676 $event['starttime_user'] = $event['starttime']+$offset*3600; 1677 1678 // Events over more than one day 1679 $time_period = ''; 1680 if($event['endtime'] > 0 && $event['endtime'] != $event['starttime']) 1681 { 1682 $event['endtime_user'] = $event['endtime']+$offset*3600; 1683 $start_day = gmmktime(0, 0, 0, gmdate("n", $event['starttime_user']), gmdate("j", $event['starttime_user']), gmdate("Y", $event['starttime_user'])); 1684 $end_day = gmmktime(0, 0, 0, gmdate("n", $event['endtime_user']), gmdate("j", $event['endtime_user']), gmdate("Y", $event['endtime_user'])); 1685 $start_time = gmdate("Hi", $event['starttime_user']); 1686 $end_time = gmdate("Hi", $event['endtime_user']); 1687 1688 // Event only runs over one day 1689 if($start_day == $end_day && $event['repeats']['repeats'] == 0) 1690 { 1691 $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']); 1692 // Event runs all day 1693 if($start_time != 0000 && $end_time != 2359) 1694 { 1695 $time_period .= $lang->comma.gmdate($mybb->settings['timeformat'], $event['starttime_user'])." - ".gmdate($mybb->settings['timeformat'], $event['endtime_user']); 1696 } 1697 else 1698 { 1699 $time_period .= $lang->comma.$lang->all_day; 1700 } 1701 } 1702 else 1703 { 1704 $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']).", ".gmdate($mybb->settings['timeformat'], $event['starttime_user']); 1705 $time_period .= " - "; 1706 $time_period .= gmdate($mybb->settings['dateformat'], $event['endtime_user']).", ".gmdate($mybb->settings['timeformat'], $event['endtime_user']); 1707 } 1708 } 1709 else 1710 { 1711 $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']); 1712 } 1713 1714 $repeats = fetch_friendly_repetition($event); 1715 if($repeats) 1716 { 1717 $repeats = "<span class=\"smalltext\"><strong>{$lang->repeats}</strong><br />{$repeats}</span>"; 1718 } 1719 1720 $edit_event = $moderator_options = $event_class = ""; 1721 if($calendar_permissions['canmoderateevents'] == 1 || ($mybb->user['uid'] > 0 && $mybb->user['uid'] == $event['uid'])) 1722 { 1723 eval("\$edit_event = \"".$templates->get("calendar_event_editbutton")."\";"); 1724 if($calendar_permissions['canmoderateevents'] == 1) 1725 { 1726 if($event['visible'] == 1) 1727 { 1728 $approve = $lang->unapprove_event; 1729 $approve_value = "unapprove"; 1730 } 1731 else 1732 { 1733 $approve = $lang->approve_event; 1734 $approve_value = "approve"; 1735 } 1736 eval("\$moderator_options = \"".$templates->get("calendar_event_modoptions")."\";"); 1737 } 1738 if($event['visible'] == 0) 1739 { 1740 $event_class = " trow_shaded"; 1741 } 1742 } 1743 eval("\$events .= \"".$templates->get("calendar_dayview_event")."\";"); 1744 } 1745 } 1746 1747 $yearsel = ''; 1748 for($i = my_date("Y"); $i < (my_date("Y") + 5); ++$i) 1749 { 1750 $yearsel .= "<option value=\"$i\">$i</option>\n"; 1751 } 1752 1753 if($mybb->usergroup['canaddevents'] == 1) 1754 { 1755 eval("\$addevent = \"".$templates->get("calendar_addeventlink")."\";"); 1756 } 1757 1758 if(!$events) 1759 { 1760 $lang->no_events = $lang->sprintf($lang->no_events, $calendar['cid'], $day, $month, $year); 1761 eval("\$events = \"".$templates->get("calendar_dayview_noevents")."\";"); 1762 } 1763 1764 // Now output the page 1765 $plugins->run_hooks("calendar_dayview_end"); 1766 1767 eval("\$day_view = \"".$templates->get("calendar_dayview")."\";"); 1768 output_page($day_view); 1769 } 1770 1771 // View all events for a specific week 1772 if($mybb->input['action'] == "weekview") 1773 { 1774 // Showing a particular calendar 1775 if($mybb->input['calendar']) 1776 { 1777 $query = $db->simple_select("calendars", "*", "cid='".intval($mybb->input['calendar'])."'"); 1778 $calendar = $db->fetch_array($query); 1779 } 1780 // Showing the default calendar 1781 else 1782 { 1783 $query = $db->simple_select("calendars", "*", "disporder='1'"); 1784 $calendar = $db->fetch_array($query); 1785 } 1786 1787 // Invalid calendar? 1788 if(!$calendar['cid']) 1789 { 1790 error($lang->invalid_calendar); 1791 } 1792 1793 // Do we have permission to view this calendar? 1794 $calendar_permissions = get_calendar_permissions($calendar['cid']); 1795 if($calendar_permissions['canviewcalendar'] != 1) 1796 { 1797 error_no_permission(); 1798 } 1799 1800 $weekdays = fetch_weekday_structure($calendar['startofweek']); 1801 1802 $yearsel = ''; 1803 for($i = my_date("Y"); $i < (my_date("Y") + 5); ++$i) 1804 { 1805 $yearsel .= "<option value=\"$i\">$i</option>\n"; 1806 } 1807 1808 // No incoming week, show THIS week 1809 if(!$mybb->input['week']) 1810 { 1811 list($day, $month, $year) = explode("-", my_date("j-n-Y")); 1812 $php_weekday = gmdate("w", gmmktime(0, 0, 0, $month, $day, $year)); 1813 $my_weekday = array_search($php_weekday, $weekdays); 1814 // So now we have the start day of this week to show 1815 $start_day = $day-$my_weekday; 1816 $mybb->input['week'] = gmmktime(0, 0, 0, $month, $start_day, $year); 1817 } 1818 else 1819 { 1820 $mybb->input['week'] = (int)str_replace("n", "-", $mybb->input['week']); 1821 } 1822 1823 // This is where we've come from and where we're headed 1824 $week_from = explode("-", gmdate("j-n-Y", $mybb->input['week'])); 1825 $week_from_one = $week_from[1]; 1826 $friendly_week_from = gmdate($mybb->settings['dateformat'], $mybb->input['week']); 1827 $week_to_stamp = gmmktime(0, 0, 0, $week_from[1], $week_from[0]+6, $week_from[2]); 1828 $week_to = explode("-", gmdate("j-n-Y-t", $week_to_stamp)); 1829 $friendly_week_to = gmdate($mybb->settings['dateformat'], $week_to_stamp); 1830 1831 add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid'])); 1832 add_breadcrumb("{$monthnames[$week_from[1]]} {$week_from[2]}", get_calendar_link($calendar['cid'], $week_from[2], $week_from[1])); 1833 add_breadcrumb($lang->weekly_overview); 1834 1835 // Establish if we have a month ending in this week 1836 if($week_from[1] != $week_to[1]) 1837 { 1838 $different_months = true; 1839 $week_months = array(array($week_from[1], $week_from[2]), array($week_to[1], $week_to[2])); 1840 $bday_months = array($week_from[1], $week_to[1]); 1841 } 1842 else 1843 { 1844 $week_months = array(array($week_from[1], $week_from[2])); 1845 $bday_months = array($week_from[1]); 1846 } 1847 1848 // Load Birthdays for this month 1849 if($calendar['showbirthdays'] == 1) 1850 { 1851 $birthdays = get_birthdays($bday_months); 1852 } 1853 1854 // We load events for the entire month date range - for our mini calendars too 1855 $events_from = gmmktime(0, 0, 0, $week_from[1], 1, $week_from[2]); 1856 $events_to = gmmktime(0, 0, 0, $week_to[1], $week_to[3], $week_to[2]); 1857 1858 $events_cache = get_events($calendar, $events_from, $events_to, $calendar_permissions['canmoderateevents']); 1859 1860 $today = my_date("dnY"); 1861 1862 $next_week = $mybb->input['week'] + 604800; 1863 $next_link = get_calendar_week_link($calendar['cid'], $next_week); 1864 $prev_week = $mybb->input['week'] - 604800; 1865 $prev_link = get_calendar_week_link($calendar['cid'], $prev_week); 1866 1867 $weekday_date = $mybb->input['week']; 1868 1869 while($weekday_date <= $week_to_stamp) 1870 { 1871 $weekday = gmdate("w", $weekday_date); 1872 $weekday_name = fetch_weekday_name($weekday); 1873 $weekday_month = gmdate("n", $weekday_date); 1874 $weekday_year = gmdate("Y", $weekday_date); 1875 $weekday_day = gmdate("j", $weekday_date); 1876 1877 // Special shading for today 1878 $day_shaded = ''; 1879 if(gmdate("dnY", $weekday_date) == $today) 1880 { 1881 $day_shaded = ' trow_shaded'; 1882 } 1883 1884 // Any events on this specific day? 1885 if(is_array($events_cache) && array_key_exists("{$weekday_day}-{$weekday_month}-{$weekday_year}", $events_cache)) 1886 { 1887 foreach($events_cache["$weekday_day-$weekday_month-$weekday_year"] as $event) 1888 { 1889 $event['eventlink'] = get_event_link($event['eid']); 1890 $event['name'] = htmlspecialchars_uni($event['name']); 1891 $event['fullname'] = $event['name']; 1892 if(my_strlen($event['name']) > 50) 1893 { 1894 $event['name'] = my_substr($event['name'], 0, 50) . "..."; 1895 } 1896 // Events over more than one day 1897 $time_period = ''; 1898 if($event['endtime'] > 0 && $event['endtime'] != $event['starttime']) 1899 { 1900 $start_day = gmmktime(0, 0, 0, gmdate("n", $event['starttime_user']), gmdate("j", $event['starttime_user']), gmdate("Y", $event['starttime_user'])); 1901 $end_day = gmmktime(0, 0, 0, gmdate("n", $event['endtime_user']), gmdate("j", $event['endtime_user']), gmdate("Y", $event['endtime_user'])); 1902 $start_time = gmdate("Hi", $event['starttime_user']); 1903 $end_time = gmdate("Hi", $event['endtime_user']); 1904 // Event only runs over one day 1905 if($start_day == $end_day || $event['repeats'] > 0) 1906 { 1907 // Event runs all day 1908 if($start_time == 0000 && $end_time == 2359) 1909 { 1910 $time_period = $lang->all_day; 1911 } 1912 else 1913 { 1914 $time_period = gmdate($mybb->settings['timeformat'], $event['starttime_user'])." - ".gmdate($mybb->settings['timeformat'], $event['endtime_user']); 1915 } 1916 } 1917 // Event starts on this day 1918 else if($start_day == $weekday_date) 1919 { 1920 // Event runs all day 1921 if($start_time == 0000) 1922 { 1923 $time_period = $lang->all_day; 1924 } 1925 else 1926 { 1927 $time_period = $lang->starts.gmdate($mybb->settings['timeformat'], $event['starttime_user']); 1928 } 1929 } 1930 // Event finishes on this day 1931 else if($end_day == $weekday_date) 1932 { 1933 // Event runs all day 1934 if($end_time == 2359) 1935 { 1936 $time_period = $lang->all_day; 1937 } 1938 else 1939 { 1940 $time_period = $lang->finishes.gmdate($mybb->settings['timeformat'], $event['endtime_user']); 1941 } 1942 } 1943 // Event is in the middle 1944 else 1945 { 1946 $time_period = $lang->all_day; 1947 } 1948 } 1949 $event_time = ''; 1950 if($time_period) 1951 { 1952 $event_time = "<span class=\"smalltext\"> ({$time_period})</span>"; 1953 } 1954 if($event['private'] == 1) 1955 { 1956 $event_class = " private_event"; 1957 } 1958 else 1959 { 1960 $event_class = " public_event"; 1961 } 1962 if($event['visible'] == 0) 1963 { 1964 $event_class .= " trow_shaded"; 1965 } 1966 eval("\$day_events .= \"".$templates->get("calendar_weekview_day_event")."\";"); 1967 } 1968 } 1969 1970 // Birthdays on this day? 1971 $day_birthdays = ""; 1972 if($calendar['showbirthdays'] && is_array($birthdays) && array_key_exists("{$weekday_day}-{$weekday_month}", $birthdays)) 1973 { 1974 $bday_count = count($birthdays["$weekday_day-$weekday_month"]); 1975 if($bday_count > 1) 1976 { 1977 $day_birthdays = "<a href=\"".get_calendar_link($calendar['cid'], $weekday_year, $weekday_month, $weekday_day)."\">{$bday_count} {$lang->birthdays}</a><br />\n"; 1978 } 1979 else 1980 { 1981 $day_birthdays = "<a href=\"".get_calendar_link($calendar['cid'], $weekday_year, $weekday_month, $weekday_day)."\">1 {$lang->birthday}</a><br />\n"; 1982 } 1983 } 1984 1985 $day_link = get_calendar_link($calendar['cid'], $weekday_year, $weekday_month, $weekday_day); 1986 eval("\$day_bits[$weekday_month] .= \"".$templates->get("calendar_weekview_day")."\";"); 1987 $day_events = $day_birthdays = ""; 1988 $weekday_date = gmmktime(0, 0, 0, $weekday_month, $weekday_day+1, $weekday_year); 1989 } 1990 1991 // Now we build our month headers 1992 foreach($week_months as $month) 1993 { 1994 $weekday_month = $monthnames[$month[0]]; 1995 $weekday_year = $month[1]; 1996 1997 // Fetch mini calendar for each month in this week 1998 $mini_calendars .= build_mini_calendar($calendar, $month[0], $weekday_year, $events_cache)."<br />"; 1999 2000 // Fetch out the days for this month 2001 $days = $day_bits[$month[0]]; 2002 2003 eval("\$weekday_bits .= \"".$templates->get("calendar_weekview_month")."\";"); 2004 } 2005 2006 if($mybb->usergroup['canaddevents'] == 1) 2007 { 2008 eval("\$addevent = \"".$templates->get("calendar_addeventlink")."\";"); 2009 } 2010 2011 // Now output the page 2012 $plugins->run_hooks("calendar_weekview_end"); 2013 2014 eval("\$weekview = \"".$templates->get("calendar_weekview")."\";"); 2015 output_page($weekview); 2016 } 2017 2018 // View yearly calendar 2019 if($mybb->input['action'] == "yearview") 2020 { 2021 } 2022 2023 // Showing a calendar 2024 if(!$mybb->input['action']) 2025 { 2026 // Showing a particular calendar 2027 if($mybb->input['calendar']) 2028 { 2029 $query = $db->simple_select("calendars", "*", "cid='".intval($mybb->input['calendar'])."'"); 2030 $calendar = $db->fetch_array($query); 2031 } 2032 // Showing the default calendar 2033 else 2034 { 2035 $query = $db->simple_select("calendars", "*", "", array('order_by' => 'disporder', 'limit' => 1)); 2036 $calendar = $db->fetch_array($query); 2037 } 2038 2039 // Invalid calendar? 2040 if(!$calendar['cid']) 2041 { 2042 error($lang->invalid_calendar); 2043 } 2044 2045 // Do we have permission to view this calendar? 2046 $calendar_permissions = get_calendar_permissions($calendar['cid']); 2047 2048 if($calendar_permissions['canviewcalendar'] != 1) 2049 { 2050 error_no_permission(); 2051 } 2052 2053 // Incoming month/year? 2054 if($mybb->input['year'] && $mybb->input['year'] <= my_date("Y")+5) 2055 { 2056 $year = intval($mybb->input['year']); 2057 } 2058 else 2059 { 2060 $year = my_date("Y"); 2061 } 2062 2063 // Then the month 2064 if($mybb->input['month'] >=1 && $mybb->input['month'] <= 12) 2065 { 2066 $month = intval($mybb->input['month']); 2067 } 2068 else 2069 { 2070 $month = my_date("n"); 2071 } 2072 2073 add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid'])); 2074 add_breadcrumb("$monthnames[$month] $year", get_calendar_link($calendar['cid'], $year, $month)); 2075 2076 $next_month = get_next_month($month, $year); 2077 $prev_month = get_prev_month($month, $year); 2078 2079 $prev_link = get_calendar_link($calendar['cid'], $prev_month['year'], $prev_month['month']); 2080 $next_link = get_calendar_link($calendar['cid'], $next_month['year'], $next_month['month']); 2081 2082 // Start constructing the calendar 2083 2084 $weekdays = fetch_weekday_structure($calendar['startofweek']); 2085 2086 $month_start_weekday = gmdate("w", gmmktime(0, 0, 0, $month, $calendar['startofweek']+1, $year)); 2087 2088 $prev_month_days = gmdate("t", gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year'])); 2089 2090 // This is if we have days in the previous month to show 2091 if($month_start_weekday != $weekdays[0] || $calendar['startofweek'] != 0) 2092 { 2093 $prev_days = $day = gmdate("t", gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year'])); 2094 $day -= array_search(($month_start_weekday), $weekdays); 2095 $day += $calendar['startofweek']+1; 2096 if($day > $prev_month_days+1) 2097 { 2098 // Go one week back 2099 $day -= 7; 2100 } 2101 $calendar_month = $prev_month['month']; 2102 $calendar_year = $prev_month['year']; 2103 } 2104 else 2105 { 2106 $day = $calendar['startofweek']+1; 2107 $calendar_month = $month; 2108 $calendar_year = $year; 2109 } 2110 2111 // So now we fetch events for this month (nb, cache events for past month, current month and next month for mini calendars too) 2112 $start_timestamp = gmmktime(0, 0, 0, $calendar_month, $day, $calendar_year); 2113 $num_days = gmdate("t", gmmktime(0, 0, 0, $month, 1, $year)); 2114 2115 $month_end_weekday = gmdate("w", gmmktime(0, 0, 0, $month, $num_days, $year)); 2116 $next_days = 6-$month_end_weekday+$calendar['startofweek']; 2117 2118 // More than a week? Go one week back 2119 if($next_days >= 7) 2120 { 2121 $next_days -= 7; 2122 } 2123 if($next_days > 0) 2124 { 2125 $end_timestamp = gmmktime(23, 59, 59, $next_month['month'], $next_days, $next_month['year']); 2126 } 2127 else 2128 { 2129 // We don't need days from the next month 2130 $end_timestamp = gmmktime(23, 59, 59, $month, $num_days, $year); 2131 } 2132 2133 $events_cache = get_events($calendar, $start_timestamp, $end_timestamp, $calendar_permissions['canmoderateevents']); 2134 2135 // Fetch birthdays 2136 if($calendar['showbirthdays']) 2137 { 2138 $bday_months = array($month, $prev_month['month'], $next_month['month']); 2139 $birthdays = get_birthdays($bday_months); 2140 } 2141 2142 $today = my_date("dnY"); 2143 2144 // Build weekday headers 2145 foreach($weekdays as $weekday) 2146 { 2147 $weekday_name = fetch_weekday_name($weekday); 2148 eval("\$weekday_headers .= \"".$templates->get("calendar_weekdayheader")."\";"); 2149 } 2150 2151 for($row = 0; $row < 6; ++$row) // Iterate weeks (each week gets a row) 2152 { 2153 foreach($weekdays as $weekday_id => $weekday) 2154 { 2155 // Current month always starts on 1st row 2156 if($row == 0 && $day == $calendar['startofweek']+1) 2157 { 2158 $in_month = 1; 2159 $calendar_month = $month; 2160 $calendar_year = $year; 2161 } 2162 else if($calendar_month == $prev_month['month'] && $day > $prev_month_days) 2163 { 2164 $day = 1; 2165 $in_month = 1; 2166 $calendar_month = $month; 2167 $calendar_year = $year; 2168 } 2169 else if($day > $num_days && $calendar_month != $prev_month['month']) 2170 { 2171 $in_month = 0; 2172 $calendar_month = $next_month['month']; 2173 $calendar_year = $next_month['year']; 2174 $day = 1; 2175 if($calendar_month == $month) 2176 { 2177 $in_month = 1; 2178 } 2179 } 2180 2181 if($weekday_id == 0) 2182 { 2183 $week_stamp = gmmktime(0, 0, 0, $calendar_month, $day, $calendar_year); 2184 $week_link = get_calendar_week_link($calendar['cid'], $week_stamp); 2185 } 2186 2187 if($weekday_id == 0 && $calendar_month == $next_month['month']) 2188 { 2189 break; 2190 } 2191 2192 // Any events on this specific day? 2193 if(is_array($events_cache) && array_key_exists("{$day}-{$calendar_month}-{$calendar_year}", $events_cache)) 2194 { 2195 $total_events = count($events_cache["$day-$calendar_month-$calendar_year"]); 2196 if($total_events > $calendar['eventlimit'] && $calendar['eventlimit'] != 0) 2197 { 2198 if($total_events > 1) 2199 { 2200 $day_events = "<div style=\"margin-bottom: 4px;\"><a href=\"".get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day)."\" class=\"smalltext\">{$total_events} {$lang->events}</a></div>\n"; 2201 } 2202 else 2203 { 2204 $day_events = "<div style=\"margin-bottom: 4px;\"><a href=\"".get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day)."\" class=\"smalltext\">1 {$lang->event}</a></div>\n"; 2205 } 2206 } 2207 else 2208 { 2209 foreach($events_cache["$day-$calendar_month-$calendar_year"] as $event) 2210 { 2211 $event['eventlink'] = get_event_link($event['eid']); 2212 $event['fullname'] = htmlspecialchars_uni($event['name']); 2213 if(my_strlen($event['name']) > 15) 2214 { 2215 $event['name'] = my_substr($event['name'], 0, 15) . "..."; 2216 } 2217 $event['name'] = htmlspecialchars_uni($event['name']); 2218 if($event['private'] == 1) 2219 { 2220 $event_class = " private_event"; 2221 } 2222 else 2223 { 2224 $event_class = " public_event"; 2225 } 2226 if($event['visible'] == 0) 2227 { 2228 $event_class .= " trow_shaded"; 2229 } 2230 eval("\$day_events .= \"".$templates->get("calendar_eventbit")."\";"); 2231 } 2232 } 2233 } 2234 2235 // Birthdays on this day? 2236 $day_birthdays = ""; 2237 if($calendar['showbirthdays'] && is_array($birthdays) && array_key_exists("$day-$calendar_month", $birthdays)) 2238 { 2239 $bday_count = count($birthdays["$day-$calendar_month"]); 2240 if($bday_count > 1) 2241 { 2242 $day_birthdays = "<div style=\"margin-bottom: 4px;\"><a href=\"".get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day)."\" class=\"smalltext\">{$bday_count} {$lang->birthdays}</a></div>\n"; 2243 } 2244 else 2245 { 2246 $day_birthdays = "<div style=\"margin-bottom: 4px;\"><a href=\"".get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day)."\" class=\"smalltext\">1 {$lang->birthday}</a></div>\n"; 2247 } 2248 } 2249 2250 $day_link = get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day); 2251 2252 // Is the current day 2253 if($day.$calendar_month.$year == $today && $month == $calendar_month) 2254 { 2255 $day_class = "trow_sep"; 2256 } 2257 // Not in this month 2258 else if($in_month == 0) 2259 { 2260 $day_class = "trow1"; 2261 } 2262 // Just a normal day in this month 2263 else 2264 { 2265 $day_class = "trow2"; 2266 } 2267 eval("\$day_bits .= \"".$templates->get("calendar_weekrow_day")."\";"); 2268 $day_birthdays = $day_events = ""; 2269 ++$day; 2270 } 2271 if($day_bits) 2272 { 2273 eval("\$calendar_rows .= \"".$templates->get("calendar_weekrow")."\";"); 2274 } 2275 $day_bits = ""; 2276 } 2277 2278 $yearsel = ''; 2279 for($i = my_date("Y"); $i < (my_date("Y") + 5); ++$i) 2280 { 2281 $yearsel .= "<option value=\"$i\">$i</option>\n"; 2282 } 2283 2284 if($mybb->usergroup['canaddevents'] == 1) 2285 { 2286 eval("\$addevent = \"".$templates->get("calendar_addeventlink")."\";"); 2287 } 2288 2289 $plugins->run_hooks("calendar_end"); 2290 2291 eval("\$calendar = \"".$templates->get("calendar")."\";"); 2292 output_page($calendar); 2293 } 2294 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |