CREATE TABLE IF NOT EXISTS `svt_plans` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  `n_virtual_tours` int(11) NOT NULL DEFAULT '-1',
  `n_rooms` int(11) NOT NULL DEFAULT '-1',
  `n_markers` int(11) NOT NULL DEFAULT '-1',
  `n_pois` int(11) NOT NULL DEFAULT '-1',
  `days` int(11) NOT NULL DEFAULT '-1',
  `create_landing` tinyint(1) NOT NULL DEFAULT '1',
  `create_showcase` tinyint(1) NOT NULL DEFAULT '1',
  `create_gallery` tinyint(1) NOT NULL DEFAULT '1',
  `create_presentation` tinyint(1) NOT NULL DEFAULT '1',
  `enable_live_session` tinyint(1) NOT NULL DEFAULT '1',
  `enable_meeting` tinyint(1) NOT NULL DEFAULT '1',
  `enable_chat` tinyint(1) NOT NULL DEFAULT '1',
  `enable_voice_commands` tinyint(1) NOT NULL DEFAULT '1',
  `enable_share` tinyint(1) NOT NULL DEFAULT '1',
  `enable_device_orientation` tinyint(1) NOT NULL DEFAULT '1',
  `enable_webvr` tinyint(1) NOT NULL DEFAULT '1',
  `enable_logo` tinyint(1) NOT NULL DEFAULT '1',
  `enable_nadir_logo` tinyint(1) NOT NULL DEFAULT '1',
  `enable_song` tinyint(1) NOT NULL DEFAULT '1',
  `enable_forms` tinyint(1) NOT NULL DEFAULT '1',
  `enable_annotations` tinyint(1) NOT NULL DEFAULT '1',
  `enable_rooms_multiple` tinyint(1) NOT NULL DEFAULT '1',
  `enable_rooms_protect` tinyint(1) NOT NULL DEFAULT '1',
  `enable_info_box` tinyint(1) NOT NULL DEFAULT '1',
  `enable_maps` tinyint(1) NOT NULL DEFAULT '1',
  `enable_icons_library` tinyint(1) NOT NULL DEFAULT '1',
  `enable_password_tour` tinyint(1) NOT NULL DEFAULT '1',
  `enable_expiring_dates` tinyint(1) NOT NULL DEFAULT '1',
  `enable_statistics` tinyint(1) NOT NULL DEFAULT '1',
  `enable_flyin` tinyint(1) NOT NULL DEFAULT '1',
  `enable_auto_rotate` tinyint(1) NOT NULL DEFAULT '1',
  `enable_multires` tinyint(1) NOT NULL DEFAULT '1',
  `max_file_size_upload` int(11) NOT NULL DEFAULT '-1',
  `price` float NOT NULL DEFAULT '0',
  `currency` varchar(3) NOT NULL DEFAULT 'USD',
  `frequency` enum('one_time','recurring') DEFAULT 'recurring',
  `interval_count` int(11) NOT NULL DEFAULT '1',
  `id_product_stripe` varchar(50) DEFAULT NULL,
  `id_price_stripe` varchar(50) DEFAULT NULL,
  `custom_features` text DEFAULT NULL,
  `visible` tinyint(1) NOT NULL DEFAULT '1',
  `external_url` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

INSERT IGNORE INTO `svt_plans` (`id`, `name`) VALUES(1, 'Unlimited');

CREATE TABLE IF NOT EXISTS `svt_users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(100) NOT NULL DEFAULT '',
  `email` varchar(100) DEFAULT NULL,
  `password` varchar(200) DEFAULT NULL,
  `role` varchar(50) DEFAULT 'customer',
  `id_plan` bigint(20) DEFAULT '1',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `forgot_code` varchar(16) DEFAULT NULL,
  `hash` varchar(32) DEFAULT NULL,
  `registration_date` timestamp DEFAULT CURRENT_TIMESTAMP,
  `expire_plan_date` datetime DEFAULT NULL,
  `id_customer_stripe` varchar(50) DEFAULT NULL,
  `id_subscription_stripe` varchar(50) DEFAULT NULL,
  `status_subscription_stripe` tinyint(1) NOT NULL DEFAULT '0',
  `language` varchar(10) DEFAULT NULL,
  `avatar` varchar(50) DEFAULT NULL,
  `first_name` varchar(100) DEFAULT NULL,
  `last_name` varchar(100) DEFAULT NULL,
  `company` varchar(100) DEFAULT NULL,
  `tax_id` varchar(100) DEFAULT NULL,
  `street` varchar(100) DEFAULT NULL,
  `city` varchar(100) DEFAULT NULL,
  `province` varchar(100) DEFAULT NULL,
  `postal_code` varchar(100) DEFAULT NULL,
  `country` varchar(100) DEFAULT NULL,
  `tel` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

INSERT IGNORE INTO `svt_users` (`id`, `username`, `password`, `role`) VALUES(1, '<USER_NAME>', MD5(<PASSWORD>), 'administrator');

CREATE TABLE IF NOT EXISTS `svt_categories` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_virtualtours` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_user` int(11) unsigned DEFAULT NULL,
  `author` varchar(50) DEFAULT NULL,
  `date_created` date NOT NULL,
  `name` varchar(100) DEFAULT NULL,
  `code` varchar(100) DEFAULT NULL,
  `hfov` int(11) NOT NULL DEFAULT '100',
  `min_hfov` int(11) NOT NULL DEFAULT '60',
  `max_hfov` int(11) NOT NULL DEFAULT '100',
  `song` varchar(50) DEFAULT NULL,
  `song_autoplay` tinyint(1) NOT NULL DEFAULT '0',
  `logo` varchar(50) DEFAULT NULL,
  `link_logo` varchar(250) DEFAULT NULL,
  `nadir_logo` varchar(50) DEFAULT NULL,
  `nadir_size` varchar(25) NOT NULL DEFAULT 'small',
  `autorotate_speed` int(11) NOT NULL DEFAULT '0',
  `autorotate_inactivity` int(11) NOT NULL DEFAULT '0',
  `markers_icon` varchar(50) NOT NULL DEFAULT 'fas fa-chevron-circle-up',
  `markers_id_icon_library` bigint(20) unsigned NOT NULL DEFAULT 0,
  `markers_background` varchar(25) NOT NULL DEFAULT 'rgba(255,255,255,0.7)',
  `markers_color` varchar(25) NOT NULL DEFAULT '#000000',
  `markers_show_room` tinyint(1) NOT NULL DEFAULT '1',
  `markers_tooltip_type` enum('none','text','preview','preview_square','preview_rect','room_name') NOT NULL DEFAULT 'none',
  `pois_icon` varchar(50) NOT NULL DEFAULT 'fas fa-info-circle',
  `pois_id_icon_library` bigint(20) unsigned NOT NULL DEFAULT 0,
  `pois_background` varchar(25) NOT NULL DEFAULT 'rgba(255,255,255,0.7)',
  `pois_color` varchar(25) NOT NULL DEFAULT '#000000',
  `pois_style` tinyint(1) NOT NULL DEFAULT '0',
  `pois_tooltip_type` enum('none','text') NOT NULL DEFAULT 'none',
  `arrows_nav` tinyint(1) NOT NULL DEFAULT '1',
  `info_box` longtext,
  `password` varchar(200) DEFAULT NULL,
  `voice_commands` tinyint(1) NOT NULL DEFAULT '0',
  `compass` tinyint(1) NOT NULL DEFAULT '1',
  `background_image` varchar(50) DEFAULT NULL,
  `auto_start` tinyint(1) NOT NULL DEFAULT '1',
  `description` text DEFAULT NULL,
  `ga_tracking_id` varchar(25) DEFAULT NULL,
  `friendly_url` varchar(100) DEFAULT NULL,
  `compress_jpg` int(11) NOT NULL DEFAULT '90',
  `max_width_compress` int(11) NOT NULL DEFAULT '8192',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `sameAzimuth` tinyint(1) NOT NULL DEFAULT '0',
  `auto_show_slider` tinyint(1) NOT NULL DEFAULT '0',
  `form_enable` tinyint(1) NOT NULL DEFAULT '0',
  `form_icon` varchar(50) NOT NULL DEFAULT 'fas fa-file-signature',
  `form_content` text DEFAULT NULL,
  `html_landing` longtext,
  `fb_messenger` tinyint(1) NOT NULL DEFAULT '0',
  `fb_page_id` varchar(50) DEFAULT NULL,
  `whatsapp_chat` tinyint(1) NOT NULL DEFAULT '0',
  `whatsapp_number` varchar(25) DEFAULT NULL,
  `show_info` tinyint(1) NOT NULL DEFAULT '1',
  `show_vt_title` tinyint(1) NOT NULL DEFAULT '1',
  `show_gallery` tinyint(1) NOT NULL DEFAULT '1',
  `show_chat` tinyint(1) NOT NULL DEFAULT '1',
  `show_icons_toggle` tinyint(1) NOT NULL DEFAULT '1',
  `show_presentation` tinyint(1) NOT NULL DEFAULT '1',
  `show_main_form` tinyint(1) NOT NULL DEFAULT '1',
  `show_share` tinyint(1) NOT NULL DEFAULT '1',
  `show_device_orientation` tinyint(1) NOT NULL DEFAULT '1',
  `show_webvr` tinyint(1) NOT NULL DEFAULT '1',
  `show_map` tinyint(1) NOT NULL DEFAULT '1',
  `show_map_tour` tinyint(1) NOT NULL DEFAULT '1',
  `show_fullscreen` tinyint(1) NOT NULL DEFAULT '1',
  `show_audio` tinyint(1) NOT NULL DEFAULT '1',
  `live_session` tinyint(1) NOT NULL DEFAULT '0',
  `meeting` tinyint(1) NOT NULL DEFAULT '0',
  `show_annotations` tinyint(1) NOT NULL DEFAULT '1',
  `show_list_alt` tinyint(1) NOT NULL DEFAULT '0',
  `list_alt` text,
  `intro_desktop` varchar(50) DEFAULT NULL,
  `intro_mobile` varchar(50) DEFAULT NULL,
  `start_date` date DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `start_url` varchar(250) DEFAULT NULL,
  `end_url` varchar(250) DEFAULT NULL,
  `auto_presentation_enable` tinyint(1) NOT NULL DEFAULT '0',
  `auto_presentation_speed` int(11) NOT NULL DEFAULT '5',
  `enable_multires` tinyint(1) NOT NULL DEFAULT '0',
  `transition_loading` tinyint(1) NOT NULL DEFAULT '1',
  `transition_time` int(11) NOT NULL DEFAULT '250',
  `transition_zoom` int(11) NOT NULL DEFAULT '20',
  `transition_fadeout` int(11) NOT NULL DEFAULT '400',
  `transition_effect` varchar(25) NOT NULL DEFAULT 'fade',
  `note` text DEFAULT NULL,
  `flyin` tinyint(1) NOT NULL DEFAULT '0',
  `language` varchar(10) DEFAULT NULL,
  `external` tinyint(1) NOT NULL DEFAULT '0',
  `external_url` varchar(250) DEFAULT NULL,
  `id_category` int(11) unsigned DEFAULT NULL,
  `keyboard_mode` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `id_user` (`id_user`),
  KEY `id_category` (`id_category`),
  CONSTRAINT `svt_virtualtours_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `svt_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `svt_virtualtours_ibfk_2` FOREIGN KEY (`id_category`) REFERENCES `svt_categories` (`id`) ON DELETE SET NULL ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_rooms` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_virtualtour` bigint(20) unsigned DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `type` enum('image','video') DEFAULT 'image',
  `panorama_image` varchar(100) DEFAULT NULL,
  `thumb_image` varchar(100) DEFAULT NULL,
  `panorama_video` varchar(100) DEFAULT NULL,
  `northOffset` int(11) NOT NULL DEFAULT '0',
  `pitch` int(11) NOT NULL DEFAULT '0',
  `yaw` int(11) NOT NULL DEFAULT '0',
  `hfov` int(11) NOT NULL DEFAULT '0',
  `h_pitch` int(11) NOT NULL DEFAULT '0',
  `h_roll` int(11) NOT NULL DEFAULT '0',
  `id_map` bigint(20) unsigned DEFAULT NULL,
  `map_top` int(11) DEFAULT NULL,
  `map_left` int(11) DEFAULT NULL,
  `lat` varchar(50) DEFAULT NULL,
  `lon` varchar(50) DEFAULT NULL,
  `allow_pitch` tinyint(1) NOT NULL DEFAULT '1',
  `min_pitch` int(11) NOT NULL DEFAULT '-90',
  `max_pitch` int(11) NOT NULL DEFAULT '90',
  `min_yaw` int(11) NOT NULL DEFAULT '-180',
  `max_yaw` int(11) NOT NULL DEFAULT '180',
  `haov` int(11) NOT NULL DEFAULT '360',
  `vaov` int(11) NOT NULL DEFAULT '180',
  `priority` int(11) NOT NULL DEFAULT '0',
  `access_count` bigint(20) NOT NULL DEFAULT '0',
  `visible_list` tinyint(1) NOT NULL DEFAULT '1',
  `song` varchar(50) DEFAULT NULL,
  `audio_track_enable` tinyint(1) NOT NULL DEFAULT '0',
  `annotation_title` varchar(100) DEFAULT NULL,
  `annotation_description` text,
  `multires_status` tinyint(1) NOT NULL DEFAULT '0',
  `transition_override` tinyint(1) NOT NULL DEFAULT '0',
  `transition_loading` tinyint(1) NOT NULL DEFAULT '1',
  `transition_time` int(11) NOT NULL DEFAULT '250',
  `transition_zoom` int(11) NOT NULL DEFAULT '20',
  `transition_fadeout` int(11) NOT NULL DEFAULT '400',
  `transition_effect` varchar(25) NOT NULL DEFAULT 'fade',
  `passcode_title` varchar(250) DEFAULT NULL,
  `passcode_description` text,
  `passcode` varchar(32) DEFAULT NULL,
  `protect_type` enum('none','passcode','leads') DEFAULT 'none',
  `filters` varchar(250) DEFAULT NULL,
  `blur` tinyint(1) NOT NULL DEFAULT '0',
  `virtual_staging` tinyint(1) NOT NULL DEFAULT '0',
  `main_view_tooltip` varchar(100) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  KEY `id_virtualtour` (`id_virtualtour`),
  CONSTRAINT `svt_rooms_ibfk_1` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_rooms_alt` (
   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
   `id_room` bigint(20) unsigned NOT NULL,
   `panorama_image` varchar(100) DEFAULT NULL,
   `multires_status` tinyint(1) NOT NULL DEFAULT '0',
   `view_tooltip` varchar(100) NOT NULL DEFAULT '',
   PRIMARY KEY (`id`),
   KEY `id_room` (`id_room`),
   CONSTRAINT `svt_rooms_alt_ibfk_1` FOREIGN KEY (`id_room`) REFERENCES `svt_rooms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_markers` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_room` bigint(20) unsigned DEFAULT NULL,
  `pitch` float DEFAULT NULL,
  `yaw` float DEFAULT NULL,
  `rotateX` int(11) NOT NULL DEFAULT '0',
  `rotateZ` int(11) NOT NULL DEFAULT '0',
  `id_room_target` bigint(20) unsigned DEFAULT NULL,
  `pitch_room_target` int(11) DEFAULT NULL,
  `yaw_room_target` int(11) DEFAULT NULL,
  `icon` varchar(50) NOT NULL DEFAULT 'fas fa-chevron-circle-up',
  `id_icon_library` bigint(20) unsigned NOT NULL DEFAULT '0',
  `background` varchar(25) NOT NULL DEFAULT 'rgba(255,255,255,0.7)',
  `color` varchar(25) NOT NULL DEFAULT '#000000',
  `tooltip_text` varchar(100) DEFAULT NULL,
  `tooltip_type` enum('none','text','preview','preview_square','preview_rect','room_name') NOT NULL DEFAULT 'none',
  `size_scale` float NOT NULL DEFAULT '1',
  `show_room` tinyint(1) NOT NULL DEFAULT '1',
  `css_class` varchar(250) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  KEY `id_room` (`id_room`),
  KEY `id_room_target` (`id_room_target`),
  CONSTRAINT `svt_markers_ibfk_1` FOREIGN KEY (`id_room`) REFERENCES `svt_rooms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `svt_markers_ibfk_2` FOREIGN KEY (`id_room_target`) REFERENCES `svt_rooms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_pois` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_room` bigint(20) unsigned DEFAULT NULL,
  `pitch` float DEFAULT NULL,
  `yaw` float DEFAULT NULL,
  `rotateX` int(11) NOT NULL DEFAULT '0',
  `rotateZ` int(11) NOT NULL DEFAULT '0',
  `type` enum('image','video','link','link_ext','html','html_sc','download','form','video360','audio','gallery') DEFAULT NULL,
  `style` tinyint(1) NOT NULL DEFAULT '0',
  `icon` varchar(50) DEFAULT NULL,
  `label` varchar(100) DEFAULT NULL,
  `id_icon_library` bigint(20) unsigned NOT NULL DEFAULT '0',
  `background` varchar(25) NOT NULL DEFAULT 'rgba(255,255,255,0.7)',
  `color` varchar(25) NOT NULL DEFAULT '#000000',
  `tooltip_text` text,
  `tooltip_type` enum('none','text') NOT NULL DEFAULT 'none',
  `size_scale` float NOT NULL DEFAULT '1',
  `title` varchar(100) DEFAULT NULL,
  `description` text,
  `content` longtext,
  `target` enum('_blank','_self') DEFAULT NULL,
  `access_count` bigint(20) NOT NULL DEFAULT '0',
  `schedule` varchar(250) DEFAULT NULL,
  `css_class` varchar(250) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  KEY `id_room` (`id_room`),
  CONSTRAINT `svt_pois_ibfk_1` FOREIGN KEY (`id_room`) REFERENCES `svt_rooms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_access_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_virtualtour` bigint(20) unsigned DEFAULT NULL,
  `date_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `id_virtualtour` (`id_virtualtour`),
  CONSTRAINT `svt_access_log_ibfk_1` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_presentations` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_virtualtour` bigint(20) unsigned DEFAULT NULL,
  `id_room` bigint(20) unsigned DEFAULT NULL,
  `action` varchar(50) DEFAULT NULL,
  `params` text,
  `sleep` int(11) NOT NULL DEFAULT '0',
  `priority_1` int(11) DEFAULT NULL,
  `priority_2` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `id_virtual_tour` (`id_virtualtour`),
  KEY `id_room` (`id_room`),
  CONSTRAINT `svt_presentations_ibfk_1` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `svt_presentations_ibfk_2` FOREIGN KEY (`id_room`) REFERENCES `svt_rooms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_gallery` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_virtualtour` bigint(20) unsigned DEFAULT NULL,
  `image` varchar(50) DEFAULT NULL,
  `title` varchar(100) DEFAULT NULL,
  `description` text,
  `priority` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `id_virtualtour` (`id_virtualtour`),
  CONSTRAINT `svt_gallery_ibfk_1` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_maps` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_virtualtour` bigint(20) unsigned NOT NULL,
  `map_type` enum('floorplan','map') DEFAULT 'floorplan',
  `map` varchar(200) DEFAULT NULL,
  `point_color` varchar(25) NOT NULL DEFAULT '#005eff',
  `name` varchar(200) DEFAULT NULL,
  `point_size` int(11) NOT NULL DEFAULT '20',
  `north_degree` int(11) NOT NULL DEFAULT '0',
  `zoom_level` int(11) NOT NULL DEFAULT '16',
  `zoom_to_point` tinyint(1) NOT NULL DEFAULT '0',
  `priority` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `id_virtualtour` (`id_virtualtour`),
  CONSTRAINT `svt_maps_ibfk_1` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_voice_commands` (
  `id` int(11) NOT NULL DEFAULT '0',
  `language` varchar(10) NOT NULL DEFAULT 'en-US',
  `initial_msg` varchar(200) NOT NULL DEFAULT 'Listening ... Say HELP for command list',
  `listening_msg` varchar(200) NOT NULL DEFAULT 'Listening ...',
  `next_cmd` varchar(200) NOT NULL DEFAULT 'next',
  `next_msg` varchar(200) NOT NULL DEFAULT 'Ok, going to next room',
  `prev_cmd` varchar(200) NOT NULL DEFAULT 'prev',
  `prev_msg` varchar(200) NOT NULL DEFAULT 'Ok, going to previous room',
  `left_cmd` varchar(200) NOT NULL DEFAULT 'left',
  `left_msg` varchar(200) NOT NULL DEFAULT 'Ok, looking left',
  `right_cmd` varchar(200) NOT NULL DEFAULT 'right',
  `right_msg` varchar(200) NOT NULL DEFAULT 'Ok, looking right',
  `up_cmd` varchar(200) NOT NULL DEFAULT 'up',
  `up_msg` varchar(200) NOT NULL DEFAULT 'Ok, looking up',
  `down_cmd` varchar(200) NOT NULL DEFAULT 'down',
  `down_msg` varchar(200) NOT NULL DEFAULT 'Ok, looking down',
  `help_cmd` varchar(200) NOT NULL DEFAULT 'help',
  `help_msg_1` varchar(200) NOT NULL DEFAULT 'Say NEXT / PREVIOUS to navigate between rooms',
  `help_msg_2` varchar(200) NOT NULL DEFAULT 'Say LEFT / RIGHT / UP / DOWN to look around',
  `error_msg` varchar(200) NOT NULL DEFAULT 'I do not understand, repeat please...',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT IGNORE INTO `svt_voice_commands` (`id`) VALUES(1);

CREATE TABLE IF NOT EXISTS `svt_settings` (
  `id` int(11) NOT NULL DEFAULT '0',
  `purchase_code` varchar(250) DEFAULT NULL,
  `license` varchar(250) DEFAULT NULL,
  `name` varchar(200) DEFAULT 'Simple Virtual Tour',
  `logo` varchar(50) DEFAULT NULL,
  `background` varchar(50) DEFAULT NULL,
  `smtp_server` varchar(100) DEFAULT NULL,
  `smtp_auth` tinyint(1) NOT NULL DEFAULT '0',
  `smtp_username` varchar(100) DEFAULT NULL,
  `smtp_password` varchar(100) DEFAULT NULL,
  `smtp_secure` enum('none','ssl','tls') DEFAULT NULL,
  `smtp_port` int(11) DEFAULT NULL,
  `smtp_from_email` varchar(100) DEFAULT NULL,
  `smtp_from_name` varchar(100) DEFAULT NULL,
  `smtp_valid` tinyint(1) NOT NULL DEFAULT '0',
  `enable_registration` tinyint(1) NOT NULL DEFAULT '0',
  `validate_email` tinyint(1) NOT NULL DEFAULT '0',
  `default_id_plan` bigint(20) unsigned DEFAULT '1',
  `furl_blacklist` text,
  `language` varchar(10) NOT NULL DEFAULT 'en_US',
  `language_domain` varchar(50) NOT NULL DEFAULT 'default',
  `contact_email` varchar(100) DEFAULT NULL,
  `change_plan` tinyint(1) NOT NULL DEFAULT '0',
  `stripe_enabled` tinyint(1) NOT NULL DEFAULT '0',
  `stripe_secret_key` varchar(200) DEFAULT NULL,
  `stripe_public_key` varchar(200) DEFAULT NULL,
  `version` varchar(10) NOT NULL DEFAULT '',
  `social_google_enable` tinyint(1) NOT NULL DEFAULT '0',
  `social_facebook_enable` tinyint(1) NOT NULL DEFAULT '0',
  `social_twitter_enable` tinyint(1) NOT NULL DEFAULT '0',
  `social_google_id` varchar(200) DEFAULT NULL,
  `social_google_secret` varchar(200) DEFAULT NULL,
  `social_facebook_id` varchar(200) DEFAULT NULL,
  `social_facebook_secret` varchar(200) DEFAULT NULL,
  `social_twitter_id` varchar(200) DEFAULT NULL,
  `social_twitter_secret` varchar(200) DEFAULT NULL,
  `help_url` varchar(250) DEFAULT NULL,
  `enable_external_vt` tinyint(1) NOT NULL DEFAULT '0',
  `mail_activate_subject` varchar(250) NOT NULL DEFAULT 'Activation Account',
  `mail_activate_body` text,
  `mail_forgot_subject` varchar(250) NOT NULL DEFAULT 'Forgot Password',
  `mail_forgot_body` text,
  `first_name_enable` tinyint(1) NOT NULL DEFAULT '1',
  `last_name_enable` tinyint(1) NOT NULL DEFAULT '1',
  `company_enable` tinyint(1) NOT NULL DEFAULT '1',
  `tax_id_enable` tinyint(1) NOT NULL DEFAULT '1',
  `street_enable` tinyint(1) NOT NULL DEFAULT '1',
  `city_enable` tinyint(1) NOT NULL DEFAULT '1',
  `postal_code_enable` tinyint(1) NOT NULL DEFAULT '1',
  `province_enable` tinyint(1) NOT NULL DEFAULT '1',
  `country_enable` tinyint(1) NOT NULL DEFAULT '1',
  `tel_enable` tinyint(1) NOT NULL DEFAULT '1',
  `first_name_mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `last_name_mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `company_mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `tax_id_mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `street_mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `city_mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `postal_code_mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `province_mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `country_mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `tel_mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `peerjs_host` varchar(250) NOT NULL DEFAULT 'svtpeerjs.simpledemo.it',
  `peerjs_port` int(5) NOT NULL DEFAULT 443,
  `peerjs_path` varchar(250) NOT NULL DEFAULT '/svt',
  `jitsi_domain` varchar(250) NOT NULL DEFAULT 'meet.jit.si',
  `leaflet_street_basemap` varchar(250) NOT NULL DEFAULT 'https://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
  `leaflet_satellite_basemap` varchar(250) NOT NULL DEFAULT 'https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',
  `leaflet_street_subdomain` varchar(250) NOT NULL DEFAULT 'mt0,mt1,mt2,mt3',
  `leaflet_street_maxzoom` int(2) NOT NULL DEFAULT 20,
  `leaflet_satellite_subdomain` varchar(250) NOT NULL DEFAULT 'mt0,mt1,mt2,mt3',
  `leaflet_satellite_maxzoom` int(2) NOT NULL DEFAULT 20,
  `languages_enabled` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT IGNORE INTO `svt_settings` (`id`) VALUES(1);
UPDATE svt_settings SET `mail_activate_body`='<p>Thanks for signing up!</p><p><br></p><p>Please click on this link to activate your account:</p><p>%LINK%</p>';
UPDATE svt_settings SET `mail_forgot_body`='<p>This is your verification code: %VERIFICATION_CODE%</p><p><br></p><p>Please click on this link to change your password:</p><p>%LINK%</p>';

CREATE TABLE IF NOT EXISTS `svt_icons` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_virtualtour` bigint(20) unsigned DEFAULT NULL,
  `image` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `id_virtualtour` (`id_virtualtour`),
  CONSTRAINT `svt_icon_ibfk_1` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_rooms_access_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_room` bigint(20) unsigned DEFAULT NULL,
  `time` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `id_room` (`id_room`),
  CONSTRAINT `svt_rooms_access_log_ibfk_1` FOREIGN KEY (`id_room`) REFERENCES `svt_rooms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_forms_data` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_virtualtour` bigint(20) unsigned NOT NULL,
  `id_room` bigint(20) unsigned DEFAULT NULL,
  `title` varchar(250) DEFAULT NULL,
  `field1` text,
  `field2` text,
  `field3` text,
  `field4` text,
  `field5` text,
  PRIMARY KEY (`id`),
  KEY `id_virtualtour` (`id_virtualtour`),
  CONSTRAINT `svt_forms_data_ibfk_1` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_poi_gallery` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_poi` bigint(20) unsigned DEFAULT NULL,
  `image` varchar(50) DEFAULT NULL,
  `title` varchar(100) DEFAULT NULL,
  `description` text,
  `priority` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `id_poi` (`id_poi`),
  CONSTRAINT `svt_poi_gallery_ibfk_1` FOREIGN KEY (`id_poi`) REFERENCES `svt_pois` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_assign_virtualtours` (
  `id_user` int(11) unsigned DEFAULT NULL,
  `id_virtualtour` bigint(20) unsigned DEFAULT NULL,
  UNIQUE KEY `id_user` (`id_user`,`id_virtualtour`),
  KEY `id_virtualtour` (`id_virtualtour`),
  CONSTRAINT `svt_assign_virtualtours_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `svt_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `svt_assign_virtualtours_ibfk_2` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_leads` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `id_virtualtour` bigint(20) unsigned NOT NULL,
  `name` varchar(250) DEFAULT NULL,
  `email` varchar(250) DEFAULT NULL,
  `phone` varchar(25) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `id_virtualtour` (`id_virtualtour`),
  CONSTRAINT `svt_leads_ibfk_1` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_showcases` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `id_user` int(11) unsigned DEFAULT NULL,
  `code` varchar(100) DEFAULT NULL,
  `name` varchar(250) DEFAULT NULL,
  `friendly_url` varchar(100) DEFAULT NULL,
  `banner` varchar(100) DEFAULT NULL,
  `logo` varchar(100) DEFAULT NULL,
  `bg_color` varchar(10) NOT NULL DEFAULT '#EEEEEE',
  `header_html` longtext DEFAULT NULL,
  `footer_html` longtext DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `id_user` (`id_user`),
  CONSTRAINT `svt_showcases_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `svt_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_showcase_list` (
  `id_showcase` bigint(20) unsigned DEFAULT NULL,
  `id_virtualtour` bigint(20) unsigned DEFAULT NULL,
  `type_viewer` enum('viewer','landing') NOT NULL DEFAULT 'viewer',
  KEY `id_showcase` (`id_showcase`),
  KEY `id_virtualtour` (`id_virtualtour`),
  CONSTRAINT `svt_showcase_list_ibfk_1` FOREIGN KEY (`id_showcase`) REFERENCES `svt_showcases` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `svt_showcase_list_ibfk_2` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_advertisements` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `image` varchar(50) DEFAULT NULL,
  `link` varchar(250) DEFAULT NULL,
  `countdown` int(11) NOT NULL DEFAULT 0,
  `id_plans` varchar(100) DEFAULT NULL,
  `auto_assign` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `svt_assign_advertisements` (
  `id_advertisement` int(11) unsigned NOT NULL,
  `id_virtualtour` bigint(20) unsigned NOT NULL,
  KEY `id_advertisement` (`id_advertisement`),
  KEY `id_virtualtour` (`id_virtualtour`),
  CONSTRAINT `svt_assign_advertisements_ibfk_1` FOREIGN KEY (`id_advertisement`) REFERENCES `svt_advertisements` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `svt_assign_advertisements_ibfk_2` FOREIGN KEY (`id_virtualtour`) REFERENCES `svt_virtualtours` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;