UPDATE resource_status SET description = 'Bookings are confirmed by resource admin' WHERE id = '5';
UPDATE resource_status SET description = 'Bookings are confirmed automatically via real-time usage tracking' WHERE id = '4';
INSERT INTO `helpdesk_category`(`id`, `label`) VALUES (NULL,'Maintenance log');

CREATE TABLE `onboarding_users` ( `id` INT NOT NULL AUTO_INCREMENT , `onboarding` INT NOT NULL , `user` INT NOT NULL , `dismiss` INT NOT NULL , `last_update` DATETIME NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `onboarding_users` ADD CONSTRAINT `onboarding_ibfk2` FOREIGN KEY (`user`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
CREATE TABLE `onboarding_dismissall` ( `id` INT NOT NULL AUTO_INCREMENT , `user` INT NOT NULL , `dismiss` INT NOT NULL , `date` DATETIME NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;

CREATE TABLE `dmp_config` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(45) NOT NULL,
  `description` TEXT NULL,
  `value` TEXT NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `id_UNIQUE` (`id` ASC))
  ENGINE = InnoDB;

CREATE TABLE `dmp_instance` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `label` VARCHAR(45) NOT NULL,
  `description` TEXT NULL,
  `permission` TINYINT(4) NOT NULL,
  `active` TINYINT(4) NOT NULL,
  `date_created` DATETIME NOT NULL,
  `last_update` DATETIME NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `id_UNIQUE` (`id` ASC))
  ENGINE = InnoDB;

CREATE TABLE `dmp_resource` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `instance` INT(11) NOT NULL,
  `type` VARCHAR(45) NOT NULL,
  `resource` INT NOT NULL,
  `date_created` DATETIME NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `id_UNIQUE` (`id` ASC))
  ENGINE = InnoDB;

ALTER TABLE `dmp_resource` ADD INDEX `FK_inst_idx` (`instance` ASC);
ALTER TABLE `dmp_resource` ADD CONSTRAINT FK_inst FOREIGN KEY (`instance`) REFERENCES `dmp_instance`(`id`)
  ON DELETE CASCADE
  ON UPDATE CASCADE;

-- dmp general configuration
INSERT INTO dmp_config VALUES (NULL, 'host_internal','File server for internal users', 'https://www.igccloud.host/');
INSERT INTO dmp_config VALUES (NULL, 'host_external','File server for external users', '');
INSERT INTO dmp_config VALUES (NULL, 'separator','Character that is used to separate labels that make up data management folders\' name', '_');
INSERT INTO dmp_config VALUES (NULL, 'requests','Whether data management is available for requests', '1');
INSERT INTO dmp_config VALUES (NULL, 'requests_path','Path to save requests\' data files, relative to file server root path', 'requests');
INSERT INTO dmp_config VALUES (NULL, 'requests_folder_name','Default folder name for requests', '$date.$name.$request_id');
INSERT INTO dmp_config VALUES (NULL, 'calendars','Whether data management is available for bookings', '0');
INSERT INTO dmp_config VALUES (NULL, 'calendars_path','Path to save calendar data files, relative to file server root path', 'calendars');
INSERT INTO dmp_config VALUES (NULL, 'calendars_folder_name','Default folder name for calendars', '$date.$time.$name.$booking_id');
INSERT INTO dmp_config VALUES (NULL, 'notes','Whether data management is available for notes &amp; SOPs', '1');
INSERT INTO dmp_config VALUES (NULL, 'notes_path','Path to save notes &amp; SOP files, relative to file server root path', 'notes');
INSERT INTO dmp_config VALUES (NULL, 'notes_folder_name','Default folder name for calendars', '$title.ver-$version (#$user_id)');
INSERT INTO dmp_config VALUES (NULL, 'date_format','Date format for folder names', 'Ymd');
INSERT INTO dmp_config VALUES (NULL, 'time_format','Time format for folder names', 'Hi');
INSERT INTO dmp_config VALUES (NULL, 'base_url','Base URL for creating new folders and to put files_sharing, relative to the server path', 'remote.php/dav/files/');
INSERT INTO dmp_config VALUES (NULL, 'share_url','Base URL for all calls to the share API, relative to the server path', 'ocs/v1.php/apps/files_sharing/api/v1/');
INSERT INTO dmp_config VALUES (NULL, 'files_url','Base URL to files when logged, relative to the server', 'index.php/apps/files/?dir=/');
INSERT INTO dmp_config VALUES (NULL, 'permissions','Map of file server permissions, in JSON format','{"1":"read","2":"update","4":"create","8":"delete","15":"write"}');


-- privileges group
INSERT INTO config VALUES (NULL, 'dmp', 0);
INSERT INTO privileges_group VALUES (NULL, 'Data management plan', 'General data management configuration');
INSERT INTO privileges VALUES (NULL, 'dmp', 'Data management plan', 'Edit data management plan configurations', 'dmp', NULL, 6);

-- flag for Bookings
ALTER TABLE calendar ADD COLUMN `remote_server` TINYINT(4) NULL DEFAULT 0 AFTER `latch_code`;
