ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
showstats.php
Go to the documentation of this file.
1 <?php
2 
6 
8 
9 /*
10  * Check input parameters
11  */
12 $preferRule = null;
13 $preferRule2 = null;
14 $preferTime = null;
16 $delimiter = null;
17 
18 if (array_key_exists('rule', $_REQUEST)) {
19  $preferRule = $_REQUEST['rule'];
20 }
21 if (array_key_exists('rule2', $_REQUEST)) {
22  $preferRule2 = $_REQUEST['rule2'];
23 }
24 if (array_key_exists('time', $_REQUEST)) {
25  $preferTime = $_REQUEST['time'];
26 }
27 if (array_key_exists('res', $_REQUEST)) {
28  $preferTimeRes = $_REQUEST['res'];
29 }
30 if (array_key_exists('d', $_REQUEST)) {
31  $delimiter = $_REQUEST['d'];
32 }
33 
34 if ($preferRule2 === '_') {
35  $preferRule2 = null;
36 }
37 
38 /*
39  * Create statistics data.
40  */
43 $rule = $statrule->getRuleID();
44 
45 $t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics.tpl.php');
46 $t->data['pageid'] = 'statistics';
47 $t->data['header'] = 'stat';
48 $t->data['available.rules'] = $ruleset->availableRulesNames();
49 $t->data['selected.rule'] = $rule;
50 $t->data['selected.rule2'] = $preferRule2;
51 
52 try {
53  $dataset = $statrule->getDataset($preferTimeRes, $preferTime);
54  $dataset->setDelimiter($delimiter);
55  $dataset->aggregateSummary();
56  $dataset->calculateMax();
57 
58  if (array_key_exists('output', $_REQUEST) && $_REQUEST['output'] === 'csv') {
59  header('Content-type: text/csv');
60  header('Content-Disposition: attachment; filename="simplesamlphp-data.csv"');
61  $data = $dataset->getDebugData();
62  foreach ($data as $de) {
63  if (isset($de[1])) {
64  echo '"'.$de[0].'",'.$de[1]."\n";
65  }
66  }
67  exit;
68  }
69 } catch (Exception $e) {
70  $t->data['error'] = "No data available";
71  $t->show();
72  exit;
73 }
74 
75 $delimiter = $dataset->getDelimiter();
76 
77 $timeres = $dataset->getTimeRes();
78 $fileslot = $dataset->getFileslot();
79 $availableFileSlots = $statrule->availableFileSlots($timeres);
80 
82 
83 $piedata = $dataset->getPieData();
84 
85 $datasets = array();
86 $datasets[] = $dataset->getPercentValues();
87 
88 $axis = $dataset->getAxis();
89 
90 $maxes = array();
91 
92 $maxes[] = $dataset->getMax();
93 
94 if (isset($preferRule2)) {
95  $statrule = $ruleset->getRule($preferRule2);
96  try {
97  $dataset2 = $statrule->getDataset($preferTimeRes, $preferTime);
98  $dataset2->aggregateSummary();
99  $dataset2->calculateMax();
100 
101  $datasets[] = $dataset2->getPercentValues();
102  $maxes[] = $dataset2->getMax();
103  } catch (Exception $e) {
104  $t->data['error'] = "No data available to compare";
105  $t->show();
106  exit;
107  }
108 }
109 
110 $dimx = $statconfig->getValue('dimension.x', 800);
111 $dimy = $statconfig->getValue('dimension.y', 350);
113 
114 $t->data['imgurl'] = $grapher->show($axis['axis'], $axis['axispos'], $datasets, $maxes);
115 if (isset($piedata)) {
116  $t->data['pieimgurl'] = $grapher->showPie($dataset->getDelimiterPresentationPie(), $piedata);
117 }
118 $t->data['available.times'] = $statrule->availableFileSlots($timeres);
119 $t->data['available.timeres'] = $statrule->availableTimeRes();
120 $t->data['available.times.prev'] = $timeNavigation['prev'];
121 $t->data['available.times.next'] = $timeNavigation['next'];
122 
123 $t->data['selected.time'] = $fileslot;
124 $t->data['selected.timeres'] = $timeres;
125 $t->data['selected.delimiter'] = $delimiter;
126 
127 $t->data['debugdata'] = $dataset->getDebugData();
128 $t->data['results'] = $dataset->getResults();
129 $t->data['summaryDataset'] = $dataset->getSummary();
130 $t->data['topdelimiters'] = $dataset->getTopDelimiters();
131 $t->data['availdelimiters'] = $dataset->availDelimiters();
132 
133 $t->data['delimiterPresentation'] = $dataset->getDelimiterPresentation();
134 
135 $t->data['post_rule'] = getBaseURL($t, 'post', 'rule');
136 $t->data['post_rule2'] = getBaseURL($t, 'post', 'rule2');
137 $t->data['post_d'] = getBaseURL($t, 'post', 'd');
138 $t->data['post_res'] = getBaseURL($t, 'post', 'res');
139 $t->data['post_time'] = getBaseURL($t, 'post', 'time');
140 $t->data['get_times_prev'] = getBaseURL($t, 'get', 'time', $t->data['available.times.prev']);
141 $t->data['get_times_next'] = getBaseURL($t, 'get', 'time', $t->data['available.times.next']);
142 
143 $t->show();
144 
145 function getBaseURL($t, $type = 'get', $key = null, $value = null)
146 {
147  $vars = array(
148  'rule' => $t->data['selected.rule'],
149  'time' => $t->data['selected.time'],
150  'res' => $t->data['selected.timeres'],
151  );
152  if (isset($t->data['selected.delimiter'])) {
153  $vars['d'] = $t->data['selected.delimiter'];
154  }
155  if (!empty($t->data['selected.rule2']) && $t->data['selected.rule2'] !== '_') {
156  $vars['rule2'] = $t->data['selected.rule2'];
157  }
158 
159  if (isset($key)) {
160  if (isset($vars[$key])) {
161  unset($vars[$key]);
162  }
163  if (isset($value)) {
164  $vars[$key] = $value;
165  }
166  }
167 
168  if ($type === 'get') {
169  return SimpleSAML\Module::getModuleURL("statistics/showstats.php").'?'.http_build_query($vars, '', '&amp;');
170  } else {
171  $text = '';
172  foreach ($vars as $k => $v) {
173  $text .= '<input type="hidden" name="'.$k.'" value="'.htmlspecialchars($v).'" />'."\n";
174  }
175  return $text;
176  }
177 }
$availableFileSlots
Definition: showstats.php:79
$preferRule2
Definition: showstats.php:13
$piedata
Definition: showstats.php:83
$config
Definition: showstats.php:3
if(isset($preferRule2)) $dimx
Definition: showstats.php:110
$session
Definition: showstats.php:5
$delimiter
Definition: showstats.php:16
$type
if(array_key_exists('rule', $_REQUEST)) if(array_key_exists('rule2', $_REQUEST)) if(array_key_exists('time', $_REQUEST)) if(array_key_exists('res', $_REQUEST)) if(array_key_exists('d', $_REQUEST)) if($preferRule2==='_') $ruleset
Definition: showstats.php:41
$fileslot
Definition: showstats.php:78
$statconfig
Definition: showstats.php:4
$dimy
Definition: showstats.php:111
$timeres
Definition: showstats.php:77
$timeNavigation
Definition: showstats.php:81
static checkAccess(SimpleSAML_Configuration $statconfig)
Check that the user has access to the statistics.
Definition: AccessCheck.php:15
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:220
$preferRule
Definition: showstats.php:12
$datasets
Definition: showstats.php:85
$rule
Definition: showstats.php:43
getBaseURL($t, $type='get', $key=null, $value=null)
Definition: showstats.php:145
$preferTimeRes
Definition: showstats.php:15
$text
Definition: errorreport.php:18
static getConfig($filename='config.php', $configSet='simplesaml')
Load a configuration file from a configuration set.
$statrule
Definition: showstats.php:42
exit
Definition: backend.php:16
$t
Definition: showstats.php:45
$preferTime
Definition: showstats.php:14
$grapher
Definition: showstats.php:112
$axis
Definition: showstats.php:88
$maxes
Definition: showstats.php:90
$key
Definition: croninfo.php:18
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:241
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
$data
Definition: bench.php:6