INSERT INTO `pl_DPageItemType` (`id`, `type`, `title`, `sorter`) VALUES (NULL, 'User\\MembershipRenew\\', 'User Membership Renew', '0');

ALTER TABLE `pl_MembershipType` ADD `duration` INT NOT NULL AFTER `price`;
UPDATE `pl_MembershipType` SET `duration` = 1;

ALTER TABLE `pl_User` ADD `membershipExpiresOn` DATE NOT NULL AFTER `membershipTypeId`;
UPDATE `pl_User` SET `membershipExpiresOn` = DATE_ADD(added, INTERVAL 1 YEAR);

-- ---------------------------------------------------------------------------------------------------------------------
-- Email Templates
-- ---------------------------------------------------------------------------------------------------------------------
SET @template := 'userMembershipRenewedToUser';
SET @categoryId := 4;
SET @sorter := IFNULL((SELECT MAX(sorter) FROM pl_Settings WHERE idCategory = @categoryId), -1) + 1;

INSERT INTO `pl_Settings` (`name`, `idCategory`, `fieldType`, `label`, `value`, `options`, `description`, `required`, `system`, `sorter`, `added`, `changed`) VALUES
(CONCAT(@template, 'Header'), @categoryId, 'header', '', 'Membership Renewed (User Notification)', '', '', 'n', 'n', @sorter, NOW(), NOW()),
(CONCAT(@template, 'Subject'), @categoryId, 'text', 'Subject', 'Membership Renewed at Pageant Life', '', '', 'y', 'n', @sorter + 1, NOW(), NOW()),
(CONCAT(@template, 'From'), @categoryId, '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', @sorter + 2, NOW(), NOW()),
(CONCAT(@template, 'Body'), @categoryId, 'HtmlEditor', 'Message Body', '<div><p>Congratulations! Your {membership} membership has been successfully renewed to {membershipExpiresOn} at Pageant Life web site!</p><p><a href="{loginUrl}" target="_blank">Click here to login at Pageant Life web site</a>.</p></div>', '', 'Constants: {firstName} {lastName} {phone} {email} {password} {membership} {membershipExpiresOn} {loginUrl}', 'y', 'n', @sorter + 3, NOW(), NOW());

INSERT INTO `pl_SettingsOptions` (`name`, `variable`, `value`, `type`, `sorter`) VALUES (CONCAT(@template, 'Body'), 'mode', 'view', 'string', NULL);
