1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
<?php
require_once 'app/controllers/calendar/calendar.php';
require_once 'app/controllers/authenticated_controller.php';
class Calendar_GroupController extends Calendar_CalendarController
{
public function before_filter(&$action, &$args)
{
$this->base = 'calendar/group/';
parent::before_filter($action, $args);
}
protected function createSidebar($active = 'week', $calendar = null)
{
parent::createSidebar($active, $calendar);
$sidebar = Sidebar::Get();
$actions = new ActionsWidget();
$actions->addLink(_('Termin anlegen'),
$this->url_for('calendar/group/edit'),
Icon::create('add'),
['data-dialog' => 'size=auto']);
$actions->addLink(_('Kalender freigeben'),
$this->url_for('calendar/single/manage_access/' . $GLOBALS['user']->id,
['group_filter' => $this->range_id]),
Icon::create('community'),
['id' => 'calendar-open-manageaccess',
'data-dialog' => '', 'data-dialogname' => 'manageaccess']);
$sidebar->addWidget($actions);
}
protected function getTitle($group)
{
$title = sprintf(_('Terminkalender der Gruppe "%s"'), $group->name);
return $title;
}
public function index_action()
{
// switch to the view the user has selected in his personal settings
$default_view = $this->settings['view'] ?: 'week';
$this->redirect($this->url_for('calendar/group/' . $default_view));
}
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);
$this->attendee_ids = [];
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 = [$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('/',
[$this->range_id, $this->event->event_id])));
return null;
}
$this->attendees = $this->event->attendees;
if (!Request::isXhr()) {
PageLayout::setTitle($this->getTitle($this->calendar, _('Termin bearbeiten')));
}
}
if (Config::get()->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",
_('Nutzer 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 Teilnehmende hinzufügen'))
// ->setDefaultSelectedUser($default_selected_user)
->setTitle(_('Mehrere Teilnehmende 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::postSuccess(_('Der Termin wurde nicht geändert.'));
$this->relocate('calendar/group/' . $this->last_view, ['atime' => $this->atime]);
}
} else {
PageLayout::postSuccess(_('Der Termin wurde gespeichert.'));
$this->relocate('calendar/group/' . $this->last_view, ['atime' => $this->atime]);
}
} else {
$this->createSidebar('edit', $this->calendar);
$this->createSidebarFilter();
$this->render_template('calendar/single/edit', $this->layout);
}
}
public function day_action($range_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->calendars[0] = SingleCalendar::getDayCalendar(
$GLOBALS['user']->id, $this->atime);
$group = $this->getGroup($this->calendars[0]);
foreach ($group->members as $member) {
$calendar = new SingleCalendar($member->user_id);
if ($calendar->havePermission(Calendar::PERMISSION_READABLE)) {
$this->calendars[] = SingleCalendar::getDayCalendar($calendar,
$this->atime, null, $this->restrictions);
}
}
PageLayout::setTitle($this->getTitle($group)
. ' - ' . _('Tagesansicht'));
Navigation::activateItem('/calendar/calendar');
$this->last_view = 'day';
$this->createSidebar('day');
$this->createSidebarFilter();
}
/**
* Returns the Statusgruppe for the given calendar.
*
* @param SingleCalendar The calendar of the group owner.
* @return Statusgruppen The found group.
* @throws AccessDeniedException If the group does not exists or the owner
* of the calendar is not the owner of the group.
*/
private function getGroup($calendar)
{
$group = Statusgruppen::find($this->range_id);
if (!$group) {
throw new AccessDeniedException();
}
// is the user the owner of this group
if ($group->range_id != $calendar->getRangeId()) {
// not the owner...
throw new AccessDeniedException();
}
return $group;
}
public function week_action($range_id = null)
{
$this->calendars = [];
$this->range_id = $range_id ?: $this->range_id;
$timestamp = mktime(12, 0, 0, date('n', $this->atime),
date('j', $this->atime), date('Y', $this->atime));
$monday = $timestamp - 86400 * (strftime('%u', $timestamp) - 1);
$day_count = $this->settings['type_week'] == 'SHORT' ? 5 : 7;
// one calendar for each day for the actual user
for ($i = 0; $i < $day_count; $i++) {
// one calendar holds the events of one day
$this->calendars[0][$i] =
SingleCalendar::getDayCalendar($GLOBALS['user']->id,
$monday + $i * 86400, null, $this->restrictions);
}
// check and get the group
$group = $this->getGroup($this->calendars[0][0]);
$n = 1;
foreach ($group->members as $member) {
$calendar = new SingleCalendar($member->user_id);
if ($calendar->havePermission(Calendar::PERMISSION_READABLE)) {
for ($i = 0; $i < $day_count; $i++) {
$this->calendars[$n][$i] =
SingleCalendar::getDayCalendar($member->user_id,
$monday + $i * 86400, null, $this->restrictions);
}
$n++;
}
}
PageLayout::setTitle($this->getTitle($group)
. ' - ' . _('Wochenansicht'));
Navigation::activateItem('/calendar/calendar');
$this->last_view = 'week';
$this->createSidebar('week');
$this->createSidebarFilter();
}
public function month_action($range_id = null)
{
$this->calendars = [];
$this->range_id = $range_id ?: $this->range_id;
$month_start = mktime(12, 0, 0, date('n', $this->atime), 1, date('Y', $this->atime));
$month_end = mktime(12, 0, 0, date('n', $this->atime), date('t', $this->atime), date('Y', $this->atime));
$adow = strftime('%u', $month_start) - 1;
$cor = date('n', $this->atime) == 3 ? 1 : 0;
$this->first_day = $month_start - $adow * 86400;
$this->last_day = ((42 - ($adow + date('t', $this->atime))) % 7 + $cor) * 86400 + $month_end;
// one calendar each day for the actual user
for ($start_day = $this->first_day; $start_day <= $this->last_day; $start_day += 86400) {
$this->calendars[0][] = SingleCalendar::getDayCalendar(
$GLOBALS['user']->id, $start_day, null, $this->restrictions);
}
// check and get the group
$group = $this->getGroup($this->calendars[0][0]);
$n = 1;
// get the calendars of the group members
foreach ($group->members as $member) {
$calendar = new SingleCalendar($member->user_id);
if ($calendar->havePermission(Calendar::PERMISSION_READABLE)) {
for ($start_day = $this->first_day; $start_day <= $this->last_day; $start_day += 86400) {
$this->calendars[$n][] =
SingleCalendar::getDayCalendar($member->user_id,
$start_day, null, $this->restrictions);
}
$n++;
}
}
PageLayout::setTitle($this->getTitle($group)
. ' - ' . _('Monatssicht'));
Navigation::activateItem('/calendar/calendar');
$this->last_view = 'month';
$this->createSidebar('month');
$this->createSidebarFilter();
}
public function year_action($range_id = null)
{
$this->calendars = [];
$this->count_lists = [];
$this->range_id = $range_id ?: $this->range_id;
$start = mktime(0, 0, 0, 1, 1, date('Y', $this->atime));
$end = mktime(23, 59, 59, 12, 31, date('Y', $this->atime));
$this->calendars[0] = new SingleCalendar(
$GLOBALS['user']->id, $start, $end);
$this->count_lists[0] = $this->calendars[0]->getListCountEvents();
// check and get the group
$group = $this->getGroup($this->calendars[0]);
$n = 1;
// get the calendars of the group members
foreach ($group->members as $member) {
$calendar = new SingleCalendar($member->user_id);
if ($calendar->havePermission(Calendar::PERMISSION_READABLE)) {
$this->calendars[$n] = $calendar->setStart($start)->setEnd($end);
$this->count_lists[$n] = $this->calendars[$n]->getListCountEvents();
$n++;
}
}
PageLayout::setTitle($this->getTitle($group)
. ' - ' . _('Jahresansicht'));
Navigation::activateItem("/calendar/calendar");
$this->last_view = 'year';
$this->createSidebar('year');
$this->createSidebarFilter();
}
}
|