Example #1
0
 public function CheckPrivileges($testPrivileges, $principal, $calendarId)
 {
     if (is_object($principal) && $principal instanceof CDavPrincipal) {
         $principal = $principal->Id();
     }
     if (!is_numeric($principal)) {
         return false;
     }
     $principal = IntVal($principal);
     $calendarIdNorm = implode("-", $calendarId);
     static $arCalendarPrivilegesCache = array();
     if (!isset($arCalendarPrivilegesCache[$calendarIdNorm][$principal])) {
         $arPriv = array();
         // $arPrivOrig = array('bAccess' => true/false, 'bReadOnly' => true/false, 'privateStatus' => 'time'/'title');
         $arPrivOrig = CCalendar::GetUserPermissionsForCalendar($calendarId, $principal);
         if ($arPrivOrig['bAccess']) {
             $arPriv[] = 'urn:ietf:params:xml:ns:caldav:read-free-busy';
             if (!isset($arPrivOrig['privateStatus']) || $arPrivOrig['privateStatus'] != 'time') {
                 $arPriv[] = 'DAV::read';
             }
             if (!$arPrivOrig['bReadOnly']) {
                 $arPriv[] = 'DAV:write';
                 $arPriv[] = 'DAV:bind';
                 $arPriv[] = 'DAV:unbind';
                 $arPriv[] = 'DAV:write-properties';
                 $arPriv[] = 'DAV:write-content';
             }
         }
         $arCalendarPrivilegesCache[$calendarIdNorm][$principal] = CDav::PackPrivileges($arPriv);
     }
     $testPrivilegesBits = CDav::PackPrivileges($testPrivileges);
     return ($arCalendarPrivilegesCache[$calendarIdNorm][$principal] & $testPrivilegesBits) > 0;
 }