Пример #1
0
/**
 * Fetch the calendar permissions for the current user for one or more calendars
 *
 * @param int Optional calendar ID. If none specified, permissions for all calendars are returned
 * @return array Array of permissions
 */
function get_calendar_permissions($cid = 0)
{
    global $db, $mybb;
    static $calendar_permissions;
    $calendars = cache_calendars();
    $group_permissions = array("canviewcalendar" => $mybb->usergroup['canviewcalendar'], "canaddevents" => $mybb->usergroup['canaddevents'], "canbypasseventmod" => $mybb->usergroup['canbypasseventmod'], "canmoderateevents" => $mybb->usergroup['canmoderateevents']);
    if (!is_array($calendars)) {
        return $group_permissions;
    }
    $gid = $mybb->user['usergroup'];
    if (isset($mybb->user['additionalgroups'])) {
        $gid .= "," . $mybb->user['additionalgroups'];
    }
    if (!is_array($calendar_permissions)) {
        $calendar_permissions = array();
        $query = $db->simple_select("calendarpermissions", "*");
        while ($permission = $db->fetch_array($query)) {
            $calendar_permissions[$permission['cid']][$permission['gid']] = $permission;
        }
        // Add in our usergroup permissions (if custom ones are set, these aren't added)
        if (is_array($calendar_permissions)) {
            foreach ($calendar_permissions as $calendar => $permission) {
                if (is_array($calendar_permissions[$calendar][$mybb->user['usergroup']])) {
                    // Already has permissions set
                    continue;
                }
                // Use the group permissions!
                $calendar_permissions[$calendar][$mybb->user['usergroup']] = $group_permissions;
                $calendar_permissions[$calendar][$mybb->user['usergroup']]['cid'] = $calendar;
                $calendar_permissions[$calendar][$mybb->user['usergroup']]['gid'] = $mybb->user['usergroup'];
            }
        }
    }
    if ($cid > 0) {
        if (isset($calendar_permissions[$cid])) {
            $permissions = fetch_calendar_permissions($cid, $gid, $calendar_permissions[$cid]);
        }
        if (empty($permissions)) {
            $permissions = $group_permissions;
        }
    } else {
        foreach ($calendars as $calendar) {
            if (isset($calendar_permissions[$calendar['cid']])) {
                $permissions[$calendar['cid']] = fetch_calendar_permissions($calendar['cid'], $gid, $calendar_permissions[$calendar['cid']]);
            }
            if (empty($permissions[$calendar['cid']])) {
                $permissions[$calendar['cid']] = $group_permissions;
            }
        }
    }
    return $permissions;
}
/**
 * Fetch the calendar permissions for the current user for one or more calendars
 *
 * @param int Optional calendar ID. If none specified, permissions for all calendars are returned
 * @return array Array of permissions
 */
function get_calendar_permissions($cid = 0)
{
    global $db, $mybb;
    static $calendar_permissions;
    $calendars = cache_calendars();
    $group_permissions = array("canviewcalendar" => $mybb->usergroup['canviewcalendar'], "canaddevents" => $mybb->usergroup['canaddevents'], "canbypasseventmod" => $mybb->usergroup['canbypasseventmod'], "canmoderateevents" => $mybb->usergroup['canmoderateevents']);
    if (!is_array($calendars)) {
        return $group_permissions;
    }
    $gid = $mybb->user['usergroup'];
    if (isset($mybb->user['additionalgroups'])) {
        $gid .= "," . $mybb->user['additionalgroups'];
    }
    if (!is_array($calendar_permissions)) {
        $calendar_permissions = array();
        $query = $db->simple_select("calendarpermissions", "*");
        while ($permission = $db->fetch_array($query)) {
            $calendar_permissions[$permission['cid']][$permission['gid']] = $permission;
        }
    }
    if ($cid > 0) {
        $permissions = fetch_calendar_permissions($cid, $gid, $calendar_permissions[$cid]);
        if (!$permissions) {
            $permissions = $group_permissions;
        }
    } else {
        foreach ($calendars as $calendar) {
            $permissions[$calendar['cid']] = fetch_calendar_permissions($calendar['cid'], $gid, $calendar_permissions[$calendar['cid']]);
            if (!$permissions[$calendar['cid']]) {
                $permissions[$calendar['cid']] = $group_permissions;
            }
        }
    }
    return $permissions;
}