Exemple #1
0
 public function edit_action($range_id = null, $event_id = null)
 {
     $this->range_id = $range_id ?: $this->range_id;
     // get group and the calendars of the members
     // the first calendar is the calendar of the actual user
     $this->calendar = new SingleCalendar($GLOBALS['user']->id);
     $group = $this->getGroup($this->calendar);
     if ($group) {
         $calendar_owners = CalendarUser::getOwners($GLOBALS['user']->id, Calendar::PERMISSION_WRITABLE)->pluck('owner_id');
         $members = $group->members->pluck('user_id');
         $user_id = Request::option('user_id');
         $this->attendee_ids = array_intersect($calendar_owners, $members);
         $this->attendee_ids[] = $GLOBALS['user']->id;
         if ($user_id && in_array($user_id, $this->attendee_ids)) {
             $this->attendee_ids = array($user_id);
         }
     }
     $this->event = $this->calendar->getEvent($event_id);
     if ($this->event->isNew()) {
         $this->event = $this->calendar->getNewEvent();
         if (Request::get('isdayevent')) {
             $this->event->setStart(mktime(0, 0, 0, date('n', $this->atime), date('j', $this->atime), date('Y', $this->atime)));
             $this->event->setEnd(mktime(23, 59, 59, date('n', $this->atime), date('j', $this->atime), date('Y', $this->atime)));
         } else {
             $this->event->setStart($this->atime);
             $this->event->setEnd($this->atime + 3600);
         }
         $this->event->setAuthorId($GLOBALS['user']->id);
         $this->event->setEditorId($GLOBALS['user']->id);
         $this->event->setAccessibility('PRIVATE');
         if ($this->attendee_ids) {
             foreach ($this->attendee_ids as $attendee_id) {
                 $attendee_event = clone $this->event;
                 $attendee_event->range_id = $attendee_id;
                 $this->attendees[] = $attendee_event;
             }
         }
         if (!Request::isXhr()) {
             PageLayout::setTitle($this->getTitle($this->calendar, _('Neuer Termin')));
         }
     } else {
         // open read only events and course events not as form
         // show information in dialog instead
         if (!$this->event->havePermission(Event::PERMISSION_WRITABLE) || $this->event instanceof CourseEvent) {
             $this->redirect($this->url_for('calendar/single/event/' . implode('/', array($this->range_id, $this->event->event_id))));
             return null;
         }
         $this->attendees = $this->event->getAttendees();
         if (!Request::isXhr()) {
             PageLayout::setTitle($this->getTitle($this->calendar, _('Termin bearbeiten')));
         }
     }
     if (get_config('CALENDAR_GROUP_ENABLE') && $this->calendar->getRange() == Calendar::RANGE_USER) {
         $search_obj = new SQLSearch("SELECT auth_user_md5.user_id, {$GLOBALS['_fullname_sql']['full_rev']} as fullname, username, perms " . "FROM calendar_user " . "LEFT JOIN auth_user_md5 ON calendar_user.owner_id = auth_user_md5.user_id " . "LEFT JOIN user_info ON (auth_user_md5.user_id = user_info.user_id) " . 'WHERE calendar_user.user_id = ' . DBManager::get()->quote($GLOBALS['user']->id) . ' AND calendar_user.permission > ' . Event::PERMISSION_READABLE . ' AND (username LIKE :input OR Vorname LIKE :input ' . "OR CONCAT(Vorname,' ',Nachname) LIKE :input " . "OR CONCAT(Nachname,' ',Vorname) LIKE :input " . "OR Nachname LIKE :input OR {$GLOBALS['_fullname_sql']['full_rev']} LIKE :input " . ") ORDER BY fullname ASC", _('Person suchen'), 'user_id');
         $this->quick_search = QuickSearch::get('user_id', $search_obj)->fireJSFunctionOnSelect('STUDIP.Messages.add_adressee');
         //      $default_selected_user = array($this->calendar->getRangeId());
         $this->mps = MultiPersonSearch::get('add_adressees')->setLinkText(_('Mehrere Teilnehmer hinzufügen'))->setTitle(_('Mehrere Teilnehmer hinzufügen'))->setExecuteURL($this->url_for($this->base . 'edit'))->setJSFunctionOnSubmit('STUDIP.Messages.add_adressees')->setSearchObject($search_obj);
         $owners = SimpleORMapCollection::createFromArray(CalendarUser::findByUser_id($this->calendar->getRangeId()))->pluck('owner_id');
         foreach (Calendar::getGroups($GLOBALS['user']->id) as $group) {
             $this->mps->addQuickfilter($group->name, $group->members->filter(function ($member) use($owners) {
                 if (in_array($member->user_id, $owners)) {
                     return $member;
                 }
             })->pluck('user_id'));
         }
     }
     $stored = false;
     if (Request::submitted('store')) {
         $stored = $this->storeEventData($this->event, $this->calendar);
     }
     if ($stored !== false) {
         // switch back to group context
         $this->range_id = $group->getId();
         if ($stored === 0) {
             if (Request::isXhr()) {
                 header('X-Dialog-Close: 1');
                 exit;
             } else {
                 PageLayout::postMessage(MessageBox::success(_('Der Termin wurde nicht geändert.')));
                 $this->relocate('calendar/group/' . $this->last_view, array('atime' => $this->atime));
             }
         } else {
             PageLayout::postMessage(MessageBox::success(_('Der Termin wurde gespeichert.')));
             $this->relocate('calendar/group/' . $this->last_view, array('atime' => $this->atime));
         }
     } else {
         $this->createSidebar('edit', $this->calendar);
         $this->createSidebarFilter();
         $this->render_template('calendar/single/edit', $this->layout);
     }
 }
Exemple #2
0
 /**
  * Retrieves all contact groups (statusgruppen) owned by the given user
  * where at least one member has granted access to his calender for the user.
  *
  * @param string $user_id User id of the owner.
  * @return type
  */
 public static function getGroups($user_id)
 {
     $groups = array();
     $calendar_owners = CalendarUser::getOwners($user_id)->pluck('owner_id');
     $sg_groups = SimpleORMapCollection::createFromArray(Statusgruppen::findByRange_id($user_id))->orderBy('position')->pluck('statusgruppe_id');
     if (sizeof($calendar_owners)) {
         $sg_users = StatusgruppeUser::findBySQL('statusgruppe_id IN(?) AND user_id IN(?)', array($sg_groups, $calendar_owners));
         foreach ($sg_users as $sg_user) {
             $groups[$sg_user->group->id] = $sg_user->group;
         }
     }
     return $groups;
 }
Exemple #3
0
                        <? foreach ($groups as $group) : ?>
                            <option value="<?php 
echo $group->getId();
?>
"<?php 
echo $range_id == $group->getId() ? ' selected' : '';
?>
>
                                 <?php 
echo htmlReady($group->name);
?>
                            </option>
                        <? endforeach ?>
                        </optgroup>
                    <? endif; ?>
                    <? $calendar_users = CalendarUser::getOwners($GLOBALS['user']->id); ?>
                    <? if (count($calendar_users)) : ?>
                        <optgroup style="font-weight:bold;" label="<?php 
echo _('Einzelkalender:');
?>
">
                        <? foreach ($calendar_users as $calendar_user) : ?>
                            <option value="<?php 
echo $calendar_user->owner_id;
?>
"<?php 
echo $range_id == $calendar_user->owner_id ? ' selected' : '';
?>
>
                                <?php 
echo htmlReady($calendar_user->owner->getFullname());