From 43148d3f173f21c372fd0b53fc0215a3aea5cfa8 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Sat, 16 Nov 2024 13:08:56 +0200 Subject: [PATCH] Participants page: Stop if there is DB connection error --- app/pages/conferences.php | 2 +- app/pages/participants.php | 289 +++++++++++++++++++------------------ 2 files changed, 148 insertions(+), 143 deletions(-) diff --git a/app/pages/conferences.php b/app/pages/conferences.php index b156ca6..31cf40e 100644 --- a/app/pages/conferences.php +++ b/app/pages/conferences.php @@ -10,7 +10,7 @@ if ($response['db'] === null) { $error = $response['error']; include '../app/templates/block-message.php'; -// otherwise if DB connectio is OK, go on +// otherwise if DB connection is OK, go on } else { $db = $response['db']; diff --git a/app/pages/participants.php b/app/pages/participants.php index ae4c58a..7b9a8dc 100644 --- a/app/pages/participants.php +++ b/app/pages/participants.php @@ -4,158 +4,163 @@ require '../app/classes/participant.php'; // connect to database $response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $platform_id); + +// if DB connection has error, display it and stop here if ($response['db'] === null) { $error = $response['error']; include '../app/templates/block-message.php'; + +// otherwise if DB connection is OK, go on } else { $db = $response['db']; -} -// specify time range -include '../app/helpers/time_range.php'; + // specify time range + include '../app/helpers/time_range.php'; -// participant id/name/IP are specified when searching specific participant(s) -// participant name - this is 'stats_id' in the db -// either id, name, OR IP - in that order -// we use $_REQUEST, so that both links and forms work -if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') { - $participantId = $_REQUEST['id']; - unset($_REQUEST['name']); - unset($participantName); -} elseif (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { - unset($participantId); - $participantName = $_REQUEST['name']; -} elseif (isset($_REQUEST['ip']) && $_REQUEST['ip'] != '') { - unset($participantId); - $participantIp = $_REQUEST['ip']; -} else { - unset($participantId); - unset($participantName); -} - - -// -// Participant listings -// - -$participantObject = new Participant($db); - -// pagination variables -$items_per_page = 15; -$browse_page = $_REQUEST['p'] ?? 1; -$browse_page = (int)$browse_page; -$offset = ($browse_page -1) * $items_per_page; - -// search and list specific participant ID -if (isset($participantId)) { - $search = $participantObject->conferenceByParticipantId($participantId, $from_time, $until_time, $offset, $items_per_page); - $search_all = $participantObject->conferenceByParticipantId($participantId, $from_time, $until_time); -// search and list specific participant name (stats_id) -} elseif (isset($participantName)) { - $search = $participantObject->conferenceByParticipantName($participantName, $from_time, $until_time, $offset, $items_per_page); - $search_all = $participantObject->conferenceByParticipantName($participantName, $from_time, $until_time); -// search and list specific participant IP -} elseif (isset($participantIp)) { - $search = $participantObject->conferenceByParticipantIP($participantIp, $from_time, $until_time, $offset, $items_per_page); - $search_all = $participantObject->conferenceByParticipantIP($participantIp, $from_time, $until_time); -// list of all participants (default) -} else { -// prepare the result - $search = $participantObject->participantsAll($from_time, $until_time, $offset, $items_per_page); - $search_all = $participantObject->participantsAll($from_time, $until_time); -} - -if (!empty($search)) { - // we get total items and number of pages - $item_count = count($search_all); - $page_count = ceil($item_count / $items_per_page); - - $participants = array(); - $participants['records'] = array(); - - foreach ($search as $item) { - extract($item); - - // search and list specific participant ID - if (isset($participantId)) { - $participant_record = array( - // assign title to the field in the array record - 'time' => $time, - 'conference ID' => $conference_id, - 'conference name' => $conference_name, - 'conference host' => $conference_host, - 'loglevel' => $loglevel, - 'participant ID' => $participant_id, - 'event' => $event_type, - 'parameter' => $event_param - ); - // search and list specific participant name (stats_id) - } elseif (isset($participantName)) { - $participant_record = array( - // assign title to the field in the array record - 'time' => $time, - 'conference ID' => $conference_id, - 'conference name' => $conference_name, - 'conference host' => $conference_host, - 'loglevel' => $loglevel, - 'participant ID' => $participant_id, - 'event' => $event_type, - 'parameter' => $event_param - ); - // search and list specific participant IP - } elseif (isset($participantIp)) { - $participant_record = array( - // assign title to the field in the array record - 'time' => $time, - 'conference ID' => $conference_id, - 'conference name' => $conference_name, - 'conference host' => $conference_host, - 'loglevel' => $loglevel, - 'participant ID' => $participant_id, - 'event' => $event_type, - 'parameter' => $event_param - ); - // list of all participants (default) - } else { - $participant_record = array( - // assign title to the field in the array record - 'component' => $jitsi_component, - 'participant ID' => $endpoint_id, - 'conference ID' => $conference_id - ); - } - - // populate the result array - array_push($participants['records'], $participant_record); + // participant id/name/IP are specified when searching specific participant(s) + // participant name - this is 'stats_id' in the db + // either id, name, OR IP - in that order + // we use $_REQUEST, so that both links and forms work + if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') { + $participantId = $_REQUEST['id']; + unset($_REQUEST['name']); + unset($participantName); + } elseif (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { + unset($participantId); + $participantName = $_REQUEST['name']; + } elseif (isset($_REQUEST['ip']) && $_REQUEST['ip'] != '') { + unset($participantId); + $participantIp = $_REQUEST['ip']; + } else { + unset($participantId); + unset($participantName); } -} -// prepare the widget -$widget['full'] = false; -$widget['name'] = 'Participants'; -$widget['collapsible'] = false; -$widget['collapsed'] = false; -$widget['filter'] = true; -$widget['pagination'] = true; -// widget title -if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { - $widget['title'] = 'Conferences with participant name (stats_id) matching "' . $_REQUEST['name'] . '"'; -} elseif (isset($_REQUEST['id']) && $_REQUEST['id'] != '') { - $widget['title'] = 'Conference with participant ID matching "' . $_REQUEST['id'] . '"'; -} elseif (isset($participantIp)) { - $widget['title'] = 'Conference with participant IP matching "' . $participantIp . '"'; -} else { - $widget['title'] = 'All participants'; -} -// widget records -if (!empty($participants['records'])) { - $widget['full'] = true; - $widget['table_headers'] = array_keys($participants['records'][0]); - $widget['table_records'] = $participants['records']; -} + // + // Participant listings + // -// display the widget -include '../app/templates/widget.php'; + $participantObject = new Participant($db); + + // pagination variables + $items_per_page = 15; + $browse_page = $_REQUEST['p'] ?? 1; + $browse_page = (int)$browse_page; + $offset = ($browse_page -1) * $items_per_page; + + // search and list specific participant ID + if (isset($participantId)) { + $search = $participantObject->conferenceByParticipantId($participantId, $from_time, $until_time, $offset, $items_per_page); + $search_all = $participantObject->conferenceByParticipantId($participantId, $from_time, $until_time); + // search and list specific participant name (stats_id) + } elseif (isset($participantName)) { + $search = $participantObject->conferenceByParticipantName($participantName, $from_time, $until_time, $offset, $items_per_page); + $search_all = $participantObject->conferenceByParticipantName($participantName, $from_time, $until_time); + // search and list specific participant IP + } elseif (isset($participantIp)) { + $search = $participantObject->conferenceByParticipantIP($participantIp, $from_time, $until_time, $offset, $items_per_page); + $search_all = $participantObject->conferenceByParticipantIP($participantIp, $from_time, $until_time); + // list of all participants (default) + } else { + // prepare the result + $search = $participantObject->participantsAll($from_time, $until_time, $offset, $items_per_page); + $search_all = $participantObject->participantsAll($from_time, $until_time); + } + + if (!empty($search)) { + // we get total items and number of pages + $item_count = count($search_all); + $page_count = ceil($item_count / $items_per_page); + + $participants = array(); + $participants['records'] = array(); + + foreach ($search as $item) { + extract($item); + + // search and list specific participant ID + if (isset($participantId)) { + $participant_record = array( + // assign title to the field in the array record + 'time' => $time, + 'conference ID' => $conference_id, + 'conference name' => $conference_name, + 'conference host' => $conference_host, + 'loglevel' => $loglevel, + 'participant ID' => $participant_id, + 'event' => $event_type, + 'parameter' => $event_param + ); + // search and list specific participant name (stats_id) + } elseif (isset($participantName)) { + $participant_record = array( + // assign title to the field in the array record + 'time' => $time, + 'conference ID' => $conference_id, + 'conference name' => $conference_name, + 'conference host' => $conference_host, + 'loglevel' => $loglevel, + 'participant ID' => $participant_id, + 'event' => $event_type, + 'parameter' => $event_param + ); + // search and list specific participant IP + } elseif (isset($participantIp)) { + $participant_record = array( + // assign title to the field in the array record + 'time' => $time, + 'conference ID' => $conference_id, + 'conference name' => $conference_name, + 'conference host' => $conference_host, + 'loglevel' => $loglevel, + 'participant ID' => $participant_id, + 'event' => $event_type, + 'parameter' => $event_param + ); + // list of all participants (default) + } else { + $participant_record = array( + // assign title to the field in the array record + 'component' => $jitsi_component, + 'participant ID' => $endpoint_id, + 'conference ID' => $conference_id + ); + } + + // populate the result array + array_push($participants['records'], $participant_record); + } + } + + // prepare the widget + $widget['full'] = false; + $widget['name'] = 'Participants'; + $widget['collapsible'] = false; + $widget['collapsed'] = false; + $widget['filter'] = true; + $widget['pagination'] = true; + + // widget title + if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { + $widget['title'] = 'Conferences with participant name (stats_id) matching "' . $_REQUEST['name'] . '"'; + } elseif (isset($_REQUEST['id']) && $_REQUEST['id'] != '') { + $widget['title'] = 'Conference with participant ID matching "' . $_REQUEST['id'] . '"'; + } elseif (isset($participantIp)) { + $widget['title'] = 'Conference with participant IP matching "' . $participantIp . '"'; + } else { + $widget['title'] = 'All participants'; + } + // widget records + if (!empty($participants['records'])) { + $widget['full'] = true; + $widget['table_headers'] = array_keys($participants['records'][0]); + $widget['table_records'] = $participants['records']; + } + + // display the widget + include '../app/templates/widget.php'; + +} ?>