ALTER TABLE `session` CHANGE  `session_id`  `session_id` VARCHAR( 160 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;

ALTER TABLE `display` CHANGE `NumberOfMacAddressChanges` `NumberOfMacAddressChanges` INT( 11 ) NOT NULL DEFAULT '0';

ALTER TABLE `display` ADD `LastWakeOnLanCommandSent` INT NULL;

ALTER TABLE `display` ADD `WakeOnLan` TINYINT NOT NULL DEFAULT 0;

ALTER TABLE `display` ADD `WakeOnLanTime` VARCHAR(5) NULL;

ALTER TABLE `display` ADD `BroadCastAddress` VARCHAR(100) NULL,
    ADD `SecureOn` VARCHAR(17) NULL,
    ADD `Cidr` SMALLINT NULL;

INSERT INTO `setting` (`settingid`, `setting`, `value`, `type`, `helptext`, `options`, `cat`, `userChange`) VALUES (NULL, 'USER_PASSWORD_POLICY', '', 'text', 'Regular Expression for password complexity, leave blank for no policy.', '', 'permissions', '1');
INSERT INTO `setting` (`settingid`, `setting`, `value`, `type`, `helptext`, `options`, `cat`, `userChange`) VALUES (NULL, 'USER_PASSWORD_ERROR', '', 'text', 'A text description of this password policy. Will be show to users when their password does not meet the required policy', '', 'permissions', '1');

DELETE FROM `help`;

INSERT INTO `help` (`HelpID`, `Topic`, `Category`, `Link`) VALUES
(1, 'Layout', 'General', 'http://lokon.vs.co.id'),
(2, 'Content', 'General', 'http://lokon.vs.co.id'),
(4, 'Schedule', 'General', 'http://lokon.vs.co.id'),
(5, 'Group', 'General', 'http://lokon.vs.co.id'),
(6, 'Admin', 'General', 'http://lokon.vs.co.id'),
(7, 'Report', 'General', 'http://lokon.vs.co.id'),
(8, 'Dashboard', 'General', 'http://lokon.vs.co.id'),
(9, 'User', 'General', 'http://lokon.vs.co.id'),
(10, 'Display', 'General', 'http://lokon.vs.co.id'),
(11, 'DisplayGroup', 'General', 'http://lokon.vs.co.id'),
(12, 'Layout', 'Add', 'http://lokon.vs.co.id'),
(13, 'Layout', 'Background', 'http://lokon.vs.co.id'),
(14, 'Content', 'Assign', 'http://lokon.vs.co.id'),
(15, 'Layout', 'RegionOptions', 'http://lokon.vs.co.id'),
(16, 'Content', 'AddtoLibrary', 'http://lokon.vs.co.id'),
(17, 'Display', 'Edit', 'http://lokon.vs.co.id'),
(18, 'Display', 'Delete', 'http://lokon.vs.co.id'),
(19, 'Displays', 'Groups', 'http://lokon.vs.co.id'),
(20, 'UserGroup', 'Add', 'http://lokon.vs.co.id'),
(21, 'User', 'Add', 'http://lokon.vs.co.id'),
(22, 'User', 'Delete', 'http://lokon.vs.co.id'),
(23, 'Content', 'Config', 'http://lokon.vs.co.id'),
(24, 'LayoutMedia', 'Permissions', 'http://lokon.vs.co.id'),
(25, 'Region', 'Permissions', 'http://lokon.vs.co.id'),
(26, 'Library', 'Assign', 'http://lokon.vs.co.id'),
(27, 'Media', 'Delete', 'http://lokon.vs.co.id'),
(28, 'DisplayGroup', 'Add', 'http://lokon.vs.co.id'),
(29, 'DisplayGroup', 'Edit', 'http://lokon.vs.co.id'),
(30, 'DisplayGroup', 'Delete', 'http://lokon.vs.co.id'),
(31, 'DisplayGroup', 'Members', 'http://lokon.vs.co.id'),
(32, 'DisplayGroup', 'Permissions', 'http://lokon.vs.co.id'),
(34, 'Schedule', 'ScheduleNow', 'http://lokon.vs.co.id'),
(35, 'Layout', 'Delete', 'http://lokon.vs.co.id'),
(36, 'Layout', 'Copy', 'http://lokon.vs.co.id'),
(37, 'Schedule', 'Edit', 'http://lokon.vs.co.id'),
(38, 'Schedule', 'Add', 'http://lokon.vs.co.id'),
(39, 'Layout', 'Permissions', 'http://lokon.vs.co.id'),
(40, 'Display', 'MediaInventory', 'http://lokon.vs.co.id'),
(41, 'User', 'ChangePassword', 'http://lokon.vs.co.id'),
(42, 'Schedule', 'Delete', 'http://lokon.vs.co.id'),
(43, 'Layout', 'Edit', 'http://lokon.vs.co.id'),
(44, 'Media', 'Permissions', 'http://lokon.vs.co.id'),
(45, 'Display', 'DefaultLayout', 'http://lokon.vs.co.id'),
(46, 'UserGroup', 'Edit', 'http://lokon.vs.co.id'),
(47, 'UserGroup', 'Members', 'http://lokon.vs.co.id'),
(48, 'User', 'PageSecurity', 'http://lokon.vs.co.id'),
(49, 'User', 'MenuSecurity', 'http://lokon.vs.co.id'),
(50, 'UserGroup', 'Delete', 'http://lokon.vs.co.id'),
(51, 'User', 'Edit', 'http://lokon.vs.co.id'),
(52, 'User', 'Applications', 'http://lokon.vs.co.id'),
(53, 'User', 'SetHomepage', 'http://lokon.vs.co.id'),
(54, 'DataSet', 'General', 'http://lokon.vs.co.id'),
(55, 'DataSet', 'Add', 'http://lokon.vs.co.id'),
(56, 'DataSet', 'Edit', 'http://lokon.vs.co.id'),
(57, 'DataSet', 'Delete', 'http://lokon.vs.co.id'),
(58, 'DataSet', 'AddColumn', 'http://lokon.vs.co.id'),
(59, 'DataSet', 'EditColumn', 'http://lokon.vs.co.id'),
(60, 'DataSet', 'DeleteColumn', 'http://lokon.vs.co.id'),
(61, 'DataSet', 'Data', 'http://lokon.vs.co.id'),
(62, 'DataSet', 'Permissions', 'http://lokon.vs.co.id'),
(63, 'Fault', 'General', 'http://lokon.vs.co.id'),
(64, 'Report', 'General', 'http://lokon.vs.co.id'),
(65, 'Stats', 'General', 'http://lokon.vs.co.id'),
(66, 'Resolution', 'General', 'http://lokon.vs.co.id'),
(67, 'Template', 'General', 'http://lokon.vs.co.id'),
(68, 'Services', 'Register', 'http://lokon.vs.co.id'),
(69, 'OAuth', 'General', 'http://lokon.vs.co.id'),
(70, 'Services', 'Log', 'http://lokon.vs.co.id'),
(71, 'Module', 'Edit', 'http://lokon.vs.co.id'),
(72, 'Module', 'General', 'http://lokon.vs.co.id');

RENAME TABLE `lkgroupdg` TO  `lkdisplaygroupgroup`;

ALTER TABLE  `lkdisplaygroupgroup` CHANGE  `LkGroupDGID`  `LkDisplayGroupGroupID` INT( 11 ) NOT NULL AUTO_INCREMENT;

ALTER TABLE  `lkdisplaygroupgroup` ADD  `View` TINYINT NOT NULL DEFAULT  '0',
ADD  `Edit` TINYINT NOT NULL DEFAULT  '0',
ADD  `Del` TINYINT NOT NULL DEFAULT  '0';

DELETE FROM `lkmenuitemgroup`;
DELETE FROM `menuitem`;
DELETE FROM `menu`;

INSERT INTO `menu` (`MenuID`, `Menu`) VALUES
(8, 'Administration Menu'),
(9, 'Advanced Menu'),
(2, 'Dashboard'),
(7, 'Display Menu'),
(6, 'Design Menu'),
(5, 'Library Menu'),
(1, 'Top Nav');

INSERT INTO `menuitem` (`MenuItemID`, `MenuID`, `PageID`, `Args`, `Text`, `Class`, `Img`, `Sequence`) VALUES
(1, 1, 2, NULL, 'Schedule', NULL, NULL, 1),
(2, 1, 5, NULL, 'Design', NULL, NULL, 2),
(3, 1, 7, NULL, 'Library', NULL, NULL, 3),
(4, 1, 17, NULL, 'Administration', NULL, NULL, 5),
(7, 7, 11, NULL, 'Displays', NULL, NULL, 1),
(8, 8, 15, NULL, 'User Groups', NULL, NULL, 2),
(9, 8, 17, NULL, 'Users', NULL, NULL, 1),
(10, 9, 16, 'sp=log', 'Log', NULL, NULL, 1),
(11, 9, 18, NULL, 'License', NULL, NULL, 4),
(12, 9, 16, 'sp=sessions', 'Sessions', NULL, NULL, 2),
(13, 8, 14, NULL, 'Settings', NULL, NULL, 3),
(14, 2, 2, 'sp=month', 'Schedule', 'schedule_button', 'img/dashboard/scheduleview.png', 1),
(15, 2, 5, NULL, 'Layouts', 'playlist_button', 'img/dashboard/presentations.png', 2),
(16, 2, 7, NULL, 'Library', 'content_button', 'img/dashboard/content.png', 3),
(17, 2, 25, NULL, 'Templates', 'layout_button', 'img/dashboard/layouts.png', 4),
(18, 2, 17, NULL, 'Users', 'user_button', 'img/dashboard/users.png', 5),
(19, 2, 14, NULL, 'Settings', 'settings_button', 'img/dashboard/settings.png', 6),
(20, 2, 18, NULL, 'License', 'license_button', 'img/dashboard/license.png', 7),
(22, 9, 26, NULL, 'Report Fault', NULL, NULL, 3),
(23, 7, 27, NULL, 'Statistics', NULL, NULL, 3),
(24, 2, 28, 'http://lokon.vs.co.id', 'Manual', 'help_button', 'img/dashboard/help.png', 10),
(25, 6, 29, NULL, 'Resolutions', NULL, NULL, 4),
(26, 6, 25, NULL, 'Templates', NULL, NULL, 3),
(27, 7, 32, NULL, 'Player Groups', NULL, NULL, 2),
(28, 8, 33, NULL, 'Applications', NULL, NULL, NULL),
(29, 5, 36, NULL, 'DataSets', NULL, NULL, NULL),
(30, 5, 7, NULL, 'Media', NULL, NULL, 1),
(33, 6, 5, NULL, 'Layouts', NULL, NULL, 2),
(34, 1, 11, NULL, 'Displays', NULL, NULL, 4),
(35, 1, 16, 'sp=log', 'Advanced', NULL, NULL, 6),
(36, 8, 24, NULL, 'Modules', NULL, NULL, 5);

INSERT INTO `lkmenuitemgroup` (`LkMenuItemGroupID`, `GroupID`, `MenuItemID`) VALUES
(1, 1, 33),
(2, 1, 14),
(3, 1, 15),
(4, 1, 16),
(5, 1, 20),
(6, 1, 24),
(7, 1, 1),
(8, 1, 2),
(9, 1, 3),
(10, 1, 29),
(11, 1, 30),
(12, 1, 26);

INSERT INTO `setting` (`settingid`, `setting`, `value`, `type`, `helptext`, `options`, `cat`, `userChange`) VALUES (NULL, 'MODULE_CONFIG_LOCKED_CHECKB', 'Unchecked', 'dropdown', 'Is the module config locked? Useful for Service providers.', 'Checked|Unchecked', 'general', '0');

DELETE FROM `schedule_detail` WHERE DisplayGroupID NOT IN (SELECT DisplayGroupID FROM `displaygroup`);

ALTER TABLE `schedule_detail` ADD FOREIGN KEY (  `DisplayGroupID` ) REFERENCES `displaygroup` (
`DisplayGroupID`
) ON DELETE RESTRICT ON UPDATE RESTRICT ;

CREATE TABLE IF NOT EXISTS `relay` (
  `rsID` varchar(50) NOT NULL,
  `lastAccessed` datetime NOT NULL,
  PRIMARY KEY (`rsID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `hardware` (
  `hwkey` varchar(50) NOT NULL,
  `userID` int(11) NOT NULL,
  `type` tinyint(4) NOT NULL,
  PRIMARY KEY (`hwkey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `video` (
  `videoID` int(11) NOT NULL AUTO_INCREMENT,
  `msID` varchar(50) NOT NULL,
  `filename` varchar(256) NOT NULL,
  `origname` varchar(256) NOT NULL,
  `duration` int(11) NOT NULL,
  `filesize` bigint(20) NOT NULL,
  `userID` int(11) NOT NULL,
  `retired` tinyint(4) NOT NULL DEFAULT '0',
  `isEdited` tinyint(4) NOT NULL DEFAULT '0',
  `editedVideoID` int(11) DEFAULT NULL,
  `magnet` varchar(256) NOT NULL,
  `torrent` varchar(2048) NOT NULL,
  `lastAccessed` datetime NOT NULL,
  PRIMARY KEY (`videoID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=37 ;

CREATE TABLE IF NOT EXISTS `campaign` (
  `CampaignID` int(11) NOT NULL AUTO_INCREMENT,
  `Campaign` varchar(254) NOT NULL,
  `IsLayoutSpecific` tinyint(4) NOT NULL,
  `UserID` int(11) NOT NULL,
  PRIMARY KEY (`CampaignID`),
  KEY `UserID` (`UserID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

ALTER TABLE `campaign`
  ADD CONSTRAINT `campaign_ibfk_1` FOREIGN KEY (`UserID`) REFERENCES `user` (`UserID`);


CREATE TABLE IF NOT EXISTS `lkcampaigngroup` (
  `LkCampaignGroupID` int(11) NOT NULL AUTO_INCREMENT,
  `CampaignID` int(11) NOT NULL,
  `GroupID` int(11) NOT NULL,
  `View` tinyint(4) NOT NULL DEFAULT '0',
  `Edit` tinyint(4) NOT NULL DEFAULT '0',
  `Del` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`LkCampaignGroupID`),
  KEY `CampaignID` (`CampaignID`),
  KEY `GroupID` (`GroupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

ALTER TABLE `lkcampaigngroup`
  ADD CONSTRAINT `lkcampaigngroup_ibfk_2` FOREIGN KEY (`GroupID`) REFERENCES `group` (`groupID`),
  ADD CONSTRAINT `lkcampaigngroup_ibfk_1` FOREIGN KEY (`CampaignID`) REFERENCES `campaign` (`CampaignID`);

CREATE TABLE IF NOT EXISTS `lkcampaignlayout` (
  `LkCampaignLayoutID` int(11) NOT NULL AUTO_INCREMENT,
  `CampaignID` int(11) NOT NULL,
  `LayoutID` int(11) NOT NULL,
  `DisplayOrder` int(11) NOT NULL,
  PRIMARY KEY (`LkCampaignLayoutID`),
  KEY `CampaignID` (`CampaignID`),
  KEY `LayoutID` (`LayoutID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

ALTER TABLE `lkcampaignlayout`
  ADD CONSTRAINT `lkcampaignlayout_ibfk_2` FOREIGN KEY (`LayoutID`) REFERENCES `layout` (`layoutID`),
  ADD CONSTRAINT `lkcampaignlayout_ibfk_1` FOREIGN KEY (`CampaignID`) REFERENCES `campaign` (`CampaignID`);

INSERT INTO `pages` (`name`, `pagegroupID`) VALUES ('campaign', '3');

INSERT INTO `menuitem` (`MenuID`, `PageID`, `Args`, `Text`, `Class`, `Img`, `Sequence`)
    SELECT 6, PageId, NULL, 'Campaigns', NULL, NULL, 1
      FROM `pages`
     WHERE name = 'campaign';
          
INSERT INTO `pages` (`name`, `pagegroupID`) VALUES ('streaming', '3');
     
INSERT INTO `menuitem` (`MenuID`, `PageID`, `Args`, `Text`, `Class`, `Img`, `Sequence`)
	SELECT 2, PageId, NULL, 'Streaming', 'streaming_button', 'img/dashboard/streaming.png', 8 FROM `pages` WHERE name = 'streaming';

INSERT INTO `pages` (`name`, `pagegroupID`) VALUES ('network', '8');

INSERT INTO `menuitem` (`MenuID`, `PageID`, `Args`, `Text`, `Class`, `Img`, `Sequence`)
	SELECT 8, PageId, NULL, 'Network', NULL, NULL, 4 FROM `pages` WHERE name = 'network';
	
INSERT INTO `pages` (`name`, `pagegroupID`) VALUES ('video', '4');

INSERT INTO `menuitem` (`MenuID`, `PageID`, `Args`, `Text`, `Class`, `Img`, `Sequence`)
	SELECT 5, PageId, NULL, 'Video', NULL, NULL, 2 FROM `pages` WHERE name = 'video';

INSERT INTO `lkmenuitemgroup` (`GroupID`, `MenuItemID`) VALUES (1, 40);

INSERT INTO `lkpagegroup` (`pageID` ,`groupID`) VALUES ('40', '1');


ALTER TABLE  `schedule_detail` ADD  `DisplayOrder` INT NOT NULL DEFAULT  '0';

UPDATE `version` SET `app_ver` = '1.3.3', `XmdsVersion` = 3;
UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE';
UPDATE `version` SET `DBVersion` = '45';
