. */ use Modules\Emails\Template; include_once __DIR__.'/core.php'; $template = Template::find(get('id')); $module = $template->module; $smtp = $template->account; $body = $module->replacePlaceholders($id_record, $template['body']); $subject = $module->replacePlaceholders($id_record, $template['subject']); $emails = []; if ($module->replacePlaceholders($id_record, '{email}')) { $emails = explode(';', $module->replacePlaceholders($id_record, '{email}')); } $id_anagrafica = $module->replacePlaceholders($id_record, '{id_anagrafica}'); // 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; } } } // 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" ]}
'; $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')\"]}
"; echo '
{[ "type": "editor", "label": "'.tr('Contenuto').'", "name": "body", "id": "body_'.rand(0, 999).'", "value": '.json_encode($body).' ]}
'; echo '
'; echo ' '; echo ' '; echo ' ';