diff --git a/src/com_tjnotifications/admin/models/notification.php b/src/com_tjnotifications/admin/models/notification.php
index ca188d5f..785cbae0 100644
--- a/src/com_tjnotifications/admin/models/notification.php
+++ b/src/com_tjnotifications/admin/models/notification.php
@@ -232,4 +232,68 @@ public function getKeys($client)
return $existingKeys;
}
+
+ /**
+ * Method to get tag replacement count
+ *
+ * @param string $key Template key.
+ * @param string $client client.
+ *
+ * @return integer replacement tags count
+ *
+ * @since 1.0.4
+ */
+ public function getReplacementTagsCount($key, $client)
+ {
+ $db = JFactory::getDbo();
+ $query = $db->getQuery(true);
+ $query->select($db->quoteName('replacement_tags'));
+ $query->from($db->quoteName('#__tj_notification_templates'));
+ $query->where($db->quoteName('client') . ' = ' . $db->quote($client));
+ $query->where($db->quoteName('key') . ' = ' . $db->quote($key));
+ $db->setQuery($query);
+ $replacementTags = $db->loadResult();
+
+ return count(json_decode($replacementTags));
+ }
+
+ /**
+ * Method to replace tags if they are changed
+ *
+ * @param array $data template data
+ *
+ * @return void
+ *
+ * @since 1.0.4
+ */
+ public function updateReplacementTags($data)
+ {
+ if (!empty($data['replacement_tags']))
+ {
+ $replacementTags = json_encode($data['replacement_tags']);
+ }
+ else
+ {
+ return;
+ }
+
+ $db = JFactory::getDbo();
+ $query = $db->getQuery(true);
+
+ // Fields to update.
+ $fields = array(
+ $db->quoteName('replacement_tags') . ' = ' . $db->quote($replacementTags)
+ );
+
+ // Conditions for which records should be updated.
+ $conditions = array(
+ $db->quoteName('client') . ' = ' . $db->quote($data['client']),
+ $db->quoteName('key') . ' = ' . $db->quote($data['key'])
+ );
+
+ $query->update($db->quoteName('#__tj_notification_templates'))->set($fields)->where($conditions);
+ $db->setQuery($query);
+
+ $result = $db->execute();
+ }
}
diff --git a/src/com_tjnotifications/admin/sql/install.mysql.utf8.sql b/src/com_tjnotifications/admin/sql/install.mysql.utf8.sql
index 9cde85d2..322a03fa 100644
--- a/src/com_tjnotifications/admin/sql/install.mysql.utf8.sql
+++ b/src/com_tjnotifications/admin/sql/install.mysql.utf8.sql
@@ -2,10 +2,7 @@ CREATE TABLE IF NOT EXISTS `#__tj_notification_providers` (
`provider` varchar(100) NOT NULL,
`state` int(1) NOT NULL,
primary key(provider)
- )
- AUTO_INCREMENT =0
- DEFAULT CHARSET =utf8;
-
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS `#__tj_notification_templates` (
`id` int(11) NOT NULL AUTO_INCREMENT,
@@ -35,41 +32,15 @@ CREATE TABLE IF NOT EXISTS `#__tj_notification_templates` (
UNIQUE KEY `client_2` (`client`,`key`),
KEY `client` (`client`),
KEY `key` (`key`)
-)
- DEFAULT CHARSET=utf8
- AUTO_INCREMENT=0 ;
+) AUTO_INCREMENT=1 ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS `#__tj_notification_user_exclusions` (
`user_id` int(11) NOT NULL,
`client` varchar(100) NOT NULL,
`key` varchar(100) NOT NULL,
`provider` varchar(100) NOT NULL,
- KEY `client1` (`client`,`provider`,`key`),
+ KEY `client1` (`client`(100),`provider`(50),`key`(100)),
KEY `key` (`key`),
KEY `provider` (`provider`),
CONSTRAINT `#__tj_notification_user_exclusions_ibfk_1` FOREIGN KEY (`provider`) REFERENCES `#__tj_notification_providers` (`provider`)
-)
- DEFAULT CHARSET=utf8;
-
-CREATE TABLE IF NOT EXISTS `#__tj_notification_logs` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `key` varchar(100) NOT NULL,
- `client` varchar(100) NOT NULL,
- `provider` varchar(50) NOT NULL,
- `subject` varchar(250) NOT NULL,
- `title` varchar(100) NOT NULL,
- `body` text NOT NULL,
- `from` varchar(500) NOT NULL,
- `to` text NOT NULL,
- `cc` text NOT NULL,
- `bcc` text NOT NULL,
- `date` datetime NOT NULL,
- `state` tinyint(2) NOT NULL,
- `params` text NOT NULL,
- `priority`int(11) NOT NULL,
- `message` text NOT NULL,
- `category` text NOT NULL,
- PRIMARY KEY (`id`)
-)
- DEFAULT CHARSET=utf8
- AUTO_INCREMENT=0 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
diff --git a/src/com_tjnotifications/admin/sql/updates/mysql/1.0.5.sql b/src/com_tjnotifications/admin/sql/updates/mysql/1.0.5.sql
new file mode 100644
index 00000000..8c7f100e
--- /dev/null
+++ b/src/com_tjnotifications/admin/sql/updates/mysql/1.0.5.sql
@@ -0,0 +1,8 @@
+
+--
+-- Change table ENGINE;
+--
+
+ALTER TABLE `#__tj_notification_providers` ENGINE = InnoDB;
+ALTER TABLE `#__tj_notification_templates` ENGINE = InnoDB;
+ALTER TABLE `#__tj_notification_user_exclusions` ENGINE = InnoDB;
diff --git a/src/com_tjnotifications/admin/sql/updates/mysql/1.0.6.sql b/src/com_tjnotifications/admin/sql/updates/mysql/1.0.6.sql
new file mode 100644
index 00000000..c10ad94a
--- /dev/null
+++ b/src/com_tjnotifications/admin/sql/updates/mysql/1.0.6.sql
@@ -0,0 +1,3 @@
+----Change table Key;
+
+ALTER TABLE `#__tj_notification_user_exclusions` CHANGE KEY `client1` (`client`(100),`provider`(50),`key`(100));
diff --git a/src/com_tjnotifications/admin/views/notification/tmpl/edit.php b/src/com_tjnotifications/admin/views/notification/tmpl/edit.php
index e7b822f6..bf7421a9 100644
--- a/src/com_tjnotifications/admin/views/notification/tmpl/edit.php
+++ b/src/com_tjnotifications/admin/views/notification/tmpl/edit.php
@@ -4,7 +4,13 @@
defined('_JEXEC') or die;
JHtml::_('formbehavior.chosen','select');
JHtml::_('behavior.formvalidator');
+use Joomla\CMS\Language\Text;
+
$today= gmdate('Y-m-d');
+
+$options['relative'] = true;
+
+JHtml::_('script', 'com_tjnotifications/template.js', $options);
?>
diff --git a/src/com_tjnotifications/admin/views/notification/view.html.php b/src/com_tjnotifications/admin/views/notification/view.html.php
index dff5fa7e..8b008b68 100644
--- a/src/com_tjnotifications/admin/views/notification/view.html.php
+++ b/src/com_tjnotifications/admin/views/notification/view.html.php
@@ -83,6 +83,10 @@ protected function addToolBar()
JToolBarHelper::apply('notification.editSave', 'JTOOLBAR_APPLY');
JToolBarHelper::save('notification.saveClose', 'JTOOLBAR_SAVE');
JToolBarHelper::custom('notification.saveNew', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
+
+ // Add preview toolbar
+ JToolbarHelper::modal('templatePreview', 'icon-eye', 'COM_TJNOTIFICATIONS_TEMPLATE_PREVIEW');
+
JToolBarHelper::cancel('notification.cancel', 'JTOOLBAR_CANCEL');
}
diff --git a/src/com_tjnotifications/media/js/template.js b/src/com_tjnotifications/media/js/template.js
new file mode 100644
index 00000000..ffb289a8
--- /dev/null
+++ b/src/com_tjnotifications/media/js/template.js
@@ -0,0 +1,47 @@
+/**
+ * @package TJNotifications
+ * @subpackage com_tjnotifications
+ *
+ * @author Techjoomla
+ * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved.
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ */
+
+var template = {
+
+ previewTemplate: function () {
+
+ jQuery(document).on('click', 'button[data-target="#templatePreview"]', function () {
+
+ jQuery('#show-info').hide();
+
+ if (typeof tinyMCE != "undefined")
+ {
+ tinyMCE.execCommand('mceToggleEditor', false, 'jform_email_body');
+ }
+ else if (typeof CodeMirror != "undefined")
+ {
+ var editor = document.querySelector('.CodeMirror').CodeMirror;
+ jQuery('#jform_email_body').html(editor.getValue());
+ }
+ else
+ {
+ jQuery('#show-info').show();
+ }
+
+ jQuery('#previewTempl').empty();
+ jQuery('