ALTER TABLE `SITE`
	DROP COLUMN `SHOW_SECTION_STUDENTS`;

--  ID: 108069 UUID: '931438dc-b0e2-4d2a-b017-1a449adf59e3'
UPDATE `ACCESSIBLE_ITEM` AS own SET own.`NAME` = 'en6:Eventspt7:Eventos' WHERE own.`UUID` = '931438dc-b0e2-4d2a-b017-1a449adf59e3';

-- 
--  Inserting new functionalities
-- 

--  ID: 108269 UUID: '95b0bf15-1f4d-4430-815a-dfc1fb373ea6'
INSERT INTO `ACCESSIBLE_ITEM` (`UUID`, `OJB_CONCRETE_CLASS`, `KEY_ROOT_DOMAIN_OBJECT`, `KEY_PARENT`, `KEY_MODULE`, `KEY_AVAILABILITY_POLICY`, `NAME`, `TITLE`, `DESCRIPTION`, `PATH`, `PREFIX`, `RELATIVE`, `ENABLED`, `PARAMETERS`, `ORDER_IN_MODULE`, `VISIBLE`, `MAXIMIZED`, `PRINCIPAL`, `KEY_SUPERIOR_SECTION`, `SECTION_ORDER`, `KEY_SITE`, `LAST_MODIFIED_DATE_YEAR_MONTH_DAY`, `KEY_SECTION`, `ITEM_ORDER`, `INFORMATION`, `KEY_FUNCTIONALITY`) SELECT '95b0bf15-1f4d-4430-815a-dfc1fb373ea6', 'net.sourceforge.fenixedu.domain.functionalities.ConcreteFunctionality', 1, NULL, `ID_INTERNAL`, NULL, 'en7:Degreespt6:Cursos', NULL, NULL, '/degrees.do', NULL, 1, 1, 'selectedDepartmentUnitID', 6, 1, 0, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM `ACCESSIBLE_ITEM` WHERE `UUID` = '3adea1cf-e612-456f-b8be-c24882b77c3e';
INSERT INTO `AVAILABILITY_POLICY` (`OJB_CONCRETE_CLASS`, `KEY_ROOT_DOMAIN_OBJECT`, `KEY_ACCESSIBLE_ITEM`, `EXPRESSION`, `TARGET_GROUP`) SELECT 'net.sourceforge.fenixedu.domain.functionalities.ExpressionGroupAvailability', 1, `ID_INTERNAL`, 'ifTrue($I(selectedDepartmentUnitID, \'organizationalStructure.DepartmentUnit\').site.showSectionDegrees)', 'ifTrue($I(selectedDepartmentUnitID, \'organizationalStructure.DepartmentUnit\').site.showSectionDegrees)' FROM `ACCESSIBLE_ITEM` WHERE `UUID` = '95b0bf15-1f4d-4430-815a-dfc1fb373ea6';
UPDATE `ACCESSIBLE_ITEM` AS f, `AVAILABILITY_POLICY` AS ap SET f.`KEY_AVAILABILITY_POLICY` = ap.`ID_INTERNAL` WHERE f.`UUID` = '95b0bf15-1f4d-4430-815a-dfc1fb373ea6' AND ap.`KEY_ACCESSIBLE_ITEM` = f.`ID_INTERNAL`;

-- add functionality section for degrees
INSERT INTO `ACCESSIBLE_ITEM` (`OJB_CONCRETE_CLASS`, `KEY_ROOT_DOMAIN_OBJECT`, `VISIBLE`, `KEY_SITE`, `SECTION_ORDER`, `KEY_FUNCTIONALITY`) 
	SELECT 'net.sourceforge.fenixedu.domain.FunctionalitySection', 1, 1, -1, 5, AI.ID_INTERNAL
	FROM `ACCESSIBLE_ITEM` AS AI WHERE AI.UUID = '95b0bf15-1f4d-4430-815a-dfc1fb373ea6';

UPDATE `ACCESSIBLE_ITEM` AS AI, `SITE` AS S
	SET AI.`KEY_SITE` = S.`ID_INTERNAL`
	WHERE AI.`OJB_CONCRETE_CLASS` LIKE 'net.sourceforge.fenixedu.domain.FunctionalitySection'
		AND AI.`KEY_SITE` = -1
		AND S.`OJB_CONCRETE_CLASS` LIKE 'net.sourceforge.fenixedu.domain.SiteTemplate'
		AND S.`SITE_TYPE` LIKE 'net.sourceforge.fenixedu.domain.DepartmentSite';

-- correct "Eventos" order
UPDATE `ACCESSIBLE_ITEM` AS AI, `ACCESSIBLE_ITEM` AS F SET AI.`SECTION_ORDER` = 0
WHERE AI.`KEY_FUNCTIONALITY` = F.`ID_INTERNAL` AND F.`UUID` = '96b1a0d4-6469-41b9-8de7-71caebe8f98c';

UPDATE `ACCESSIBLE_ITEM` AS AI, `ACCESSIBLE_ITEM` AS F SET AI.`SECTION_ORDER` = 1
WHERE AI.`KEY_FUNCTIONALITY` = F.`ID_INTERNAL` AND F.`UUID` = 'c113952d-6c49-44c0-b30b-d56ab1d2d047';

UPDATE `ACCESSIBLE_ITEM` AS AI, `ACCESSIBLE_ITEM` AS F SET AI.`SECTION_ORDER` = 2
WHERE AI.`KEY_FUNCTIONALITY` = F.`ID_INTERNAL` AND F.`UUID` = '931438dc-b0e2-4d2a-b017-1a449adf59e3';

UPDATE `ACCESSIBLE_ITEM` AS AI, `ACCESSIBLE_ITEM` AS F SET AI.`SECTION_ORDER` = 3
WHERE AI.`KEY_FUNCTIONALITY` = F.`ID_INTERNAL` AND F.`UUID` = '173e00ae-66ff-408b-a8ce-d4a4011fe3f5';

UPDATE `ACCESSIBLE_ITEM` AS AI, `ACCESSIBLE_ITEM` AS F SET AI.`SECTION_ORDER` = 4
WHERE AI.`KEY_FUNCTIONALITY` = F.`ID_INTERNAL` AND F.`UUID` = '3bd0759b-edca-4ff7-87d6-6e03b6be1b3c';

UPDATE `ACCESSIBLE_ITEM` AS AI, `ACCESSIBLE_ITEM` AS F SET AI.`SECTION_ORDER` = 6
WHERE AI.`KEY_FUNCTIONALITY` = F.`ID_INTERNAL` AND F.`UUID` = '85372e2e-ffe0-48ff-a758-1017a11c797f';

-- 
--  Change availability of "Anúncios" e "Eventos"
-- 

--  ID: 26327 UUID: 'c113952d-6c49-44c0-b30b-d56ab1d2d047'
UPDATE `ACCESSIBLE_ITEM` AS own SET own.`KEY_AVAILABILITY_POLICY` = NULL WHERE own.`UUID` = 'c113952d-6c49-44c0-b30b-d56ab1d2d047';
INSERT INTO `AVAILABILITY_POLICY` (`OJB_CONCRETE_CLASS`, `KEY_ROOT_DOMAIN_OBJECT`, `KEY_ACCESSIBLE_ITEM`, `EXPRESSION`, `TARGET_GROUP`) SELECT 'net.sourceforge.fenixedu.domain.functionalities.ExpressionGroupAvailability', 1, `ID_INTERNAL`, 'ifTrue($I(selectedDepartmentUnitID, \'organizationalStructure.DepartmentUnit\').site.showAnnouncements)', 'ifTrue($I(selectedDepartmentUnitID, \'organizationalStructure.DepartmentUnit\').site.showAnnouncements)' FROM `ACCESSIBLE_ITEM` WHERE `UUID` = 'c113952d-6c49-44c0-b30b-d56ab1d2d047';
UPDATE `ACCESSIBLE_ITEM` AS f, `AVAILABILITY_POLICY` AS ap SET f.`KEY_AVAILABILITY_POLICY` = ap.`ID_INTERNAL` WHERE f.`UUID` = 'c113952d-6c49-44c0-b30b-d56ab1d2d047' AND ap.`KEY_ACCESSIBLE_ITEM` = f.`ID_INTERNAL`;

--  ID: 108069 UUID: '931438dc-b0e2-4d2a-b017-1a449adf59e3'
UPDATE `ACCESSIBLE_ITEM` AS own SET own.`KEY_AVAILABILITY_POLICY` = NULL WHERE own.`UUID` = '931438dc-b0e2-4d2a-b017-1a449adf59e3';
INSERT INTO `AVAILABILITY_POLICY` (`OJB_CONCRETE_CLASS`, `KEY_ROOT_DOMAIN_OBJECT`, `KEY_ACCESSIBLE_ITEM`, `EXPRESSION`, `TARGET_GROUP`) SELECT 'net.sourceforge.fenixedu.domain.functionalities.ExpressionGroupAvailability', 1, `ID_INTERNAL`, 'ifTrue($I(selectedDepartmentUnitID, \'organizationalStructure.DepartmentUnit\').site.showEvents)', 'ifTrue($I(selectedDepartmentUnitID, \'organizationalStructure.DepartmentUnit\').site.showEvents)' FROM `ACCESSIBLE_ITEM` WHERE `UUID` = '931438dc-b0e2-4d2a-b017-1a449adf59e3';
UPDATE `ACCESSIBLE_ITEM` AS f, `AVAILABILITY_POLICY` AS ap SET f.`KEY_AVAILABILITY_POLICY` = ap.`ID_INTERNAL` WHERE f.`UUID` = '931438dc-b0e2-4d2a-b017-1a449adf59e3' AND ap.`KEY_ACCESSIBLE_ITEM` = f.`ID_INTERNAL`;
