FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openstamanager/src/Settings.php at master · devcode-it/openstamanager · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
devcode-it
/
openstamanager
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
86
Star
148
Code
Issues
180
Pull requests
30
Actions
Projects
Security and quality
18
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openstamanager
/
src
/
Settings.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
342 lines (291 loc) · 12.4 KB
Breadcrumbs
openstamanager
/
src
/
Settings.php
Copy path
File metadata and controls
executable file
·
342 lines (291 loc) · 12.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?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/>.
*/
use
Models
\
Setting
;
use
Respect
\
Validation
\
Validator
as
v
;
/**
* Classe per la gestione dell impostazioni del progetto.
*
* @since 2.3
*/
class
Settings
{
/** @var array Elenco delle impostazioni disponibili */
protected
static
$
settings
= [];
protected
static
$
references
= [];
protected
static
$
sections
= [];
/**
* Restituisce tutte le informazioni di tutti le impostazioni presenti.
*
* @return array
*/
public
static
function
getSettings
()
{
if
(
empty
(
self
::
$
settings
)) {
$
settings
= [];
$
references
= [];
$
sections
= [];
try
{
$
results
= Setting::
all
();
}
catch
(
\
Exception
$
e
) {
$
results
= [];
}
foreach
(
$
results
as
$
result
) {
$
settings
[
$
result
->
id
] =
$
result
;
$
references
[
$
result
->
nome
] =
$
result
->
id
;
if
(!
isset
(
$
sections
[
$
result
[
'
sezione
'
]])) {
$
sections
[
$
result
[
'
sezione
'
]] = [];
}
$
sections
[
$
result
[
'
sezione
'
]][] =
$
result
->
id
;
}
self
::
$
settings
=
$
settings
;
self
::
$
references
=
$
references
;
self
::
$
sections
=
$
sections
;
}
return
self
::
$
settings
;
}
/**
* Restituisce le informazioni relative ad una singola impostazione specificata.
*
* @param string|int $setting
*
* @return array
*/
public
static
function
get
(
$
setting
)
{
$
settings
=
self
::
getSettings
();
if
(!
is_numeric
(
$
setting
) && !
empty
(
self
::
$
references
[
$
setting
])) {
$
setting
=
self
::
$
references
[
$
setting
];
}
return
$
settings
[
$
setting
];
}
/**
* Restituisce il valore corrente dell'impostazione ricercata.
*
* @param string|int $setting
*
* @return string
*/
public
static
function
getValue
(
$
setting
)
{
return
self
::
get
(
$
setting
)->
valore
;
}
/**
* Imposta il valore dell'impostazione indicata.
*
* @param string|int $setting
*
* @return bool
*/
public
static
function
setValue
(
$
setting
,
$
value
)
{
$
setting
= Setting::
where
(
'
id
'
,
'
=
'
,
$
setting
)->
orWhere
(
'
nome
'
,
'
=
'
,
$
setting
)->
first
();
$
value
= (
is_array
(
$
value
) ?
implode
(
'
,
'
,
$
value
) :
$
value
);
// Trasformazioni
// Boolean (checkbox)
if
(
$
setting
->
tipo
==
'
boolean
'
) {
$
value
= (
empty
(
$
value
) ||
$
value
==
'
off
'
) ?
false
:
true
;
}
// Validazioni
// integer
if
(
$
setting
->
tipo
==
'
integer
'
) {
$
validator
= v::
intVal
();
}
// list
// verifico che il valore scelto sia nella lista enumerata nel db
elseif
(
preg_match
(
"
/list\[(.+?)\]/
"
, (
string
)
$
setting
->
tipo
,
$
m
)) {
$
validator
= v::
in
(
explode
(
'
,
'
,
$
m
[
1
]));
}
// multiple
// verifico che il valore scelto sia nella lista enumerata nel db
elseif
(
preg_match
(
"
/multiple\[(.+?)\]/
"
, (
string
)
$
setting
->
tipo
,
$
m
[
0
][
0
])) {
// $validator = v::in(explode(',', $m[0][0][1]));
}
// Boolean (checkbox)
elseif
(
$
setting
->
tipo
==
'
boolean
'
) {
$
validator
= v::
boolType
();
}
if
(
empty
(
$
validator
) ||
$
validator
->
isValid
(
$
value
)) {
$
setting
->
valore
=
$
value
;
$
setting
->
save
();
return
true
;
}
return
false
;
}
/**
* Genera l'input HTML per la modifica dell'impostazione.
*
* @param string|int $setting
* @param bool $required
*
* @return string
*/
public
static
function
input
(
$
setting
,
$
required
=
false
,
$
value_user
=
null
)
{
$
setting
= Setting::
where
(
'
nome
'
,
'
=
'
,
$
setting
)->
orWhere
(
'
id
'
,
'
=
'
,
$
setting
)->
first
();
if
(
$
value_user
!==
null
) {
$
input_value
=
is_array
(
$
value_user
) ?
implode
(
'
,
'
,
$
value_user
) :
$
value_user
;
}
else
{
$
input_value
=
$
setting
->
valore
;
}
// Definizione icona per evidenziare le impostazioni personalizzate e personalizzabili
$
user
=
auth_osm
()->
getUser
();
$
user_options
= [];
$
user_setting_icon
=
''
;
$
tooltip
=
$
setting
->
getTranslation
(
'
help
'
);
if
(
$
user
) {
$
user_options
=
json_decode
((
string
)
$
user
->
options
?:
''
,
true
);
}
if
(
$
user_options
[
'
settings
'
][
$
setting
->
id
] !==
null
) {
$
user_setting_icon
=
'
<i class="fa fa-user text-primary"></i>
'
;
$
tooltip
.= (
$
tooltip
?
'
<br>
'
:
''
).
'
<em>
'
.
tr
(
'
Personalizzata dall
\'
utente
'
).
'
</em>
'
;
}
elseif
(
$
setting
->
is_user_setting
) {
$
user_setting_icon
=
'
<i class="fa fa-user text-secondary"></i>
'
;
$
tooltip
.= (
$
tooltip
?
'
<br>
'
:
''
).
'
<em>
'
.
tr
(
'
Personalizzabile dall
\'
utente
'
).
'
</em>
'
;
}
// Lista predefinita
if
(
preg_match
(
"
/list\[(.+?)\]/
"
, (
string
)
$
setting
->
tipo
,
$
m
)) {
$
values
=
explode
(
'
,
'
,
$
m
[
1
]);
$
list
= [];
foreach
(
$
values
as
$
value
) {
$
list
[] = [
'
id
'
=>
$
value
,
'
text
'
=>
$
value
,
];
}
$
result
=
'
{[ "type": "select", "multiple": 0, "label":
'
.
json_encode
(
$
user_setting_icon
.
'
'
.
$
setting
->
getTranslation
(
'
title
'
)).
'
, "readonly": "
'
.!
$
setting
->
editable
.
'
", "name": "setting[
'
.
$
setting
->
id
.
'
]", "values":
'
.
json_encode
(
$
list
).
'
, "value": "
'
.
$
input_value
.
'
", "required": "
'
.
intval
(
$
required
).
'
", "help": "
'
.
$
tooltip
.
'
" ]}
'
;
}
// Lista multipla
elseif
(
preg_match
(
"
/multiple\[(.+?)\]/
"
, (
string
)
$
setting
->
tipo
,
$
m
)) {
$
list
= [];
// Gestisco il multiple da query trasformando i risultati in formato List
if
(
strstr
((
string
)
$
setting
->
tipo
,
'
query=
'
)) {
$
database
=
database
();
$
value
=
str_replace
(
'
]
'
,
''
,
explode
(
'
[
'
, (
string
)
$
setting
->
tipo
)[
1
]);
$
query
=
str_replace
(
'
query=
'
,
''
,
$
value
);
// $query = str_replace('"', '\"', $query);
$
rs
=
$
database
->
fetchArray
(
$
query
);
foreach
(
$
rs
as
$
r
) {
$
list
[] = [
'
id
'
=>
$
r
[
'
id
'
],
'
text
'
=>
$
r
[
'
descrizione
'
],
];
}
}
else
{
$
values
=
explode
(
'
,
'
,
$
m
[
1
]);
foreach
(
$
values
as
$
value
) {
$
list
[] = [
'
id
'
=>
$
value
,
'
text
'
=>
$
value
,
];
}
}
$
result
=
'
{[ "type": "select", "multiple": 1, "label":
'
.
json_encode
(
$
user_setting_icon
.
'
'
.
$
setting
->
getTranslation
(
'
title
'
)).
'
, "readonly": "
'
.!
$
setting
->
editable
.
'
", "name": "setting[
'
.
$
setting
->
id
.
'
][]", "values":
'
.
json_encode
(
$
list
).
'
, "value": "
'
.
$
input_value
.
'
", "required": "
'
.
intval
(
$
required
).
'
", "help": "
'
.
$
tooltip
.
'
" ]}
'
;
}
// Lista da query
elseif
(
preg_match
(
'
/^query=(.+?)$/
'
, (
string
)
$
setting
->
tipo
,
$
m
)) {
$
result
=
'
{[ "type": "select", "label":
'
.
json_encode
(
$
user_setting_icon
.
'
'
.
$
setting
->
getTranslation
(
'
title
'
)).
'
, "readonly": "
'
.!
$
setting
->
editable
.
'
", "name": "setting[
'
.
$
setting
->
id
.
'
]", "values": "
'
.
str_replace
(
'
"
'
,
'
\"
'
,
$
setting
->
tipo
).
'
", "value": "
'
.
$
input_value
.
'
", "required": "
'
.
intval
(
$
required
).
'
", "help": "
'
.
$
tooltip
.
'
" ]}
'
;
}
// Boolean (checkbox)
elseif
(
$
setting
->
tipo
==
'
boolean
'
) {
$
result
=
'
{[ "type": "checkbox", "label":
'
.
json_encode
(
$
user_setting_icon
.
'
'
.
$
setting
->
getTranslation
(
'
title
'
)).
'
, "readonly": "
'
.!
$
setting
->
editable
.
'
", "name": "setting[
'
.
$
setting
->
id
.
'
]", "placeholder": "
'
.
tr
(
'
Attivo
'
).
'
", "value": "
'
.
$
input_value
.
'
", "required": "
'
.
intval
(
$
required
).
'
", "help": "
'
.
$
tooltip
.
'
" ]}
'
;
}
// Editor
elseif
(
$
setting
->
tipo
==
'
ckeditor
'
) {
$
result
=
input
([
'
type
'
=>
'
ckeditor
'
,
'
label
'
=>
$
user_setting_icon
.
'
'
.
$
setting
->
getTranslation
(
'
title
'
),
'
readonly
'
=> !
$
setting
->
editable
,
'
name
'
=>
'
setting[
'
.
$
setting
->
id
.
'
]
'
,
'
value
'
=>
$
input_value
,
'
required
'
=>
intval
(
$
required
),
'
help
'
=>
$
tooltip
,
]);
}
// Media (caricamento file)
elseif
(
$
setting
->
tipo
==
'
media
'
) {
$
result
=
self
::
mediaInput
(
$
setting
,
$
input_value
,
$
required
,
$
user_setting_icon
,
$
tooltip
);
}
// Campi di default
elseif
(
in_array
(
$
setting
->
tipo
, [
'
textarea
'
,
'
timestamp
'
,
'
date
'
,
'
time
'
])) {
$
result
=
'
{[ "type": "
'
.
$
setting
->
tipo
.
'
", "label":
'
.
json_encode
(
$
user_setting_icon
.
'
'
.
$
setting
->
getTranslation
(
'
title
'
)).
'
, "readonly": "
'
.!
$
setting
->
editable
.
'
", "name": "setting[
'
.
$
setting
->
id
.
'
]", "value":
'
.
json_encode
(
$
input_value
).
'
, "required": "
'
.
intval
(
$
required
).
'
", "help": "
'
.
$
tooltip
.
'
" ]}
'
;
}
// Campo di testo
else
{
$
numerico
=
in_array
(
$
setting
->
tipo
, [
'
integer
'
,
'
decimal
'
]);
$
tipo
=
preg_match
(
'
/password/i
'
, (
string
)
$
setting
->
getTranslation
(
'
title
'
),
$
m
) ?
'
password
'
:
$
setting
->
tipo
;
$
tipo
=
$
numerico
?
'
number
'
:
'
text
'
;
$
result
=
'
{[ "type": "
'
.
$
tipo
.
'
", "label":
'
.
json_encode
(
$
user_setting_icon
.
'
'
.
$
setting
->
getTranslation
(
'
title
'
)).
'
, "readonly": "
'
.!
$
setting
->
editable
.
'
", "name": "setting[
'
.
$
setting
->
id
.
'
]", "value": "
'
.
$
input_value
.
'
"
'
.(
$
numerico
&&
$
setting
->
tipo
==
'
integer
'
?
'
, "decimals": 0
'
:
''
).
'
, "required": "
'
.
intval
(
$
required
).
'
", "help": "
'
.
$
tooltip
.
'
" ]}
'
;
}
return
$
result
;
}
/**
* Genera l'input HTML per il caricamento di un file (impostazioni di tipo "media").
*
* @param Setting $setting
* @param string $input_value
* @param bool $required
* @param string $user_setting_icon
* @param string $tooltip
*
* @return string
*/
protected
static
function
mediaInput
(
$
setting
,
$
input_value
,
$
required
,
$
user_setting_icon
,
$
tooltip
)
{
$
upload
=
null
;
$
accepted
=
'
.jpg,.jpeg,.png,.gif,.bmp,.svg
'
;
if
(!
empty
(
$
input_value
)) {
$
upload
= \
Models
\Upload::
find
(
$
input_value
);
}
// Anteprima del file caricato
$
preview
=
''
;
if
(!
empty
(
$
upload
)) {
$
preview_url
=
base_path_osm
().
'
/view.php?file_id=
'
.
$
upload
->
id
.
'
&preview=1
'
;
$
preview
=
'
<div class="setting-media-preview mb-2" id="media_preview_
'
.
$
setting
->
id
.
'
">
<img src="
'
.
$
preview_url
.
'
" class="img-thumbnail" style="max-height: 80px;">
<div class="mt-1">
<a href="
'
.
$
file_url
.
'
" target="_blank"><i class="fa fa-external-link"></i>
'
.
$
upload
->
name
.
'
</a>
<button type="button" class="btn btn-xs btn-danger ml-2" onclick="rimuoviMediaImpostazione(
'
.
$
setting
->
id
.
'
)">
<i class="fa fa-trash"></i>
</button>
</div>
</div>
'
;
}
$
result
=
'
<div class="form-group">
<label>
'
.
$
user_setting_icon
.
'
'
.
$
setting
->
getTranslation
(
'
title
'
).
'
</label>
'
;
if
(!
empty
(
$
tooltip
)) {
$
result
.=
'
<span class="tip" title="
'
.
prepareToField
(
$
tooltip
).
'
">
<i class="fa fa-question-circle-o text-muted ml-1"></i>
</span>
'
;
}
$
result
.=
$
preview
.
'
<input type="file" name="media_
'
.
$
setting
->
id
.
'
" id="media_
'
.
$
setting
->
id
.
'
" accept="
'
.
$
accepted
.
'
" class="form-control"
'
.(!
empty
(
$
setting
->
editable
) ?
''
:
'
disabled
'
).
'
>
<input type="hidden" name="setting[
'
.
$
setting
->
id
.
'
]" id="setting
'
.
$
setting
->
id
.
'
" value="
'
.
$
input_value
.
'
">
</div>
'
;
return
$
result
;
}
}
Back
|
FazBrowse Home
|
New Git URL