openstamanager/modules/newsletter/edit.php

200 lines
6.2 KiB
PHP
Raw Normal View History

2019-08-27 17:25:52 +02:00
<?php
2019-08-29 10:25:14 +02:00
use Modules\Emails\Mail;
2019-08-27 17:25:52 +02:00
include_once __DIR__.'/../../core.php';
$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 -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">'.tr('Dati campagna').'</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Template email').'", "name": "id_template", "values": "query=SELECT id, name AS descrizione FROM em_templates", "required": 1, "value": "$id_template$", "disabled": 1 ]}
</div>
<div class="col-md-6">
{[ "type": "text", "label": "'.tr('Nome').'", "name": "name", "required": 1, "value": "$name$" ]}
</div>
</div>
<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>
<div class="col-md-6">
2019-08-28 16:58:47 +02:00
{[ "type": "timestamp", "label": "'.tr('Data di completamento').'", "name": "completed_at", "value": "$completed_at$", "disabled": 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>
<div class="row">
<div class="col-md-12">
{[ "type": "ckeditor", "label": "'.tr('Contenuto').'", "name": "content", "value": "$content$" ]}
</div>
</div>
</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">
<!-- Destinatari -->
2019-09-24 10:09:29 +02:00
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">'.tr('Aggiunta destinatari').'</h3>
2019-08-27 17:25:52 +02:00
</div>
2019-09-24 10:09:29 +02:00
<div class="box-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">
2019-08-29 15:09:01 +02:00
{[ "type": "select", "label": "'.tr('Destinatari').'", "name": "receivers[]", "ajax-source": "anagrafiche_newsletter", "multiple": 1 ]}
2019-08-27 17:25:52 +02:00
</div>
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>
<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")
}
})
$("#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
$anagrafiche = $newsletter->anagrafiche;
2019-09-24 10:09:29 +02:00
echo '
<!-- Destinatari -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
'.tr('Destinatari').'
<span class="badge">'.$anagrafiche->count().'</span>
</h3>
</div>
<div class="panel-body">';
2019-08-27 17:25:52 +02:00
if (!$anagrafiche->isEmpty()) {
echo '
2019-09-24 10:09:29 +02:00
<table class="table table-hover table-condensed table-bordered">
<thead>
<tr>
<th>'.tr('Nome').'</th>
<th class="text-center">'.tr('Indirizzo').'</th>
<th class="text-center">'.tr('Data di invio').'</th>
<th class="text-center" width="60">#</th>
</tr>
</thead>
<tbody>';
2019-08-27 17:25:52 +02:00
foreach ($anagrafiche as $anagrafica) {
$mail_id = $anagrafica->pivot->id_email;
2019-08-28 16:58:47 +02:00
$mail = Mail::find($mail_id);
if (!empty($mail) && !empty($mail->sent_at)) {
$data = timestampFormat($mail->sent_at);
2019-08-27 17:25:52 +02:00
} else {
$data = tr('Non ancora inviata');
}
echo '
2019-09-24 10:09:29 +02:00
<tr '.(empty($anagrafica->email) ? 'class="bg-danger"' : '').'>
<td>'.Modules::link('Anagrafiche', $anagrafica->id, $anagrafica->ragione_sociale).'</td>
<td class="text-center">'.$anagrafica->email.'</td>
<td class="text-center">'.$data.'</td>
<td class="text-center">
<a class="btn btn-danger ask btn-sm" data-backto="record-edit" data-op="remove_receiver" data-id="'.$anagrafica->id.'">
<i class="fa fa-trash"></i>
</a>
</td>
</tr>';
2019-08-27 17:25:52 +02:00
}
echo '
2019-09-24 10:09:29 +02:00
</tbody>
</table>';
2019-08-27 17:25:52 +02:00
} else {
echo '
2019-09-24 10:09:29 +02:00
<p>'.tr('Nessuna anagrafica collegata alla campagna').'.</p>';
2019-08-27 17:25:52 +02:00
}
echo '
</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();
});
</script>';
}