5 include_once
"Services/Authentication/classes/class.ilSessionStatistics.php";
38 switch ($ilCtrl->getNextClass()) {
40 $cmd = $ilCtrl->getCmd(
"current");
53 $lng->txt(
"trac_current_system_load"),
54 $ilCtrl->getLinkTarget($this,
"current")
58 $lng->txt(
"trac_short_system_load"),
59 $ilCtrl->getLinkTarget($this,
"short")
63 $lng->txt(
"trac_long_system_load"),
64 $ilCtrl->getLinkTarget($this,
"long")
68 $lng->txt(
"trac_periodic_system_load"),
69 $ilCtrl->getLinkTarget($this,
"periodic")
73 protected function current($a_export =
false)
77 $ilTabs->activateSubTab(
"current");
80 if (!$_REQUEST[
"smd"]) {
81 $_REQUEST[
"smd"] = self::MODE_TODAY;
83 $mode = (int) $_REQUEST[
"smd"];
86 if (!$_REQUEST[
"smm"]) {
87 $_REQUEST[
"smm"] =
"avg";
89 $measure = (
string) $_REQUEST[
"smm"];
93 case self::MODE_TODAY:
94 $time_from = strtotime(
"today");
95 $time_to = strtotime(
"tomorrow")-1;
96 $scale = self::SCALE_DAY;
99 case self::MODE_LAST_DAY:
101 $time_from = $time_to-60*60*24;
102 $scale = self::SCALE_DAY;
105 case self::MODE_LAST_WEEK:
107 $time_from = $time_to-60*60*24*7;
108 $scale = self::SCALE_WEEK;
111 case self::MODE_LAST_MONTH:
113 $time_from = $time_to-60*60*24*30;
114 $scale = self::SCALE_MONTH;
118 $mode_options =
array(
119 self::MODE_TODAY => $lng->txt(
"trac_session_statistics_mode_today"),
120 self::MODE_LAST_DAY => $lng->txt(
"trac_session_statistics_mode_last_day"),
121 self::MODE_LAST_WEEK => $lng->txt(
"trac_session_statistics_mode_last_week"),
122 self::MODE_LAST_MONTH => $lng->txt(
"trac_session_statistics_mode_last_month"));
124 $title = $lng->txt(
"trac_current_system_load") .
" - " . $mode_options[$mode];
129 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
130 $ilToolbar->setFormAction($ilCtrl->getFormAction($this,
"current"));
132 $mode_selector =
new ilSelectInputGUI(
" " . $lng->txt(
"trac_scale"),
"smd");
134 $mode_selector->setValue($mode);
135 $ilToolbar->addInputItem($mode_selector,
true);
137 $measure_options =
array(
138 "avg" => $lng->txt(
"trac_session_active_avg"),
139 "min" => $lng->txt(
"trac_session_active_min"),
140 "max" => $lng->txt(
"trac_session_active_max"));
142 $measure_selector =
new ilSelectInputGUI(
" " . $lng->txt(
"trac_measure"),
"smm");
143 $measure_selector->
setOptions($measure_options);
144 $measure_selector->setValue($measure);
145 $ilToolbar->addInputItem($measure_selector,
true);
147 $ilToolbar->addFormButton($lng->txt(
"ok"),
"current");
149 if (
sizeof(
$data[
"active"])) {
150 $ilToolbar->addSeparator();
151 $ilToolbar->addFormButton($lng->txt(
"export"),
"currentExport");
154 $tpl->setContent($this->
render(
$data, $scale, $measure));
167 protected function importDate($a_incoming, $a_default = null)
173 include_once
"Services/Calendar/classes/class.ilCalendarUtil.php";
180 protected function short($a_export =
false)
184 $ilTabs->activateSubTab(
"short");
187 $time_to = $this->
importDate($_REQUEST[
"sst"]);
190 if (!$_REQUEST[
"smd"]) {
191 $_REQUEST[
"smd"] = self::MODE_DAY;
193 $mode = (int) $_REQUEST[
"smd"];
196 if (!$_REQUEST[
"smm"]) {
197 $_REQUEST[
"smm"] =
"avg";
199 $measure = (
string) $_REQUEST[
"smm"];
203 $time_from = $time_to-60*60*24;
204 $scale = self::SCALE_DAY;
207 case self::MODE_WEEK:
208 $time_from = $time_to-60*60*24*7;
209 $scale = self::SCALE_WEEK;
213 $mode_options =
array(
214 self::MODE_DAY => $lng->txt(
"trac_session_statistics_mode_day"),
215 self::MODE_WEEK => $lng->txt(
"trac_session_statistics_mode_week")
218 $title = $lng->txt(
"trac_short_system_load") .
" - " . $mode_options[$mode];
223 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
224 $ilToolbar->setFormAction($ilCtrl->getFormAction($this,
"short"));
228 $ilToolbar->addInputItem($start_selector,
true);
230 $mode_selector =
new ilSelectInputGUI(
" " . $lng->txt(
"trac_scale"),
"smd");
232 $mode_selector->setValue($mode);
233 $ilToolbar->addInputItem($mode_selector,
true);
235 $measure_options =
array(
236 "avg" => $lng->txt(
"trac_session_active_avg"),
237 "min" => $lng->txt(
"trac_session_active_min"),
238 "max" => $lng->txt(
"trac_session_active_max"));
240 $measure_selector =
new ilSelectInputGUI(
" " . $lng->txt(
"trac_measure"),
"smm");
241 $measure_selector->
setOptions($measure_options);
242 $measure_selector->setValue($measure);
243 $ilToolbar->addInputItem($measure_selector,
true);
245 $ilToolbar->addFormButton($lng->txt(
"ok"),
"short");
247 if (
sizeof(
$data[
"active"])) {
248 $ilToolbar->addSeparator();
249 $ilToolbar->addFormButton($lng->txt(
"export"),
"shortExport");
252 $tpl->setContent($this->
render(
$data, $scale, $measure));
263 protected function long($a_export =
false)
267 $ilTabs->activateSubTab(
"long");
270 $time_to = $this->
importDate($_REQUEST[
"sst"]);
273 if (!$_REQUEST[
"smd"]) {
274 $_REQUEST[
"smd"] = self::MODE_WEEK;
276 $mode = (int) $_REQUEST[
"smd"];
279 case self::MODE_WEEK:
280 $time_from = $time_to-60*60*24*7;
281 $scale = self::SCALE_WEEK;
284 case self::MODE_MONTH:
285 $time_from = $time_to-60*60*24*30;
286 $scale = self::SCALE_MONTH;
289 case self::MODE_YEAR:
290 $time_from = $time_to-60*60*24*365;
291 $scale = self::SCALE_YEAR;
295 $mode_options =
array(
296 self::MODE_WEEK => $lng->txt(
"trac_session_statistics_mode_week"),
297 self::MODE_MONTH => $lng->txt(
"trac_session_statistics_mode_month"),
298 self::MODE_YEAR => $lng->txt(
"trac_session_statistics_mode_year")
301 $title = $lng->txt(
"trac_long_system_load") .
" - " . $mode_options[$mode];
306 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
307 $ilToolbar->setFormAction($ilCtrl->getFormAction($this,
"long"));
311 $ilToolbar->addInputItem($start_selector,
true);
313 $mode_selector =
new ilSelectInputGUI(
" " . $lng->txt(
"trac_scale"),
"smd");
315 $mode_selector->setValue($mode);
316 $ilToolbar->addInputItem($mode_selector,
true);
318 $ilToolbar->addFormButton($lng->txt(
"ok"),
"long");
320 if (
sizeof(
$data[
"active"])) {
321 $ilToolbar->addSeparator();
322 $ilToolbar->addFormButton($lng->txt(
"export"),
"longExport");
340 $ilTabs->activateSubTab(
"periodic");
343 $time_to = $this->
importDate($_REQUEST[
"sst"]);
346 $time_from = $this->
importDate($_REQUEST[
"sto"], strtotime(
"-7 days"));
349 if ($time_to < $time_from) {
351 $time_to = $time_from;
355 $title = $lng->txt(
"trac_periodic_system_load");
360 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
361 $ilToolbar->setFormAction($ilCtrl->getFormAction($this,
"periodic"));
365 $ilToolbar->addInputItem($end_selector,
true);
369 $ilToolbar->addInputItem($start_selector,
true);
371 $ilToolbar->addFormButton($lng->txt(
"ok"),
"periodic");
373 if (
sizeof(
$data[
"active"])) {
374 $ilToolbar->addSeparator();
375 $ilToolbar->addFormButton($lng->txt(
"export"),
"periodicExport");
378 $tpl->setContent($this->
render(
$data, self::SCALE_PERIODIC_WEEK));
395 include_once
"Services/Authentication/classes/class.ilSessionControl.php";
398 $control_active = ($ilSetting->get(
'session_handling_type', 0) == 1);
399 if ($control_active) {
412 $left =
new ilTemplate(
"tpl.session_statistics_left.html",
true,
true,
"Services/Authentication");
414 $left->setVariable(
"CAPTION_CURRENT", $lng->txt(
"users_online"));
415 $left->setVariable(
"VALUE_CURRENT", $active);
417 $left->setVariable(
"CAPTION_LAST_AGGR", $lng->txt(
"trac_last_aggregation"));
420 $left->setVariable(
"CAPTION_LAST_MAX", $lng->txt(
"trac_last_maxed_out_sessions"));
423 $left->setVariable(
"CAPTION_SESSION_CONTROL", $lng->txt(
"sess_load_dependent_session_handling"));
424 if (!$control_active) {
425 $left->setVariable(
"VALUE_SESSION_CONTROL", $lng->txt(
"no"));
427 $left->setVariable(
"VALUE_SESSION_CONTROL", $lng->txt(
"yes"));
429 $left->setCurrentBlock(
"control_details");
431 $left->setVariable(
"CAPTION_SESSION_CONTROL_LIMIT", $lng->txt(
"session_max_count"));
432 $left->setVariable(
"VALUE_SESSION_CONTROL_LIMIT", $control_max_sessions);
434 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_MIN", $lng->txt(
"session_min_idle"));
435 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_MIN", $control_min_idle);
437 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_MAX", $lng->txt(
"session_max_idle"));
438 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_MAX", $control_max_idle);
440 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_FIRST", $lng->txt(
"session_max_idle_after_first_request"));
441 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_FIRST", $control_max_idle_first);
443 $left->parseCurrentBlock();
447 if ($ilAccess->checkAccess(
"write",
"", (
int) $_REQUEST[
"ref_id"])) {
448 $left->setVariable(
"URL_SYNC", $ilCtrl->getFormAction($this,
"adminSync"));
449 $left->setVariable(
"CMD_SYNC",
"adminSync");
450 $left->setVariable(
"TXT_SYNC", $lng->txt(
"trac_sync_session_stats"));
456 protected function buildData($a_time_from, $a_time_to, $a_title)
464 $opened = (int) $counters[
"opened"];
465 $closed_limit = (int) $counters[
"closed_limit"];
466 unset($counters[
"opened"]);
467 unset($counters[
"closed_limit"]);
475 $data[
"title"] = $a_title .
" (" .
481 $data[
"maxed_out_time"] =
array($lng->txt(
"trac_maxed_out_time"), $maxed_out_duration);
482 $data[
"maxed_out_counter"] =
array($lng->txt(
"trac_maxed_out_counter"), $closed_limit);
483 $data[
"opened"] =
array($lng->txt(
"trac_sessions_opened"), $opened);
484 $data[
"closed"] =
array($lng->txt(
"trac_sessions_closed"), array_sum($counters));
494 protected function render($a_data, $a_scale, $a_measure = null)
498 $center =
new ilTemplate(
"tpl.session_statistics_center.html",
true,
true,
"Services/Authentication");
500 foreach ($a_data as $idx => $item) {
507 case "closed_details":
508 $center->setCurrentBlock(
"closed_details");
509 foreach ($item as $detail) {
510 $center->setVariable(
"CAPTION_CLOSED_DETAILS", $detail[0]);
511 $center->setVariable(
"VALUE_CLOSED_DETAILS", $detail[1]);
512 $center->parseCurrentBlock();
517 $tpl_var = strtoupper($idx);
518 $center->setVariable(
"CAPTION_" . $tpl_var, $item[0]);
519 $center->setVariable(
"VALUE_" . $tpl_var, $item[1]);
524 if ($a_data[
"active"]) {
525 $center->setVariable(
"CHART", $this->
getChart($a_data[
"active"], $a_data[
"title"], $a_scale, $a_measure));
530 return $center->get();
542 protected function getChart($a_data, $a_title, $a_scale = self::SCALE_DAY, $a_measure = null)
546 include_once
"Services/Chart/classes/class.ilChart.php";
548 $chart->setsize(700, 500);
549 $chart->setYAxisToInteger(
true);
555 $a_measure =
array(
"min",
"avg",
"max");
556 } elseif (!is_array($a_measure)) {
557 $a_measure =
array($a_measure);
560 $colors_map =
array(
"min" =>
"#00cc00",
564 $colors = $act_line =
array();
565 foreach ($a_measure as $measure) {
567 $act_line[$measure]->setLineSteps(
true);
568 $act_line[$measure]->setLabel($lng->txt(
"trac_session_active_" . $measure));
569 $colors[] = $colors_map[$measure];
572 if ($a_scale != self::SCALE_PERIODIC_WEEK) {
574 $max_line->setLabel($lng->txt(
"session_max_count"));
575 $colors[] =
"#cc0000";
578 $chart->setColors($colors);
583 $scale = ceil(
sizeof($chart_data)/5);
585 foreach ($chart_data as $idx => $item) {
586 $date = $item[
"slot_begin"];
588 if ($a_scale == self::SCALE_PERIODIC_WEEK || !($idx % ceil($scale))) {
590 case self::SCALE_DAY:
591 $labels[$date] =
date(
"H:i", $date);
594 case self::SCALE_WEEK:
595 $labels[$date] =
date(
"d.m. H", $date) .
"h";
598 case self::SCALE_MONTH:
599 $labels[$date] =
date(
"d.m.", $date);
602 case self::SCALE_YEAR:
603 $labels[$date] =
date(
"Y-m", $date);
606 case self::SCALE_PERIODIC_WEEK:
607 $day = substr($date, 0, 1);
608 $hour = substr($date, 1, 2);
609 $min = substr($date, 3, 2);
612 $day_value = ($day-1)*60*60*24;
613 $date = $day_value+$hour*60*60+$min*60;
616 if ($hour != $old_hour && $hour && $hour%6 == 0) {
617 $labels[$date] = $hour;
621 if ($day != $old_day) {
629 foreach ($a_measure as $measure) {
630 $value = (int) $item[
"active_" . $measure];
631 $act_line[$measure]->addPoint($date, $value);
634 if ($a_scale != self::SCALE_PERIODIC_WEEK) {
635 $max_line->addPoint($date, (
int) $item[
"max_sessions"]);
639 foreach ($act_line as $line) {
642 if ($a_scale != self::SCALE_PERIODIC_WEEK) {
643 $chart->addData($max_line);
646 $chart->setTicks($labels, null,
true);
655 case self::SCALE_DAY:
659 case self::SCALE_WEEK:
665 foreach ($a_data as $item) {
666 $date_parts = getdate($item[
"slot_begin"]);
670 case self::SCALE_MONTH:
672 $slot = mktime($date_parts[
"hours"], 0, 0, $date_parts[
"mon"], $date_parts[
"mday"], $date_parts[
"year"]);
675 case self::SCALE_YEAR:
677 $slot = mktime(0, 0, 1, $date_parts[
"mon"], $date_parts[
"mday"], $date_parts[
"year"]);
680 case self::SCALE_PERIODIC_WEEK:
682 $day = $date_parts[
"wday"];
686 $slot = $day .
date(
"His", $item[
"slot_begin"]);
691 foreach ($item as
$id => $value) {
692 switch (substr(
$id, -3)) {
694 if (!$tmp[$slot][
$id] || $value < $tmp[$slot][
$id]) {
695 $tmp[$slot][
$id] = $value;
700 if (!$tmp[$slot][$id] || $value > $tmp[$slot][$id]) {
701 $tmp[$slot][
$id] = $value;
706 $tmp[$slot][
$id][] = $value;
712 foreach ($tmp as $slot => $attr) {
713 $tmp[$slot][
"active_avg"] = (int) round(array_sum($attr[
"active_avg"])/
sizeof($attr[
"active_avg"]));
714 $tmp[$slot][
"slot_begin"] = $slot;
717 return array_values($tmp);
730 $ilCtrl->redirect($this);
738 include_once
'./Services/Link/classes/class.ilLink.php';
740 include_once
"./Services/Utilities/classes/class.ilCSVWriter.php";
742 $csv->setSeparator(
";");
748 $lng->txt(
"trac_name_of_installation") => $ilClientIniFile->readVariable(
'client',
'name'),
750 $lng->txt(
"trac_report_owner") => $ilUser->getFullName(),
752 foreach ($a_data as $idx => $item) {
755 $meta[$lng->txt(
"title")] = $item;
762 case "closed_details":
763 foreach ($item as $detail) {
764 $meta[$a_data[
"closed"][0] .
" - " . $detail[0]] = $detail[1];
769 $meta[$item[0]] = $item[1];
773 foreach ($meta as $caption => $value) {
774 $csv->addColumn(strip_tags($caption));
775 $csv->addColumn(strip_tags($value));
786 $first = array_keys(array_shift($first));
789 if ($a_scale == self::SCALE_PERIODIC_WEEK && $column ==
"slot_begin") {
790 $csv->addColumn(
"weekday");
791 $csv->addColumn(
"time");
793 $csv->addColumn(strip_tags($column));
799 foreach ($aggr_data as
$row) {
800 foreach ($row as $column => $value) {
801 if (is_array($value)) {
802 $value = implode(
', ', $value);
807 if ($a_scale == self::SCALE_PERIODIC_WEEK) {
809 $value = substr($value, 1, 2) .
":" . substr($value, 3, 2);
816 $value =
date(
"d.m.Y H:i", $value);
819 $csv->addColumn(strip_tags($value));
825 $filename .=
"session_statistics_" .
date(
"Ymd", $now) .
".csv";
826 header(
"Content-type: text/comma-separated-values");
827 header(
"Content-Disposition: attachment; filename=\"" .
$filename .
"\"");
829 header(
"Cache-Control: must-revalidate, post-check=0,pre-check=0");
831 echo $csv->getCSVString();
Class ilSessionStatisticsGUI.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
const DEFAULT_MAX_COUNT
default value for settings that have not been defined in setup or administration yet ...
exportCSV(array $a_data, $a_scale)
static getMaxedOutDuration($a_from, $a_to)
Get maxed out duration in given timeframe.
Helper class to generate CSV files.
static _numericDayToString($a_day, $a_long=true)
get
const SCALE_PERIODIC_WEEK
static $session_types_controlled
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
if(!array_key_exists('StateId', $_REQUEST)) $id
static setUseRelativeDates($a_status)
set use relative dates
static getNumberOfSessionsByType($a_from, $a_to)
Get session counters by type (opened, closed)
static _destroyExpiredSessions()
Destroy expired sessions.
importDate($a_incoming, $a_default=null)
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
render($a_data, $a_scale, $a_measure=null)
static getLastAggregation()
Get timestamp of last aggregation.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
special template class to simplify handling of ITX/PEAR
Add a drawing to the header
Create styles array
The data for the language used.
static getExistingSessionCount(array $a_types)
returns number of valid sessions relating to given session types
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
adaptDataToScale($a_scale, array $a_data)
getChart($a_data, $a_title, $a_scale=self::SCALE_DAY, $a_measure=null)
Build chart for active sessions.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
periodic($a_export=false)
static getLastMaxedOut()
Get latest slot during which sessions were maxed out.
static aggretateRaw($a_now)
Aggregate raw session data (older than given time)
buildData($a_time_from, $a_time_to, $a_title)
static getInstanceByType($a_type, $a_id)
Get type instance.
const DEFAULT_MAX_IDLE_AFTER_FIRST_REQUEST
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.
static getActiveSessions($a_from, $a_to)
Get active sessions aggregated data.