###
# Novetats o noticies a la web
###

CREATE TABLE novetats (
  nid int UNSIGNED NOT NULL auto_increment,
  titol varchar(80) NOT NULL default '',
  date timestamp NOT NULL,
  bodytext text NOT NULL default '',
  PRIMARY KEY (nid)
) TYPE=MyISAM;

CREATE TABLE novetats_es (
  nid int UNSIGNED NOT NULL auto_increment,
  titol varchar(80) NOT NULL default '',
  date timestamp NOT NULL,
  bodytext text NOT NULL default '',
  PRIMARY KEY (nid)
) TYPE=MyISAM;

CREATE TABLE novetats_en (
  nid int UNSIGNED NOT NULL auto_increment,
  titol varchar(80) NOT NULL default '',
  date timestamp NOT NULL,
  bodytext text NOT NULL default '',
  PRIMARY KEY (nid)
) TYPE=MyISAM;


###
# Personal del departament
###

CREATE TABLE personal (
  id int UNSIGNED NOT NULL auto_increment UNIQUE,
  nom varchar(50) NOT NULL,
  despatx varchar(15),
  telf int,
  email varchar(30),
  web varchar(50),
  area int UNSIGNED NOT NULL default 1,
  consultes varchar(100),
  PRIMARY KEY (nom)
) TYPE=MyISAM;

###
# Arees
###

CREATE TABLE arees (
  aid int UNSIGNED NOT NULL auto_increment,
  area varchar(100) NOT NULL,
  PRIMARY KEY (aid)
) TYPE=MyISAM;

INSERT INTO arees (area) VALUES ('No determinada');
INSERT INTO arees (area) VALUES ('ATC - Arquitectura i Tecnologia de Computadors');
INSERT INTO arees (area) VALUES ('CCIA - Cičncies de la Computaciķ i Intelˇligčncia Artificial');
INSERT INTO arees (area) VALUES ('DM - Didāctica Matemātica');
INSERT INTO arees (area) VALUES ('LSI - Llenguatges i Sistemes Informātics');
INSERT INTO arees (area) VALUES ('MAT - Matemātica Aplicada');
INSERT INTO arees (area) VALUES ('PAS - Personal d\'Administraciķ i Serveis');



###
# Professors associats al departament
# id es correspondra amb un registre de personal
###

CREATE TABLE profes_associats (
 id int UNSIGNED NOT NULL,
 PRIMARY KEY (id)
) TYPE=MyISAM;

###
# Becaris del departament
# id es correspondra amb un registre de personal
###

CREATE TABLE becaris (
 id int UNSIGNED NOT NULL,
 PRIMARY KEY (id)
) TYPE=MyISAM;

###
# Propostes de Tesi
###

CREATE TABLE tesis (
 tid int UNSIGNED NOT NULL auto_increment,
 titol varchar(100) NOT NULL,
 keywords varchar(100) NOT NULL default '',
 resum text NOT NULL default '',
 categoria int UNSIGNED NOT NULL default 0,
 assignatures_rel varchar(100),
 data timestamp NOT NULL,
 id1 int UNSIGNED NOT NULL,
 id2 int UNSIGNED,
 id3 int UNSIGNED,
 PRIMARY KEY (tid)
) TYPE=MyISAM;

CREATE TABLE tesis_en (
 tid int UNSIGNED NOT NULL auto_increment,
 titol varchar(100) NOT NULL,
 keywords varchar(100) NOT NULL default '',
 resum text NOT NULL default '',
 categoria int UNSIGNED NOT NULL default 0,
 assignatures_rel varchar(100),
 data timestamp NOT NULL,
 id1 int UNSIGNED NOT NULL,
 id2 int UNSIGNED,
 id3 int UNSIGNED,
 PRIMARY KEY (tid)
) TYPE=MyISAM;

CREATE TABLE tesis_es (
 tid int UNSIGNED NOT NULL auto_increment,
 titol varchar(100) NOT NULL,
 keywords varchar(100) NOT NULL default '',
 resum text NOT NULL default '',
 categoria int UNSIGNED NOT NULL default 0,
 assignatures_rel varchar(100),
 data timestamp NOT NULL,
 id1 int UNSIGNED NOT NULL,
 id2 int UNSIGNED,
 id3 int UNSIGNED,
 PRIMARY KEY (tid)
) TYPE=MyISAM;


###
# Categories de les tesis
###

CREATE TABLE categories (
 cid int UNSIGNED NOT NULL auto_increment,
 titol varchar(100) NOT NULL,
 PRIMARY KEY (cid)
) TYPE=MyISAM;

INSERT INTO categories (titol) VALUES ('Sense catalogar');
INSERT INTO categories (titol) VALUES ('Intelˇligencia Artificial');
INSERT INTO categories (titol) VALUES ('Internet');
INSERT INTO categories (titol) VALUES ('Cālcul Numčric');
INSERT INTO categories (titol) VALUES ('Sistemes Operatius');

###
# Deiminaris
###

CREATE TABLE deiminaris (
  did int UNSIGNED NOT NULL auto_increment,
  titol varchar(100) NOT NULL default '',
  encarregat varchar(100) NOT NULL,
  institucio varchar(100),
  departament varchar(100),
  resum text NOT NULL default '',
  data date NOT NULL,
  hora time NOT NULL,
  lloc varchar(100) NOT NULL,
  obert_a varchar(100) NOT NULL,
  idioma varchar(20) NOT NULL,
  cicle INTEGER NOT NULL,
  PRIMARY KEY (did)
) TYPE=MyISAM;

CREATE TABLE deiminaris_mail (
  email varchar(50) NOT NULL,
  PRIMARY KEY (email)
) TYPE=MyISAM;

###
# Links de la plana principal
###
CREATE TABLE links (
 info varchar(20) NOT NULL,
 link varchar(200) NOT NULL,
 pos integer NOT NULL DEFAULT '0',
 PRIMARY KEY (pos)
) TYPE=MyISAM;

###
# Informacio dels usuaris
###

CREATE TABLE usuaris (
 login char(16) binary NOT NULL,
 password char(16) binary NOT NULL,
 sessio char(32) binary default '',
 novetats ENUM('false','true') NOT NULL default 'false',
 personal ENUM('false','true') NOT NULL default 'false',
 personal_propi ENUM('false','true') NOT NULL default 'false',
 tesis_total ENUM('false', 'true') NOT NULL default 'false',
 tesis_propies ENUM('false', 'true') NOT NULL default 'false',
 deiminaris ENUM('false', 'true') NOT NULL default 'false',
 usuaris ENUM('false', 'true') NOT NULL default 'false',
 cercador ENUM('false','true') NOT NULL default 'false',
 id int unsigned NOT NULL,
 PRIMARY KEY (login)
) TYPE=MyISAM;

INSERT INTO usuaris
(login,password,novetats,personal,personal_propi,tesis_total,tesis_propies,deiminaris,usuaris,
cercador,id) VALUES ('admin',PASSWORD('admin'),'true','true','true','true','true','true','true'
,'true','0');

###
# Log del les autentificacions
###

CREATE TABLE log (
  login char(16) binary NOT NULL,
  ip varchar(15) NOT NULL,
  data date NOT NULL,
  hora varchar(8) NOT NULL,
  login_correcte ENUM('false','true') NOT NULL default 'false'
) TYPE=MyISAM;

############### Inici taules del cercador ###############
# --------------------------------------------------------
#
# Structure de la table 'engine'
#

CREATE TABLE engine (
   spider_id mediumint(9) DEFAULT '0' NOT NULL,
   key_id mediumint(9) DEFAULT '0' NOT NULL,
   weight smallint(4) DEFAULT '0' NOT NULL,
   KEY spider_id (spider_id),
   KEY key_id (key_id)
);


# --------------------------------------------------------
#
# Structure de la table 'keywords'
#

CREATE TABLE keywords (
   key_id mediumint(9) NOT NULL auto_increment,
   twoletters char(2) NOT NULL,
   keyword varchar(64) NOT NULL,
   UNIQUE key_id_2 (key_id),
   UNIQUE keyword (keyword),
   KEY twoletters (twoletters)
);


# --------------------------------------------------------
#
# Structure de la table 'sites'
#

CREATE TABLE sites (
   site_id mediumint(9) NOT NULL auto_increment,
   site_url varchar(127) NOT NULL,
   upddate timestamp(14),
   username varchar(32),
   password varchar(32),
   port smallint(6),
   UNIQUE site_id (site_id)
);


# --------------------------------------------------------
#
# Structure de la table 'spider'
#

CREATE TABLE spider (
   spider_id mediumint(9) NOT NULL auto_increment,
   file varchar(127) NOT NULL,
   first_words text NOT NULL,
   upddate timestamp(14),
   md5 varchar(50),
   site_id mediumint(9) DEFAULT '0' NOT NULL,
   path varchar(127) NOT NULL,
   num_words int(11) DEFAULT '1' NOT NULL,
   last_modified timestamp(14),
   PRIMARY KEY (spider_id),
   KEY site_id (site_id)
);


# --------------------------------------------------------
#
# Structure de la table 'tempspider'
#

CREATE TABLE tempspider (
   file text NOT NULL,
   id mediumint(11) NOT NULL auto_increment,
   level tinyint(6) DEFAULT '0' NOT NULL,
   path text NOT NULL,
   site_id mediumint(9) DEFAULT '0' NOT NULL,
   indexed tinyint(1) DEFAULT '0' NOT NULL,
   upddate timestamp(14),
   error tinyint(4) DEFAULT '0' NOT NULL,
   UNIQUE id (id)
);
############### Final taules del cercador ###############


