Index: sandbox/workflow/branches/993/lib/settings/Settings.php
===================================================================
--- sandbox/workflow/branches/993/lib/settings/Settings.php	(revision 2418)
+++ sandbox/workflow/branches/993/lib/settings/Settings.php	(revision 2418)
@@ -0,0 +1,180 @@
+<?php
+/**************************************************************************\
+* eGroupWare                                                               *
+* http://www.egroupware.org                                                *
+* --------------------------------------------                             *
+*  This program is free software; you can redistribute it and/or modify it *
+*  under the terms of the GNU General Public License as published by the   *
+*  Free Software Foundation; either version 2 of the License, or (at your  *
+*  option) any later version.                                              *
+\**************************************************************************/
+
+/**
+ * 
+ *
+ * @package Settings
+ * @license http://www.gnu.org/copyleft/gpl.html GPL
+ * @author Pedro EugÃªnio Rocha - pedro.eugenio.rocha@gmail.com
+ */
+
+class Settings {
+
+	/**
+	 * @var array $_configs Here we should define which settings we are able
+	 * 						to get. The settings not defined here will throw
+	 * 						an exception when someone asks for it.
+	 * @access private
+	 */
+	private static $_configs = array(
+		'workflow' => array(
+			'intranet_subnetworks' => '',
+			'db' => array(
+				'name' => '',
+				'host' => '',
+				'port' => '',
+				'admin_user' => '',
+				'admin_password' => '',
+				'type' => ''
+			),
+			'galaxia' => array(
+				'db' => array(
+					'name' => '',
+					'host' => '',
+					'port' => '',
+					'user' => '',
+					'password' => '',
+					'type' => ''
+				)
+			),
+			'ldap' => array(
+				'host' => '',
+				'user' => '',
+				'password' => '',
+				'follow_referrals' => ''
+			),
+		),
+		'expresso' => array(
+			'db' => array(
+				'name' => '',
+				'host' => '',
+				'port' => '',
+				'user' => '',
+				'password' => '',
+				'type' => ''
+			),
+			'ldap' => array(
+				'host' => ''
+			),
+		),
+		'process' => array(
+		)
+	);
+
+	private static $loaded_from_db = false;
+
+
+	/**
+	 * Constructor. Just disabling direct instantiation.
+	 *
+	 * @access public
+	 * @return void
+	 */
+	public function __construct() {
+		throw new Exception("Oops! Static only class.");
+	}
+
+
+	/**
+	 * Returns settings.
+	 *
+	 * @param string $args 	A variable number of parameters which specify the scope
+	 *						and the configuration to be retrieved.
+	 * @access public
+	 * @return string
+	 * @static
+	 */
+	public static function get() {
+
+		/* getting the variable number of parameters */
+		$args = func_get_args();
+
+		/**
+		 * Here we check if the configuration was defined into $_configs array.
+		 * If it does not, an exception will be thrown.
+		 * p.s. Do not try to understand this piece of code. Just fave faith! It works...
+		 */
+		for ($i=0, $sub_array=&self::$_configs; $i<count($args); $sub_array=&$sub_array[$args[$i++]]) {
+			if (!array_key_exists($args[$i], $sub_array))
+				throw new Exception("Sorry! Setting '".implode("->", $args)."' do not exists.");
+		}
+
+		/* check if the setting was loaded */
+		$methodName = "populate" . ucfirst(strtolower($args[0]));
+		self::$methodName();
+
+
+		/* retrieving the setting. More 'for' programming. */
+		for ($i=0, $value=&self::$_configs; $i<count($args); $value=&$value[$args[$i++]]);
+
+		return $value;
+	}
+
+
+	public static function load() {
+
+		self::$_configs['expresso']['db']['name'] = $GLOBALS['phpgw_info']['server']['db_name'];
+		self::$_configs['expresso']['db']['host'] = $GLOBALS['phpgw_info']['server']['db_host'];
+		self::$_configs['expresso']['db']['port'] = $GLOBALS['phpgw_info']['server']['db_port'];
+		self::$_configs['expresso']['db']['user'] = $GLOBALS['phpgw_info']['server']['db_user'];
+		self::$_configs['expresso']['db']['password'] = $GLOBALS['phpgw_info']['server']['db_pass'];
+		self::$_configs['expresso']['db']['type'] = $GLOBALS['phpgw_info']['server']['db_type'];
+
+		self::$_configs['expresso']['ldap']['host'] = $GLOBALS['phpgw_info']['server']['ldap_host'];
+	}
+
+	private static function populateWorkflow() {
+
+		$values = self::loadFromDb();
+
+		self::$_configs['workflow']['intranet_subnetworks'] = $values['intranet_subnetworks'];
+
+		self::$_configs['workflow']['db']['name'] = $values['database_name'];
+		self::$_configs['workflow']['db']['host'] = $values['database_host'];
+		self::$_configs['workflow']['db']['port'] = $values['database_port'];
+		self::$_configs['workflow']['db']['admin_user'] = $values['database_admin_user'];
+		self::$_configs['workflow']['db']['admin_password'] = $values['database_admin_password'];
+		self::$_configs['workflow']['db']['type'] = $values['database_type'];
+
+		self::$_configs['workflow']['galaxia']['db']['name'] = $values['workflow_database_name'];
+		self::$_configs['workflow']['galaxia']['db']['host'] = $values['workflow_database_host'];
+		self::$_configs['workflow']['galaxia']['db']['port'] = $values['workflow_database_port'];
+		self::$_configs['workflow']['galaxia']['db']['user'] = $values['workflow_database_user'];
+		self::$_configs['workflow']['galaxia']['db']['password'] = $values['workflow_database_password'];
+		self::$_configs['workflow']['galaxia']['db']['type'] = $values['workflow_database_type'];
+
+		self::$_configs['workflow']['ldap']['host'] = $values['ldap_host'];
+		self::$_configs['workflow']['ldap']['user'] = $values['ldap_user'];
+		self::$_configs['workflow']['ldap']['password'] = $values['ldap_password'];
+		self::$_configs['workflow']['ldap']['follow_referrals'] = $values['ldap_follow_referrals'];
+	}
+
+	private static function populateExpresso() {}
+
+
+	private static function loadFromDb() {
+
+		/* */
+		$config = &Factory::newInstance('config', 'workflow');
+		$values = $config->read_repository();
+
+		/*
+		foreach ($values as $key => $value) {
+			self::$_configs[$key] = $value;
+		}
+		self::$loaded_from_db = true;
+		*/
+		return $values;
+	}
+}
+
+?>
Index: sandbox/workflow/branches/993/inc/class.bo_utils.inc.php
===================================================================
--- sandbox/workflow/branches/993/inc/class.bo_utils.inc.php	(revision 2372)
+++ sandbox/workflow/branches/993/inc/class.bo_utils.inc.php	(revision 2418)
@@ -86,4 +86,9 @@
 			$ret_name = empty($params['name']) ? 'cn' : $params['name'];
 
+			/**
+			 * This is wrong. We should incorporate this settings into
+			 * workflow configuration table. Therefore, workflow should
+			 * not depend on other modules..
+			 */
 			$ajaxConfig = &Factory::newInstance('ajax_config', 'contactcenter');
 			$config = $ajaxConfig->read_repository();
Index: sandbox/workflow/branches/993/inc/class.WorkflowObjects.inc.php
===================================================================
--- sandbox/workflow/branches/993/inc/class.WorkflowObjects.inc.php	(revision 2372)
+++ sandbox/workflow/branches/993/inc/class.WorkflowObjects.inc.php	(revision 2418)
@@ -13,4 +13,5 @@
  * Provê objetos de multipropósito do Workflow
  * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com
+ * @author Pedro Eugenio Rocha - pedro.eugenio.rocha@gmail.com
  * @version 1.0
  * @package Workflow
@@ -23,17 +24,8 @@
 	 * @access private
 	 */
-	private $cache;
+	private $cache = array();
 
 	/**
-	 * Construtor da classe
-	 * @return object
-	 * @access public
-	 */
-	function WorkflowObjects()
-	{
-		$this->cache = array();
-	}
-
-	/**
+	 * TODO We should remove this method..
 	 * Monta o ambiente requerido pelos métodos (somente se for necessário)
 	 * @param bool $requireGalaxia Indica que os métodos da engine Galaxia são necessários
@@ -68,20 +60,16 @@
 			$this->assureEnvironment();
 
-			/* load the configuration required to establish a connection to the Galaxia database */
-			$dbConfigValues = galaxia_get_config_values(array(
-				'workflow_database_name' => '',
-				'workflow_database_host' => '',
-				'workflow_database_port' => '',
-				'workflow_database_user' => '',
-				'workflow_database_password' => '',
-				'workflow_database_type' => ''
-			));
-
 			/* check if all configuration is OK */
 			$dedicatedDB = true;
-			foreach ($dbConfigValues as $configName => $configValue)
-				if (empty($configValue) && ($configName != 'workflow_database_password'))
-					$dedicatedDB = false;
 
+			/* if any parameter is not set, then we will return expresso database */
+			if ((Settings::get('workflow', 'galaxia', 'db', 'name') == '') or
+				(Settings::get('workflow', 'galaxia', 'db', 'host') == '') or
+				(Settings::get('workflow', 'galaxia', 'db', 'port') == '') or
+				(Settings::get('workflow', 'galaxia', 'db', 'user') == '') or
+				(Settings::get('workflow', 'galaxia', 'db', 'type') == ''))
+				$dedicatedDB = false;
+
+			/* should we connect to a dedicated database? */
 			if ($dedicatedDB)
 			{
@@ -91,10 +79,10 @@
 				$this->cache['DBGalaxia']->Halt_On_Error = 'no';
 				$this->cache['DBGalaxia']->connect(
-					$dbConfigValues['workflow_database_name'],
-					$dbConfigValues['workflow_database_host'],
-					$dbConfigValues['workflow_database_port'],
-					$dbConfigValues['workflow_database_user'],
-					$dbConfigValues['workflow_database_password'],
-					$dbConfigValues['workflow_database_type']
+					Settings::get('workflow', 'galaxia', 'db', 'name'),
+					Settings::get('workflow', 'galaxia', 'db', 'host'),
+					Settings::get('workflow', 'galaxia', 'db', 'port'),
+					Settings::get('workflow', 'galaxia', 'db', 'user'),
+					Settings::get('workflow', 'galaxia', 'db', 'password'),
+					Settings::get('workflow', 'galaxia', 'db', 'type')
 				);
 				Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBGalaxia']);
@@ -120,19 +108,4 @@
 			$this->assureEnvironment(false);
 
-			/* check where the connection parameters are */
-			$connectionInfo = (isset($GLOBALS['phpgw_info']['server']['db_name'])) ?
-				$GLOBALS['phpgw_info']['server'] :
-				$_SESSION['phpgw_info']['workflow']['server'];
-
-			/* the information was not found. Try to load the environment */
-			if (!isset($connectionInfo['db_name']))
-			{
-				Factory::getInstance('WorkflowMacro')->prepareEnvironment();
-				if (isset($GLOBALS['phpgw_info']['server']))
-					$connectionInfo = $GLOBALS['phpgw_info']['server'];
-				else
-					return false;
-			}
-
 			/* connect to the database */
 			$this->cache['DBExpresso'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db'));
@@ -140,10 +113,10 @@
 			$this->cache['DBExpresso']->Halt_On_Error = 'no';
 			$this->cache['DBExpresso']->connect(
-				$connectionInfo['db_name'],
-				$connectionInfo['db_host'],
-				$connectionInfo['db_port'],
-				$connectionInfo['db_user'],
-				$connectionInfo['db_pass'],
-				$connectionInfo['db_type']
+				Settings::get('expresso', 'db', 'name'),
+				Settings::get('expresso', 'db', 'host'),
+				Settings::get('expresso', 'db', 'port'),
+				Settings::get('expresso', 'db', 'user'),
+				Settings::get('expresso', 'db', 'password'),
+				Settings::get('expresso', 'db', 'type')
 			);
 			Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBExpresso']);
@@ -166,14 +139,4 @@
 			$this->assureEnvironment();
 
-			/* load the configuration required to establish a connection to the Galaxia database */
-			$dbConfigValues = galaxia_get_config_values(array(
-				'database_name' => '',
-				'database_host' => '',
-				'database_port' => '',
-				'database_admin_user' => '',
-				'database_admin_password' => '',
-				'database_type' => ''
-			));
-
 			/* connect to the database */
 			$this->cache['DBWorkflow'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db'));
@@ -181,10 +144,10 @@
 			$this->cache['DBWorkflow']->Halt_On_Error = 'no';
 			$this->cache['DBWorkflow']->connect(
-				$dbConfigValues['database_name'],
-				$dbConfigValues['database_host'],
-				$dbConfigValues['database_port'],
-				$dbConfigValues['database_admin_user'],
-				$dbConfigValues['database_admin_password'],
-				$dbConfigValues['database_type']
+				Settings::get('workflow', 'db', 'name'),
+				Settings::get('workflow', 'db', 'host'),
+				Settings::get('workflow', 'db', 'port'),
+				Settings::get('workflow', 'db', 'admin_user'),
+				Settings::get('workflow', 'db', 'admin_password'),
+				Settings::get('workflow', 'db', 'type')
 			);
 			Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBWorkflow']);
@@ -207,24 +170,23 @@
 			$this->assureEnvironment();
 
-			/* check where the connection parameters are */
-			$connectionInfo = (isset($GLOBALS['phpgw_info']['server']['ldap_host'])) ?
-				$GLOBALS['phpgw_info']['server'] :
-				$_SESSION['phpgw_info']['workflow']['server'];
-
-			/* load required information */
-			$ldapConfigValues = galaxia_get_config_values(array('ldap_host' => '', 'ldap_user' => '', 'ldap_password'=> '', 'ldap_follow_referrals' => ''));
-			if (empty($ldapConfigValues['ldap_host']))
-				$ldapConfigValues['ldap_host'] = $connectionInfo['ldap_host'];
+			/* which ldap host to connect? */
+			$ldapHost = Settings::get('workflow', 'ldap', 'host');
+			if (empty($ldapHost))
+				$ldapHost = Settings::get('expresso', 'ldap', 'host');
 
 			/* connect to the LDAP server */
-			$this->cache['ldap'] = ldap_connect($ldapConfigValues['ldap_host']);
+			$this->cache['ldap'] = ldap_connect($ldapHost);
 
 			/* configure the connection */
 			ldap_set_option($this->cache['ldap'], LDAP_OPT_PROTOCOL_VERSION, 3);
-			ldap_set_option($this->cache['ldap'], LDAP_OPT_REFERRALS, ($ldapConfigValues['ldap_follow_referrals'] == 1) ? 1 : 0);
+			ldap_set_option($this->cache['ldap'], LDAP_OPT_REFERRALS, (Settings::get('workflow', 'ldap', 'follow_referrals') == 1) ? 1 : 0);
 
 			/* if  username and password are available, bind the connection */
-			if ((!empty($ldapConfigValues['ldap_user'])) && (!empty($ldapConfigValues['ldap_password'])))
-				ldap_bind($this->cache['ldap'], $ldapConfigValues['ldap_user'], $ldapConfigValues['ldap_password']);
+			if ((Settings::get('workflow', 'ldap', 'user') != '') and
+				(Settings::get('workflow', 'ldap', 'password') != ''))
+				ldap_bind(	$this->cache['ldap'],
+							Settings::get('workflow', 'ldap', 'user'),
+							Settings::get('workflow', 'ldap', 'password')
+							);
 		}
 
Index: sandbox/workflow/branches/993/inc/common.inc.php
===================================================================
--- sandbox/workflow/branches/993/inc/common.inc.php	(revision 2372)
+++ sandbox/workflow/branches/993/inc/common.inc.php	(revision 2418)
@@ -11,16 +11,31 @@
 
 /**
- * Server base path. This constant is somewhat simililar to
- * 'PHPGW_SERVER_ROOT'. Nevertheless, there are cases that we
- * access Workflow directly and it must be defined somewhere.
- * Recently discovered, when we are runnnig jobs HTTP_SERVER_VARS
- * exported by apache are not available.
- * Therefore, we are using this workaround here, setting
- * EGW_SERVER_ROOT based on the location of this file. This constant
- * should be updated properly every time we move this file.
+ * This is other big workaround. In ajax calls, we use controller.php
+ * directly, which do not includes header.inc for performance issues.
+ * However, for phpgwAPI to work properly we need to set several
+ * constants and objects, which are created in this file (header.inc).
+ * As much as this problem still unsolved (by phpAPI group), this potencially
+ * problematic and ugly code must still here.. =(
+ */
+$old = $GLOBALS['phpgw_info']['flags'];
+$GLOBALS['phpgw_info']['flags'] = array(
+        'noheader' => True,
+        'nonavbar' => True,
+        'currentapp' => 'workflow'
+);
+/* TODO TODO TODO TODO */
+$base = dirname(dirname(dirname(__FILE__)));
+require_once ($base . '/header.inc.php');
+$GLOBALS['phpgw_info']['flags'] = $old;
+
+
+/**
+ * Server base path. In this module, we should only use
+ * constants defined here. PHPGW_SERVER_ROOT is defined
+ * on 'header.inc.php' which is always included by this
+ * file.
  * @name EGW_SERVER_ROOT
  */
-define('EGW_SERVER_ROOT', dirname(dirname(dirname(__FILE__))));
-//define('EGW_SERVER_ROOT', $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT']);
+define('EGW_SERVER_ROOT', PHPGW_SERVER_ROOT);
 
 /**
@@ -51,8 +66,4 @@
 
 
-if (file_exists(EGW_SERVER_ROOT . '/header.session.inc.php')) {
-	require_once EGW_SERVER_ROOT . '/header.session.inc.php';
-}
-
 
 /* assure that the correct encondig will be used (e.g string functions) */
@@ -70,4 +81,7 @@
 require_once WF_LIB_ROOT . 'factory/WorkflowFactory.php';
 require_once WF_LIB_ROOT . 'factory/ProcessFactory.php';
+require_once WF_LIB_ROOT . 'settings/Settings.php';
+
+Settings::load();
 
 $GLOBALS['workflow']['workflowObjects'] = Factory::getInstance('WorkflowObjects');
Index: sandbox/workflow/branches/993/inc/class.so_userinterface.inc.php
===================================================================
--- sandbox/workflow/branches/993/inc/class.so_userinterface.inc.php	(revision 2372)
+++ sandbox/workflow/branches/993/inc/class.so_userinterface.inc.php	(revision 2418)
@@ -60,7 +60,5 @@
 		$oldDB = $GLOBALS['phpgw']->db;
 		$GLOBALS['phpgw']->db = $GLOBALS['ajax']->db;
-		$config = &Factory::getInstance('config', 'workflow');
-		$configValues = $config->read_repository();
-		$submasksString = $configValues['intranet_subnetworks'];
+		$submasksString = Settings::get('workflow', 'intranet_subnetworks');
 		$GLOBALS['phpgw']->db = $oldDB;
 
Index: sandbox/workflow/branches/993/inc/class.ui_orgchart.inc.php
===================================================================
--- sandbox/workflow/branches/993/inc/class.ui_orgchart.inc.php	(revision 2372)
+++ sandbox/workflow/branches/993/inc/class.ui_orgchart.inc.php	(revision 2418)
@@ -37,5 +37,5 @@
 	 * @access public
 	 */
-	function ui_orgchart()
+	public function ui_orgchart()
 	{
 	}
@@ -45,5 +45,5 @@
 	 * @access public
 	 */
-	function draw($tab_index = "")
+	public function draw($tab_index = "")
 	{
 		$this->workflow_acl = Factory::getInstance('workflow_acl');
@@ -92,7 +92,7 @@
 	 * Show the graph
 	 * @access public
-	 * @return void 
+	 * @return void
 	 */
-	function graph()
+	public function graph()
 	{
 		if (!isset($_GET['organizationID']))
@@ -104,17 +104,6 @@
 			die();
 
-		$config_values = Factory::getInstance('config', 'workflow');
-		$config_values->read_repository();
-		$conf_db = $config_values->config_data;
-		$db = Factory::getInstance('db');
-		$db->connect(
-			$conf_db['database_name'],
-			$conf_db['database_host'],
-			$conf_db['database_port'],
-			$conf_db['database_admin_user'],
-			$conf_db['database_admin_password'],
-			$conf_db['database_type']
-		);
-		$db = $db->Link_ID;
+		$db = &Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Link_ID;
+
 		$attributes = array();
 		$attributes['ranksep'] = '1.5 equally';
@@ -122,75 +111,5 @@
 		$graph = &Factory::getInstance('Process_GraphViz', true, $attributes);
 
-
-		/**
-		 * Get Hierarchical Area
-		 * @param organizationID 
-		 * @param $parent 
-		 * @param $depth
-		 * @param $db
-		 * @param $graph
-		 * @return 
-		 */
-		function getHierarchicalArea($organizationID, $parent, $depth, $db, $graph)
-		{
-			/* orgchart graph configuration */
-			$color='black';
-			$fillcolor='lightblue2'; //blue TLS values
-			$fontsize = '10';
-			$color = '0.25,1,0.28'; #dark green in TLS values
-			$arrowsize = 0.8;
-
-			if (is_null($parent))
-				$result = $db->query("SELECT area_id, sigla, titular_funcionario_id FROM area WHERE (superior_area_id IS NULL) AND (organizacao_id = ?) AND (ativa = 'S') ORDER BY sigla", array($organizationID));
-			else
-				$result = $db->query("SELECT area_id, sigla, titular_funcionario_id FROM area WHERE (superior_area_id = ?) AND (ativa = 'S') ORDER BY sigla", array($parent));
-
-			$output = $result->GetArray(-1);
-
-			if (is_null($parent) && (count($output) == 0))
-				return false;
-
-			$ldap = &Factory::getInstance('WorkflowLDAP');
-			for ($i = 0; $i < count($output); $i++)
-			{
-				for ($j = 0; $j < $result->_numOfFields; $j++)
-					unset($output[$i][$j]);
-				if ($output[$i]['titular_funcionario_id'] != '')
-				{
-					$supervisor = $ldap->getName($output[$i]['titular_funcionario_id']);
-					$supervisor = str_replace(array(" da ", " de ", " do ", " das ", " dos "), " ", $supervisor);
-					$supervisorArray = explode(' ', $supervisor);
-					$supervisorName = '';
-					for ($j = 0; $j < count($supervisorArray); $j++)
-						$supervisorName .= (($j == 0) || ($j == count($supervisorArray) - 1)) ? $supervisorArray[$j] . ' ' : $supervisorArray[$j][0] . '. ';
-					$supervisorName = trim(str_replace("Junior", "Jr", $supervisorName));
-				}
-				else
-					$supervisorName = '';
-				/* add the area box */
-				$graph->addNode($output[$i]['area_id'],array(
-					'URL'		=> $output[$i]['area_id'],
-					'label'		=> $output[$i]['sigla'] . '\n' . $supervisorName,
-					'shape'		=> 'box',
-					'color'		=> $color,
-					'fillcolor'	=> $fillcolor,
-					'style'		=> 'filled',
-					'fontsize'	=> $fontsize,
-					'fontname'	=> 'serif'
-					)
-				);
-
-				/* add the conection between areas */
-				if (!is_null($parent))
-					$graph->addEdge(array($parent => $output[$i]['area_id']), array('color'=>$color,arrowsize=>$arrowsize));
-				$output[$i]['children'] = getHierarchicalArea($organizationID, $output[$i]['area_id'], $depth + 1, $db, $graph);
-				$output[$i]['depth'] = $depth;
-			}
-
-			return $output;
-		}
-
-
-		$result = getHierarchicalArea($organizationID, null, 0, $db, $graph);
+		$result = $this->getHierarchicalArea($organizationID, null, 0, $db, $graph);
 		if ($result !== false)
 			$graph->image('png', '/tmp/grafico');
@@ -198,4 +117,74 @@
 				die();
 	}
+
+
+	/**
+	 * Get Hierarchical Area
+	 * @param organizationID 
+	 * @param $parent 
+	 * @param $depth
+	 * @param $db
+	 * @param $graph
+	 * @return 
+	 */
+	private function getHierarchicalArea($organizationID, $parent, $depth, $db, $graph)
+	{
+		/* orgchart graph configuration */
+		$color='black';
+		$fillcolor='lightblue2'; //blue TLS values
+		$fontsize = '10';
+		$color = '0.25,1,0.28'; #dark green in TLS values
+		$arrowsize = 0.8;
+
+		if (is_null($parent))
+			$result = $db->query("SELECT area_id, sigla, titular_funcionario_id FROM area WHERE (superior_area_id IS NULL) AND (organizacao_id = ?) AND (ativa = 'S') ORDER BY sigla", array($organizationID));
+		else
+			$result = $db->query("SELECT area_id, sigla, titular_funcionario_id FROM area WHERE (superior_area_id = ?) AND (ativa = 'S') ORDER BY sigla", array($parent));
+
+		$output = $result->GetArray(-1);
+
+		if (is_null($parent) && (count($output) == 0))
+			return false;
+
+		$ldap = &Factory::getInstance('WorkflowLDAP');
+		for ($i = 0; $i < count($output); $i++)
+		{
+			for ($j = 0; $j < $result->_numOfFields; $j++)
+				unset($output[$i][$j]);
+			if ($output[$i]['titular_funcionario_id'] != '')
+			{
+				$supervisor = $ldap->getName($output[$i]['titular_funcionario_id']);
+				$supervisor = str_replace(array(" da ", " de ", " do ", " das ", " dos "), " ", $supervisor);
+				$supervisorArray = explode(' ', $supervisor);
+				$supervisorName = '';
+				for ($j = 0; $j < count($supervisorArray); $j++)
+					$supervisorName .= (($j == 0) || ($j == count($supervisorArray) - 1)) ? $supervisorArray[$j] . ' ' : $supervisorArray[$j][0] . '. ';
+				$supervisorName = trim(str_replace("Junior", "Jr", $supervisorName));
+			}
+			else
+				$supervisorName = '';
+
+			/* add the area box */
+			$graph->addNode($output[$i]['area_id'],array(
+				'URL'		=> $output[$i]['area_id'],
+				'label'		=> $output[$i]['sigla'] . '\n' . $supervisorName,
+				'shape'		=> 'box',
+				'color'		=> $color,
+				'fillcolor'	=> $fillcolor,
+				'style'		=> 'filled',
+				'fontsize'	=> $fontsize,
+				'fontname'	=> 'serif'
+				)
+			);
+
+			/* add the conection between areas */
+			if (!is_null($parent))
+				$graph->addEdge(array($parent => $output[$i]['area_id']), array('color'=>$color,'arrowsize'=>$arrowsize));
+			$output[$i]['children'] = $this->getHierarchicalArea($organizationID, $output[$i]['area_id'], $depth + 1, $db, $graph);
+			$output[$i]['depth'] = $depth;
+		}
+
+		return $output;
+	}
 }
 ?>
Index: sandbox/workflow/branches/993/index.php
===================================================================
--- sandbox/workflow/branches/993/index.php	(revision 2372)
+++ sandbox/workflow/branches/993/index.php	(revision 2418)
@@ -46,5 +46,4 @@
 	else
 	{
-		$GLOBALS['phpgw']->preferences->read_repository();
 		$start_tab = $GLOBALS['phpgw_info']['user']['preferences']['workflow']['startpage'];
 		if (is_null($start_tab))
