Participants page: Stop if there is DB connection error

main
Yasen Pramatarov 2024-11-16 13:08:56 +02:00
parent 8c37fea093
commit 43148d3f17
2 changed files with 148 additions and 143 deletions

View File

@ -10,7 +10,7 @@ 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 connectio is OK, go on // otherwise if DB connection is OK, go on
} else { } else {
$db = $response['db']; $db = $response['db'];

View File

@ -4,68 +4,71 @@ require '../app/classes/participant.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';
// participant id/name/IP are specified when searching specific participant(s) // participant id/name/IP are specified when searching specific participant(s)
// participant name - this is 'stats_id' in the db // participant name - this is 'stats_id' in the db
// either id, name, OR IP - in that order // either id, name, OR IP - in that order
// we use $_REQUEST, so that both links and forms work // we use $_REQUEST, so that both links and forms work
if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') { if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
$participantId = $_REQUEST['id']; $participantId = $_REQUEST['id'];
unset($_REQUEST['name']); unset($_REQUEST['name']);
unset($participantName); unset($participantName);
} elseif (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { } elseif (isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
unset($participantId); unset($participantId);
$participantName = $_REQUEST['name']; $participantName = $_REQUEST['name'];
} elseif (isset($_REQUEST['ip']) && $_REQUEST['ip'] != '') { } elseif (isset($_REQUEST['ip']) && $_REQUEST['ip'] != '') {
unset($participantId); unset($participantId);
$participantIp = $_REQUEST['ip']; $participantIp = $_REQUEST['ip'];
} else { } else {
unset($participantId); unset($participantId);
unset($participantName); unset($participantName);
} }
// //
// Participant listings // Participant listings
// //
$participantObject = new Participant($db); $participantObject = new Participant($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;
// search and list specific participant ID // search and list specific participant ID
if (isset($participantId)) { if (isset($participantId)) {
$search = $participantObject->conferenceByParticipantId($participantId, $from_time, $until_time, $offset, $items_per_page); $search = $participantObject->conferenceByParticipantId($participantId, $from_time, $until_time, $offset, $items_per_page);
$search_all = $participantObject->conferenceByParticipantId($participantId, $from_time, $until_time); $search_all = $participantObject->conferenceByParticipantId($participantId, $from_time, $until_time);
// search and list specific participant name (stats_id) // search and list specific participant name (stats_id)
} elseif (isset($participantName)) { } elseif (isset($participantName)) {
$search = $participantObject->conferenceByParticipantName($participantName, $from_time, $until_time, $offset, $items_per_page); $search = $participantObject->conferenceByParticipantName($participantName, $from_time, $until_time, $offset, $items_per_page);
$search_all = $participantObject->conferenceByParticipantName($participantName, $from_time, $until_time); $search_all = $participantObject->conferenceByParticipantName($participantName, $from_time, $until_time);
// search and list specific participant IP // search and list specific participant IP
} elseif (isset($participantIp)) { } elseif (isset($participantIp)) {
$search = $participantObject->conferenceByParticipantIP($participantIp, $from_time, $until_time, $offset, $items_per_page); $search = $participantObject->conferenceByParticipantIP($participantIp, $from_time, $until_time, $offset, $items_per_page);
$search_all = $participantObject->conferenceByParticipantIP($participantIp, $from_time, $until_time); $search_all = $participantObject->conferenceByParticipantIP($participantIp, $from_time, $until_time);
// list of all participants (default) // list of all participants (default)
} else { } else {
// prepare the result // prepare the result
$search = $participantObject->participantsAll($from_time, $until_time, $offset, $items_per_page); $search = $participantObject->participantsAll($from_time, $until_time, $offset, $items_per_page);
$search_all = $participantObject->participantsAll($from_time, $until_time); $search_all = $participantObject->participantsAll($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);
@ -128,34 +131,36 @@ if (!empty($search)) {
// populate the result array // populate the result array
array_push($participants['records'], $participant_record); array_push($participants['records'], $participant_record);
} }
} }
// prepare the widget // prepare the widget
$widget['full'] = false; $widget['full'] = false;
$widget['name'] = 'Participants'; $widget['name'] = 'Participants';
$widget['collapsible'] = false; $widget['collapsible'] = false;
$widget['collapsed'] = false; $widget['collapsed'] = false;
$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'] = 'Conferences with participant name (stats_id) matching "<strong>' . $_REQUEST['name'] . '"</strong>'; $widget['title'] = 'Conferences with participant name (stats_id) matching "<strong>' . $_REQUEST['name'] . '"</strong>';
} elseif (isset($_REQUEST['id']) && $_REQUEST['id'] != '') { } elseif (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
$widget['title'] = 'Conference with participant ID matching "<strong>' . $_REQUEST['id'] . '"</strong>'; $widget['title'] = 'Conference with participant ID matching "<strong>' . $_REQUEST['id'] . '"</strong>';
} elseif (isset($participantIp)) { } elseif (isset($participantIp)) {
$widget['title'] = 'Conference with participant IP matching "<strong>' . $participantIp . '"</strong>'; $widget['title'] = 'Conference with participant IP matching "<strong>' . $participantIp . '"</strong>';
} else { } else {
$widget['title'] = 'All participants'; $widget['title'] = 'All participants';
} }
// widget records // widget records
if (!empty($participants['records'])) { if (!empty($participants['records'])) {
$widget['full'] = true; $widget['full'] = true;
$widget['table_headers'] = array_keys($participants['records'][0]); $widget['table_headers'] = array_keys($participants['records'][0]);
$widget['table_records'] = $participants['records']; $widget['table_records'] = $participants['records'];
}
// display the widget
include '../app/templates/widget.php';
} }
// display the widget
include '../app/templates/widget.php';
?> ?>