diff --git a/public_html/classes/conference.php b/public_html/classes/conference.php index 269292d..bf447c8 100644 --- a/public_html/classes/conference.php +++ b/public_html/classes/conference.php @@ -19,7 +19,7 @@ class Conference { } - // search/list specific conference + // search/list specific conference ID public function conferenceById($conference_id, $from_time, $until_time) { // time period drill-down @@ -44,6 +44,31 @@ class Conference { } + // search/list specific conference name + public function conferenceByName($conference_name, $from_time, $until_time) { + + // time period drill-down + // FIXME make it similar to the bash version + if (empty($from_time)) { + $from_time = '0000-01-01'; + } + if (empty($until_time)) { + $until_time = '9999-12-31'; + } + + // this is needed for compatibility with the bash version, so we use '%s' placeholders + $from_time = htmlspecialchars(strip_tags($from_time)); + $until_time = htmlspecialchars(strip_tags($until_time)); + $sql = $this->queries['conference_by_name']; + $sql = sprintf($sql, $conference_name, $from_time, $until_time, $conference_name, $from_time, $until_time); + + $query = $this->db->prepare($sql); + $query->execute(); + + return $query->fetchAll(PDO::FETCH_ASSOC); + } + + // list of all conferences public function conferencesAllFormatted($from_time, $until_time) { diff --git a/public_html/classes/queries.php b/public_html/classes/queries.php index 66f6d26..be825fc 100644 --- a/public_html/classes/queries.php +++ b/public_html/classes/queries.php @@ -94,7 +94,53 @@ WHERE AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59') ORDER BY - pe.time;" + pe.time;", + + + // search for a conference by its name for a time period (if given) + 'conference_by_name' => " +SELECT + pe.time, + c.conference_id, + c.conference_name, + c.conference_host, + pe.loglevel, + pe.event_type, + p.endpoint_id AS participant_id, + pe.event_param +FROM + conferences c +LEFT JOIN + conference_events ce ON c.conference_id = ce.conference_id +LEFT JOIN + participants p ON c.conference_id = p.conference_id +LEFT JOIN + participant_events pe ON p.endpoint_id = pe.participant_id +WHERE + c.conference_name = '%s' +AND (pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59') + +UNION + +SELECT + ce.time AS event_time, + c.conference_id, + c.conference_name, + c.conference_host, + ce.loglevel, + ce.conference_event AS event_type, + NULL AS participant_id, + ce.conference_param AS event_param +FROM + conferences c +LEFT JOIN + conference_events ce ON c.conference_id = ce.conference_id +WHERE + c.conference_name = '%s' +AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59') + +ORDER BY + pe.time;", ]; diff --git a/public_html/pages/conferences.php b/public_html/pages/conferences.php index 5f4121e..c364eb0 100644 --- a/public_html/pages/conferences.php +++ b/public_html/pages/conferences.php @@ -116,7 +116,84 @@ if (isset($conference_id)) { } -// list of all conferences +// search and list specific conference ID +} elseif (isset($conference_name)) { + + try { + $conference = new Conference($db); + + // prepare the result + $search = $conference->conferenceByName($conference_name, $from_time, $until_time); + + if (!empty($search)) { + $conferences = array(); + $conferences['records'] = array(); + + foreach ($search as $item) { + extract($item); + $conference_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 + ); + // populate the result array + array_push($conferences['records'], $conference_record); + } + } + + } catch (Exception $e) { + $error = 'Error: ' . $e->getMessage(); + include 'templates/message.php'; + exit(); + } + + // display the result + echo "Conferences with name matching \"$conference_name\""; + if ($time_range_specified) { + echo " for the time period $from_time - $until_time"; + } + + if (!empty($conferences['records'])) { + + echo "\t"; + echo "\t\t"; + + // table headers + foreach (array_keys($conferences['records'][0]) as $header) { + echo "\t\t\t"; + } + echo "\t\t"; + + //table rows + foreach ($conferences['records'] as $row) { + echo "\t\t"; + // sometimes $column is empty, we make it '' then + foreach ($row as $key => $column) { + if ($column === $conference_name) { + echo "\t\t\t"; + } elseif ($key === 'conference ID') { + echo "\t\t\t"; + } else { + echo "\t\t\t"; + } + } + echo "\t\t"; + } + + echo "\t
" . htmlspecialchars($header) . "
" . htmlspecialchars($column ?? '') . "" . htmlspecialchars($column ?? '') . "" . htmlspecialchars($column ?? '') . "
"; + + } else { + echo '

No matching conferences found.

'; + } + + +// list of all conferences (default) } else { try { $conference = new Conference($db);