-- zjednotenie podpisov odosielanych sprav SMS a email
\encoding UTF8

BEGIN;

INSERT INTO message_layout (name, sysname, medium, content)
VALUES
('HTML e-mail s podpisom firmy','html-email-company',1,
'{$body|noescape}

<p>S pozdravom,</p>
<p>{$sender->data[name]}</p>'
),
('Plaintext e-mail s podpisom firmy','plaintext-email-company',1,
'{$body|noescape}

S pozdravom,
{$sender->data[name]}'
),
('SMS s podpisom firmy','sms-company',3,
'{$body|noescape} ({$sender->data[name]})'
);

UPDATE message_template_variant SET layout=(SELECT id FROM message_layout WHERE sysname='sms-company'),
body=REPLACE(body, '({$sender->data[name]})', '') WHERE layout=2 AND POSITION('({$sender->data[name]})' IN body)::BOOLEAN;

UPDATE message_template_variant SET layout=(SELECT id FROM message_layout WHERE sysname='sms-company')
WHERE layout=2 AND id IN (1,3,21,23,25,28);

UPDATE message_template_variant SET layout=(SELECT id FROM message_layout WHERE sysname='html-email-company'),
body=REPLACE(body, '\r
<p>S pozdravom,</p>\r
<p>{$sender->data[name]}', '') WHERE layout=1 AND POSITION('\r
<p>S pozdravom,</p>\r
<p>{$sender->data[name]}' IN body)::BOOLEAN;

UPDATE message_template_variant SET layout=(SELECT id FROM message_layout WHERE sysname='html-email-company'),
body=REPLACE(body, '
<p>S pozdravom,</p>
<p>{$sender->data[name]}', '') WHERE layout=1 AND POSITION('
<p>S pozdravom,</p>
<p>{$sender->data[name]}' IN body)::BOOLEAN;

UPDATE message_template_variant SET layout=(SELECT id FROM message_layout WHERE sysname='plaintext-email-company'),
body=REPLACE(body, '\r
S pozdravom,\r
{$sender->data[name]}', '') WHERE layout=1 AND POSITION('\r
S pozdravom,\r
{$sender->data[name]}' IN body)::BOOLEAN;

COMMIT;
