[ Index ]

PHP Cross Reference of MyBB 1.8.17

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,calendar_weekview_nextlink";
  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_weekview_prevlink";
  16  $templatelist .= ",calendar_event_editbutton,calendar_event_modoptions,calendar_dayview_event,calendar_dayview,codebuttons,calendar_weekrow_day_events,calendar_weekview_month,calendar_addeventlink,calendar_weekview";
  17  $templatelist .= ",calendar_jump,calendar_jump_option,calendar_editevent,calendar_dayview_birthdays_bday,calendar_dayview_birthdays,calendar_dayview_noevents,calendar_addevent_calendarselect_hidden,calendar_nextlink";
  18  $templatelist .= ",calendar_weekrow_day_birthdays,calendar_weekview_day_birthdays,calendar_year_sel,calendar_event_userstar,calendar_addevent_calendarselect,calendar_eventbit,calendar_event,calendar_move,calendar_prevlink";
  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['usergroup'])
1449      {
1450          $user_usergroup = usergroup_permissions($event['usergroup']);
1451      }
1452      else
1453      {
1454          $user_usergroup = usergroup_permissions(1);
1455      }
1456  
1457      $displaygroupfields = array("title", "description", "namestyle", "usertitle", "stars", "starimage", "image");
1458  
1459      if(!$event['displaygroup'])
1460      {
1461          $event['displaygroup'] = $event['usergroup'];
1462      }
1463  
1464      $display_group = usergroup_displaygroup($event['displaygroup']);
1465      if(is_array($display_group))
1466      {
1467          $user_usergroup = array_merge($user_usergroup, $display_group);
1468      }
1469  
1470      $titles_cache = $cache->read("usertitles");
1471  
1472      // Event made by registered user
1473      if($event['uid'] > 0 && $event['username'])
1474      {
1475          $event['username'] = htmlspecialchars_uni($event['username']);
1476          $event['profilelink'] = build_profile_link(format_name($event['username'], $event['usergroup'], $event['displaygroup']), $event['uid']);
1477  
1478          if(trim($event['usertitle']) != "")
1479          {
1480              // Do nothing, no need for an extra variable..
1481          }
1482          elseif($user_usergroup['usertitle'] != "")
1483          {
1484              $event['usertitle'] = $user_usergroup['usertitle'];
1485          }
1486          elseif(is_array($titles_cache) && !$user_usergroup['usertitle'])
1487          {
1488              reset($titles_cache);
1489              foreach($titles_cache as $title)
1490              {
1491                  if($event['postnum'] >= $title['posts'])
1492                  {
1493                      $event['usertitle'] = $title['title'];
1494                      $event['stars'] = $title['stars'];
1495                      $event['starimage'] = $title['starimage'];
1496                      break;
1497                  }
1498              }
1499          }
1500  
1501          if($user_usergroup['stars'])
1502          {
1503              $event['stars'] = $user_usergroup['stars'];
1504          }
1505  
1506          if(empty($event['starimage']))
1507          {
1508              $event['starimage'] = $user_usergroup['starimage'];
1509          }
1510          $event['starimage'] = str_replace("{theme}", $theme['imgdir'], $event['starimage']);
1511  
1512          $event['userstars'] = '';
1513          for($i = 0; $i < $event['stars']; ++$i)
1514          {
1515              eval("\$event['userstars'] .= \"".$templates->get("calendar_event_userstar", 1, 0)."\";");
1516          }
1517  
1518          if($event['userstars'] && $event['starimage'] && $event['stars'])
1519          {
1520              $event['userstars'] .= "<br />";
1521          }
1522      }
1523      // Created by a guest or an unknown user
1524      else
1525      {
1526          if(!$event['username'])
1527          {
1528              $event['username'] = $lang->guest;
1529          }
1530  
1531          $event['username'] = htmlspecialchars_uni($event['username']);
1532          $event['profilelink'] = format_name($event['username'], 1);
1533  
1534          if($user_usergroup['usertitle'])
1535          {
1536              $event['usertitle'] = $user_usergroup['usertitle'];
1537          }
1538          else
1539          {
1540              $event['usertitle'] = $lang->guest;
1541          }
1542          $event['userstars'] = '';
1543      }
1544  
1545      $event['usertitle'] = htmlspecialchars_uni($event['usertitle']);
1546  
1547      if($event['ignoretimezone'] == 0)
1548      {
1549          $offset = (float)$event['timezone'];
1550      }
1551      else
1552      {
1553          $offset = (float)$mybb->user['timezone'];
1554      }
1555  
1556      $event['starttime_user'] = $event['starttime']+$offset*3600;
1557  
1558      // Events over more than one day
1559      $time_period = '';
1560      if($event['endtime'] > 0 && $event['endtime'] != $event['starttime'])
1561      {
1562          $event['endtime_user'] = $event['endtime']+$offset*3600;
1563          $start_day = adodb_gmmktime(0, 0, 0, gmdate("n", $event['starttime_user']), gmdate("j", $event['starttime_user']), gmdate("Y", $event['starttime_user']));
1564          $end_day = adodb_gmmktime(0, 0, 0, gmdate("n", $event['endtime_user']), gmdate("j", $event['endtime_user']), gmdate("Y", $event['endtime_user']));
1565          $start_time = gmdate("Hi", $event['starttime_user']);
1566          $end_time = gmdate("Hi", $event['endtime_user']);
1567  
1568          $event['repeats'] = my_unserialize($event['repeats']);
1569  
1570          // Event only runs over one day
1571          if($start_day == $end_day && $event['repeats']['repeats'] == 0)
1572          {
1573              $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']);
1574              // Event runs all day
1575              if($start_time != 0000 && $end_time != 2359)
1576              {
1577                  $time_period .= $lang->comma.gmdate($mybb->settings['timeformat'], $event['starttime_user'])." - ".gmdate($mybb->settings['timeformat'], $event['endtime_user']);
1578              }
1579              else
1580              {
1581                  $time_period .= $lang->comma.$lang->all_day;
1582              }
1583          }
1584          else
1585          {
1586              $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']).", ".gmdate($mybb->settings['timeformat'], $event['starttime_user']);
1587              $time_period .= " - ";
1588              $time_period .= gmdate($mybb->settings['dateformat'], $event['endtime_user']).", ".gmdate($mybb->settings['timeformat'], $event['endtime_user']);
1589          }
1590      }
1591      else
1592      {
1593          $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']);
1594      }
1595  
1596      $repeats = fetch_friendly_repetition($event);
1597      if($repeats)
1598      {
1599          eval("\$repeats = \"".$templates->get("calendar_repeats")."\";");
1600      }
1601  
1602      $event_class = '';
1603      if($calendar_permissions['canmoderateevents'] == 1 || ($mybb->user['uid'] > 0 && $mybb->user['uid'] == $event['uid']))
1604      {
1605          eval("\$edit_event = \"".$templates->get("calendar_event_editbutton")."\";");
1606          if($calendar_permissions['canmoderateevents'] == 1)
1607          {
1608              if($event['visible'] == 1)
1609              {
1610                  $approve = $lang->unapprove_event;
1611                  $approve_value = "unapprove";
1612              }
1613              else
1614              {
1615                  $approve = $lang->approve_event;
1616                  $approve_value = "approve";
1617              }
1618              eval("\$moderator_options = \"".$templates->get("calendar_event_modoptions")."\";");
1619          }
1620  
1621          if($event['visible'] == 0)
1622          {
1623              $event_class = " trow_shaded";
1624          }
1625      }
1626  
1627      $month = my_date("n");
1628  
1629      $yearsel = '';
1630      for($year_sel = my_date("Y"); $year_sel < (my_date("Y") + 5); ++$year_sel)
1631      {
1632          eval("\$yearsel .= \"".$templates->get("calendar_year_sel")."\";");
1633      }
1634  
1635      $addevent = '';
1636      if($mybb->usergroup['canaddevents'] == 1)
1637      {
1638          eval("\$addevent = \"".$templates->get("calendar_addeventlink")."\";");
1639      }
1640  
1641      // Now output the page
1642      $plugins->run_hooks("calendar_event_end");
1643      eval("\$event = \"".$templates->get("calendar_event")."\";");
1644      output_page($event);
1645  }
1646  
1647  // View all events on a specific day.
1648  if($mybb->input['action'] == "dayview")
1649  {
1650      // Showing a particular calendar
1651      if($mybb->input['calendar'])
1652      {
1653          $query = $db->simple_select("calendars", "*", "cid='{$mybb->input['calendar']}'");
1654          $calendar = $db->fetch_array($query);
1655      }
1656      // Showing the default calendar
1657      else
1658      {
1659          $query = $db->simple_select("calendars", "*", "disporder='1'");
1660          $calendar = $db->fetch_array($query);
1661      }
1662  
1663      // Invalid calendar?
1664      if(!$calendar)
1665      {
1666          error($lang->invalid_calendar);
1667      }
1668  
1669      // Do we have permission to view this calendar?
1670      $calendar_permissions = get_calendar_permissions($calendar['cid']);
1671      if($calendar_permissions['canviewcalendar']  != 1)
1672      {
1673          error_no_permission();
1674      }
1675  
1676      // Incoming year?
1677      if(isset($mybb->input['year']) && $mybb->get_input('year', MyBB::INPUT_INT) <= my_date("Y")+5 && $mybb->get_input('year', MyBB::INPUT_INT) >= 1901)
1678      {
1679          $year = $mybb->get_input('year', MyBB::INPUT_INT);
1680      }
1681      else
1682      {
1683          $year = my_date("Y");
1684      }
1685  
1686      // Then the month
1687      $mybb->input['month'] = $mybb->get_input('month', MyBB::INPUT_INT);
1688      if($mybb->input['month'] >= 1 && $mybb->input['month'] <= 12)
1689      {
1690          $month = $mybb->input['month'];
1691      }
1692      else
1693      {
1694          $month = my_date("n");
1695      }
1696  
1697      // And day?
1698      $mybb->input['day'] = $mybb->get_input('day', MyBB::INPUT_INT);
1699      if($mybb->input['day'] && $mybb->input['day'] <= gmdate("t", adodb_gmmktime(0, 0, 0, $month, 1, $year)))
1700      {
1701          $day = $mybb->input['day'];
1702      }
1703      else
1704      {
1705          $day = my_date("j");
1706      }
1707  
1708      add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid']));
1709      add_breadcrumb("$day $monthnames[$month] $year", get_calendar_link($calendar['cid'], $year, $month, $day));
1710  
1711      $plugins->run_hooks("calendar_dayview_start");
1712  
1713      // Load Birthdays for this day
1714      $birthday_list = $birthdays = '';
1715      if($calendar['showbirthdays'])
1716      {
1717          $birthdays2 = get_birthdays($month, $day);
1718          $bdayhidden = 0;
1719          if(is_array($birthdays2))
1720          {
1721              foreach($birthdays2 as $birthday)
1722              {
1723                  if($birthday['birthdayprivacy'] == 'all')
1724                  {
1725                      $bday = explode("-", $birthday['birthday']);
1726                      if($bday[2] && $bday[2] < $year)
1727                      {
1728                          $age = $year - $bday[2];
1729                          $age = " (".$lang->sprintf($lang->years_old, $age).")";
1730                      }
1731                      else
1732                      {
1733                          $age = '';
1734                      }
1735  
1736                      $birthday['username'] = format_name(htmlspecialchars_uni($birthday['username']), $birthday['usergroup'], $birthday['displaygroup']);
1737                      $birthday['profilelink'] = build_profile_link($birthday['username'], $birthday['uid']);
1738                      eval("\$birthday_list .= \"".$templates->get("calendar_dayview_birthdays_bday", 1, 0)."\";");
1739                      $comma = $lang->comma;
1740                  }
1741                  else
1742                  {
1743                      ++$bdayhidden;
1744                  }
1745              }
1746          }
1747          if($bdayhidden > 0)
1748          {
1749              if($birthday_list)
1750              {
1751                  $birthday_list .= " - ";
1752              }
1753              $birthday_list .= "{$bdayhidden} {$lang->birthdayhidden}";
1754          }
1755          if($birthday_list)
1756          {
1757              $bdaydate = my_date($mybb->settings['dateformat'], adodb_gmmktime(0, 0, 0, $month, $day, $year), 0, 0);
1758              $lang->birthdays_on_day = $lang->sprintf($lang->birthdays_on_day, $bdaydate);
1759              eval("\$birthdays = \"".$templates->get("calendar_dayview_birthdays", 1, 0)."\";");
1760          }
1761      }
1762  
1763      // So now we fetch events for this month
1764      $start_timestamp = adodb_gmmktime(0, 0, 0, $month, $day, $year);
1765      $end_timestamp = adodb_gmmktime(23, 59, 59, $month, $day, $year);
1766  
1767      $events_cache = get_events($calendar, $start_timestamp, $end_timestamp, $calendar_permissions['canmoderateevents']);
1768  
1769      $events = '';
1770      if(isset($events_cache["$day-$month-$year"]) && is_array($events_cache["$day-$month-$year"]))
1771      {
1772          foreach($events_cache["$day-$month-$year"] as $event)
1773          {
1774              $event['name'] = htmlspecialchars_uni($event['name']);
1775  
1776              $event_parser_options = array(
1777                  "allow_html" => $calendar['allowhtml'],
1778                  "allow_mycode" => $calendar['allowmycode'],
1779                  "allow_smilies" => $calendar['allowsmilies'],
1780                  "allow_imgcode" => $calendar['allowimgcode'],
1781                  "allow_videocode" => $calendar['allowvideocode']
1782              );
1783  
1784              if($mybb->user['showimages'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
1785              {
1786                  $event_parser_options['allow_imgcode'] = 0;
1787              }
1788  
1789              if($mybb->user['showvideos'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0)
1790              {
1791                  $event_parser_options['allow_videocode'] = 0;
1792              }
1793  
1794              $event['description'] = $parser->parse_message($event['description'], $event_parser_options);
1795  
1796              // Get the usergroup
1797              if($event['usergroup'])
1798              {
1799                  $user_usergroup = usergroup_permissions($event['usergroup']);
1800              }
1801              else
1802              {
1803                  $user_usergroup = usergroup_permissions(1);
1804              }
1805  
1806              $displaygroupfields = array("title", "description", "namestyle", "usertitle", "stars", "starimage", "image");
1807  
1808              if(!$event['displaygroup'])
1809              {
1810                  $event['displaygroup'] = $event['usergroup'];
1811              }
1812  
1813              $display_group = usergroup_displaygroup($event['displaygroup']);
1814              if(is_array($display_group))
1815              {
1816                  $user_usergroup = array_merge($user_usergroup, $display_group);
1817              }
1818  
1819              $titles_cache = $cache->read("usertitles");
1820  
1821              // Event made by registered user
1822              if($event['uid'] > 0 && $event['username'])
1823              {
1824                  $event['username'] = htmlspecialchars_uni($event['username']);
1825                  $event['profilelink'] = build_profile_link(format_name($event['username'], $event['usergroup'], $event['displaygroup']), $event['uid']);
1826  
1827                  if(trim($event['usertitle']) != "")
1828                  {
1829                      // Do nothing, no need for an extra variable..
1830                  }
1831                  elseif($user_usergroup['usertitle'] != "")
1832                  {
1833                      $event['usertitle'] = $user_usergroup['usertitle'];
1834                  }
1835                  elseif(is_array($titles_cache) && !$user_usergroup['usertitle'])
1836                  {
1837                      reset($titles_cache);
1838                      foreach($titles_cache as $title)
1839                      {
1840                          if($event['postnum'] >= $title['posts'])
1841                          {
1842                              $event['usertitle'] = $title['title'];
1843                              $event['stars'] = $title['stars'];
1844                              $event['starimage'] = $title['starimage'];
1845                              break;
1846                          }
1847                      }
1848                  }
1849  
1850                  if($user_usergroup['stars'])
1851                  {
1852                      $event['stars'] = $user_usergroup['stars'];
1853                  }
1854  
1855                  if(empty($event['starimage']))
1856                  {
1857                      $event['starimage'] = $user_usergroup['starimage'];
1858                  }
1859  
1860                  $event['userstars'] = '';
1861                  for($i = 0; $i < $event['stars']; ++$i)
1862                  {
1863                      eval("\$event['userstars'] .= \"".$templates->get("calendar_event_userstar", 1, 0)."\";");
1864                  }
1865  
1866                  if($event['userstars'] && $event['starimage'] && $event['stars'])
1867                  {
1868                      $event['userstars'] .= "<br />";
1869                  }
1870              }
1871              // Created by a guest or an unknown user
1872              else
1873              {
1874                  if(!$event['username'])
1875                  {
1876                      $event['username'] = $lang->guest;
1877                  }
1878  
1879                  $event['username'] = htmlspecialchars_uni($event['username']);
1880                  $event['profilelink'] = format_name($event['username'], 1);
1881  
1882                  if($user_usergroup['usertitle'])
1883                  {
1884                      $event['usertitle'] = $user_usergroup['usertitle'];
1885                  }
1886                  else
1887                  {
1888                      $event['usertitle'] = $lang->guest;
1889                  }
1890                  $event['userstars'] = '';
1891              }
1892  
1893              $event['usertitle'] = htmlspecialchars_uni($event['usertitle']);
1894  
1895              if($event['ignoretimezone'] == 0)
1896              {
1897                  $offset = (float)$event['timezone'];
1898              }
1899              else
1900              {
1901                  $offset = (float)$mybb->user['timezone'];
1902              }
1903  
1904              $event['starttime_user'] = $event['starttime']+$offset*3600;
1905  
1906              // Events over more than one day
1907              $time_period = '';
1908              if($event['endtime'] > 0 && $event['endtime'] != $event['starttime'])
1909              {
1910                  $event['endtime_user'] = $event['endtime']+$offset*3600;
1911                  $start_day = adodb_gmmktime(0, 0, 0, gmdate("n", $event['starttime_user']), gmdate("j", $event['starttime_user']), gmdate("Y", $event['starttime_user']));
1912                  $end_day = adodb_gmmktime(0, 0, 0, gmdate("n", $event['endtime_user']), gmdate("j", $event['endtime_user']), gmdate("Y", $event['endtime_user']));
1913                  $start_time = gmdate("Hi", $event['starttime_user']);
1914                  $end_time = gmdate("Hi", $event['endtime_user']);
1915  
1916                  // Event only runs over one day
1917                  if($start_day == $end_day && $event['repeats']['repeats'] == 0)
1918                  {
1919                      $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']);
1920                      // Event runs all day
1921                      if($start_time != 0000 && $end_time != 2359)
1922                      {
1923                          $time_period .= $lang->comma.gmdate($mybb->settings['timeformat'], $event['starttime_user'])." - ".gmdate($mybb->settings['timeformat'], $event['endtime_user']);
1924                      }
1925                      else
1926                      {
1927                          $time_period .= $lang->comma.$lang->all_day;
1928                      }
1929                  }
1930                  else
1931                  {
1932                      $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']).", ".gmdate($mybb->settings['timeformat'], $event['starttime_user']);
1933                      $time_period .= " - ";
1934                      $time_period .= gmdate($mybb->settings['dateformat'], $event['endtime_user']).", ".gmdate($mybb->settings['timeformat'], $event['endtime_user']);
1935                  }
1936              }
1937              else
1938              {
1939                  $time_period = gmdate($mybb->settings['dateformat'], $event['starttime_user']);
1940              }
1941  
1942              $repeats = fetch_friendly_repetition($event);
1943              if($repeats)
1944              {
1945                  eval("\$repeats = \"".$templates->get("calendar_repeats")."\";");
1946              }
1947  
1948              $edit_event = $moderator_options = $event_class = "";
1949              if($calendar_permissions['canmoderateevents'] == 1 || ($mybb->user['uid'] > 0 && $mybb->user['uid'] == $event['uid']))
1950              {
1951                  eval("\$edit_event = \"".$templates->get("calendar_event_editbutton")."\";");
1952                  if($calendar_permissions['canmoderateevents'] == 1)
1953                  {
1954                      if($event['visible'] == 1)
1955                      {
1956                          $approve = $lang->unapprove_event;
1957                          $approve_value = "unapprove";
1958                      }
1959                      else
1960                      {
1961                          $approve = $lang->approve_event;
1962                          $approve_value = "approve";
1963                      }
1964                      eval("\$moderator_options = \"".$templates->get("calendar_event_modoptions")."\";");
1965                  }
1966                  if($event['visible'] == 0)
1967                  {
1968                      $event_class = " trow_shaded";
1969                  }
1970              }
1971              eval("\$events .= \"".$templates->get("calendar_dayview_event")."\";");
1972          }
1973      }
1974  
1975      $yearsel = '';
1976      for($year_sel = my_date("Y"); $year_sel < (my_date("Y") + 5); ++$year_sel)
1977      {
1978          eval("\$yearsel .= \"".$templates->get("calendar_year_sel")."\";");
1979      }
1980  
1981      $addevent = '';
1982      if($mybb->usergroup['canaddevents'] == 1)
1983      {
1984          eval("\$addevent = \"".$templates->get("calendar_addeventlink")."\";");
1985      }
1986  
1987      if(!$events)
1988      {
1989          $lang->no_events = $lang->sprintf($lang->no_events, $calendar['cid'], $day, $month, $year);
1990          eval("\$events = \"".$templates->get("calendar_dayview_noevents")."\";");
1991      }
1992  
1993      // Now output the page
1994      $plugins->run_hooks("calendar_dayview_end");
1995  
1996      eval("\$day_view = \"".$templates->get("calendar_dayview")."\";");
1997      output_page($day_view);
1998  }
1999  
2000  // View all events for a specific week
2001  if($mybb->input['action'] == "weekview")
2002  {
2003      // Showing a particular calendar
2004      if($mybb->input['calendar'])
2005      {
2006          $query = $db->simple_select("calendars", "*", "cid='{$mybb->input['calendar']}'");
2007          $calendar = $db->fetch_array($query);
2008      }
2009      // Showing the default calendar
2010      else
2011      {
2012          $query = $db->simple_select("calendars", "*", "disporder='1'");
2013          $calendar = $db->fetch_array($query);
2014      }
2015  
2016      // Invalid calendar?
2017      if(!$calendar)
2018      {
2019          error($lang->invalid_calendar);
2020      }
2021  
2022      // Do we have permission to view this calendar?
2023      $calendar_permissions = get_calendar_permissions($calendar['cid']);
2024      if($calendar_permissions['canviewcalendar']  != 1)
2025      {
2026          error_no_permission();
2027      }
2028  
2029      $weekdays = fetch_weekday_structure($calendar['startofweek']);
2030  
2031      $yearsel = '';
2032      for($year_sel = my_date("Y"); $year_sel < (my_date("Y") + 5); ++$year_sel)
2033      {
2034          eval("\$yearsel .= \"".$templates->get("calendar_year_sel")."\";");
2035      }
2036  
2037      // No incoming week, show THIS week
2038      if(empty($mybb->input['week']))
2039      {
2040          list($day, $month, $year) = explode("-", my_date("j-n-Y"));
2041          $php_weekday = gmdate("w", adodb_gmmktime(0, 0, 0, $month, $day, $year));
2042          $my_weekday = array_search($php_weekday, $weekdays);
2043          // So now we have the start day of this week to show
2044          $start_day = $day-$my_weekday;
2045          $mybb->input['week'] = adodb_gmmktime(0, 0, 0, $month, $start_day, $year);
2046      }
2047      else
2048      {
2049          $mybb->input['week'] = (int)str_replace("n", "-", $mybb->get_input('week'));
2050          // Nothing before 1901 please ;)
2051          if($mybb->input['week'] < -2177625600)
2052          {
2053              $mybb->input['week'] = -2177625600;
2054          }
2055      }
2056  
2057      // This is where we've come from and where we're headed
2058      $week_from = explode("-", gmdate("j-n-Y", $mybb->input['week']));
2059      $week_from_one = $week_from[1];
2060      $friendly_week_from = gmdate($mybb->settings['dateformat'], $mybb->input['week']);
2061      $week_to_stamp = adodb_gmmktime(0, 0, 0, $week_from[1], $week_from[0]+6, $week_from[2]);
2062      $week_to = explode("-", gmdate("j-n-Y-t", $week_to_stamp));
2063      $friendly_week_to = gmdate($mybb->settings['dateformat'], $week_to_stamp);
2064  
2065      add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid']));
2066      add_breadcrumb("{$monthnames[$week_from[1]]} {$week_from[2]}", get_calendar_link($calendar['cid'], $week_from[2], $week_from[1]));
2067      add_breadcrumb($lang->weekly_overview);
2068  
2069      $plugins->run_hooks("calendar_weekview_start");
2070  
2071      // Establish if we have a month ending in this week
2072      if($week_from[1] != $week_to[1])
2073      {
2074          $different_months = true;
2075          $week_months = array(array($week_from[1], $week_from[2]), array($week_to[1], $week_to[2]));
2076          $bday_months = array($week_from[1], $week_to[1]);
2077      }
2078      else
2079      {
2080          $week_months = array(array($week_from[1], $week_from[2]));
2081          $bday_months = array($week_from[1]);
2082      }
2083  
2084      // Load Birthdays for this month
2085      if($calendar['showbirthdays'] == 1)
2086      {
2087          $birthdays = get_birthdays($bday_months);
2088      }
2089  
2090      // We load events for the entire month date range - for our mini calendars too
2091      $events_from = adodb_gmmktime(0, 0, 0, $week_from[1], 1, $week_from[2]);
2092      $events_to = adodb_gmmktime(0, 0, 0, $week_to[1], $week_to[3], $week_to[2]);
2093  
2094      $events_cache = get_events($calendar, $events_from, $events_to, $calendar_permissions['canmoderateevents']);
2095  
2096      $today = my_date("dnY");
2097  
2098      $prev_week = $mybb->input['week'] - 604800;
2099  
2100      $prev_week_link = '';
2101      if(my_date("Y", $prev_week) >= 1901)
2102      {
2103          $prev_link = get_calendar_week_link($calendar['cid'], $prev_week);
2104  
2105          eval("\$prev_week_link = \"".$templates->get("calendar_weekview_prevlink")."\";");
2106      }
2107  
2108      $next_week = $mybb->input['week'] + 604800;
2109  
2110      $next_week_link = '';
2111      if(my_date("Y", $next_week)+1 <= my_date("Y")+5)
2112      {
2113          $next_link = get_calendar_week_link($calendar['cid'], $next_week);
2114  
2115          eval("\$next_week_link = \"".$templates->get("calendar_weekview_nextlink")."\";");
2116      }
2117  
2118      $sep = '';
2119      if(!empty($prev_week_link) && !empty($next_week_link))
2120      {
2121          $sep = " | ";
2122      }
2123  
2124      $weekday_date = $mybb->input['week'];
2125  
2126      while($weekday_date <= $week_to_stamp)
2127      {
2128          $weekday = gmdate("w", $weekday_date);
2129          $weekday_name = fetch_weekday_name($weekday);
2130          $weekday_month = gmdate("n", $weekday_date);
2131          $weekday_year = gmdate("Y", $weekday_date);
2132          $weekday_day = gmdate("j", $weekday_date);
2133  
2134          // Special shading for today
2135          $day_shaded = '';
2136          if(gmdate("dnY", $weekday_date) == $today)
2137          {
2138              $day_shaded = ' trow_shaded';
2139          }
2140  
2141          $day_events = '';
2142  
2143          // Any events on this specific day?
2144          if(is_array($events_cache) && array_key_exists("{$weekday_day}-{$weekday_month}-{$weekday_year}", $events_cache))
2145          {
2146              foreach($events_cache["$weekday_day-$weekday_month-$weekday_year"] as $event)
2147              {
2148                  $event['eventlink'] = get_event_link($event['eid']);
2149                  $event['name'] = htmlspecialchars_uni($event['name']);
2150                  $event['fullname'] = $event['name'];
2151                  if(my_strlen($event['name']) > 50)
2152                  {
2153                      $event['name'] = my_substr($event['name'], 0, 50) . "...";
2154                  }
2155                  // Events over more than one day
2156                  $time_period = '';
2157                  if($event['endtime'] > 0 && $event['endtime'] != $event['starttime'])
2158                  {
2159                      $start_day = adodb_gmmktime(0, 0, 0, gmdate("n", $event['starttime_user']), gmdate("j", $event['starttime_user']), gmdate("Y", $event['starttime_user']));
2160                      $end_day = adodb_gmmktime(0, 0, 0, gmdate("n", $event['endtime_user']), gmdate("j", $event['endtime_user']), gmdate("Y", $event['endtime_user']));
2161                      $start_time = gmdate("Hi", $event['starttime_user']);
2162                      $end_time = gmdate("Hi", $event['endtime_user']);
2163                      // Event only runs over one day
2164                      if($start_day == $end_day || $event['repeats'] > 0)
2165                      {
2166                          // Event runs all day
2167                          if($start_time == 0000 && $end_time == 2359)
2168                          {
2169                              $time_period = $lang->all_day;
2170                          }
2171                          else
2172                          {
2173                              $time_period = gmdate($mybb->settings['timeformat'], $event['starttime_user'])." - ".gmdate($mybb->settings['timeformat'], $event['endtime_user']);
2174                          }
2175                      }
2176                      // Event starts on this day
2177                      else if($start_day == $weekday_date)
2178                      {
2179                          // Event runs all day
2180                          if($start_time == 0000)
2181                          {
2182                              $time_period = $lang->all_day;
2183                          }
2184                          else
2185                          {
2186                              $time_period = $lang->starts.gmdate($mybb->settings['timeformat'], $event['starttime_user']);
2187                          }
2188                      }
2189                      // Event finishes on this day
2190                      else if($end_day == $weekday_date)
2191                      {
2192                          // Event runs all day
2193                          if($end_time == 2359)
2194                          {
2195                              $time_period = $lang->all_day;
2196                          }
2197                          else
2198                          {
2199                              $time_period = $lang->finishes.gmdate($mybb->settings['timeformat'], $event['endtime_user']);
2200                          }
2201                      }
2202                      // Event is in the middle
2203                      else
2204                      {
2205                          $time_period = $lang->all_day;
2206                      }
2207                  }
2208                  $event_time = '';
2209                  if($time_period)
2210                  {
2211                      eval("\$event_time = \"".$templates->get("calendar_weekview_day_event_time")."\";");
2212                  }
2213                  if($event['private'] == 1)
2214                  {
2215                      $event_class = " private_event";
2216                  }
2217                  else
2218                  {
2219                      $event_class = " public_event";
2220                  }
2221                  if($event['visible'] == 0)
2222                  {
2223                      $event_class .= " trow_shaded";
2224                  }
2225                  eval("\$day_events .= \"".$templates->get("calendar_weekview_day_event")."\";");
2226              }
2227          }
2228  
2229          // Birthdays on this day?
2230          $day_birthdays = $calendar_link = $birthday_lang = '';
2231          if($calendar['showbirthdays'] && is_array($birthdays) && array_key_exists("{$weekday_day}-{$weekday_month}", $birthdays))
2232          {
2233              $bday_count = count($birthdays["$weekday_day-$weekday_month"]);
2234              if($bday_count > 1)
2235              {
2236                  $birthday_lang = $lang->birthdays;
2237              }
2238              else
2239              {
2240                  $birthday_lang = $lang->birthday;
2241              }
2242  
2243              $calendar_link = get_calendar_link($calendar['cid'], $weekday_year, $weekday_month, $weekday_day);
2244              eval("\$day_birthdays = \"".$templates->get("calendar_weekview_day_birthdays")."\";");
2245          }
2246  
2247          $day_link = get_calendar_link($calendar['cid'], $weekday_year, $weekday_month, $weekday_day);
2248          if(!isset($day_bits[$weekday_month]))
2249          {
2250              $day_bits[$weekday_month] = '';
2251          }
2252          eval("\$day_bits[$weekday_month] .= \"".$templates->get("calendar_weekview_day")."\";");
2253          $day_events = $day_birthdays = "";
2254          $weekday_date = adodb_gmmktime(0, 0, 0, $weekday_month, $weekday_day+1, $weekday_year);
2255      }
2256  
2257      // Now we build our month headers
2258      $mini_calendars = $weekday_bits = '';
2259      foreach($week_months as $month)
2260      {
2261          $weekday_month = $monthnames[$month[0]];
2262          $weekday_year = $month[1];
2263  
2264          // Fetch mini calendar for each month in this week
2265          $mini_calendars .= build_mini_calendar($calendar, $month[0], $weekday_year, $events_cache)."<br />";
2266  
2267          // Fetch out the days for this month
2268          $days = $day_bits[$month[0]];
2269  
2270          eval("\$weekday_bits .= \"".$templates->get("calendar_weekview_month")."\";");
2271      }
2272  
2273      $addevent = '';
2274      if($mybb->usergroup['canaddevents'] == 1)
2275      {
2276          eval("\$addevent = \"".$templates->get("calendar_addeventlink")."\";");
2277      }
2278  
2279      // Now output the page
2280      $plugins->run_hooks("calendar_weekview_end");
2281  
2282      eval("\$weekview = \"".$templates->get("calendar_weekview")."\";");
2283      output_page($weekview);
2284  }
2285  
2286  // Showing a calendar
2287  if(!$mybb->input['action'])
2288  {
2289      // Showing a particular calendar
2290      if($mybb->input['calendar'])
2291      {
2292          $query = $db->simple_select("calendars", "*", "cid='{$mybb->input['calendar']}'");
2293          $calendar = $db->fetch_array($query);
2294      }
2295      // Showing the default calendar
2296      else
2297      {
2298          $query = $db->simple_select("calendars", "*", "", array('order_by' => 'disporder', 'limit' => 1));
2299          $calendar = $db->fetch_array($query);
2300      }
2301  
2302      // Invalid calendar?
2303      if(!$calendar['cid'])
2304      {
2305          error($lang->invalid_calendar);
2306      }
2307  
2308      // Do we have permission to view this calendar?
2309      $calendar_permissions = get_calendar_permissions($calendar['cid']);
2310  
2311      if($calendar_permissions['canviewcalendar'] != 1)
2312      {
2313          error_no_permission();
2314      }
2315  
2316      $plugins->run_hooks("calendar_main_view");
2317  
2318      // Incoming year?
2319      if(isset($mybb->input['year']) && $mybb->get_input('year', MyBB::INPUT_INT) <= my_date("Y")+5 && $mybb->get_input('year', MyBB::INPUT_INT) >= 1901)
2320      {
2321          $year = $mybb->get_input('year', MyBB::INPUT_INT);
2322      }
2323      else
2324      {
2325          $year = my_date("Y");
2326      }
2327  
2328      // Then the month
2329      $mybb->input['month'] = $mybb->get_input('month', MyBB::INPUT_INT);
2330      if($mybb->input['month'] >= 1 && $mybb->input['month'] <= 12)
2331      {
2332          $month = $mybb->input['month'];
2333      }
2334      else
2335      {
2336          $month = my_date("n");
2337      }
2338  
2339      add_breadcrumb(htmlspecialchars_uni($calendar['name']), get_calendar_link($calendar['cid']));
2340      add_breadcrumb("$monthnames[$month] $year", get_calendar_link($calendar['cid'], $year, $month));
2341  
2342      $prev_month = get_prev_month($month, $year);
2343  
2344      $prev_month_link = '';
2345      if($prev_month['year'] >= 1901)
2346      {
2347          $prev_link = get_calendar_link($calendar['cid'], $prev_month['year'], $prev_month['month']);
2348  
2349          eval("\$prev_month_link = \"".$templates->get("calendar_prevlink")."\";");
2350      }
2351  
2352      $next_month = get_next_month($month, $year);
2353  
2354      $next_month_link = '';
2355      if($next_month['year'] <= my_date("Y")+5)
2356      {
2357          $next_link = get_calendar_link($calendar['cid'], $next_month['year'], $next_month['month']);
2358  
2359          eval("\$next_month_link = \"".$templates->get("calendar_nextlink")."\";");
2360      }
2361  
2362      $sep = '';
2363      if(!empty($prev_month_link) && !empty($next_month_link))
2364      {
2365          $sep = " | ";
2366      }
2367  
2368      // Start constructing the calendar
2369  
2370      $weekdays = fetch_weekday_structure($calendar['startofweek']);
2371  
2372      $month_start_weekday = gmdate("w", adodb_gmmktime(0, 0, 0, $month, $calendar['startofweek']+1, $year));
2373  
2374      $prev_month_days = gmdate("t", adodb_gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year']));
2375  
2376      // This is if we have days in the previous month to show
2377      if($month_start_weekday != $weekdays[0] || $calendar['startofweek'] != 0)
2378      {
2379          $prev_days = $day = gmdate("t", adodb_gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year']));
2380          $day -= array_search(($month_start_weekday), $weekdays);
2381          $day += $calendar['startofweek']+1;
2382          if($day > $prev_month_days+1)
2383          {
2384              // Go one week back
2385              $day -= 7;
2386          }
2387          $calendar_month = $prev_month['month'];
2388          $calendar_year = $prev_month['year'];
2389      }
2390      else
2391      {
2392          $day = $calendar['startofweek']+1;
2393          $calendar_month = $month;
2394          $calendar_year = $year;
2395      }
2396  
2397      // So now we fetch events for this month (nb, cache events for past month, current month and next month for mini calendars too)
2398      $start_timestamp = adodb_gmmktime(0, 0, 0, $calendar_month, $day, $calendar_year);
2399      $num_days = gmdate("t", adodb_gmmktime(0, 0, 0, $month, 1, $year));
2400  
2401      $month_end_weekday = gmdate("w", adodb_gmmktime(0, 0, 0, $month, $num_days, $year));
2402      $next_days = 6-$month_end_weekday+$calendar['startofweek'];
2403  
2404      // More than a week? Go one week back
2405      if($next_days >= 7)
2406      {
2407          $next_days -= 7;
2408      }
2409      if($next_days > 0)
2410      {
2411          $end_timestamp = adodb_gmmktime(23, 59, 59, $next_month['month'], $next_days, $next_month['year']);
2412      }
2413      else
2414      {
2415          // We don't need days from the next month
2416          $end_timestamp = adodb_gmmktime(23, 59, 59, $month, $num_days, $year);
2417      }
2418  
2419      $events_cache = get_events($calendar, $start_timestamp, $end_timestamp, $calendar_permissions['canmoderateevents']);
2420  
2421      // Fetch birthdays
2422      if($calendar['showbirthdays'])
2423      {
2424          $bday_months = array($month, $prev_month['month'], $next_month['month']);
2425          $birthdays = get_birthdays($bday_months);
2426      }
2427  
2428      $today = my_date("dnY");
2429      $weekday_headers = '';
2430  
2431      // Build weekday headers
2432      foreach($weekdays as $weekday)
2433      {
2434          $weekday_name = fetch_weekday_name($weekday);
2435          eval("\$weekday_headers .= \"".$templates->get("calendar_weekdayheader")."\";");
2436      }
2437  
2438      $in_month = 0;
2439      $day_bits = $calendar_rows = '';
2440      for($row = 0; $row < 6; ++$row) // Iterate weeks (each week gets a row)
2441      {
2442          foreach($weekdays as $weekday_id => $weekday)
2443          {
2444              // Current month always starts on 1st row
2445              if($row == 0 && $day == $calendar['startofweek']+1)
2446              {
2447                  $in_month = 1;
2448                  $calendar_month = $month;
2449                  $calendar_year = $year;
2450              }
2451              else if($calendar_month == $prev_month['month'] && $day > $prev_month_days)
2452              {
2453                  $day = 1;
2454                  $in_month = 1;
2455                  $calendar_month = $month;
2456                  $calendar_year = $year;
2457              }
2458              else if($day > $num_days && $calendar_month != $prev_month['month'])
2459              {
2460                  $in_month = 0;
2461                  $calendar_month = $next_month['month'];
2462                  $calendar_year = $next_month['year'];
2463                  $day = 1;
2464                  if($calendar_month == $month)
2465                  {
2466                      $in_month = 1;
2467                  }
2468              }
2469  
2470              if($weekday_id == 0)
2471              {
2472                  $week_stamp = adodb_gmmktime(0, 0, 0, $calendar_month, $day, $calendar_year);
2473                  $week_link = get_calendar_week_link($calendar['cid'], $week_stamp);
2474              }
2475  
2476              if($weekday_id == 0 && $calendar_month == $next_month['month'])
2477              {
2478                  break;
2479              }
2480  
2481              // Any events on this specific day?
2482              $day_events = $event_lang = '';
2483              if(is_array($events_cache) && array_key_exists("{$day}-{$calendar_month}-{$calendar_year}", $events_cache))
2484              {
2485                  $total_events = count($events_cache["$day-$calendar_month-$calendar_year"]);
2486                  if($total_events > $calendar['eventlimit'] && $calendar['eventlimit'] != 0)
2487                  {
2488                      if($total_events > 1)
2489                      {
2490                          $event_lang = $lang->events;
2491                      }
2492                      else
2493                      {
2494                          $event_lang = $lang->event;
2495                      }
2496  
2497                      $calendar['link'] = get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day);
2498                      eval("\$day_events = \"".$templates->get("calendar_weekrow_day_events")."\";");
2499                  }
2500                  else
2501                  {
2502                      foreach($events_cache["$day-$calendar_month-$calendar_year"] as $event)
2503                      {
2504                          $event['eventlink'] = get_event_link($event['eid']);
2505                          $event['fullname'] = htmlspecialchars_uni($event['name']);
2506                          if(my_strlen($event['name']) > 15)
2507                          {
2508                              $event['name'] = my_substr($event['name'], 0, 15) . "...";
2509                          }
2510                          $event['name'] = htmlspecialchars_uni($event['name']);
2511                          if($event['private'] == 1)
2512                          {
2513                              $event_class = " private_event";
2514                          }
2515                          else
2516                          {
2517                              $event_class = " public_event";
2518                          }
2519                          if($event['visible'] == 0)
2520                          {
2521                              $event_class .= " trow_shaded";
2522                          }
2523                          eval("\$day_events .= \"".$templates->get("calendar_eventbit")."\";");
2524                      }
2525                  }
2526              }
2527  
2528              // Birthdays on this day?
2529              $day_birthdays = $birthday_lang = '';
2530              if($calendar['showbirthdays'] && is_array($birthdays) && array_key_exists("$day-$calendar_month", $birthdays))
2531              {
2532                  $bday_count = count($birthdays["$day-$calendar_month"]);
2533                  if($bday_count > 1)
2534                  {
2535                      $birthday_lang = $lang->birthdays;
2536                  }
2537                  else
2538                  {
2539                      $birthday_lang = $lang->birthday;
2540                  }
2541  
2542                  $calendar['link'] = get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day);
2543                  eval("\$day_birthdays = \"".$templates->get("calendar_weekrow_day_birthdays")."\";");
2544              }
2545  
2546              $day_link = get_calendar_link($calendar['cid'], $calendar_year, $calendar_month, $day);
2547  
2548              // Is the current day
2549              if($day.$calendar_month.$year == $today && $month == $calendar_month)
2550              {
2551                  $day_class = "trow_sep";
2552              }
2553              // Not in this month
2554              else if($in_month == 0)
2555              {
2556                  $day_class = "trow1";
2557              }
2558              // Just a normal day in this month
2559              else
2560              {
2561                  $day_class = "trow2";
2562              }
2563              eval("\$day_bits .= \"".$templates->get("calendar_weekrow_day")."\";");
2564              $day_birthdays = $day_events = "";
2565              ++$day;
2566          }
2567          if($day_bits)
2568          {
2569              eval("\$calendar_rows .= \"".$templates->get("calendar_weekrow")."\";");
2570          }
2571          $day_bits = "";
2572      }
2573  
2574      $yearsel = '';
2575      for($year_sel = my_date("Y"); $year_sel < (my_date("Y") + 5); ++$year_sel)
2576      {
2577          eval("\$yearsel .= \"".$templates->get("calendar_year_sel")."\";");
2578      }
2579  
2580      $addevent = '';
2581      if($mybb->usergroup['canaddevents'] == 1)
2582      {
2583          eval("\$addevent = \"".$templates->get("calendar_addeventlink")."\";");
2584      }
2585  
2586      $plugins->run_hooks("calendar_end");
2587  
2588      eval("\$calendar = \"".$templates->get("calendar")."\";");
2589      output_page($calendar);
2590  }


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