CREATE TABLE BanRules (
  RuleId int(11) NOT NULL auto_increment,
  RuleType tinyint(4) NOT NULL default '0',
  ItemField varchar(255) default NULL,
  ItemVerb tinyint(4) NOT NULL default '0',
  ItemValue varchar(255) NOT NULL default '',
  ItemType int(11) NOT NULL default '0',
  Priority int(11) NOT NULL default '0',
  Status tinyint(4) NOT NULL default '1',
  ErrorTag varchar(255) default NULL,
  PRIMARY KEY  (RuleId)
)

# --------------------------------------------------------

CREATE TABLE Category (
  CategoryId int(11) NOT NULL auto_increment,
  Type int(11) NOT NULL default '0',
  ParentId int(11) NOT NULL default '0',
  Name varchar(255) NOT NULL default '',
  Description text NOT NULL,
  CreatedOn int(11) NOT NULL default '0',
  EditorsPick tinyint(4) default NULL,
  Status tinyint(4) NOT NULL default '0',
  Pop tinyint(4) default NULL,
  Priority int(11) NOT NULL default '0',
  MetaKeywords varchar(255) default NULL,
  CachedDescendantCatsQty int(11) default NULL,
  CachedNavbar text NOT NULL,
  CreatedById int(11) NOT NULL default '0',
  ResourceId int(11) default NULL,
  ParentPath text NOT NULL,
  MetaDescription varchar(255) default NULL,
  HotItem int(11) NOT NULL default '2',
  NewItem int(11) NOT NULL default '2',
  PopItem int(11) NOT NULL default '2',
  Modified int(11) NOT NULL default '0',
  ModifiedById int(11) NOT NULL default '0',
  PRIMARY KEY  (CategoryId),
  KEY ParentId (ParentId),
  UNIQUE KEY ResourceId (ResourceId),
  KEY Modified (Modified),
  KEY Priority (Priority),
  KEY sorting (Name,Priority)
)

# --------------------------------------------------------

CREATE TABLE CategoryItems (
  CategoryId int(11) NOT NULL default '0',
  ItemResourceId int(11) NOT NULL default '0',
  PrimaryCat tinyint(4) NOT NULL default '0',
  KEY CategoryId (CategoryId),
  KEY ItemResourceId (ItemResourceId),
  KEY PrimaryCat (PrimaryCat)
)

# --------------------------------------------------------

CREATE TABLE ConfigurationAdmin (
  VariableName varchar(80) NOT NULL default '',
  heading varchar(255) default NULL,
  prompt varchar(255) default NULL,
  element_type varchar(20) NOT NULL default '',
  validation varchar(255) default NULL,
  ValueList text default NULL,
  DisplayOrder int(11) NOT NULL default '0',
  Install int(11) NOT NULL default '1',
  PRIMARY KEY  (VariableName)
)

# --------------------------------------------------------

CREATE TABLE ConfigurationValues (
  VariableName varchar(255) NOT NULL default '',
  VariableValue varchar(255) default NULL,
  ModuleOwner varchar(20) default 'In-Portal',
  Section varchar(255) NOT NULL default '',
  PRIMARY KEY  (VariableName)
)

# --------------------------------------------------------

CREATE TABLE CountCache (
  ListType int(11) NOT NULL default '0',
  ItemType int(11) NOT NULL default '-1',
  Value int(11) NOT NULL default '0',
  CountCacheId int(11) NOT NULL auto_increment,
  LastUpdate int(11) NOT NULL default '0',
  ExtraId varchar(50) default NULL,
  TodayOnly tinyint(4) NOT NULL default '0',
  PRIMARY KEY  (CountCacheId)
)

# --------------------------------------------------------

CREATE TABLE CustomField (
  CustomFieldId int(11) NOT NULL auto_increment,
  Type int(11) NOT NULL default '0',
  FieldName varchar(255) NOT NULL default '',
  FieldLabel varchar(40) default NULL,
  Heading varchar(60) default NULL,
  Prompt varchar(60) default NULL,
  ElementType varchar(50) NOT NULL default '',
  ValueList varchar(255) default NULL,
  DisplayOrder int(11) NOT NULL default '0',
  OnGeneralTab tinyint(4) NOT NULL default '0',
  PRIMARY KEY  (CustomFieldId),
  KEY Type (Type)
)

# --------------------------------------------------------

CREATE TABLE CustomMetaData (
  CustomDataId int(11) NOT NULL auto_increment,
  ResourceId int(11) NOT NULL default '0',
  CustomFieldId int(11) NOT NULL default '0',
  Value text NOT NULL,
  PRIMARY KEY  (CustomDataId),
  KEY ResourceId (ResourceId),
  KEY CustomFieldId (CustomFieldId)
)

# --------------------------------------------------------

CREATE TABLE EmailMessage (
  EmailMessageId int(10) NOT NULL auto_increment,
  Template longtext,
  MessageType enum('html','text') NOT NULL default 'text',
  LanguageId int(11) NOT NULL default '0',
  EventId int(11) NOT NULL default '0',
  PRIMARY KEY  (EmailMessageId)
)

# --------------------------------------------------------

CREATE TABLE EmailQueue (
  Subject text NOT NULL,
  toaddr text NOT NULL,
  fromaddr text NOT NULL,
  message blob,
  headers blob,
  queued timestamp NOT NULL
)

# --------------------------------------------------------

CREATE TABLE EmailSubscribers (
  EmailMessageId int(11) NOT NULL default '0',
  PortalUserId int(11) NOT NULL default '0'
)

# --------------------------------------------------------

CREATE TABLE Events (
  EventId int(11) NOT NULL auto_increment,
  Event varchar(40) NOT NULL default '',
  Enabled int(11) NOT NULL default '1',
  FromUserId int(11) NOT NULL default '0',
  Module varchar(40) NOT NULL default '',
  Description varchar(255) NOT NULL default '',
  Type int(11) NOT NULL default '0',
  PRIMARY KEY  (EventId)
)

# --------------------------------------------------------

CREATE TABLE Favorites (
  FavoriteId int(11) NOT NULL auto_increment,
  PortalUserId int(11) NOT NULL default '0',
  ResourceId int(11) NOT NULL default '0',
  ItemTypeId int(11) NOT NULL default '0',
  Modified int(11) NOT NULL default '0',
  PRIMARY KEY  (FavoriteId),
  UNIQUE KEY main (PortalUserId,ResourceId)
)

# --------------------------------------------------------

CREATE TABLE IdGenerator (
  lastid int(11) default NULL
)

# --------------------------------------------------------

CREATE TABLE Images (
  ImageId int(11) NOT NULL auto_increment,
  ResourceId int(11) NOT NULL default '0',
  Url varchar(255) NOT NULL default '',
  Name varchar(255) NOT NULL default '',
  AltName varchar(255) default NULL,
  ImageIndex int(11) NOT NULL default '0',
  LocalImage tinyint(4) NOT NULL default '1',
  LocalPath varchar(240) NOT NULL default '',
  Enabled int(11) NOT NULL default '1',
  DefaultImg int(11) NOT NULL default '0',
  ThumbUrl varchar(255) default NULL,
  Priority int(11) NOT NULL default '0',
  ThumbPath varchar(255) default NULL,
  LocalThumb tinyint(4) NOT NULL default '0',
  SameImages tinyint(4) NOT NULL default '0',
  PRIMARY KEY  (ImageId),
  KEY ResourceId (ResourceId)
)

# --------------------------------------------------------

CREATE TABLE ItemRating (
  RatingId int(11) NOT NULL auto_increment,
  IPAddress varchar(255) NOT NULL default '',
  CreatedOn double NOT NULL default '0',
  RatingValue int(11) NOT NULL default '0',
  ItemId int(11) NOT NULL default '0',
  PRIMARY KEY  (RatingId)
)

# --------------------------------------------------------

CREATE TABLE ItemReview (
  ReviewId int(11) NOT NULL auto_increment,
  CreatedOn double NOT NULL default '0',
  ReviewText longtext NOT NULL,
  IPAddress varchar(255) NOT NULL default '',
  ItemId int(11) NOT NULL default '0',
  CreatedById int(11) NOT NULL default '0',
  ItemType tinyint(4) NOT NULL default '0',
  Priority int(11) NOT NULL default '0',
  Status tinyint(4) NOT NULL default '0',
  TextFormat int(11) NOT NULL default '0',
  Module varchar(255) NOT NULL default '',
  PRIMARY KEY  (ReviewId)
)

# --------------------------------------------------------

CREATE TABLE ItemTypes (
  ItemType int(11) NOT NULL default '0',
  Module varchar(50) NOT NULL default '',
  SourceTable varchar(100) NOT NULL default '',
  TitleField varchar(50) default NULL,
  CreatorField varchar(255) NOT NULL default '',
  PopField varchar(255) default NULL,
  RateField varchar(255) default NULL,
  LangVar varchar(255) NOT NULL default '',
  PrimaryItem int(11) NOT NULL default '0',
  EditUrl varchar(255) NOT NULL default '',
  ClassName varchar(40) NOT NULL default '',
  ItemName varchar(50) NOT NULL default '',
  PRIMARY KEY  (ItemType),
  KEY Module (Module)
)

# --------------------------------------------------------

CREATE TABLE Language (
  LanguageId int(11) NOT NULL auto_increment,
  PackName varchar(40) NOT NULL default '',
  LocalName varchar(40) NOT NULL default '',
  Enabled int(11) NOT NULL default '0',
  PrimaryLang int(11) NOT NULL default '0',
  IconURL varchar(255) default NULL,
  DateFormat varchar(50) NOT NULL default '',
  TimeFormat varchar(50) NOT NULL default '',
  DecimalPoint char(2) NOT NULL default '.',
  ThousandSep char(1) NOT NULL default ',',
  Charset varchar(20) NOT NULL default '',
  PRIMARY KEY  (LanguageId)
)

# --------------------------------------------------------

CREATE TABLE Modules (
  Name varchar(255) NOT NULL default '',
  Path varchar(255) NOT NULL default '',
  Var varchar(10) NOT NULL default '',
  Version varchar(10) NOT NULL default '',
  Loaded tinyint(4) NOT NULL default '1',
  LoadOrder tinyint(4) NOT NULL default '0',
  TemplatePath varchar(255) NOT NULL default '',
  RootCat int(11) NOT NULL default '0',
  BuildDate double NOT NULL default '0',
  PRIMARY KEY  (Name)
)

# --------------------------------------------------------

CREATE TABLE PermCache (
  PermCacheId int(11) NOT NULL auto_increment,
  CategoryId int(11) NOT NULL default '0',
  PermId int(11) NOT NULL default '0',
  ACL varchar(255) NOT NULL default '',
  DACL varchar(255) NOT NULL default '',
  PRIMARY KEY  (PermCacheId),
  KEY CategoryId (CategoryId),
  KEY PermId (PermId)
)

# --------------------------------------------------------

CREATE TABLE PermissionConfig (
  PermissionConfigId int(11) NOT NULL auto_increment,
  PermissionName varchar(30) NOT NULL default '',
  Description varchar(255) NOT NULL default '',
  ErrorMessage varchar(255) NOT NULL default '',
  ModuleId varchar(20) NOT NULL default '0',
  PRIMARY KEY  (PermissionConfigId),
  KEY PermissionName (PermissionName)
)

# --------------------------------------------------------

CREATE TABLE Permissions (
  PermissionId int(11) NOT NULL auto_increment,
  Permission varchar(30) NOT NULL default '',
  GroupId int(11) default '0',
  PermissionValue int(11) NOT NULL default '0',
  Type tinyint(4) NOT NULL default '0',
  CatId int(11) NOT NULL default '0',
  PRIMARY KEY  (PermissionId)
)

# --------------------------------------------------------

CREATE TABLE PersistantSessionData (
  PortalUserId int(11) NOT NULL default '0',
  VariableName varchar(255) NOT NULL default '',
  VariableValue text NOT NULL,
  KEY UserId (PortalUserId),
  KEY VariableName (VariableName)
)

# --------------------------------------------------------

CREATE TABLE Phrase (
  Phrase varchar(255) NOT NULL default '',
  Translation varchar(255) NOT NULL default '',
  PhraseType int(11) NOT NULL default '0',
  PhraseId int(11) NOT NULL auto_increment,
  LanguageId int(11) NOT NULL default '0',
  PRIMARY KEY  (PhraseId),
  INDEX Phrase_Index (Phrase)
)

# --------------------------------------------------------

CREATE TABLE PhraseCache (
  Template varchar(40) NOT NULL default '',
  PhraseList text NOT NULL,
  CacheDate int(11) NOT NULL default '0',
  ThemeId int(11) NOT NULL default '0',
  PRIMARY KEY  (Template)
)

# --------------------------------------------------------

CREATE TABLE PortalGroup (
  GroupId int(11) NOT NULL auto_increment,
  Name varchar(255) NOT NULL default '',
  Description varchar(255) default NULL,
  CreatedOn double NOT NULL default '0',
  System tinyint(4) NOT NULL default '0',
  Personal tinyint(4) NOT NULL default '0',
  Enabled tinyint(4) NOT NULL default '1',
  ResourceId int(11) NOT NULL default '0',
  PRIMARY KEY  (GroupId),
  UNIQUE KEY Name (Name),
  UNIQUE KEY ResourceId (ResourceId),
  KEY Personal (Personal),
  KEY Enabled (Enabled)
)

# --------------------------------------------------------

CREATE TABLE PortalUser (
  PortalUserId int(11) NOT NULL auto_increment,
  Login varchar(255) default NULL,
  Password varchar(255) default NULL,
  FirstName varchar(255) default NULL,
  LastName varchar(255) default NULL,
  Email varchar(255) NOT NULL default '',
  CreatedOn double NOT NULL default '0',
  Phone varchar(20) default NULL,
  Street varchar(255) default NULL,
  City varchar(20) default NULL,
  State varchar(20) default NULL,
  Zip varchar(20) default NULL,
  Country varchar(20) NOT NULL default '',
  ResourceId int(11) NOT NULL default '0',
  Status tinyint(4) NOT NULL default '2',
  Modified int(11) NOT NULL default '0',
  dob double NOT NULL default '0',
  tz int(11) default NULL,
  ip varchar(20) default NULL,
  IsBanned tinyint(1) NOT NULL default '0',
  PassResetTime bigint(20),
  PwResetConfirm varchar(255),
  PwRequestTime bigint(25),
  MinPwResetDelay int(11) NOT NULL default '1800', 
  PRIMARY KEY  (PortalUserId),
  UNIQUE KEY Login (Login),
  UNIQUE KEY ResourceId (ResourceId),
  KEY CreatedOn (CreatedOn)
)

# --------------------------------------------------------

CREATE TABLE Relationship (
  RelationshipId int(11) NOT NULL auto_increment,
  SourceId int(11) default NULL,
  TargetId int(11) default NULL,
  SourceType tinyint(4) NOT NULL default '0',
  TargetType tinyint(4) NOT NULL default '0',
  Type int(11) NOT NULL default '0',
  Enabled int(11) NOT NULL default '1',
  Priority int(11) NOT NULL default '0',
  PRIMARY KEY  (RelationshipId),
  KEY RelSource (SourceId),
  KEY RelTarget (TargetId)
)

# --------------------------------------------------------

CREATE TABLE SearchConfig (
  TableName varchar(40) NOT NULL default '',
  FieldName varchar(40) NOT NULL default '',
  SimpleSearch tinyint(4) NOT NULL default '0',
  AdvancedSearch tinyint(4) NOT NULL default '0',
  Description varchar(255) default NULL,
  DisplayName varchar(80) default NULL,
  ModuleName varchar(20) default NULL,
  ConfigHeader varchar(255) default NULL,
  DisplayOrder int(11) NOT NULL default '0',
  SearchConfigId int(11) NOT NULL auto_increment,
  Priority int(11) NOT NULL default '0',
  FieldType varchar(20) NOT NULL default 'text',
  ForeignField varchar(255) default NULL,
  JoinClause varchar(255) default NULL,
  IsWhere text,
  IsNotWhere text,
  ContainsWhere text,
  NotContainsWhere text,
  CustomFieldId int(11) NOT NULL default '0',
  PRIMARY KEY  (SearchConfigId)
)

# --------------------------------------------------------

CREATE TABLE SearchLog (
  SearchLogId int(11) NOT NULL auto_increment,
  Keyword varchar(255) NOT NULL default '',
  Indices bigint(20) NOT NULL default '0',
  SearchType int(11) NOT NULL default '0',
  PRIMARY KEY  (SearchLogId)
)

# --------------------------------------------------------

CREATE TABLE SessionData (
  SessionKey varchar(50) NOT NULL default '',
  VariableName varchar(255) NOT NULL default '',
  VariableValue text NOT NULL,
  PRIMARY KEY  (`SessionKey`,`VariableName`),
  KEY SessionKey (SessionKey),
  KEY VariableName (VariableName)
)

# --------------------------------------------------------

CREATE TABLE SpamControl (
  ItemResourceId int(11) NOT NULL default '0',
  IPaddress varchar(20) NOT NULL default '',
  Expire double NOT NULL default '0',
  PortalUserId int(11) NOT NULL default '0',
  DataType varchar(20) default NULL
)

# --------------------------------------------------------

CREATE TABLE StatItem (
  StatItemId int(11) NOT NULL auto_increment,
  Module varchar(20) NOT NULL default '',
  ValueSQL varchar(255) default NULL,
  ResetSQL varchar(255) default NULL,
  ListLabel varchar(255) NOT NULL default '',
  Priority int(11) NOT NULL default '0',
  AdminSummary int(11) NOT NULL default '0',
  PRIMARY KEY  (StatItemId)
)

# --------------------------------------------------------

CREATE TABLE Theme (
  ThemeId int(11) NOT NULL auto_increment,
  Name varchar(40) NOT NULL default '',
  Enabled int(11) NOT NULL default '1',
  Description varchar(255) default NULL,
  PrimaryTheme int(11) NOT NULL default '0',
  CacheTimeout int(11) NOT NULL default '0',
  PRIMARY KEY  (ThemeId)
)

# --------------------------------------------------------

CREATE TABLE ThemeFiles (
  FileId int(11) NOT NULL auto_increment,
  ThemeId int(11) NOT NULL default '0',
  FileName varchar(255) NOT NULL default '',
  FilePath varchar(255) NOT NULL default '',
  Description varchar(255) default NULL,
  FileType int(11) NOT NULL default '0',
  PRIMARY KEY  (FileId),
  KEY theme (ThemeId)
)

# --------------------------------------------------------

CREATE TABLE UserGroup (
  PortalUserId int(11) NOT NULL default '0',
  GroupId int(11) NOT NULL default '0',
  PrimaryGroup tinyint(4) NOT NULL default '1',
  PRIMARY KEY  (PortalUserId,GroupId),
  KEY GroupId (GroupId),
  KEY PrimaryGroup (PrimaryGroup)
)

# --------------------------------------------------------



CREATE TABLE UserSession (
  SessionKey varchar(50) NOT NULL default '',
  CurrentTempKey varchar(50) default NULL,
  PrevTempKey varchar(50) default NULL,
  LastAccessed double NOT NULL default '0',
  PortalUserId varchar(255) NOT NULL default '',
  Language varchar(255) NOT NULL default '',
  Theme varchar(255) NOT NULL default '',
  GroupId int(11) NOT NULL default '0',
  IpAddress varchar(20) NOT NULL default '0.0.0.0',
  Status int(11) NOT NULL default '1',
  GroupList varchar(255) default NULL,
  tz int(11) default NULL,
  PRIMARY KEY  (SessionKey),
  KEY UserId (PortalUserId),
  KEY LastAccessed (LastAccessed)
)

# --------------------------------------------------------

CREATE TABLE SuggestMail (
  email varchar(255) NOT NULL default '',
  sent double,
  PRIMARY KEY  (email)
) 

# --------------------------------------------------------

CREATE TABLE SysCache (
  SysCacheId int(11) NOT NULL auto_increment,
  Name varchar(255) NOT NULL default '',
  Value mediumtext,
  Expire double NOT NULL default '0',
  Module varchar(20) default NULL,
  Context varchar(255) default NULL,
  GroupList varchar(255) NOT NULL default '',
  PRIMARY KEY  (SysCacheId),
  KEY Name (Name),
  KEY Expire (Expire)
)    

# --------------------------------------------------------

CREATE TABLE TagLibrary (
  TagId int(11) NOT NULL auto_increment,
  name varchar(255) NOT NULL default '',
  description text,
  example text,
  scope varchar(20) NOT NULL default 'global',
  PRIMARY KEY  (TagId)
)

# --------------------------------------------------------

CREATE TABLE TagAttributes (
  AttrId int(11) NOT NULL auto_increment,
  TagId int(11) NOT NULL default '0',
  Name varchar(255) NOT NULL default '',
  AttrType varchar(20) default NULL,
  DefValue varchar(255) default NULL,
  Description TEXT,
  Required int(11) NOT NULL default '0',
  PRIMARY KEY  (AttrId)
)

# --------------------------------------------------------

CREATE TABLE EmailLog (
  EmailLogId int(11) NOT NULL auto_increment,
  fromuser varchar(200) default NULL,
  addressto varchar(255) default NULL,
  subject varchar(255) default NULL,
  timestamp bigint(20) default '0',
  event varchar(100) default NULL,
  PRIMARY KEY  (EmailLogId)
)

# --------------------------------------------------------

CREATE TABLE ImportScripts (
  is_id smallint(5) unsigned NOT NULL auto_increment,
  is_Module varchar(50) NOT NULL default '',
  is_string_id varchar(10) NOT NULL default '',
  is_script varchar(100) NOT NULL default '',
  is_label varchar(255) NOT NULL default '',
  is_field_prefix varchar(50) NOT NULL default '',
  is_requred_fields varchar(255) NOT NULL default '',
  is_enabled tinyint(1) unsigned NOT NULL default '0',
  PRIMARY KEY  (is_id)
)