-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetric.php
273 lines (222 loc) · 10.9 KB
/
metric.php
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
<?php
include_once('php/data.php');
include_once('php/metric.php');
?>
<!DOCTYPE html>
<html>
<head>
<?php
// Including head-contents (files, scripts, metadata,...)
echo file_get_contents("partials/head.html");
?>
<style>
#metric-info {
font-size: 18px;
}
#metric-info span {font-weight: bold;}
#metric-info div {
margin-top: 15px;
}
.checkbox {
display: inline-block;
margin-left: 15px;
}
</style>
</head>
<body>
<div id="container">
<div id="dashboard">
<img src="media/images/logo.png" id="logo">
<div id="left-nav">
<div id="opunit-select">
<span>Selected OP UNIT</span>
<span id="selected-opunit">
<?php
// Retrieving name of current opunit
foreach ($operational_units as $opunit) {
if ($opunit->id == $_GET['opunit']) {
echo $opunit->name;
break;
}
}
?>
</span>
<div id="opunits">
<ul>
<?php
// Inserting all Operational Units in top navigation bar
foreach ($operational_units as $opunit) {
echo "<li><a class='opunit' id='".$opunit->id."' href='?opunit=".$opunit->id."'>".$opunit->name."</a></li>";
}
?>
</ul>
</div>
</div>
<?php
// Outputting al dashboard-options
echo str_replace("%opunit%", $_GET['opunit'], file_get_contents("partials/dashboard-options.html"));
?>
</div>
<div id="content">
<h2>Metric aanpassen</h2>
<div id="metric-info" data-dd-id="<?php echo $dd_id; ?>" data-opunit-id="<?php echo $_GET['opunit']; ?>" data-customer-id="<?php echo $_GET['customer']; ?>">
<label>View data for month</label>
<select name='month'>
<option>Select month</option>
<?php
$i = 1;
foreach ($months as $month) {
echo "<option value='".$i."'>".$month."</option>";
$i++;
}
?>
</select>
<?php
if ($is_waived == 1) {
$is_waived = "checked";
}
if ($na == 1) {
$na = "checked";
}
echo "<div><span>Metric:</span> ".$definition." </div>";
echo "<div><span>Displayname:</span> <input type='text' value='".$displayname."' name='displayname'>";
echo "
<select name='allDisplaynames'>
<option value=''> </option>
";
foreach ($allDisplaynames as $dn => $val) {
if ($val != NULL && val != "") {
echo "<option>".$val."</option>";
}
}
echo "
</select></div>
";
echo "<div><span>Target:</span> <input type='text' value='' name='target'></div>";
echo "<div><span>Expression:</span> <input type='text' value='' name='expr'></div>";
echo "<div><span>Waived:</span> <input type='checkbox' name='is_waived'></div>";
echo "<div><span>Not applicable:</span> <input type='checkbox' name='na'></div>";
echo "<div><span>No data:</span> <input type='checkbox' name='no_data'></div>";
echo "<div><span>Level:</span>
<select name='level'>
<option value='0'>None</option>
<option value='1'>Starter</option>
<option value='2'>Regular</option>
<option value='3'>Advanced</option>
</select>
</div>";
echo "<br>";
echo "<label>Save data for month</label>";
$i = 1;
foreach ($months as $month) {
echo "<input type='checkbox' name='month[]' value='".$i."' class='checkbox'><label class='month-label'>".$month."</label'>";
$i++;
}
?>
<br><br>
<button id="save">Save</button>
</div>
</div>
</div>
</div>
<script>
document.getElementById("save").addEventListener('click', save_data);
document.getElementsByName("month")[0].addEventListener('change', get_data);
document.getElementsByName("allDisplaynames")[0].addEventListener('change', change_dn);
function change_dn(e) {
document.getElementsByName("displayname")[0].value = e.target.value;
get_data();
}
function get_data() {
let month = document.getElementsByName("month")[0].value;
let definition = document.getElementById("metric-info").getAttribute("data-definition-id");
let opunit = document.getElementById("metric-info").getAttribute("data-opunit-id");
let customer = document.getElementById("metric-info").getAttribute("data-customer-id");
let dd_id = document.getElementById("metric-info").getAttribute("data-dd-id");
let displayname = document.getElementsByName("displayname")[0].value;
let url = "php/metric.php?getdata=true&month=" + month + "&dd=" + dd_id + "&opunit=" + opunit + "&displayname=" + displayname;
$.ajax({
type: 'GET',
url: url,
data: $(this).serialize(),
success: function(response) {
console.log(response);
let data = response.split(',');
//let dd_id = data[0];
//let definition = data[1];
let displayname = data[0];
let target = data[1];
let expr = data[2];
let is_waived = data[3];
let na = data[4];
let no_data = data[5];
let level = data[6];
document.getElementsByName("target")[0].value = target;
document.getElementsByName("expr")[0].value = expr;
//alert(response);
document.getElementsByName("is_waived")[0].checked = false;
document.getElementsByName("na")[0].checked = false;
document.getElementsByName("no_data")[0].checked = false;
if (is_waived == "1") {
document.getElementsByName("is_waived")[0].checked = true;
}
if (na == "1") {
document.getElementsByName("na")[0].checked = true;
}
if (no_data == "1") {
document.getElementsByName("no_data")[0].checked = true;
}
document.getElementsByName("level")[0].selectedIndex = level;
}
});
}
function save_data(e) {
//let row_to_edit = e.target.parentElement.getAttribute("data-id");
let definition = document.getElementById("metric-info").getAttribute("data-definition-id");
let opsunit = document.getElementById("metric-info").getAttribute("data-opunit-id");
let customer = document.getElementById("metric-info").getAttribute("data-customer-id");
let month = document.getElementsByName("month[]");
let dd_id = document.getElementById("metric-info").getAttribute("data-dd-id");
var checked_months = [];
$("input[name='month[]']").each(function() {
if ($(this).is(":checked")) {
checked_months.push($(this).val());
}
});
checked_months_str = "";
for (i = 0; i < checked_months.length; i++) {
checked_months_str += checked_months[i] + ",";
}
if (checked_months_str.length > 0) {
checked_months_str = checked_months_str.substring(0, checked_months_str.length -1);
}
//alert(checked_months_str)
let target = document.getElementsByName("target")[0].value;
let expr = document.getElementsByName("expr")[0].value;
let is_waived = document.getElementsByName("is_waived")[0].checked;
let na = document.getElementsByName("na")[0].checked;
let no_data = document.getElementsByName("no_data")[0].checked;
let displayname = document.getElementsByName("displayname")[0].value;
let level = document.getElementsByName("level")[0].value;
if (is_waived == true) {
is_waived = 1;
}
if (na == true) {
na = 1;
}
if (no_data == true) {
no_data = 1;
}
let url = "php/metric.php?save=true&target=" + target + "&expr=" + expr + "&waived=" + is_waived + "&na=" + na + "&no_data=" + no_data + "&month=" + checked_months_str + "&opunit=" + opsunit + "&dd=" + dd_id + "&displayname=" + displayname + "&level=" + level;
$.ajax({
type: 'POST',
url: url,
data: $(this).serialize(),
success: function(response) {
console.log(response);
}
});
}
</script>
</body>
</html>