CREATE TABLE IF NOT EXISTS `#__rsfiles_config` (
  `IdConfig` int(11) NOT NULL AUTO_INCREMENT,
  `ConfigName` varchar(255) NOT NULL,
  `ConfigValue` text NOT NULL,
  PRIMARY KEY (`IdConfig`)
) ;

CREATE TABLE IF NOT EXISTS `#__rsfiles_files` (
  `IdFile` int(11) NOT NULL AUTO_INCREMENT,
  `FileName` varchar(255) NOT NULL,
  `FilePath` varchar(255) NOT NULL,
  `FileSize` varchar(255) NOT NULL,
  `FileVersion` varchar(255) NOT NULL,
  `FileStatistics` int(2) NOT NULL,
  `FileDescription` text NOT NULL,
  `DateAdded` int(15) NOT NULL,
  `ModifiedDate` int(15) NOT NULL,
  `IdLicense` int(11) NOT NULL,
  `IdUser` int(3) NOT NULL,
  `DownloadMethod` int(2) NOT NULL,
  `FileThumb` varchar(255) NOT NULL,
  `CanPerforMaintenance` varchar(255) NOT NULL,
  `CanDownload` varchar(255) NOT NULL,
  `CanView` varchar(255) NOT NULL,
  `hash` varchar(255) NOT NULL,
  `hits` int(15) NOT NULL,
  `published` int(2) NOT NULL DEFAULT '1',
  PRIMARY KEY (`IdFile`),
  UNIQUE KEY `FilePath` (`FilePath`)
) ;

CREATE TABLE IF NOT EXISTS `#__rsfiles_groups` (
  `IdGroup` int(3) NOT NULL AUTO_INCREMENT,
  `GroupName` varchar(255) NOT NULL,
  PRIMARY KEY (`IdGroup`)
) ;

CREATE TABLE IF NOT EXISTS `#__rsfiles_group_details` (
  `IdGroupDetail` int(3) NOT NULL AUTO_INCREMENT,
  `IdGroup` int(3) NOT NULL,
  `IdUsers` text NOT NULL,
  `IdAcls` text NOT NULL,
  PRIMARY KEY (`IdGroupDetail`),
  KEY `IdGroup` (`IdGroup`)
) ;

CREATE TABLE IF NOT EXISTS `#__rsfiles_licenses` (
  `IdLicense` int(3) NOT NULL AUTO_INCREMENT,
  `LicenseName` varchar(255) NOT NULL,
  `LicenseText` text NOT NULL,
  `published` int(2) NOT NULL,
  PRIMARY KEY (`IdLicense`)
) ;

CREATE TABLE IF NOT EXISTS `#__rsfiles_mirrors` (
  `IdMirror` int(3) NOT NULL AUTO_INCREMENT,
  `IdFile` int(3) NOT NULL,
  `MirrorName` varchar(255) NOT NULL,
  `MirrorURL` text NOT NULL,
  PRIMARY KEY (`IdMirror`)
) ;

CREATE TABLE IF NOT EXISTS `#__rsfiles_screenshots` (
  `IdScreenshot` int(3) NOT NULL AUTO_INCREMENT,
  `IdFile` int(3) NOT NULL,
  `Path` text NOT NULL,
  PRIMARY KEY (`IdScreenshot`)
) ;

CREATE TABLE IF NOT EXISTS `#__rsfiles_statistics` (
  `IdStatistic` int(3) NOT NULL AUTO_INCREMENT,
  `IdFile` int(5) NOT NULL,
  `Date` int(15) NOT NULL,
  `Ip` varchar(255) NOT NULL,
  `UserId` int(5) NOT NULL,
  PRIMARY KEY (`IdStatistic`),
  KEY `IdFile` (`IdFile`)
) ;

CREATE TABLE IF NOT EXISTS `#__rsfiles_templates` (
  `IdTemplate` int(3) NOT NULL AUTO_INCREMENT,
  `IdTheme` int(3) NOT NULL,
  `TemplateName` varchar(255) NOT NULL,
  `TemplateLayout` longtext NOT NULL,
  `TemplateHeader` text NOT NULL,
  `Type` int(2) NOT NULL,
  PRIMARY KEY (`IdTemplate`),
  KEY `IdTemplate` (`IdTheme`)
) ;

CREATE TABLE IF NOT EXISTS `#__rsfiles_themes` (
  `IdTheme` int(3) NOT NULL AUTO_INCREMENT,
  `ThemeName` varchar(255) NOT NULL,
  `default` int(3) NOT NULL,
  `published` int(3) NOT NULL,
  PRIMARY KEY (`IdTheme`)
) ;

CREATE TABLE IF NOT EXISTS `#__rsfiles_reports` (
  `IdReport` int(5) NOT NULL AUTO_INCREMENT,
  `IdFile` int(5) NOT NULL,
  `ReportMessage` text NOT NULL,
  `uid` int(11) NOT NULL,
  `ip` varchar(15) NOT NULL,
  `date` int(20) NOT NULL,
  PRIMARY KEY (`IdReport`),
  KEY `IdFile` (`IdFile`)
);

INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(1, 'download_folder', '');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(2, 'license_code', '');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(3, 'global_date', 'd/m/Y H:i:s');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(4, 'preview_files', 'jpg,txt,png,pdf,gif');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(5, 'nr_per_page', '5');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(6, 'component_title', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(7, 'default_order', 'name');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(8, 'default_order_way', 'ASC');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(9, 'show_pagination_position', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(10, 'show_descriptions', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(11, 'allowed_files', 'jpg\r\ntxt\r\npdf\r\ngif\r\npng');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(13, 'show_search', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(15, 'enable_upload', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(16, 'max_upl_size', '10240');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(17, 'email_from', 'from@site.com');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(18, 'email_from_name', 'From Site');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(19, 'email_reply', 'reply@site.com');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(20, 'email_reply_name', 'Reply Site');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(21, 'email_cc', 'cc@site.com');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(22, 'email_bcc', 'bcc@site.com');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(27, 'email_admin_enable', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(28, 'email_admin_subject', 'Admin Email');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(29, 'email_admin_mode', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(30, 'email_admin_message', '<p>Hello ,</p>\r\n<p>Someone has downloaded the file {filename}.</p>\r\n<p><strong>Details :</strong></p>\r\n<p>Ip: {ip}</p>\r\n<p>Username : {username}</p>');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(31, 'email_admin_to', 'admin@localhost');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(32, 'email_download_subject', 'Download email');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(33, 'email_download_mode', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(34, 'email_download_message', '<p>Hello {email},</p>\r\n<p> </p>\r\n<p>You can download the file from here : {downloadurl}</p>');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(35, 'thumb_width', '64');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(36, 'email_upload_enable', '0');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(37, 'email_upload_to', 'to@email.com');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(38, 'email_upload_subject', 'A new user has uploaded a file');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(39, 'email_upload_mode', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(40, 'email_upload_message', '<p>The user {username} has uploaded a new file .</p>\r\n<p>{files}</p>');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(41, 'file_path', '0');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(42, 'enable_rss', '0');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(43, 'enable_flash_upload', '0');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(44, 'email_report_enable', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(45, 'email_report_to', 'report@email.com');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(46, 'email_report_subject', 'Someone submitted a new report');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(47, 'email_report_mode', '1');
INSERT IGNORE INTO `#__rsfiles_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(48, 'email_report_message', '<p>A new report for {filename} was added. Here are the details :</p>\r\n<p>Username : {username}</p>\r\n<p>IP: {ip}</p>\r\n<p>Report: {report}</p>');



INSERT IGNORE INTO `#__rsfiles_themes` (`IdTheme`, `ThemeName`, `default`, `published`) VALUES(1, 'default', 1, 1);
INSERT IGNORE INTO `#__rsfiles_templates` (`IdTemplate`, `IdTheme`, `TemplateName`, `TemplateLayout`, `TemplateHeader`, `Type`) VALUES(1, 1, 'Files template', '<table style="margin-bottom:5px;border:1px solid #cccccc;background:#F8F8F8;width:100%">\r\n<tr>\r\n<td width="30%">{FileName}</td>\r\n<td width="7%">{FileVersion}</td>\r\n<td width="7%">{FileLicense}</td>\r\n<td width="7%">{FileSize}</td>\r\n<td width="10%" align="center">{DateAdded}</td>\r\n<td width="1%">{Download}{Details}{View}</td>\r\n</tr>\r\n</table>', '<table style="margin-bottom:5px;border:1px solid #cccccc;background:#F8F8F8;width:100%">\r\n<tr>\r\n<td width="30%">File Name</td>\r\n<td width="7%">File Version</td>\r\n<td width="7%">File License</td>\r\n<td width="7%">File Size</td>\r\n<td width="10%" align="center">Date Added</td>\r\n<td width="1%">&nbsp;</td>\r\n</tr>\r\n</table>', 1);
INSERT IGNORE INTO `#__rsfiles_templates` (`IdTemplate`, `IdTheme`, `TemplateName`, `TemplateLayout`, `TemplateHeader`, `Type`) VALUES(2, 1, 'Download template', '<h1>{FileName}</h1>\r\n<div class="filesdownload">\r\n	<h2>\r\n		{maindownload}\r\n	</h2>\r\n</div>\r\n{screenshots}\r\n<table class="filesdetail" width="100%">\r\n	<tr>\r\n		<td>\r\n			<table width="100%">\r\n				<tr>\r\n					<td width="100"><strong>License:</strong></td>\r\n					<td>{FileLicense}</td>\r\n				</tr>\r\n				<tr>\r\n					<td><strong>Total Size:</strong></td>\r\n					<td>{FileSize}</td>\r\n				</tr>\r\n				<tr>\r\n					<td><strong>File Version:</strong></td>\r\n					<td>{FileVersion}</td>\r\n				</tr>\r\n			</table>\r\n		</td>\r\n\r\n		<td>\r\n			<table width="100%">\r\n				<tr>\r\n					<td><strong>Added:</strong></td>\r\n					<td>{DateAdded}</td>\r\n				</tr>\r\n				<tr>\r\n					<td width="100"><strong>Last Updated:</strong></td>\r\n					<td>{FileModified}</td>\r\n				</tr>\r\n				<tr>\r\n					<td><strong>Downloads:</strong></td>\r\n					<td>{FileHits}</td>\r\n				</tr>\r\n			</table>\r\n		</td>\r\n	</tr>\r\n</table>\r\n<div class="filedescription">\r\n<h3>Description</h3>\r\n{FileDescription}\r\n</div>\r\n\r\n<style>\r\n.filesdownload{\r\nbackground-color:#EFF3FB;\r\nborder:1px solid #8BA7CD;\r\npadding:10px 10px 20px 10px;\r\nmargin:20px;\r\n}\r\n.filesdownload h2{\r\nmargin:0;padding:10px;\r\nfont-size:15px;\r\n}\r\n.filesdetail, .filedescription{\r\nmargin:20px;\r\n}\r\n</style>', '', 2);
INSERT IGNORE INTO `#__rsfiles_templates` (`IdTemplate`, `IdTheme`, `TemplateName`, `TemplateLayout`, `TemplateHeader`, `Type`) VALUES(3, 1, 'Details template', '<h1>Details for "{FileName}"</h1>\r\n\r\n<table cellspacing="0" class="rsfl_table">\r\n	<tbody>\r\n		<tr>\r\n			<td class="rsfl_prop">Name</td>\r\n			<td>{FileName}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">Description</td>\r\n			<td>{FileDescription}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">License</td>\r\n			<td>{FileLicense}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">Filename</td>\r\n			<td>{RealFileName}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">FileVersion</td>\r\n			<td>{FileVersion}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">Filesize</td>\r\n			<td>{FileSize}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">Filetype</td>\r\n			<td>{FileType}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">Creator</td>\r\n			<td>{FileUploader}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">Created On:</td>\r\n			<td>{DateAdded}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">Hits</td>\r\n			<td>{FileHits}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">Last updated on</td>\r\n			<td>{FileModified}</td>\r\n		</tr>\r\n		<tr>\r\n			<td class="rsfl_prop">MD5 Checksum</td>\r\n			<td>{FileChecksum}</td>\r\n		</tr>\r\n	</tbody>\r\n</table>\r\n\r\n<style type="text/css">\r\ntd.rsfl_prop{\r\n	background-color:#E9E9E9;\r\n        font-weight:bold;\r\n}\r\n\r\ntable.rsfl_table td {\r\n	padding:5px;\r\n}\r\n</style>', '', 3);