'You do not have access to that client.']); exit; } enforceCalendarEvent(['event_client_id' => $client_id], 'edit'); } $form_locked_client = $form_client_id && !empty($_GET['lock_client']); // When - what was picked on the calendar, or the next whole hour $start = ticketScheduleValue(str_replace('T', ' ', (string) ($_GET['start'] ?? '')) . (strlen((string) ($_GET['start'] ?? '')) === 10 ? ' 00:00:00' : '')); $end = ticketScheduleValue(str_replace('T', ' ', (string) ($_GET['end'] ?? '')) . (strlen((string) ($_GET['end'] ?? '')) === 10 ? ' 00:00:00' : '')); $all_day = !empty($_GET['all_day']); if ($start === '') { $start = date('Y-m-d H:00:00', strtotime('+1 hour')); } if ($all_day) { $start = substr($start, 0, 10) . ' 00:00:00'; // A picked range ends the day after its last day $end = $end !== '' ? date('Y-m-d 00:00:00', max(strtotime($start), strtotime(substr($end, 0, 10) . ' -1 day'))) : $start; } elseif ($end === '' || $end <= $start) { $end = date('Y-m-d H:i:s', strtotime($start) + 3600); } // Picked on the viewer's own clock - kept in the company's (functions/user_timezone.php) if (!$all_day && ($_GET['start'] ?? '') !== '') { [$start, $end] = [timezoneFromView($start), timezoneFromView($end)]; } $form = [ 'event_title' => (string) ($_GET['title'] ?? ''), 'event_calendar_id' => intval($_GET['calendar_id'] ?? 0), 'event_start' => $start, 'event_end' => $end, 'event_all_day' => $all_day ? 1 : 0, 'event_location_id' => $form_client_id ? intval(assetClientOwnedId('location', $_GET['location_id'] ?? 0, $form_client_id)) : 0, ]; $form_attendees = [ // Assigned to the agent whose calendar it was added from, or the one adding it 'agents' => calendarEventDefaultAgents($_GET['agent_id'] ?? 0), 'contacts' => $form_client_id && intval(assetClientOwnedId('contact', $_GET['contact_id'] ?? 0, $form_client_id)) ? [intval($_GET['contact_id'])] : [], 'emails' => [], ]; $form_invited = false; if (!calendarList()) { echo json_encode(['error' => 'There is no calendar to put it on yet - ' . (calendarCanManage() ? 'add one first.' : 'ask an admin to add one.')]); exit; } ob_start(); ?>