. */ use Modules\Emails\Template; include_once __DIR__.'/core.php'; $template = Template::find(get('id')); $module = $template->module; $smtp = $template->account; $placeholder_options = [ 'is_pec' => intval($smtp['pec']), ]; $body = $module->replacePlaceholders($id_record, $template['body'], $placeholder_options); $subject = $module->replacePlaceholders($id_record, $template['subject'], $placeholder_options); $emails = []; if ($module->replacePlaceholders($id_record, '{email}')) { $emails = explode(';', $module->replacePlaceholders($id_record, '{email}', $placeholder_options)); } $id_anagrafica = $module->replacePlaceholders($id_record, '{id_anagrafica}', $placeholder_options); // Aggiungo email referenti in base alla mansione impostata nel template $mansioni = $dbo->select('em_mansioni_template', 'idmansione', ['id_template' => $template->id]); foreach ($mansioni as $mansione) { $referenti = $dbo->table('an_referenti')->where('idmansione', $mansione['idmansione'])->where('idanagrafica', $id_anagrafica)->where('email', '!=', '')->get(); foreach ($referenti as $referente) { if (!in_array($referente->email, $emails)) { $emails[] = $referente->email; } } } // Aggiungo email tecnici assegnati quando sono sul template Notifica intervento if ($template->name == 'Notifica intervento') { $tecnici = $dbo->select('in_interventi_tecnici_assegnati', 'id_tecnico', ['id_intervento' => $id_record]); foreach ($tecnici as $tecnico) { $anagrafica = $dbo->table('an_anagrafiche')->where('idanagrafica', $tecnico['id_tecnico'])->where('email', '!=', '')->first(); if (!in_array($anagrafica->email, $emails)) { $emails[] = $anagrafica->email; } } } // Campi mancanti $campi_mancanti = []; if (empty($smtp['from_address'])) { $campi_mancanti[] = tr('Mittente'); } if (empty($smtp['server'])) { $campi_mancanti[] = tr('Server SMTP'); } if (empty($smtp['port'])) { $campi_mancanti[] = tr('Porta'); } if (sizeof($campi_mancanti) > 0) { echo '
'.tr("Prima di procedere all'invio completa: _VALUES_", [ '_VALUES_' => ''.implode(', ', $campi_mancanti).'', ]).'
'.Modules::link('Account email', $smtp['id'], tr('Vai alla scheda account email'), null).'
'; } // Form echo '

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

'; if (!empty($template['cc'])) { echo '

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

'; } if (!empty($template['bcc'])) { echo '

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

'; } echo ' '.tr('Destinatari').'
'; $idx = 0; foreach ($emails as $email) { echo '
{[ "type": "email", "name": "destinatari['.$idx++.']", "value": "'.$email.'", "icon-before": "choice|email", "extra": "onkeyup=\'aggiungiDestinatario();\'", "class": "destinatari", "required": 0 ]}
'; } if (empty($emails)) { echo '
{[ "type": "email", "name": "destinatari['.$idx++.']", "value": "", "icon-before": "choice|email", "extra": "onkeyup=\'aggiungiDestinatario();\'", "class": "destinatari", "required": 0 ]}
'; } echo '

{[ "type": "text", "label": "'.tr('Oggetto').'", "name": "subject", "value": "'.$subject.'", "required": 1 ]}
{[ "type": "checkbox", "label": "'.tr('Richiedi notifica di lettura').'", "name": "read_notify", "value": "'.$template['read_notify'].'" ]}
'; // Stampe $selected_prints = $dbo->fetchArray('SELECT id_print FROM em_print_template WHERE id_template = '.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).' AND enabled=1 AND is_record=1", "link": "stampa" ]}
'; $uploads = []; if ($smtp['pec'] == 1 && $module['name'] == 'Fatture di vendita') { $uploads = $dbo->fetchArray('SELECT id FROM zz_files WHERE id_module = '.prepare($module['id']).' AND id_record = '.prepare($id_record).' AND category = \'Fattura Elettronica\''); $uploads = array_column($uploads, 'id'); } // Allegati echo '
{[ "type": "select", "multiple": "1", "label": "'.tr('Allegati').'", "name": "uploads[]", "value": "'.implode(',', $uploads).'", "help": "'.tr('Allegati del documento o caricati nell\'anagrafica dell\'azienda.').'", "values": "query=SELECT id, name AS text FROM zz_files WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record).' UNION SELECT id, CONCAT(name, \' (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\')", "link": "allegato" ]}
'; echo '
'; echo input([ 'type' => 'ckeditor', 'use_full_ckeditor' => 1, 'label' => tr('Contenuto'), 'name' => 'body', 'id' => 'body_'.rand(0, 999), 'value' => $body, ]); echo '
'; echo '
'; echo ' '; echo ' '; echo ' ';