ALTER TABLE `an_User`
    ADD `firstName` varchar(255) NOT NULL AFTER `id`,
    ADD `lastName` varchar(255) NOT NULL AFTER `firstName`;

UPDATE `an_User` SET `firstName` = `name`;

UPDATE `an_User`
SET `firstName` = SUBSTRING(`name`, 1, LOCATE(' ', `name`) - 1),
  `lastName`  = SUBSTRING(`name`, LOCATE(' ', `name`) + 1)
WHERE LOCATE(' ', `name`) > 0;

ALTER TABLE `an_User` DROP `name`;

--

UPDATE `an_Settings`SET `sorter` = 750 WHERE `name` = 'certificatePdfHeader' LIMIT 1;
UPDATE `an_Settings`SET `sorter` = 751 WHERE `name` = 'certificatePdfTitle' LIMIT 1;
UPDATE `an_Settings`SET `sorter` = 752 WHERE `name` = 'certificatePdfSubtitle' LIMIT 1;
UPDATE `an_Settings`SET `sorter` = 753 WHERE `name` = 'certificatePdfName' LIMIT 1;
UPDATE `an_Settings`SET `sorter` = 754 WHERE `name` = 'certificatePdfCongratulations' LIMIT 1;
UPDATE `an_Settings`SET `sorter` = 755 WHERE `name` = 'certificatePdfSignature' LIMIT 1;

INSERT INTO `an_Settings` (`name`, `idCategory`, `fieldType`, `label`, `value`, `options`, `description`, `required`, `system`, `sorter`, `added`, `changed`) VALUES
('userCertificateFailAdminEmailHeader', 6, 'header', 'Training Failed (Admin Notification)', '', '', '', 'n', 'n', 20, '2016-03-11 17:25:00', '2016-03-11 17:25:00'),
('userCertificateFailAdminEmailSubject', 6, 'text', 'Subject', 'Training has been failed', '', '', 'y', 'n', 21, '2016-03-11 17:25:00', '2016-03-11 17:25:00'),
('userCertificateFailAdminEmailFrom', 6, 'text', 'From Email Address &nbsp; <span class="label_description">If you leave this field empty - the From Email Address will be the same as the one in General Settings.</span>', '', '', '', 'n', 'n', 22, '2016-03-11 17:25:00', '2016-03-11 17:25:00'),
('userCertificateFailAdminEmailTo', 6, 'emails', 'To Email Address(es) &nbsp; <span class="label_description">If you leave this field empty - the From Email Address will be the same as the one in General Settings.</span>', '', '', 'Use commas to separate email addresses', 'n', 'n', 23, '2016-03-11 17:25:00', '2016-03-11 17:25:00'),
('userCertificateFailAdminEmailBody', 6, 'htmlEditor', 'Message Body', '<p>User, <a target="_blank" href="mailto:{email}">{name}</a> has failed test {test}.</p>\r\n\r\n<p>Click <a href="{link}">here</a> to view details.</p>\r\n\r\n<p>Have a nice day.</p>\r\n\r\n<p>&nbsp;</p>\r\n', '', 'Constants: {name} {email} {company} {address} {test} {link}', 'y', 'n', 24, '2016-03-11 17:25:00', '2016-03-11 17:25:00');

INSERT INTO `an_SettingsOptions` (`id`, `name`, `variable`, `value`, `type`, `sorter`) VALUES
(NULL, 'userCertificateFailAdminEmailBody', 'mode', 'view', 'string', NULL);


--

UPDATE `an_Settings` SET `value` = 'Certificate of Training Completion' WHERE `name` = 'certificatePdfTitle' LIMIT 1;
UPDATE `an_Settings` SET `value` = '<span style="text-decoration: overline;">Betsy Brock, Program Director</span>' WHERE `name` = 'certificatePdfSignature' LIMIT 1;

DELETE FROM `an_Settings` WHERE `name` = 'certificatePdfSubtitle' LIMIT 1;
DELETE FROM `an_Settings` WHERE `name` = 'certificatePdfName' LIMIT 1;

-- Manually update Training title: Complying With the Law When Selling Tobacco
