openstamanager/modules/utenti/edit.php

330 lines
14 KiB
PHP
Raw Normal View History

<?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/>.
*/
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']));
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>
</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>
<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.'" ]}
</div>
2022-08-29 17:48:19 +02:00
</div>
<br>';
2017-09-12 14:53:19 +02:00
if (!empty($utenti)) {
echo '
2018-11-20 23:38:50 +01:00
<div class="table-responsive">
<table class="table table-hover table-condensed table-striped">
<tr>
<th>'.tr('Nome utente').'</th>
<th>'.tr('Email').'</th>
<th>'.tr('Ragione sociale').'</th>
<th>'.tr('Tipo di anagrafica').'</th>
<th>'.tr('Sedi').'</th>
2018-11-20 23:38:50 +01:00
<th width="120">'.tr('Opzioni').'</th>
</tr>';
2017-09-12 14:53:19 +02:00
foreach ($utenti as $utente) {
echo '
<tr>
<td '.(empty($utente['enabled']) ? ' style="text-decoration:line-through;"' : '').'>
<i class="fa fa-user"></i> '.$utente['username'].'
</td>';
if (!empty($utente['email'])) {
echo '
<td>'.$utente['email'].'</td>';
} else {
echo '
<td>-</td>';
}
if (!empty($utente['idanagrafica'])) {
echo '
2017-09-12 14:53:19 +02:00
<td>'.Modules::link('Anagrafiche', $utente['idanagrafica'], $utente['ragione_sociale']).'</td>
<td>'.$utente['tipo'].'</td>';
} else {
echo '
<td>-</td>
<td>-</td>';
}
$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'];
echo '
<td>'.$sedi.'</td>';
echo '
<td>';
// Disabilitazione utente, se diverso da id_utente #1 (admin)
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">
<i class="fa fa-eye-slash"></i>
</span></div>';
} elseif ($utente['enabled'] == 1) {
echo '
<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>
</a>';
} else {
echo '
<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>
</a>';
}
// Cambio password e nome utente
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)
$token = $dbo->fetchOne('SELECT `enabled` FROM `zz_tokens` WHERE `id_utente` = '.prepare($utente['id']).'')['enabled'];
2020-10-30 17:24:13 +01: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">
<i class="fa fa-key "></i>
</span></div>';
} elseif (!empty($token)) {
echo '
<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>
</a>';
2018-07-02 09:55:16 +02:00
} else {
echo '
<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>
</a>';
2018-07-02 09:55:16 +02:00
}
// Eliminazione utente, se diverso da id_utente #1 (admin)
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">
<i class="fa fa-trash"></i>
</span></div>';
} else {
echo '
<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>
</a>';
}
echo '
</td>
</tr>';
}
echo '
</table>
2018-11-20 23:38:50 +01:00
</div>';
} else {
echo '
<div class="alert alert-info">
<i class="fa fa-info-circle"></i> '.tr('Non ci sono utenti in questo gruppo').'.
</div>';
}
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">
<i class="fa fa-plus"></i> '.tr('Aggiungi utente').'
</a>
</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>
</div>
2024-05-16 18:02:50 +02:00
<div class="card-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">
<tr>
<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);
}
echo '
2018-11-20 23:38:50 +01:00
</table>
</div>';
} else {
echo '
<div class="alert alert-info">
<i class="fa fa-info-circle"></i> '.tr('Gli amministratori hanno accesso a qualsiasi modulo').'.
</div>';
}
echo '
</div>
</div>';
// Eliminazione gruppo (se non è tra quelli di default)
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>';
echo '
<script>
$(document).ready(function() {
$("#save-buttons").hide();
$("#email-button").remove();
setTimeout(function() { colorize_select2(); }, 500);
});
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{
}
});
}
$("li.active.header button.btn-primary").attr("data-href", $("a.pull-right").attr("data-href") );
function update_permissions(id, value, color){
$.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") {
2019-08-28 11:52:04 +02:00
toastr["success"]("'.tr('Permessi aggiornati!').'");
content_was_modified = false;
$("#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();
update_id_module_start($("#id_module_start").val());
2022-08-29 17:48:19 +02:00
}
2019-08-28 11:52:04 +02:00
} else {
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(){
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
});
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");
}
}
);
}
function update_theme(value){
2022-08-29 17:48:19 +02:00
$.get(
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") {
toastr["success"]("'.tr('Tema aggiornato!').'");
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
}
}
);
}
</script>';