|
933 | 933 | if (is_writable(Uploads::getDirectory($id_module))) { |
934 | 934 | if (post('firma_base64') != '') { |
935 | 935 | // Salvataggio firma |
936 | | - $firma_file = 'firma_'.time().'.jpg'; |
937 | 936 | $firma_nome = post('firma_nome'); |
938 | 937 |
|
939 | 938 | $data = explode(',', post('firma_base64')); |
|
948 | 947 | $img->contrast((float) setting('Contrasto firma Wacom')); |
949 | 948 | } |
950 | 949 |
|
951 | | - if (!$img->save(base_dir().'/files/interventi/'.$firma_file)) { |
| 950 | + // Salva temporaneamente il file per l'upload |
| 951 | + $temp_file = base_dir().'/files/interventi/firma_temp_'.time().'.jpg'; |
| 952 | + if (!$img->save($temp_file)) { |
952 | 953 | flash()->error(tr('Impossibile creare il file.')); |
953 | | - } elseif ($dbo->query('UPDATE in_interventi SET firma_file='.prepare($firma_file).', firma_data=NOW(), firma_nome = '.prepare($firma_nome).' WHERE id='.prepare($id_record))) { |
954 | | - flash()->info(tr('Firma salvata correttamente.')); |
| 954 | + } else { |
| 955 | + // Upload del file in zz_files con key='signature_nome_data' |
| 956 | + $data_firma = date('Y-m-d'); |
| 957 | + $upload = Uploads::upload($temp_file, [ |
| 958 | + 'name' => 'Firma', |
| 959 | + 'category' => 'Firme', |
| 960 | + 'id_module' => $id_module, |
| 961 | + 'id_record' => $id_record, |
| 962 | + 'key' => 'signature_'.$firma_nome.'_'.$data_firma, |
| 963 | + ]); |
955 | 964 |
|
956 | | - $id_stato = setting("Stato dell'attività dopo la firma"); |
957 | | - $stato = $dbo->selectOne('in_statiintervento', '*', ['id' => $id_stato]); |
958 | | - $intervento = Intervento::find($id_record); |
959 | | - if (!empty($stato)) { |
| 965 | + if (empty($upload)) { |
| 966 | + flash()->error(tr('Errore durante il caricamento della firma!')); |
| 967 | + } else { |
| 968 | + flash()->info(tr('Firma salvata correttamente.')); |
| 969 | + |
| 970 | + $id_stato = setting("Stato dell'attività dopo la firma"); |
| 971 | + $stato = $dbo->selectOne('in_statiintervento', '*', ['id' => $id_stato]); |
960 | 972 | $intervento = Intervento::find($id_record); |
961 | | - $intervento->idstatointervento = $stato['id']; |
962 | | - $intervento->save(); |
| 973 | + if (!empty($stato)) { |
| 974 | + $intervento = Intervento::find($id_record); |
| 975 | + $intervento->idstatointervento = $stato['id']; |
| 976 | + $intervento->save(); |
| 977 | + } |
963 | 978 | } |
964 | | - |
| 979 | + |
965 | 980 | // Notifica chiusura intervento |
966 | 981 | if (!empty($stato['notifica'])) { |
967 | 982 | $template = Template::find($stato['id_email']); |
|
998 | 1013 | } |
999 | 1014 | } |
1000 | 1015 | } |
1001 | | - } else { |
1002 | | - flash()->error(tr('Errore durante il salvataggio della firma nel database.')); |
1003 | | - } |
| 1016 | + } |
1004 | 1017 | } else { |
1005 | 1018 | flash()->error(tr('Errore durante il salvataggio della firma.').'<br>'.tr('La firma risulta vuota.')); |
1006 | 1019 | } |
|
1021 | 1034 | if (post('firma_base64') != '') { |
1022 | 1035 | foreach ($id_records as $id_record) { |
1023 | 1036 | // Salvataggio firma |
1024 | | - $firma_file = 'firma_'.time().'.jpg'; |
1025 | 1037 | $firma_nome = post('firma_nome'); |
1026 | 1038 |
|
1027 | 1039 | $data = explode(',', post('firma_base64')); |
|
1031 | 1043 | $constraint->aspectRatio(); |
1032 | 1044 | }); |
1033 | 1045 |
|
1034 | | - if (!$img->save(base_dir().'/files/interventi/'.$firma_file)) { |
| 1046 | + // Salva temporaneamente il file per l'upload |
| 1047 | + $temp_file = base_dir().'/files/interventi/firma_temp_'.time().'.jpg'; |
| 1048 | + if (!$img->save($temp_file)) { |
1035 | 1049 | flash()->error(tr('Impossibile creare il file!')); |
1036 | | - } elseif ($dbo->query('UPDATE in_interventi SET firma_file='.prepare($firma_file).', firma_data=NOW(), firma_nome = '.prepare($firma_nome).' WHERE id='.prepare($id_record))) { |
1037 | | - ++$firmati; |
1038 | | - |
1039 | | - $id_stato = setting("Stato dell'attività dopo la firma"); |
1040 | | - $stato = $dbo->selectOne('in_statiintervento', '*', ['id' => $id_stato]); |
1041 | | - $intervento = Intervento::find($id_record); |
1042 | | - if (!empty($stato)) { |
| 1050 | + } else { |
| 1051 | + // Upload del file in zz_files con key='signature_nome_data' |
| 1052 | + $data_firma = date('Y-m-d'); |
| 1053 | + $upload = Uploads::upload($temp_file, [ |
| 1054 | + 'name' => 'Firma', |
| 1055 | + 'category' => 'Firme', |
| 1056 | + 'id_module' => $id_module, |
| 1057 | + 'id_record' => $id_record, |
| 1058 | + 'key' => 'signature_'.$firma_nome.'_'.$data_firma, |
| 1059 | + ]); |
| 1060 | + |
| 1061 | + if (!empty($upload)) { |
| 1062 | + ++$firmati; |
| 1063 | + |
| 1064 | + $id_stato = setting("Stato dell'attività dopo la firma"); |
| 1065 | + $stato = $dbo->selectOne('in_statiintervento', '*', ['id' => $id_stato]); |
1043 | 1066 | $intervento = Intervento::find($id_record); |
1044 | | - $intervento->idstatointervento = $stato['id']; |
1045 | | - $intervento->save(); |
1046 | | - } |
1047 | | - |
1048 | | - // Notifica chiusura intervento |
1049 | | - if (!empty($stato['notifica'])) { |
1050 | | - $template = Template::find($stato['id_email']); |
1051 | | - |
1052 | | - if (!empty($stato['destinatari'])) { |
1053 | | - $mail = Mail::build(auth()->getUser(), $template, $id_record); |
1054 | | - $mail->addReceiver($stato['destinatari']); |
1055 | | - $mail->save(); |
| 1067 | + if (!empty($stato)) { |
| 1068 | + $intervento = Intervento::find($id_record); |
| 1069 | + $intervento->idstatointervento = $stato['id']; |
| 1070 | + $intervento->save(); |
1056 | 1071 | } |
1057 | 1072 |
|
1058 | | - if (!empty($stato['notifica_cliente'])) { |
1059 | | - if (!empty($intervento->anagrafica->email)) { |
| 1073 | + // Notifica chiusura intervento |
| 1074 | + if (!empty($stato['notifica'])) { |
| 1075 | + $template = Template::find($stato['id_email']); |
| 1076 | + |
| 1077 | + if (!empty($stato['destinatari'])) { |
1060 | 1078 | $mail = Mail::build(auth()->getUser(), $template, $id_record); |
1061 | | - $mail->addReceiver($intervento->anagrafica->email); |
| 1079 | + $mail->addReceiver($stato['destinatari']); |
1062 | 1080 | $mail->save(); |
1063 | 1081 | } |
1064 | | - } |
1065 | | - |
1066 | | - if (!empty($stato['notifica_tecnici'])) { |
1067 | | - $tecnici_intervento = $dbo->select('in_interventi_tecnici', 'idtecnico', [], ['idintervento' => $id_record]); |
1068 | | - $tecnici_assegnati = $dbo->select('in_interventi_tecnici_assegnati', 'id_tecnico AS idtecnico', [], ['id_intervento' => $id_record]); |
1069 | | - $tecnici = array_unique(array_merge($tecnici_intervento, $tecnici_assegnati), SORT_REGULAR); |
1070 | 1082 |
|
1071 | | - foreach ($tecnici as $tecnico) { |
1072 | | - $mail_tecnico = $dbo->selectOne('an_anagrafiche', '*', ['idanagrafica' => $tecnico]); |
1073 | | - if (!empty($mail_tecnico['email'])) { |
| 1083 | + if (!empty($stato['notifica_cliente'])) { |
| 1084 | + if (!empty($intervento->anagrafica->email)) { |
1074 | 1085 | $mail = Mail::build(auth()->getUser(), $template, $id_record); |
1075 | | - $mail->addReceiver($mail_tecnico['email']); |
| 1086 | + $mail->addReceiver($intervento->anagrafica->email); |
1076 | 1087 | $mail->save(); |
1077 | 1088 | } |
1078 | 1089 | } |
| 1090 | + |
| 1091 | + if (!empty($stato['notifica_tecnici'])) { |
| 1092 | + $tecnici_intervento = $dbo->select('in_interventi_tecnici', 'idtecnico', [], ['idintervento' => $id_record]); |
| 1093 | + $tecnici_assegnati = $dbo->select('in_interventi_tecnici_assegnati', 'id_tecnico AS idtecnico', [], ['id_intervento' => $id_record]); |
| 1094 | + $tecnici = array_unique(array_merge($tecnici_intervento, $tecnici_assegnati), SORT_REGULAR); |
| 1095 | + |
| 1096 | + foreach ($tecnici as $tecnico) { |
| 1097 | + $mail_tecnico = $dbo->selectOne('an_anagrafiche', '*', ['idanagrafica' => $tecnico]); |
| 1098 | + if (!empty($mail_tecnico['email'])) { |
| 1099 | + $mail = Mail::build(auth()->getUser(), $template, $id_record); |
| 1100 | + $mail->addReceiver($mail_tecnico['email']); |
| 1101 | + $mail->save(); |
| 1102 | + } |
| 1103 | + } |
| 1104 | + } |
1079 | 1105 | } |
| 1106 | + } else { |
| 1107 | + ++$non_firmati; |
1080 | 1108 | } |
1081 | | - } else { |
1082 | | - ++$non_firmati; |
1083 | 1109 | } |
1084 | 1110 | } |
1085 | | - } else { |
1086 | | - flash()->error(tr('Errore durante il salvataggio della firma.').'<br>'.tr('La firma risulta vuota')); |
1087 | 1111 | } |
1088 | 1112 | } else { |
1089 | 1113 | flash()->error(tr("Non è stato possibile creare la cartella _DIRECTORY_ per salvare l'immagine della firma.", [ |
|
0 commit comments