2019-08-27 17:25:52 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
2019-08-27 17:25:52 +02:00
2021-07-16 10:44:20 +02:00
use Modules\Emails\Template ;
2019-08-27 17:25:52 +02:00
include_once __DIR__ . '/../../core.php' ;
2021-08-03 14:59:42 +02:00
// Controllo se il template è ancora attivo
2021-07-20 10:01:59 +02:00
if ( empty ( $template )) {
2021-07-16 10:44:20 +02:00
echo '
2021-08-02 18:27:28 +02:00
< div class = " alert alert-danger " > '.tr(' ATTENZIONE ! Questa newsletter risulta collegata ad un template non più presente a sistema ').' </ div > ' ;
2021-07-16 10:44:20 +02:00
}
2019-08-27 17:25:52 +02:00
$block_edit = $newsletter -> state != 'DEV' ;
$stati = [
[
'id' => 'DEV' ,
'text' => 'Bozza' ,
],
[
'id' => 'WAIT' ,
'text' => 'Invio in corso' ,
],
[
'id' => 'OK' ,
'text' => 'Completata' ,
],
];
echo '
< form action = " " method = " post " id = " edit-form " >
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " op " value = " update " >
<!-- DATI -->
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Dati campagna ').' </ h3 >
2019-08-27 17:25:52 +02:00
</ div >
2020-09-07 15:04:06 +02:00
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2019-08-27 17:25:52 +02:00
< div class = " row " >
< div class = " col-md-6 " >
2021-05-31 16:54:48 +02:00
'.Modules::link(' Template email ', $record[' id_template '], null, null, ' class = " pull-right " ').'
2024-04-18 17:44:05 +02:00
{[ " type " : " select " , " label " : " '.tr('Template email').' " , " name " : " id_template " , " values " : " query=SELECT `em_templates`.`id`, `em_templates_lang`.`title` AS descrizione FROM `em_templates` LEFT JOIN `em_templates_lang` ON (`em_templates`.`id` = `em_templates_lang`.`id_record` AND `em_templates_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') WHERE `deleted_at` IS NULL ORDER BY `title` " , " required " : 1 , " value " : " $id_template $ " , " readonly " : 1 ]}
2019-08-27 17:25:52 +02:00
</ div >
2020-09-07 15:04:06 +02:00
2019-08-27 17:25:52 +02:00
< div class = " col-md-6 " >
2024-04-19 16:44:08 +02:00
{[ " type " : " text " , " label " : " '.tr('Nome').' " , " name " : " name " , " required " : 1 , " value " : " $title $ " ]}
2019-08-27 17:25:52 +02:00
</ div >
</ div >
2020-09-07 15:04:06 +02:00
2019-08-27 17:25:52 +02:00
< div class = " row " >
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " state " , " values " : '.json_encode($stati).' , " required " : 1 , " value " : " $state $ " , " class " : " unblockable " ]}
</ div >
2020-09-07 15:04:06 +02:00
2019-08-27 17:25:52 +02:00
< div class = " col-md-6 " >
2021-05-31 16:54:48 +02:00
{[ " type " : " timestamp " , " label " : " '.tr('Data di completamento').' " , " name " : " completed_at " , " value " : " $completed_at $ " , " readonly " : 1 ]}
2019-08-27 17:25:52 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
{[ " type " : " text " , " label " : " '.tr('Oggetto').' " , " name " : " subject " , " value " : " $subject $ " ]}
</ div >
</ div >
2020-09-07 15:04:06 +02:00
2019-08-27 17:25:52 +02:00
< div class = " row " >
2023-08-04 14:54:28 +02:00
< div class = " col-md-12 " > ' ;
2024-01-15 15:30:45 +01:00
echo input ([
'type' => 'ckeditor' ,
2024-07-02 15:13:14 +02:00
'use_full_ckeditor' => 1 ,
2024-01-15 15:30:45 +01:00
'label' => tr ( 'Contenuto' ),
'name' => 'content' ,
'value' => $record [ 'content' ],
]);
echo '
2023-02-24 13:36:37 +01:00
</ div >
2019-08-27 17:25:52 +02:00
</ div >
2020-09-07 15:04:06 +02:00
2019-08-27 17:25:52 +02:00
</ div >
</ div >
</ form >
< form action = " " method = " post " id = " receivers-form " >
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " op " value = " add_receivers " >
2020-09-07 15:04:06 +02:00
2019-08-27 17:25:52 +02:00
<!-- Destinatari -->
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
< div class = " card-header " >
< h3 class = " card-title " > '.tr(' Aggiunta destinatari ').' </ h3 >
2019-08-27 17:25:52 +02:00
</ div >
2020-09-07 15:04:06 +02:00
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2019-08-27 17:25:52 +02:00
< div class = " row " >
2019-09-24 10:09:29 +02:00
< div class = " col-md-6 " >
2021-08-02 18:27:28 +02:00
{[ " type " : " select " , " label " : " '.tr('Destinatari').' " , " name " : " receivers[] " , " ajax-source " : " destinatari_newsletter " , " multiple " : 1 ]}
2019-08-27 17:25:52 +02:00
</ div >
2020-09-07 15:04:06 +02:00
2019-09-24 10:09:29 +02:00
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Lista').' " , " name " : " id_list " , " ajax-source " : " liste_newsletter " ]}
</ div >
</ div >
2020-09-07 15:04:06 +02:00
2019-09-24 10:09:29 +02:00
< div class = " row pull-right " >
< div class = " col-md-12 " >
2019-08-27 17:25:52 +02:00
< button type = " submit " class = " btn btn-primary " >
< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi ').'
</ button >
</ div >
2019-09-24 10:09:29 +02:00
</ div >
</ div >
</ div >
</ form >
< script >
$ ( document ) . ready ( function () {
$ ( " #receivers " ) . on ( " change " , function () {
if ( $ ( this ) . selectData ()) {
$ ( " #id_list " ) . attr ( " disabled " , true ) . addClass ( " disabled " )
} else {
$ ( " #id_list " ) . attr ( " disabled " , false ) . removeClass ( " disabled " )
}
})
2020-09-07 15:04:06 +02:00
2019-09-24 10:09:29 +02:00
$ ( " #id_list " ) . on ( " change " , function () {
if ( $ ( this ) . selectData ()) {
$ ( " #receivers " ) . attr ( " disabled " , true ) . addClass ( " disabled " )
} else {
$ ( " #receivers " ) . attr ( " disabled " , false ) . removeClass ( " disabled " )
}
})
})
</ script > ' ;
2019-08-27 17:25:52 +02:00
2021-08-03 14:59:42 +02:00
$numero_destinatari = $newsletter -> destinatari () -> count ();
$destinatari_senza_mail = $newsletter -> getNumeroDestinatariSenzaEmail ();
2019-09-24 10:09:29 +02:00
echo '
<!-- Destinatari -->
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " >
2019-09-24 10:09:29 +02:00
'.tr(' Destinatari ').'
2021-08-03 14:59:42 +02:00
< span > ( '.$numero_destinatari.' ) </ span >
2024-05-16 18:02:50 +02:00
< div class = " float-right d-none d-sm-inline " >
'.(($destinatari_senza_mail > 0) ? ' < span title = " '.tr('Indirizzi e-mail mancanti').' " class = " tip badge badge-danger clickable " > '.$destinatari_senza_mail.' </ span > ' : ' ' )
. '<span title="' . tr ( 'Indirizzi e-mail senza consenso per newsletter' ) . ' " class= " tip badge badge - warning clickable " id= " numero_consenso_disabilitato " ></span>
2021-08-03 14:59:42 +02:00
</ div >
2019-09-24 10:09:29 +02:00
</ h3 >
</ div >
2020-09-07 15:04:06 +02:00
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2021-08-03 14:59:42 +02:00
< table class = " table table-hover table-condensed table-bordered " id = " destinatari " >
2019-09-24 10:09:29 +02:00
< thead >
< tr >
2021-05-31 16:54:48 +02:00
< th > '.tr(' Ragione sociale ').' </ th >
< th > '.tr(' Tipo ').' </ th >
< th > '.tr(' Tipologia ').' </ th >
< th class = " text-center " > '.tr(' E - mail ').' </ th >
2019-09-24 10:09:29 +02:00
< th class = " text-center " > '.tr(' Data di invio ').' </ th >
2021-06-01 15:17:52 +02:00
< th class = " text-center " > '.tr(' Newsletter ').' </ th >
2019-09-24 10:09:29 +02:00
< th class = " text-center " width = " 60 " > #</th>
</ tr >
</ thead >
2021-06-01 17:22:27 +02:00
</ table >
2021-08-02 18:27:28 +02:00
< a class = " btn btn-danger ask pull-right " data - backto = " record-edit " data - op = " remove_all_receivers " >
< i class = " fa fa-trash " ></ i > '.tr(' Elimina tutti ').'
2021-08-03 14:59:42 +02:00
</ a >
2019-08-27 17:25:52 +02:00
</ div >
2019-09-24 10:09:29 +02:00
</ div >
2019-08-27 17:25:52 +02:00
2019-08-28 16:58:47 +02:00
{( " name " : " filelist_and_upload " , " id_module " : " $id_module $ " , " id_record " : " $id_record $ " )}
2019-08-27 17:25:52 +02:00
< a class = " btn btn-danger ask " data - backto = " record-list " >
< i class = " fa fa-trash " ></ i > '.tr(' Elimina ').'
</ a > ' ;
if ( $block_edit ) {
echo '
< script >
$ ( document ) . ready ( function () {
$ ( " #receivers " ) . parent () . hide ();
$ ( " #receivers-form .btn " ) . hide ();
2021-08-03 14:59:42 +02:00
});
2021-08-02 18:27:28 +02:00
</ script > ' ;
}
2021-08-03 14:59:42 +02:00
echo '
2021-08-02 18:27:28 +02:00
< script >
globals . newsletter = {
2021-08-03 14:59:42 +02:00
senza_consenso : " '. $newsletter->getNumeroDestinatariSenzaConsenso ().' " ,
table_url : " '. $structure->fileurl ('ajax/table.php').'?id_newsletter='. $id_record .' " ,
2021-08-02 18:27:28 +02:00
};
$ ( document ) . ready ( function () {
const senza_consenso = $ ( " #numero_consenso_disabilitato " );
if ( globals . newsletter . senza_consenso > 0 ) {
senza_consenso . text ( globals . newsletter . senza_consenso );
} else {
senza_consenso . hide ();
}
2021-08-03 14:59:42 +02:00
2021-08-05 12:21:34 +02:00
const table = $ ( " #destinatari " ) . DataTable ({
2021-08-03 14:59:42 +02:00
language : globals . translations . datatables ,
retrieve : true ,
ordering : false ,
searching : true ,
paging : true ,
order : [],
lengthChange : false ,
processing : true ,
serverSide : true ,
ajax : {
url : globals . newsletter . table_url ,
type : " GET " ,
dataSrc : " data " ,
},
searchDelay : 500 ,
pageLength : 50 ,
});
2021-08-05 12:21:34 +02:00
table . on ( " processing.dt " , function ( e , settings , processing ) {
if ( processing ) {
$ ( " #mini-loader " ) . show ();
} else {
$ ( " #mini-loader " ) . hide ();
}
});
2019-08-27 17:25:52 +02:00
});
2021-09-23 10:04:44 +02:00
function testInvio ( button ) {
const destinatario_id = $ ( button ) . data ( " id " );
const destinatario_type = $ ( button ) . data ( " type " );
const email = $ ( button ) . data ( " email " );
swal ({
2023-09-08 17:30:27 +02:00
title : " '.tr('Inviare la newsletter?').' " ,
html : ` '.tr("Vuoi effettuare un invio all' indirizzo _EMAIL_ ? " , ['_EMAIL_' => ' ${ email } ']).' '.tr( " L 'email non sarà registrata come inviata, e l' invio della newsletter non escluderà questo indirizzo se impostato come invio di test " ).'.<br><br>
{[ " type " : " checkbox " , " label " : " '.tr('Invio di test').' " , " name " : " test " ]} ` ,
2021-09-23 10:04:44 +02:00
type : " warning " ,
showCancelButton : true ,
confirmButtonText : " '.tr('Invia').' " ,
confirmButtonClass : " btn btn-lg btn-success " ,
}) . then ( function () {
const restore = buttonLoading ( button );
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " POST " ,
dataType : " JSON " ,
data : {
id_module : globals . id_module ,
id_record : globals . id_record ,
2023-09-08 17:30:27 +02:00
op : " send-line " ,
2021-09-23 10:04:44 +02:00
id : destinatario_id ,
type : destinatario_type ,
2023-09-08 17:30:27 +02:00
test : input ( " test " ) . get (),
2021-09-23 10:04:44 +02:00
},
success : function ( response ) {
buttonRestore ( button , restore );
if ( response . result ) {
swal ( " '.tr('Invio completato').' " , " " , " success " );
} else {
swal ( " '.tr('Invio fallito').' " , " " , " error " );
}
},
error : function () {
buttonRestore ( button , restore );
swal ( " '.tr('Errore').' " , " '.tr( " Errore durante l 'invio dell' email " ).' " , " error " );
}
});
});
}
2019-08-27 17:25:52 +02:00
</ script > ' ;