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