Skip to content

Commit 7a18812

Browse files
committed
fix: preselezione gruppo utenti in creazione utente
1 parent bad96df commit 7a18812

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

modules/utenti/components/base.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
if (!empty(filter('idanagrafica'))) {
2626
$utente['id_anagrafica'] = filter('idanagrafica');
2727
} else {
28-
$current_idgruppo = Group::find($id_record)->id;
28+
$current_idgruppo = !empty($id_record) ? Group::find($id_record)->id : null;
2929
}
3030

3131
echo '
3232
3333
<div class="row">
3434
<div class="col-md-12">
35-
{[ "type": "select", "label": "'.tr('Gruppo di appartenenza').'", "name": "idgruppo", "required": 1, "ajax-source": "gruppi", "value": "'.(!empty($utente['idgruppo']) ? $utente['idgruppo'] : $current_idgruppo).'", "icon-after": "add|'.Module::where('name', 'Utenti e permessi')->first()->id.'", "readonly": "'.(($utente['id'] == '1') ? 1 : 0).'" ]}
35+
{[ "type": "select", "label": "'.tr('Gruppo di appartenenza').'", "name": "idgruppo", "required": 1, "ajax-source": "gruppi", "value": "'.(!empty($utente['idgruppo']) ? $utente['idgruppo'] : $current_idgruppo).'", "icon-after": "add|'.Module::where('name', 'Utenti e permessi')->first()->id.'", "readonly": "'.(($utente['id'] == '1') || (!empty($id_record) && empty($utente['id'])) ? 1 : 0).'" ]}
3636
</div>
3737
</div>';
3838

modules/utenti/user.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

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

23+
use Models\Group;
2324
use Models\Module;
2425
use Models\Upload;
2526
use Models\User;
@@ -42,6 +43,13 @@
4243
$gruppo = $gruppi[$gruppo_utente];
4344
}
4445

46+
// Preseleziona il gruppo quando si aggiunge un nuovo utente dal contesto di un gruppo
47+
if (!empty(filter('idanagrafica'))) {
48+
$utente['id_anagrafica'] = filter('idanagrafica');
49+
} else {
50+
$current_idgruppo = !empty($id_record) ? Group::find($id_record)->id : null;
51+
}
52+
4553
// Lettura sedi dell'utente già impostate
4654
if (!empty($user)) {
4755
$sedi = $dbo->fetchOne('SELECT GROUP_CONCAT(idsede) as sedi FROM zz_user_sedi WHERE id_user='.prepare($id_utente).' GROUP BY id_user')['sedi'];
@@ -73,7 +81,7 @@
7381
<div class="col-md-9">
7482
<div class="row">
7583
<div class="col-md-6">
76-
{[ "type": "select", "label": "'.tr('Gruppo di appartenenza').'", "name": "idgruppo", "required": 1, "ajax-source": "gruppi", "value": "'.(!empty($utente['idgruppo']) ? $utente['idgruppo'] : $current_idgruppo).'", "icon-after": "add|'.Module::where('name', 'Utenti e permessi')->first()->id.'", "readonly": "'.(($utente['id'] == '1') ? 1 : 0).'" ]}
84+
{[ "type": "select", "label": "'.tr('Gruppo di appartenenza').'", "name": "idgruppo", "required": 1, "ajax-source": "gruppi", "value": "'.(!empty($utente['idgruppo']) ? $utente['idgruppo'] : $current_idgruppo).'", "readonly": "'.(($utente['id'] == '1') || (!empty($id_record) && empty($utente['id'])) ? 1 : 0).'" ]}
7785
</div>
7886
7987
<div class="col-md-6">
@@ -178,7 +186,7 @@ function no_check_pwd(){
178186
no_check_pwd();
179187
}
180188
});
181-
189+
182190
no_check_pwd();';
183191
}
184192

0 commit comments

Comments
 (0)