From 60612585b117e30e1b00c2b55ee4c67b18d961ff Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 22 Sep 2017 12:31:06 +0200 Subject: [PATCH] Introduzione della gestione dei template per le email --- modules/anagrafiche/edit.php | 3 +- modules/emails/actions.php | 41 +++++++++++++++++ modules/emails/add.php | 31 +++++++++++++ modules/emails/edit.php | 87 ++++++++++++++++++++++++++++++++++++ modules/emails/init.php | 5 +++ update/2_3_1.sql | 58 +++++++++++++++++++++++- 6 files changed, 222 insertions(+), 3 deletions(-) create mode 100644 modules/emails/actions.php create mode 100644 modules/emails/add.php create mode 100644 modules/emails/edit.php create mode 100644 modules/emails/init.php diff --git a/modules/anagrafiche/edit.php b/modules/anagrafiche/edit.php index 591881261..6ca0555e7 100644 --- a/modules/anagrafiche/edit.php +++ b/modules/anagrafiche/edit.php @@ -24,7 +24,8 @@ if (!$cliente) { } -?>
+?> + diff --git a/modules/emails/actions.php b/modules/emails/actions.php new file mode 100644 index 000000000..2be2da36c --- /dev/null +++ b/modules/emails/actions.php @@ -0,0 +1,41 @@ +insert('zz_emails', [ + 'name' => $post['name'], + 'id_module' => $post['module'], + 'subject' => $post['subject'], + ]); + + $id_record = $dbo->last_inserted_id(); + + $_SESSION['infos'][] = tr('Aggiunto nuovo template per le email!'); + + break; + + case 'update': + $dbo->update('zz_emails', [ + 'name' => $post['name'], + 'icon' => $post['icon'], + 'subject' => $post['subject'], + 'reply_to' => $post['reply_to'], + 'cc' => $post['cc'], + 'bcc' => $post['bcc'], + 'body' => $_POST['body'],// $post['body'], + 'read_notify' => $post['read_notify'], + ], ['id' => $id_record]); + + $_SESSION['infos'][] = tr('Informazioni salvate correttamente!'); + + break; + + case 'delete': + $dbo->query('UPDATE zz_emails SET deleted = 1 WHERE id='.prepare($id_record)); + + $_SESSION['infos'][] = tr('Template delle email eliminato!'); + + break; +} diff --git a/modules/emails/add.php b/modules/emails/add.php new file mode 100644 index 000000000..0d1e911db --- /dev/null +++ b/modules/emails/add.php @@ -0,0 +1,31 @@ + + + + +
+
+ {[ "type": "text", "label": "", "name": "name", "required": 1 ]} +
+
+ +
+
+ {[ "type": "select", "label": "", "name": "module", "values": "query=SELECT id, title AS descrizione FROM zz_modules WHERE enabled = 1" ]} +
+ +
+ {[ "type": "text", "label": "", "name": "subject" ]} +
+
+ + +
+
+ +
+
+
diff --git a/modules/emails/edit.php b/modules/emails/edit.php new file mode 100644 index 000000000..3a132aa3e --- /dev/null +++ b/modules/emails/edit.php @@ -0,0 +1,87 @@ +'; + +?> +
+ + + + +
+
+

+
+ +
+
+ +
+

+ +
+
+ {[ "type": "text", "label": "", "name": "name", "value": "$name$", "required": 1 ]} +
+ +
+ {[ "type": "span", "label": "", "name": "module", "values": "query=SELECT id, title AS descrizione FROM zz_modules WHERE enabled = 1", "value": "" ]} +
+ +
+ {[ "type": "checkbox", "label": "", "name": "read_notify", "value": "$read_notify$", "placeholder": "" ]} +
+
+ +
+
+ {[ "type": "email", "label": "", "name": "subject", "value": "$subject$" ]} +
+ +
+ {[ "type": "text", "label": "", "name": "icon", "value": "$icon$" ]} +
+
+ +
+
+ {[ "type": "text", "label": "", "name": "cc", "value": "$cc$" ]} +
+ +
+ {[ "type": "text", "label": "", "name": "port", "value": "$bcc$" ]} +
+ +
+ {[ "type": "text", "label": "", "name": "reply_to", "value": "$reply_to$" ]} +
+
+ +
+
+ {[ "type": "textarea", "label": "", "name": "body", "value": "$body$" ]} +
+
+ +
+
+ +
+ + + + + + diff --git a/modules/emails/init.php b/modules/emails/init.php new file mode 100644 index 000000000..a78bbadab --- /dev/null +++ b/modules/emails/init.php @@ -0,0 +1,5 @@ +fetchArray("SELECT * FROM zz_emails WHERE id=".prepare($id_record)." AND deleted = 0"); +} diff --git a/update/2_3_1.sql b/update/2_3_1.sql index 0957e826e..f12b1c251 100644 --- a/update/2_3_1.sql +++ b/update/2_3_1.sql @@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS `zz_prints` ( `directory` varchar(50) NOT NULL, `previous` varchar(50) NOT NULL, `options` text NOT NULL, - `icon` varchar(255) NOT NULL, + `icon` varchar(50) NOT NULL, `version` varchar(15) NOT NULL, `compatibility` varchar(1000) NOT NULL, `order` int(11) NOT NULL, @@ -86,11 +86,65 @@ CREATE TABLE IF NOT EXISTS `zz_smtp` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB; +-- +-- Struttura della tabella `zz_emails` +-- + +CREATE TABLE IF NOT EXISTS `zz_emails` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `id_module` int(11) NOT NULL, + `name` varchar(255) NOT NULL, + `icon` varchar(50) NOT NULL, + `subject` varchar(255) NOT NULL, + `reply_to` varchar(255) NOT NULL, + `cc` varchar(255) NOT NULL, + `bcc` varchar(255) NOT NULL, + `body` text NOT NULL, + `read_notify` tinyint(1) NOT NULL, + `deleted` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB; + +-- +-- Struttura della tabella `zz_email_smtp_user` +-- + +CREATE TABLE IF NOT EXISTS `zz_email_smtp_user` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `id_email` int(11) NOT NULL, + `id_smtp` int(11) NOT NULL, + `id_user` int(11) NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_email`) REFERENCES `zz_emails`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`id_smtp`) REFERENCES `zz_smtp`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`id_user`) REFERENCES `zz_users`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB; + +-- +-- Struttura della tabella `zz_emails` +-- + +CREATE TABLE IF NOT EXISTS `zz_email_print` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `id_email` int(11) NOT NULL, + `id_print` int(11) NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_email`) REFERENCES `zz_emails`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`id_print`) REFERENCES `zz_prints`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB; + +-- Aggiunta dei moduli dedicati alla gestione delle email INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Account email', 'Account email', 'smtp', 'SELECT |select| FROM zz_smtp WHERE 1=1 AND deleted = 0 HAVING 2=2 ORDER BY `name`', 'fa fa-envelope', '2.3', '2.3', '10', NULL, 1, 1); +INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Template email', 'Template email', 'emails', 'SELECT |select| FROM zz_emails WHERE 1=1 AND deleted = 0 HAVING 2=2 ORDER BY `name`', 'fa fa-pencil-square-o', '2.3', '2.3', '10', NULL, 1, 1); INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, `enabled`, `default`) VALUES ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Account email'), 'id', 'id', 1, 1, 0, 0, 1), ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Account email'), '#', 'id', 2, 1, 0, 1, 1), ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Account email'), 'Nome account', 'name', 3, 1, 0, 1, 1), ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Account email'), 'Nome visualizzato', 'from_name', 4, 1, 0, 1, 1), -((SELECT `id` FROM `zz_modules` WHERE `name` = 'Account email'), 'Email mittente', 'from_address', 5, 1, 0, 1, 1); +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Account email'), 'Email mittente', 'from_address', 5, 1, 0, 1, 1), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Template email'), 'id', 'id', 1, 1, 0, 0, 1), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Template email'), '#', 'id', 2, 1, 0, 1, 1), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Template email'), 'Nome', 'name', 3, 1, 0, 1, 1), +((SELECT `id` FROM `zz_modules` WHERE `name` = 'Template email'), 'Oggetto', 'subject', 4, 1, 0, 1, 1);