-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathajax.php
executable file
·182 lines (133 loc) · 4.9 KB
/
ajax.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
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/core.php';
use Models\Hook;
switch (filter('op')) {
// Imposta un valore ad un array di $_SESSION
// esempio: push di un valore in $_SESSION['dashboard']['idtecnici']
// iversed: specifica se rimuovere dall'array il valore trovato e applicare quindi una deselezione (valori 0 o 1, default 1)
case 'session_set_array':
$array = explode(',', get('session'));
$value = "'".get('value')."'";
$inversed = get('inversed');
$found = false;
// Ricerca valore nell'array
foreach ($_SESSION[$array[0]][$array[1]] as $idx => $val) {
// Se il valore esiste lo tolgo
if ($val == $value) {
$found = true;
if ((int) $inversed == 1) {
unset($_SESSION[$array[0]][$array[1]][$idx]);
}
}
}
if (!$found) {
array_push($_SESSION[$array[0]][$array[1]], $value);
}
// print_r($_SESSION[$array[0]][$array[1]]);
break;
// Imposta un valore ad una sessione
case 'session_set':
$array = explode(',', get('session'));
$value = get('value', true);
$clear = get('clear');
if ($clear == 1 || $value == '') {
unset($_SESSION[$array[0]][$array[1]]);
} else {
$_SESSION[$array[0]][$array[1]] = $value;
}
break;
case 'list_attachments':
echo '{( "name": "filelist_and_upload", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "id_plugin": "'.$id_plugin.'" )}';
break;
case 'checklists':
include base_dir().'/plugins/checks.php';
break;
case 'active_users':
$posizione = get('id_module');
if (!empty($id_record)) {
$posizione .= ', '.get('id_record');
}
$user = Auth::user();
$interval = setting('Timeout notifica di presenza (minuti)') * 60;
$dbo->query('UPDATE zz_semaphores SET updated = NOW() WHERE id_utente = :user_id AND posizione = :position', [
':user_id' => $user['id'],
':position' => $posizione,
]);
// Rimozione record scaduti
$dbo->query('DELETE FROM zz_semaphores WHERE DATE_ADD(updated, INTERVAL :interval SECOND) <= NOW()', [
':interval' => $interval,
]);
$datas = $dbo->fetchArray('SELECT DISTINCT username FROM zz_semaphores INNER JOIN zz_users ON zz_semaphores.id_utente=zz_users.id WHERE zz_semaphores.id_utente != :user_id AND posizione = :position', [
':user_id' => $user['id'],
':position' => $posizione,
]);
echo json_encode($datas);
break;
case 'hooks':
$hooks = Hook::all();
$results = [];
foreach ($hooks as $hook) {
if ($hook->permission != '-') {
$results[] = [
'id' => $hook->id,
'name' => $hook->name,
];
}
}
echo json_encode($results);
break;
case 'hook-lock':
$hook_id = filter('id');
$hook = Hook::find($hook_id);
$token = $hook->lock();
echo json_encode($token);
break;
case 'hook-execute':
$hook_id = filter('id');
$token = filter('token');
$hook = Hook::find($hook_id);
$response = $hook->execute($token);
echo json_encode($response);
break;
case 'hook-response':
$hook_id = filter('id');
$hook = Hook::find($hook_id);
$response = $hook->response();
echo json_encode($response);
break;
case 'flash':
$response = flash()->getMessages();
echo json_encode($response);
break;
case 'summable-results':
$ids = post('ids') ?: [];
$results = Util\Query::getSums($structure, [
'id' => $ids,
]);
echo json_encode($results);
break;
case 'avg-results':
$ids = post('ids') ?: [];
$results = Util\Query::getAverages($structure, [
'id' => $ids,
]);
echo json_encode($results);
break;
}