diff --git a/actions.php b/actions.php index 28a057484..e8d9182ff 100644 --- a/actions.php +++ b/actions.php @@ -217,47 +217,57 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') { } elseif (filter('op') == 'send-email') { $template = Mail::getTemplate($post['template']); - $final_attachments = []; + $attachments = []; - $prints = Prints::getModulePrints($id_module); - foreach ($prints as $print) { - if (!empty($post['print-'.$print['id']])) { - $filename = $upload_dir.'/'.$print['title'].' - '.$id_record.'.pdf'; + // Stampe + foreach ($post['prints'] as $print) { + $print = Prints::get($print); - Prints::render($print['id'], $id_record, $filename); + $filename = $upload_dir.'/'.$print['title'].' - '.$id_record.'.pdf'; - $final_attachments[] = [ - 'path' => $filename, - 'name' => $print['title'], - ]; - } + Prints::render($print['id'], $id_record, $filename); + + $attachments[] = [ + 'path' => $filename, + 'name' => $print['title'], + ]; } - $attachments = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record)); - foreach ($attachments as $attachment) { - if (!empty($post['attachment-'.$attachment['id']])) { - $final_attachments[] = [ - 'path' => $upload_dir.'/'.$attachment['filename'], - 'name' => $attachment['nome'], - ]; - } + // Allegati del record + $selected = []; + if (!empty($post['attachments'])) { + $selected = $dbo->fetchArray('SELECT * FROM zz_files WHERE id IN ('.implode($post['attachments']).') AND id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record)); } + foreach ($selected as $attachment) { + $attachments[] = [ + 'path' => $upload_dir.'/'.$attachment['filename'], + 'name' => $attachment['nome'], + ]; + } + + // Allegati dell'Azienda predefinita $anagrafiche = Modules::get('Anagrafiche'); - $attachments = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module = '.prepare($anagrafiche['id'])." AND id_record = (SELECT valore FROM zz_settings WHERE nome = 'Azienda predefinita')"); - foreach ($attachments as $attachment) { - if (!empty($post['default-'.$attachment['id']])) { - $final_attachments[] = [ - 'path' => DOCROOT.'/files/'.$anagrafiche['directory'].'/'.$attachment['filename'], - 'name' => $attachment['nome'], - ]; - } + + $selected = []; + if (!empty($post['attachments'])) { + $selected = $dbo->fetchArray('SELECT * FROM zz_files WHERE id IN ('.implode(',', $post['attachments']).') AND id_module != '.prepare($id_module)); + } + + foreach ($selected as $attachment) { + $attachments[] = [ + 'path' => DOCROOT.'/files/'.$anagrafiche['directory'].'/'.$attachment['filename'], + 'name' => $attachment['nome'], + ]; } // Preparazione email $mail = new Mail(); - $mail->AddAddress($post['email']); + // Conferma di lettura + if (!empty($post['read_notify'])) { + $mail->ConfirmReadingTo = $mail->From; + } // Reply To if (!empty($template['reply_to'])) { @@ -274,6 +284,32 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') { $mail->AddBCC($template['bcc']); } + // Destinatari + foreach ($post['destinatari'] as $key => $destinatario) { + $type = $post['tipo_destinatari'][$key]; + + $pieces = explode('<', $destinatario); + $count = count($pieces); + + $name = null; + if ($count > 1) { + $email = substr(end($pieces), 0, -1); + $name = substr($destinatario, 0, strpos($destinatario, '<'.$email)); + } else { + $email = $destinatario; + } + + if (!empty($email)) { + if ($type == 'a') { + $mail->AddAddress($email, $name); + } elseif ($type == 'cc') { + $mail->AddCC($email, $name); + } elseif ($type == 'bcc') { + $mail->AddBCC($email, $name); + } + } + } + // Oggetto $mail->Subject = $post['subject']; @@ -282,14 +318,18 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') { $mail->AddAttachment($attachment['path'], $attachment['name']); } + // Contenuto $mail->Body = $post['body']; // Invio mail if (!$mail->send()) { - $_SESSION['errors'][] = tr("Errore durante l'invio della segnalazione").': '.$mail->ErrorInfo; + $_SESSION['errors'][] = tr("Errore durante l'invio dell'email").': '.$mail->ErrorInfo; } else { $_SESSION['infos'][] = tr('Email inviata correttamente!'); } + + redirect(ROOTDIR.'/editor.php?id_module='.$id_module.'&id_record='.$id_record); + exit(); } if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso) == 'rw') { diff --git a/assets/src/css/style.css b/assets/src/css/style.css index 94171030d..ca6ed7f5c 100644 --- a/assets/src/css/style.css +++ b/assets/src/css/style.css @@ -75,6 +75,7 @@ a.disabled { } .ui-autocomplete { + z-index: 10000; min-width: 160px; padding: 10px; margin: 2px; @@ -274,7 +275,6 @@ span.form-control { margin-top: 0; } - /* Aggiustamenti per i widget */ .widget li { @@ -301,7 +301,6 @@ span.form-control { opacity: 0.1; } - /* Tooltip dark */ .ui-tooltip { @@ -448,12 +447,11 @@ span.form-control { margin: 5px; } - /* Personalizzazione del plugin Select2 */ .select2-search, .select2-search__field { - width: 100% + width: 100% !important } .select2-results__option[aria-selected=true] { @@ -476,7 +474,6 @@ span.form-control { border-radius: 0px; } - /* Interventi da pianificare in Dashboard */ #external-events .fc-event { @@ -519,11 +516,9 @@ input.small-width { width: 90%; margin-top: 20px } - .main-header .logo { display: none; } - /* .content-wrapper, .right-side, @@ -554,7 +549,6 @@ input.small-width { .push { position: static; } - .signature-pad { top: 0; left: 0; diff --git a/mail.php b/mail.php index e03cf7dce..9a9a26c15 100644 --- a/mail.php +++ b/mail.php @@ -4,141 +4,149 @@ include_once __DIR__.'/core.php'; $template = Mail::getTemplate($get['id']); $module = Modules::get($id_module); +$smtp = Mail::get($template['id_smtp']); $body = $template['body']; $subject = $template['subject']; -$variables = Mail::getTemplateVariables($template); +$variables = Mail::getTemplateVariables($template['id'], $id_record); $email = $variables['email']; +// Sostituzione delle variabili di base +$replaces = []; +foreach ($variables as $key => $value) { + $replaces['{'.$key.'}'] = $value; +} + +$body = str_replace(array_keys($replaces), array_values($replaces), $body); +$subject = str_replace(array_keys($replaces), array_values($replaces), $subject); + +// Form echo ' -
+ - -
-
-

'.tr('Dati').'

-
+

'.tr('Mittente').': '.$smtp['from_name'].' <'.$smtp['from_address'].'>

'; -
-
-
- {[ "type": "text", "label": "'.tr('Oggetto').'", "name": "subject", "value": "'.$subject.'", "required": 1 ]} -
+if (!empty($smtp['cc'])) { + echo ' +

'.tr('CC').': '.$smtp['cc'].'

'; +} -
- {[ "type": "email", "label": "'.tr('Destinatario').'", "name": "email", "value": "'.$email.'", "required": 1 ]} -
-
+if (!empty($smtp['cc'])) { + echo ' +

'.tr('CCN').': '.$smtp['bcc'].'

'; +} -
-
- {[ "type": "textarea", "label": "'.tr('Contenuto').'", "name": "body", "value": '.json_encode($body).' ]} -
-
+echo ' + + '.tr('Destinatari').' +
+
+ {[ "type": "email", "name": "destinatari[]", "value": "'.$email.'", "icon-before": "choice|email", "extra": "onkeyup=\'aggiungi_destinatario();\'", "class": "destinatari", "required": 1 ]} +
+
+ +
+ +
+
+ {[ "type": "text", "label": "'.tr('Oggetto').'", "name": "subject", "value": "'.$subject.'", "required": 1 ]} +
+ +
+ {[ "type": "checkbox", "label": "'.tr('Notifica di lettura').'", "name": "read_notify", "value": "'.$template['read_notify'].'" ]} +
+
'; + +// Stampe +$selected_prints = $dbo->fetchArray('SELECT id_print FROM zz_email_print WHERE id_email = '.prepare($template['id'])); +$selected = array_column($selected_prints, 'id_print'); + +echo ' + +
+
+ {[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected).'", "values": "query=SELECT id, title AS text FROM zz_prints WHERE id_module = '.prepare($id_module).'" ]} +
'; + +// Allegati +echo ' + +
+ {[ "type": "select", "multiple": "1", "label": "'.tr('Allegati').'", "name": "attachments[]", "values": "query=SELECT id, nome AS text FROM zz_files WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record)." UNION SELECT id, CONCAT(nome, ' (Azienda)') AS text FROM zz_files WHERE id_module = ".prepare(Modules::get('Anagrafiche')['id'])." AND id_record = (SELECT valore FROM zz_settings WHERE nome = 'Azienda predefinita')\" ]} +
+
"; + +echo ' + +
+
+ {[ "type": "textarea", "label": "'.tr('Contenuto').'", "name": "body", "value": '.json_encode($body).' ]}
'; echo ' -
- - -
-
-
-

'.tr('Stampe').'

-
- -
'; - -$selected_prints = $dbo->fetchArray('SELECT id_print FROM zz_email_print WHERE id_email = '.prepare($template['id'])); -$selected = array_column($selected_prints, 'id_print'); - -$prints = Prints::getModulePrints($id_module); -foreach ($prints as $print) { - echo ' - {[ "type": "checkbox", "label": "'.$print['title'].'", "name": "print-'.$print['id'].'", "value": "'.in_array($print['id'], $selected).'" ]}'; -} - -echo ' -
-
-
- - -
-
-
-

'.tr('Allegati').'

-
- -
'; - -$attachments = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record)); - -if (empty($attachments)) { - echo ' -

'.tr('Nessun allegato disponibile').'.

'; -} - -foreach ($attachments as $attachment) { - echo ' - {[ "type": "checkbox", "label": "'.$attachment['nome'].'", "name": "attachment-'.$attachment['id'].'" ]}'; -} - -echo ' -
-
-
- - -
-
-
-

'.tr('Anagrafica').'

-
- -
'; - -$attachments = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module = '.prepare(Modules::get('Anagrafiche')['id'])." AND id_record = (SELECT valore FROM zz_settings WHERE nome = 'Azienda predefinita')"); - -if (empty($attachments)) { - echo ' -

'.tr('Nessun allegato disponibile').'.

'; -} - -foreach ($attachments as $attachment) { - echo ' - {[ "type": "checkbox", "label": "'.$attachment['nome'].'", "name": "default-'.$attachment['id'].'" ]}'; -} - -echo ' -
-
-
- -
- +
'; +echo ' +
+
+ {[ "type": "email", "name": "destinatari[]", "icon-before": "choice|email|cc", "extra": "onkeyup=\'aggiungi_destinatario();\'", "class": "destinatari" ]} +
+
'; + echo ' '; echo ' '; echo ' diff --git a/modules/interventi/variables.php b/modules/interventi/variables.php new file mode 100644 index 000000000..6fa1d65e5 --- /dev/null +++ b/modules/interventi/variables.php @@ -0,0 +1,7 @@ +fetchArray('SELECT * FROM in_interventi WHERE id='.prepare($id_record))[0]; + +return [ + 'id_anagrafica' => $rs['idanagrafica'], +]; diff --git a/modules/smtp/ajax/complete.php b/modules/smtp/ajax/complete.php new file mode 100644 index 000000000..0ca34cb04 --- /dev/null +++ b/modules/smtp/ajax/complete.php @@ -0,0 +1,52 @@ +fetchArray($q); + foreach ($rs as $r) { + $results[] = [ + 'value' => $r['email'], + 'label' => $r['ragione_sociale'].' <'.$r['email'].'>', + ]; + } + + // Tutti gli agenti + $q = "SELECT DISTINCT(email), ragione_sociale, an_anagrafiche.idanagrafica FROM an_anagrafiche INNER JOIN an_tipianagrafiche_anagrafiche ON an_anagrafiche.idanagrafica=an_tipianagrafiche_anagrafiche.idanagrafica WHERE idtipoanagrafica = (SELECT idtipoanagrafica FROM an_tipianagrafiche WHERE descrizione='Agente') AND email != '' ORDER BY idanagrafica"; + + $rs = $dbo->fetchArray($q); + foreach ($rs as $r) { + $results[] = [ + 'value' => $r['email'], + 'label' => $r['ragione_sociale'].' <'.$r['email'].'>', + ]; + } + + // Email del cliente + $q = "SELECT DISTINCT(email), ragione_sociale, idanagrafica FROM an_anagrafiche WHERE email != '' ".$where.' ORDER BY idanagrafica'; + + $rs = $dbo->fetchArray($q); + foreach ($rs as $r) { + $results[] = [ + 'value' => $r['email'], + 'label' => $r['ragione_sociale'].' <'.$r['email'].'>', + ]; + } + + echo json_encode($results); + + break; +} diff --git a/modules/utenti/user.php b/modules/utenti/user.php index 9b2d28c88..5d6289101 100644 --- a/modules/utenti/user.php +++ b/modules/utenti/user.php @@ -60,14 +60,14 @@ if ($self_edit) { echo '
-
+
{[ "type": "password", "label": "'.tr('Password').'", "name": "password1", "required": 1, "value": "" ]}
'; echo '
-
+
{[ "type": "password", "label": "'.tr('Ripeti la password').'", "name": "password2", "value": "" ]}
'; diff --git a/src/HTMLBuilder/Wrapper/HTMLWrapper.php b/src/HTMLBuilder/Wrapper/HTMLWrapper.php index 6c494a042..c6092ef04 100644 --- a/src/HTMLBuilder/Wrapper/HTMLWrapper.php +++ b/src/HTMLBuilder/Wrapper/HTMLWrapper.php @@ -118,28 +118,43 @@ class HTMLWrapper implements WrapperInterface { $result = null; - $choices = [ - [ - 'id' => 'UNT', - 'descrizione' => tr('€'), - ], - [ - 'id' => 'PRC', - 'descrizione' => '%', - ], - ]; - $pieces = explode('|', $string); - $type = $pieces[1]; - $value = (empty($pieces[2]) || !in_array($pieces[2], array_column($choices, 'id'))) ? 'UNT' : $pieces[2]; if ($type == 'untprc') { - $result = '{[ "type": "select", "name": "tipo_'.prepareToField($values['name']).'", "value": "'.prepareToField($value).'", "values": '.json_encode($choices).', "class": "no-search" ]}'; - - $result = \HTMLBuilder\HTMLBuilder::replace($result); + $choices = [ + [ + 'id' => 'UNT', + 'descrizione' => tr('€'), + ], + [ + 'id' => 'PRC', + 'descrizione' => '%', + ], + ]; + } elseif ($type == 'email') { + $choices = [ + [ + 'id' => 'a', + 'descrizione' => tr('A').'     ', + ], + [ + 'id' => 'cc', + 'descrizione' => tr('CC').'  ', + ], + [ + 'id' => 'bcc', + 'descrizione' => tr('CCN'), + ], + ]; } + $value = (empty($pieces[2]) || !in_array($pieces[2], array_column($choices, 'id'))) ? $choices[0]['id'] : $pieces[2]; + + $result = '{[ "type": "select", "name": "tipo_'.prepareToField($values['name']).'", "value": "'.prepareToField($value).'", "values": '.json_encode($choices).', "class": "no-search" ]}'; + + $result = \HTMLBuilder\HTMLBuilder::replace($result); + return $result; } } diff --git a/src/Mail.php b/src/Mail.php index 8ef037928..81639867e 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -120,15 +120,18 @@ class Mail extends PHPMailer\PHPMailer\PHPMailer * * @return array */ - public static function getTemplateVariables($template) + public static function getTemplateVariables($template, $id_record) { $template = self::getTemplate($template); $module = Modules::get($template['id_module']); - $directory = DOCROOT.'/modules/'.$module['directory'].'|custom|/variables.php'; + $file = DOCROOT.'/modules/'.$module['directory'].'|custom|/variables.php'; - $original_file = str_replace('|custom|', '', $directory).'form.php'; - $custom_file = str_replace('|custom|', '/custom', $directory).'form.php'; + $original_file = str_replace('|custom|', '', $file); + $custom_file = str_replace('|custom|', '/custom', $file); + + $database = Database::getConnection(); + $dbo = $database; // Lettura delle variabili nei singoli moduli if (file_exists($custom_file)) {