2017-08-04 16:28:16 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* 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 />.
*/
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2024-04-18 17:44:05 +02:00
$utenti = $dbo -> fetchArray ( 'SELECT *, (SELECT `ragione_sociale` FROM `an_anagrafiche` WHERE `an_anagrafiche`.`idanagrafica`=`zz_users`.`idanagrafica` ) AS `ragione_sociale`, (SELECT GROUP_CONCAT(`title` SEPARATOR ", ") FROM `an_tipianagrafiche` 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 ) . ') INNER JOIN `an_tipianagrafiche_anagrafiche` ON `an_tipianagrafiche`.`id`=`an_tipianagrafiche_anagrafiche`.`idtipoanagrafica` WHERE `idanagrafica`=`zz_users`.`idanagrafica` GROUP BY `idanagrafica`) AS tipo FROM `zz_users` WHERE `idgruppo`=' . prepare ( $record [ 'id' ]));
2017-08-04 16:28:16 +02:00
echo '
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Utenti del gruppo : _GROUP_ ' , [
2024-04-18 17:44:05 +02:00
'_GROUP_' => $group -> getTranslation ( 'title' ),
2024-03-22 15:52:24 +01:00
]) . ' </ h3 >
2017-08-04 16:28:16 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2022-08-29 17:48:19 +02:00
< div class = " row " >
< div class = " col-md-3 pull-right " >
2024-03-12 16:39:34 +01:00
{[ " 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 .' " ]}
2022-08-29 17:48:19 +02:00
</ div >
2024-01-18 22:39:15 +01:00
< div class = " col-md-3 pull-right " >
2024-05-17 12:11:00 +02:00
{[ " 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 .' " ]}
2024-01-18 22:39:15 +01:00
</ div >
2022-08-29 17:48:19 +02:00
</ div >
< br > ' ;
2019-07-18 18:33:56 +02:00
2017-09-12 14:53:19 +02:00
if ( ! empty ( $utenti )) {
2017-08-04 16:28:16 +02:00
echo '
2018-11-20 23:38:50 +01:00
< div class = " table-responsive " >
2017-08-04 16:28:16 +02:00
< table class = " table table-hover table-condensed table-striped " >
< tr >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Nome utente ').' </ th >
2021-06-28 15:06:30 +02:00
< th > '.tr(' Email ').' </ th >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Ragione sociale ').' </ th >
2019-06-20 16:44:45 +02:00
< th > '.tr(' Tipo di anagrafica ').' </ th >
< th > '.tr(' Sedi ').' </ th >
2018-11-20 23:38:50 +01:00
< th width = " 120 " > '.tr(' Opzioni ').' </ th >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
2017-09-12 14:53:19 +02:00
foreach ( $utenti as $utente ) {
2017-08-04 16:28:16 +02:00
echo '
< tr >
2019-07-18 18:33:56 +02:00
< td '.(empty($utente[' enabled ']) ? ' style = " text-decoration:line-through; " ' : ' ').' >
< i class = " fa fa-user " ></ i > '.$utente[' username '].'
</ td > ' ;
2021-06-28 15:06:30 +02:00
if ( ! empty ( $utente [ 'email' ])) {
echo '
< td > '.$utente[' email '].' </ td > ' ;
} else {
echo '
< td >-</ td > ' ;
}
2019-07-18 18:33:56 +02:00
if ( ! empty ( $utente [ 'idanagrafica' ])) {
2017-08-04 16:28:16 +02:00
echo '
2017-09-12 14:53:19 +02:00
< td > '.Modules::link(' Anagrafiche ', $utente[' idanagrafica '], $utente[' ragione_sociale ']).' </ td >
< td > '.$utente[' tipo '].' </ td > ' ;
2017-08-04 16:28:16 +02:00
} else {
echo '
< td >-</ td >
< td >-</ td > ' ;
}
2019-06-20 16:44:45 +02:00
$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' ];
2019-06-29 11:01:26 +02:00
2019-06-20 16:44:45 +02:00
echo '
< td > '.$sedi.' </ td > ' ;
2019-06-29 11:01:26 +02:00
2017-08-04 16:28:16 +02:00
echo '
2019-06-29 11:01:26 +02:00
< td > ' ;
2019-07-18 18:33:56 +02:00
2017-09-01 18:13:25 +02:00
// Disabilitazione utente, se diverso da id_utente #1 (admin)
2019-07-18 18:33:56 +02:00
if ( $utente [ 'id' ] == '1' ) {
echo '
2024-05-16 18:02:50 +02:00
< div data - card - widget = " tooltip " class = " tip " title = " '.tr( " Non è possibile disabilitare l 'utente admin").' " ><span class= " btn btn - xs btn - danger disabled " >
2020-10-28 16:39:44 +01:00
< i class = " fa fa-eye-slash " ></ i >
</ span ></ div > ' ;
2019-07-18 18:33:56 +02:00
} elseif ( $utente [ 'enabled' ] == 1 ) {
echo '
2020-10-28 16:39:44 +01:00
< a title = " '.tr('Disabilita utente').' " class = " btn btn-xs btn-danger tip ask " data - msg = " " data - backto = " record-edit " data - title = " '.tr('Disabilitare questo utente?').' " data - op = " disable_user " data - id_utente = " '. $utente['id'] .' " data - button = " '.tr('Disabilita').' " >
< i class = " fa fa-eye-slash " ></ i >
2019-07-18 18:33:56 +02:00
</ a > ' ;
2017-08-04 16:28:16 +02:00
} else {
echo '
2020-10-28 16:39:44 +01:00
< a title = " '.tr('Abilita utente').' " class = " btn btn-xs btn-success tip ask " data - msg = " " data - backto = " record-edit " data - title = " '.tr('Abiltare questo utente?').' " data - op = " enable_user " data - id_utente = " '. $utente['id'] .' " data - button = " '.tr('Abilita').' " data - class = " btn btn-lg btn-warning " >
< i class = " fa fa-eye " ></ i >
2019-07-18 18:33:56 +02:00
</ a > ' ;
2017-08-04 16:28:16 +02:00
}
2017-09-10 14:35:41 +02:00
// Cambio password e nome utente
2017-08-04 16:28:16 +02:00
echo '
2024-05-16 18:02:50 +02:00
< a href = " " data - href = " '. $structure->fileurl ('user.php').'?id_module='. $id_module .'&id_record='. $id_record .'&id_utente='. $utente['id'] .' " class = " btn btn-xs btn-warning tip " data - card - widget = " modal " title = " '.tr('Aggiorna dati utente').' " data - msg = " " data - backto = " record-edit " data - title = " '.tr('Aggiorna dati utente').' " >< i class = " fa fa-unlock-alt " ></ i ></ a > ' ;
2018-07-02 09:55:16 +02:00
// Disabilitazione token API, se diverso da id_utente #1 (admin)
2020-02-20 19:41:10 +01:00
$token = $dbo -> fetchOne ( 'SELECT `enabled` FROM `zz_tokens` WHERE `id_utente` = ' . prepare ( $utente [ 'id' ]) . '' )[ 'enabled' ];
2020-10-30 17:24:13 +01:00
2019-07-18 18:33:56 +02:00
if ( $utente [ 'id' ] == '1' ) {
echo '
2024-05-16 18:02:50 +02:00
< 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 " >
2020-10-28 16:39:44 +01:00
< i class = " fa fa-key " ></ i >
</ span ></ div > ' ;
2020-02-20 19:41:10 +01:00
} elseif ( ! empty ( $token )) {
2019-07-18 18:33:56 +02:00
echo '
2020-10-28 16:39:44 +01:00
< a title = " '.tr('Disabilita API').' " class = " btn btn-xs btn-danger tip ask " data - msg = " " data - backto = " record-edit " data - title = " '.tr( " Disabilitare l 'accesso API per questo utente?").' " data-op= " token_disable " data-id_utente= " '.$utente[' id '].' " data-button= " '.tr(' Disabilita ').' " >
< i class = " fa fa-key " ></ i >
2019-07-18 18:33:56 +02:00
</ a > ' ;
2018-07-02 09:55:16 +02:00
} else {
echo '
2020-10-28 16:39:44 +01:00
< a title = " '.tr('Abilitare API').' " class = " btn btn-xs btn-success tip ask " data - msg = " " data - backto = " record-edit " data - title = " '.tr( " Abilitare l 'accesso API per questo utente?").' " data-op= " token_enable " data-id_utente= " '.$utente[' id '].' " data-button= " '.tr(' Abilita ').' " data-class= " btn btn - lg btn - warning " >
< i class = " fa fa-key " ></ i >
2019-07-18 18:33:56 +02:00
</ a > ' ;
2018-07-02 09:55:16 +02:00
}
2017-08-04 16:28:16 +02:00
2017-09-01 18:13:25 +02:00
// Eliminazione utente, se diverso da id_utente #1 (admin)
2019-07-18 18:33:56 +02:00
if ( $utente [ 'id' ] == '1' ) {
2018-06-26 14:30:26 +02:00
echo '
2024-05-16 18:02:50 +02:00
< div data - card - widget = " tooltip " class = " tip " title = " '.tr( " Non è possibile eliminare l 'utente admin").' " ><span class= " btn btn - xs btn - danger disabled " >
2020-10-28 16:39:44 +01:00
< i class = " fa fa-trash " ></ i >
</ span ></ div > ' ;
2017-08-04 16:28:16 +02:00
} else {
echo '
2020-10-28 16:39:44 +01:00
< a title = " Elimina utente " class = " btn btn-xs btn-danger tip ask " data - msg = " " data - backto = " record-edit " data - title = " '.tr('Eliminare questo utente?').' " data - op = " delete_user " data - id_utente = " '. $utente['id'] .' " >
< i class = " fa fa-trash " ></ i >
2019-07-18 18:33:56 +02:00
</ a > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ td >
</ tr > ' ;
}
echo '
2019-07-18 18:33:56 +02:00
</ table >
2018-11-20 23:38:50 +01:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
} else {
echo '
2019-07-18 18:33:56 +02:00
< div class = " alert alert-info " >
< i class = " fa fa-info-circle " ></ i > '.tr(' Non ci sono utenti in questo gruppo ').' .
</ div > ' ;
2017-08-04 16:28:16 +02:00
}
2019-07-18 18:33:56 +02:00
2017-08-04 16:28:16 +02:00
echo '
2024-05-16 18:02:50 +02:00
< 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 " >
2019-07-18 18:33:56 +02:00
< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi utente ').'
</ a >
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
// Aggiunta nuovo utente
echo '
< hr > ' ;
echo '
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Permessi del gruppo : _GROUP_ ' , [
2024-03-22 15:52:24 +01:00
'_GROUP_' => $record [ 'nome' ],
]) . (( empty ( $record [ 'editable' ]) && ( $record [ 'nome' ] != 'Amministratori' )) ? '<a class=\'clickable btn-xs pull-right ask\' data-msg="' . tr ( 'Verranno reimpostati i permessi di default per il gruppo \'' . $record [ 'nome' ] . '\' ' ) . '." data-class="btn btn-lg btn-warning" data-button="' . tr ( 'Reimposta permessi' ) . '" data-op="restore_permission" >' . tr ( 'Reimposta permessi' ) . '</a>' : '' ) . ' </ h3 >
2017-08-04 16:28:16 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " > ' ;
2017-08-04 16:28:16 +02:00
if ( $record [ 'nome' ] != 'Amministratori' ) {
echo '
2018-11-20 23:38:50 +01:00
< div class = " table-responsive " >
< table class = " table table-hover table-condensed table-striped " >
2017-08-04 16:28:16 +02:00
< tr >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Modulo ').' </ th >
< th > '.tr(' Permessi ').' </ th >
2018-07-02 09:55:16 +02:00
</ tr > ' ;
2018-03-02 19:01:30 +01:00
2018-07-02 09:55:16 +02:00
$moduli = Modules :: getHierarchy ();
2020-10-30 17:24:13 +01:00
$permessi_disponibili = [
2018-07-02 09:55:16 +02:00
'-' => tr ( 'Nessun permesso' ),
'r' => tr ( 'Sola lettura' ),
'rw' => tr ( 'Lettura e scrittura' ),
];
for ( $m = 0 ; $m < count ( $moduli ); ++ $m ) {
2020-10-30 17:24:13 +01:00
echo menuSelection ( $moduli [ $m ], $id_record , - 1 , $permessi_disponibili );
2017-08-04 16:28:16 +02:00
}
echo '
2018-11-20 23:38:50 +01:00
</ table >
</ div > ' ;
2017-08-04 16:28:16 +02:00
} else {
echo '
2019-07-18 18:33:56 +02:00
< div class = " alert alert-info " >
< i class = " fa fa-info-circle " ></ i > '.tr(' Gli amministratori hanno accesso a qualsiasi modulo ').' .
</ div > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ div >
</ div > ' ;
// Eliminazione gruppo (se non è tra quelli di default)
2022-11-24 18:55:19 +01:00
echo '
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
< a class = " btn btn-danger ask '.(! $record['editable'] ? 'disabled' : '').' " '.(!$record[' editable '] ? ' disabled ' : ' ').' data - backto = " record-list " data - msg = " '.tr('Eliminando questo gruppo verranno eliminati anche i permessi e gli utenti collegati').' " data - op = " deletegroup " >
< i class = " fa fa-trash " ></ i > '.tr(' Elimina ').'
</ a >
</ div >
</ div > ' ;
2017-08-04 16:28:16 +02:00
echo '
< script >
2020-07-31 14:25:50 +02:00
$ ( document ) . ready ( function () {
2021-03-15 11:10:46 +01:00
$ ( " #save-buttons " ) . hide ();
2020-07-31 14:25:50 +02:00
2019-07-30 16:52:16 +02:00
$ ( " #email-button " ) . remove ();
2022-11-24 18:55:19 +01:00
setTimeout ( function () { colorize_select2 (); }, 500 );
2019-07-30 16:52:16 +02:00
});
2022-11-24 18:55:19 +01:00
function colorize_select2 (){
$ ( " .select2-selection__rendered " ) . each ( function () {
if ( $ ( this ) . attr ( " title " ) == " Lettura e scrittura " ){
$ ( this ) . addClass ( " text-green " );
}
else if ( $ ( this ) . attr ( " title " ) == " Sola lettura " ){
$ ( this ) . addClass ( " text-orange " );
}
else if ( $ ( this ) . attr ( " title " ) == " Nessun permesso " ){
$ ( this ) . addClass ( " text-red " );
} else {
}
});
}
2019-07-30 16:52:16 +02:00
$ ( " li.active.header button.btn-primary " ) . attr ( " data-href " , $ ( " a.pull-right " ) . attr ( " data-href " ) );
2022-11-24 18:55:19 +01:00
function update_permissions ( id , value , color ){
2019-07-30 16:52:16 +02:00
$ . get (
globals . rootdir + " /actions.php?id_module='. $id_module .'&id_record='. $id_record .'&op=update_permission&idmodulo= " + id + " &permesso= " + value ,
function ( data ){
2019-08-28 11:52:04 +02:00
if ( data == " ok " ) {
2024-01-18 22:39:15 +01:00
2019-08-28 11:52:04 +02:00
toastr [ " success " ]( " '.tr('Permessi aggiornati!').' " );
2022-11-24 19:27:18 +01:00
content_was_modified = false ;
2022-11-24 18:55:19 +01:00
$ ( " #select2-permesso_ " + id + " -container " ) . removeClass ( " text-red " );
$ ( " #select2-permesso_ " + id + " -container " ) . removeClass ( " text-orange " );
$ ( " #select2-permesso_ " + id + " -container " ) . removeClass ( " text-green " );
$ ( " #select2-permesso_ " + id + " -container " ) . addClass ( color );
2022-08-29 17:48:19 +02:00
if ( id == $ ( " #id_module_start " ) . val () && value == " - " ){
$ ( " #id_module_start " ) . selectReset ();
2024-01-18 22:39:15 +01:00
update_id_module_start ( $ ( " #id_module_start " ) . val ());
2022-08-29 17:48:19 +02:00
}
2024-01-18 22:39:15 +01:00
2019-08-28 11:52:04 +02:00
} else {
2019-07-30 16:52:16 +02:00
swal ( " '.tr('Errore').' " , " '.tr( " Errore durante l 'aggiornamento dei permessi!").' " , " error " );
}
}
);
}
2022-08-29 17:48:19 +02:00
2024-02-12 18:13:39 +01:00
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 " ];
function changeSkin ( cls ){
$ . each ( mySkins , function ( i ){
$ ( " body " ) . removeClass ( mySkins [ i ])
});
$ ( " body " ) . addClass ( " skin- " + cls );
return false ;
}
2022-08-29 17:48:19 +02:00
$ ( " #id_module_start " ) . change ( function (){
2024-01-18 22:39:15 +01:00
update_id_module_start ( $ ( this ) . val ());
});
$ ( " #theme " ) . change ( function (){
update_theme ( $ ( this ) . val ());
2024-02-23 19:44:52 +01:00
if ( $ ( this ) . val ())
changeSkin ( $ ( this ) . val ());
2022-08-29 17:48:19 +02:00
});
2024-01-18 22:39:15 +01:00
function update_id_module_start ( value ){
$ . get (
globals . rootdir + " /actions.php?id_module='. $id_module .'&id_record='. $id_record .'&op=update_id_module_start&id_module_start= " + value ,
function ( data ){
if ( data == " ok " ) {
toastr [ " success " ]( " '.tr('Modulo iniziale aggiornato!').' " );
content_was_modified = false ;
} else {
2024-03-12 17:27:26 +01:00
swal ( " '.tr('Errore').' " , data , " error " );
2024-01-18 22:39:15 +01:00
}
}
);
}
function update_theme ( value ){
2022-08-29 17:48:19 +02:00
$ . get (
2024-01-18 22:39:15 +01:00
globals . rootdir + " /actions.php?id_module='. $id_module .'&id_record='. $id_record .'&op=update_theme&theme= " + value ,
2022-08-29 17:48:19 +02:00
function ( data ){
if ( data == " ok " ) {
2024-01-18 22:39:15 +01:00
toastr [ " success " ]( " '.tr('Tema aggiornato!').' " );
2022-11-24 19:27:18 +01:00
content_was_modified = false ;
2022-08-29 17:48:19 +02:00
} else {
2024-03-12 17:27:26 +01:00
swal ( " '.tr('Errore').' " , data , " error " );
2022-08-29 17:48:19 +02:00
}
}
);
}
2017-08-04 16:28:16 +02:00
</ script > ' ;