Merge pull request #9731 from MrPetovan/task/various-theme-changes
[friendica.git/.git] / mod / events.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  * The events module
21  */
22
23 use Friendica\App;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Widget\CalendarExport;
26 use Friendica\Core\ACL;
27 use Friendica\Core\Logger;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\Theme;
30 use Friendica\Core\Worker;
31 use Friendica\Database\DBA;
32 use Friendica\DI;
33 use Friendica\Model\Contact;
34 use Friendica\Model\Event;
35 use Friendica\Model\Item;
36 use Friendica\Model\User;
37 use Friendica\Module\BaseProfile;
38 use Friendica\Module\Security\Login;
39 use Friendica\Util\DateTimeFormat;
40 use Friendica\Util\Strings;
41 use Friendica\Util\Temporal;
42 use Friendica\Worker\Delivery;
43
44 function events_init(App $a)
45 {
46         if (!local_user()) {
47                 return;
48         }
49
50         // If it's a json request abort here because we don't
51         // need the widget data
52         if ($a->argc > 1 && $a->argv[1] === 'json') {
53                 return;
54         }
55
56         if (empty(DI::page()['aside'])) {
57                 DI::page()['aside'] = '';
58         }
59
60         $cal_widget = CalendarExport::getHTML();
61
62         DI::page()['aside'] .= $cal_widget;
63
64         return;
65 }
66
67 function events_post(App $a)
68 {
69         Logger::debug('post', ['request' => $_REQUEST]);
70         if (!local_user()) {
71                 return;
72         }
73
74         $event_id = !empty($_POST['event_id']) ? intval($_POST['event_id']) : 0;
75         $cid = !empty($_POST['cid']) ? intval($_POST['cid']) : 0;
76         $uid = local_user();
77
78         $start_text  = Strings::escapeHtml($_REQUEST['start_text'] ?? '');
79         $finish_text = Strings::escapeHtml($_REQUEST['finish_text'] ?? '');
80
81         $adjust   = intval($_POST['adjust'] ?? 0);
82         $nofinish = intval($_POST['nofinish'] ?? 0);
83
84         $share = intval($_POST['share'] ?? 0);
85
86         // The default setting for the `private` field in event_store() is false, so mirror that
87         $private_event = false;
88
89         $start  = DBA::NULL_DATETIME;
90         $finish = DBA::NULL_DATETIME;
91
92         if ($start_text) {
93                 $start = $start_text;
94         }
95
96         if ($finish_text) {
97                 $finish = $finish_text;
98         }
99
100         if ($adjust) {
101                 $start = DateTimeFormat::convert($start, 'UTC', date_default_timezone_get());
102                 if (!$nofinish) {
103                         $finish = DateTimeFormat::convert($finish, 'UTC', date_default_timezone_get());
104                 }
105         } else {
106                 $start = DateTimeFormat::utc($start);
107                 if (!$nofinish) {
108                         $finish = DateTimeFormat::utc($finish);
109                 }
110         }
111
112         // Don't allow the event to finish before it begins.
113         // It won't hurt anything, but somebody will file a bug report
114         // and we'll waste a bunch of time responding to it. Time that
115         // could've been spent doing something else.
116
117         $summary  = trim($_POST['summary']  ?? '');
118         $desc     = trim($_POST['desc']     ?? '');
119         $location = trim($_POST['location'] ?? '');
120         $type     = 'event';
121
122         $params = [
123                 'summary'     => $summary,
124                 'description' => $desc,
125                 'location'    => $location,
126                 'start'       => $start_text,
127                 'finish'      => $finish_text,
128                 'adjust'      => $adjust,
129                 'nofinish'    => $nofinish,
130         ];
131
132         $action = ($event_id == '') ? 'new' : 'event/' . $event_id;
133         $onerror_path = 'events/' . $action . '?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986);
134
135         if (strcmp($finish, $start) < 0 && !$nofinish) {
136                 notice(DI::l10n()->t('Event can not end before it has started.'));
137                 if (intval($_REQUEST['preview'])) {
138                         echo DI::l10n()->t('Event can not end before it has started.');
139                         exit();
140                 }
141                 DI::baseUrl()->redirect($onerror_path);
142         }
143
144         if (!$summary || ($start === DBA::NULL_DATETIME)) {
145                 notice(DI::l10n()->t('Event title and start time are required.'));
146                 if (intval($_REQUEST['preview'])) {
147                         echo DI::l10n()->t('Event title and start time are required.');
148                         exit();
149                 }
150                 DI::baseUrl()->redirect($onerror_path);
151         }
152
153         $self = \Friendica\Model\Contact::getPublicIdByUserId($uid);
154
155         $aclFormatter = DI::aclFormatter();
156
157         if ($share) {
158                 $user = User::getById($uid, ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
159                 if (!DBA::isResult($user)) {
160                         return;
161                 }
162
163                 $str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $user['allow_cid'] ?? '';
164                 $str_group_allow   = isset($_REQUEST['group_allow'])   ? $aclFormatter->toString($_REQUEST['group_allow'])   : $user['allow_gid'] ?? '';
165                 $str_contact_deny  = isset($_REQUEST['contact_deny'])  ? $aclFormatter->toString($_REQUEST['contact_deny'])  : $user['deny_cid']  ?? '';
166                 $str_group_deny    = isset($_REQUEST['group_deny'])    ? $aclFormatter->toString($_REQUEST['group_deny'])    : $user['deny_gid']  ?? '';
167
168                 $visibility = $_REQUEST['visibility'] ?? '';
169                 if ($visibility === 'public') {
170                         // The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
171                         $str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
172                 } else if ($visibility === 'custom') {
173                         // Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
174                         // case that would make it public. So we always append the author's contact id to the allowed contacts.
175                         // See https://github.com/friendica/friendica/issues/9672
176                         $str_contact_allow .= $aclFormatter->toString($self);
177                 }
178         } else {
179                 $str_contact_allow = $aclFormatter->toString($self);
180                 $str_group_allow = $str_contact_deny = $str_group_deny = '';
181         }
182
183         // Make sure to set the `private` field as true. This is necessary to
184         // have the posts show up correctly in Diaspora if an event is created
185         // as visible only to self at first, but then edited to display to others.
186         if (strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) {
187                 $private_event = true;
188         }
189
190         $datarray = [];
191         $datarray['start']     = $start;
192         $datarray['finish']    = $finish;
193         $datarray['summary']   = $summary;
194         $datarray['desc']      = $desc;
195         $datarray['location']  = $location;
196         $datarray['type']      = $type;
197         $datarray['adjust']    = $adjust;
198         $datarray['nofinish']  = $nofinish;
199         $datarray['uid']       = $uid;
200         $datarray['cid']       = $cid;
201         $datarray['allow_cid'] = $str_contact_allow;
202         $datarray['allow_gid'] = $str_group_allow;
203         $datarray['deny_cid']  = $str_contact_deny;
204         $datarray['deny_gid']  = $str_group_deny;
205         $datarray['private']   = $private_event;
206         $datarray['id']        = $event_id;
207
208         if (intval($_REQUEST['preview'])) {
209                 $html = Event::getHTML($datarray);
210                 echo $html;
211                 exit();
212         }
213
214         $item_id = Event::store($datarray);
215
216         if (!$cid) {
217                 Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $item_id);
218         }
219
220         DI::baseUrl()->redirect('events');
221 }
222
223 function events_content(App $a)
224 {
225         if (!local_user()) {
226                 notice(DI::l10n()->t('Permission denied.'));
227                 return Login::form();
228         }
229
230         if ($a->argc == 1) {
231                 $_SESSION['return_path'] = DI::args()->getCommand();
232         }
233
234         if (($a->argc > 2) && ($a->argv[1] === 'ignore') && intval($a->argv[2])) {
235                 q("UPDATE `event` SET `ignore` = 1 WHERE `id` = %d AND `uid` = %d",
236                         intval($a->argv[2]),
237                         intval(local_user())
238                 );
239         }
240
241         if (($a->argc > 2) && ($a->argv[1] === 'unignore') && intval($a->argv[2])) {
242                 q("UPDATE `event` SET `ignore` = 0 WHERE `id` = %d AND `uid` = %d",
243                         intval($a->argv[2]),
244                         intval(local_user())
245                 );
246         }
247
248         if ($a->theme_events_in_profile) {
249                 Nav::setSelected('home');
250         } else {
251                 Nav::setSelected('events');
252         }
253
254         // get the translation strings for the callendar
255         $i18n = Event::getStrings();
256
257         DI::page()->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.min.css');
258         DI::page()->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.print.min.css', 'print');
259         DI::page()->registerFooterScript('view/asset/moment/min/moment-with-locales.min.js');
260         DI::page()->registerFooterScript('view/asset/fullcalendar/dist/fullcalendar.min.js');
261
262         $htpl = Renderer::getMarkupTemplate('event_head.tpl');
263         DI::page()['htmlhead'] .= Renderer::replaceMacros($htpl, [
264                 '$module_url' => '/events',
265                 '$modparams' => 1,
266                 '$i18n' => $i18n,
267         ]);
268
269         $o = '';
270         $tabs = '';
271         // tabs
272         if ($a->theme_events_in_profile) {
273                 $tabs = BaseProfile::getTabsHTML($a, 'events', true);
274         }
275
276         $mode = 'view';
277         $y = 0;
278         $m = 0;
279         $ignored = !empty($_REQUEST['ignored']) ? intval($_REQUEST['ignored']) : 0;
280
281         if ($a->argc > 1) {
282                 if ($a->argc > 2 && $a->argv[1] == 'event') {
283                         $mode = 'edit';
284                         $event_id = intval($a->argv[2]);
285                 }
286                 if ($a->argc > 2 && $a->argv[1] == 'drop') {
287                         $mode = 'drop';
288                         $event_id = intval($a->argv[2]);
289                 }
290                 if ($a->argc > 2 && $a->argv[1] == 'copy') {
291                         $mode = 'copy';
292                         $event_id = intval($a->argv[2]);
293                 }
294                 if ($a->argv[1] === 'new') {
295                         $mode = 'new';
296                         $event_id = 0;
297                 }
298                 if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
299                         $mode = 'view';
300                         $y = intval($a->argv[1]);
301                         $m = intval($a->argv[2]);
302                 }
303         }
304
305         // The view mode part is similiar to /mod/cal.php
306         if ($mode == 'view') {
307                 $thisyear  = DateTimeFormat::localNow('Y');
308                 $thismonth = DateTimeFormat::localNow('m');
309                 if (!$y) {
310                         $y = intval($thisyear);
311                 }
312                 if (!$m) {
313                         $m = intval($thismonth);
314                 }
315
316                 // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
317                 // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
318
319                 if ($y < 1901) {
320                         $y = 1900;
321                 }
322                 if ($y > 2099) {
323                         $y = 2100;
324                 }
325
326                 $dim    = Temporal::getDaysInMonth($y, $m);
327                 $start  = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
328                 $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
329
330                 if ($a->argc > 1 && $a->argv[1] === 'json') {
331                         if (!empty($_GET['start'])) {
332                                 $start = $_GET['start'];
333                         }
334                         if (!empty($_GET['end'])) {
335                                 $finish = $_GET['end'];
336                         }
337                 }
338
339                 $start  = DateTimeFormat::utc($start);
340                 $finish = DateTimeFormat::utc($finish);
341
342                 $adjust_start  = DateTimeFormat::local($start);
343                 $adjust_finish = DateTimeFormat::local($finish);
344
345                 // put the event parametes in an array so we can better transmit them
346                 $event_params = [
347                         'event_id'      => intval($_GET['id'] ?? 0),
348                         'start'         => $start,
349                         'finish'        => $finish,
350                         'adjust_start'  => $adjust_start,
351                         'adjust_finish' => $adjust_finish,
352                         'ignore'        => $ignored,
353                 ];
354
355                 // get events by id or by date
356                 if ($event_params['event_id']) {
357                         $r = Event::getListById(local_user(), $event_params['event_id']);
358                 } else {
359                         $r = Event::getListByDate(local_user(), $event_params);
360                 }
361
362                 $links = [];
363
364                 if (DBA::isResult($r)) {
365                         $r = Event::sortByDate($r);
366                         foreach ($r as $rr) {
367                                 $j = $rr['adjust'] ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j');
368                                 if (empty($links[$j])) {
369                                         $links[$j] = DI::baseUrl() . '/' . DI::args()->getCommand() . '#link-' . $j;
370                                 }
371                         }
372                 }
373
374                 $events = [];
375
376                 // transform the event in a usable array
377                 if (DBA::isResult($r)) {
378                         $r = Event::sortByDate($r);
379                         $events = Event::prepareListForTemplate($r);
380                 }
381
382                 if ($a->argc > 1 && $a->argv[1] === 'json') {
383                         header('Content-Type: application/json');
384                         echo json_encode($events);
385                         exit();
386                 }
387
388                 if (!empty($_GET['id'])) {
389                         $tpl = Renderer::getMarkupTemplate("event.tpl");
390                 } else {
391                         $tpl = Renderer::getMarkupTemplate("events_js.tpl");
392                 }
393
394                 // Get rid of dashes in key names, Smarty3 can't handle them
395                 foreach ($events as $key => $event) {
396                         $event_item = [];
397                         foreach ($event['item'] as $k => $v) {
398                                 $k = str_replace('-', '_', $k);
399                                 $event_item[$k] = $v;
400                         }
401                         $events[$key]['item'] = $event_item;
402                 }
403
404                 // ACL blocks are loaded in modals in frio
405                 DI::page()->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
406                 DI::page()->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
407                 DI::page()->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
408                 DI::page()->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
409
410                 $o = Renderer::replaceMacros($tpl, [
411                         '$tabs'      => $tabs,
412                         '$title'     => DI::l10n()->t('Events'),
413                         '$view'      => DI::l10n()->t('View'),
414                         '$new_event' => [DI::baseUrl() . '/events/new', DI::l10n()->t('Create New Event'), '', ''],
415                         '$previous'  => [DI::baseUrl() . '/events/$prevyear/$prevmonth', DI::l10n()->t('Previous'), '', ''],
416                         '$next'      => [DI::baseUrl() . '/events/$nextyear/$nextmonth', DI::l10n()->t('Next'), '', ''],
417                         '$calendar'  => Temporal::getCalendarTable($y, $m, $links, ' eventcal'),
418
419                         '$events'    => $events,
420
421                         '$today' => DI::l10n()->t('today'),
422                         '$month' => DI::l10n()->t('month'),
423                         '$week'  => DI::l10n()->t('week'),
424                         '$day'   => DI::l10n()->t('day'),
425                         '$list'  => DI::l10n()->t('list'),
426                 ]);
427
428                 if (!empty($_GET['id'])) {
429                         echo $o;
430                         exit();
431                 }
432
433                 return $o;
434         }
435
436         if (($mode === 'edit' || $mode === 'copy') && $event_id) {
437                 $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1",
438                         intval($event_id),
439                         intval(local_user())
440                 );
441                 if (DBA::isResult($r)) {
442                         $orig_event = $r[0];
443                 }
444         }
445
446         // Passed parameters overrides anything found in the DB
447         if (in_array($mode, ['edit', 'new', 'copy'])) {
448                 $share_checked = '';
449                 $share_disabled = '';
450
451                 if (empty($orig_event)) {
452                         $orig_event = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);;
453                 } elseif ($orig_event['allow_cid'] !== '<' . local_user() . '>'
454                         || $orig_event['allow_gid']
455                         || $orig_event['deny_cid']
456                         || $orig_event['deny_gid']) {
457                         $share_checked = ' checked="checked" ';
458                 }
459
460                 // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
461                 if (!empty($_REQUEST['nofinish']))    {$orig_event['nofinish']    = $_REQUEST['nofinish'];}
462                 if (!empty($_REQUEST['adjust']))      {$orig_event['adjust']      = $_REQUEST['adjust'];}
463                 if (!empty($_REQUEST['summary']))     {$orig_event['summary']     = $_REQUEST['summary'];}
464                 if (!empty($_REQUEST['desc']))        {$orig_event['desc']        = $_REQUEST['desc'];}
465                 if (!empty($_REQUEST['location']))    {$orig_event['location']    = $_REQUEST['location'];}
466                 if (!empty($_REQUEST['start']))       {$orig_event['start']       = $_REQUEST['start'];}
467                 if (!empty($_REQUEST['finish']))      {$orig_event['finish']      = $_REQUEST['finish'];}
468
469                 $n_checked = (!empty($orig_event['nofinish']) ? ' checked="checked" ' : '');
470                 $a_checked = (!empty($orig_event['adjust'])   ? ' checked="checked" ' : '');
471
472                 $t_orig = $orig_event['summary']  ?? '';
473                 $d_orig = $orig_event['desc']     ?? '';
474                 $l_orig = $orig_event['location'] ?? '';
475                 $eid = $orig_event['id'] ?? 0;
476                 $cid = $orig_event['cid'] ?? 0;
477                 $uri = $orig_event['uri'] ?? '';
478
479                 if ($cid || $mode === 'edit') {
480                         $share_disabled = 'disabled="disabled"';
481                 }
482
483                 $sdt = $orig_event['start'] ?? 'now';
484                 $fdt = $orig_event['finish'] ?? 'now';
485
486                 $tz = date_default_timezone_get();
487                 if (!empty($orig_event)) {
488                         $tz = ($orig_event['adjust'] ? date_default_timezone_get() : 'UTC');
489                 }
490
491                 $syear  = DateTimeFormat::convert($sdt, $tz, 'UTC', 'Y');
492                 $smonth = DateTimeFormat::convert($sdt, $tz, 'UTC', 'm');
493                 $sday   = DateTimeFormat::convert($sdt, $tz, 'UTC', 'd');
494
495                 $shour   = !empty($orig_event) ? DateTimeFormat::convert($sdt, $tz, 'UTC', 'H') : '00';
496                 $sminute = !empty($orig_event) ? DateTimeFormat::convert($sdt, $tz, 'UTC', 'i') : '00';
497
498                 $fyear  = DateTimeFormat::convert($fdt, $tz, 'UTC', 'Y');
499                 $fmonth = DateTimeFormat::convert($fdt, $tz, 'UTC', 'm');
500                 $fday   = DateTimeFormat::convert($fdt, $tz, 'UTC', 'd');
501
502                 $fhour   = !empty($orig_event) ? DateTimeFormat::convert($fdt, $tz, 'UTC', 'H') : '00';
503                 $fminute = !empty($orig_event) ? DateTimeFormat::convert($fdt, $tz, 'UTC', 'i') : '00';
504
505                 if (!$cid && in_array($mode, ['new', 'copy'])) {
506                         $acl = ACL::getFullSelectorHTML(DI::page(), $a->user, false, ACL::getDefaultUserPermissions($orig_event));
507                 } else {
508                         $acl = '';
509                 }
510
511                 // If we copy an old event, we need to remove the ID and URI
512                 // from the original event.
513                 if ($mode === 'copy') {
514                         $eid = 0;
515                         $uri = '';
516                 }
517
518                 $tpl = Renderer::getMarkupTemplate('event_form.tpl');
519
520                 $o .= Renderer::replaceMacros($tpl, [
521                         '$post' => DI::baseUrl() . '/events',
522                         '$eid'  => $eid,
523                         '$cid'  => $cid,
524                         '$uri'  => $uri,
525
526                         '$title' => DI::l10n()->t('Event details'),
527                         '$desc' => DI::l10n()->t('Starting date and Title are required.'),
528                         '$s_text' => DI::l10n()->t('Event Starts:') . ' <span class="required" title="' . DI::l10n()->t('Required') . '">*</span>',
529                         '$s_dsel' => Temporal::getDateTimeField(
530                                 new DateTime(),
531                                 DateTime::createFromFormat('Y', intval($syear) + 5),
532                                 DateTime::createFromFormat('Y-m-d H:i', "$syear-$smonth-$sday $shour:$sminute"),
533                                 DI::l10n()->t('Event Starts:'),
534                                 'start_text',
535                                 true,
536                                 true,
537                                 '',
538                                 '',
539                                 true
540                         ),
541                         '$n_text' => DI::l10n()->t('Finish date/time is not known or not relevant'),
542                         '$n_checked' => $n_checked,
543                         '$f_text' => DI::l10n()->t('Event Finishes:'),
544                         '$f_dsel' => Temporal::getDateTimeField(
545                                 new DateTime(),
546                                 DateTime::createFromFormat('Y', intval($fyear) + 5),
547                                 DateTime::createFromFormat('Y-m-d H:i', "$fyear-$fmonth-$fday $fhour:$fminute"),
548                                 DI::l10n()->t('Event Finishes:'),
549                                 'finish_text',
550                                 true,
551                                 true,
552                                 'start_text'
553                         ),
554                         '$a_text' => DI::l10n()->t('Adjust for viewer timezone'),
555                         '$a_checked' => $a_checked,
556                         '$d_text' => DI::l10n()->t('Description:'),
557                         '$d_orig' => $d_orig,
558                         '$l_text' => DI::l10n()->t('Location:'),
559                         '$l_orig' => $l_orig,
560                         '$t_text' => DI::l10n()->t('Title:') . ' <span class="required" title="' . DI::l10n()->t('Required') . '">*</span>',
561                         '$t_orig' => $t_orig,
562                         '$summary' => ['summary', DI::l10n()->t('Title:'), $t_orig, '', '*'],
563                         '$sh_text' => DI::l10n()->t('Share this event'),
564                         '$share' => ['share', DI::l10n()->t('Share this event'), $share_checked, '', $share_disabled],
565                         '$sh_checked' => $share_checked,
566                         '$nofinish' => ['nofinish', DI::l10n()->t('Finish date/time is not known or not relevant'), $n_checked],
567                         '$adjust' => ['adjust', DI::l10n()->t('Adjust for viewer timezone'), $a_checked],
568                         '$preview' => DI::l10n()->t('Preview'),
569                         '$acl' => $acl,
570                         '$submit' => DI::l10n()->t('Submit'),
571                         '$basic' => DI::l10n()->t('Basic'),
572                         '$advanced' => DI::l10n()->t('Advanced'),
573                         '$permissions' => DI::l10n()->t('Permissions'),
574                 ]);
575
576                 return $o;
577         }
578
579         // Remove an event from the calendar and its related items
580         if ($mode === 'drop' && $event_id) {
581                 $ev = Event::getListById(local_user(), $event_id);
582
583                 // Delete only real events (no birthdays)
584                 if (DBA::isResult($ev) && $ev[0]['type'] == 'event') {
585                         Item::deleteForUser(['id' => $ev[0]['itemid']], local_user());
586                 }
587
588                 if (Item::exists(['id' => $ev[0]['itemid']])) {
589                         notice(DI::l10n()->t('Failed to remove event'));
590                 }
591
592                 DI::baseUrl()->redirect('events');
593         }
594 }