2018-02-20 17:57:16 +01:00
< ? php
2019-08-29 10:25:14 +02:00
use Modules\Emails\Template ;
2019-08-26 18:02:05 +02:00
2018-02-20 17:57:16 +01:00
include_once __DIR__ . '/core.php' ;
2019-08-29 10:25:14 +02:00
$template = Template :: find ( get ( 'id' ));
2019-08-26 18:02:05 +02:00
$module = $template -> module ;
$smtp = $template -> account ;
2018-02-20 17:57:16 +01:00
$body = $template [ 'body' ];
$subject = $template [ 'subject' ];
2019-07-10 11:53:35 +02:00
$body = $module -> replacePlaceholders ( $id_record , $template [ 'body' ]);
$subject = $module -> replacePlaceholders ( $id_record , $template [ 'subject' ]);
2018-02-21 17:47:43 +01:00
2019-07-24 17:54:50 +02:00
$email = $module -> replacePlaceholders ( $id_record , '{email}' );
2019-09-12 16:14:38 +02:00
$id_anagrafica = $module -> replacePlaceholders ( $id_record , '{id_anagrafica}' );
2019-07-24 17:54:50 +02:00
2018-04-15 14:46:33 +02:00
// Campi mancanti
2018-04-03 15:15:15 +02:00
$campi_mancanti = [];
2018-04-15 14:46:33 +02:00
if ( empty ( $smtp [ 'from_address' ])) {
$campi_mancanti [] = tr ( 'Mittente' );
2018-04-03 15:15:15 +02:00
}
2018-04-15 14:46:33 +02:00
if ( empty ( $smtp [ 'server' ])) {
$campi_mancanti [] = tr ( 'Server SMTP' );
2018-04-03 15:15:15 +02:00
}
2018-04-15 14:46:33 +02:00
if ( empty ( $smtp [ 'port' ])) {
$campi_mancanti [] = tr ( 'Porta' );
2018-04-03 15:15:15 +02:00
}
2018-04-15 14:46:33 +02:00
2018-04-03 15:15:15 +02:00
if ( sizeof ( $campi_mancanti ) > 0 ) {
2018-07-10 17:07:27 +02:00
echo '
< div class = " alert alert-warning " >
< i class = " fa fa-warning " ></ i > '.tr("Prima di procedere all' invio completa : _VALUES_ " , [
'_VALUES_' => '<b>' . implode ( ', ' , $campi_mancanti ) . '</b>' ,
]) . ' < br />
'.Modules::link(' Account email ', $smtp[' id '], tr(' Vai alla scheda account email '), null).'
</ div > ' ;
2018-04-03 15:15:15 +02:00
}
2018-02-21 17:47:43 +01:00
// Form
2018-02-20 17:57:16 +01:00
echo '
2018-02-21 17:47:43 +01:00
< form action = " " method = " post " id = " email-form " >
2018-02-20 17:57:16 +01:00
< input type = " hidden " name = " op " value = " send-email " >
2019-09-11 18:11:19 +02:00
< input type = " hidden " name = " backto " value = " '.(get('back') ? get('back') : 'record-edit').' " >
< input type = " hidden " name = " id_module " value = " '. $id_module .' " >
< input type = " hidden " name = " id_record " value = " '. $id_record .' " >
2018-02-20 17:57:16 +01:00
< input type = " hidden " name = " template " value = " '. $template['id'] .' " >
2018-02-21 17:47:43 +01:00
< p >< b > '.tr(' Mittente ').' </ b >: '.$smtp[' from_name '].' & lt ; '.$smtp[' from_address '].' & gt ; </ p > ' ;
2018-02-20 17:57:16 +01:00
2018-07-10 16:50:23 +02:00
if ( ! empty ( $template [ 'cc' ])) {
2018-02-21 17:47:43 +01:00
echo '
2018-07-10 16:50:23 +02:00
< p >< b > '.tr(' CC ').' </ b >: '.$template[' cc '].' </ p > ' ;
2018-02-21 17:47:43 +01:00
}
2018-02-20 17:57:16 +01:00
2018-07-10 16:50:23 +02:00
if ( ! empty ( $template [ 'bcc' ])) {
2018-02-20 17:57:16 +01:00
echo '
2018-07-10 16:50:23 +02:00
< p >< b > '.tr(' CCN ').' </ b >: '.$template[' bcc '].' </ p > ' ;
2018-02-20 17:57:16 +01:00
}
echo '
2018-02-21 17:47:43 +01:00
< b > '.tr(' Destinatari ').' </ b >
< div class = " row " id = " lista-destinatari " >
< div class = " col-md-12 " >
{[ " type " : " email " , " name " : " destinatari[] " , " value " : " '. $email .' " , " icon-before " : " choice|email " , " extra " : " onkeyup= \ 'aggiungi_destinatario(); \ ' " , " class " : " destinatari " , " required " : 1 ]}
</ div >
</ div >
2018-02-20 17:57:16 +01:00
2018-02-21 17:47:43 +01:00
< br >
2018-02-20 17:57:16 +01:00
2018-02-21 17:47:43 +01:00
< div class = " row " >
< div class = " col-md-8 " >
{[ " type " : " text " , " label " : " '.tr('Oggetto').' " , " name " : " subject " , " value " : " '. $subject .' " , " required " : 1 ]}
2018-02-20 17:57:16 +01:00
</ div >
< div class = " col-md-4 " >
2018-12-28 00:04:41 +01:00
{[ " type " : " checkbox " , " label " : " '.tr('Richiedi notifica di lettura').' " , " name " : " read_notify " , " value " : " '. $template['read_notify'] .' " ]}
2018-02-21 17:47:43 +01:00
</ div >
</ div > ' ;
2018-02-20 17:57:16 +01:00
2018-02-21 17:47:43 +01:00
// Stampe
2019-08-29 10:25:14 +02:00
$selected_prints = $dbo -> fetchArray ( 'SELECT id_print FROM em_print_template WHERE id_template = ' . prepare ( $template [ 'id' ]));
2018-02-21 17:47:43 +01:00
$selected = array_column ( $selected_prints , 'id_print' );
2018-02-20 17:57:16 +01:00
2018-02-21 17:47:43 +01:00
echo '
2018-02-20 17:57:16 +01:00
2018-02-21 17:47:43 +01:00
< div class = " row " >
< div class = " col-md-6 " >
2018-05-30 12:09:08 +02:00
{[ " 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 " ]}
2018-02-21 17:47:43 +01:00
</ div > ' ;
2018-02-20 17:57:16 +01:00
2019-08-29 10:25:14 +02:00
$uploads = [];
2018-07-10 12:07:48 +02:00
if ( $template [ 'name' ] == 'Fattura Elettronica' ) {
2019-08-29 10:25:14 +02:00
$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' );
2018-07-10 12:07:48 +02:00
}
2018-02-21 17:47:43 +01:00
// Allegati
echo '
< div class = " col-md-6 " >
2019-08-29 10:25:14 +02:00
{[ " type " : " select " , " multiple " : " 1 " , " label " : " '.tr('Allegati').' " , " name " : " uploads[] " , " value " : " '.implode(',', $uploads ).' " , " 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' ) \ " ]}
2018-02-21 17:47:43 +01:00
</ div >
</ div > " ;
2018-02-20 17:57:16 +01:00
echo '
2018-02-21 17:47:43 +01:00
< div class = " row " >
< div class = " col-md-12 " >
2018-09-07 17:43:52 +02:00
{[ " type " : " ckeditor " , " label " : " '.tr('Contenuto').' " , " name " : " body " , " value " : '.json_encode($body).' ]}
2018-02-20 17:57:16 +01:00
</ div >
2018-02-21 17:47:43 +01:00
</ div > ' ;
2018-02-20 17:57:16 +01:00
2018-02-21 17:47:43 +01:00
echo '
2018-02-20 17:57:16 +01:00
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
2018-02-21 17:47:43 +01:00
< button type = " button " class = " btn btn-primary " onclick = " send() " >< i class = " fa fa-envelope " ></ i > '.tr(' Invia ').' </ button >
2018-02-20 17:57:16 +01:00
</ div >
</ div >
</ form > ' ;
2018-02-21 17:47:43 +01:00
echo '
< div id = " destinatari_input " class = " hide " >
< div class = " col-md-12 " >
{[ " type " : " email " , " name " : " destinatari[] " , " icon-before " : " choice|email|cc " , " extra " : " onkeyup= \ 'aggiungi_destinatario(); \ ' " , " class " : " destinatari " ]}
</ div >
</ div > ' ;
2018-02-20 17:57:16 +01:00
echo '
< script >
2018-02-21 17:47:43 +01:00
var emails = [];
2018-06-23 15:41:32 +02:00
$ ( document ) . ready ( function (){ ' ;
2018-02-21 17:47:43 +01:00
// Autocompletamento destinatario
2019-09-12 16:14:38 +02:00
if ( ! empty ( $id_anagrafica )) {
2018-06-23 15:41:32 +02:00
echo '
2019-09-12 16:14:38 +02:00
$ ( document ) . load ( globals . rootdir + " /ajax_complete.php?module=Anagrafiche&op=get_email&id_anagrafica='. $id_anagrafica .(( $smtp['pec'] ) ? '&type=pec' : '').' " , function ( response ) {
2018-02-21 17:47:43 +01:00
emails = JSON . parse ( response );
$ ( " .destinatari " ) . each ( function (){
2018-02-23 09:49:31 +01:00
$ ( this ) . autocomplete ({
source : emails ,
minLength : 0
}) . focus ( function () {
$ ( this ) . autocomplete ( " search " , $ ( this ) . val ())
2018-09-20 12:05:22 +02:00
});
2018-02-21 17:47:43 +01:00
});
2018-08-31 11:39:38 +02:00
2018-08-01 15:10:56 +02:00
aggiungi_destinatario ();
2018-06-23 15:41:32 +02:00
}); ' ;
}
echo '
2018-02-21 17:47:43 +01:00
2018-02-20 17:57:16 +01:00
});
2018-02-21 17:47:43 +01:00
function send (){
if ( $ ( " #email-form " ) . parsley () . validate () && confirm ( " Inviare e-mail? " )) {
$ ( " #email-form " ) . submit ();
}
}
function aggiungi_destinatario (){
var last = $ ( " #lista-destinatari input " ) . last ();
2019-07-26 17:40:52 +02:00
if ( last . val ()) {
cleanup_inputs ();
2018-02-21 17:47:43 +01:00
$ ( " #lista-destinatari " ) . append ( $ ( " #destinatari_input " ) . html ());
$ ( " .destinatari " ) . each ( function (){
$ ( this ) . autocomplete ({ source : emails });
});
2019-07-26 17:40:52 +02:00
restart_inputs ();
2018-02-21 17:47:43 +01:00
}
}
2018-02-20 17:57:16 +01:00
</ script > ' ;
echo '
2019-07-26 17:40:52 +02:00
< script > $ ( document ) . ready ( init ) </ script > ' ;