示例#1
0
 /**
  * Returns the permission of the given user for this calendar.
  *
  * @param string $user_id User id.
  * @return int The calendar permission.
  */
 public function getPermissionByUser($user_id = null)
 {
     static $user_permission = array();
     $user_id = $user_id ?: $GLOBALS['user']->id;
     $id = $user_id . $this->getRangeId();
     if ($user_permission[$id]) {
         return $user_permission[$id];
     }
     // own calendar
     if ($this->range == Calendar::RANGE_USER && $this->getRangeId() == $user_id) {
         $user_permission[$id] = Calendar::PERMISSION_OWN;
         return $user_permission[$id];
     }
     switch ($this->type) {
         case 'User':
             // alle Dozenten haben gegenseitig schreibenden Zugriff, ab dozent immer schreibenden Zugriff
             /*
                             if ($GLOBALS['perm']->have_perm('dozent') && $GLOBALS['perm']->get_perm($this->range_object->getId()) == 'dozent') {
                return Calendar::PERMISSION_WRITABLE;
                             }
             *
             */
             $cal_user = CalendarUser::find(array($this->getRangeId(), $user_id));
             if ($cal_user) {
                 switch ($cal_user->permission) {
                     case 1:
                         $user_permission[$id] = Calendar::PERMISSION_FORBIDDEN;
                         break;
                     case 2:
                         $user_permission[$id] = Calendar::PERMISSION_READABLE;
                         break;
                     case 4:
                         $user_permission[$id] = Calendar::PERMISSION_WRITABLE;
                         break;
                     default:
                         $user_permission[$id] = Calendar::PERMISSION_FORBIDDEN;
                 }
             } else {
                 $user_permission[$id] = Calendar::PERMISSION_FORBIDDEN;
             }
             break;
             /*
                         case 'group' :
                             $stmt = DBManager::get()->prepare('SELECT range_id FROM statusgruppen WHERE statusgruppe_id = ?');
                             $stmt->execute(array($range_id));
                             $result = $stmt->fetch(PDO::FETCH_ASSOC);
                             if ($result) {
                if ($result['range_id'] == $user_id) {
                    return Calendar::PERMISSION_OWN;
                }
                             }
                             return Calendar::PERMISSION_FORBIDDEN;
             *
             */
         /*
                     case 'group' :
                         $stmt = DBManager::get()->prepare('SELECT range_id FROM statusgruppen WHERE statusgruppe_id = ?');
                         $stmt->execute(array($range_id));
                         $result = $stmt->fetch(PDO::FETCH_ASSOC);
                         if ($result) {
            if ($result['range_id'] == $user_id) {
                return Calendar::PERMISSION_OWN;
            }
                         }
                         return Calendar::PERMISSION_FORBIDDEN;
         *
         */
         case 'Course':
             switch ($GLOBALS['perm']->get_studip_perm($this->range_object->getId(), $user_id)) {
                 case 'user':
                 case 'autor':
                     $user_permission[$id] = Calendar::PERMISSION_READABLE;
                     break;
                 case 'tutor':
                 case 'dozent':
                 case 'admin':
                 case 'root':
                     $user_permission[$id] = Calendar::PERMISSION_WRITABLE;
                     break;
                 default:
                     $user_permission[$id] = Calendar::PERMISSION_FORBIDDEN;
             }
             break;
         case 'Institute':
             switch ($GLOBALS['perm']->get_studip_perm($this->range_object->getId(), $user_id)) {
                 case 'user':
                     $user_permission[$id] = Calendar::PERMISSION_READABLE;
                     break;
                 case 'autor':
                     $user_permission[$id] = Calendar::PERMISSION_READABLE;
                     break;
                 case 'tutor':
                 case 'dozent':
                 case 'admin':
                 case 'root':
                     $user_permission[$id] = Calendar::PERMISSION_WRITABLE;
                     break;
                 default:
                     // readable for all
                     $user_permission[$id] = Calendar::PERMISSION_READABLE;
             }
             break;
         default:
             $user_permission[$id] = Calendar::PERMISSION_FORBIDDEN;
     }
     return $user_permission[$id];
 }
示例#2
0
 private function getUserCalendarPermission($user_id)
 {
     $permission = Event::PERMISSION_FORBIDDEN;
     $accessibility = $this->getAccessibility();
     if ($this->user->id) {
         if ($user_id != $this->user->id) {
             if ($accessibility == 'PUBLIC') {
                 $permission = Event::PERMISSION_READABLE;
             }
             $calendar_user = CalendarUser::find(array($this->user->getId(), $user_id));
             if ($calendar_user) {
                 if ($accessibility == 'CONFIDENTIAL') {
                     if ($this->event->calendars->findOneBy('range_id', $user_id)) {
                         if ($calendar_user->permission == Calendar::PERMISSION_WRITABLE) {
                             $permission = Event::PERMISSION_WRITABLE;
                         } else {
                             $permission = Event::PERMISSION_READABLE;
                         }
                     } else {
                         $permission = Event::PERMISSION_CONFIDENTIAL;
                     }
                 } else {
                     if ($calendar_user->permission == Calendar::PERMISSION_WRITABLE) {
                         $permission = Event::PERMISSION_WRITABLE;
                     } else {
                         $permission = Event::PERMISSION_READABLE;
                     }
                 }
             }
         } else {
             $permission = Event::PERMISSION_WRITABLE;
         }
     }
     return $permission;
 }
示例#3
0
文件: single.php 项目: ratbird/hope
 public function manage_access_action($range_id = null)
 {
     $this->range_id = $range_id ?: $this->range_id;
     $this->calendar = new SingleCalendar($this->range_id);
     $all_calendar_users = CalendarUser::getUsers($this->calendar->getRangeId());
     $this->filter_groups = Statusgruppen::findByRange_id($this->calendar->getRangeId());
     $this->users = array();
     $this->group_filter_selected = Request::option('group_filter', 'list');
     if ($this->group_filter_selected != 'list') {
         $contact_group = Statusgruppen::find($this->group_filter_selected);
         $calendar_users = array();
         foreach ($contact_group->members as $member) {
             $calendar_users[] = new CalendarUser(array($this->calendar->getRangeId(), $member->user_id));
         }
         $this->calendar_users = SimpleORMapCollection::createFromArray($calendar_users);
     } else {
         $this->group_filter_selected = 'list';
         $this->calendar_users = $all_calendar_users;
     }
     $this->own_perms = array();
     foreach ($this->calendar_users as $calendar_user) {
         $other_user = CalendarUser::find(array($calendar_user->user_id, $this->calendar->getRangeId()));
         if ($other_user) {
             $this->own_perms[$calendar_user->user_id] = $other_user->permission;
         } else {
             $this->own_perms[$calendar_user->user_id] = Calendar::PERMISSION_FORBIDDEN;
         }
         $this->users[strtoupper(SimpleCollection::translitLatin1($calendar_user->nachname[0]))][] = $calendar_user;
     }
     ksort($this->users);
     $this->users = array_map(function ($g) {
         return SimpleCollection::createFromArray($g)->orderBy('nachname, vorname');
     }, $this->users);
     $this->mps = MultiPersonSearch::get('calendar-manage_access')->setTitle(_('Personhinzufügen'))->setLinkText(_('Person hinzufügen'))->setDefaultSelectedUser($all_calendar_users->pluck('user_id'))->setJSFunctionOnSubmit('STUDIP.CalendarDialog.closeMps')->setExecuteURL($this->url_for('calendar/single/add_users/' . $this->calendar->getRangeId()))->setSearchObject(new StandardSearch('user_id'));
     PageLayout::setTitle($this->getTitle($this->calendar, _('Kalender freigeben')));
     $this->createSidebar('manage_access', $this->calendar);
     $this->createSidebarFilter();
 }