[ Index ]

PHP Cross Reference of MyBB 1.8.12

title

Body

[close]

/ -> calendar.php (source)

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


2005 - 2016 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref 0.7.1