2018-02-20 17:57:16 +01:00
< ? php
include_once __DIR__ . '/core.php' ;
$template = Mail :: getTemplate ( $get [ 'id' ]);
$module = Modules :: get ( $id_module );
2018-02-21 17:47:43 +01:00
$smtp = Mail :: get ( $template [ 'id_smtp' ]);
2018-02-20 17:57:16 +01:00
$body = $template [ 'body' ];
$subject = $template [ 'subject' ];
2018-02-21 17:47:43 +01:00
$variables = Mail :: getTemplateVariables ( $template [ 'id' ], $id_record );
2018-02-20 17:57:16 +01:00
$email = $variables [ 'email' ];
2018-02-21 17:47:43 +01:00
// 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 );
2018-04-03 15:15:15 +02:00
//Campi mancanti
$rs2 = $dbo -> fetchArray ( 'SELECT from_address, server, port FROM zz_smtp WHERE id=' . prepare ( $template [ 'id_smtp' ]));
$campi_mancanti = [];
if ( $rs2 [ 0 ][ 'from_address' ] == '' ) {
array_push ( $campi_mancanti , 'Mittente' );
}
if ( $rs2 [ 0 ][ 'server' ] == '' ) {
array_push ( $campi_mancanti , 'Server SMTP' );
}
if ( $rs2 [ 0 ][ 'port' ] == '' ) {
array_push ( $campi_mancanti , 'Porta' );
}
if ( sizeof ( $campi_mancanti ) > 0 ) {
echo " <div class='alert alert-warning'><i class='fa fa-warning'></i> Prima di procedere all'invio completa: <b> " . implode ( ', ' , $campi_mancanti ) . ' </ b >< br />
'.Modules::link(' Gestione email ', $template[' id_smtp '], tr(' Vai alla scheda account email '), null).' </ div > ' ;
}
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 " >
< input type = " hidden " name = " backto " value = " record-edit " >
< 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-02-21 17:47:43 +01:00
if ( ! empty ( $smtp [ 'cc' ])) {
echo '
< p >< b > '.tr(' CC ').' </ b >: '.$smtp[' cc '].' </ p > ' ;
}
2018-02-20 17:57:16 +01:00
2018-02-21 17:47:43 +01:00
if ( ! empty ( $smtp [ 'cc' ])) {
2018-02-20 17:57:16 +01:00
echo '
2018-02-21 17:47:43 +01:00
< p >< b > '.tr(' CCN ').' </ b >: '.$smtp[' 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-02-21 17:47:43 +01:00
{[ " type " : " checkbox " , " label " : " '.tr('Notifica di lettura').' " , " name " : " read_notify " , " value " : " '. $template['read_notify'] .' " ]}
</ div >
</ div > ' ;
2018-02-20 17:57:16 +01:00
2018-02-21 17:47:43 +01:00
// 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' );
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 " >
{[ " 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 ).' " ]}
</ div > ' ;
2018-02-20 17:57:16 +01:00
2018-02-21 17:47:43 +01:00
// Allegati
echo '
< div class = " col-md-6 " >
{[ " 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' ) \ " ]}
</ 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 " >
{[ " type " : " textarea " , " 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 src = " '. $rootdir .'/assets/dist/js/ckeditor/ckeditor.js " ></ script > ' ;
echo '
< script >
2018-02-21 17:47:43 +01:00
var emails = [];
2018-02-20 17:57:16 +01:00
$ ( document ) . ready ( function (){
2018-02-21 17:47:43 +01:00
// Autocompletamento destinatario
$ ( document ) . load ( globals . rootdir + " /ajax_complete.php?module=Anagrafiche&op=get_email&id_anagrafica='. $variables['id_anagrafica'] .' " , function ( response ) {
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-02-21 17:47:43 +01:00
});
});
2018-02-23 09:49:31 +01:00
CKEDITOR . replace ( " body " , {
2018-03-07 23:50:28 +01:00
toolbar : globals . ckeditorToolbar ,
language : globals . locale ,
scayt_autoStartup : true ,
scayt_sLang : globals . scayt_sLang
2018-02-23 09:49:31 +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 ();
if ( last . val ()){
$ ( " #destinatari_input " ) . find ( " .select2 " ) . remove ()
$ ( " #lista-destinatari " ) . append ( $ ( " #destinatari_input " ) . html ());
$ ( " .destinatari " ) . each ( function (){
$ ( this ) . autocomplete ({ source : emails });
});
start_superselect ();
}
}
2018-02-20 17:57:16 +01:00
</ script > ' ;
echo '
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;