forked from anas-araid/Gestione-RapportiVVF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.php
366 lines (348 loc) · 16.3 KB
/
stats.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<html>
<head>
<?php
include "core/_header.php";
session_start();
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// error_reporting per togliere il notice quando non trova isLogged
//error_reporting(0);
include "core/dbConnection.php";
include "core/getData.php";
include "core/getStats.php";
include "core/functions.php";
if ($error_message) {
echo "
<script>
flatAlert('Accesso', 'Impossibile connettersi al database', 'error', 'index.php');
</script>";
}
?>
</head>
<body>
<div class="mdl-layout mdl-js-layout">
<main class="mdl-layout__content">
<div class="page-content">
<div class="mdl-grid">
<section class="mdl-cell mdl-cell--middle mdl-cell--3-col mdl-cell--hide-phone mdl-cell--hide-tablet">
<div style="padding:5px">
<h1>
<mark style="background-color:white;border:none;border-radius:10px;padding:5px;">
<span class="style-gradient-text">Rapporti</span>
</mark>
</h1>
<h1>
<mark style="background-color:white;border:none;border-radius:10px;padding:5px;">
<span class="style-gradient-text">d'intervento</span>
</mark>
</h1>
<h3 class="style-gradient-text">
<mark style="background-color:white;border:none;border-radius:10px;padding:5px;">
<span class="style-gradient-text">vvf Pergine</span>
</mark>
<br>
<br>
<mark style="background-color:white;border:none;border-radius:10px;padding:5px;">
<span class="style-gradient-text">Valsugana</span>
</mark>
</h3>
</div>
<div class="mdl-cell mdl-cell--middle mdl-cell--12-col">
<button class="mdl-button mdl-js-button mdl-button--raised style-gradient style-button"
style="width:100%;height:35px;color:white;border:none;border-radius:20px;;text-align:center;margin-bottom:15px"
type="reset"
onclick="location.href='index.php?back=true'">
Indietro
<i class="material-icons">cancel</i>
</button>
</div>
</section>
<section class="mdl-cell mdl-cell--middle mdl-cell--9-col" >
<div class="mdl-card mdl-shadow--8dp style-card" style="width:100%">
<div id="stats-container" style="max-height:650px;overflow:auto;text-align:center;padding-bottom:30px">
<h3 style="text-align:center" class="style-gradient-text">Statistiche</h3>
<br>
<script>
function updateYears() {
var select = document.getElementById("anno").value;
if (select == 1){
window.location.href= '?year=""'
}else{
window.location.href= '?year=' + select;
}
}
</script>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label is-dirty is-upgraded" style="width:60%" data-upgraded=",MaterialTextfield">
<select id="anno" onchange="updateYears()" class="mdl-textfield__input" style="outline:none">
<option value="1">TUTTI</option>
<?php
$years = getReportYears($db_conn);
$annoSelezionato = "";
if (isset($_GET['year'])){
$annoSelezionato = $_GET['year'];
if (!in_array($annoSelezionato, $years)){
$annoSelezionato = "";
}
}
for ($i=0; $i < count($years); $i++){
$selected = "";
if ($annoSelezionato == $years[$i]){
$selected = "selected";
}
echo '<option value="'.$years[$i].'" '.$selected.'>'.$years[$i].'</option>';
}
?>
</select>
<label class="mdl-textfield__label" for="anno">Seleziona anno</label>
</div>
<button class="mdl-button mdl-js-button mdl-button--raised style-gradient style-button"
style="width:200px;height:35px;color:white;border:none;border-radius:20px;;text-align:center;margin-bottom:15px"
type="reset"
onclick="allInterventi.open()">
Riepilogo interventi
<i class="material-icons">cancel</i>
</button>
<?php
$interventi = getInterventi($annoSelezionato, $db_conn, true);
//print_r($interventi);
$chartData = array();
$chartLabel = array();
// creo due array contenenti uno il nome dell'intervento, e l'altro il numero
for ($i=0; $i<count($interventi);$i++){
$chartData[$i] = $interventi[$i][1];
$chartLabel[$i] = $interventi[$i][0];
}
// conversione da array php a qullo javscript
$chartLabel = json_encode($chartLabel);
$chartData = json_encode($chartData);
?>
<!-- ### GRAFICO INTERVENTI FREQUENTI ### -->
<div style="text-align:center">
<h5 class="style-gradient-text" style="text-align:left">Interventi più frequenti:</h5>
<canvas id="chartInterventiFrequenti" style="max-height:300px;max-width:300px;display:unset"></canvas>
</div>
<script>
// lista colori
chartColors = {
1: '#e74c3c',
2: '#e67e22',
3: '#2ecc71',
4: '#f1c40f',
5: '#3498db',
6: '#9b59b6',
7: '#34495e'
};
var colors = Array();
for (var i=0; i < <?php echo $chartData ?>.length;i++){
colors[i]= chartColors[i+1];
}
var ctx = document.getElementById("chartInterventiFrequenti").getContext('2d');
var data = {
labels: <?php echo $chartLabel ?>,
datasets: [{
data: <?php echo $chartData ?>,
backgroundColor: colors,
}],
}
var chartFrequenti = new Chart(ctx, {
type: 'doughnut',
data: data,
options: {
responsive: true
}
});
</script>
<!-- ### GRAFICO INTERVENTI ANNUALI ### -->
<?php
$anno = getInterventiAnnuali($annoSelezionato, $db_conn);
$chartMese = array();
$chartInterventi = array();
// creo due array contenenti uno il nome dell'intervento, e l'altro il numero
for ($i=0; $i<count($anno);$i++){
$chartMese[$i] = $anno[$i][0];
$chartInterventi[$i] = $anno[$i][1];
}
// conversione da array php a qullo javscript
$maxInterventiAlMese = max($chartInterventi);
$chartMese = json_encode($chartMese);
$chartInterventi = json_encode($chartInterventi);
?>
<h5 class="style-gradient-text" style="text-align:left">Numeri di interventi nell'anno:</h5>
<canvas id="chartInterventiAnnuali" style="max-height:auto;max-width:100%"></canvas>
<script>
var ctx = document.getElementById("chartInterventiAnnuali").getContext('2d');
var chartAnnuali = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: 'Interventi: ',
data: <?php echo $chartInterventi ?>,
backgroundColor: "rgba(231, 77, 60, 0.49)",
borderColor: "#e74c3c",
}],
labels: <?php echo $chartMese ?>
},
options: {
scales: {
yAxes: [{
ticks: {
suggestedMin: 0,
suggestedMax: <?php echo $maxInterventiAlMese + 1 ?>
}
}]
}
}
});
</script>
<!-- ### GRAFICO FASCIE ORARIE ### -->
<?php
$interventiOrari = getHours($annoSelezionato, $db_conn);
$chartOra = array();
$chartInterventiPerOra = array();
// creo due array contenenti uno l'ora dell'intervento, e l'altro il numero
for ($i=0; $i<count($interventiOrari);$i++){
$chartOra[$i] = "$i".".00";
$chartInterventiPerOra[$i] = $interventiOrari[$i];
}
// conversione da array php a qullo javscript
$maxInterventiPerOra = max($chartInterventiPerOra);
$chartOra = json_encode($chartOra);
$chartInterventiPerOra = json_encode($chartInterventiPerOra);
?>
<h5 class="style-gradient-text" style="text-align:left">Fascie orarie:</h5>
<canvas id="chartFascieOrarie" style="max-height:auto;max-width:100%"></canvas>
<script>
var ctx = document.getElementById("chartFascieOrarie").getContext('2d');
var chartFascieOrarieOrari = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: 'Interventi ogni ora: ',
data: <?php echo $chartInterventiPerOra ?>,
backgroundColor: "rgba(231, 77, 60, 0.49)",
borderColor: "#e74c3c",
}],
labels: <?php echo $chartOra ?>
},
options: {
scales: {
yAxes: [{
ticks: {
suggestedMin: 0,
suggestedMax: <?php echo $maxInterventiPerOra +1 ?>
}
}]
}
}
});
</script>
<!-- ### GRAFICO MEZZI FREQUENTI ### -->
<?php
$mezziIntervenuti = getMezziIntervenuti($annoSelezionato, $db_conn, true);
$chartData = array();
$chartLabel = array();
// creo due array contenenti uno il nome dell'intervento, e l'altro il numero
for ($i=0; $i<count($mezziIntervenuti);$i++){
$chartData[$i] = $mezziIntervenuti[$i][1];
$chartLabel[$i] = $mezziIntervenuti[$i][0];
}
// conversione da array php a qullo javscript
$chartLabel = json_encode($chartLabel);
$chartData = json_encode($chartData);
?>
<div style="text-align:center">
<h5 class="style-gradient-text" style="text-align:left">Mezzi più utilizzati:</h5>
<canvas id="chartMezziUsati" style="max-height:300px;max-width:300px;display:unset"></canvas>
</div>
<script>
// lista colori
chartColors = {
1: '#e74c3c',
2: '#e67e22',
3: '#2ecc71',
4: '#f1c40f',
5: '#3498db',
6: '#9b59b6',
7: '#34495e'
};
var colors = Array();
for (var i=0; i < <?php echo $chartData ?>.length;i++){
colors[i]= chartColors[i+1];
}
var ctx = document.getElementById("chartMezziUsati").getContext('2d');
var data = {
labels: <?php echo $chartLabel ?>,
datasets: [{
data: <?php echo $chartData ?>,
backgroundColor: colors,
}],
}
var chartFrequenti = new Chart(ctx, {
type: 'doughnut',
data: data,
options: {
responsive: true
}
});
</script>
</div>
<br>
<br>
<br>
<div class="mdl-cell mdl-cell--middle mdl-cell--12-col mdl-cell--hide-desktop" style="100%">
<button class="mdl-button mdl-js-button mdl-button--raised style-gradient style-button"
style="width:100%;height:35px;color:white;border:none;border-radius:20px;;text-align:center;margin-bottom:15px"
type="reset"
onclick="location.href='index.php?back=true'">
Indietro
<i class="material-icons">cancel</i>
</button>
</div>
</div>
</section>
</div>
<?php include "core/_footer.php" ?>
</div>
<?php
$tuttiInterventi = "'";
for ($i=0; $i < sizeOf($interventi); $i++){
if($interventi[$i][1]==1){
$inter = "intervento";
}else{
$inter = "interventi";
}
$tipoIntervento = $interventi[$i][0];
$totInterventi = $interventi[$i][1];
$tuttiInterventi .= "<b>$tipoIntervento: </b> $totInterventi $inter <br>";
}
$tuttiInterventi .= "'";
?>
<script>
var allInterventi = new tingle.modal({
closeMethods: ['overlay', 'button', 'escape'],
closeLabel: "Chiudi",
cssClass: ['custom-class-1', 'custom-class-2'],
onOpen: function() {
console.log('modal open');
},
onClose: function() {
console.log('modal closed');
},
beforeClose: function() {
return true; // close the modal
return false; // nothing happens
}
});
allInterventi.setContent(
'<h2 class="style-gradient-text">Tutti gli interventi<h2>'+
'<div>'+
'<ul class="mdl-list">'+
<?php echo $tuttiInterventi ?> +
'</ul>'+
'</div>'
);
jQuery('stats-container').css('max-height', jQuery(document).height() - '100px');
</script>
</main>
</div>
</body>
</html>