diff --git a/CHANGELOG.md b/CHANGELOG.md
index f5499d1..7b85438 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
### Added
- Added collapsible front page widgets
- Added widgets to conferences, participants and components pages
+- Added front page widget for monthly conferences number
### Changed
- MVC design - models(classes folder), views(templates folder) and controllers(pages folder)
diff --git a/public_html/classes/conference.php b/public_html/classes/conference.php
index 039552f..d9aaba4 100644
--- a/public_html/classes/conference.php
+++ b/public_html/classes/conference.php
@@ -84,6 +84,30 @@ class Conference {
return $query->fetchAll(PDO::FETCH_ASSOC);
}
+ // number of conferences
+ public function conferencesNumber($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['conferences_number'];
+ $sql = sprintf($sql, $from_time, $until_time);
+
+ $query = $this->db->prepare($sql);
+ $query->execute();
+
+ return $query->fetchAll(PDO::FETCH_ASSOC);
+ }
+
}
diff --git a/public_html/classes/queries.php b/public_html/classes/queries.php
index 65d8304..9e05edd 100644
--- a/public_html/classes/queries.php
+++ b/public_html/classes/queries.php
@@ -4,6 +4,64 @@
return [
+ // number of conferences for time period (if given)
+ 'conferences_number' => "
+SELECT COUNT(c.conference_id) as conferences
+FROM
+ conferences c
+LEFT JOIN
+ conference_events ce ON c.conference_id = ce.conference_id
+WHERE (ce.time >= '%s 00:00:00' AND ce.time <= '%s 23:59:59')",
+
+
+ // search for a conference by its ID for a time period (if given)
+ 'conference_by_id' => "
+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_id = '%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_id = '%s'
+AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
+
+ORDER BY
+ pe.time;",
+
+
+
+
// list of conferences for time period (if given)
// fields: component, duration, conference ID, conference name, number of participants, name count (the conf name is found), conference host
'conferences_all_formatted' => "
diff --git a/public_html/index.php b/public_html/index.php
index 7aa08a5..54758f5 100644
--- a/public_html/index.php
+++ b/public_html/index.php
@@ -83,27 +83,27 @@ if (in_array($page, $allowed_urls)) {
setcookie('username', "", time() - 100, $config['folder'], $config['domain'], isset($_SERVER['HTTPS']), true);
$notice = "You were logged out.
You can log in again.";
- include 'templates/header.php';
- include 'templates/menu.php';
- include 'templates/message.php';
+ include 'templates/page-header.php';
+ include 'templates/page-menu.php';
+ include 'templates/block-message.php';
include 'pages/login.php';
// all other normal pages
} else {
- include 'templates/header.php';
- include 'templates/menu.php';
- include 'templates/message.php';
+ include 'templates/page-header.php';
+ include 'templates/page-menu.php';
+ include 'templates/block-message.php';
include "pages/{$page}.php";
}
// the page is not in allowed urls, loading front page
} else {
- include 'templates/header.php';
- include 'templates/menu.php';
- include 'templates/message.php';
+ include 'templates/page-header.php';
+ include 'templates/page-menu.php';
+ include 'templates/block-message.php';
include 'pages/front.php';
}
-include 'templates/footer.php';
+include 'templates/page-footer.php';
// clear errors and notices before next page just in case
unset($_SESSION['error']);
diff --git a/public_html/pages/components.php b/public_html/pages/components.php
index 9147f2d..cf4a780 100644
--- a/public_html/pages/components.php
+++ b/public_html/pages/components.php
@@ -37,7 +37,7 @@ try {
$db = new Database($config['jilo_database']);
} catch (Exception $e) {
$error = 'Error: ' . $e->getMessage();
- include 'templates/message.php';
+ include 'templates/block-message.php';
exit();
}
diff --git a/public_html/pages/conferences.php b/public_html/pages/conferences.php
index cfc7ac6..c1f0fd1 100644
--- a/public_html/pages/conferences.php
+++ b/public_html/pages/conferences.php
@@ -38,7 +38,7 @@ try {
$db = new Database($config['jilo_database']);
} catch (Exception $e) {
$error = 'Error: ' . $e->getMessage();
- include 'templates/message.php';
+ include 'templates/block-message.php';
exit();
}
diff --git a/public_html/pages/front.php b/public_html/pages/front.php
index ce51d65..75df76b 100644
--- a/public_html/pages/front.php
+++ b/public_html/pages/front.php
@@ -8,7 +8,7 @@ try {
$db = new Database($config['jilo_database']);
} catch (Exception $e) {
$error = 'Error: ' . $e->getMessage();
- include 'templates/message.php';
+ include 'templates/block-message.php';
exit();
}
@@ -16,52 +16,102 @@ try {
// dashboard widget listings
//
-// conferences in last 7 days
-try {
- $conference = new Conference($db);
- // conferences for last 2 days
- $from_time = date('Y-m-d', time() - 60 * 60 * 24 * 2);
- $until_time = date('Y-m-d', time());
- $time_range_specified = true;
+////
+// monthly usage
+$conference = new Conference($db);
- // prepare the result
- $search = $conference->conferencesAllFormatted($from_time, $until_time);
+// monthly conferences for the last year
+$fromMonth = (new DateTime())->sub(new DateInterval('P1Y'));
+$fromMonth->modify('first day of this month');
+$thisMonth = new DateTime();
+$from_time = $fromMonth->format('Y-m-d');
+$until_time = $thisMonth->format('Y-m-d');
- if (!empty($search)) {
- $conferences = array();
- $conferences['records'] = array();
+$widget['table_headers'] = array();
+$widget['table_records'] = array();
- foreach ($search as $item) {
- extract($item);
+// loop 1 year in the past
+while ($fromMonth < $thisMonth) {
- // we don't have duration field, so we calculate it
- if (!empty($start) && !empty($end)) {
- $duration = gmdate("H:i:s", abs(strtotime($end) - strtotime($start)));
- } else {
- $duration = '';
- }
- $conference_record = array(
- // assign title to the field in the array record
- 'component' => $jitsi_component,
- 'start' => $start,
- 'end' => $end,
- 'duration' => $duration,
- 'conference ID' => $conference_id,
- 'conference name' => $conference_name,
- 'participants' => $participants,
- 'name count' => $name_count,
- 'conference host' => $conference_host
- );
- // populate the result array
- array_push($conferences['records'], $conference_record);
- }
+ $untilMonth = clone $fromMonth;
+ $untilMonth->modify('last day of this month');
+
+ $search = $conference->conferencesNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d'));
+
+ // pretty format for displaying the month in the widget
+ $month = $fromMonth->format('F Y');
+
+ // populate the table
+ array_push($widget['table_headers'], $month);
+ if (isset($search[0]['conferences'])) {
+ array_push($widget['table_records'], $search[0]['conferences']);
+ } else {
+ array_push($widget['table_records'], '0');
}
-} catch (Exception $e) {
- $error = 'Error: ' . $e->getMessage();
- include 'templates/message.php';
- exit();
+ // move everything one month in future
+ $untilMonth->add(new DateInterval('P1M'));
+ $fromMonth->add(new DateInterval('P1M'));
+}
+
+$time_range_specified = true;
+
+// prepare the widget
+$widget['full'] = false;
+$widget['name'] = 'LastYearMonths';
+$widget['title'] = 'Conferences monthly number for the last year';
+$widget['collapsible'] = true;
+$widget['collapsed'] = false;
+$widget['filter'] = false;
+if (!empty($search)) {
+ $widget['full'] = true;
+}
+
+// display the widget
+include('templates/widget-monthly.php');
+
+
+////
+// conferences in last 2 days
+$conference = new Conference($db);
+
+// time range limit
+$from_time = date('Y-m-d', time() - 60 * 60 * 24 * 2);
+$until_time = date('Y-m-d', time());
+$time_range_specified = true;
+
+// prepare the result
+$search = $conference->conferencesAllFormatted($from_time, $until_time);
+
+if (!empty($search)) {
+ $conferences = array();
+ $conferences['records'] = array();
+
+ foreach ($search as $item) {
+ extract($item);
+
+ // we don't have duration field, so we calculate it
+ if (!empty($start) && !empty($end)) {
+ $duration = gmdate("H:i:s", abs(strtotime($end) - strtotime($start)));
+ } else {
+ $duration = '';
+ }
+ $conference_record = array(
+ // assign title to the field in the array record
+ 'component' => $jitsi_component,
+ 'start' => $start,
+ 'end' => $end,
+ 'duration' => $duration,
+ 'conference ID' => $conference_id,
+ 'conference name' => $conference_name,
+ 'participants' => $participants,
+ 'name count' => $name_count,
+ 'conference host' => $conference_host
+ );
+ // populate the result array
+ array_push($conferences['records'], $conference_record);
+ }
}
// prepare the widget
@@ -81,59 +131,53 @@ if (!empty($conferences['records'])) {
include('templates/widget.php');
+////
// last 10 conferences
-try {
- $conference = new Conference($db);
+$conference = new Conference($db);
- // all time
- $from_time = '0000-01-01';
- $until_time = '9999-12-31';
- $time_range_specified = false;
- // number of conferences to show
- $conference_number = 10;
+// all time
+$from_time = '0000-01-01';
+$until_time = '9999-12-31';
+$time_range_specified = false;
+// number of conferences to show
+$conference_number = 10;
- // prepare the result
- $search = $conference->conferencesAllFormatted($from_time, $until_time);
+// prepare the result
+$search = $conference->conferencesAllFormatted($from_time, $until_time);
- if (!empty($search)) {
- $conferences = array();
- $conferences['records'] = array();
+if (!empty($search)) {
+ $conferences = array();
+ $conferences['records'] = array();
- $i = 0;
- foreach ($search as $item) {
- extract($item);
+ $i = 0;
+ foreach ($search as $item) {
+ extract($item);
- // we don't have duration field, so we calculate it
- if (!empty($start) && !empty($end)) {
- $duration = gmdate("H:i:s", abs(strtotime($end) - strtotime($start)));
- } else {
- $duration = '';
- }
- $conference_record = array(
- // assign title to the field in the array record
- 'component' => $jitsi_component,
- 'start' => $start,
- 'end' => $end,
- 'duration' => $duration,
- 'conference ID' => $conference_id,
- 'conference name' => $conference_name,
- 'participants' => $participants,
- 'name count' => $name_count,
- 'conference host' => $conference_host
- );
- // populate the result array
- array_push($conferences['records'], $conference_record);
-
- // we only take the first 10 results
- $i++;
- if ($i == 10) break;
+ // we don't have duration field, so we calculate it
+ if (!empty($start) && !empty($end)) {
+ $duration = gmdate("H:i:s", abs(strtotime($end) - strtotime($start)));
+ } else {
+ $duration = '';
}
- }
+ $conference_record = array(
+ // assign title to the field in the array record
+ 'component' => $jitsi_component,
+ 'start' => $start,
+ 'end' => $end,
+ 'duration' => $duration,
+ 'conference ID' => $conference_id,
+ 'conference name' => $conference_name,
+ 'participants' => $participants,
+ 'name count' => $name_count,
+ 'conference host' => $conference_host
+ );
+ // populate the result array
+ array_push($conferences['records'], $conference_record);
-} catch (Exception $e) {
- $error = 'Error: ' . $e->getMessage();
- include 'templates/message.php';
- exit();
+ // we only take the first 10 results
+ $i++;
+ if ($i == 10) break;
+ }
}
// prepare the widget
diff --git a/public_html/pages/participants.php b/public_html/pages/participants.php
index 36c4d0b..f7b3b70 100644
--- a/public_html/pages/participants.php
+++ b/public_html/pages/participants.php
@@ -42,7 +42,7 @@ try {
$db = new Database($config['jilo_database']);
} catch (Exception $e) {
$error = 'Error: ' . $e->getMessage();
- include 'templates/message.php';
+ include 'templates/block-message.php';
exit();
}
diff --git a/public_html/pages/register.php b/public_html/pages/register.php
index 925afa1..5ae47c7 100644
--- a/public_html/pages/register.php
+++ b/public_html/pages/register.php
@@ -28,7 +28,7 @@ try {
$error = $e->getMessage();
}
-include 'templates/message.php';
+include 'templates/block-message.php';
include 'templates/form-register.php';
?>
diff --git a/public_html/templates/message.php b/public_html/templates/block-message.php
similarity index 100%
rename from public_html/templates/message.php
rename to public_html/templates/block-message.php
diff --git a/public_html/templates/results-filter.php b/public_html/templates/block-results-filter.php
similarity index 100%
rename from public_html/templates/results-filter.php
rename to public_html/templates/block-results-filter.php
diff --git a/public_html/templates/footer.php b/public_html/templates/page-footer.php
similarity index 100%
rename from public_html/templates/footer.php
rename to public_html/templates/page-footer.php
diff --git a/public_html/templates/header.php b/public_html/templates/page-header.php
similarity index 100%
rename from public_html/templates/header.php
rename to public_html/templates/page-header.php
diff --git a/public_html/templates/menu.php b/public_html/templates/page-menu.php
similarity index 100%
rename from public_html/templates/menu.php
rename to public_html/templates/page-menu.php
diff --git a/public_html/templates/widget-monthly.php b/public_html/templates/widget-monthly.php
new file mode 100644
index 0000000..020fec5
--- /dev/null
+++ b/public_html/templates/widget-monthly.php
@@ -0,0 +1,44 @@
+
+
time period: = $from_time ?> - = $until_time ?>
+ += htmlspecialchars($header) ?> | + +
---|
= htmlspecialchars($row ?? '') ?> | + +
No matching records found.
+ +