-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadminTools.php
More file actions
280 lines (237 loc) · 13.7 KB
/
Copy pathadminTools.php
File metadata and controls
280 lines (237 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php
require __DIR__ . "/../../config/bootstrap.php";
redirectToolDevOutside();
# find available tools - by user
$tools = array();
$result = array();
$stats_filter = array();
// query 'tools' collection
if ($_SESSION['User']['Type'] == UserType::Admin->value) {
// do query
$result = $GLOBALS['toolsCol']->find(array());
} elseif ($_SESSION['User']['Type'] == UserType::ToolDev->value) {
if ($_SESSION['User']['ToolsDev']) {
// do query
$result = $GLOBALS['toolsCol']->find(array("_id" => array('$in' => $_SESSION['User']['ToolsDev'])));
// prepare stats filter
$stats_filter = array("toolId" => array('$in' => $_SESSION['User']['ToolsDev']));
} else {
// return error
$_SESSION['errorData']['Error'][] = "Sorry, your account has no tool ownership. Sorry, cannot adminstrate them.";
// do dump query
$result = $GLOBALS['toolsCol']->find(array("_id" => "force_empty"));
// prepare dump stats filter
$stats_filter = array("force" => "empty");
}
} else {
redirect($GLOBALS['URL']);
}
// format query result
foreach (array_values(iterator_to_array($result)) as $v) {
$toolId = $v['_id'];
$tools[$toolId]['json'] = $v;
if ($tools[$toolId]['json']['owner']['user']) {
$tools[$toolId]['json']["owners"] = array($tools[$toolId]['json']['owner']['user']);
} else {
$tools[$toolId]['json']["owners"] = array($tools[$toolId]['json']['owner']['author']);
}
}
// get statistics
if ($_REQUEST['tools']) {
if (! is_array($_REQUEST['tools'])) {
$_REQUEST['tools'] = array($_REQUEST['tools']);
}
$stats_filter = array("toolId" => array('$in' => $_REQUEST['tools']));
}
$jobs = aggregateJobLogs($stats_filter);
$stats = getStatsFromJobLogs($jobs, array_keys($tools));
//// if export=true, generate CSV and exit
if ($_REQUEST['export'] == 1) {
// set CSV name
$filename = 'VRE_jobstats_' . date('m-d-Y') . ".csv";
// print job entry per line
ob_start();
ob_clean();
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=' . $filename);
printCSVJobLogs($jobs, 'php://output');
ob_flush();
die(0);
}
//// if no export, print logs html page
$toolsList = $tools;
?>
<?php require "../htmlib/header.inc.php"; ?>
<body class="page-header-fixed page-sidebar-closed-hide-logo page-content-white page-container-bg-solid page-sidebar-fixed">
<div class="page-wrapper">
<?php require "../htmlib/top.inc.php"; ?>
<?php require "../htmlib/menu.inc.php"; ?>
<!-- BEGIN CONTENT -->
<div class="page-content-wrapper">
<!-- BEGIN CONTENT BODY -->
<div class="page-content">
<!-- BEGIN PAGE HEADER-->
<!-- BEGIN PAGE BAR -->
<div class="page-bar">
<ul class="page-breadcrumb">
<li>
<span>Admin</span>
<i class="fa fa-circle"></i>
</li>
<li>
<span>My installed Tools</span>
</li>
</ul>
</div>
<!-- END PAGE BAR -->
<!-- BEGIN PAGE TITLE-->
<h1 class="page-title"> My Tools Administration
<small>configure & test</small>
<div class="btn-group" style="float:right;">
<div class="actions">
<a href="admin/adminTools.php?export=1" class="btn green"><i class="fa fa-download"></i> Download Statistics </a>
</div>
</div>
</h1>
<!-- END PAGE TITLE-->
<!-- END PAGE HEADER-->
<div class="row">
<div class="col-md-12">
<?php
$error_data = false;
if ($_SESSION['errorData']) {
$error_data = true;
?>
<?php if ($_SESSION['errorData']['Info']) { ?>
<div class="alert alert-info">
<?php } else { ?>
<div class="alert alert-danger">
<?php } ?>
<?php
foreach ($_SESSION['errorData'] as $subTitle => $txts) {
print "<strong>$subTitle</strong><br/>";
foreach ($txts as $txt) {
print "<div>$txt</div>";
}
}
unset($_SESSION['errorData']);
?>
</div>
<?php } ?>
</div>
</div>
<div class="row">
<div class="col-md-12">
<!-- BEGIN EXAMPLE TABLE PORTLET-->
<div class="portlet light portlet-fit bordered">
<div class="portlet-body">
<input type="hidden" id="base-url" value="<?php echo $GLOBALS['BASEURL']; ?>" />
<table class="table table-striped table-hover table-bordered" id="sample_editable_1">
<thead>
<tr>
<th>Tool Id</th>
<th>Status</th>
<th>Owner/s</th>
<th>Tool specification</th>
<th>Statistics</th>
</tr>
</thead>
<tbody>
<?php
foreach ($toolsList as $toolId => $v) {
?>
<tr>
<td><?php echo $toolId; ?></td>
<td><?php
if (!$v["json"]["external"]) {
// show Internal tool
echo '<span class="label label-default"><b>Internal</b></span>';
} else {
// allow update status
if ($_SESSION['User']['Type'] == UserType::Admin->value || ($_SESSION["User"]["Type"] == UserType::ToolDev->value && in_array($toolId, $_SESSION['User']['ToolsDev']))) {
echo ' <select onChange="changeToolStatus(\'' . $toolId . '\', this);">';
echo ' <option value="" disabled selected> status...</option>';
foreach ($GLOBALS['tool_status'] as $k => $stts) {
echo '<option value="' . $k . '" ' . $sel . '>' . $stts . '</option>';
}
echo '</select> ';
}
switch ($v["json"]["status"]) {
case 0:
echo '<span class="label label-warning"><b> ' . $GLOBALS['tool_status'][$v["json"]["status"]] . ' </b></span>';
break;
case 1:
echo '<span class="label label-primary"><b> ' . $GLOBALS['tool_status'][$v["json"]["status"]] . ' </b></span>';
break;
case 2:
echo '<span class="label label-danger"><b> ' . $GLOBALS['tool_status'][$v["json"]["status"]] . ' </b></span>';
break;
case 3:
echo '<span class="label bg-purple-intense"><b> ' . $GLOBALS['tool_status'][$v["json"]["status"]] . '</b></span>';
break;
}
}
?>
</td>
<td>
<?php echo implode(",<br/>", $v["json"]["owners"]); ?>
<td>
<a href="javascript:callShowToolJson('<?php echo $toolId; ?>')">View JSON</a>
</td>
<td>
<?php if ($stats[$toolId]["jobs_total"]) { ?>
<ul>
<li><?php echo "Total num. of jobs: " . $stats[$toolId]["jobs_total"]; ?></li>
<li><?php echo "Successfully finished: " . number_format(($stats[$toolId]["jobs_finished_success"] / $stats[$toolId]["jobs_total"]) * 100, 2) . "%"; ?></li>
<li><?php echo "Distinct users: " . count(array_keys($stats[$toolId]["distinct_users"])); ?></li>
<li><?php echo "Average duration: " . $stats[$toolId]["avg_duration"] . " minutes"; ?></li>
</ul>
<!--
<div class="sparkline-chart">
<span id="spark_registers"><?php //$i = 1; foreach($stats[$toolId]["freq_executions"] as $k => $v){ if($i < sizeof($$stats[$toolId]["freq_executions"])) { echo $v.','; }else{ echo $v; } $i++; }
?></span>
<p style="margin-top:15px;">Monthly new users</p>
</div> -->
<p><a href="admin/adminTools.php?tools=<?php echo $toolId; ?>&export=1" class="btn btn-sm green"><i class="fa fa-download"></i> Download statistics </a></p>
<?php } else { ?>
<ul>
<li><?php echo "Total num. of jobs: " . $stats[$toolId]["jobs_total"]; ?></li>
</ul>
<?php } ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<!-- END EXAMPLE TABLE PORTLET-->
</div>
</div>
</div>
<!-- END CONTENT BODY -->
</div>
<!-- END CONTENT -->
<div class="modal fade bs-modal" id="modalAnalysis" tabindex="-1" role="basic" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Execution Summary</h4>
</div>
<div class="modal-body table-responsive"></div>
<div class="modal-footer">
<button type="button" class="btn dark btn-outline" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php
require "../htmlib/footer.inc.php";
require "../htmlib/js.inc.php";
?>