Components page: Stop if there is database error

main
Yasen Pramatarov 2024-11-17 14:11:22 +02:00
parent 43148d3f17
commit 6fcc6da51c
1 changed files with 68 additions and 63 deletions

View File

@ -4,43 +4,46 @@ require '../app/classes/component.php';
// connect to database // connect to database
$response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $platform_id); $response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $platform_id);
// if DB connection has error, display it and stop here
if ($response['db'] === null) { if ($response['db'] === null) {
$error = $response['error']; $error = $response['error'];
include '../app/templates/block-message.php'; include '../app/templates/block-message.php';
// otherwise if DB connection is OK, go on
} else { } else {
$db = $response['db']; $db = $response['db'];
}
// specify time range // specify time range
include '../app/helpers/time_range.php'; include '../app/helpers/time_range.php';
// jitsi component events list // jitsi component events list
// we use $_REQUEST, so that both links and forms work // we use $_REQUEST, so that both links and forms work
// if it's there, but empty, we make it same as the field name; otherwise assign the value // if it's there, but empty, we make it same as the field name; otherwise assign the value
$jitsi_component = !empty($_REQUEST['name']) ? "'" . $_REQUEST['name'] . "'" : 'jitsi_component'; $jitsi_component = !empty($_REQUEST['name']) ? "'" . $_REQUEST['name'] . "'" : 'jitsi_component';
$component_id = !empty($_REQUEST['id']) ? "'" . $_REQUEST['id'] . "'" : 'component_id'; $component_id = !empty($_REQUEST['id']) ? "'" . $_REQUEST['id'] . "'" : 'component_id';
$event_type = !empty($_REQUEST['event']) ? "'" . $_REQUEST['event'] . "'" : 'event_type'; $event_type = !empty($_REQUEST['event']) ? "'" . $_REQUEST['event'] . "'" : 'event_type';
// //
// Component events listings // Component events listings
// //
// list of all component events (default) // list of all component events (default)
$componentObject = new Component($db); $componentObject = new Component($db);
// pagination variables // pagination variables
$items_per_page = 15; $items_per_page = 15;
$browse_page = $_REQUEST['p'] ?? 1; $browse_page = $_REQUEST['p'] ?? 1;
$browse_page = (int)$browse_page; $browse_page = (int)$browse_page;
$offset = ($browse_page -1) * $items_per_page; $offset = ($browse_page -1) * $items_per_page;
// prepare the result // prepare the result
$search = $componentObject->jitsiComponents($jitsi_component, $component_id, $event_type, $from_time, $until_time, $offset, $items_per_page); $search = $componentObject->jitsiComponents($jitsi_component, $component_id, $event_type, $from_time, $until_time, $offset, $items_per_page);
$search_all = $componentObject->jitsiComponents($jitsi_component, $component_id, $event_type, $from_time, $until_time); $search_all = $componentObject->jitsiComponents($jitsi_component, $component_id, $event_type, $from_time, $until_time);
if (!empty($search)) { if (!empty($search)) {
// we get total items and number of pages // we get total items and number of pages
$item_count = count($search_all); $item_count = count($search_all);
$page_count = ceil($item_count / $items_per_page); $page_count = ceil($item_count / $items_per_page);
@ -62,30 +65,32 @@ if (!empty($search)) {
// populate the result array // populate the result array
array_push($components['records'], $component_record); array_push($components['records'], $component_record);
} }
} }
// prepare the widget // prepare the widget
$widget['full'] = false; $widget['full'] = false;
$widget['name'] = 'AllComponents'; $widget['name'] = 'AllComponents';
$widget['filter'] = true; $widget['filter'] = true;
$widget['pagination'] = true; $widget['pagination'] = true;
// widget title // widget title
if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
$widget['title'] = 'Jitsi events for component&nbsp;<strong>' . $_REQUEST['name'] . '</strong>'; $widget['title'] = 'Jitsi events for component&nbsp;<strong>' . $_REQUEST['name'] . '</strong>';
} elseif (isset($_REQUEST['id']) && $_REQUEST['id'] != '') { } elseif (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
$widget['title'] = 'Jitsi events for component ID&nbsp;<strong>' . $_REQUEST['id'] . '</strong>'; $widget['title'] = 'Jitsi events for component ID&nbsp;<strong>' . $_REQUEST['id'] . '</strong>';
} else { } else {
$widget['title'] = 'Jitsi events for&nbsp;<strong>all components</strong>'; $widget['title'] = 'Jitsi events for&nbsp;<strong>all components</strong>';
} }
// widget records // widget records
if (!empty($components['records'])) { if (!empty($components['records'])) {
$widget['full'] = true; $widget['full'] = true;
$widget['table_headers'] = array_keys($components['records'][0]); $widget['table_headers'] = array_keys($components['records'][0]);
$widget['table_records'] = $components['records']; $widget['table_records'] = $components['records'];
}
// display the widget
include '../app/templates/event-list-components.php';
} }
// display the widget
include '../app/templates/event-list-components.php';
?> ?>