mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-23 14:57:46 +01:00
Aggiunta tabella em_templates_lang
This commit is contained in:
parent
6490ca640d
commit
0f8b68e7d6
@ -22,13 +22,16 @@ include_once __DIR__.'/../../core.php';
|
||||
switch (post('op')) {
|
||||
case 'add':
|
||||
$dbo->insert('em_templates', [
|
||||
'name' => post('name'),
|
||||
'id_module' => post('module'),
|
||||
'id_account' => post('smtp'),
|
||||
'subject' => post('subject'),
|
||||
]);
|
||||
|
||||
$id_record = $dbo->lastInsertedID();
|
||||
$dbo->insert('em_templates_lang', [
|
||||
'name' => post('name'),
|
||||
'subject' => post('subject'),
|
||||
'id_lang' => setting('Lingua'),
|
||||
'id_record' => $id_record
|
||||
]);
|
||||
|
||||
flash()->info(tr('Aggiunto nuovo template per le email!'));
|
||||
|
||||
@ -36,19 +39,22 @@ switch (post('op')) {
|
||||
|
||||
case 'update':
|
||||
$dbo->update('em_templates', [
|
||||
'name' => post('name'),
|
||||
'id_account' => post('smtp'),
|
||||
'icon' => post('icon'),
|
||||
'subject' => post('subject'),
|
||||
'tipo_reply_to' => post('tipo_reply_to'),
|
||||
'reply_to' => post('reply_to'),
|
||||
'cc' => post('cc'),
|
||||
'bcc' => post('bcc'),
|
||||
'body' => $_POST['body'], // post('body', true),
|
||||
'read_notify' => post('read_notify'),
|
||||
'note_aggiuntive' => post('note_aggiuntive'),
|
||||
'note_aggiuntive' => post('note_aggiuntive')
|
||||
], ['id' => $id_record]);
|
||||
|
||||
$dbo->update('em_templates_lang', [
|
||||
'name' => post('name'),
|
||||
'subject' => post('subject'),
|
||||
'body' => post('body')
|
||||
], ['id_record' => $id_record, 'id_lang' => (setting('Lingua'))]);
|
||||
|
||||
$dbo->sync('em_print_template', ['id_template' => $id_record], ['id_print' => (array) post('prints')]);
|
||||
$dbo->sync('em_mansioni_template', ['id_template' => $id_record], ['idmansione' => (array) post('idmansioni')]);
|
||||
|
||||
@ -57,22 +63,25 @@ switch (post('op')) {
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$dbo->query('UPDATE em_templates SET deleted_at = NOW() WHERE id='.prepare($id_record));
|
||||
$dbo->query('UPDATE `em_templates` SET `deleted_at` = NOW() WHERE `id`='.prepare($id_record));
|
||||
|
||||
flash()->info(tr('Template delle email eliminato!'));
|
||||
|
||||
break;
|
||||
|
||||
case 'copy':
|
||||
$dbo->query('CREATE TEMPORARY TABLE tmp SELECT * FROM em_templates WHERE id= '.prepare($id_record));
|
||||
$dbo->query('ALTER TABLE tmp DROP id');
|
||||
$dbo->query('INSERT INTO em_templates SELECT NULL,tmp. * FROM tmp');
|
||||
$id_record = $dbo->lastInsertedID();
|
||||
$dbo->query('DROP TEMPORARY TABLE tmp');
|
||||
|
||||
$dbo->query('UPDATE em_templates SET name = CONCAT (name, " (copia)"), predefined=0 WHERE id = '.prepare($id_record));
|
||||
|
||||
$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();
|
||||
$database->query('INSERT INTO `em_templates_lang` SELECT NULL, id_lang, '.$id_record.',name, subject, body FROM tmp_lang');
|
||||
$database->query('DROP TEMPORARY TABLE tmp');
|
||||
$database->query('DROP TEMPORARY TABLE tmp_lang');
|
||||
$database->query('UPDATE `em_templates_lang` SET `name` = CONCAT (`name`, " (copia)") WHERE id_record = '.prepare($id_record));
|
||||
$database->query('UPDATE `em_templates` SET `predefined` = 0 WHERE `id` = '.prepare($id_record));
|
||||
flash()->info(tr('Template duplicato correttamente!'));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ if (!$record['predefined']) {
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{[ "type": "span", "label": "<?php echo tr('Modulo del template'); ?>", "name": "module", "values": "query=SELECT id, title AS descrizione FROM zz_modules WHERE enabled = 1", "value": "<?php echo Modules::get($record['id_module'])['title']; ?>" ]}
|
||||
{[ "type": "span", "label": "<?php echo tr('Modulo del template'); ?>", "name": "module", "values": "query=SELECT `id`, `title` AS descrizione FROM `zz_modules` WHERE `enabled` = 1", "value": "<?php echo Modules::get($record['id_module'])['title']; ?>" ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -22,7 +22,7 @@ use Modules\Newsletter\Newsletter;
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
if (isset($id_record)) {
|
||||
$record = $dbo->fetchOne('SELECT * FROM em_templates WHERE id='.prepare($id_record).' AND deleted_at IS NULL');
|
||||
$record = $dbo->fetchOne('SELECT * FROM em_templates LEFT JOIN `em_templates_lang` ON (`em_templates`.`id` = `em_templates_lang`.`id_record` AND `em_templates_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `em_templates`.`id`='.prepare($id_record).' AND `deleted_at` IS NULL');
|
||||
|
||||
// Controllo se ci sono newletter collegate a questo template
|
||||
$newsletters = Newsletter::where('id_template', $id_record)->get();
|
||||
|
@ -60,4 +60,67 @@ class Template extends Model
|
||||
{
|
||||
return $this->belongsToMany(PrintTemplate::class, 'em_print_template', 'id_template', 'id_print');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ritorna l'attributo name del template.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return database()->table($this->table.'_lang')
|
||||
->select('name')
|
||||
->where('id_record', '=', $this->id)
|
||||
->where('id_lang', '=', setting('Lingua'))
|
||||
->first()->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ritorna l'attributo subject del template.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubjectAttribute()
|
||||
{
|
||||
return database()->table($this->table.'_lang')
|
||||
->select('subject')
|
||||
->where('id_record', '=', $this->id)
|
||||
->where('id_lang', '=', setting('Lingua'))
|
||||
->first()->subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ritorna l'attributo body del template.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBodyAttribute()
|
||||
{
|
||||
return database()->table($this->table.'_lang')
|
||||
->select('body')
|
||||
->where('id_record', '=', $this->id)
|
||||
->where('id_lang', '=', setting('Lingua'))
|
||||
->first()->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ritorna l'id del template a partire dal nome.
|
||||
*
|
||||
* @param string $name il nome da ricercare
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getByName($name)
|
||||
{
|
||||
return database()->table($this->table.'_lang')
|
||||
->select('id_record')
|
||||
->where('name', '=', $name)
|
||||
->where('id_lang', '=', setting('Lingua'))
|
||||
->first();
|
||||
}
|
||||
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(TemplateLang::class, 'id');
|
||||
}
|
||||
}
|
||||
|
32
modules/emails/src/TemplateLang.php
Normal file
32
modules/emails/src/TemplateLang.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/*
|
||||
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
||||
* Copyright (C) DevCode s.r.l.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
namespace Modules\Emails;
|
||||
|
||||
use Common\SimpleModelTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Traits\LocalPoolTrait;
|
||||
|
||||
class TemplateLang extends Model
|
||||
{
|
||||
use SimpleModelTrait;
|
||||
use LocalPoolTrait;
|
||||
|
||||
protected $table = 'em_templates_lang';
|
||||
}
|
@ -471,7 +471,7 @@ $operations['send-mail'] = [
|
||||
'data' => [
|
||||
'title' => tr('Inviare mail?'),
|
||||
'msg' => tr('Per ciascuna attività selezionata, verrà inviata una mail').'<br><br>
|
||||
{[ "type": "select", "label": "'.tr('Template').'", "name": "id_template", "required": "1", "values": "query=SELECT id, name AS descrizione FROM em_templates WHERE id_module='.prepare($id_module).' AND deleted_at IS NULL;" ]}',
|
||||
{[ "type": "select", "label": "'.tr('Template').'", "name": "id_template", "required": "1", "values": "query=SELECT `em_templates`.`id`, `em_templates_lang`.`name` 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(setting('Lingua')).') WHERE `id_module`='.prepare($id_module).' AND `deleted_at` IS NULL;" ]}',
|
||||
'button' => tr('Invia'),
|
||||
'class' => 'btn btn-lg btn-warning',
|
||||
],
|
||||
|
@ -26,7 +26,7 @@ echo '
|
||||
|
||||
<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 WHERE deleted_at IS NULL ORDER BY descrizione", "required": 1 ]}
|
||||
{[ "type": "select", "label": "'.tr('Template email').'", "name": "id_template", "values": "query=SELECT `em_templates`.`id`, `em_templates_lang`.`name` 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(setting('Lingua')).') WHERE `deleted_at` IS NULL ORDER BY `name`", "required": 1 ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
|
@ -59,7 +59,7 @@ echo '
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
'.Modules::link('Template email', $record['id_template'], null, null, 'class="pull-right"').'
|
||||
{[ "type": "select", "label": "'.tr('Template email').'", "name": "id_template", "values": "query=SELECT id, name AS descrizione FROM em_templates WHERE deleted_at IS NULL ORDER BY descrizione", "required": 1, "value": "$id_template$", "readonly": 1 ]}
|
||||
{[ "type": "select", "label": "'.tr('Template email').'", "name": "id_template", "values": "query=SELECT `em_templates`.`id`, `em_templates_lang`.`name` 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(setting('Lingua')).') WHERE `deleted_at` IS NULL ORDER BY `name`", "required": 1, "value": "$id_template$", "readonly": 1 ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
|
@ -216,7 +216,7 @@ $(document).ready(function() {
|
||||
|
||||
// Collegamenti diretti
|
||||
// Template email collegati a questo account
|
||||
$elementi = $dbo->fetchArray('SELECT `id`, `name` FROM `em_templates` WHERE `id_account` = '.prepare($id_record));
|
||||
$elementi = $dbo->fetchArray('SELECT `em_templates`.`id`, `em_templates_lang`.`name` FROM `em_templates` LEFT JOIN `em_templates_lang` ON (`em_templates`.`id` = `em_templates_lang`.`id_record` AND `em_templates_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_account` = '.prepare($id_record));
|
||||
|
||||
if (!empty($elementi)) {
|
||||
echo '
|
||||
|
@ -58,7 +58,7 @@ if ($record['can_delete']) {
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-6">
|
||||
{[ "type": "select", "label": "<?php echo tr('Template email'); ?>", "name": "email", "value": "$id_email$", "values": "query=SELECT id, name AS descrizione FROM em_templates WHERE id_module = <?php echo Modules::get('Interventi')['id']; ?> AND deleted_at IS NULL", "disabled": <?php echo intval(empty($record['notifica'])); ?> ]}
|
||||
{[ "type": "select", "label": "<?php echo tr('Template email'); ?>", "name": "email", "value": "$id_email$", "values": "query=SELECT `em_templates`.`id`, `em_templates_lang`.`name` 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` = <?php echo prepare(setting('Lingua')); ?>) WHERE `id_module` = <?php echo Modules::get('Interventi')['id']; ?> AND `deleted_at` IS NULL", "disabled": <?php echo intval(empty($record['notifica'])); ?> ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
|
@ -60,7 +60,7 @@ class ButtonManager implements ManagerInterface
|
||||
|
||||
$result = [
|
||||
'link' => base_path().'/mail.php?id_module='.$options['id_module'].'&id_record='.$options['id_record'].'&id='.$options['id'].$options['parameters'],
|
||||
'title' => tr('Invia').' '.((strtoupper($template_email['name']) == $template_email['name']) ? $template_email['name'] : lcfirst($template_email['name'])),
|
||||
'title' => tr('Invia').' '.((strtoupper($template_email->name) == $template_email->name) ? $template_email->name : lcfirst($template_email->name)),
|
||||
'icon' => $template_email['icon'],
|
||||
'type' => 'modal',
|
||||
];
|
||||
@ -118,7 +118,9 @@ class ButtonManager implements ManagerInterface
|
||||
if ($options['type'] == 'print') {
|
||||
$results = \Prints::getModulePrints($options['id_module']);
|
||||
} elseif ($options['type'] == 'email') {
|
||||
$results = TemplateEmail::where('id_module', $options['id_module'])->orderBy('name')->get()->toArray();
|
||||
$results = (TemplateEmail::where('id_module', $options['id_module']))->with(['translations' => function($query) {
|
||||
$query->orderBy('name');
|
||||
}])->get()->toArray();
|
||||
} elseif ($options['type'] == 'sms') {
|
||||
$results = TemplateSMS::where('id_module', $options['id_module'])->orderBy('name')->get()->toArray();
|
||||
}
|
||||
|
@ -1093,4 +1093,60 @@ HAVING
|
||||
2=2" WHERE `name` = 'Liste newsletter';
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`em_lists`.`id`' WHERE `zz_modules`.`name` = 'Liste newsletter' AND `zz_views`.`name` = 'id';
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`em_lists_lang`.`description`' WHERE `zz_modules`.`name` = 'Liste newsletter' AND `zz_views`.`name` = 'Descrizione';
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`em_lists_lang`.`name`' WHERE `zz_modules`.`name` = 'Liste newsletter' AND `zz_views`.`name` = 'Nome';
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`em_lists_lang`.`name`' WHERE `zz_modules`.`name` = 'Liste newsletter' AND `zz_views`.`name` = 'Nome';
|
||||
|
||||
-- Aggiunta tabella em_templates_lang
|
||||
CREATE TABLE IF NOT EXISTS `em_templates_lang` (
|
||||
`id` int NOT NULL,
|
||||
`id_lang` int NOT NULL,
|
||||
`id_record` int NOT NULL,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`subject` VARCHAR(255) NOT NULL,
|
||||
`body` TEXT NOT NULL
|
||||
);
|
||||
ALTER TABLE `em_templates_lang`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
ALTER TABLE `em_templates_lang`
|
||||
MODIFY `id` int NOT NULL AUTO_INCREMENT;
|
||||
|
||||
INSERT INTO `em_templates_lang` (`id`, `id_lang`, `id_record`, `name`, `subject`, `body`) SELECT NULL, (SELECT `id` FROM `zz_langs` WHERE `iso_code` = 'it'), `id`, `name`, `subject`, `body` FROM `em_templates`;
|
||||
|
||||
ALTER TABLE `em_templates`
|
||||
DROP `name`,
|
||||
DROP `subject`,
|
||||
DROP `body`;
|
||||
|
||||
ALTER TABLE `em_templates_lang` ADD CONSTRAINT `em_templates_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `em_templates`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;
|
||||
|
||||
-- Allineamento vista Template email
|
||||
UPDATE `zz_modules` SET `options` = "
|
||||
SELECT
|
||||
|select|
|
||||
FROM
|
||||
`em_templates`
|
||||
LEFT JOIN `em_templates_lang` ON (`em_templates_lang`.`id_record` = `em_templates`.`id` AND `em_templates_lang`.|lang|)
|
||||
INNER JOIN `zz_modules` on `zz_modules`.`id` = `em_templates`.`id_module`
|
||||
WHERE
|
||||
1=1 AND `deleted_at` IS NULL
|
||||
HAVING
|
||||
2=2
|
||||
ORDER BY
|
||||
`zz_modules`.`name`" WHERE `name` = 'Template email';
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`em_templates_lang`.`subject`' WHERE `zz_modules`.`name` = 'Template email' AND `zz_views`.`name` = 'Oggetto';
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`em_templates_lang`.`name`' WHERE `zz_modules`.`name` = 'Template email' AND `zz_views`.`name` = 'Nome';
|
||||
|
||||
-- Allineamento vista Newsletter
|
||||
UPDATE `zz_modules` SET `options` = "
|
||||
SELECT
|
||||
|select|
|
||||
FROM
|
||||
`em_newsletters`
|
||||
LEFT JOIN `em_templates` ON `em_newsletters`.`id_template` = `em_templates`.`id`
|
||||
LEFT JOIN `em_templates_lang` ON (`em_templates_lang`.`id_record` = `em_templates`.`id` AND `em_templates_lang`.|lang|)
|
||||
LEFT JOIN (SELECT `id_newsletter`, COUNT(*) AS totale FROM `em_newsletter_receiver` GROUP BY `id_newsletter`) AS riceventi ON `riceventi`.`id_newsletter` = `em_newsletters`.`id`
|
||||
WHERE
|
||||
1=1 AND `em_newsletters`.`deleted_at` IS NULL
|
||||
HAVING
|
||||
2=2" WHERE `name` = 'Newsletter';
|
||||
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`em_templates_lang`.`name`' WHERE `zz_modules`.`name` = 'Newsletter' AND `zz_views`.`name` = 'Template';
|
@ -79,6 +79,7 @@ return [
|
||||
'em_print_template',
|
||||
'em_accounts',
|
||||
'em_templates',
|
||||
'em_templates_lang',
|
||||
'em_newsletters',
|
||||
'em_mansioni_template',
|
||||
'em_lists',
|
||||
|
Loading…
x
Reference in New Issue
Block a user