Esempio n. 1
0
require_once MYBB_ROOT . "inc/class_parser.php";
$parser = new postParser();
// Load global language phrases
$lang->load("calendar");
if ($mybb->settings['enablecalendar'] == 0) {
    error($lang->calendar_disabled);
}
if ($mybb->usergroup['canviewcalendar'] == 0) {
    error_no_permission();
}
$monthnames = array("offset", $lang->alt_month_1, $lang->alt_month_2, $lang->alt_month_3, $lang->alt_month_4, $lang->alt_month_5, $lang->alt_month_6, $lang->alt_month_7, $lang->alt_month_8, $lang->alt_month_9, $lang->alt_month_10, $lang->alt_month_11, $lang->alt_month_12);
$plugins->run_hooks("calendar_start");
// Make navigation
add_breadcrumb($lang->nav_calendar, "calendar.php");
$mybb->input['calendar'] = $mybb->get_input('calendar', MyBB::INPUT_INT);
$calendars = cache_calendars();
$calendar_jump = '';
if (count($calendars) > 1) {
    $calendar_jump = build_calendar_jump($mybb->input['calendar']);
}
$mybb->input['action'] = $mybb->get_input('action');
// Add an event
if ($mybb->input['action'] == "do_addevent" && $mybb->request_method == "post") {
    $query = $db->simple_select("calendars", "*", "cid='{$mybb->input['calendar']}'");
    $calendar = $db->fetch_array($query);
    // Invalid calendar?
    if (!$calendar) {
        error($lang->invalid_calendar);
    }
    // Do we have permission to view this calendar or post events?
    $calendar_permissions = get_calendar_permissions($calendar['cid']);
/**
 * Build a calendar select list to jump between calendars
 *
 * @param int The selected calendar ID
 * @return string The calendar select
 */
function build_calendar_jump($selected = 0)
{
    global $db, $mybb, $templates, $lang, $gobutton;
    $calendar_permissions = get_calendar_permissions();
    $calendars = cache_calendars();
    if (!is_array($calendars)) {
        return;
    }
    $jump_options = '';
    foreach ($calendars as $calendar) {
        if ($calendar_permissions[$calendar['cid']]['canviewcalendar'] == 0) {
            continue;
        }
        $calendar['name'] = htmlspecialchars_uni($calendar['name']);
        $sel = "";
        if ($selected == $calendar['cid'] || $selected == 0 && $calendar['disporder'] == 1) {
            $sel = "selected=\"selected\"";
        }
        eval("\$jump_options .= \"" . $templates->get("calendar_jump_option") . "\";");
    }
    eval("\$calendar_jump = \"" . $templates->get("calendar_jump") . "\";");
    return $calendar_jump;
}
/**
 * Build a calendar select list to jump between calendars
 *
 * @param int The selected calendar ID
 * @return string The calendar select
 */
function build_calendar_jump($selected = 0)
{
    global $db, $mybb;
    $calendar_permissions = get_calendar_permissions();
    $calendars = cache_calendars();
    if (!is_array($calendars)) {
        return;
    }
    foreach ($calendars as $calendar) {
        if ($calendar_permissions[$calendar['cid']]['canviewcalendar'] == 0) {
            continue;
        }
        $calendar['name'] = htmlspecialchars_uni($calendar['name']);
        $sel = "";
        if ($selected == $calendar['cid'] || $selected == 0 && $calendar['disporder'] == 1) {
            $sel = "selected=\"selected\"";
        }
        $jump_options .= "<option value=\"{$calendar['cid']}\" {$sel}>{$calendar['name']}</option>\n";
    }
    return "<select name=\"calendar\">\n{$jump_options}</select>";
}