# ===== v 4.0.1 =====
ALTER TABLE EmailLog ADD EventParams TEXT NOT NULL;

INSERT INTO ConfigurationAdmin VALUES ('MailFunctionHeaderSeparator', 'la_Text_smtp_server', 'la_config_MailFunctionHeaderSeparator', 'radio', NULL, '1=la_Linux,2=la_Windows', 30.08, 0, 0);
INSERT INTO ConfigurationValues VALUES (0, 'MailFunctionHeaderSeparator', 1, 'In-Portal', 'in-portal:configure_general');

ALTER TABLE PersistantSessionData DROP PRIMARY KEY ;
ALTER TABLE PersistantSessionData ADD INDEX ( `PortalUserId` ) ;

# ===== v 4.1.0 =====
ALTER TABLE EmailMessage ADD ReplacementTags TEXT AFTER Template;
ALTER TABLE Phrase
	CHANGE Translation Translation TEXT NOT NULL,
	CHANGE Module Module VARCHAR(30) NOT NULL DEFAULT 'In-Portal';
ALTER TABLE Category
	CHANGE Description Description TEXT,
	CHANGE l1_Description l1_Description TEXT,
	CHANGE l2_Description l2_Description TEXT,
	CHANGE l3_Description l3_Description TEXT,
	CHANGE l4_Description l4_Description TEXT,
	CHANGE l5_Description l5_Description TEXT,
	CHANGE CachedNavbar CachedNavbar text,
	CHANGE l1_CachedNavbar l1_CachedNavbar text,
	CHANGE l2_CachedNavbar l2_CachedNavbar text,
	CHANGE l3_CachedNavbar l3_CachedNavbar text,
	CHANGE l4_CachedNavbar l4_CachedNavbar text,
	CHANGE l5_CachedNavbar l5_CachedNavbar text,
	CHANGE ParentPath ParentPath TEXT NULL DEFAULT NULL,
	CHANGE NamedParentPath NamedParentPath TEXT NULL DEFAULT NULL;
ALTER TABLE ConfigurationAdmin CHANGE ValueList ValueList TEXT;
ALTER TABLE EmailQueue
	CHANGE `Subject` `Subject` TEXT,
	CHANGE toaddr toaddr TEXT,
	CHANGE fromaddr fromaddr TEXT;
ALTER TABLE Category DROP Pop;
ALTER TABLE PortalUser
	CHANGE CreatedOn CreatedOn INT DEFAULT NULL,
	CHANGE dob dob INT(11) NULL DEFAULT NULL,
	CHANGE PassResetTime PassResetTime INT(11) UNSIGNED NULL DEFAULT NULL,
	CHANGE PwRequestTime PwRequestTime INT(11) UNSIGNED NULL DEFAULT NULL,
	CHANGE `Password` `Password` VARCHAR(255) NULL DEFAULT 'd41d8cd98f00b204e9800998ecf8427e';
ALTER TABLE Modules
	CHANGE BuildDate BuildDate INT UNSIGNED NULL DEFAULT NULL,
	CHANGE Version Version VARCHAR(10) NOT NULL DEFAULT '0.0.0',
	CHANGE `Var` `Var` VARCHAR(100) NOT NULL DEFAULT '';
ALTER TABLE Language
	CHANGE Enabled Enabled INT(11) NOT NULL DEFAULT '1',
	CHANGE InputDateFormat InputDateFormat VARCHAR(50) NOT NULL DEFAULT 'm/d/Y',
	CHANGE InputTimeFormat InputTimeFormat VARCHAR(50) NOT NULL DEFAULT 'g:i:s A',
	CHANGE DecimalPoint DecimalPoint VARCHAR(10) NOT NULL DEFAULT '',
	CHANGE ThousandSep ThousandSep VARCHAR(10) NOT NULL DEFAULT '';
ALTER TABLE Events CHANGE FromUserId FromUserId INT(11) NOT NULL DEFAULT '-1';
ALTER TABLE StdDestinations CHANGE DestAbbr2 DestAbbr2 CHAR(2) NULL DEFAULT NULL;
ALTER TABLE PermCache DROP DACL;
ALTER TABLE PortalGroup CHANGE CreatedOn CreatedOn INT UNSIGNED NULL DEFAULT NULL;
ALTER TABLE UserSession
	CHANGE SessionKey SessionKey INT UNSIGNED NULL DEFAULT NULL ,
	CHANGE CurrentTempKey CurrentTempKey INT UNSIGNED NULL DEFAULT NULL ,
	CHANGE PrevTempKey PrevTempKey INT UNSIGNED NULL DEFAULT NULL ,
	CHANGE LastAccessed LastAccessed INT UNSIGNED NOT NULL DEFAULT '0',
	CHANGE PortalUserId PortalUserId INT(11) NOT NULL DEFAULT '-2',
	CHANGE Language Language INT(11) NOT NULL DEFAULT '1',
	CHANGE Theme Theme INT(11) NOT NULL DEFAULT '1';
CREATE TABLE Counters (
  CounterId int(10) unsigned NOT NULL auto_increment,
  Name varchar(100) NOT NULL default '',
  CountQuery text,
  CountValue text,
  LastCounted int(10) unsigned default NULL,
  LifeTime int(10) unsigned NOT NULL default '3600',
  IsClone tinyint(3) unsigned NOT NULL default '0',
  TablesAffected text,
  PRIMARY KEY  (CounterId),
  UNIQUE KEY Name (Name)
);
CREATE TABLE Skins (
  `SkinId` int(11) NOT NULL auto_increment,
  `Name` varchar(255) default NULL,
  `CSS` text,
  `Logo` varchar(255) default NULL,
  `Options` text,
  `LastCompiled` int(11) NOT NULL default '0',
  `IsPrimary` int(1) NOT NULL default '0',
  PRIMARY KEY  (`SkinId`)
);
INSERT INTO Skins VALUES (DEFAULT, 'Default', '/* General elements */\r\n\r\nhtml {\r\n	height: 100%;\r\n}\r\n\r\nbody {\r\n 	font-family: verdana,arial,helvetica,sans-serif;\r\n	font-size: 9pt;\r\n 	color: #000000;\r\n	overflow-x: auto; overflow-y: auto;\r\n	margin: 0px 0px 0px 0px;\r\n	text-decoration: none;\r\n}\r\n\r\na {\r\n	color: #006699;\r\n	text-decoration: none;\r\n}\r\n\r\na:hover {\r\n	color: #009ff0;\r\n	text-decoration: none;\r\n}\r\n\r\nform {\r\n   display: inline;\r\n}\r\n\r\nimg { border: 0px; }\r\n\r\nbody.height-100 {\r\n	height: 100%;\r\n}\r\n\r\nbody.regular-body {\r\n	margin: 0px 10px 5px 10px;\r\n	color: #000000;\r\n	background-color: @@SectionBgColor@@;\r\n}\r\n\r\nbody.edit-popup {\r\n	margin: 0px 0px 0px 0px;\r\n}\r\n\r\ntable.collapsed {\r\n	border-collapse: collapse;\r\n}\r\n\r\n.bordered, table.bordered, .bordered-no-bottom {\r\n	border: 1px solid #000000;\r\n	border-collapse: collapse;\r\n}\r\n\r\n.bordered-no-bottom {\r\n	border-bottom: none;\r\n}\r\n\r\n.login-table td {\r\n	padding: 1px;\r\n}\r\n\r\n.disabled {\r\n	background-color: #ebebeb;\r\n}\r\n\r\n/* Head frame */\r\n.head-table tr td {\r\n	background-color: @@HeadBgColor@@;\r\n	color: @@HeadColor@@\r\n}\r\n\r\ntd.kx-block-header, .head-table tr td.kx-block-header{\r\n	color: @@HeadBarColor@@;\r\n	background-color: @@HeadBarBgColor@@;\r\n	padding-left: 7px;\r\n	padding-right: 7px;\r\n}\r\n\r\na.kx-header-link {\r\n	text-decoration: underline;\r\n	color: #FFFFFF;\r\n}\r\n\r\na.kx-header-link:hover {\r\n	color: #FFCB05;\r\n	text-decoration: none;\r\n}\r\n\r\n.kx-secondary-foreground 	{\r\n	color: @@HeadBarColor@@;\r\n	background-color: @@HeadBarBgColor@@;\r\n}\r\n\r\n.kx-login-button {\r\n	background-color: #2D79D6;\r\n	color: #FFFFFF;\r\n}\r\n\r\n/* General form button (yellow) */\r\n.button {\r\n	font-size: 12px;\r\n	font-weight: normal;\r\n	color: #000000;\r\n	background: url(@@base_url@@/proj-base/admin_templates/img/button_back.gif) #f9eeae repeat-x;\r\n	text-decoration: none;\r\n}\r\n\r\n/* Disabled (grayed-out) form button */\r\n.button-disabled {\r\n	font-size: 12px;\r\n	font-weight: normal;\r\n	color: #676767;\r\n	background: url(@@base_url@@/proj-base/admin_templates/img/button_back_disabled.gif) #f9eeae repeat-x;\r\n	text-decoration: none;\r\n}\r\n\r\n/* Tabs bar */\r\n\r\n.tab, .tab-active {\r\n	background-color: #F0F1EB;\r\n	padding: 3px 7px 2px 7px;\r\n	border-top: 1px solid black;\r\n	border-left: 1px solid black;\r\n	border-right: 1px solid black;\r\n}\r\n\r\n.tab-active {\r\n	background-color: #2D79D6;\r\n	border-bottom: 1px solid #2D79D6;\r\n}\r\n\r\n.tab a {\r\n	color: #00659C;\r\n	font-weight: bold;\r\n}\r\n\r\n.tab-active a {\r\n	color: #fff;\r\n	font-weight: bold;\r\n}\r\n\r\n\r\n/* Toolbar */\r\n\r\n.toolbar {\r\n	font-size: 8pt;\r\n	border: 1px solid #000000;\r\n	border-width: 0px 1px 1px 1px;\r\n	background-color: @@ToolbarBgColor@@;\r\n	border-collapse: collapse;\r\n}\r\n\r\n.toolbar td {\r\n	height: 100%;\r\n}\r\n\r\n.toolbar-button, .toolbar-button-disabled, .toolbar-button-over {\r\n	float: left;\r\n	text-align: center;\r\n	font-size: 8pt;\r\n	padding: 5px 5px 5px 5px;\r\n	vertical-align: middle;\r\n	color: #006F99;\r\n}\r\n\r\n.toolbar-button-over {\r\n	color: #000;\r\n}\r\n\r\n.toolbar-button-disabled {\r\n	color: #444;\r\n}\r\n\r\n/*  Scrollable Grids */\r\n\r\n\r\n/* Main Grid class */\r\n.grid-scrollable {\r\n	padding: 0px;\r\n	border: 1px solid black !important;\r\n	border-top: none !important;\r\n}\r\n\r\n/* Div generated by js, which contains all the scrollable grid elements, affects the style of scrollable area without data (if there are too few rows) */\r\n.grid-container {\r\n	background-color: #fff;\r\n}\r\n\r\n.grid-container table {\r\n	border-collapse: collapse;\r\n}\r\n\r\n/* Inner div generated in each data-cell */\r\n.grid-cell-div {\r\n	overflow: hidden;\r\n	height: auto;\r\n}\r\n\r\n/* Main row definition */\r\n.grid-data-row td, .grid-data-row-selected td, .grid-data-row-even-selected td, .grid-data-row-mouseover td, .table-color1, .table-color2 {\r\n	font-weight: normal;\r\n	color: @@OddColor@@;\r\n	background-color: @@OddBgColor@@;\r\n	padding: 3px 5px 3px 5px;\r\n	height: 30px;\r\n	overflow: hidden;\r\n	/* border-right: 1px solid black; */\r\n}\r\n.grid-data-row-even td, .table-color2 {\r\n	background-color: @@EvenBgColor@@;\r\n	color: @@EvenColor@@;\r\n}\r\n.grid-data-row td a, .grid-data-row-selected td a, .grid-data-row-mouseover td a {\r\n	text-decoration: underline;\r\n}\r\n\r\n/* mouse-over rows */\r\n.grid-data-row-mouseover td {\r\n	background: #FFFDF4;\r\n}\r\n\r\n/* Selected row, applies to both checkbox and data areas */\r\n.grid-data-row-selected td {\r\n	background: #FEF2D6;\r\n}\r\n\r\n.grid-data-row-even-selected td {\r\n	background: #FFF7E0;\r\n}\r\n\r\n/* General header cell definition */\r\n.grid-header-row td {\r\n	font-weight: bold;\r\n	background-color: @@ColumnTitlesBgColor@@;\r\n	text-decoration: none;\r\n	padding: 3px 5px 3px 5px;\r\n	color: @@ColumnTitlesColor@@;\r\n	border-right: none;\r\n	text-align: left;\r\n	vertical-align: middle !important;\r\n	white-space: nowrap;\r\n	/* border-right: 1px solid black; */\r\n}\r\n\r\n/* Filters row */\r\ntr.grid-header-row-0 td {\r\n	background-color: @@FiltersBgColor@@;\r\n	border-bottom: 1px solid black;\r\n}\r\n\r\n/* Grid Filters */\r\ntable.range-filter {\r\n	width: 100%;\r\n}\r\n\r\n.range-filter td {\r\n	padding: 0px 0px 2px 2px !important;\r\n	border: none !important;\r\n	font-size: 8pt !important;\r\n	font-weight: normal !important;\r\n	text-align: left;\r\n	color: #000000 !important;\r\n}\r\n\r\ninput.filter, select.filter {\r\n	margin-bottom: 0px;\r\n	width: 85%;\r\n}\r\n\r\ninput.filter-active {\r\n  background-color: #FFFF00;\r\n}\r\n\r\nselect.filter-active {\r\n background-color: #FFFF00;\r\n}\r\n\r\n/* Column titles row */\r\ntr.grid-header-row-1 td {\r\n	height: 25px;\r\n	font-weight: bold;\r\n	background-color: @@ColumnTitlesBgColor@@;\r\n	color: @@ColumnTitlesColor@@;\r\n}\r\n\r\ntr.grid-header-row-1 td a {\r\n	color: @@ColumnTitlesColor@@;\r\n}\r\n\r\ntr.grid-header-row-1 td a:hover {\r\n	color: #FFCC00;\r\n}\r\n\r\n\r\n.grid-footer-row td {\r\n	background-color: #D7D7D7;\r\n	font-weight: bold;\r\n	border-right: none;\r\n	padding: 3px 5px 3px 5px;\r\n}\r\n\r\ntd.grid-header-last-cell, td.grid-data-last-cell, td.grid-footer-last-cell {\r\n	border-right: none !important;\r\n}\r\n\r\ntd.grid-data-col-0, td.grid-data-col-0 div {\r\n	text-align: center;\r\n	vertical-align: middle !important;\r\n}\r\n\r\ntr.grid-header-row-0 td.grid-header-col-0 {\r\n	text-align: center;\r\n	vertical-align: middle !important;\r\n}\r\n\r\ntr.grid-header-row-0 td.grid-header-col-0 div {\r\n	display: table-cell;\r\n	vertical-align: middle;\r\n}\r\n\r\n.grid-status-bar {\r\n	border: 1px solid black;\r\n	border-top: none;\r\n	padding: 0px;\r\n	width: 100%;\r\n	border-collapse: collapse;\r\n	height: 30px;\r\n}\r\n\r\n.grid-status-bar td {\r\n	background-color: @@TitleBarBgColor@@;\r\n  color: @@TitleBarColor@@;\r\n	font-size: 11pt;\r\n	font-weight: normal;\r\n	padding: 2px 8px 2px 8px;\r\n}\r\n\r\n/*  /Scrollable Grids */\r\n\r\n\r\n/* Forms */\r\ntable.edit-form {\r\n	border: none;\r\n	border-top-width: 0px;\r\n	border-collapse: collapse;\r\n	width: 100%;\r\n}\r\n\r\n.edit-form-odd, .edit-form-even {\r\n	padding: 0px;\r\n}\r\n\r\n.subsectiontitle {\r\n	font-size: 10pt;\r\n	font-weight: bold;\r\n	background-color: #4A92CE;\r\n	color: #fff;\r\n	height: 25px;\r\n	border-top: 1px solid black;\r\n}\r\n\r\n.label-cell {\r\n	background: #DEE7F6 url(@@base_url@@/proj-base/admin_templates/img/bgr_input_name_line.gif) no-repeat right bottom;\r\n  font: 12px arial, sans-serif;\r\n  padding: 4px 20px;\r\n  width: 150px;\r\n}\r\n\r\n.control-mid {\r\n	width: 13px;\r\n	border-left: 1px solid #7A95C2;\r\n	background: #fff url(@@base_url@@/proj-base/admin_templates/img/bgr_mid.gif) repeat-x left bottom;\r\n}\r\n\r\n.control-cell {\r\n	font: 11px arial, sans-serif;\r\n	padding: 4px 10px 5px 5px;\r\n	background: #fff url(@@base_url@@/proj-base/admin_templates/img/bgr_input_line.gif) no-repeat left bottom;\r\n	width: auto;\r\n	vertical-align: middle;\r\n}\r\n\r\n.label-cell-filler {\r\n	background: #DEE7F6 none;\r\n}\r\n.control-mid-filler {\r\n	background: #fff none;\r\n	border-left: 1px solid #7A95C2;\r\n}\r\n.control-cell-filler {\r\n	background: #fff none;\r\n}\r\n\r\n\r\n.error-cell {\r\n	background-color: #fff;\r\n	color: red;\r\n}\r\n\r\n.form-warning {\r\n	color: red;\r\n}\r\n\r\n.req-note {\r\n	font-style: italic;\r\n	color: #333;\r\n}\r\n\r\n#scroll_container table.tableborder {\r\n	border-collapse: separate\r\n}\r\n\r\n\r\n/* Uploader */\r\n\r\n.uploader-main {\r\n	position: absolute;\r\n	display: none;\r\n	z-index: 10;\r\n	border: 1px solid #777;\r\n	padding: 10px;\r\n	width: 350px;\r\n	height: 120px;\r\n	overflow: hidden;\r\n	background-color: #fff;\r\n}\r\n\r\n.uploader-percent {\r\n	width: 100%;\r\n	padding-top: 3px;\r\n	text-align: center;\r\n	position: relative;\r\n	z-index: 20;\r\n	float: left;\r\n	font-weight: bold;\r\n}\r\n\r\n.uploader-left {\r\n	width: 100%;\r\n	border: 1px solid black;\r\n	height: 20px;\r\n	background: #fff url(@@base_url@@/core/admin_templates/img/progress_left.gif);\r\n}\r\n\r\n.uploader-done {\r\n	width: 0%;\r\n	background-color: green;\r\n	height: 20px;\r\n	background: #4A92CE url(@@base_url@@/core/admin_templates/img/progress_done.gif);\r\n}\r\n\r\n\r\n/* To be sorted */\r\n\r\n\r\n/* Section title, right to the big icon */\r\n.admintitle {\r\n	font-size: 16pt;\r\n	font-weight: bold;\r\n	color: @@SectionColor@@;\r\n	text-decoration: none;\r\n}\r\n\r\n/* Left sid of bluebar */\r\n.header_left_bg {\r\n	background-color: @@TitleBarBgColor@@;\r\n	background-image: none;\r\n	padding-left: 5px;\r\n}\r\n\r\n/* Right side of bluebar */\r\n.tablenav, tablenav a {\r\n	font-size: 11pt;\r\n	font-weight: bold;\r\n	color: @@TitleBarColor@@;\r\n\r\n	text-decoration: none;\r\n	background-color: @@TitleBarBgColor@@;\r\n	background-image: none;\r\n}\r\n\r\n/* Section title in the bluebar * -- why ''link''? :S */\r\n.tablenav_link {\r\n	font-size: 11pt;\r\n	font-weight: bold;\r\n	color: @@TitleBarColor@@;\r\n	text-decoration: none;\r\n}\r\n\r\n/* Active page in top and bottom bluebars pagination */\r\n.current_page {\r\n	font-size: 10pt;\r\n	font-weight: bold;\r\n	background-color: #fff;\r\n	color: #2D79D6;\r\n	padding: 3px 2px 3px 3px;\r\n}\r\n\r\n/* Other pages and arrows in pagination on blue */\r\n.nav_url {\r\n	font-size: 10pt;\r\n	font-weight: bold;\r\n	color: #fff;\r\n	padding: 3px 2px 3px 3px;\r\n}\r\n\r\n/* Tree */\r\n.tree-body {\r\n	background-color: @@TreeBgColor@@;\r\n	height: 100%\r\n}\r\n\r\n.tree_head.td, .tree_head, .tree_head:hover {\r\n font-weight: bold;\r\n font-size: 10px;\r\n color: #FFFFFF;\r\n font-family: Verdana, Arial;\r\n text-decoration: none;\r\n}\r\n\r\n.tree {\r\n	padding: 0px;\r\n	border: none;\r\n	border-collapse: collapse;\r\n}\r\n\r\n.tree tr td {\r\n	padding: 0px;\r\n	margin: 0px;\r\n	font-family: helvetica, arial, verdana,;\r\n	font-size: 11px;\r\n	white-space: nowrap;\r\n}\r\n\r\n.tree tr td a {\r\n	font-size: 11px;\r\n	color: @@TreeColor@@;\r\n	font-family: Helvetica, Arial, Verdana;\r\n	text-decoration: none;\r\n	padding: 2px 0px 2px 2px;\r\n}\r\n\r\n.tree tr.highlighted td a {\r\n	background-color: @@TreeHighBgColor@@;\r\n	color: @@TreeHighColor@@;\r\n}\r\n\r\n.tree tr.highlighted td a:hover {\r\n	color: #fff;\r\n}\r\n\r\n.tree tr td a:hover {\r\n	color: #000000;\r\n}', 'just_logo.gif', 'a:20:{s:11:"HeadBgColor";a:2:{s:11:"Description";s:27:"Head frame background color";s:5:"Value";s:7:"#1961B8";}s:9:"HeadColor";a:2:{s:11:"Description";s:21:"Head frame text color";s:5:"Value";s:7:"#CCFF00";}s:14:"SectionBgColor";a:2:{s:11:"Description";s:28:"Section bar background color";s:5:"Value";s:7:"#FFFFFF";}s:12:"SectionColor";a:2:{s:11:"Description";s:22:"Section bar text color";s:5:"Value";s:7:"#2D79D6";}s:12:"HeadBarColor";a:1:{s:5:"Value";s:7:"#FFFFFF";}s:14:"HeadBarBgColor";a:1:{s:5:"Value";s:7:"#1961B8";}s:13:"TitleBarColor";a:1:{s:5:"Value";s:7:"#FFFFFF";}s:15:"TitleBarBgColor";a:1:{s:5:"Value";s:7:"#2D79D6";}s:14:"ToolbarBgColor";a:1:{s:5:"Value";s:7:"#F0F1EB";}s:14:"FiltersBgColor";a:1:{s:5:"Value";s:7:"#D7D7D7";}s:17:"ColumnTitlesColor";a:1:{s:5:"Value";s:7:"#FFFFFF";}s:19:"ColumnTitlesBgColor";a:1:{s:5:"Value";s:7:"#999999";}s:8:"OddColor";a:1:{s:5:"Value";s:7:"#000000";}s:10:"OddBgColor";a:1:{s:5:"Value";s:7:"#F6F6F6";}s:9:"EvenColor";a:1:{s:5:"Value";s:7:"#000000";}s:11:"EvenBgColor";a:1:{s:5:"Value";s:7:"#EBEBEB";}s:9:"TreeColor";a:1:{s:5:"Value";s:7:"#006F99";}s:11:"TreeBgColor";a:1:{s:5:"Value";s:7:"#FFFFFF";}s:13:"TreeHighColor";a:1:{s:5:"Value";s:7:"#FFFFFF";}s:15:"TreeHighBgColor";a:1:{s:5:"Value";s:7:"#4A92CE";}}', 1178706881, 1);
INSERT INTO Permissions VALUES (0, 'in-portal:skins.view', 11, 1, 1, 0), (0, 'in-portal:skins.add', 11, 1, 1, 0), (0, 'in-portal:skins.edit', 11, 1, 1, 0), (0, 'in-portal:skins.delete', 11, 1, 1, 0);

# ===== v 4.1.1 =====
DROP TABLE EmailQueue;

CREATE TABLE EmailQueue (
  EmailQueueId int(10) unsigned NOT NULL auto_increment,
  ToEmail varchar(255) NOT NULL default '',
  `Subject` varchar(255) NOT NULL default '',
  MessageHeaders text,
  MessageBody longtext,
  Queued int(10) unsigned NOT NULL default '0',
  SendRetries int(10) unsigned NOT NULL default '0',
  LastSendRetry int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (EmailQueueId),
  KEY LastSendRetry (LastSendRetry),
  KEY SendRetries (SendRetries)
);

ALTER TABLE Events ADD ReplacementTags TEXT AFTER Event;

# ===== v 4.2.0 =====
ALTER TABLE CustomField ADD MultiLingual TINYINT UNSIGNED NOT NULL DEFAULT '1' AFTER FieldLabel;
ALTER TABLE Category
	ADD TreeLeft BIGINT NOT NULL AFTER ParentPath,
	ADD TreeRight BIGINT NOT NULL AFTER TreeLeft;

ALTER TABLE Category ADD INDEX (TreeLeft);
ALTER TABLE Category ADD INDEX (TreeRight);

INSERT INTO ConfigurationValues VALUES (DEFAULT, 'CategoriesRebuildSerial', '0', 'In-Portal', '');

UPDATE ConfigurationAdmin SET `element_type` = 'textarea' WHERE `VariableName` IN ('Category_MetaKey', 'Category_MetaDesc');

ALTER TABLE PortalUser
	CHANGE FirstName FirstName VARCHAR(255) NOT NULL DEFAULT '',
	CHANGE LastName LastName VARCHAR(255) NOT NULL DEFAULT '';

# ===== v 4.2.1 =====
INSERT INTO ConfigurationAdmin VALUES ('UseSmallHeader', 'la_Text_Website', 'la_config_UseSmallHeader', 'checkbox', '', '', 10.21, 0, 0);
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'UseSmallHeader', '0', 'In-Portal', 'in-portal:configure_general');

INSERT INTO ConfigurationAdmin VALUES ('User_Default_Registration_Country', 'la_Text_General', 'la_config_DefaultRegistrationCountry', 'select', NULL , '=+,<SQL>SELECT DestName AS OptionName, DestId AS OptionValue FROM <PREFIX>StdDestinations WHERE DestParentId IS NULL Order BY OptionName</SQL>', 10.111, 0, 0);
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'User_Default_Registration_Country', '', 'In-Portal:Users', 'in-portal:configure_users');

ALTER TABLE Category ADD SymLinkCategoryId INT UNSIGNED NULL DEFAULT NULL AFTER `Type`, ADD INDEX (SymLinkCategoryId);
ALTER TABLE ConfigurationValues CHANGE VariableValue VariableValue TEXT NULL DEFAULT NULL;

ALTER TABLE Language
	ADD AdminInterfaceLang TINYINT UNSIGNED NOT NULL AFTER PrimaryLang,
	ADD Priority INT NOT NULL AFTER AdminInterfaceLang;

UPDATE Language SET AdminInterfaceLang = 1 WHERE PrimaryLang = 1;

DELETE FROM PersistantSessionData WHERE VariableName = 'lang_columns_.';
ALTER TABLE SessionData CHANGE VariableValue VariableValue longtext NOT NULL;

REPLACE INTO ConfigurationAdmin VALUES ('CSVExportDelimiter', 'la_Text_CSV_Export', 'la_config_CSVExportDelimiter', 'select', NULL, '0=la_Tab,1=la_Comma,2=la_Semicolon,3=la_Space,4=la_Colon', 40.1, 0, 1);
REPLACE INTO ConfigurationAdmin VALUES ('CSVExportEnclosure', 'la_Text_CSV_Export', 'la_config_CSVExportEnclosure', 'radio', NULL, '0=la_Doublequotes,1=la_Quotes', 40.2, 0, 1);
REPLACE INTO ConfigurationAdmin VALUES ('CSVExportSeparator', 'la_Text_CSV_Export', 'la_config_CSVExportSeparator', 'radio', NULL, '0=la_Linux,1=la_Windows', 40.3, 0, 1);
REPLACE INTO ConfigurationAdmin VALUES ('CSVExportEncoding', 'la_Text_CSV_Export', 'la_config_CSVExportEncoding', 'radio', NULL, '0=la_Unicode,1=la_Regular', 40.4, 0, 1);

REPLACE INTO ConfigurationValues VALUES (DEFAULT, 'CSVExportDelimiter', '0', 'In-Portal', 'in-portal:configure_general');
REPLACE INTO ConfigurationValues VALUES (DEFAULT, 'CSVExportEnclosure', '0', 'In-Portal', 'in-portal:configure_general');
REPLACE INTO ConfigurationValues VALUES (DEFAULT, 'CSVExportSeparator', '0', 'In-Portal', 'in-portal:configure_general');
REPLACE INTO ConfigurationValues VALUES (DEFAULT, 'CSVExportEncoding', '0', 'In-Portal', 'in-portal:configure_general');

# ===== v 4.2.2 =====
INSERT INTO ConfigurationAdmin VALUES ('UseColumnFreezer', 'la_Text_Website', 'la_config_UseColumnFreezer', 'checkbox', '', '', 10.22, 0, 0);
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'UseColumnFreezer', '0', 'In-Portal', 'in-portal:configure_general');

INSERT INTO ConfigurationAdmin VALUES ('TrimRequiredFields', 'la_Text_Website', 'la_config_TrimRequiredFields', 'checkbox', '', '', 10.23, 0, 0);
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'TrimRequiredFields', '0', 'In-Portal', 'in-portal:configure_general');

INSERT INTO ConfigurationAdmin VALUES ('MenuFrameWidth', 'la_title_General', 'la_prompt_MenuFrameWidth', 'text', NULL, NULL, '11', '0', '0');
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'MenuFrameWidth', 200, 'In-Portal', 'in-portal:configure_general');

INSERT INTO ConfigurationAdmin VALUES ('DefaultSettingsUserId', 'la_title_General', 'la_prompt_DefaultUserId', 'text', NULL, NULL, '12', '0', '0');
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'DefaultSettingsUserId', -1, 'In-Portal', 'in-portal:configure_general');

INSERT INTO ConfigurationAdmin VALUES ('KeepSessionOnBrowserClose', 'la_title_General', 'la_prompt_KeepSessionOnBrowserClose', 'checkbox', NULL, NULL, '13', '0', '0');
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'KeepSessionOnBrowserClose', 0, 'In-Portal', 'in-portal:configure_general');

ALTER TABLE PersistantSessionData ADD VariableId BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;

# ===== v 4.3.0 =====
INSERT INTO ConfigurationAdmin VALUES ('u_MaxImageCount', 'la_section_ImageSettings', 'la_config_MaxImageCount', 'text', '', '', 30.01, 0, 0);
INSERT INTO ConfigurationAdmin VALUES ('u_ThumbnailImageWidth', 'la_section_ImageSettings', 'la_config_ThumbnailImageWidth', 'text', '', '', 30.02, 0, 0);
INSERT INTO ConfigurationAdmin VALUES ('u_ThumbnailImageHeight', 'la_section_ImageSettings', 'la_config_ThumbnailImageHeight', 'text', '', '', 30.03, 0, 0);
INSERT INTO ConfigurationAdmin VALUES ('u_FullImageWidth', 'la_section_ImageSettings', 'la_config_FullImageWidth', 'text', '', '', 30.04, 0, 0);
INSERT INTO ConfigurationAdmin VALUES ('u_FullImageHeight', 'la_section_ImageSettings', 'la_config_FullImageHeight', 'text', '', '', 30.05, 0, 0);

INSERT INTO ConfigurationValues VALUES (DEFAULT, 'u_MaxImageCount', 5, 'In-Portal:Users', 'in-portal:configure_users');
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'u_ThumbnailImageWidth', 120, 'In-Portal:Users', 'in-portal:configure_users');
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'u_ThumbnailImageHeight', 120, 'In-Portal:Users', 'in-portal:configure_users');
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'u_FullImageWidth', 450, 'In-Portal:Users', 'in-portal:configure_users');
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'u_FullImageHeight', 450, 'In-Portal:Users', 'in-portal:configure_users');

CREATE TABLE ChangeLogs (
  ChangeLogId bigint(20) NOT NULL auto_increment,
  PortalUserId int(11) NOT NULL default '0',
  SessionLogId int(11) NOT NULL default '0',
  `Action` tinyint(4) NOT NULL default '0',
  OccuredOn int(11) NOT NULL default '0',
  Prefix varchar(255) NOT NULL default '',
  ItemId bigint(20) NOT NULL default '0',
  Changes text NOT NULL,
  MasterPrefix varchar(255) NOT NULL default '',
  MasterId bigint(20) NOT NULL default '0',
  PRIMARY KEY  (ChangeLogId),
  KEY PortalUserId (PortalUserId),
  KEY SessionLogId (SessionLogId),
  KEY `Action` (`Action`),
  KEY OccuredOn (OccuredOn),
  KEY Prefix (Prefix),
  KEY MasterPrefix (MasterPrefix)
);

CREATE TABLE SessionLogs (
  SessionLogId bigint(20) NOT NULL auto_increment,
  PortalUserId int(11) NOT NULL default '0',
  SessionId int(10) NOT NULL default '0',
  `Status` tinyint(4) NOT NULL default '1',
  SessionStart int(11) NOT NULL default '0',
  SessionEnd int(11) default NULL,
  IP varchar(15) NOT NULL default '',
  AffectedItems int(11) NOT NULL default '0',
  PRIMARY KEY  (SessionLogId),
  KEY SessionId (SessionId),
  KEY `Status` (`Status`),
  KEY PortalUserId (PortalUserId)
);

ALTER TABLE CustomField ADD INDEX (MultiLingual), ADD INDEX (DisplayOrder), ADD INDEX (OnGeneralTab), ADD INDEX (IsSystem);
ALTER TABLE ConfigurationAdmin ADD INDEX (DisplayOrder), ADD INDEX (GroupDisplayOrder), ADD INDEX (Install);
ALTER TABLE EmailSubscribers ADD INDEX (EmailMessageId), ADD INDEX (PortalUserId);
ALTER TABLE Events ADD INDEX (`Type`), ADD INDEX (Enabled);
ALTER TABLE Language ADD INDEX (Enabled), ADD INDEX (PrimaryLang), ADD INDEX (AdminInterfaceLang), ADD INDEX (Priority);
ALTER TABLE Modules ADD INDEX (Loaded), ADD INDEX (LoadOrder);
ALTER TABLE PhraseCache ADD INDEX (CacheDate), ADD INDEX (ThemeId), ADD INDEX (StylesheetId);
ALTER TABLE PortalGroup ADD INDEX (CreatedOn);
ALTER TABLE PortalUser ADD INDEX (Status), ADD INDEX (Modified), ADD INDEX (dob), ADD INDEX (IsBanned);
ALTER TABLE Theme ADD INDEX (Enabled), ADD INDEX (StylesheetId), ADD INDEX (PrimaryTheme);
ALTER TABLE UserGroup ADD INDEX (MembershipExpires), ADD INDEX (ExpirationReminderSent);
ALTER TABLE EmailLog ADD INDEX (`timestamp`);
ALTER TABLE StdDestinations ADD INDEX (DestType), ADD INDEX (DestParentId);
ALTER TABLE Category ADD INDEX (Status), ADD INDEX (CreatedOn), ADD INDEX (EditorsPick);
ALTER TABLE Stylesheets ADD INDEX (Enabled), ADD INDEX (LastCompiled);
ALTER TABLE Counters ADD INDEX (IsClone), ADD INDEX (LifeTime), ADD INDEX (LastCounted);
ALTER TABLE Skins ADD INDEX (IsPrimary), ADD INDEX (LastCompiled);

INSERT INTO ConfigurationAdmin VALUES ('UseChangeLog', 'la_Text_Website', 'la_config_UseChangeLog', 'checkbox', '', '', 10.25, 0, 0);
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'UseChangeLog', '0', 'In-Portal', 'in-portal:configure_general');

INSERT INTO ConfigurationAdmin VALUES ('AutoRefreshIntervals', 'la_Text_Website', 'la_config_AutoRefreshIntervals', 'text', '', '', 10.26, 0, 0);
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'AutoRefreshIntervals', '1,5,15,30,60,120,240', 'In-Portal', 'in-portal:configure_general');

DELETE FROM Cache WHERE SUBSTRING(VarName, 1, 7) = 'mod_rw_';

ALTER TABLE Category CHANGE `Status` `Status` TINYINT(4) NOT NULL DEFAULT '2';

# ===== v 4.3.1 =====
INSERT INTO ConfigurationAdmin VALUES ('RememberLastAdminTemplate', 'la_Text_General', 'la_config_RememberLastAdminTemplate', 'checkbox', '', '', 10.13, 0, 0);
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'RememberLastAdminTemplate', '', 'In-Portal:Users', 'in-portal:configure_users');
