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