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