openstamanager/modules/emails/actions.php

100 lines
4.0 KiB
PHP
Raw Normal View History

<?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/>.
*/
2024-03-07 14:52:41 +01:00
use Modules\Emails\Template;
include_once __DIR__.'/../../core.php';
switch (post('op')) {
case 'add':
2024-03-08 13:10:32 +01:00
$module = post('module');
2024-03-07 14:52:41 +01:00
$id_account = post('smtp');
$name = post('name');
$subject = post('subject');
2024-10-07 08:54:37 +02:00
$template = Template::build($module, $id_account, $name);
2024-03-08 13:10:32 +01:00
$id_record = $dbo->lastInsertedID();
2024-04-18 17:44:05 +02:00
$template->setTranslation('title', $name);
2024-03-26 16:06:18 +01:00
$template->setTranslation('subject', $subject);
2024-03-07 14:52:41 +01:00
$template->save();
2018-07-19 17:29:21 +02:00
flash()->info(tr('Aggiunto nuovo template per le email!'));
break;
case 'update':
2024-04-18 17:44:05 +02:00
$template->setTranslation('title', post('name'));
2024-03-07 14:52:41 +01:00
$template->id_account = post('smtp');
$template->icon = post('icon');
$template->tipo_reply_to = post('tipo_reply_to');
$template->reply_to = post('reply_to');
$template->cc = post('cc');
$template->bcc = post('bcc');
$template->read_notify = post('read_notify');
$template->note_aggiuntive = post('note_aggiuntive');
2024-03-26 16:06:18 +01:00
$template->setTranslation('subject', post('subject'));
$template->setTranslation('body', post('body'));
$template->type = post('type');
$template->indirizzi_proposti = post('indirizzi_proposti');
2024-09-20 10:34:38 +02:00
$template->enabled = post('enabled');
2024-03-07 14:52:41 +01:00
$template->save();
2024-02-28 09:38:04 +01:00
2024-04-12 16:25:04 +02:00
$prints[] = post('prints');
2024-04-23 09:56:36 +02:00
2024-04-12 16:25:04 +02:00
foreach ($prints as $print) {
if (!empty($print)) {
$dbo->sync('em_print_template', ['id_template' => $id_record], ['id_print' => $print]);
}
}
2024-04-12 16:25:04 +02:00
$mansioni[] = post('idmansioni');
foreach ($mansioni as $mansione) {
if (!empty($mansione)) {
$dbo->sync('em_mansioni_template', ['id_template' => $id_record], ['idmansione' => $mansione]);
}
}
2024-04-23 09:56:36 +02:00
2018-07-19 17:29:21 +02:00
flash()->info(tr('Informazioni salvate correttamente!'));
break;
case 'delete':
2024-02-28 09:38:04 +01:00
$dbo->query('UPDATE `em_templates` SET `deleted_at` = NOW() WHERE `id`='.prepare($id_record));
2018-07-19 17:29:21 +02:00
flash()->info(tr('Template delle email eliminato!'));
2021-04-20 16:25:20 +02:00
break;
case 'copy':
2024-02-28 09:38:04 +01:00
$database->beginTransaction();
$database->query('CREATE TEMPORARY TABLE `tmp` SELECT * FROM `em_templates` WHERE `id`= '.prepare($id_record));
$database->query('CREATE TEMPORARY TABLE `tmp_lang` SELECT * FROM `em_templates_lang` WHERE `id_record`= '.prepare($id_record));
$database->query('ALTER TABLE `tmp` DROP `id`');
$database->query('ALTER TABLE `tmp_lang` DROP `id_record`');
$database->query('INSERT INTO `em_templates` SELECT NULL,tmp. * FROM tmp');
$id_record = $database->lastInsertedID();
2024-05-21 10:48:53 +02:00
$database->query('INSERT INTO `em_templates_lang` SELECT NULL, `id_lang`, '.$id_record.', `title`, `subject`, `body`, NULL, NULL FROM tmp_lang');
2024-02-28 09:38:04 +01:00
$database->query('DROP TEMPORARY TABLE tmp');
$database->query('DROP TEMPORARY TABLE tmp_lang');
2024-04-18 17:44:05 +02:00
$database->query('UPDATE `em_templates_lang` SET `title` = CONCAT (`title`, " (copia)") WHERE id_record = '.prepare($id_record));
2024-02-28 09:38:04 +01:00
$database->query('UPDATE `em_templates` SET `predefined` = 0 WHERE `id` = '.prepare($id_record));
2021-04-20 16:25:20 +02:00
flash()->info(tr('Template duplicato correttamente!'));
break;
}