]> git.mxchange.org Git - friendica.git/blob - mod/events.php
Merge remote-tracking branch 'upstream/develop' into network-thread-view
[friendica.git] / mod / events.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
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 (DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] === 'json') {
55                 return;
56         }
57
58         if (empty(DI::page()['aside'])) {
59                 DI::page()['aside'] = '';
60         }
61
62         $cal_widget = CalendarExport::getHTML(local_user());
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
210         if (intval($_REQUEST['preview'])) {
211                 $html = Event::getHTML($datarray);
212                 echo $html;
213                 exit();
214         }
215
216         $event_id = Event::store($datarray);
217
218         $item = ['network' => Protocol::DFRN, 'protocol' => Conversation::PARCEL_DIRECT, 'direction' => Conversation::PUSH];    
219         $item = Event::getItemArrayForId($event_id, $item);
220         if (Item::insert($item)) {
221                 $uri_id = $item['uri-id'];
222         } else {
223                 $uri_id = 0;
224         }
225
226         if (!$cid && $uri_id) {
227                 Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, (int)$uri_id, (int)$uid);
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 (DI::args()->getArgc() == 1) {
241                 $_SESSION['return_path'] = DI::args()->getCommand();
242         }
243
244         if ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[1] === 'ignore') && intval(DI::args()->getArgv()[2])) {
245                 DBA::update('event', ['ignore' => true], ['id' => DI::args()->getArgv()[2], 'uid' => local_user()]);
246         }
247
248         if ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[1] === 'unignore') && intval(DI::args()->getArgv()[2])) {
249                 DBA::update('event', ['ignore' => false], ['id' => DI::args()->getArgv()[2], 'uid' => local_user()]);
250         }
251
252         if ($a->getThemeInfoValue('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->getThemeInfoValue('events_in_profile')) {
277                 $tabs = BaseProfile::getTabsHTML($a, 'events', true, $a->getLoggedInUserNickname(), false);
278         }
279
280         $mode = 'view';
281         $y = 0;
282         $m = 0;
283         $ignored = !empty($_REQUEST['ignored']) ? intval($_REQUEST['ignored']) : 0;
284
285         if (DI::args()->getArgc() > 1) {
286                 if (DI::args()->getArgc() > 2 && DI::args()->getArgv()[1] == 'event') {
287                         $mode = 'edit';
288                         $event_id = intval(DI::args()->getArgv()[2]);
289                 }
290                 if (DI::args()->getArgc() > 2 && DI::args()->getArgv()[1] == 'drop') {
291                         $mode = 'drop';
292                         $event_id = intval(DI::args()->getArgv()[2]);
293                 }
294                 if (DI::args()->getArgc() > 2 && DI::args()->getArgv()[1] == 'copy') {
295                         $mode = 'copy';
296                         $event_id = intval(DI::args()->getArgv()[2]);
297                 }
298                 if (DI::args()->getArgv()[1] === 'new') {
299                         $mode = 'new';
300                         $event_id = 0;
301                 }
302                 if (DI::args()->getArgc() > 2 && intval(DI::args()->getArgv()[1]) && intval(DI::args()->getArgv()[2])) {
303                         $mode = 'view';
304                         $y = intval(DI::args()->getArgv()[1]);
305                         $m = intval(DI::args()->getArgv()[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 (DI::args()->getArgc() > 1 && DI::args()->getArgv()[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 (DI::args()->getArgc() > 1 && DI::args()->getArgv()[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                 $orig_event = DBA::selectFirst('event', [], ['id' => $event_id, 'uid' => local_user()]);
442         }
443
444         // Passed parameters overrides anything found in the DB
445         if (in_array($mode, ['edit', 'new', 'copy'])) {
446                 $share_checked = '';
447                 $share_disabled = '';
448
449                 if (empty($orig_event)) {
450                         $orig_event = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);;
451                 } elseif ($orig_event['allow_cid'] !== '<' . local_user() . '>'
452                         || $orig_event['allow_gid']
453                         || $orig_event['deny_cid']
454                         || $orig_event['deny_gid']) {
455                         $share_checked = ' checked="checked" ';
456                 }
457
458                 // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
459                 if (!empty($_REQUEST['nofinish']))    {$orig_event['nofinish']    = $_REQUEST['nofinish'];}
460                 if (!empty($_REQUEST['adjust']))      {$orig_event['adjust']      = $_REQUEST['adjust'];}
461                 if (!empty($_REQUEST['summary']))     {$orig_event['summary']     = $_REQUEST['summary'];}
462                 if (!empty($_REQUEST['desc']))        {$orig_event['desc']        = $_REQUEST['desc'];}
463                 if (!empty($_REQUEST['location']))    {$orig_event['location']    = $_REQUEST['location'];}
464                 if (!empty($_REQUEST['start']))       {$orig_event['start']       = $_REQUEST['start'];}
465                 if (!empty($_REQUEST['finish']))      {$orig_event['finish']      = $_REQUEST['finish'];}
466
467                 $n_checked = (!empty($orig_event['nofinish']) ? ' checked="checked" ' : '');
468                 $a_checked = (!empty($orig_event['adjust'])   ? ' checked="checked" ' : '');
469
470                 $t_orig = $orig_event['summary']  ?? '';
471                 $d_orig = $orig_event['desc']     ?? '';
472                 $l_orig = $orig_event['location'] ?? '';
473                 $eid = $orig_event['id'] ?? 0;
474                 $cid = $orig_event['cid'] ?? 0;
475                 $uri = $orig_event['uri'] ?? '';
476
477                 if ($cid || $mode === 'edit') {
478                         $share_disabled = 'disabled="disabled"';
479                 }
480
481                 $sdt = $orig_event['start'] ?? 'now';
482                 $fdt = $orig_event['finish'] ?? 'now';
483
484                 $tz = date_default_timezone_get();
485                 if (isset($orig_event['adjust'])) {
486                         $tz = ($orig_event['adjust'] ? date_default_timezone_get() : 'UTC');
487                 }
488
489                 $syear  = DateTimeFormat::convert($sdt, $tz, 'UTC', 'Y');
490                 $smonth = DateTimeFormat::convert($sdt, $tz, 'UTC', 'm');
491                 $sday   = DateTimeFormat::convert($sdt, $tz, 'UTC', 'd');
492
493                 $shour   = !empty($orig_event) ? DateTimeFormat::convert($sdt, $tz, 'UTC', 'H') : '00';
494                 $sminute = !empty($orig_event) ? DateTimeFormat::convert($sdt, $tz, 'UTC', 'i') : '00';
495
496                 $fyear  = DateTimeFormat::convert($fdt, $tz, 'UTC', 'Y');
497                 $fmonth = DateTimeFormat::convert($fdt, $tz, 'UTC', 'm');
498                 $fday   = DateTimeFormat::convert($fdt, $tz, 'UTC', 'd');
499
500                 $fhour   = !empty($orig_event) ? DateTimeFormat::convert($fdt, $tz, 'UTC', 'H') : '00';
501                 $fminute = !empty($orig_event) ? DateTimeFormat::convert($fdt, $tz, 'UTC', 'i') : '00';
502
503                 if (!$cid && in_array($mode, ['new', 'copy'])) {
504                         $acl = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($orig_event));
505                 } else {
506                         $acl = '';
507                 }
508
509                 // If we copy an old event, we need to remove the ID and URI
510                 // from the original event.
511                 if ($mode === 'copy') {
512                         $eid = 0;
513                         $uri = '';
514                 }
515
516                 $tpl = Renderer::getMarkupTemplate('event_form.tpl');
517
518                 $o .= Renderer::replaceMacros($tpl, [
519                         '$post' => DI::baseUrl() . '/events',
520                         '$eid'  => $eid,
521                         '$cid'  => $cid,
522                         '$uri'  => $uri,
523
524                         '$title' => DI::l10n()->t('Event details'),
525                         '$desc' => DI::l10n()->t('Starting date and Title are required.'),
526                         '$s_text' => DI::l10n()->t('Event Starts:') . ' <span class="required" title="' . DI::l10n()->t('Required') . '">*</span>',
527                         '$s_dsel' => Temporal::getDateTimeField(
528                                 new DateTime(),
529                                 DateTime::createFromFormat('Y', intval($syear) + 5),
530                                 DateTime::createFromFormat('Y-m-d H:i', "$syear-$smonth-$sday $shour:$sminute"),
531                                 DI::l10n()->t('Event Starts:'),
532                                 'start_text',
533                                 true,
534                                 true,
535                                 '',
536                                 '',
537                                 true
538                         ),
539                         '$n_text' => DI::l10n()->t('Finish date/time is not known or not relevant'),
540                         '$n_checked' => $n_checked,
541                         '$f_text' => DI::l10n()->t('Event Finishes:'),
542                         '$f_dsel' => Temporal::getDateTimeField(
543                                 new DateTime(),
544                                 DateTime::createFromFormat('Y', intval($fyear) + 5),
545                                 DateTime::createFromFormat('Y-m-d H:i', "$fyear-$fmonth-$fday $fhour:$fminute"),
546                                 DI::l10n()->t('Event Finishes:'),
547                                 'finish_text',
548                                 true,
549                                 true,
550                                 'start_text'
551                         ),
552                         '$a_text' => DI::l10n()->t('Adjust for viewer timezone'),
553                         '$a_checked' => $a_checked,
554                         '$d_text' => DI::l10n()->t('Description:'),
555                         '$d_orig' => $d_orig,
556                         '$l_text' => DI::l10n()->t('Location:'),
557                         '$l_orig' => $l_orig,
558                         '$t_text' => DI::l10n()->t('Title:') . ' <span class="required" title="' . DI::l10n()->t('Required') . '">*</span>',
559                         '$t_orig' => $t_orig,
560                         '$summary' => ['summary', DI::l10n()->t('Title:'), $t_orig, '', '*'],
561                         '$sh_text' => DI::l10n()->t('Share this event'),
562                         '$share' => ['share', DI::l10n()->t('Share this event'), $share_checked, '', $share_disabled],
563                         '$sh_checked' => $share_checked,
564                         '$nofinish' => ['nofinish', DI::l10n()->t('Finish date/time is not known or not relevant'), $n_checked],
565                         '$adjust' => ['adjust', DI::l10n()->t('Adjust for viewer timezone'), $a_checked],
566                         '$preview' => DI::l10n()->t('Preview'),
567                         '$acl' => $acl,
568                         '$submit' => DI::l10n()->t('Submit'),
569                         '$basic' => DI::l10n()->t('Basic'),
570                         '$advanced' => DI::l10n()->t('Advanced'),
571                         '$permissions' => DI::l10n()->t('Permissions'),
572                 ]);
573
574                 return $o;
575         }
576
577         // Remove an event from the calendar and its related items
578         if ($mode === 'drop' && $event_id) {
579                 $ev = Event::getListById(local_user(), $event_id);
580
581                 // Delete only real events (no birthdays)
582                 if (DBA::isResult($ev) && $ev[0]['type'] == 'event') {
583                         Item::deleteForUser(['id' => $ev[0]['itemid']], local_user());
584                 }
585
586                 if (Post::exists(['id' => $ev[0]['itemid']])) {
587                         notice(DI::l10n()->t('Failed to remove event'));
588                 }
589
590                 DI::baseUrl()->redirect('events');
591         }
592 }