Files
itflow/api/v1/events/read.php
johnnyq ecbb974fff API stage 3, calendar events, trips, accounts and money, contracts, and files and folders: calendars can be read, and calendar events read with their attendees, created once or repeating for a client or nobody, changed, sent as invitations, skipped for a day of a series and deleted, following calendarEventCan(); trips can be read, logged, changed and deleted through tripSave() and tripDelete(), anyone their own and someone else's with Financial; accounts can be read with their balances, added, changed, archived, unarchived and deleted while nothing is on them, other income and transfers read, recorded, changed and deleted, and recurring expenses read, set up, changed, paused and resumed, recorded now, moved on past missed runs and deleted, keeping reconciled lines as they were; contracts can be read with their prepaid hours and signing state, added, changed, made active, renewed, cancelled and deleted, sent for signature or the link sent again, the request withdrawn, prepaid hours added with a draft invoice or deleted, tickets' time drawn or put back, and the billing recurring invoice made, linked or unlinked; a client's files can be read, uploaded as base64, downloaded, renamed, moved, archived, unarchived and deleted once archived, and folders read, made, renamed, moved and deleted with their contents moved up; new api/v1/form_input.php builds a save function's input from the API's field names; the upload allow-list moves from agent/post/file.php into fileUploadExtensions() so Upload Files and the API check the same list; enforce_api_rbac.php maps the new resources, lets events, calendars and trips check their own rules, puts the new state changes at Modify and treats files/download as a read; 26.11.9 changelog entries
2026-11-13 23:51:10 -05:00

50 lines
2.2 KiB
PHP

<?php
/*
* API - Calendar Events - Read
* GET /api/v1/events/read.php
*
* Events on your calendars, by when they start - a client's only for a key whose
* role can see Clients, or that its agent made or is on. One, by event_id, also
* has its attendees: agents, the client's contacts and others by email, and when
* each was sent the invitation. A repeating event is one row: event_repeat (Day,
* Week, Month or Year), every event_repeat_interval, until event_repeat_until,
* without the days in event_repeat_skip.
*
* event_id optional - Just this event, with its attendees
* calendar_id optional - Just this calendar's
* client_id optional - Just this client's; 0 for those of no client
* from, to optional - Starting on or after, and on or before, these days (Y-m-d)
* limit, offset optional - Paging
*/
require_once '../validate_api_key.php';
require_once '../require_get_method.php';
$where = 'event_archived_at IS NULL' . calendarEventScopeSql();
if (isset($_GET['event_id'])) {
$where .= ' AND event_id = ' . intval($_GET['event_id']);
}
if (isset($_GET['calendar_id'])) {
$where .= ' AND event_calendar_id = ' . intval($_GET['calendar_id']);
}
foreach (['from' => '>=', 'to' => '<='] as $field => $op) {
if (!empty($_GET[$field]) && calendarIsDate($_GET[$field])) {
$where .= " AND DATE(event_start) $op '" . escapeSql($_GET[$field]) . "'";
}
}
$sql = mysqli_query($mysqli, "SELECT calendar_events.*, calendar_name FROM calendar_events LEFT JOIN calendars ON calendar_id = event_calendar_id
WHERE $where " . apiClientScopeSql('event_client_id') . " ORDER BY event_start, event_id LIMIT $limit OFFSET $offset");
if (isset($_GET['event_id']) && $sql && ($row = mysqli_fetch_assoc($sql))) {
$row['attendees'] = array_map(function ($a) {
return ['attendee_id' => intval($a['attendee_id']), 'kind' => $a['kind'], 'user_id' => intval($a['attendee_user_id']), 'contact_id' => intval($a['attendee_contact_id']),
'name' => $a['name'], 'email' => $a['email'], 'invited_at' => $a['attendee_invited_at']];
}, calendarEventAttendees($row['event_id']));
echo json_encode(['success' => 'True', 'count' => 1, 'data' => [$row]]);
exit();
}
// Output
require_once "../read_output.php";