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' ;
2018-07-03 11:12:32 +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(descrizione SEPARATOR ", ") FROM an_tipianagrafiche INNER JOIN an_tipianagrafiche_anagrafiche ON an_tipianagrafiche.idtipoanagrafica=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 '
< div class = " panel panel-primary " >
< div class = " panel-heading " >
2017-09-10 14:35:41 +02:00
< h3 class = " panel-title " > '.tr(' Utenti _GROUP_ ' , [
2018-07-18 15:20:10 +02:00
'_GROUP_' => $record [ 'nome' ],
2017-09-10 14:35:41 +02:00
]) . ' </ h3 >
2017-08-04 16:28:16 +02:00
</ div >
2022-08-29 17:48:19 +02:00
< div class = " panel-body " >
< div class = " row " >
< div class = " col-md-3 pull-right " >
{[ " type " : " select " , " label " : " " , " name " : " id_module_start " , " ajax-source " : " moduli_gruppo " , " select-options " : '.json_encode([' idgruppo ' => $record[' id ']]).' , " placeholder " : " '.tr('Modulo iniziale').' " , " value " : " '. $record['id_module_start'] .' " ]}
</ div >
</ 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 '
2021-06-28 15:06:30 +02:00
< div data - toggle = " 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 '
2020-10-28 16:39:44 +01: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 - toggle = " 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 '
2021-06-28 15:06:30 +02:00
< div data - toggle = " 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 '
2021-06-28 15:06:30 +02:00
< div data - toggle = " 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 '
2019-07-18 18:33:56 +02:00
< a data - toggle = " 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 " >
< 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 '
< div class = " panel panel-primary " >
< div class = " panel-heading " >
2018-05-22 22:51:22 +02:00
< h3 class = " panel-title " > '.tr(' Permessi _GROUP_ ' , [
2018-07-18 15:20:10 +02:00
'_GROUP_' => $record [ 'nome' ],
2018-11-20 23:38:50 +01:00
]) . (( empty ( $record [ 'editable' ])) ? '<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 >
2018-08-29 18:15:12 +02:00
2017-08-04 16:28:16 +02:00
</ div >
< div class = " panel-body " > ' ;
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)
if ( $record [ 'editable' ] == 1 ) {
echo '
2017-09-12 16:17:11 +02:00
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
< a class = " btn btn-danger ask " 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 >
2017-08-04 16:28:16 +02:00
</ div > ' ;
}
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 ();
});
$ ( " li.active.header button.btn-primary " ) . attr ( " data-href " , $ ( " a.pull-right " ) . attr ( " data-href " ) );
function update_permissions ( id , value ){
$ . 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 " ) {
toastr [ " success " ]( " '.tr('Permessi aggiornati!').' " );
2022-08-29 17:48:19 +02:00
if ( id == $ ( " #id_module_start " ) . val () && value == " - " ){
$ ( " #id_module_start " ) . selectReset ();
update_user ( $ ( " #id_module_start " ) . val ());
}
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
$ ( " #id_module_start " ) . change ( function (){
update_user ( $ ( this ) . val ());
});
function update_user ( value ){
$ . get (
globals . rootdir + " /actions.php?id_module='. $id_module .'&id_record='. $id_record .'&op=update&id_module_start= " + value ,
function ( data ){
if ( data == " ok " ) {
toastr [ " success " ]( " '.tr('Prima pagina aggiornata!').' " );
} else {
swal ( " '.tr('Errore').' " , " '.tr( " Errore durante l 'aggiornamento delle informazioni!").' " , " error " );
}
}
);
}
2017-08-04 16:28:16 +02:00
</ script > ' ;