5include_once
"Services/Authentication/classes/class.ilSessionStatistics.php";
38 switch($ilCtrl->getNextClass())
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");
73 $mode = (int)$_REQUEST[
"smd"];
78 $_REQUEST[
"smm"] =
"avg";
80 $measure = (string)$_REQUEST[
"smm"];
86 $time_from = strtotime(
"today");
87 $time_to = strtotime(
"tomorrow")-1;
93 $time_from = $time_to-60*60*24;
99 $time_from = $time_to-60*60*24*7;
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"));
126 $mode_selector->setOptions($mode_options);
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"));
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");
163 protected function importDate($a_incoming, $a_default =
null)
170 include_once
"Services/Calendar/classes/class.ilCalendarUtil.php";
177 protected function short($a_export =
false)
181 $ilTabs->activateSubTab(
"short");
184 $time_to = $this->
importDate($_REQUEST[
"sst"]);
187 if(!$_REQUEST[
"smd"])
191 $mode = (int)$_REQUEST[
"smd"];
194 if(!$_REQUEST[
"smm"])
196 $_REQUEST[
"smm"] =
"avg";
198 $measure = (string)$_REQUEST[
"smm"];
203 $time_from = $time_to-60*60*24;
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);
232 $mode_selector->setOptions($mode_options);
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"));
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");
267 protected function long($a_export =
false)
271 $ilTabs->activateSubTab(
"long");
274 $time_to = $this->
importDate($_REQUEST[
"sst"]);
277 if(!$_REQUEST[
"smd"])
281 $mode = (int)$_REQUEST[
"smd"];
286 $time_from = $time_to-60*60*24*7;
291 $time_from = $time_to-60*60*24*30;
296 $time_from = $time_to-60*60*24*365;
301 $mode_options = array(
302 self::MODE_WEEK =>
$lng->txt(
"trac_session_statistics_mode_week"),
303 self::MODE_MONTH =>
$lng->txt(
"trac_session_statistics_mode_month"),
304 self::MODE_YEAR =>
$lng->txt(
"trac_session_statistics_mode_year")
307 $title =
$lng->txt(
"trac_long_system_load").
" - ".$mode_options[$mode];
313 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
314 $ilToolbar->setFormAction(
$ilCtrl->getFormAction($this,
"long"));
318 $ilToolbar->addInputItem($start_selector,
true);
321 $mode_selector->setOptions($mode_options);
322 $mode_selector->setValue($mode);
323 $ilToolbar->addInputItem($mode_selector,
true);
325 $ilToolbar->addFormButton(
$lng->txt(
"ok"),
"long");
327 if(
sizeof(
$data[
"active"]))
329 $ilToolbar->addSeparator();
330 $ilToolbar->addFormButton(
$lng->txt(
"export"),
"longExport");
350 $ilTabs->activateSubTab(
"periodic");
353 $time_to = $this->
importDate($_REQUEST[
"sst"]);
356 $time_from = $this->
importDate($_REQUEST[
"sto"], strtotime(
"-7 days"));
359 if($time_to < $time_from)
362 $time_to = $time_from;
366 $title =
$lng->txt(
"trac_periodic_system_load");
372 include_once
"Services/Form/classes/class.ilPropertyFormGUI.php";
373 $ilToolbar->setFormAction(
$ilCtrl->getFormAction($this,
"periodic"));
377 $ilToolbar->addInputItem($end_selector,
true);
381 $ilToolbar->addInputItem($start_selector,
true);
383 $ilToolbar->addFormButton(
$lng->txt(
"ok"),
"periodic");
385 if(
sizeof(
$data[
"active"]))
387 $ilToolbar->addSeparator();
388 $ilToolbar->addFormButton(
$lng->txt(
"export"),
"periodicExport");
410 include_once
"Services/Authentication/classes/class.ilSessionControl.php";
413 $control_active = (
$ilSetting->get(
'session_handling_type', 0) == 1);
428 $left =
new ilTemplate(
"tpl.session_statistics_left.html",
true,
true,
"Services/Authentication");
430 $left->setVariable(
"CAPTION_CURRENT",
$lng->txt(
"users_online"));
431 $left->setVariable(
"VALUE_CURRENT", $active);
433 $left->setVariable(
"CAPTION_LAST_AGGR",
$lng->txt(
"trac_last_aggregation"));
436 $left->setVariable(
"CAPTION_LAST_MAX",
$lng->txt(
"trac_last_maxed_out_sessions"));
439 $left->setVariable(
"CAPTION_SESSION_CONTROL",
$lng->txt(
"sess_load_dependent_session_handling"));
442 $left->setVariable(
"VALUE_SESSION_CONTROL",
$lng->txt(
"no"));
446 $left->setVariable(
"VALUE_SESSION_CONTROL",
$lng->txt(
"yes"));
448 $left->setCurrentBlock(
"control_details");
450 $left->setVariable(
"CAPTION_SESSION_CONTROL_LIMIT",
$lng->txt(
"session_max_count"));
451 $left->setVariable(
"VALUE_SESSION_CONTROL_LIMIT", $control_max_sessions);
453 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_MIN",
$lng->txt(
"session_min_idle"));
454 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_MIN", $control_min_idle);
456 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_MAX",
$lng->txt(
"session_max_idle"));
457 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_MAX", $control_max_idle);
459 $left->setVariable(
"CAPTION_SESSION_CONTROL_IDLE_FIRST",
$lng->txt(
"session_max_idle_after_first_request"));
460 $left->setVariable(
"VALUE_SESSION_CONTROL_IDLE_FIRST", $control_max_idle_first);
462 $left->parseCurrentBlock();
466 if($ilAccess->checkAccess(
"write",
"", (
int)$_REQUEST[
"ref_id"]))
468 $left->setVariable(
"URL_SYNC",
$ilCtrl->getFormAction($this,
"adminSync"));
469 $left->setVariable(
"CMD_SYNC",
"adminSync");
470 $left->setVariable(
"TXT_SYNC",
$lng->txt(
"trac_sync_session_stats"));
476 protected function buildData($a_time_from, $a_time_to, $a_title)
484 $opened = (int)$counters[
"opened"];
485 $closed_limit = (int)$counters[
"closed_limit"];
486 unset($counters[
"opened"]);
487 unset($counters[
"closed_limit"]);
495 $data[
"title"] = $a_title.
" (".
499 $data[
"maxed_out_time"] = array(
$lng->txt(
"trac_maxed_out_time"), $maxed_out_duration);
500 $data[
"maxed_out_counter"] = array(
$lng->txt(
"trac_maxed_out_counter"), $closed_limit);
501 $data[
"opened"] = array(
$lng->txt(
"trac_sessions_opened"), $opened);
502 $data[
"closed"] = array(
$lng->txt(
"trac_sessions_closed"), array_sum($counters));
503 foreach($counters as $type =>
$counter)
513 protected function render($a_data, $a_scale, $a_measure =
null)
517 $center =
new ilTemplate(
"tpl.session_statistics_center.html",
true,
true,
"Services/Authentication");
519 foreach($a_data as $idx => $item)
528 case "closed_details":
529 $center->setCurrentBlock(
"closed_details");
530 foreach($item as $detail)
532 $center->setVariable(
"CAPTION_CLOSED_DETAILS", $detail[0]);
533 $center->setVariable(
"VALUE_CLOSED_DETAILS", $detail[1]);
534 $center->parseCurrentBlock();
539 $tpl_var = strtoupper($idx);
540 $center->setVariable(
"CAPTION_".$tpl_var, $item[0]);
541 $center->setVariable(
"VALUE_".$tpl_var, $item[1]);
546 if($a_data[
"active"])
548 $center->setVariable(
"CHART", $this->
getChart($a_data[
"active"], $a_data[
"title"], $a_scale, $a_measure));
555 return $center->get();
567 protected function getChart($a_data, $a_title, $a_scale = self::SCALE_DAY, $a_measure =
null)
571 include_once
"Services/Chart/classes/class.ilChart.php";
573 $chart->setsize(700, 500);
574 $chart->setYAxisToInteger(
true);
581 $a_measure = array(
"min",
"avg",
"max");
583 else if(!is_array($a_measure))
585 $a_measure = array($a_measure);
588 $colors_map = array(
"min" =>
"#00cc00",
592 $colors = $act_line = array();
593 foreach($a_measure as $measure)
596 $act_line[$measure]->setLineSteps(
true);
597 $act_line[$measure]->setLabel(
$lng->txt(
"trac_session_active_".$measure));
598 $colors[] = $colors_map[$measure];
601 if($a_scale != self::SCALE_PERIODIC_WEEK)
604 $max_line->setLabel(
$lng->txt(
"session_max_count"));
605 $colors[] =
"#cc0000";
608 $chart->setColors($colors);
613 $scale = ceil(
sizeof($chart_data)/5);
615 foreach($chart_data as $idx => $item)
617 $date = $item[
"slot_begin"];
619 if($a_scale == self::SCALE_PERIODIC_WEEK || !($idx % ceil($scale)))
624 $labels[$date] =
date(
"H:i", $date);
628 $labels[$date] =
date(
"d.m. H", $date).
"h";
632 $labels[$date] =
date(
"d.m.", $date);
636 $labels[$date] =
date(
"Y-m", $date);
640 $day = substr($date, 0, 1);
641 $hour = substr($date, 1, 2);
642 $min = substr($date, 3, 2);
645 $day_value = ($day-1)*60*60*24;
646 $date = $day_value+$hour*60*60+$min*60;
649 if($hour != $old_hour && $hour && $hour%6 == 0)
651 $labels[$date] = $hour;
664 foreach($a_measure as $measure)
666 $value = (int)$item[
"active_".$measure];
667 $act_line[$measure]->addPoint($date, $value);
670 if($a_scale != self::SCALE_PERIODIC_WEEK)
672 $max_line->addPoint($date, (
int)$item[
"max_sessions"]);
676 foreach($act_line as $line)
680 if($a_scale != self::SCALE_PERIODIC_WEEK)
682 $chart->addData($max_line);
685 $chart->setTicks($labels,
null,
true);
705 foreach($a_data as $item)
707 $date_parts = getdate($item[
"slot_begin"]);
714 $slot = mktime($date_parts[
"hours"], 0, 0, $date_parts[
"mon"], $date_parts[
"mday"], $date_parts[
"year"]);
719 $slot = mktime(0, 0, 1, $date_parts[
"mon"], $date_parts[
"mday"], $date_parts[
"year"]);
724 $day = $date_parts[
"wday"];
729 $slot = $day.date(
"His", $item[
"slot_begin"]);
734 foreach($item as $id => $value)
736 switch(substr($id, -3))
739 if(!$tmp[$slot][$id] || $value < $tmp[$slot][$id])
741 $tmp[$slot][$id] = $value;
746 if(!$tmp[$slot][$id] || $value > $tmp[$slot][$id])
748 $tmp[$slot][$id] = $value;
753 $tmp[$slot][$id][] = $value;
759 foreach($tmp as $slot => $attr)
761 $tmp[$slot][
"active_avg"] = (int)round(array_sum($attr[
"active_avg"])/
sizeof($attr[
"active_avg"]));
762 $tmp[$slot][
"slot_begin"] = $slot;
765 return array_values($tmp);
786 include_once
'./Services/Link/classes/class.ilLink.php';
788 include_once
"./Services/Utilities/classes/class.ilCSVWriter.php";
790 $csv->setSeparator(
";");
796 $lng->txt(
"trac_name_of_installation") => $ilClientIniFile->readVariable(
'client',
'name'),
797 $lng->txt(
"trac_report_date") =>
799 $lng->txt(
"trac_report_owner") =>
$ilUser->getFullName(),
801 foreach($a_data as $idx => $item)
806 $meta[
$lng->txt(
"title")] = $item;
813 case "closed_details":
814 foreach($item as $detail)
816 $meta[$a_data[
"closed"][0].
" - ".$detail[0]] = $detail[1];
821 $meta[$item[0]] = $item[1];
825 foreach($meta as $caption => $value)
827 $csv->addColumn(strip_tags($caption));
828 $csv->addColumn(strip_tags($value));
839 $first = array_keys(array_shift($first));
843 if($a_scale == self::SCALE_PERIODIC_WEEK &&
$column ==
"slot_begin")
845 $csv->addColumn(
"weekday");
846 $csv->addColumn(
"time");
850 $csv->addColumn(strip_tags(
$column));
856 foreach($aggr_data as
$row)
862 $value = implode(
', ', $value);
868 if($a_scale == self::SCALE_PERIODIC_WEEK)
871 $value = substr($value, 1, 2).
":".substr($value, 3, 2);
877 $value =
date(
"d.m.Y H:i", $value);
880 $csv->addColumn(strip_tags($value));
886 $filename .=
"session_statistics_".date(
"Ymd", $now).
".csv";
887 header(
"Content-type: text/comma-separated-values");
888 header(
"Content-Disposition: attachment; filename=\"".
$filename.
"\"");
889 header(
"Expires: 0");
890 header(
"Cache-Control: must-revalidate, post-check=0,pre-check=0");
891 header(
"Pragma: public");
892 echo $csv->getCSVString();
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
Helper class to generate CSV files.
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.
static _numericDayToString($a_day, $a_long=true)
get
static getInstanceByType($a_type, $a_id)
Get type instance.
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
static $session_types_controlled
const DEFAULT_MAX_IDLE_AFTER_FIRST_REQUEST
static getExistingSessionCount(array $a_types)
returns number of valid sessions relating to given session types
const DEFAULT_MAX_COUNT
default value for settings that have not been defined in setup or administration yet
Class ilSessionStatisticsGUI.
importDate($a_incoming, $a_default=null)
const SCALE_PERIODIC_WEEK
getChart($a_data, $a_title, $a_scale=self::SCALE_DAY, $a_measure=null)
Build chart for active sessions.
buildData($a_time_from, $a_time_to, $a_title)
render($a_data, $a_scale, $a_measure=null)
periodic($a_export=false)
exportCSV(array $a_data, $a_scale)
adaptDataToScale($a_scale, array $a_data)
static getActiveSessions($a_from, $a_to)
Get active sessions aggregated data.
static getLastAggregation()
Get timestamp of last aggregation.
static getMaxedOutDuration($a_from, $a_to)
Get maxed out duration in given timeframe.
static getLastMaxedOut()
Get latest slot during which sessions were maxed out.
static getNumberOfSessionsByType($a_from, $a_to)
Get session counters by type (opened, closed)
static aggretateRaw($a_now)
static _destroyExpiredSessions()
Destroy expired sessions.
special template class to simplify handling of ITX/PEAR
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.