CREATE TABLE IF NOT EXISTS jcow_accounts (
  id serial,
  fbid bigint NOT NULL default '0',
  email varchar(120) NOT NULL default '',
  lastact int NOT NULL default '0',
  created int NOT NULL default '0',
  username varchar(25) NOT NULL default '',
  fullname varchar(30) NOT NULL default '',
  password varchar(32) NOT NULL default '',
  level smallint NOT NULL default '0',
  points int NOT NULL default '0',
  avatar varchar(200) NOT NULL default '',
  signature text,
  blurbs text,
  profile_permission smallint NOT NULL default '0',
  location varchar(100) NOT NULL default '',
  lastlogin int NOT NULL default '0',
  ipaddress varchar(30) NOT NULL default '',
  chpass varchar(10) NOT NULL default '',
  disabled smallint NOT NULL default '0',
  intr text,
  gender smallint NOT NULL default '0',
  about_me text,
  birthyear int NOT NULL default '0',
  birthmonth smallint NOT NULL default '0',
  birthday smallint NOT NULL default '0',
  hide_age smallint NOT NULL default '0',
  reg_code varchar(8) NOT NULL default '',
  forum_posts int NOT NULL default '0',
  featured smallint NOT NULL default '0',
  roles varchar(255) NOT NULL default '',
  country varchar(50) NOT NULL default '',
  locale varchar(50) NOT NULL default '',
  state varchar(50) NOT NULL default '',
  jcowsess char(12) NOT NULL default '',
  token varchar(32) NOT NULL default '',
  wall_id int NOT NULL default '0',
  followers int NOT NULL default '0',
  coins int NOT NULL default '0',
  verified int NOT NULL default '0',
  settings text,
  var1 varchar(255) NOT NULL default '',
  var2 varchar(255) NOT NULL default '',
  var3 varchar(255) NOT NULL default '',
  var4 varchar(255) NOT NULL default '',
  var5 varchar(255) NOT NULL default '',
  var6 varchar(255) NOT NULL default '',
  var7 varchar(255) NOT NULL default '',
  pass varchar(32) NOT NULL default '',
  hide_me smallint NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_accounts_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_accounts (username);
CREATE INDEX ON jcow_accounts (lastlogin);
CREATE INDEX ON jcow_accounts (email);
CREATE INDEX ON jcow_accounts (fbid);




CREATE TABLE IF NOT EXISTS jcow_blacks (
  id serial,
  uid int NOT NULL default '0',
  bid int NOT NULL default '0',
  bname varchar(50) NOT NULL default '',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_blacks_id_seq RESTART WITH 4;

CREATE INDEX ON jcow_blacks (uid,bid);




CREATE TABLE IF NOT EXISTS jcow_cache (
  ckey varchar(50) NOT NULL default '',
  content text,
  expired int NOT NULL default '0'
) ;


CREATE TABLE IF NOT EXISTS jcow_signup_attempts(ipaddress varchar(255), created int) ;


CREATE TABLE IF NOT EXISTS jcow_comments (
  id serial,
  target_id varchar(20) NOT NULL default '',
  uid int NOT NULL default '0',
  message text,
  created int NOT NULL default '0',
  stream_id int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_comments_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_comments (target_id);
CREATE INDEX ON jcow_comments (stream_id);



CREATE TABLE IF NOT EXISTS jcow_favorites (
  id serial,
  uid int NOT NULL default '0',
  fuid int NOT NULL default '0',
  fapp text NOT NULL default '',
  fsid int NOT NULL default '0',
  created int NOT NULL default '0',
  title text NOT NULL default '',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_favorites_id_seq RESTART WITH 24;

CREATE INDEX ON jcow_favorites (uid,fuid,fsid,created);



CREATE TABLE IF NOT EXISTS jcow_followers (
  uid int NOT NULL default '0',
  fid int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_followers (uid,fid);




CREATE TABLE IF NOT EXISTS jcow_forums (
  id serial,
  weight int NOT NULL default '0',
  parent_id int NOT NULL default '0',
  name varchar(255) NOT NULL default '',
  type_pic varchar(255) NOT NULL default '',
  description text,
  rules text,
  forum_type varchar(50) NOT NULL default '0',
  threads int NOT NULL default '0',
  posts int NOT NULL default '0',
  lastpostname varchar(32) NOT NULL default '',
  lastposttopicid int NOT NULL default '0',
  lastposttopic varchar(70) NOT NULL default '',
  lastpostcreated int NOT NULL default '0',
  moderator varchar(255) NOT NULL default '',
  settings text,
  fmembers int NOT NULL default '0',
  image varchar(250) NOT NULL default '',
  read_roles varchar(255) NOT NULL default '',
  upload_roles varchar(255) NOT NULL default '',
  thread_roles varchar(255) NOT NULL default '',
  reply_roles varchar(255) NOT NULL default '',
  moderators varchar(255) NOT NULL default '',
  PRIMARY KEY  (id)
)  ;
 
ALTER SEQUENCE jcow_forums_id_seq RESTART WITH 9;

CREATE INDEX ON jcow_forums (parent_id);
CREATE INDEX ON jcow_forums (weight);
CREATE INDEX ON jcow_forums (forum_type);




INSERT INTO jcow_forums (id, weight, parent_id, name, type_pic, description, rules, forum_type, threads, posts, lastpostname, lastposttopicid, lastposttopic, lastpostcreated, moderator, settings, fmembers, image, read_roles, upload_roles, thread_roles, reply_roles, moderators) VALUES
(7, 1, 0, 'General Category', '', '', '', 'category', 0, 0, '', 0, '', 0, '', '', 0, '', '', '', '', '', ''),
(8, 1, 7, 'General Forum', '', 'This is a general forum', '', 'forum', 0, 0, '', 0, '', 0, '', '', 0, '', '1|2', '2', '2', '2', '');




CREATE TABLE IF NOT EXISTS jcow_forum_attachments (
  id serial,
  pid int NOT NULL default '0',
  tid int NOT NULL default '0',
  uri varchar(100) NOT NULL default '',
  des varchar(255) NOT NULL default '',
  size int NOT NULL default '0',
  orginal_name varchar(255) NOT NULL default '',
  downloads int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_forum_attachments_id_seq RESTART WITH 5;

CREATE INDEX ON jcow_forum_attachments (pid);
CREATE INDEX ON jcow_forum_attachments (tid);




CREATE TABLE IF NOT EXISTS jcow_forum_polls (
  id serial,
  tid int NOT NULL default '0',
  question varchar(100) NOT NULL default '',
  created int NOT NULL default '0',
  options text,
  timeout int NOT NULL default '0',
  options_per_user smallint NOT NULL default '0',
  voters text,
  total int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_forum_polls_id_seq RESTART WITH 8;

CREATE INDEX ON jcow_forum_polls (tid);




CREATE TABLE IF NOT EXISTS jcow_forum_posts (
  id serial,
  tid bigint NOT NULL default '0',
  uid int NOT NULL default '0',
  title varchar(255) NOT NULL default '',
  message text,
  created int NOT NULL default '0',
  ip varchar(30) NOT NULL default '',
  is_first smallint NOT NULL default '0',
  attach int NOT NULL default '0',
  bbcode_off smallint NOT NULL default '0',
  emote_off smallint NOT NULL default '0',
  got_attach smallint NOT NULL default '0',
  stream_id int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_forum_posts_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_forum_posts (tid);
CREATE INDEX ON jcow_forum_posts (uid);
CREATE INDEX ON jcow_forum_posts (stream_id);



CREATE TABLE IF NOT EXISTS jcow_forum_threads (
  id serial,
  fid int NOT NULL default '0',
  old_fid int NOT NULL default '0',
  pid int NOT NULL default '0',
  userid int NOT NULL default '0',
  username varchar(50) NOT NULL default '',
  topic varchar(255) NOT NULL default '',
  views int NOT NULL default '0',
  posts int NOT NULL default '0',
  closed smallint NOT NULL default '0',
  created int NOT NULL default '0',
  lastpostusername varchar(255) NOT NULL default '0',
  lastpostcreated int NOT NULL default '0',
  icon smallint NOT NULL default '0',
  thread_type smallint NOT NULL default '0',
  thread_lock smallint NOT NULL default '0',
  got_poll smallint NOT NULL default '0',
  got_attach smallint NOT NULL default '0',
  stressed smallint NOT NULL default '0',
  digg int NOT NULL default '0',
  dugg int NOT NULL default '0',
  votes text,
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_forum_threads_id_seq RESTART WITH 29;

CREATE INDEX ON jcow_forum_threads (fid);
CREATE INDEX ON jcow_forum_threads (thread_type);




CREATE TABLE IF NOT EXISTS jcow_friends (
  uid int NOT NULL default '0',
  fid int NOT NULL default '0',
  created int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_friends (uid,fid);
CREATE INDEX ON jcow_friends (fid);




CREATE TABLE IF NOT EXISTS jcow_friend_reqs (
  uid int NOT NULL default '0',
  fid int NOT NULL default '0',
  created int NOT NULL default '0',
  msg varchar(200)  NOT NULL default ''
) ;

CREATE INDEX ON jcow_friend_reqs (uid,fid);




CREATE TABLE IF NOT EXISTS jcow_groups (
  id serial,
  uri varchar(30) NOT NULL default '',
  name varchar(100) NOT NULL default '',
  slogan varchar(200) NOT NULL default '',
  creatorid int NOT NULL default '0',
  creator varchar(50) NOT NULL default '',
  description text,
  members int NOT NULL default '0',
  created int NOT NULL default '0',
  logo varchar(100) NOT NULL default '',
  private smallint NOT NULL default '0',
  needapproval smallint NOT NULL default '0',
  posts int NOT NULL default '0',
  topics int NOT NULL default '0',
  lastptime int NOT NULL default '0',
  lastpname varchar(50) NOT NULL default '',
  password varchar(32) NOT NULL default '',
  custom_css text,
  style_ids varchar(50) NOT NULL default '',
  category char(2) NOT NULL default '',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_groups_id_seq RESTART WITH 21;

CREATE INDEX ON jcow_groups (creatorid);
CREATE INDEX ON jcow_groups (uri);




CREATE TABLE IF NOT EXISTS jcow_group_categories (
  id serial,
  name varchar(50) NOT NULL default '',
  groups int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_group_categories_id_seq RESTART WITH 1;




CREATE TABLE IF NOT EXISTS jcow_group_members (
  gid int NOT NULL default '0',
  uid int NOT NULL default '0',
  created int NOT NULL default '0',
  nickname varchar(20) NOT NULL default '',
  about_me text,
  hide_profile smallint NOT NULL default '0'
) ;

CREATE INDEX ON jcow_group_members (gid);




CREATE TABLE IF NOT EXISTS jcow_group_members_pending (
  uid int NOT NULL default '0',
  gid int NOT NULL default '0',
  created int NOT NULL default '0',
  ignored smallint NOT NULL default '0'
) ;

CREATE INDEX ON jcow_group_members_pending (uid,gid);




CREATE TABLE IF NOT EXISTS jcow_group_polls (
  id serial,
  tid int NOT NULL default '0',
  question varchar(100) NOT NULL default '',
  created int NOT NULL default '0',
  options text,
  timeout int NOT NULL default '0',
  options_per_user smallint NOT NULL default '0',
  voters text,
  total int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_group_polls_id_seq RESTART WITH 6;

CREATE INDEX ON jcow_group_polls (tid);




CREATE TABLE IF NOT EXISTS jcow_group_postcats (
  id serial,
  gid int NOT NULL default '0',
  name varchar(100) NOT NULL default '',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_group_postcats_id_seq RESTART WITH 3;

CREATE INDEX ON jcow_group_postcats (gid);




CREATE TABLE IF NOT EXISTS jcow_group_posts (
  id serial,
  gid int NOT NULL default '0',
  tid bigint NOT NULL default '0',
  uid int NOT NULL default '0',
  username varchar(50) NOT NULL default '',
  rtid int NOT NULL default '0',
  rid int NOT NULL default '0',
  rname varchar(100) NOT NULL default '',
  message text,
  created int NOT NULL default '0',
  ip varchar(30) NOT NULL default '',
  attach int NOT NULL default '0',
  bbcode_off smallint NOT NULL default '0',
  emote_off smallint NOT NULL default '0',
  got_attach smallint NOT NULL default '0',
  topic varchar(100) NOT NULL default '',
  is_first smallint NOT NULL default '0',
  replies int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_group_posts_id_seq RESTART WITH 100;

CREATE INDEX ON jcow_group_posts (tid);
CREATE INDEX ON jcow_group_posts (uid);
CREATE INDEX ON jcow_group_posts (gid);
CREATE INDEX ON jcow_group_posts (rtid);
CREATE INDEX ON jcow_group_posts (rid);




CREATE TABLE IF NOT EXISTS jcow_group_topics (
  id serial,
  gid int NOT NULL default '0',
  old_fid int NOT NULL default '0',
  pid int NOT NULL default '0',
  uid int NOT NULL default '0',
  username varchar(50) NOT NULL default '',
  topic varchar(255) NOT NULL default '',
  views int NOT NULL default '0',
  posts int NOT NULL default '0',
  closed smallint NOT NULL default '0',
  created int NOT NULL default '0',
  lastpostusername varchar(255) NOT NULL default '0',
  lastpostcreated int NOT NULL default '0',
  icon smallint NOT NULL default '0',
  thread_type smallint NOT NULL default '0',
  thread_lock smallint NOT NULL default '0',
  got_poll smallint NOT NULL default '0',
  got_attach smallint NOT NULL default '0',
  stressed smallint NOT NULL default '0',
  digg int NOT NULL default '0',
  dugg int NOT NULL default '0',
  votes text,
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_group_topics_id_seq RESTART WITH 32;

CREATE INDEX ON jcow_group_topics (gid);




CREATE TABLE IF NOT EXISTS jcow_gvars (
  gkey varchar(50) NOT NULL default '',
  gvalue text
) ;

CREATE INDEX ON jcow_gvars (gkey);




INSERT INTO jcow_gvars (gkey, gvalue) VALUES
('theme_folder', 'themes/default'),
('cf_var1', 'disabled'),
('cf_var2', 'disabled'),
('cf_var3', 'disabled'),
('cf_var4', 'disabled'),
('cf_var5', 'disabled'),
('cf_var6', 'disabled'),
('cf_var7', 'disabled'),
('jcow_version', '4.0'),
('app_music_disable', '0'),
('story_access', 'all'),
('profile_access', 'all'),
('site_slogan', 'This is a Social Network'),
('ad_block_content_top', ''),
('ad_block_content_bottom', ''),
('site_name', 'My Jcow Network'),
('site_email', 'name@domain.com'),
('block_top', ''),
('block_bottom', ''),
('only_invited', '0'),
('session_lived', '1267784005'),
('permission_etheme', '2'),
('permission_atheme', '2|11'),
('private_network', '0'),
('theme_tpl', 'default'),
('theme_css', '1.css'),
('hide_ad_roles', '3'),
('acc_verify', '0'),
('permission_upload', '2'),
('permission_comment', '2'),
('permission_add', '2'),
('permission_browse', '1|2'),
('permission_feed', '1|2'),
('theme_block_adsbar', 'Go to "Admin CP" - "Themes" - "Manage Blocks" to edit this message.'),
('limit_posting_num', '5'),
('app_music', '0');



CREATE TABLE IF NOT EXISTS jcow_invites (
  id serial,
  uid int NOT NULL default '0',
  email varchar(255) NOT NULL default '',
  status smallint NOT NULL default '0',
  created int NOT NULL default '0',
  code varchar(15) NOT NULL default '',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_invites_id_seq RESTART WITH 1;




CREATE TABLE IF NOT EXISTS jcow_langs (
  lang_from varchar(255) NOT NULL default '',
  lang_to text,
  lang varchar(20) NOT NULL default ''
) ;

CREATE INDEX ON jcow_langs (lang_from);




CREATE TABLE IF NOT EXISTS jcow_messages (
  id serial,
  subject varchar(100) NOT NULL default '',
  message text,
  from_id int NOT NULL default '0',
  to_id int NOT NULL default '0',
  created int NOT NULL default '0',
  hasread smallint NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_messages_id_seq RESTART WITH 25;

CREATE INDEX ON jcow_messages (from_id,to_id);





CREATE TABLE IF NOT EXISTS jcow_profiles (
  id int NOT NULL default '0',
  style_ids varchar(255) NOT NULL default '',
  custom_css text,
  background varchar(100) NOT NULL default '',
  videoid int NOT NULL default '0',
  favorites int NOT NULL default '0',
  views int NOT NULL default '0',
  PRIMARY KEY  (id)
) ;



CREATE TABLE IF NOT EXISTS jcow_profile_comments (
  id serial,
  uid int NOT NULL default '0',
  target_id int NOT NULL default '0',
  message text,
  created int NOT NULL default '0',
  stream_id int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_profile_comments_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_profile_comments (stream_id);




CREATE TABLE IF NOT EXISTS jcow_roles (
  id int NOT NULL default '0',
  name text NOT NULL default ''
) ;

CREATE INDEX ON jcow_roles (id);




INSERT INTO jcow_roles (id, name) VALUES
(1, 'Guest'),
(2, 'General member'),
(3, 'Administrator');





CREATE TABLE IF NOT EXISTS jcow_stories (
  id serial,
  cid int NOT NULL default '0',
  sticky smallint NOT NULL default '0',
  closed smallint NOT NULL default '0',
  title varchar(120) NOT NULL default '',
  thumbnail varchar(255) NOT NULL default '',
  content text,
  uid int NOT NULL default '0',
  created int NOT NULL default '0',
  lastreply int NOT NULL default '0',
  lastreplyuname varchar(50) NOT NULL default '',
  lastreplyuid int NOT NULL default '0',
  updated int NOT NULL default '0',
  views int NOT NULL default '0',
  comments int NOT NULL default '0',
  stream_id int NOT NULL default '0',
  app varchar(50) NOT NULL default '',
  digg int NOT NULL default '0',
  dugg int NOT NULL default '0',
  photos int NOT NULL default '0',
  tags varchar(255) NOT NULL default '',
  featured smallint NOT NULL default '0',
  var1 varchar(255) NOT NULL default '',
  var2 varchar(255) NOT NULL default '',
  var3 varchar(255) NOT NULL default '',
  var4 varchar(255) NOT NULL default '',
  var5 varchar(255) NOT NULL default '',
  inte1 int NOT NULL default '0',
  inte2 int NOT NULL default '0',
  text1 text,
  text2 text,
  blob1 bytea,
  rating text,
  page_id int NOT NULL default '0',
  page_type VARCHAR( 25 ) NOT NULL default '',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_stories_id_seq RESTART WITH 79;

CREATE INDEX ON jcow_stories (app);
CREATE INDEX ON jcow_stories (uid);
CREATE INDEX ON jcow_stories (page_id);
CREATE INDEX ON jcow_stories (cid);




CREATE TABLE IF NOT EXISTS jcow_story_categories (
  id serial,
  gid int NOT NULL default '0',
  name varchar(150) NOT NULL default '',
  description text,
  weight int NOT NULL default '0',
  app varchar(50) NOT NULL default '',
  var1 varchar(255) NOT NULL default '',
  var2 varchar(255) NOT NULL default '',
  var3 varchar(255) NOT NULL default '',
  var4 varchar(255) NOT NULL default '',
  var5 varchar(255) NOT NULL default '',
  uri varchar(255) NOT NULL default '',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_story_categories_id_seq RESTART WITH 7;

CREATE INDEX ON jcow_story_categories (app);
CREATE INDEX ON jcow_story_categories (weight);



CREATE TABLE IF NOT EXISTS jcow_story_cat_groups (
  id serial,
  name varchar(100) NOT NULL default '',
  app varchar(50) NOT NULL default '',
  weight int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_story_cat_groups_id_seq RESTART WITH 7;




CREATE TABLE IF NOT EXISTS jcow_story_photos (
  id serial,
  sid int NOT NULL default '0',
  uid int NOT NULL default '0',
  uri varchar(100) NOT NULL default '',
  des varchar(255) NOT NULL default '',
  thumb varchar(100) NOT NULL default '',
  size int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_story_photos_id_seq RESTART WITH 48;

CREATE INDEX ON jcow_story_photos (sid);
CREATE INDEX ON jcow_story_photos (uid);




CREATE TABLE IF NOT EXISTS jcow_streams (
  id serial,
  message text,
  wall_id int NOT NULL default '0',
  uid int NOT NULL default '0',
  comments int NOT NULL default '0',
  attachment text,
  like_types text,
  created int NOT NULL default '0',
  updated int NOT NULL default '0',
  type smallint NOT NULL default '0',
  app varchar(20) NOT NULL default '',
  fb_post_id varchar(50) NOT NULL default '',
  aid int NOT NULL default '0',
  hide smallint NOT NULL default '0',
  likes int NOT NULL default '0',
  dislikes int NOT NULL default '0',
  stuff_id int NOT NULL default '0',
   audio_uri varchar(255) NOT NULL default '',
  pid int NOT NULL default '0',
  data text,
  PRIMARY KEY  (id)
)  ;

ALTER SEQUENCE jcow_streams_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_streams (app);
CREATE INDEX ON jcow_streams (aid);
CREATE INDEX ON jcow_streams (wall_id);
CREATE INDEX ON jcow_streams (stuff_id);



CREATE TABLE IF NOT EXISTS jcow_disliked (
  id serial,
  uid int NOT NULL default '0',
  stream_id int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_disliked_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_disliked (uid,stream_id);





CREATE TABLE IF NOT EXISTS jcow_tags (
  id serial,
  name varchar(50) NOT NULL default '',
  app varchar(25) NOT NULL default '',
  lowercase varchar(100) NOT NULL default '',
  num int NOT NULL default '0',
  updated int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_tags_id_seq RESTART WITH 17;

CREATE INDEX ON jcow_tags (name);
CREATE INDEX ON jcow_tags (lowercase);




CREATE TABLE IF NOT EXISTS jcow_tag_ids (
  tid int NOT NULL default '0',
  sid int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_tag_ids (tid,sid);





CREATE TABLE IF NOT EXISTS jcow_texts (
  tkey varchar(50) NOT NULL default '',
  tvalue text
) ;

CREATE INDEX ON jcow_texts (tkey);




INSERT INTO jcow_texts (tkey, tvalue) VALUES
('welcome_pm', 'Hello %username%!rnThank you for your registeration!rnPlease invite your friends to join our community.'),
('welcome_email', 'Dear %username%,rnWelcome to %sitelink%!rnYour login email is: %email%rnOur URL is:rn%sitelink%'),
('welcome_msg', 'Welcome to our Community!'),
('rules_conditions', 'none'),
('footermsg', 'Your footer here..'),
('locations', 'Afghanistan  rnAlbania  rnAlgeria  rnAmerican Samoa  rnAndorra  rnAngola  rnAnguilla  rnAntarctica  rnAntigua and Barbuda  rnArgentina  rnArmenia  rnAruba  rnAustralia  rnAustria  rnAzerbaidjan  rnBahamas  rnBahrain  rnBangladesh  rnBarbados  rnBelarus  rnBelgium  rnBelize  rnBenin  rnBermuda  rnBhutan  rnBolivia  rnBosnia-Herzegovina  rnBotswana  rnBouvet Island  rnBrazil  rnBrunei Darussalam  rnBulgaria  rnBurkina Faso  rnBurundi  rnCambodia  rnCameroon  rnCanada  rnCape Verde  rnCayman Islands  rnCentral African Republic  rnChad  rnChile  rnChina  rnChristmas Island  rnCocos Islands  rnColombia  rnComoros  rnCongo  rnCook Islands  rnCosta Rica  rnCroatia  rnCuba  rnCyprus  rnCzech Republic  rnDenmark  rnDjibouti  rnDominica  rnDominican Republic  rnEast Timor  rnEcuador  rnEgypt  rnEl Salvador  rnEquatorial Guinea  rnEstonia  rnEthiopia  rnFalkland Islands  rnFaroe Islands  rnFiji  rnFinland  rnFormer Czechoslovakia  rnFrance  rnFrench Guyana  rnGabon  rnGambia  rnGeorgia  rnGermany  rnGhana  rnGibraltar  rnGreat Britain  rnGreece  rnGreenland  rnGrenada  rnGuadeloupe  rnGuam  rnGuatemala  rnGuinea  rnGuinea Bissau  rnGuyana  rnHaiti  rnHonduras  rnHong Kong  rnHungary  rnIceland  rnIndia  rnIndonesia  rnIran  rnIraq  rnIreland  rnIsrael  rnItaly  rnIvory Coast  rnJamaica  rnJapan  rnJordan  rnKazakhstan  rnKenya  rnKiribati  rnKuwait  rnKyrgyzstan  rnLaos  rnLatvia  rnLebanon  rnLesotho  rnLiberia  rnLibya  rnLiechtenstein  rnLithuania  rnLuxembourg  rnMacau  rnMacedonia  rnMadagascar  rnMalawi  rnMalaysia  rnMaldives  rnMali  rnMalta  rnMarshall Islands  rnMartinique  rnMauritania  rnMauritius  rnMayotte  rnMexico  rnMicronesia  rnMoldavia  rnMonaco  rnMongolia  rnMontserrat  rnMorocco  rnMozambique  rnMyanmar  rnNamibia  rnNauru  rnNepal  rnNetherlands  rnNetherlands Antilles  rnNeutral Zone  rnNew Caledonia  rnNew Zealand  rnNicaragua  rnNiger  rnNigeria  rnNiue  rnNorfolk Island  rnNorth Korea  rnNorway  rnOman  rnPakistan  rnPalau  rnPanama  rnPapua New Guinea  rnParaguay  rnPeru  rnPhilippines  rnPitcairn Island  rnPoland  rnPolynesia  rnPortugal  rnPuerto Rico  rnQatar  rnReunion  rnRomania  rnRussian Federation  rnRwanda  rnSaint Helena  rnSaint Lucia  rnSaint Vincent and Grenadines  rnSamoa  rnSan Marino  rnSaudi Arabia  rnSenegal  rnSeychelles  rnSierra Leone  rnSingapore  rnSlovak Republic  rnSlovenia  rnSolomon Islands  rnSomalia  rnSouth Africa  rnSouth Korea  rnSpain  rnSri Lanka  rnSudan  rnSuriname  rnSwaziland  rnSweden  rnSwitzerland  rnSyria  rnTadjikistan  rnTaiwan  rnTanzania  rnThailand  rnTogo  rnTokelau  rnTonga  rnTrinidad and Tobago  rnTunisia  rnTurkey  rnTurkmenistan  rnTuvalu  rnUganda  rnUkraine  rnUnited Arab Emirates  rnUnited Kingdom  rnUnited States  rnUruguay  rnUzbekistan  rnVanuatu  rnVatican City State  rnVenezuela  rnVietnam  rnVirgin Islands (British)  rnVirgin Islands (USA)  rnWallis and Futuna Islands  rnWestern Sahara  rnYemen  rnYugoslavia  rnZaire  rnZambia  rnZimbabwe');



CREATE TABLE IF NOT EXISTS jcow_tmp (
  tkey varchar(70) NOT NULL default '',
  tcontent text
) ;

CREATE INDEX ON jcow_tmp (tkey);




CREATE TABLE IF NOT EXISTS jcow_var_cache (
  name varchar(60) NOT NULL default '',
  content varchar(255) NOT NULL default '',
  created int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_var_cache (name,created);




CREATE TABLE IF NOT EXISTS jcow_votes (
  sid int NOT NULL default '0',
  created int NOT NULL default '0',
  rate int NOT NULL default '0',
  uid int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_votes (sid,uid);
CREATE INDEX ON jcow_votes (created);
CREATE INDEX ON jcow_votes (uid);




CREATE TABLE IF NOT EXISTS jcow_forum_subscribes (
  uid int NOT NULL default '0',
  tid int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_forum_subscribes (uid,tid);


CREATE TABLE IF NOT EXISTS jcow_chatrooms (
  id serial,
  uid int NOT NULL default '0',
  fid int NOT NULL default '0',
  content text,
  updated int NOT NULL default '0',
  created int NOT NULL default '0',
  request_id int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_chatrooms_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_chatrooms (uid,fid);



CREATE TABLE IF NOT EXISTS jcow_reports (
  id serial,
  uid int NOT NULL default '0',
  url varchar(255) NOT NULL default '',
  message text,
  hasread smallint NOT NULL default '0',
  created int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_reports_id_seq RESTART WITH 1;




CREATE TABLE IF NOT EXISTS jcow_reports (
  id serial,
  uid int NOT NULL default '0',
  url varchar(255) NOT NULL default '',
  message text,
  hasread smallint NOT NULL default '0',
  created int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_reports_id_seq RESTART WITH 1;


CREATE TABLE IF NOT EXISTS jcow_messages_sent (
  id serial,
  subject varchar(100) NOT NULL default '',
  message text,
  from_id int NOT NULL default '0',
  to_id int NOT NULL default '0',
  created int NOT NULL default '0',
  hasread smallint NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_messages_sent_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_messages_sent (from_id,to_id);


CREATE TABLE IF NOT EXISTS jcow_liked (
  id serial,
  uid int NOT NULL default '0',
  stream_id int NOT NULL default '0',
  type varchar(20) NOT NULL default '',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_liked_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_liked (uid);
CREATE INDEX ON jcow_liked (stream_id);


CREATE TABLE IF NOT EXISTS jcow_awards(
	id serial,
  name varchar(100) NOT NULL default '',
  cost int NOT NULL default 0,
  profit int NOT NULL default 0,
  image varchar(100) NOT NULL default '',
  image_id int NOT NULL default 0,
  PRIMARY KEY  (id)
)  ;


INSERT INTO jcow_awards VALUES (6,'You Have The Key',150,75,'static/awards/you_have_the_key.png',0),(7,'Love Song',150,75,'static/awards/love_song.png',0),(8,'Coffee Cup',150,75,'static/awards/coffee_cup.png',0),(9,'Chocolate Box',150,75,'static/awards/chocolate_box.png',0),(10,'Cookies',150,75,'static/awards/cookies.png',0),(11,'Love Letter',150,75,'static/awards/love_letter.png',0),(12,'Be Mine',150,75,'static/awards/be_mine.png',0),(13,'Love Message',150,75,'static/awards/love_message.png',0),(14,'Bee',150,75,'static/awards/bee.png',0),(15,'Got You',150,75,'static/awards/got_you.png',0),(16,'Love You',150,75,'static/awards/love_you.png',0),(17,'Valentines Day',150,75,'static/awards/valentines_day.png',0),(18,'I Love You',150,75,'static/awards/i_love_you.png',0),(19,'Cupid',150,75,'static/awards/cupid.png',0),(20,'Love Birds',150,75,'static/awards/love_birds.png',0),(21,'Flower',150,75,'static/awards/flower.png',0),(22,'Cassette Tape',150,75,'static/awards/cassette_tape.png',0),(23,'Love',150,75,'static/awards/love.png',0);


CREATE TABLE IF NOT EXISTS jcow_awards_histories(
	id serial,
  award_id int NOT NULL default 0,
  uid int NOT NULL default 0,
  created int NOT NULL default 0,
  stream_id int NOT NULL default 0,
  author_id int NOT NULL default 0,
  cost int NOT NULL default 0,
  profit int NOT NULL default 0,
  PRIMARY KEY  (id)
)  ;
 
 CREATE INDEX ON jcow_awards_histories (stream_id);



CREATE TABLE IF NOT EXISTS jcow_subscr (
  id varchar(32) NOT NULL default '',
  item_number varchar(32) NOT NULL default '',
  status varchar(25) NOT NULL default '',
  uid int NOT NULL default '0',
  timeline int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_subscr (id);
CREATE INDEX ON jcow_subscr (uid);




CREATE TABLE IF NOT EXISTS jcow_menu (
  id serial,
  name varchar(50) NOT NULL default '',
  tab_name varchar(50) NOT NULL default '',
  weight int NOT NULL default '0',
  path varchar(255) NOT NULL default '',
  app varchar(50) NOT NULL default '',
  actived smallint NOT NULL default '0',
  type varchar(25) NOT NULL default '',
  protected smallint NOT NULL default '0',
  allowed_roles text,
  icon varchar(255) NOT NULL default '',
  parent varchar(255) NOT NULL default '',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_menu_id_seq RESTART WITH 200;









CREATE TABLE IF NOT EXISTS jcow_modules (
  name varchar(50) NOT NULL default '',
  actived smallint NOT NULL default '0',
  hooking smallint NOT NULL default '0'
) ;

CREATE INDEX ON jcow_modules (name);




INSERT INTO jcow_modules VALUES ('browse',1,0),('feed',1,0),('dashboard',1,1),('account',1,0),('admin',1,1),('u',1,0),('member',1,0),('follow',1,0),('friends',1,0),('jquery',1,0),('language',1,0),('message',1,0),('notifications',1,0),('preference',1,0),('report',1,0),('rss',1,0),('search',1,0),('invite',1,0),('apps',1,0),('blacklist',1,0),('update',1,0),('images',1,1),('forums',0,1),('forumadmin',0,0),('ads',0,1),('music',0,1),('blogs',0,1),('page',0,0),('group',0,0),('groups',0,1),('videos',0,1),('events',0,1),('pages',0,1),('questions',0,1),('chatbar',0,1),('cache',0,1),('fblogin',0,0),('mobile',0,1);





CREATE TABLE IF NOT EXISTS jcow_banned (
  id serial,
  username varchar(100) NOT NULL default '',
  ip1 varchar(3) NOT NULL default '',
  ip2 varchar(3) NOT NULL default '',
  ip3 varchar(3) NOT NULL default '',
  ip4 varchar(3) NOT NULL default '',
  created int NOT NULL default '0',
  expired int NOT NULL default '0',
  operator varchar(100) NOT NULL default '',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_banned_id_seq RESTART WITH 15;




CREATE TABLE IF NOT EXISTS jcow_pages (
  id serial,
  uri varchar(30) NOT NULL default '',
  uid int NOT NULL default '0',
  views int NOT NULL default '0',
  logo varchar(200) NOT NULL default '',
  name varchar(100) NOT NULL default '',
  style_ids text,
  custom_css text,
  background varchar(200) NOT NULL default '',
  type varchar(25) NOT NULL default '',
  description text,
  users int NOT NULL default '0',
  updated int NOT NULL default '0',
  var1 varchar(255) NOT NULL default '',
  var2 varchar(255) NOT NULL default '',
  var3 varchar(255) NOT NULL default '',
  text1 text,
  text2 text,
  PRIMARY KEY  (id)
)  ;
 
 CREATE INDEX ON jcow_pages (uid);
 CREATE INDEX ON jcow_pages (uri);




CREATE TABLE IF NOT EXISTS jcow_page_users (
  id serial,
  pid int NOT NULL default '0',
  uid int NOT NULL default '0',
  PRIMARY KEY  (id)
) ;

CREATE INDEX ON jcow_page_users (pid,uid);
CREATE INDEX ON jcow_page_users (uid);




CREATE TABLE IF NOT EXISTS jcow_user_crafts (
  uid int NOT NULL default '0',
  hash varchar(5) NOT NULL default '',
  created int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_user_crafts (uid,created);




CREATE TABLE IF NOT EXISTS jcow_disliked (
  id serial,
  uid int NOT NULL default '0',
  stream_id int NOT NULL default '0',
  PRIMARY KEY  (id)
)  ;
 
 CREATE INDEX ON jcow_disliked (uid,stream_id);



CREATE TABLE IF NOT EXISTS jcow_footer_pages (
  id serial,
  name varchar(255) NOT NULL default '',
  link_name varchar(255) NOT NULL default '',
  content text,
  weight int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_footer_pages_id_seq RESTART WITH 1;



INSERT INTO jcow_footer_pages (id, name, link_name, content, weight) VALUES
(1, 'About Us', 'About Us', 'You(admin) can edit this page from "Admin CP"-"Footer Pages".', 1),
(2, 'Contact Us', 'Contact Us', 'You(admin) can edit this page from "Admin CP"-"Footer Pages".', 2);



CREATE TABLE IF NOT EXISTS jcow_pending_review (
  id serial,
  uid int NOT NULL default '0',
  content text,
  uri varchar(255) NOT NULL default '',
  post_id varchar(50) NOT NULL default '',
  created int NOT NULL default '0',
  ignored smallint NOT NULL default '0',
  stream_id int NOT NULL default '0',
  PRIMARY KEY  (id)
)   ;
 
ALTER SEQUENCE jcow_pending_review_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_pending_review (uid);
CREATE INDEX ON jcow_pending_review (post_id);
CREATE INDEX ON jcow_pending_review (stream_id);



CREATE TABLE IF NOT EXISTS jcow_limit_posting (
  uid int NOT NULL default '0',
  created int NOT NULL default '0',
  act varchar(50) NOT NULL default ''
) ;

CREATE INDEX ON jcow_limit_posting (uid,created);


CREATE TABLE IF NOT EXISTS jcow_mentions (
  id serial,
  uid int NOT NULL default '0',
  stream_id int NOT NULL default '0',
  wall_id int NOT NULL default '0',
  PRIMARY KEY  (id)
) ;

CREATE INDEX ON jcow_mentions (uid);




CREATE TABLE IF NOT EXISTS jcow_topics (
  id serial,
  name varchar(50) NOT NULL default '',
  stories int NOT NULL default '0',
  followers int NOT NULL default '0',
  updated int NOT NULL default '0',
  featured smallint NOT NULL default '0',
  description text,
  PRIMARY KEY  (id)
)  ;

ALTER SEQUENCE jcow_topics_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_topics (name);
CREATE INDEX ON jcow_topics (stories);
CREATE INDEX ON jcow_topics (featured);




CREATE TABLE IF NOT EXISTS jcow_topics_followed (
  uid int NOT NULL default '0',
  tid int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_topics_followed (uid);




CREATE TABLE IF NOT EXISTS jcow_topic_ids (
  tid int NOT NULL default '0',
  sid int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_topic_ids (tid,sid);



CREATE TABLE IF NOT EXISTS jcow_page_visitors (
  pid int NOT NULL default '0',
  uid int NOT NULL default '0',
  updated int NOT NULL default '0'
) ;

CREATE INDEX ON jcow_page_visitors (pid,uid);
CREATE INDEX ON jcow_page_visitors (pid,updated);


CREATE TABLE IF NOT EXISTS jcow_status_photos (
  id serial,
  sid int NOT NULL default '0',
  pid int NOT NULL default '0',
  uri varchar(100) NOT NULL default '',
  des varchar(255) NOT NULL default '',
  thumb varchar(100) NOT NULL default '',
  size int NOT NULL default '0',
  PRIMARY KEY (id)
)  ;

ALTER SEQUENCE jcow_status_photos_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_status_photos (sid);
CREATE INDEX ON jcow_status_photos (pid);


CREATE TABLE IF NOT EXISTS jcow_spammers (
  id serial,
  userkey varchar(255) NOT NULL default '',
  type varchar(50) NOT NULL default '',
  created int NOT NULL default '0',
  status varchar(50) NOT NULL default '',
  PRIMARY KEY (id),
  UNIQUE (userkey)
)   ;
 
ALTER SEQUENCE jcow_spammers_id_seq RESTART WITH 1;


CREATE TABLE IF NOT EXISTS jcow_spammers_cloud (
  id serial,
  userkey varchar(255) NOT NULL default '',
  type varchar(50) NOT NULL default '',
  created int NOT NULL default '0',
  status varchar(50) NOT NULL default '',
  PRIMARY KEY (id),
  UNIQUE (userkey)
)   ;
 
ALTER SEQUENCE jcow_spammers_cloud_id_seq RESTART WITH 1;


CREATE TABLE IF NOT EXISTS jcow_requests (
  id serial,
  uid int NOT NULL default '0',
  question text,
  answer text,
  created int NOT NULL default '0',
  PRIMARY KEY (id)
)   ;
 
ALTER SEQUENCE jcow_requests_id_seq RESTART WITH 1;

CREATE INDEX ON jcow_requests (uid);


CREATE TABLE IF NOT EXISTS jcow_im (
id serial primary key,
  from_id int NOT NULL default '0',
  to_id int NOT NULL default '0',
  pid int NOT NULL default '0',
  message text,
  created int NOT NULL default '0',
  hasread smallint NOT NULL
)   ;
 CREATE INDEX ON jcow_im(from_id,to_id);

CREATE TABLE IF NOT EXISTS jcow_notes (
id serial primary key,
  uid int NOT NULL default '0',
  created int NOT NULL default '0',
  uri varchar(200) NOT NULL default '',
  message text,
  from_uid int NOT NULL default '0',
  hasread smallint NOT NULL
)   ;
 
CREATE INDEX ON jcow_notes(uid);



CREATE TABLE IF NOT EXISTS jcow_shortcuts (
  uid int NOT NULL,
  page_id int NOT NULL,
  weight int NOT NULL
) ;

CREATE INDEX ON jcow_shortcuts (uid);


CREATE TABLE IF NOT EXISTS jcow_points (
  uid int NOT NULL,
  type text NOT NULL,
  points int NOT NULL
) ;

CREATE INDEX ON jcow_points (uid);


CREATE TABLE IF NOT EXISTS jcow_wiki_versions (
  id serial,
  uid int NOT NULL,
  sid int NOT NULL,
  created int NOT NULL,
  title text NOT NULL,
  content text NOT NULL,
  tags text NOT NULL ,
  note text NOT NULL ,
  type text NOT NULL,
  status text NOT NULL,
  PRIMARY KEY  (id)
) ;

CREATE INDEX ON jcow_wiki_versions (sid);
CREATE INDEX ON jcow_wiki_versions (uid);