Skip to content

Commit 91eb13a

Browse files
committed
refactor: avviso in aggiunta utente
1 parent 21fd891 commit 91eb13a

2 files changed

Lines changed: 116 additions & 1 deletion

File tree

modules/utenti/ajax/complete.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/*
3+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
4+
* Copyright (C) DevCode s.r.l.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
include_once __DIR__.'/../../../core.php';
21+
22+
switch ($resource) {
23+
case 'check_anagrafica_tipo':
24+
$idanagrafica = get('idanagrafica');
25+
$result = [
26+
'is_tecnico' => false,
27+
'tipi' => []
28+
];
29+
30+
if (!empty($idanagrafica)) {
31+
// Query per ottenere i tipi di anagrafica
32+
$query = "SELECT `an_tipianagrafiche_lang`.`title`
33+
FROM `an_tipianagrafiche_anagrafiche`
34+
INNER JOIN `an_tipianagrafiche` ON `an_tipianagrafiche_anagrafiche`.`idtipoanagrafica` = `an_tipianagrafiche`.`id`
35+
LEFT JOIN `an_tipianagrafiche_lang` ON (`an_tipianagrafiche`.`id` = `an_tipianagrafiche_lang`.`id_record` AND `an_tipianagrafiche_lang`.`id_lang` = ".prepare(Models\Locale::getDefault()->id).")
36+
WHERE `an_tipianagrafiche_anagrafiche`.`idanagrafica` = ".prepare($idanagrafica);
37+
38+
$rs = $dbo->fetchArray($query);
39+
40+
foreach ($rs as $r) {
41+
$result['tipi'][] = $r['title'];
42+
if ($r['title'] == 'Tecnico') {
43+
$result['is_tecnico'] = true;
44+
}
45+
}
46+
}
47+
48+
echo json_encode($result);
49+
break;
50+
}

modules/utenti/user.php

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,39 @@
5555
$sedi = $dbo->fetchOne('SELECT GROUP_CONCAT(idsede) as sedi FROM zz_user_sedi WHERE id_user='.prepare($id_utente).' GROUP BY id_user')['sedi'];
5656
}
5757

58+
// Verifica se si sta creando un utente per il gruppo Tecnici
59+
$is_new_user = empty($user);
60+
$is_tecnici_group = false;
61+
if (!empty($id_record)) {
62+
$current_group = Group::find($id_record);
63+
$is_tecnici_group = $current_group && $current_group->getTranslation('title') == 'Tecnici';
64+
}
65+
5866
echo '
5967
<form action="'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'" method="post" enctype="multipart/form-data" id="user_update">
6068
<input type="hidden" name="op" value="update_user">
6169
<input type="hidden" name="backto" value="record-edit">
6270
<input type="hidden" name="id_utente" value="'.$utente['id'].'">
6371
72+
<!-- Contenitore per avviso dinamico -->
73+
<div id="anagrafica-warning" style="display: none;">
74+
<div class="alert alert-warning">
75+
<i class="fa fa-exclamation-triangle"></i> <span id="warning-message">'.tr('Attenzione: per poter utilizzare l\'applicazione mobile, questo utente deve essere associato ad un\'anagrafica di tipo <strong>Tecnico</strong>').'.</span>
76+
</div>
77+
</div>
78+
79+
6480
<div class="row">
6581
<div class="col-md-3">';
6682

6783
// Photo component
68-
$user_photo = $rootdir.'/files/utenti/'.Upload::find($user->image_file_id)->filename;
84+
$user_photo = null;
85+
if (!empty($user) && !empty($user->image_file_id)) {
86+
$upload = Upload::find($user->image_file_id);
87+
if ($upload) {
88+
$user_photo = $rootdir.'/files/utenti/'.$upload->filename;
89+
}
90+
}
6991

7092
if ($user_photo) {
7193
echo '
@@ -165,6 +187,49 @@ function submitCheck() {
165187
$("#idanag").change(function() {
166188
session_set("superselect,idanagrafica", $(this).val(), 0);
167189
$("#idsede").selectReset();
190+
191+
// Verifica tipo anagrafica per utenti tecnici
192+
var isNewUser = '.($is_new_user ? 'true' : 'false').';
193+
var isTecniciGroup = '.($is_tecnici_group ? 'true' : 'false').';
194+
195+
if (isNewUser && isTecniciGroup) {
196+
if ($(this).val()) {
197+
// Anagrafica selezionata - verifica il tipo
198+
$.ajax({
199+
url: "'.base_path().'/ajax_complete.php",
200+
type: "GET",
201+
data: {
202+
module: "Utenti",
203+
op: "check_anagrafica_tipo",
204+
idanagrafica: $(this).val()
205+
},
206+
success: function(data) {
207+
try {
208+
var result = JSON.parse(data);
209+
if (!result.is_tecnico) {
210+
// Aggiorna il messaggio con il tipo effettivo
211+
var tipoEffettivo = result.tipi.join(", ");
212+
var messaggio = "'.tr('Attenzione: per poter utilizzare l\'applicazione mobile, questo utente deve essere associato ad un\'anagrafica di tipo <strong>Tecnico</strong>').'. '.tr('L\'anagrafica selezionata è di tipo').': <strong>" + tipoEffettivo + "</strong>.";
213+
$("#warning-message").html(messaggio);
214+
// Mostra warning se non è tecnico
215+
$("#anagrafica-warning").show();
216+
} else {
217+
// Nascondi warning se è tecnico
218+
$("#anagrafica-warning").hide();
219+
}
220+
} catch (e) {
221+
console.error("Errore parsing JSON:", e);
222+
}
223+
},
224+
error: function() {
225+
console.error("Errore nella verifica del tipo anagrafica");
226+
}
227+
});
228+
} else {
229+
// Nessuna anagrafica selezionata - nascondi warning
230+
$("#anagrafica-warning").hide();
231+
}
232+
}
168233
});';
169234

170235
if (!empty($user)) {

0 commit comments

Comments
 (0)