Index: /trunk/workflow/setup/default_records.inc.php
===================================================================
--- /trunk/workflow/setup/default_records.inc.php	(revision 3167)
+++ /trunk/workflow/setup/default_records.inc.php	(revision 5726)
@@ -81,13 +81,13 @@
 
 	/* create the new workflow tables */
-	$workflowDB->query('CREATE TABLE organizacao (organizacao_id serial NOT NULL, nome character varying(20) NOT NULL, descricao character varying(100) NOT NULL, url_imagem character varying(200), ativa character varying(1) NOT NULL, sitio CHARACTER VARYING(100))');
+	$workflowDB->query('CREATE TABLE organizacao (organizacao_id serial NOT NULL, nome character varying(20) NOT NULL, descricao character varying(100) NOT NULL, url_imagem character varying(200), ativa character varying(1) NOT NULL, sitio CHARACTER VARYING(100), gidnumber_simplificado character varying(100))');
 	$workflowDB->query('CREATE TABLE area_status (area_status_id serial NOT NULL, organizacao_id integer NOT NULL, descricao character varying(50) NOT NULL, nivel integer NOT NULL)');
 	$workflowDB->query('CREATE TABLE centro_custo (organizacao_id integer NOT NULL, centro_custo_id serial NOT NULL, nm_centro_custo integer NOT NULL, grupo character varying(30), descricao character varying(100) NOT NULL)');
 	$workflowDB->query('CREATE TABLE localidade (organizacao_id integer NOT NULL, localidade_id serial NOT NULL, centro_custo_id integer, descricao character varying(50) NOT NULL, empresa CHARACTER VARYING(100), endereco CHARACTER VARYING(100), complemento CHARACTER VARYING(50), cep CHARACTER VARYING(9), bairro CHARACTER VARYING(30), cidade CHARACTER VARYING(50), uf CHARACTER(2))');
 	$workflowDB->query('CREATE TABLE funcionario (funcionario_id int4 NOT NULL, area_id integer NOT NULL, localidade_id integer NOT NULL, centro_custo_id integer, organizacao_id integer NOT NULL, funcionario_status_id integer NOT NULL, cargo_id int4, nivel int2, funcionario_categoria_id int4, titulo CHARACTER VARYING(30))');
-	$workflowDB->query('CREATE TABLE area (organizacao_id integer NOT NULL, area_id serial NOT NULL, area_status_id integer NOT NULL, areasup_organizacao_id integer, superior_area_id integer, centro_custo_id integer, titular_funcionario_id int4, sigla character varying(20) NOT NULL, descricao character varying(100) NOT NULL, ativa character varying(1) NOT NULL, auxiliar_funcionario_id int4)');
+	$workflowDB->query('CREATE TABLE area (organizacao_id integer NOT NULL, area_id serial NOT NULL, area_status_id integer NOT NULL, superior_area_id integer, centro_custo_id integer, titular_funcionario_id int4, sigla character varying(20) NOT NULL, descricao character varying(100) NOT NULL, ativa character varying(1) NOT NULL, auxiliar_funcionario_id int4)');
 	$workflowDB->query('CREATE TABLE funcionario_status (funcionario_status_id serial NOT NULL, descricao character varying(50) NOT NULL, exibir character varying(1) NOT NULL, organizacao_id integer NOT NULL)');
 	$workflowDB->query('CREATE TABLE cargo (cargo_id serial NOT NULL, descricao character varying(150), organizacao_id int4)');
-	$workflowDB->query('CREATE TABLE funcionario_categoria (funcionario_categoria_id serial NOT NULL, descricao character varying(150), organizacao_id int4)');
+	$workflowDB->query('CREATE TABLE funcionario_categoria (funcionario_categoria_id serial NOT NULL, descricao character varying(150), organizacao_id int4 NOT NULL)');
 	$workflowDB->query('CREATE TABLE telefone (telefone_id serial NOT NULL, descricao character varying(50) NOT NULL, numero character varying(50) NOT NULL, organizacao_id integer NOT NULL)');
 	$workflowDB->query('CREATE TABLE substituicao (substituicao_id serial NOT NULL, area_id integer NOT NULL, funcionario_id integer NOT NULL, data_inicio date NOT NULL, data_fim date NOT NULL)');
@@ -98,7 +98,7 @@
 	/* primary keys */
 	$workflowDB->query('ALTER TABLE ONLY organizacao ADD CONSTRAINT organizacao_pkey PRIMARY KEY (organizacao_id)');
-	$workflowDB->query('ALTER TABLE ONLY area_status ADD CONSTRAINT areastatus_pkey PRIMARY KEY (area_status_id, organizacao_id)');
-	$workflowDB->query('ALTER TABLE ONLY centro_custo ADD CONSTRAINT centrocusto_pkey PRIMARY KEY (organizacao_id, centro_custo_id)');
-	$workflowDB->query('ALTER TABLE ONLY localidade ADD CONSTRAINT localidade_pkey PRIMARY KEY (organizacao_id, localidade_id)');
+	$workflowDB->query('ALTER TABLE ONLY area_status ADD CONSTRAINT areastatus_pkey PRIMARY KEY (area_status_id)');
+	$workflowDB->query('ALTER TABLE ONLY centro_custo ADD CONSTRAINT centrocusto_pkey PRIMARY KEY (centro_custo_id)');
+	$workflowDB->query('ALTER TABLE ONLY localidade ADD CONSTRAINT localidade_pkey PRIMARY KEY (localidade_id)');
 	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT funcionario_pkey PRIMARY KEY (funcionario_id)');
 	$workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT area_pkey PRIMARY KEY (area_id)');
@@ -106,4 +106,6 @@
 	$workflowDB->query('ALTER TABLE ONLY telefone ADD CONSTRAINT telefone_pkey PRIMARY KEY (telefone_id)');
 	$workflowDB->query('ALTER TABLE ONLY substituicao ADD CONSTRAINT substituicao_pkey PRIMARY KEY (substituicao_id)');
+	$workflowDB->query('ALTER TABLE ONLY cargo ADD CONSTRAINT cargo_pkey PRIMARY KEY (cargo_id)');
+	$workflowDB->query('ALTER TABLE ONLY funcionario_categoria ADD CONSTRAINT funcionario_categoria_pkey PRIMARY KEY (funcionario_categoria_id)');
 
 
@@ -112,21 +114,23 @@
 	$workflowDB->query('ALTER TABLE ONLY area_status ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)');
 	$workflowDB->query('ALTER TABLE ONLY centro_custo ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)');
-	$workflowDB->query('ALTER TABLE ONLY localidade ADD CONSTRAINT "$1" FOREIGN KEY (centro_custo_id, organizacao_id) REFERENCES centro_custo(centro_custo_id, organizacao_id)');
+	$workflowDB->query('ALTER TABLE ONLY localidade ADD CONSTRAINT "$1" FOREIGN KEY (centro_custo_id) REFERENCES centro_custo(centro_custo_id)');
 	$workflowDB->query('ALTER TABLE ONLY localidade ADD CONSTRAINT "$2" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)');
-	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id, centro_custo_id) REFERENCES centro_custo(organizacao_id, centro_custo_id)');
-	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$2" FOREIGN KEY (organizacao_id, localidade_id) REFERENCES localidade(organizacao_id, localidade_id)');
-	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$3" FOREIGN KEY (organizacao_id, area_id) REFERENCES area(organizacao_id, area_id)');
+	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$1" FOREIGN KEY (centro_custo_id) REFERENCES centro_custo(centro_custo_id)');
+	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$2" FOREIGN KEY (localidade_id) REFERENCES localidade(localidade_id)');
+	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$3" FOREIGN KEY (area_id) REFERENCES area(area_id)');
 	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$4" FOREIGN KEY (funcionario_status_id) REFERENCES funcionario_status(funcionario_status_id)');
-	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$5" FOREIGN KEY (cargo_id) REFERENCES cargo (cargo_id)');
-	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$6" FOREIGN KEY (funcionario_categoria_id) REFERENCES funcionario_categoria (funcionario_categoria_id)');
-	$workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$1" FOREIGN KEY (superior_area_id, areasup_organizacao_id) REFERENCES area(area_id, organizacao_id)');
-	$workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$2" FOREIGN KEY (centro_custo_id, organizacao_id) REFERENCES centro_custo(centro_custo_id, organizacao_id)');
+	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$5" FOREIGN KEY (cargo_id) REFERENCES cargo(cargo_id)');
+	$workflowDB->query('ALTER TABLE ONLY funcionario ADD CONSTRAINT "$6" FOREIGN KEY (funcionario_categoria_id) REFERENCES funcionario_categoria(funcionario_categoria_id)');
+	$workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$1" FOREIGN KEY (superior_area_id) REFERENCES area(area_id)');
+	$workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$2" FOREIGN KEY (centro_custo_id) REFERENCES centro_custo(centro_custo_id)');
 	$workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$3" FOREIGN KEY (titular_funcionario_id) REFERENCES funcionario(funcionario_id)');
 	$workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$4" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)');
-	$workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$5" FOREIGN KEY (area_status_id, organizacao_id) REFERENCES area_status(area_status_id, organizacao_id)');
+	$workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$5" FOREIGN KEY (area_status_id) REFERENCES area_status(area_status_id)');
 	$workflowDB->query('ALTER TABLE ONLY area ADD CONSTRAINT "$6" FOREIGN KEY (auxiliar_funcionario_id) REFERENCES funcionario(funcionario_id)');
 	$workflowDB->query('ALTER TABLE ONLY telefone ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)');
 	$workflowDB->query('ALTER TABLE ONLY substituicao ADD CONSTRAINT "$1" FOREIGN KEY (area_id) REFERENCES area(area_id)');
 	$workflowDB->query('ALTER TABLE ONLY substituicao ADD CONSTRAINT "$2" FOREIGN KEY (funcionario_id) REFERENCES funcionario(funcionario_id)');
+	$workflowDB->query('ALTER TABLE ONLY cargo ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)');
+	$workflowDB->query('ALTER TABLE ONLY funcionario_categoria ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)');
 
 
Index: /trunk/workflow/setup/tables_update.inc.php
===================================================================
--- /trunk/workflow/setup/tables_update.inc.php	(revision 5311)
+++ /trunk/workflow/setup/tables_update.inc.php	(revision 5726)
@@ -40,69 +40,4 @@
 	}
 
-	// Since Expresso 1.2 using Workflow 1.8.04.000
-	$test[] = '1.8.04.000';
-	function workflow_upgrade1_8_04_000()
-	{
-		/* Create index for table egw_wf_workitems  */
-		if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly)
-		{
-			$GLOBALS['phpgw']->ADOdb->query('CREATE INDEX egw_wf_workitems_wf_instance_id_idx ON egw_wf_workitems(wf_instance_id)');
-		}
-
-		#updating the current version
-		$GLOBALS['setup_info']['workflow']['currentver'] = '1.8.05.000';
-		return $GLOBALS['setup_info']['workflow']['currentver'];
-	}
-
-	$test[] = '1.8.05.000';
-	function workflow_upgrade1_8_05_000()
-	{
-		/* Alter tables of orgchart */
-		if (!$GLOBALS['phpgw_setup']->oProc->m_bDeltaOnly)
-		{
-			$workflowHostInfo = extractDatabaseParameters();
-
-			/* connect to workflow database */
-			$workflowDB = $GLOBALS['phpgw']->ADOdb;
-			if ($workflowDB->connect($workflowHostInfo['host'].":".$workflowHostInfo['port'], $workflowHostInfo['user'], $workflowHostInfo['password'], 'workflow'))
-			{
-				/* add the new columns */
-				$workflowDB->query('ALTER TABLE public.funcionario ADD COLUMN titulo CHARACTER VARYING(30)');
-				$workflowDB->query('ALTER TABLE public.organizacao ADD COLUMN sitio CHARACTER VARYING(100)');
-				$workflowDB->query('ALTER TABLE public.localidade ADD COLUMN empresa CHARACTER VARYING(100)');
-				$workflowDB->query('ALTER TABLE public.localidade ADD COLUMN endereco CHARACTER VARYING(100)');
-				$workflowDB->query('ALTER TABLE public.localidade ADD COLUMN complemento CHARACTER VARYING(50)');
-				$workflowDB->query('ALTER TABLE public.localidade ADD COLUMN cep CHARACTER VARYING(9)');
-				$workflowDB->query('ALTER TABLE public.localidade ADD COLUMN bairro CHARACTER VARYING(30)');
-				$workflowDB->query('ALTER TABLE public.localidade ADD COLUMN cidade CHARACTER VARYING(50)');
-				$workflowDB->query('ALTER TABLE public.localidade ADD COLUMN uf CHARACTER(2)');
-
-				/* create table telefone */
-				$workflowDB->query('CREATE TABLE public.telefone (telefone_id serial NOT NULL, descricao character varying(50) NOT NULL, numero character varying(50) NOT NULL, organizacao_id integer NOT NULL)');
-				$workflowDB->query('ALTER TABLE ONLY public.telefone ADD CONSTRAINT telefone_pkey PRIMARY KEY (telefone_id)');
-				$workflowDB->query('ALTER TABLE ONLY public.telefone ADD CONSTRAINT "$1" FOREIGN KEY (organizacao_id) REFERENCES organizacao(organizacao_id)');
-				$workflowDB->query("GRANT ALL ON TABLE public.telefone TO admin_workflow");
-				$workflowDB->query("GRANT ALL ON TABLE public.telefone TO postgres");
-				$workflowDB->query("GRANT SELECT ON TABLE public.telefone TO public");
-				$workflowDB->query("GRANT ALL ON TABLE public.telefone_telefone_id_seq TO admin_workflow");
-				$workflowDB->query("GRANT ALL ON TABLE public.telefone_telefone_id_seq TO postgres");
-				$workflowDB->query("GRANT SELECT ON TABLE public.telefone_telefone_id_seq TO public");
-			}
-
-			/* reconnect to the previous database */
-			$GLOBALS['phpgw']->ADOdb->connect($workflowHostInfo['host'].":".$workflowHostInfo['port'], $workflowHostInfo['user'], $workflowHostInfo['password'], $workflowHostInfo['dbname']);
-		}
-		#updating the current version
-		$GLOBALS['setup_info']['workflow']['currentver'] = '1.8.06.000';
-		return $GLOBALS['setup_info']['workflow']['currentver'];
-	}
-
-	$test[] = '1.8.06.000';
-	function workflow_upgrade1_8_06_000()
-	{
-		#updating the current version
-		$GLOBALS['setup_info']['workflow']['currentver'] = '2.0.000';
-		return $GLOBALS['setup_info']['workflow']['currentver'];
-	}
 	$test[] = '2.0.000';
 	function workflow_upgrade2_0_000()
@@ -194,5 +129,5 @@
 			/* adding primary key without the column removed */
 			$GLOBALS['phpgw']->ADOdb->query('ALTER TABLE egw_wf_interinstance_relations ADD CONSTRAINT egw_wf_interinstance_relations_pkey PRIMARY KEY (wf_parent_instance_id, wf_child_instance_id)');
-			
+
 			/* Update the organogram level of administration off all users from 0 to 1. */
 			$GLOBALS['phpgw']->ADOdb->query('UPDATE egw_wf_admin_access set nivel = 1 WHERE tipo = \'ORG\' and nivel = 0');
@@ -228,9 +163,9 @@
 	{
 		#updating the current version
-		
+
 		$GLOBALS['phpgw']->ADOdb->query("INSERT into phpgw_lang values ('en','workflow','Reports','Reports') ");
-		
-		$GLOBALS['phpgw']->ADOdb->query("INSERT into phpgw_lang values ('pt-br','workflow','Reports','Relatórios') ");	
-		
+
+		$GLOBALS['phpgw']->ADOdb->query("INSERT into phpgw_lang values ('pt-br','workflow','Reports','Relatórios') ");
+
 		$workflowHostInfo = extractDatabaseParameters();
 
@@ -241,5 +176,5 @@
 				/* creating table substitution */
 				$workflowDB->query('CREATE SCHEMA listagem AUTHORIZATION postgres; GRANT ALL ON SCHEMA listagem TO postgres; GRANT ALL ON SCHEMA listagem TO admin_workflow;');
-		
+
 			$workflowDB->query("CREATE TABLE listagem.listagem
 							(
@@ -309,5 +244,5 @@
 							GRANT ALL ON TABLE listagem.listagem_coluna TO admin_workflow;");
 
-			
+
 			$workflowDB->query("CREATE TABLE listagem.listagem_indicador
 								(
@@ -330,5 +265,5 @@
 								GRANT ALL ON TABLE listagem.listagem_indicador TO admin_workflow;");
 
-			
+
 			$workflowDB->query("CREATE TABLE listagem.listagem_parametro
 								(
@@ -349,9 +284,9 @@
 								GRANT ALL ON TABLE listagem.listagem_parametro TO postgres;
 								GRANT ALL ON TABLE listagem.listagem_parametro TO admin_workflow;");
-								
-								
-								
-			
-				$workflowDB->query("CREATE SEQUENCE listagem.listagem_coluna_lslcoid_seq
+
+
+
+
+			$workflowDB->query("CREATE SEQUENCE listagem.listagem_coluna_lslcoid_seq
 				  INCREMENT 1
 				  MINVALUE 1
@@ -360,6 +295,6 @@
 				  CACHE 1;
 				ALTER TABLE listagem.listagem_coluna_lslcoid_seq OWNER TO postgres;
-				
-				
+
+
 				CREATE SEQUENCE listagem.listagem_indicador_lsioid_seq
 				  INCREMENT 1
@@ -369,6 +304,6 @@
 				  CACHE 1;
 				ALTER TABLE listagem.listagem_indicador_lsioid_seq OWNER TO postgres;
-				
-				
+
+
 				CREATE SEQUENCE listagem.listagem_lstoid_seq
 				  INCREMENT 1
@@ -378,6 +313,6 @@
 				  CACHE 1;
 				ALTER TABLE listagem.listagem_lstoid_seq OWNER TO postgres;
-				
-				
+
+
 				CREATE SEQUENCE listagem.listagem_parametro_lspoid_seq
 				  INCREMENT 1
@@ -390,5 +325,5 @@
 
 			}
-		
+
 
 		$GLOBALS['setup_info']['workflow']['currentver'] = '2.4.0';
