CREATE TABLE IF NOT EXISTS `#__rsevents_categories` (
  `IdCategory` int(11) NOT NULL AUTO_INCREMENT,
  `CategoryName` varchar(255) NOT NULL,
  `CategoryColor` varchar(20) NOT NULL,
  `CategoryDescription` text NOT NULL,
  `published` tinyint(1) NOT NULL,
  `ordering` int(11) NOT NULL,
  `CategoryAlias` varchar(255) NOT NULL,
  PRIMARY KEY (`IdCategory`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_config` (
  `IdConfig` int(11) NOT NULL AUTO_INCREMENT,
  `ConfigName` varchar(255) NOT NULL,
  `ConfigValue` text NOT NULL,
  PRIMARY KEY (`IdConfig`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_designs` (
  `IdDesign` int(11) NOT NULL AUTO_INCREMENT,
  `DesignName` varchar(255) NOT NULL,
  `DesignDefault` tinyint(1) NOT NULL,
  `published` tinyint(1) NOT NULL,
  `ordering` int(11) NOT NULL,
  `params` text NOT NULL,
  PRIMARY KEY (`IdDesign`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_events` (
  `IdEvent` int(11) NOT NULL AUTO_INCREMENT,
  `IdLocation` int(11) NOT NULL,
  `IdDesign` int(11) NOT NULL,
  `IdUser` int(11) NOT NULL,
  `IdParent` tinyint(2) NOT NULL,
  `EventName` varchar(255) NOT NULL,
  `EventAlias` char(255) NOT NULL,
  `EventSubtitle` varchar(255) NOT NULL,
  `EventHost` varchar(255) NOT NULL,
  `EventURL` varchar(255) NOT NULL,
  `EventPhone` varchar(255) NOT NULL,
  `EventEmail` varchar(255) NOT NULL,
  `EventDescription` text NOT NULL,
  `EventType` tinyint(1) NOT NULL DEFAULT '1',
  `EventOverbooking` tinyint(2) NOT NULL,
  `EventStartDate` int(11) NOT NULL,
  `EventEndDate` int(11) NOT NULL,
  `EventEnableRegistration` tinyint(1) NOT NULL,
  `EventShowGuest` tinyint(1) NOT NULL,
  `EventEnableComments` tinyint(1) NOT NULL,
  `EventPostReminder` tinyint(1) NOT NULL,
  `published` tinyint(1) NOT NULL,
  `EventPrivateUrl` varchar(255) NOT NULL,
  `EventEnableRepeat` tinyint(2) NOT NULL,
  `EventRepeatType` tinyint(2) NOT NULL,
  `EventRepeatNumber` int(10) NOT NULL,
  `EventRepeatUntil` int(11) NOT NULL,
  `EventRepeatAlso` text NOT NULL,
  `EventRegistrationForm` tinyint(2) NOT NULL,
  `EventArchive` tinyint(2) NOT NULL,
  `EventAutoApprove` tinyint(2) NOT NULL,
  `EventPaypalEmail` varchar(255) NOT NULL,
  `EventIcon` text NOT NULL,
  `EventReturnUrl` varchar(255) NOT NULL,
  `EventKeywords` varchar(255) NOT NULL,
  `EventMetaDescription` varchar(255) NOT NULL,
  `EventAmPm1` int(1) NOT NULL,
  `EventAmPm2` int(1) NOT NULL,
  `EventCreation` int(15) NOT NULL,
  PRIMARY KEY (`IdEvent`),
  KEY `EventPeriod` (`EventStartDate`,`EventEndDate`),
  KEY `IdLocation` (`IdLocation`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_events_cat` (
  `IdEventCategory` int(11) NOT NULL AUTO_INCREMENT,
  `IdEvent` int(11) NOT NULL,
  `IdCategory` int(11) NOT NULL,
  PRIMARY KEY (`IdEventCategory`),
  KEY `IdEvent` (`IdEvent`,`IdCategory`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_extras` (
  `IdExtra` int(11) NOT NULL AUTO_INCREMENT,
  `IdEvent` int(11) NOT NULL,
  `ExtraName` varchar(255) NOT NULL,
  `ExtraValue` text NOT NULL,
  PRIMARY KEY (`IdExtra`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_files` (
  `IdFile` int(11) NOT NULL AUTO_INCREMENT,
  `IdEvent` int(11) NOT NULL,
  `FileName` text NOT NULL,
  `FileDescription` text NOT NULL,
  `FileLocation` text NOT NULL,
  `FilePermission` varchar(30) NOT NULL,
  PRIMARY KEY (`IdFile`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_groups` (
  `IdGroup` int(11) NOT NULL AUTO_INCREMENT,
  `GroupName` varchar(255) NOT NULL,
  PRIMARY KEY (`IdGroup`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_groups_acl` (
  `IdGroupAcl` int(11) NOT NULL AUTO_INCREMENT,
  `IdGroup` int(11) NOT NULL,
  `GroupAcl` int(11) NOT NULL,
  PRIMARY KEY (`IdGroupAcl`),
  KEY `IdGroup` (`IdGroup`,`GroupAcl`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_group_permissions` (
  `IdGroupPermission` int(11) NOT NULL AUTO_INCREMENT,
  `IdGroup` int(11) NOT NULL,
  `PermissionName` varchar(255) NOT NULL,
  `PermissionValue` text NOT NULL,
  PRIMARY KEY (`IdGroupPermission`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;


CREATE TABLE IF NOT EXISTS `#__rsevents_locations` (
  `IdLocation` int(11) NOT NULL AUTO_INCREMENT,
  `LocationName` varchar(255) NOT NULL,
  `LocationDescription` text NOT NULL,
  `LocationAlias` varchar(255) NOT NULL,
  `LocationURL` varchar(255) NOT NULL,
  `LocationCity` varchar(255) NOT NULL,
  `LocationAddress` varchar(255) NOT NULL,
  `LocationZip` varchar(255) NOT NULL,
  `LocationState` varchar(255) NOT NULL,
  `LocationCountry` varchar(255) NOT NULL,
  `LocationLat` varchar(255) NOT NULL,
  `LocationLon` varchar(255) NOT NULL,
  `published` tinyint(1) NOT NULL,
  `ordering` int(10) NOT NULL,
  PRIMARY KEY (`IdLocation`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_subscriptions` (
  `IdSubscription` int(11) NOT NULL AUTO_INCREMENT,
  `IdEvent` int(11) NOT NULL,
  `IdUser` int(11) NOT NULL,
  `FirstName` varchar(255) NOT NULL,
  `LastName` varchar(255) NOT NULL,
  `Email` varchar(255) NOT NULL,
  `SubscriptionState` tinyint(4) NOT NULL,
  `SubscriptionTotalFee` double NOT NULL,
  `SubscriptionDate` int(11) NOT NULL,
  `ValidationDate` int(11) NOT NULL,
  `ConfirmationDate` int(11) NOT NULL,
  `SubscriptionVerification` varchar(32) NOT NULL,
  `TransactionGateway` varchar(20) NOT NULL,
  `TransactionParams` text NOT NULL,
  `SubscriptionFormId` int(3) NOT NULL,
  `UserIp` varchar(15) NOT NULL,
  PRIMARY KEY (`IdSubscription`),
  KEY `IdEvent` (`IdEvent`),
  KEY `Email` (`Email`),
  KEY `IdUser` (`IdUser`),
  KEY `EventSubscriptionState` (`IdEvent`,`SubscriptionState`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_subscription_tickets` (
  `IdSubscriptionTickets` int(11) NOT NULL AUTO_INCREMENT,
  `IdSubscription` int(11) NOT NULL,
  `IdTicket` int(11) NOT NULL,
  `TicketsSubscribed` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`IdSubscriptionTickets`),
  UNIQUE KEY `IdSubscription_2` (`IdSubscription`,`IdTicket`),
  KEY `IdSubscription` (`IdSubscription`),
  KEY `IdFee` (`IdTicket`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `#__rsevents_tickets` (
  `IdTicket` int(11) NOT NULL AUTO_INCREMENT,
  `IdEvent` int(11) NOT NULL,
  `TicketName` varchar(255) NOT NULL,
  `TicketPrice` double NOT NULL,
  `TicketMaxAudience` int(11) NOT NULL,
  `TicketsPerUser` int(5) NOT NULL,
  `TicketDescription` text NOT NULL,
  `ordering` int(11) NOT NULL,
  PRIMARY KEY (`IdTicket`),
  KEY `IdEvent` (`IdEvent`),
  KEY `EventFeeNameUnique` (`IdEvent`,`TicketName`),
  KEY `IdEvent_2` (`IdEvent`,`TicketName`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(1, 'global.register.code', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(2, 'events.extras.flash', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(3, 'events.extras.youtube', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(4, 'events.extras.mp3', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(5, 'events.extras.meebo', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(7, 'events.commenting', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(8, 'global.dateformat', 'd M y H:i');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(9, 'layouts.eventintro', '<div style="overflow: hidden">\r\n{EventIcon}<a href="{EventLink}"><strong>{EventName}</strong></a><br/>\r\n{EventSubtitle}\r\n<p>{EventDescription}</p>\r\nAt <em>{LocationName}</em> from {EventStartDate} to {EventEndDate} - Hosted by {EventHost} - {CategoryName} - <a href="{EventLink}">Details</a></div>\r\n<hr/>');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(10, 'event.files', 'zip\r\ngif\r\njpg\r\ntxt\r\n');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(11, 'locations.gmaps', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(12, 'locations.gMaps.key', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(13, 'locations.gMaps.center', '37.92686760148135,23.818359375');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(14, 'emails.from', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(15, 'emails.reply', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(16, 'emails.registration.subject', 'Registration E-mail');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(17, 'emails.registration.type', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(18, 'emails.registration.content', '<h3>Welcome {username}</h3>  <p>You have registered at {EventName}.</p><p>&nbsp;</p><p> The event will start on {EventStartDate} and will end on {EventEndDate}</p> <p>at {LocationName}</p>.');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(19, 'emails.activation.subject', 'Activation E-mail');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(20, 'emails.activation.content', '<h3>Hello  {username}</h3>   <p>You`re request to participate to {EventName} has been aproved.</p>');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(21, 'emails.activation.type', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(22, 'emails.reminder.content', 'Hello ,  The event {EventName} has finished.  Please follow this <a href="http://editthistoaddyourlink.com">link</a> for sharing photos after the event. ');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(23, 'emails.reminder.type', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(24, 'emails.reminder.subject', 'Reminder of {EventName}');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(25, 'emails.from.name', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(26, 'emails.invite.subject', 'Invitation to {EventName}');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(27, 'emails.invite.type', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(28, 'emails.invite.content', 'Hello ,   <p>You have been invited to {EventName} which starts on {EventStartDate} and will end on {EventEndDate} at {LocationName}</p> {EventName}  {message}');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(29, 'payment.currency', 'EUR');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(30, 'payment.thousands', ',');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(31, 'payment.decimal', '.');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(32, 'payment.nrdecimals', '2');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(33, 'payment.default', 'wire');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(34, 'subscribers.link', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(35, 'flikr.key', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(36, 'flikr.num.photos', '5');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(37, 'events.extras.flickr', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(38, 'event.full.booking', 'This event is full');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(39, 'event.redirect.registration', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(40, 'event.registration.form', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(41, 'event.enable.autoarchive', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(42, 'event.archive.days', '5');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(43, 'google.map', 'G_NORMAL_MAP');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(44, 'emails.cc', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(45, 'emails.bcc', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(46, 'paypal.for.users', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(47, 'events.layout', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(48, 'enable.event.icon', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(49, 'event.icon.small', '80');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(50, 'event.icon.big', '185');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(51, 'cb.autoapprove', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(52, 'cb.redirect', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(53, 'moderation.email', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(54, 'event.show.invite', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(55, 'event.show.outlook', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(56, 'enable.debug', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(57, 'emails.registration.enable', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(58, 'emails.activation.enable', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(59, 'event.enable.guests', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(60, 'emails.rem.subject', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(61, 'emails.rem.type', '1');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(62, 'emails.rem.content', '');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(63, 'enable.12format', '0');
INSERT IGNORE  INTO `#__rsevents_config` (`IdConfig`, `ConfigName`, `ConfigValue`) VALUES(64, 'event.multiple.reg', '0');

INSERT IGNORE INTO `#__rsevents_designs` (`IdDesign`, `DesignName`, `DesignDefault`, `published`, `ordering`, `params`) VALUES
(1, 'default', 1, 1, 1, '');

INSERT IGNORE INTO `#__rsevents_categories` (`IdCategory`, `CategoryName`, `CategoryColor`, `CategoryDescription`, `published`, `ordering`, `CategoryAlias`) VALUES
(1, 'Events', '', 'My first category.', 1, 1, 'events');

INSERT IGNORE INTO `#__rsevents_locations` (`IdLocation`, `LocationName`, `LocationDescription`, `LocationAlias`, `LocationURL`, `LocationCity`, `LocationAddress`, `LocationZip`, `LocationState`, `LocationCountry`, `LocationLat`, `LocationLon`, `published`, `ordering`) VALUES
(1, 'My first location', 'My First Location.', 'my-first-location', 'http://myfirstlocation.com', 'My first city', 'My address', 'My zip code', '', 'My Country', '', '', 1, 1);

INSERT IGNORE INTO `#__rsevents_groups` (`IdGroup`, `GroupName`) VALUES (1, 'Public');

INSERT IGNORE INTO `#__rsevents_groups_acl` (`IdGroupAcl`, `IdGroup`, `GroupAcl`) VALUES (1, 1, 29);

INSERT IGNORE INTO `#__rsevents_group_permissions` (`IdGroupPermission`, `IdGroup`, `PermissionName`, `PermissionValue`) VALUES
('', 1, 'enablePosts', '0'),
('', 1, 'enableModeration', '1'),
('', 1, 'allowRegistration', '1'),
('', 1, 'allowRegistrationCancel', '0'),
('', 1, 'allowDownload', '1'),
('', 1, 'allowUpload', '0'),
('', 1, 'allowLocations', '0'),
('', 1, 'canEdit', '0'),
('', 1, 'enableLocationModeration', '1');
