CREATE TABLE `myemergency_files_entries` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT 'police',
  `file_id` varchar(90) NOT NULL DEFAULT '',
  `file_entry_id` varchar(90) NOT NULL DEFAULT '',
  `content` TEXT,
  `is_wanted` tinyint(1) NOT NULL DEFAULT 0,
  `is_wanted_by` varchar(90) NOT NULL DEFAULT '',
  `is_wanted_done` tinyint(1) NOT NULL DEFAULT 0,
  `is_wanted_reason` TEXT,
  `type_of_entry` int(11) NOT NULL DEFAULT 0,
  `fine` int(11) NOT NULL DEFAULT 0,
  `detention_time` int(11) NOT NULL DEFAULT 0,
  `closed` tinyint(1) NOT NULL DEFAULT 0,
  `shared` TINYINT(1) NOT NULL DEFAULT 0,
  `injury_head` tinyint(1) NOT NULL DEFAULT 0,
  `injury_left_shoulder` tinyint(1) NOT NULL DEFAULT 0,
  `injury_right_shoulder` tinyint(1) NOT NULL DEFAULT 0,
  `injury_left_arm` tinyint(1) NOT NULL DEFAULT 0,
  `injury_right_arm` tinyint(1) NOT NULL DEFAULT 0,
  `injury_chest` tinyint(1) NOT NULL DEFAULT 0,
  `injury_stomach` tinyint(1) NOT NULL DEFAULT 0,
  `injury_left_leg` tinyint(1) NOT NULL DEFAULT 0,
  `injury_right_leg` tinyint(1) NOT NULL DEFAULT 0,
  `injury_left_hand` tinyint(1) NOT NULL DEFAULT 0,
  `injury_right_hand` tinyint(1) NOT NULL DEFAULT 0,
  `injury_left_foot` tinyint(1) NOT NULL DEFAULT 0,
  `injury_right_foot` tinyint(1) NOT NULL DEFAULT 0,
  `injury_summary` TEXT,
  `intensity_of_wounds` VARCHAR(128) NOT NULL DEFAULT '',
  `type_of_bleeding` VARCHAR(128) NOT NULL DEFAULT '',
  `treatment` VARCHAR(128) NOT NULL DEFAULT '',
  `needs_follow_up_treatment` TINYINT(1) NOT NULL DEFAULT 0,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp(),
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_file_id` (`file_id`),
  KEY `idx_is_wanted_done` (`is_wanted_done`),
  KEY `idx_is_wanted` (`is_wanted`)
);

CREATE TABLE `myemergency_reg_weapons` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT 'police',
  `serialno` VARCHAR(128) NOT NULL DEFAULT '',
  `owner` VARCHAR(90) NULL DEFAULT NULL,
  `weapontype` VARCHAR(128) NOT NULL DEFAULT '',
  `weaponmodel` VARCHAR(128) NOT NULL DEFAULT '',
  `others` TEXT,
  `is_wanted` TINYINT(1) NOT NULL DEFAULT 0,
  `is_wanted_reason` VARCHAR(512) NOT NULL DEFAULT '',
  
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp,
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE current_timestamp,
  PRIMARY KEY (`id`),
  INDEX `idx_serialno` (`serialno` ASC) ,
  INDEX `idx_owner` (`owner` ASC) ,
  INDEX `idx_weapontype` (`weapontype` ASC) ,
  INDEX `idx_weaponmodel` (`weaponmodel` ASC) );


  CREATE TABLE `myemergency_criminal_complaint` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT 'police',
  `charge_from` VARCHAR(90) NOT NULL DEFAULT '',
  `perpetrator` VARCHAR(90) NOT NULL DEFAULT '',
  `perpetrator_description` TEXT,
  `state` INT NOT NULL DEFAULT 0,
  `act_of_crime` TEXT,
  `notes` TEXT,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp,
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE current_timestamp,
  PRIMARY KEY (`id`),
  INDEX `idx_from` (`charge_from` ASC) ,
  INDEX `idx_perpetrator` (`perpetrator` ASC) );

CREATE TABLE `myemergency_investigations` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT 'police',
  `name` VARCHAR(90) NOT NULL DEFAULT '',
  `reason` TEXT,
  `closed` tinyint(1) NOT NULL DEFAULT 0,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp,
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE current_timestamp,
  PRIMARY KEY (`id`),
  INDEX `idx_name` (`name` ASC) );

CREATE TABLE `myemergency_investigations_entries` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `investigation_id` int(11) NOT NULL DEFAULT 0,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT 'police',
  `content` TEXT,
  `is_important_entry` tinyint(1) NOT NULL DEFAULT 0,
  `createdby` VARCHAR(90) NOT NULL DEFAULT 0,
  `createddate` timestamp NOT NULL DEFAULT current_timestamp(),
  `changedby` VARCHAR(90) NOT NULL DEFAULT 0,
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;


CREATE TABLE `myemergency_law_books` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT 'police',
  `name` varchar(90) NOT NULL DEFAULT '',
  `short_name` varchar(90) NOT NULL DEFAULT '',
  `deleted` TINYINT(1) NOT NULL DEFAULT 0,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp,
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE current_timestamp,
  PRIMARY KEY (`id`),
  KEY `idx_name` (`name`),
  KEY `idx_short_name` (`short_name`)
) ENGINE=InnoDB;

CREATE TABLE `myemergency_law_book_laws` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `lawbook_id` int(11) NOT NULL DEFAULT 0,
  `fromsystem` varchar(50) NOT NULL DEFAULT 'police',
  `crime` varchar(90) NOT NULL DEFAULT '',
  `paragraph` varchar(90) NOT NULL DEFAULT '',
  `minimum_penalty` int(11) NOT NULL DEFAULT 0,
  `detention_time` int(11) NOT NULL DEFAULT 0,
  `others` text DEFAULT NULL,
  `deleted` tinyint(1) NOT NULL DEFAULT 0,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp(),
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `content` text DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;


CREATE TABLE `myemergency_files_entries_laws_relation` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT 'police',
  `file_entry_id` varchar(90) NOT NULL DEFAULT '',
  `lawbook_law_id` INT  NOT NULL DEFAULT 0,
  `amount` INT  NOT NULL DEFAULT 0,
  `historized_minimum_penalty` INT  NOT NULL DEFAULT 0,
  `historized_detention_time` INT  NOT NULL DEFAULT 0,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp(),
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_file_entry_id` (`file_entry_id`)
);

CREATE TABLE `myemergency_licenses` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT 'police',
  `string_key` VARCHAR(60),
  `name` VARCHAR(90) NOT NULL DEFAULT '',
  `createdby` VARCHAR(90) NOT NULL DEFAULT '',
  `createddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
  `changedby` VARCHAR(90) NOT NULL DEFAULT '',
  `changeddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(),
  PRIMARY KEY (`id`),
  INDEX `idx_name` (`name` ASC));

INSERT INTO `myemergency_possible_rights` (`fromsystem`, `right_key`, `sortorder`) VALUES 
('medic','files.view',1000),
('police','files.view',1000),
('medic','files.edit',1010),
('police','files.edit',1010),
('medic','files.delete',1020),
('police','files.delete',1020),
('medic','files.close',1030),
('police','files.close',1030),
('medic','files.blacken',1040),
('police','files.blacken',1040),
('medic','files.licenses',1050),
('police','files.licenses',1050),
('medic','filesentry.finish',1060),
('police','filesentry.finish',1060),
('police','criminalcomplaint.view',2000),
('police','criminalcomplaint.edit',2010),
('police','criminalcomplaint.delete',2020),
('police','manhunt.view',3000),
('police','manhunt.add',3010),
('police','manhunt.finish',3020),
('police','regvehicles.view',4000),
('police','regvehicles.edit',4010),
('police','regvehicles.delete',4020),
('police','regweapons.view',5000),
('police','regweapons.edit',5010),
('police','regweapons.delete',5020),
('medic','employees.view',6000),
('police','employees.view',6000),
('medic','employees.suspend',6010),
('police','employees.suspend',6010),
('medic','employeesentries.view',7000),
('police','employeesentries.view',7000),
('medic','employeesentries.edit',7010),
('police','employeesentries.edit',7010),
('medic','employeesentries.delete',7020),
('police','employeesentries.delete',7020),
('medic','employeesentries.finish',7030),
('police','employeesentries.finish',7030),
('medic','trainings.view',8000),
('police','trainings.view',8000),
('medic','trainings.edit',8010),
('police','trainings.edit',8010),
('medic','trainings.delete',8020),
('police','trainings.delete',8020),
('medic','trainingsemployees.view',9000),
('police','trainingsemployees.view',9000),
('medic','trainingsemployees.edit',9010),
('police','trainingsemployees.edit',9010),
('police','lawbooks.view',10000),
('police','lawbooks.edit',10010),
('police','lawbooks.delete',10020),
('police','investigation.view',11000),
('police','investigation.edit',11010),
('police','investigation.delete',11020),
('police','investigation.close',11030),
('medic','missionreport.view',12000),
('police','missionreport.view',12000),
('medic','missionreport.edit',12010),
('police','missionreport.edit',12010),
('medic','missionreport.delete',12020),
('police','missionreport.delete',12020),
('medic','missionreport.viewall',12030),
('police','missionreport.viewall',12030),
('medic','radiostate.edit',13000),
('police','radiostate.edit',13000),
('medic','radiostate.delete',13010),
('police','radiostate.delete',13010),
('medic','emergencyvehicle.edit',14000),
('police','emergencyvehicle.edit',14000),
('medic','emergencyvehicle.delete',14010),
('police','emergencyvehicle.delete',14010),
('medic','controlcentre.view',15000),
('police','controlcentre.view',15000),
('medic','controlcentre.take',15010),
('police','controlcentre.take',15010),
('police','licenses.view',16000),
('police','licenses.edit',16010),
('police','licenses.delete',16020),
('police','employees.edit',6005),
('medic','employees.edit',6005),
('medic','files.share',1041),
('police','files.share',1041),
('medic','sharedfiles.view',1042),
('police','sharedfiles.view',1042),
('police','speedcams.view',5050),
('police','speedcamsprofit.view',5060),
('medic','licenses.view',16000),
('medic','licenses.edit',16010),
('medic','licenses.delete',16020),
('police','notes.edit',17000),
('police','notes.delete',17010),
('medic','notes.edit',17000),
('medic','notes.delete',17010),
('police','evidencerooms.view',18000),
('police','evidencerooms.edit',18010),
('police','evidencerooms.delete',18020),
('police','prison.view',19000)
;



CREATE TABLE `myemergency_files_licences` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT 'police',
  `file_id` VARCHAR(90) NOT NULL,
  `license_id` INT NOT NULL,
  `createdby` VARCHAR(90) NOT NULL DEFAULT '',
  `createddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
  `changedby` VARCHAR(90) NOT NULL DEFAULT '',
  `changeddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(),
  PRIMARY KEY (`file_id`, `license_id`),
  UNIQUE INDEX `id_UNIQUE` (`id` ASC) );


  CREATE TABLE `myemergency_files_shared` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `file_id` varchar(90) NOT NULL DEFAULT '',
  `fromsystem` varchar(50) NOT NULL DEFAULT 'police',
  `is_shared` tinyint(1) NOT NULL DEFAULT 0,
  `createdby` VARCHAR(90) NOT NULL DEFAULT '',
  `createddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
  `changedby` VARCHAR(90) NOT NULL DEFAULT '',
  `changeddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(),
  PRIMARY KEY (`file_id`,`fromsystem`),
  UNIQUE KEY `id_UNIQUE` (`id`)
);


CREATE TABLE `mymdt_evidencerooms` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT 'police',
  `name` varchar(90) NOT NULL DEFAULT '',
  `deleted` TINYINT(1) NOT NULL DEFAULT 0,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp,
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp ON UPDATE current_timestamp,
  PRIMARY KEY (`id`),
  KEY `idx_name` (`name`)
);

CREATE TABLE `mymdt_evidenceroom_articles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `evidenceroom_id` int(11) NOT NULL DEFAULT 0,
  `fromsystem` varchar(50) NOT NULL DEFAULT 'police',
  `file_id` varchar(90) NOT NULL,
  `name` varchar(90) NOT NULL DEFAULT '',
  `amount` int NOT NULL DEFAULT 0,
  `state` int NOT NULL DEFAULT 0,
  `others` text DEFAULT NULL,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp(),
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_evidenceroom_id` (`evidenceroom_id`),
  KEY `idx_state` (`state`)
);