-- Autor: Fernando Salas
-- Fecha: 2018-01-16
-- Calendario de Eventos
CREATE TABLE `event` (
`serial_event` INT NOT NULL AUTO_INCREMENT,
`name_event` TEXT NOT NULL,
`description_event` TEXT NULL DEFAULT NULL,
`start_date_event` DATETIME NOT NULL,
`end_date_event` DATETIME NOT NULL,
`status_event` ENUM('ACTIVE', 'INACTIVE') NULL DEFAULT 'ACTIVE',
PRIMARY KEY (`serial_event`))
ENGINE = InnoDB;

CREATE TABLE `event_profile` (
`serial_evpf` INT NOT NULL AUTO_INCREMENT,
`serial_event` INT NOT NULL,
`serial_prf` INT NOT NULL,
`status_evpf` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
PRIMARY KEY (`serial_evpf`),
INDEX `serial_event_idx` (`serial_event` ASC),
INDEX `serial_prf_idx` (`serial_prf` ASC),
CONSTRAINT `serial_event`
FOREIGN KEY (`serial_event`)
REFERENCES `event` (`serial_event`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `serial_prf`
FOREIGN KEY (`serial_prf`)
REFERENCES `profile` (`serial_prf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);


CREATE TABLE `event_section` (
`serial_evset` INT NOT NULL AUTO_INCREMENT,
`serial_event` INT NOT NULL,
`serial_set` INT NOT NULL,
`status_evset` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
PRIMARY KEY (`serial_evset`),
INDEX `event_idx` (`serial_event` ASC),
INDEX `section_idx` (`serial_set` ASC),
CONSTRAINT `event`
FOREIGN KEY (`serial_event`)
REFERENCES `event` (`serial_event`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `section`
FOREIGN KEY (`serial_set`)
REFERENCES `section` (`serial_set`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);

ALTER TABLE `section` 
ADD COLUMN `color_set` VARCHAR(45) NOT NULL DEFAULT '#3a87ad';

ALTER TABLE `event_section`
DROP FOREIGN KEY `section`;
ALTER TABLE `event_section`
CHANGE COLUMN `serial_set` `serial_set` INT(11) NULL ;
ALTER TABLE `event_section`
ADD CONSTRAINT `section`
  FOREIGN KEY (`serial_set`)
  REFERENCES `section` (`serial_set`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;


-- Administración de Eventos
insert into process(serial_prc,prc_serial_prc,name_prc,link_prc,weight_prc)
values(648,(select prc.serial_prc from process prc where prc.name_prc like '%Agenda%'),'Administración de Eventos','laravel/public/event',1.00);

insert into allowed_pages_by_process(serial_prc,url_dsc)
values
(648,'eventcontroller@getindex'),
(648,'eventcontroller@postcalendar'),
(648,'eventcontroller@postevents'),
(648,'eventcontroller@getshowcreateevent'),
(648,'eventcontroller@getshoweditevent'),
(648,'eventcontroller@postcreateevent'),
(648,'eventcontroller@posteditevent');

-- Eventos de cada usuario según sus perfiles asignados y activos

insert into process(serial_prc,prc_serial_prc,name_prc,link_prc,weight_prc)
values(649,(select prc.serial_prc from process prc where prc.name_prc like '%Agenda%'),'Calendario de Eventos Generales','laravel/public/event/events-user',2.00);

insert into allowed_pages_by_process(serial_prc,url_dsc)
values
(649,'eventcontroller@geteventsuser'),
(649,'eventcontroller@posteventsuser'),
(649,'eventcontroller@getshoweditevent');








