Skip to content

Commit 0d9a3f1

Browse files
committed
refactor: miglioria grafica modulo Utenti e permessi
1 parent 49e4279 commit 0d9a3f1

4 files changed

Lines changed: 260 additions & 135 deletions

File tree

modules/utenti/add.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,30 @@
2323
<input type="hidden" name="op" value="add">
2424
<input type="hidden" name="backto" value="record-list">
2525

26-
<div class="row">
27-
<div class="col-md-6">
28-
{[ "type": "text", "label": "<?php echo tr('Nome gruppo'); ?>", "name": "nome", "required": 1, "validation": "gruppo", "help": "<?php echo tr('Compilando questo campo verrà creato un nuovo gruppo di utenti.'); ?>" ]}
29-
</div>
30-
<div class="col-md-3">
31-
{[ "type": "select", "label": "<?php echo tr('Tema'); ?>", "name": "theme", "values": "list=\"\": \"<?php echo tr('Predefinito'); ?>\",\"black-light\": \"<?php echo tr('Bianco'); ?>\",\"black\": \"<?php echo tr('Nero'); ?>\",\"red-light\": \"<?php echo tr('Rosso chiaro'); ?>\",\"red\": \"<?php echo tr('Rosso'); ?>\",\"blue-light\": \"<?php echo tr('Blu chiaro'); ?>\",\"blue\": \"<?php echo tr('Blu'); ?>\",\"green-light\": \"<?php echo tr('Verde chiaro'); ?>\",\"green\": \"<?php echo tr('Verde'); ?>\",\"yellow-light\": \"<?php echo tr('Giallo chiaro'); ?>\",\"yellow\": \"<?php echo tr('Giallo'); ?>\",\"purple-light\": \"<?php echo tr('Viola chiaro'); ?>\",\"purple\": \"<?php echo tr('Viola'); ?>\"", "value": "$theme$" ]}
32-
</div>
33-
<div class="col-md-3">
34-
{["type":"select", "label":"<?php echo tr('Modulo iniziale'); ?>", "name":"id_module_start", "ajax-source":"moduli_gruppo", "placeholder":"<?php tr('Modulo iniziale'); ?>" ]}
26+
<div class="card card-primary card-outline">
27+
<div class="card-body">
28+
<div class="row">
29+
<div class="col-md-6">
30+
{[ "type": "text", "label": "<?php echo tr('Nome gruppo'); ?>", "name": "nome", "required": 1, "validation": "gruppo", "help": "<?php echo tr('Compilando questo campo verrà creato un nuovo gruppo di utenti.'); ?>" ]}
31+
</div>
32+
<div class="col-md-6">
33+
{[ "type": "select", "label": "<?php echo tr('Modulo iniziale'); ?>", "name":"id_module_start", "ajax-source":"moduli_gruppo", "placeholder":"<?php tr('Modulo iniziale'); ?>" ]}
34+
</div>
35+
</div>
36+
37+
<div class="row">
38+
<div class="col-md-6">
39+
{[ "type": "select", "label": "<?php echo tr('Tema'); ?>", "name": "theme", "values": "list=\"\": \"<?php echo tr('Predefinito'); ?>\",\"black-light\": \"<?php echo tr('Bianco'); ?>\",\"black\": \"<?php echo tr('Nero'); ?>\",\"red-light\": \"<?php echo tr('Rosso chiaro'); ?>\",\"red\": \"<?php echo tr('Rosso'); ?>\",\"blue-light\": \"<?php echo tr('Blu chiaro'); ?>\",\"blue\": \"<?php echo tr('Blu'); ?>\",\"green-light\": \"<?php echo tr('Verde chiaro'); ?>\",\"green\": \"<?php echo tr('Verde'); ?>\",\"yellow-light\": \"<?php echo tr('Giallo chiaro'); ?>\",\"yellow\": \"<?php echo tr('Giallo'); ?>\",\"purple-light\": \"<?php echo tr('Viola chiaro'); ?>\",\"purple\": \"<?php echo tr('Viola'); ?>\"", "value": "$theme$" ]}
40+
</div>
41+
<div class="col-md-6">
42+
<!-- Spazio per eventuali campi futuri -->
43+
</div>
44+
</div>
3545
</div>
3646
</div>
3747

3848
<!-- PULSANTI -->
39-
<div class="modal-footer">
49+
<div class="row">
4050
<div class="col-md-12 text-right">
4151
<button type="button" onclick="submitCheck()" class="btn btn-primary"><i class="fa fa-plus"></i> <?php echo tr('Aggiungi'); ?></button>
4252
</div>
@@ -54,7 +64,7 @@ function submitCheck() {
5464
}else{
5565
$("input[name=nome]").focus();
5666
swal("<?php echo tr('Impossibile procedere'); ?>", "<?php echo tr('Nome gruppo già utilizzato'); ?>.", "error");
57-
67+
5868
}
5969
}
6070
</script>

modules/utenti/edit.php

Lines changed: 123 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -20,91 +20,118 @@
2020

2121
include_once __DIR__.'/../../core.php';
2222

23+
use Models\Group;
24+
use Models\Module;
25+
use Models\User;
26+
27+
$group = Group::find($id_record);
28+
$record = $group->toArray();
29+
30+
// Lettura gruppi
31+
$gruppi = $dbo->fetchArray('SELECT `id`, `nome` FROM `zz_groups`');
32+
33+
// Lettura utenti
2334
$utenti = $dbo->fetchArray('
24-
SELECT
25-
`zz_users`.*,
26-
`an_anagrafiche`.`ragione_sociale`,
27-
GROUP_CONCAT(`an_tipianagrafiche_lang`.`title` SEPARATOR ", ") AS tipo
28-
FROM
29-
`zz_users`
30-
LEFT JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica` = `zz_users`.`idanagrafica`
31-
LEFT JOIN `an_tipianagrafiche_anagrafiche` ON `an_tipianagrafiche_anagrafiche`.`idanagrafica` = `zz_users`.`idanagrafica`
32-
LEFT JOIN `an_tipianagrafiche` ON `an_tipianagrafiche`.`id` = `an_tipianagrafiche_anagrafiche`.`idtipoanagrafica`
35+
SELECT
36+
`zz_users`.*,
37+
`an_anagrafiche`.`ragione_sociale`,
38+
GROUP_CONCAT(`an_tipianagrafiche_lang`.`title` SEPARATOR ", ") AS tipo
39+
FROM
40+
`zz_users`
41+
LEFT JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica` = `zz_users`.`idanagrafica`
42+
LEFT JOIN `an_tipianagrafiche_anagrafiche` ON `an_tipianagrafiche_anagrafiche`.`idanagrafica` = `zz_users`.`idanagrafica`
43+
LEFT JOIN `an_tipianagrafiche` ON `an_tipianagrafiche`.`id` = `an_tipianagrafiche_anagrafiche`.`idtipoanagrafica`
3344
LEFT JOIN `an_tipianagrafiche_lang` ON (`an_tipianagrafiche_lang`.`id_record` = `an_tipianagrafiche`.`id` AND `an_tipianagrafiche_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
34-
WHERE
35-
`zz_users`.`idgruppo` = '.prepare($record['id']).'
36-
GROUP BY
45+
WHERE
46+
`zz_users`.`idgruppo` = '.prepare($record['id']).'
47+
GROUP BY
3748
`zz_users`.`id`');
3849

3950
echo '
40-
<div class="card card-primary">
51+
<div class="card card-primary card-outline">
4152
<div class="card-header">
42-
<h3 class="card-title">'.tr('Utenti del gruppo: _GROUP_', [
43-
'_GROUP_' => $group->getTranslation('title'),
53+
<h3 class="card-title">
54+
<i class="fa fa-users mr-2"></i>'.tr('Utenti del gruppo: _GROUP_', [
55+
'_GROUP_' => '<span class="text-primary">'.$group->getTranslation('title').'</span>',
4456
]).'</h3>
57+
<div class="card-tools">
58+
<a data-card-widget="modal" data-href="'.$structure->fileurl('user.php').'?id_module='.$id_module.'&id_record='.$id_record.'" data-msg="" data-backto="record-edit" data-title="'.tr('Aggiungi utente').'" class="btn btn-sm btn-primary">
59+
<i class="fa fa-plus"></i> '.tr('Aggiungi utente').'
60+
</a>
61+
</div>
4562
</div>
4663
4764
<div class="card-body">
48-
<div class="row">
49-
<div class="col-md-3 pull-right">
50-
{["type":"select", "label":"'.tr('Modulo iniziale').'", "name":"id_module_start", "ajax-source":"moduli_gruppo", "select-options": '.json_encode(['idgruppo' => $group->id]).', "placeholder":"'.tr('Modulo iniziale').'", "value":"'.($group->id_module_start ?: 0).'" ]}
65+
<div class="row mb-4">
66+
<div class="col-md-4">
67+
<div class="form-group">
68+
<label><i class="fa fa-home mr-1"></i> '.tr('Modulo iniziale').'</label>
69+
{["type":"select", "name":"id_module_start", "ajax-source":"moduli_gruppo", "select-options": '.json_encode(['idgruppo' => $group->id]).', "placeholder":"'.tr('Modulo iniziale').'", "value":"'.($group->id_module_start ?: 0).'" ]}
70+
</div>
5171
</div>
52-
<div class="col-md-3 pull-right">
53-
{["type":"select", "label":"'.tr('Tema').'", "name":"theme", "values":"list=\"\": \"'.tr('Predefinito').'\",\"black-light\": \"'.tr('Bianco').'\",\"black\": \"'.tr('Nero').'\",\"red-light\": \"'.tr('Rosso chiaro').'\",\"red\": \"'.tr('Rosso').'\",\"blue-light\": \"'.tr('Blu chiaro').'\",\"blue\": \"'.tr('Blu').'\",\"info-light\": \"'.tr('Azzurro chiaro').'\",\"info\": \"'.tr('Azzurro').'\",\"green-light\": \"'.tr('Verde chiaro').'\",\"green\": \"'.tr('Verde').'\",\"yellow-light\": \"'.tr('Giallo chiaro').'\",\"yellow\": \"'.tr('Giallo').'\",\"purple-light\": \"'.tr('Viola chiaro').'\",\"purple\": \"'.tr('Viola').'\" ", "value":"'.$group->theme.'" ]}
72+
<div class="col-md-4">
73+
<div class="form-group">
74+
<label><i class="fa fa-palette mr-1"></i> '.tr('Tema').'</label>
75+
{["type":"select", "name":"theme", "values":"list=\"\": \"'.tr('Predefinito').'\",\"black-light\": \"'.tr('Bianco').'\",\"black\": \"'.tr('Nero').'\",\"red-light\": \"'.tr('Rosso chiaro').'\",\"red\": \"'.tr('Rosso').'\",\"blue-light\": \"'.tr('Blu chiaro').'\",\"blue\": \"'.tr('Blu').'\",\"info-light\": \"'.tr('Azzurro chiaro').'\",\"info\": \"'.tr('Azzurro').'\",\"green-light\": \"'.tr('Verde chiaro').'\",\"green\": \"'.tr('Verde').'\",\"yellow-light\": \"'.tr('Giallo chiaro').'\",\"yellow\": \"'.tr('Giallo').'\",\"purple-light\": \"'.tr('Viola chiaro').'\",\"purple\": \"'.tr('Viola').'\" ", "value":"'.$group->theme.'" ]}
76+
</div>
5477
</div>
55-
</div>
56-
<br>';
78+
</div>';
5779

5880
if (!empty($utenti)) {
5981
echo '
6082
<div class="table-responsive">
61-
<table class="table table-hover table-sm table-striped">
62-
<tr>
63-
<th>'.tr('Nome utente').'</th>
64-
<th>'.tr('Email').'</th>
65-
<th>'.tr('Ragione sociale').'</th>
66-
<th>'.tr('Tipo di anagrafica').'</th>
67-
<th>'.tr('Sedi').'</th>
68-
<th width="120">'.tr('Opzioni').'</th>
69-
</tr>';
83+
<table class="table table-hover table-sm table-striped">
84+
<thead>
85+
<tr>
86+
<th><i class="fa fa-user mr-1"></i>'.tr('Nome utente').'</th>
87+
<th><i class="fa fa-envelope mr-1"></i>'.tr('Email').'</th>
88+
<th><i class="fa fa-building mr-1"></i>'.tr('Ragione sociale').'</th>
89+
<th><i class="fa fa-tag mr-1"></i>'.tr('Tipo di anagrafica').'</th>
90+
<th><i class="fa fa-map-marker-alt mr-1"></i>'.tr('Sedi').'</th>
91+
<th width="140" class="text-center"><i class="fa fa-cog mr-1"></i>'.tr('Opzioni').'</th>
92+
</tr>
93+
</thead>
94+
<tbody>';
7095

7196
foreach ($utenti as $utente) {
97+
$status_class = empty($utente['enabled']) ? 'text-muted' : '';
7298
echo '
73-
<tr>
74-
<td '.(empty($utente['enabled']) ? ' style="text-decoration:line-through;"' : '').'>
75-
<i class="fa fa-user"></i> '.$utente['username'].'
76-
</td>';
99+
<tr>
100+
<td class="'.$status_class.'">
101+
<i class="fa fa-user '.($status_class ? '' : 'text-primary').'"></i> '.$utente['username'].'
102+
'.(!empty($status_class) ? '<span class="badge badge-danger">'.tr('Disabilitato').'</span>' : '').'
103+
</td>';
77104

78105
if (!empty($utente['email'])) {
79106
echo '
80107
<td>'.$utente['email'].'</td>';
81108
} else {
82109
echo '
83-
<td>-</td>';
110+
<td><span class="text-muted">-</span></td>';
84111
}
85112

86113
if (!empty($utente['idanagrafica'])) {
87114
echo '
88-
<td>'.Modules::link('Anagrafiche', $utente['idanagrafica'], $utente['ragione_sociale']).'</td>
89-
<td>'.$utente['tipo'].'</td>';
115+
<td>'.Modules::link('Anagrafiche', $utente['idanagrafica'], $utente['ragione_sociale']).'</td>
116+
<td>'.$utente['tipo'].'</td>';
90117
} else {
91118
echo '
92-
<td>-</td>
93-
<td>-</td>';
119+
<td><span class="text-muted">-</span></td>
120+
<td><span class="text-muted">-</span></td>';
94121
}
95122

96123
$sedi = $dbo->fetchOne('SELECT GROUP_CONCAT(nomesede SEPARATOR ", " ) as nomesede FROM zz_user_sedi INNER JOIN ((SELECT "0" AS id, "Sede legale" AS nomesede) UNION (SELECT id, nomesede FROM an_sedi)) sedi ON zz_user_sedi.idsede=sedi.id WHERE id_user='.prepare($utente['id']).' GROUP BY id_user')['nomesede'];
97124

98125
echo '
99-
<td>'.$sedi.'</td>';
126+
<td>'.(!empty($sedi) ? $sedi : '<span class="text-muted">-</span>').'</td>';
100127

101128
echo '
102-
<td>';
129+
<td class="text-center">';
103130

104131
// Disabilitazione utente, se diverso da id_utente #1 (admin)
105132
if ($utente['id'] == '1') {
106133
echo '
107-
<div data-card-widget="tooltip" class="tip" title="'.tr("Non è possibile disabilitare l'utente admin").'" ><span class="btn btn-xs btn-danger disabled">
134+
<div data-card-widget="tooltip" class="tip d-inline-block" title="'.tr("Non è possibile disabilitare l'utente admin").'" ><span class="btn btn-xs btn-danger disabled">
108135
<i class="fa fa-eye-slash"></i>
109136
</span></div>';
110137
} elseif ($utente['enabled'] == 1) {
@@ -128,7 +155,7 @@
128155

129156
if ($utente['id'] == '1') {
130157
echo '
131-
<div data-card-widget="tooltip" class="tip" title="'.tr("Non è possibile gestire l'accesso API per l'utente admin").'" ><span class="btn btn-xs btn-danger disabled">
158+
<div data-card-widget="tooltip" class="tip d-inline-block" title="'.tr("Non è possibile gestire l'accesso API per l'utente admin").'" ><span class="btn btn-xs btn-danger disabled">
132159
<i class="fa fa-key "></i>
133160
</span></div>';
134161
} elseif (!empty($token)) {
@@ -146,7 +173,7 @@
146173
// Eliminazione utente, se diverso da id_utente #1 (admin)
147174
if ($utente['id'] == '1') {
148175
echo '
149-
<div data-card-widget="tooltip" class="tip" title="'.tr("Non è possibile eliminare l'utente admin").'" ><span class="btn btn-xs btn-danger disabled">
176+
<div data-card-widget="tooltip" class="tip d-inline-block" title="'.tr("Non è possibile eliminare l'utente admin").'" ><span class="btn btn-xs btn-danger disabled">
150177
<i class="fa fa-trash"></i>
151178
</span></div>';
152179
} else {
@@ -157,11 +184,12 @@
157184
}
158185

159186
echo '
160-
</td>
161-
</tr>';
187+
</td>
188+
</tr>';
162189
}
163190

164191
echo '
192+
</tbody>
165193
</table>
166194
</div>';
167195
} else {
@@ -172,36 +200,38 @@
172200
}
173201

174202
echo '
175-
<a data-card-widget="modal" data-href="'.$structure->fileurl('user.php').'?id_module='.$id_module.'&id_record='.$id_record.'" data-msg="" data-backto="record-edit" data-title="'.tr('Aggiungi utente').'" class="pull-right btn btn-primary">
176-
<i class="fa fa-plus"></i> '.tr('Aggiungi utente').'
177-
</a>
178203
</div>
179204
</div>';
180205

181206
// Aggiunta nuovo utente
182207
echo '
183-
<hr>';
208+
<hr>
184209
185-
echo '
186-
<div class="card card-primary">
187-
<div class="card-header">
188-
<h3 class="card-title">'.tr('Permessi del gruppo: _GROUP_', [
189-
'_GROUP_' => $record['nome'],
190-
]).'</h3>'.((empty($record['editable']) && ($record['nome'] != 'Amministratori')) ? '
191-
<div class="card-tools">
192-
<btn type="button" class="btn clickable btn-xs btn-warning float-right ask" data-msg="<small>'.tr('Verranno reimpostati i permessi di default per il gruppo '.$record['nome']).'.</small>" data-class="btn btn-warning" data-button="'.tr('Reimposta permessi').'" data-op="restore_permission">'.tr('Reimposta permessi').'</btn>
193-
</div>' : '').'
194-
</div>
195-
196-
<div class="card-body">';
210+
<div class="row">
211+
<div class="col-md-6 mx-auto">
212+
<div class="card card-primary card-outline">
213+
<div class="card-header">
214+
<h3 class="card-title">
215+
<i class="fa fa-lock mr-2"></i>'.tr('Permessi del gruppo: _GROUP_', [
216+
'_GROUP_' => '<span class="text-primary">'.$record['nome'].'</span>',
217+
]).'</h3>'.((empty($record['editable']) && ($record['nome'] != 'Amministratori')) ? '
218+
<div class="card-tools">
219+
<btn type="button" class="btn clickable btn-sm btn-warning float-right ask" data-msg="<small>'.tr('Verranno reimpostati i permessi di default per il gruppo '.$record['nome']).'.</small>" data-class="btn btn-warning" data-button="'.tr('Reimposta permessi').'" data-op="restore_permission">'.tr('Reimposta permessi').'</btn>
220+
</div>' : '').'
221+
</div>
222+
223+
<div class="card-body">';
197224
if ($record['nome'] != 'Amministratori') {
198225
echo '
199-
<div class="table-responsive">
200-
<table class="table table-hover table-sm table-striped">
201-
<tr>
202-
<th>'.tr('Modulo').'</th>
203-
<th>'.tr('Permessi').'</th>
204-
</tr>';
226+
<div class="table-responsive">
227+
<table class="table table-hover table-sm table-striped">
228+
<thead>
229+
<tr>
230+
<th style="padding: 4px 8px;"><i class="fa fa-cube"></i> '.tr('Modulo').'</th>
231+
<th style="padding: 4px 8px;"><i class="fa fa-shield-alt"></i> '.tr('Permessi').'</th>
232+
</tr>
233+
</thead>
234+
<tbody>';
205235

206236
$moduli = Modules::getHierarchy();
207237

@@ -216,15 +246,18 @@
216246
}
217247

218248
echo '
219-
</table>
220-
</div>';
249+
</tbody>
250+
</table>
251+
</div>';
221252
} else {
222253
echo '
223-
<div class="alert alert-info">
224-
<i class="fa fa-info-circle"></i> '.tr('Gli amministratori hanno accesso a qualsiasi modulo').'.
225-
</div>';
254+
<div class="alert alert-info">
255+
<i class="fa fa-info-circle"></i> '.tr('Gli amministratori hanno accesso a qualsiasi modulo').'.
256+
</div>';
226257
}
227258
echo '
259+
</div>
260+
</div>
228261
</div>
229262
</div>';
230263

@@ -252,17 +285,22 @@
252285
});
253286
254287
function colorize_select2(){
255-
$( ".select2-selection__rendered" ).each(function() {
256-
if ($( this ).attr("title") == "Lettura e scrittura"){
257-
$( this ).addClass( "text-green" );
288+
// Colora i valori selezionati nei select
289+
$(".select2-selection__rendered").each(function() {
290+
var title = $(this).attr("title");
291+
var select = $(this).closest(".select2-container").prev("select");
292+
var value = select.val();
293+
294+
$(this).removeClass("text-green text-orange text-red");
295+
296+
if (title == "Lettura e scrittura" || value == "rw"){
297+
$(this).addClass("text-green");
258298
}
259-
else if ($( this ).attr("title") == "Sola lettura"){
260-
$( this ).addClass( "text-orange" );
299+
else if (title == "Sola lettura" || value == "r"){
300+
$(this).addClass("text-orange");
261301
}
262-
else if ($( this ).attr("title") == "Nessun permesso"){
263-
$( this ).addClass( "text-red" );
264-
}else{
265-
302+
else if (title == "Nessun permesso" || value == "-"){
303+
$(this).addClass("text-red");
266304
}
267305
});
268306
}
@@ -271,7 +309,7 @@ function colorize_select2(){
271309
$("li.active.header button.btn-primary").attr("data-href", $("a.pull-right").attr("data-href") );
272310
273311
function update_permissions(id, value, color){
274-
312+
275313
$.get(
276314
globals.rootdir + "/actions.php?id_module='.$id_module.'&id_record='.$id_record.'&op=update_permission&idmodulo=" + id + "&permesso=" + value,
277315
function(data){
@@ -285,6 +323,7 @@ function(data){
285323
$("#select2-permesso_"+id+"-container").removeClass("text-green");
286324
$("#select2-permesso_"+id+"-container").addClass(color);
287325
326+
288327
if( id==$("#id_module_start").val() && value=="-" ){
289328
$("#id_module_start").selectReset();
290329
update_id_module_start($("#id_module_start").val());
@@ -296,7 +335,6 @@ function(data){
296335
}
297336
);
298337
}
299-
300338
var mySkins=["skin-blue","skin-black","skin-red","skin-yellow","skin-purple","skin-green","skin-blue-light","skin-black-light","skin-red-light","skin-yellow-light","skin-purple-light","skin-green-light"];
301339
302340
function changeSkin(cls){

0 commit comments

Comments
 (0)