5 include_once
"Services/Authentication/classes/class.ilSessionStatistics.php";
38 switch($ilCtrl->getNextClass())
41 $cmd = $ilCtrl->getCmd(
"current");
52 $ilTabs->addSubTab(
"current", $lng->txt(
"trac_current_system_load"),
53 $ilCtrl->getLinkTarget($this,
"current"));
54 $ilTabs->addSubTab(
"short", $lng->txt(
"trac_short_system_load"),
55 $ilCtrl->getLinkTarget($this,
"short"));
56 $ilTabs->addSubTab(
"long", $lng->txt(
"trac_long_system_load"),
57 $ilCtrl->getLinkTarget($this,
"long"));
58 $ilTabs->addSubTab(
"periodic", $lng->txt(
"trac_periodic_system_load"),
59 $ilCtrl->getLinkTarget($this,
"periodic"));
62 protected function current($a_export =
false)
66 $ilTabs->activateSubTab(
"current");
85 case self::MODE_TODAY:
86 $time_from = strtotime(
"today");
87 $time_to = strtotime(
"tomorrow")-1;
91 case self::MODE_LAST_DAY:
93 $time_from = $time_to-60*60*24;
97 case self::MODE_LAST_WEEK:
99 $time_from = $time_to-60*60*24*7;
103 case self::MODE_LAST_MONTH:
105 $time_from = $time_to-60*60*24*30;
110 $mode_options = array(
111 self::MODE_TODAY => $lng->txt(
"trac_session_statistics_mode_today"),
112 self::MODE_LAST_DAY => $lng->txt(
"trac_session_statistics_mode_last_day"),
113 self::MODE_LAST_WEEK => $lng->txt(
"trac_session_statistics_mode_last_week"),
114 self::MODE_LAST_MONTH => $lng->txt(
"trac_session_statistics_mode_last_month"));
116 $title = $lng->txt(
"trac_current_system_load").
" - ".$mode_options[$mode];
122 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
123 $ilToolbar->setFormAction($ilCtrl->getFormAction($this,
"current"));
125 $mode_selector =
new ilSelectInputGUI(
" ".$lng->txt(
"trac_scale"),
"smd");
127 $mode_selector->setValue($mode);
128 $ilToolbar->addInputItem($mode_selector,
true);
130 $measure_options = array(
131 "avg" => $lng->txt(
"trac_session_active_avg"),
132 "min" => $lng->txt(
"trac_session_active_min"),
133 "max" => $lng->txt(
"trac_session_active_max"));
135 $measure_selector =
new ilSelectInputGUI(
" ".$lng->txt(
"trac_measure"),
"smm");
136 $measure_selector->
setOptions($measure_options);
137 $measure_selector->setValue($measure);
138 $ilToolbar->addInputItem($measure_selector,
true);
140 $ilToolbar->addFormButton($lng->txt(
"ok"),
"current");
142 if(
sizeof(
$data[
"active"]))
144 $ilToolbar->addSeparator();
145 $ilToolbar->addFormButton($lng->txt(
"export"),
"currentExport");
148 $tpl->setContent($this->
render(
$data, $scale, $measure));
163 protected function short($a_export =
false)
167 $ilTabs->activateSubTab(
"short");
178 str_pad($org[
"m"], 2,
"0", STR_PAD_LEFT).
179 str_pad($org[
"d"], 2,
"0", STR_PAD_LEFT);
198 $time_to = mktime(23, 59, 59, substr($start, 4, 2), substr($start, 6, 2),
199 substr($start, 0, 4));
203 $time_from = $time_to-60*60*24;
207 case self::MODE_WEEK:
208 $time_from = $time_to-60*60*24*7;
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];
224 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
225 $ilToolbar->setFormAction($ilCtrl->getFormAction($this,
"short"));
229 $ilToolbar->addInputItem($start_selector,
true);
231 $mode_selector =
new ilSelectInputGUI(
" ".$lng->txt(
"trac_scale"),
"smd");
233 $mode_selector->setValue($mode);
234 $ilToolbar->addInputItem($mode_selector,
true);
236 $measure_options = array(
237 "avg" => $lng->txt(
"trac_session_active_avg"),
238 "min" => $lng->txt(
"trac_session_active_min"),
239 "max" => $lng->txt(
"trac_session_active_max"));
241 $measure_selector =
new ilSelectInputGUI(
" ".$lng->txt(
"trac_measure"),
"smm");
242 $measure_selector->
setOptions($measure_options);
243 $measure_selector->setValue($measure);
244 $ilToolbar->addInputItem($measure_selector,
true);
246 $ilToolbar->addFormButton($lng->txt(
"ok"),
"short");
248 if(
sizeof(
$data[
"active"]))
250 $ilToolbar->addSeparator();
251 $ilToolbar->addFormButton($lng->txt(
"export"),
"shortExport");
254 $tpl->setContent($this->
render(
$data, $scale, $measure));
267 protected function long($a_export =
false)
271 $ilTabs->activateSubTab(
"long");
282 str_pad($org[
"m"], 2,
"0", STR_PAD_LEFT).
283 str_pad($org[
"d"], 2,
"0", STR_PAD_LEFT);
295 $time_to = mktime(23, 59, 59, substr($start, 4, 2), substr($start, 6, 2),
296 substr($start, 0, 4));
299 case self::MODE_WEEK:
300 $time_from = $time_to-60*60*24*7;
304 case self::MODE_MONTH:
305 $time_from = $time_to-60*60*24*30;
309 case self::MODE_YEAR:
310 $time_from = $time_to-60*60*24*365;
315 $mode_options = array(
316 self::MODE_WEEK => $lng->txt(
"trac_session_statistics_mode_week"),
317 self::MODE_MONTH => $lng->txt(
"trac_session_statistics_mode_month"),
318 self::MODE_YEAR => $lng->txt(
"trac_session_statistics_mode_year")
321 $title = $lng->txt(
"trac_long_system_load").
" - ".$mode_options[$mode];
327 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
328 $ilToolbar->setFormAction($ilCtrl->getFormAction($this,
"long"));
332 $ilToolbar->addInputItem($start_selector,
true);
334 $mode_selector =
new ilSelectInputGUI(
" ".$lng->txt(
"trac_scale"),
"smd");
336 $mode_selector->setValue($mode);
337 $ilToolbar->addInputItem($mode_selector,
true);
339 $ilToolbar->addFormButton($lng->txt(
"ok"),
"long");
341 if(
sizeof(
$data[
"active"]))
343 $ilToolbar->addSeparator();
344 $ilToolbar->addFormButton($lng->txt(
"export"),
"longExport");
364 $ilTabs->activateSubTab(
"periodic");
375 "-".str_pad($org[
"m"], 2,
"0", STR_PAD_LEFT).
376 "-".str_pad($org[
"d"], 2,
"0", STR_PAD_LEFT);
383 $_REQUEST[
"sto"] = date(
"Y-m-d", strtotime(
"-7 days"));
389 "-".str_pad($org[
"m"], 2,
"0", STR_PAD_LEFT).
390 "-".str_pad($org[
"d"], 2,
"0", STR_PAD_LEFT);
395 $time_to = mktime(23, 59, 59, substr($start, 5, 2), substr($start, 8, 2),
396 substr($start, 0, 4));
397 $time_from = mktime(0, 0, 1, substr($end, 5, 2), substr($end, 8, 2),
401 if($time_to < $time_from)
404 $time_to = $time_from;
408 $title = $lng->txt(
"trac_periodic_system_load");
414 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
415 $ilToolbar->setFormAction($ilCtrl->getFormAction($this,
"periodic"));
419 $ilToolbar->addInputItem($end_selector,
true);
423 $ilToolbar->addInputItem($start_selector,
true);
425 $ilToolbar->addFormButton($lng->txt(
"ok"),
"periodic");
427 if(
sizeof(
$data[
"active"]))
429 $ilToolbar->addSeparator();
430 $ilToolbar->addFormButton($lng->txt(
"export"),
"periodicExport");
433 $tpl->setContent($this->
render(
$data, self::SCALE_PERIODIC_WEEK));
452 include_once
"Services/Authentication/classes/class.ilSessionControl.php";
455 $control_active = ($ilSetting->get(
'session_handling_type', 0) == 1);
470 $left =
new ilTemplate(
"tpl.session_statistics_left.html",
true,
true,
"Services/Authentication");
472 $left->setVariable(
"CAPTION_CURRENT", $lng->txt(
"users_online"));
473 $left->setVariable(
"VALUE_CURRENT", $active);
475 $left->setVariable(
"CAPTION_LAST_AGGR", $lng->txt(
"trac_last_aggregation"));
478 $left->setVariable(
"CAPTION_LAST_MAX", $lng->txt(
"trac_last_maxed_out_sessions"));
481 $left->setVariable(
"CAPTION_SESSION_CONTROL", $lng->txt(
"sess_load_dependent_session_handling"));
484 $left->setVariable(
"VALUE_SESSION_CONTROL", $lng->txt(
"no"));
488 $left->setVariable(
"VALUE_SESSION_CONTROL", $lng->txt(
"yes"));
490 $left->setCurrentBlock(
"control_details");
492 $left->setVariable(
"CAPTION_SESSION_CONTROL_LIMIT", $lng->txt(
"session_max_count"));
493 $left->setVariable(
"VALUE_SESSION_CONTROL_LIMIT", $control_max_sessions);
495 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_MIN", $lng->txt(
"session_min_idle"));
496 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_MIN", $control_min_idle);
498 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_MAX", $lng->txt(
"session_max_idle"));
499 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_MAX", $control_max_idle);
501 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_FIRST", $lng->txt(
"session_max_idle_after_first_request"));
502 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_FIRST", $control_max_idle_first);
504 $left->parseCurrentBlock();
508 if($ilAccess->checkAccess(
"write",
"", (
int)
$_REQUEST[
"ref_id"]))
510 $left->setVariable(
"URL_SYNC", $ilCtrl->getFormAction($this,
"adminSync"));
511 $left->setVariable(
"CMD_SYNC",
"adminSync");
512 $left->setVariable(
"TXT_SYNC", $lng->txt(
"trac_sync_session_stats"));
518 protected function buildData($a_time_from, $a_time_to, $a_title)
526 $opened = (int)$counters[
"opened"];
527 $closed_limit = (int)$counters[
"closed_limit"];
528 unset($counters[
"opened"]);
529 unset($counters[
"closed_limit"]);
537 $data[
"title"] = $a_title.
" (".
541 $data[
"maxed_out_time"] = array($lng->txt(
"trac_maxed_out_time"), $maxed_out_duration);
542 $data[
"maxed_out_counter"] = array($lng->txt(
"trac_maxed_out_counter"), $closed_limit);
543 $data[
"opened"] = array($lng->txt(
"trac_sessions_opened"), $opened);
544 $data[
"closed"] = array($lng->txt(
"trac_sessions_closed"), array_sum($counters));
545 foreach($counters as $type => $counter)
547 $data[
"closed_details"][] = array($lng->txt(
"trac_".$type), (int)$counter);
555 protected function render($a_data, $a_scale, $a_measure = null)
559 $center =
new ilTemplate(
"tpl.session_statistics_center.html",
true,
true,
"Services/Authentication");
561 foreach($a_data as $idx => $item)
570 case "closed_details":
571 $center->setCurrentBlock(
"closed_details");
572 foreach($item as $detail)
574 $center->setVariable(
"CAPTION_CLOSED_DETAILS", $detail[0]);
575 $center->setVariable(
"VALUE_CLOSED_DETAILS", $detail[1]);
576 $center->parseCurrentBlock();
581 $tpl_var = strtoupper($idx);
582 $center->setVariable(
"CAPTION_".$tpl_var, $item[0]);
583 $center->setVariable(
"VALUE_".$tpl_var, $item[1]);
588 if($a_data[
"active"])
590 $center->setVariable(
"CHART", $this->
getChart($a_data[
"active"], $a_data[
"title"], $a_scale, $a_measure));
597 return $center->get();
609 protected function getChart($a_data, $a_title, $a_scale = self::SCALE_DAY, $a_measure = null)
613 include_once
"Services/Chart/classes/class.ilChart.php";
614 $chart =
new ilChart(
"objstacc", 700, 500);
615 $chart->setYAxisToInteger(
true);
622 $a_measure = array(
"min",
"avg",
"max");
624 else if(!is_array($a_measure))
626 $a_measure = array($a_measure);
629 $colors_map = array(
"min" =>
"#00cc00",
633 $colors = $act_line = array();
634 foreach($a_measure as $measure)
637 $act_line[$measure]->setLineSteps(
true);
638 $act_line[$measure]->setLabel($lng->txt(
"trac_session_active_".$measure));
639 $colors[] = $colors_map[$measure];
642 if($a_scale != self::SCALE_PERIODIC_WEEK)
645 $max_line->setLabel($lng->txt(
"session_max_count"));
646 $colors[] =
"#cc0000";
649 $chart->setColors($colors);
654 $scale = ceil(
sizeof($chart_data)/5);
656 foreach($chart_data as $idx => $item)
658 $date = $item[
"slot_begin"];
660 if($a_scale == self::SCALE_PERIODIC_WEEK || !($idx % ceil($scale)))
664 case self::SCALE_DAY:
665 $labels[$date] = date(
"H:i", $date);
668 case self::SCALE_WEEK:
669 $labels[$date] = date(
"d.m. H", $date).
"h";
672 case self::SCALE_MONTH:
673 $labels[$date] = date(
"d.m.", $date);
676 case self::SCALE_YEAR:
677 $labels[$date] = date(
"Y-m", $date);
680 case self::SCALE_PERIODIC_WEEK:
681 $day = substr($date, 0, 1);
682 $hour = substr($date, 1, 2);
683 $min = substr($date, 3, 2);
686 $day_value = ($day-1)*60*60*24;
687 $date = $day_value+$hour*60*60+$min*60;
690 if($hour != $old_hour && $hour && $hour%6 == 0)
692 $labels[$date] = $hour;
705 foreach($a_measure as $measure)
707 $value = (int)$item[
"active_".$measure];
708 $act_line[$measure]->addPoint($date, $value);
711 if($a_scale != self::SCALE_PERIODIC_WEEK)
713 $max_line->addPoint($date, (
int)$item[
"max_sessions"]);
717 foreach($act_line as $line)
719 $chart->addData($line);
721 if($a_scale != self::SCALE_PERIODIC_WEEK)
723 $chart->addData($max_line);
726 $chart->setTicks($labels, null,
true);
728 return $chart->getHTML();
736 case self::SCALE_DAY:
740 case self::SCALE_WEEK:
746 foreach($a_data as $item)
748 $date_parts = getdate($item[
"slot_begin"]);
753 case self::SCALE_MONTH:
755 $slot = mktime($date_parts[
"hours"], 0, 0, $date_parts[
"mon"], $date_parts[
"mday"], $date_parts[
"year"]);
758 case self::SCALE_YEAR:
760 $slot = mktime(0, 0, 1, $date_parts[
"mon"], $date_parts[
"mday"], $date_parts[
"year"]);
763 case self::SCALE_PERIODIC_WEEK:
765 $day = $date_parts[
"wday"];
770 $slot = $day.date(
"His", $item[
"slot_begin"]);
775 foreach($item as $id => $value)
777 switch(substr($id, -3))
780 if(!$tmp[$slot][$id] || $value < $tmp[$slot][$id])
782 $tmp[$slot][$id] = $value;
787 if(!$tmp[$slot][$id] || $value > $tmp[$slot][$id])
789 $tmp[$slot][$id] = $value;
794 $tmp[$slot][$id][] = $value;
800 foreach($tmp as $slot => $attr)
802 $tmp[$slot][
"active_avg"] = (int)round(array_sum($attr[
"active_avg"])/
sizeof($attr[
"active_avg"]));
803 $tmp[$slot][
"slot_begin"] = $slot;
806 return array_values($tmp);
819 $ilCtrl->redirect($this);
827 include_once
'./Services/Link/classes/class.ilLink.php';
829 include_once
"./Services/Utilities/classes/class.ilCSVWriter.php";
831 $csv->setSeparator(
";");
837 $lng->txt(
"trac_name_of_installation") => $ilClientIniFile->readVariable(
'client',
'name'),
838 $lng->txt(
"trac_report_date") =>
840 $lng->txt(
"trac_report_owner") => $ilUser->getFullName(),
842 foreach($a_data as $idx => $item)
847 $meta[$lng->txt(
"title")] = $item;
854 case "closed_details":
855 foreach($item as $detail)
857 $meta[$a_data[
"closed"][0].
" - ".$detail[0]] = $detail[1];
862 $meta[$item[0]] = $item[1];
866 foreach($meta as $caption => $value)
868 $csv->addColumn(strip_tags($caption));
869 $csv->addColumn(strip_tags($value));
880 $first = array_keys(array_shift($first));
881 foreach ($first as $column)
884 if($a_scale == self::SCALE_PERIODIC_WEEK && $column ==
"slot_begin")
886 $csv->addColumn(
"weekday");
887 $csv->addColumn(
"time");
891 $csv->addColumn(strip_tags($column));
897 foreach($aggr_data as
$row)
899 foreach ($row as $column => $value)
903 $value = implode(
', ', $value);
909 if($a_scale == self::SCALE_PERIODIC_WEEK)
912 $value = substr($value, 1, 2).
":".substr($value, 3, 2);
918 $value = date(
"d.m.Y H:i", $value);
921 $csv->addColumn(strip_tags($value));
927 $filename .=
"session_statistics_".date(
"Ymd", $now).
".csv";
928 header(
"Content-type: text/comma-separated-values");
929 header(
"Content-Disposition: attachment; filename=\"".
$filename.
"\"");
930 header(
"Expires: 0");
931 header(
"Cache-Control: must-revalidate, post-check=0,pre-check=0");
932 header(
"Pragma: public");
933 echo $csv->getCSVString();