|
55 | 55 | $sedi = $dbo->fetchOne('SELECT GROUP_CONCAT(idsede) as sedi FROM zz_user_sedi WHERE id_user='.prepare($id_utente).' GROUP BY id_user')['sedi']; |
56 | 56 | } |
57 | 57 |
|
| 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 | + |
58 | 66 | echo ' |
59 | 67 | <form action="'.base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'" method="post" enctype="multipart/form-data" id="user_update"> |
60 | 68 | <input type="hidden" name="op" value="update_user"> |
61 | 69 | <input type="hidden" name="backto" value="record-edit"> |
62 | 70 | <input type="hidden" name="id_utente" value="'.$utente['id'].'"> |
63 | 71 |
|
| 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 | +
|
64 | 80 | <div class="row"> |
65 | 81 | <div class="col-md-3">'; |
66 | 82 |
|
67 | 83 | // 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 | +} |
69 | 91 |
|
70 | 92 | if ($user_photo) { |
71 | 93 | echo ' |
@@ -165,6 +187,49 @@ function submitCheck() { |
165 | 187 | $("#idanag").change(function() { |
166 | 188 | session_set("superselect,idanagrafica", $(this).val(), 0); |
167 | 189 | $("#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 | + } |
168 | 233 | });'; |
169 | 234 |
|
170 | 235 | if (!empty($user)) { |
|
0 commit comments