Ignore:
Timestamp:
04/05/10 15:30:21 (14 years ago)
Author:
pedroerp
Message:

Ticket #993 - Versão inicial da classe 'Settings' e substituicao de chamadas 'read_repository'.

Location:
sandbox/workflow/branches/993
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • sandbox/workflow/branches/993/inc/class.WorkflowObjects.inc.php

    r2372 r2418  
    1313 * Provê objetos de multipropósito do Workflow 
    1414 * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com 
     15 * @author Pedro Eugenio Rocha - pedro.eugenio.rocha@gmail.com 
    1516 * @version 1.0 
    1617 * @package Workflow 
     
    2324         * @access private 
    2425         */ 
    25         private $cache; 
     26        private $cache = array(); 
    2627 
    2728        /** 
    28          * Construtor da classe 
    29          * @return object 
    30          * @access public 
    31          */ 
    32         function WorkflowObjects() 
    33         { 
    34                 $this->cache = array(); 
    35         } 
    36  
    37         /** 
     29         * TODO We should remove this method.. 
    3830         * Monta o ambiente requerido pelos métodos (somente se for necessário) 
    3931         * @param bool $requireGalaxia Indica que os métodos da engine Galaxia são necessários 
     
    6860                        $this->assureEnvironment(); 
    6961 
    70                         /* load the configuration required to establish a connection to the Galaxia database */ 
    71                         $dbConfigValues = galaxia_get_config_values(array( 
    72                                 'workflow_database_name' => '', 
    73                                 'workflow_database_host' => '', 
    74                                 'workflow_database_port' => '', 
    75                                 'workflow_database_user' => '', 
    76                                 'workflow_database_password' => '', 
    77                                 'workflow_database_type' => '' 
    78                         )); 
    79  
    8062                        /* check if all configuration is OK */ 
    8163                        $dedicatedDB = true; 
    82                         foreach ($dbConfigValues as $configName => $configValue) 
    83                                 if (empty($configValue) && ($configName != 'workflow_database_password')) 
    84                                         $dedicatedDB = false; 
    8564 
     65                        /* if any parameter is not set, then we will return expresso database */ 
     66                        if ((Settings::get('workflow', 'galaxia', 'db', 'name') == '') or 
     67                                (Settings::get('workflow', 'galaxia', 'db', 'host') == '') or 
     68                                (Settings::get('workflow', 'galaxia', 'db', 'port') == '') or 
     69                                (Settings::get('workflow', 'galaxia', 'db', 'user') == '') or 
     70                                (Settings::get('workflow', 'galaxia', 'db', 'type') == '')) 
     71                                $dedicatedDB = false; 
     72 
     73                        /* should we connect to a dedicated database? */ 
    8674                        if ($dedicatedDB) 
    8775                        { 
     
    9179                                $this->cache['DBGalaxia']->Halt_On_Error = 'no'; 
    9280                                $this->cache['DBGalaxia']->connect( 
    93                                         $dbConfigValues['workflow_database_name'], 
    94                                         $dbConfigValues['workflow_database_host'], 
    95                                         $dbConfigValues['workflow_database_port'], 
    96                                         $dbConfigValues['workflow_database_user'], 
    97                                         $dbConfigValues['workflow_database_password'], 
    98                                         $dbConfigValues['workflow_database_type'] 
     81                                        Settings::get('workflow', 'galaxia', 'db', 'name'), 
     82                                        Settings::get('workflow', 'galaxia', 'db', 'host'), 
     83                                        Settings::get('workflow', 'galaxia', 'db', 'port'), 
     84                                        Settings::get('workflow', 'galaxia', 'db', 'user'), 
     85                                        Settings::get('workflow', 'galaxia', 'db', 'password'), 
     86                                        Settings::get('workflow', 'galaxia', 'db', 'type') 
    9987                                ); 
    10088                                Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBGalaxia']); 
     
    120108                        $this->assureEnvironment(false); 
    121109 
    122                         /* check where the connection parameters are */ 
    123                         $connectionInfo = (isset($GLOBALS['phpgw_info']['server']['db_name'])) ? 
    124                                 $GLOBALS['phpgw_info']['server'] : 
    125                                 $_SESSION['phpgw_info']['workflow']['server']; 
    126  
    127                         /* the information was not found. Try to load the environment */ 
    128                         if (!isset($connectionInfo['db_name'])) 
    129                         { 
    130                                 Factory::getInstance('WorkflowMacro')->prepareEnvironment(); 
    131                                 if (isset($GLOBALS['phpgw_info']['server'])) 
    132                                         $connectionInfo = $GLOBALS['phpgw_info']['server']; 
    133                                 else 
    134                                         return false; 
    135                         } 
    136  
    137110                        /* connect to the database */ 
    138111                        $this->cache['DBExpresso'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); 
     
    140113                        $this->cache['DBExpresso']->Halt_On_Error = 'no'; 
    141114                        $this->cache['DBExpresso']->connect( 
    142                                 $connectionInfo['db_name'], 
    143                                 $connectionInfo['db_host'], 
    144                                 $connectionInfo['db_port'], 
    145                                 $connectionInfo['db_user'], 
    146                                 $connectionInfo['db_pass'], 
    147                                 $connectionInfo['db_type'] 
     115                                Settings::get('expresso', 'db', 'name'), 
     116                                Settings::get('expresso', 'db', 'host'), 
     117                                Settings::get('expresso', 'db', 'port'), 
     118                                Settings::get('expresso', 'db', 'user'), 
     119                                Settings::get('expresso', 'db', 'password'), 
     120                                Settings::get('expresso', 'db', 'type') 
    148121                        ); 
    149122                        Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBExpresso']); 
     
    166139                        $this->assureEnvironment(); 
    167140 
    168                         /* load the configuration required to establish a connection to the Galaxia database */ 
    169                         $dbConfigValues = galaxia_get_config_values(array( 
    170                                 'database_name' => '', 
    171                                 'database_host' => '', 
    172                                 'database_port' => '', 
    173                                 'database_admin_user' => '', 
    174                                 'database_admin_password' => '', 
    175                                 'database_type' => '' 
    176                         )); 
    177  
    178141                        /* connect to the database */ 
    179142                        $this->cache['DBWorkflow'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); 
     
    181144                        $this->cache['DBWorkflow']->Halt_On_Error = 'no'; 
    182145                        $this->cache['DBWorkflow']->connect( 
    183                                 $dbConfigValues['database_name'], 
    184                                 $dbConfigValues['database_host'], 
    185                                 $dbConfigValues['database_port'], 
    186                                 $dbConfigValues['database_admin_user'], 
    187                                 $dbConfigValues['database_admin_password'], 
    188                                 $dbConfigValues['database_type'] 
     146                                Settings::get('workflow', 'db', 'name'), 
     147                                Settings::get('workflow', 'db', 'host'), 
     148                                Settings::get('workflow', 'db', 'port'), 
     149                                Settings::get('workflow', 'db', 'admin_user'), 
     150                                Settings::get('workflow', 'db', 'admin_password'), 
     151                                Settings::get('workflow', 'db', 'type') 
    189152                        ); 
    190153                        Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBWorkflow']); 
     
    207170                        $this->assureEnvironment(); 
    208171 
    209                         /* check where the connection parameters are */ 
    210                         $connectionInfo = (isset($GLOBALS['phpgw_info']['server']['ldap_host'])) ? 
    211                                 $GLOBALS['phpgw_info']['server'] : 
    212                                 $_SESSION['phpgw_info']['workflow']['server']; 
    213  
    214                         /* load required information */ 
    215                         $ldapConfigValues = galaxia_get_config_values(array('ldap_host' => '', 'ldap_user' => '', 'ldap_password'=> '', 'ldap_follow_referrals' => '')); 
    216                         if (empty($ldapConfigValues['ldap_host'])) 
    217                                 $ldapConfigValues['ldap_host'] = $connectionInfo['ldap_host']; 
     172                        /* which ldap host to connect? */ 
     173                        $ldapHost = Settings::get('workflow', 'ldap', 'host'); 
     174                        if (empty($ldapHost)) 
     175                                $ldapHost = Settings::get('expresso', 'ldap', 'host'); 
    218176 
    219177                        /* connect to the LDAP server */ 
    220                         $this->cache['ldap'] = ldap_connect($ldapConfigValues['ldap_host']); 
     178                        $this->cache['ldap'] = ldap_connect($ldapHost); 
    221179 
    222180                        /* configure the connection */ 
    223181                        ldap_set_option($this->cache['ldap'], LDAP_OPT_PROTOCOL_VERSION, 3); 
    224                         ldap_set_option($this->cache['ldap'], LDAP_OPT_REFERRALS, ($ldapConfigValues['ldap_follow_referrals'] == 1) ? 1 : 0); 
     182                        ldap_set_option($this->cache['ldap'], LDAP_OPT_REFERRALS, (Settings::get('workflow', 'ldap', 'follow_referrals') == 1) ? 1 : 0); 
    225183 
    226184                        /* if  username and password are available, bind the connection */ 
    227                         if ((!empty($ldapConfigValues['ldap_user'])) && (!empty($ldapConfigValues['ldap_password']))) 
    228                                 ldap_bind($this->cache['ldap'], $ldapConfigValues['ldap_user'], $ldapConfigValues['ldap_password']); 
     185                        if ((Settings::get('workflow', 'ldap', 'user') != '') and 
     186                                (Settings::get('workflow', 'ldap', 'password') != '')) 
     187                                ldap_bind(      $this->cache['ldap'], 
     188                                                        Settings::get('workflow', 'ldap', 'user'), 
     189                                                        Settings::get('workflow', 'ldap', 'password') 
     190                                                        ); 
    229191                } 
    230192 
  • sandbox/workflow/branches/993/inc/class.bo_utils.inc.php

    r2372 r2418  
    8686                        $ret_name = empty($params['name']) ? 'cn' : $params['name']; 
    8787 
     88                        /** 
     89                         * This is wrong. We should incorporate this settings into 
     90                         * workflow configuration table. Therefore, workflow should 
     91                         * not depend on other modules.. 
     92                         */ 
    8893                        $ajaxConfig = &Factory::newInstance('ajax_config', 'contactcenter'); 
    8994                        $config = $ajaxConfig->read_repository(); 
  • sandbox/workflow/branches/993/inc/class.so_userinterface.inc.php

    r2372 r2418  
    6060                $oldDB = $GLOBALS['phpgw']->db; 
    6161                $GLOBALS['phpgw']->db = $GLOBALS['ajax']->db; 
    62                 $config = &Factory::getInstance('config', 'workflow'); 
    63                 $configValues = $config->read_repository(); 
    64                 $submasksString = $configValues['intranet_subnetworks']; 
     62                $submasksString = Settings::get('workflow', 'intranet_subnetworks'); 
    6563                $GLOBALS['phpgw']->db = $oldDB; 
    6664 
  • sandbox/workflow/branches/993/inc/class.ui_orgchart.inc.php

    r2372 r2418  
    3737         * @access public 
    3838         */ 
    39         function ui_orgchart() 
     39        public function ui_orgchart() 
    4040        { 
    4141        } 
     
    4545         * @access public 
    4646         */ 
    47         function draw($tab_index = "") 
     47        public function draw($tab_index = "") 
    4848        { 
    4949                $this->workflow_acl = Factory::getInstance('workflow_acl'); 
     
    9292         * Show the graph 
    9393         * @access public 
    94          * @return void  
     94         * @return void 
    9595         */ 
    96         function graph() 
     96        public function graph() 
    9797        { 
    9898                if (!isset($_GET['organizationID'])) 
     
    104104                        die(); 
    105105 
    106                 $config_values = Factory::getInstance('config', 'workflow'); 
    107                 $config_values->read_repository(); 
    108                 $conf_db = $config_values->config_data; 
    109                 $db = Factory::getInstance('db'); 
    110                 $db->connect( 
    111                         $conf_db['database_name'], 
    112                         $conf_db['database_host'], 
    113                         $conf_db['database_port'], 
    114                         $conf_db['database_admin_user'], 
    115                         $conf_db['database_admin_password'], 
    116                         $conf_db['database_type'] 
    117                 ); 
    118                 $db = $db->Link_ID; 
     106                $db = &Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Link_ID; 
     107 
    119108                $attributes = array(); 
    120109                $attributes['ranksep'] = '1.5 equally'; 
     
    122111                $graph = &Factory::getInstance('Process_GraphViz', true, $attributes); 
    123112 
    124  
    125                 /** 
    126                  * Get Hierarchical Area 
    127                  * @param organizationID  
    128                  * @param $parent  
    129                  * @param $depth 
    130                  * @param $db 
    131                  * @param $graph 
    132                  * @return  
    133                  */ 
    134                 function getHierarchicalArea($organizationID, $parent, $depth, $db, $graph) 
    135                 { 
    136                         /* orgchart graph configuration */ 
    137                         $color='black'; 
    138                         $fillcolor='lightblue2'; //blue TLS values 
    139                         $fontsize = '10'; 
    140                         $color = '0.25,1,0.28'; #dark green in TLS values 
    141                         $arrowsize = 0.8; 
    142  
    143                         if (is_null($parent)) 
    144                                 $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)); 
    145                         else 
    146                                 $result = $db->query("SELECT area_id, sigla, titular_funcionario_id FROM area WHERE (superior_area_id = ?) AND (ativa = 'S') ORDER BY sigla", array($parent)); 
    147  
    148                         $output = $result->GetArray(-1); 
    149  
    150                         if (is_null($parent) && (count($output) == 0)) 
    151                                 return false; 
    152  
    153                         $ldap = &Factory::getInstance('WorkflowLDAP'); 
    154                         for ($i = 0; $i < count($output); $i++) 
    155                         { 
    156                                 for ($j = 0; $j < $result->_numOfFields; $j++) 
    157                                         unset($output[$i][$j]); 
    158                                 if ($output[$i]['titular_funcionario_id'] != '') 
    159                                 { 
    160                                         $supervisor = $ldap->getName($output[$i]['titular_funcionario_id']); 
    161                                         $supervisor = str_replace(array(" da ", " de ", " do ", " das ", " dos "), " ", $supervisor); 
    162                                         $supervisorArray = explode(' ', $supervisor); 
    163                                         $supervisorName = ''; 
    164                                         for ($j = 0; $j < count($supervisorArray); $j++) 
    165                                                 $supervisorName .= (($j == 0) || ($j == count($supervisorArray) - 1)) ? $supervisorArray[$j] . ' ' : $supervisorArray[$j][0] . '. '; 
    166                                         $supervisorName = trim(str_replace("Junior", "Jr", $supervisorName)); 
    167                                 } 
    168                                 else 
    169                                         $supervisorName = ''; 
    170                                 /* add the area box */ 
    171                                 $graph->addNode($output[$i]['area_id'],array( 
    172                                         'URL'           => $output[$i]['area_id'], 
    173                                         'label'         => $output[$i]['sigla'] . '\n' . $supervisorName, 
    174                                         'shape'         => 'box', 
    175                                         'color'         => $color, 
    176                                         'fillcolor'     => $fillcolor, 
    177                                         'style'         => 'filled', 
    178                                         'fontsize'      => $fontsize, 
    179                                         'fontname'      => 'serif' 
    180                                         ) 
    181                                 ); 
    182  
    183                                 /* add the conection between areas */ 
    184                                 if (!is_null($parent)) 
    185                                         $graph->addEdge(array($parent => $output[$i]['area_id']), array('color'=>$color,arrowsize=>$arrowsize)); 
    186                                 $output[$i]['children'] = getHierarchicalArea($organizationID, $output[$i]['area_id'], $depth + 1, $db, $graph); 
    187                                 $output[$i]['depth'] = $depth; 
    188                         } 
    189  
    190                         return $output; 
    191                 } 
    192  
    193  
    194                 $result = getHierarchicalArea($organizationID, null, 0, $db, $graph); 
     113                $result = $this->getHierarchicalArea($organizationID, null, 0, $db, $graph); 
    195114                if ($result !== false) 
    196115                        $graph->image('png', '/tmp/grafico'); 
     
    198117                                die(); 
    199118        } 
     119 
     120 
     121        /** 
     122         * Get Hierarchical Area 
     123         * @param organizationID  
     124         * @param $parent  
     125         * @param $depth 
     126         * @param $db 
     127         * @param $graph 
     128         * @return  
     129         */ 
     130        private function getHierarchicalArea($organizationID, $parent, $depth, $db, $graph) 
     131        { 
     132                /* orgchart graph configuration */ 
     133                $color='black'; 
     134                $fillcolor='lightblue2'; //blue TLS values 
     135                $fontsize = '10'; 
     136                $color = '0.25,1,0.28'; #dark green in TLS values 
     137                $arrowsize = 0.8; 
     138 
     139                if (is_null($parent)) 
     140                        $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)); 
     141                else 
     142                        $result = $db->query("SELECT area_id, sigla, titular_funcionario_id FROM area WHERE (superior_area_id = ?) AND (ativa = 'S') ORDER BY sigla", array($parent)); 
     143 
     144                $output = $result->GetArray(-1); 
     145 
     146                if (is_null($parent) && (count($output) == 0)) 
     147                        return false; 
     148 
     149                $ldap = &Factory::getInstance('WorkflowLDAP'); 
     150                for ($i = 0; $i < count($output); $i++) 
     151                { 
     152                        for ($j = 0; $j < $result->_numOfFields; $j++) 
     153                                unset($output[$i][$j]); 
     154                        if ($output[$i]['titular_funcionario_id'] != '') 
     155                        { 
     156                                $supervisor = $ldap->getName($output[$i]['titular_funcionario_id']); 
     157                                $supervisor = str_replace(array(" da ", " de ", " do ", " das ", " dos "), " ", $supervisor); 
     158                                $supervisorArray = explode(' ', $supervisor); 
     159                                $supervisorName = ''; 
     160                                for ($j = 0; $j < count($supervisorArray); $j++) 
     161                                        $supervisorName .= (($j == 0) || ($j == count($supervisorArray) - 1)) ? $supervisorArray[$j] . ' ' : $supervisorArray[$j][0] . '. '; 
     162                                $supervisorName = trim(str_replace("Junior", "Jr", $supervisorName)); 
     163                        } 
     164                        else 
     165                                $supervisorName = ''; 
     166 
     167                        /* add the area box */ 
     168                        $graph->addNode($output[$i]['area_id'],array( 
     169                                'URL'           => $output[$i]['area_id'], 
     170                                'label'         => $output[$i]['sigla'] . '\n' . $supervisorName, 
     171                                'shape'         => 'box', 
     172                                'color'         => $color, 
     173                                'fillcolor'     => $fillcolor, 
     174                                'style'         => 'filled', 
     175                                'fontsize'      => $fontsize, 
     176                                'fontname'      => 'serif' 
     177                                ) 
     178                        ); 
     179 
     180                        /* add the conection between areas */ 
     181                        if (!is_null($parent)) 
     182                                $graph->addEdge(array($parent => $output[$i]['area_id']), array('color'=>$color,'arrowsize'=>$arrowsize)); 
     183                        $output[$i]['children'] = $this->getHierarchicalArea($organizationID, $output[$i]['area_id'], $depth + 1, $db, $graph); 
     184                        $output[$i]['depth'] = $depth; 
     185                } 
     186 
     187                return $output; 
     188        } 
    200189} 
    201190?> 
  • sandbox/workflow/branches/993/inc/common.inc.php

    r2372 r2418  
    1111 
    1212/** 
    13  * Server base path. This constant is somewhat simililar to 
    14  * 'PHPGW_SERVER_ROOT'. Nevertheless, there are cases that we 
    15  * access Workflow directly and it must be defined somewhere. 
    16  * Recently discovered, when we are runnnig jobs HTTP_SERVER_VARS 
    17  * exported by apache are not available. 
    18  * Therefore, we are using this workaround here, setting 
    19  * EGW_SERVER_ROOT based on the location of this file. This constant 
    20  * should be updated properly every time we move this file. 
     13 * This is other big workaround. In ajax calls, we use controller.php 
     14 * directly, which do not includes header.inc for performance issues. 
     15 * However, for phpgwAPI to work properly we need to set several 
     16 * constants and objects, which are created in this file (header.inc). 
     17 * As much as this problem still unsolved (by phpAPI group), this potencially 
     18 * problematic and ugly code must still here.. =( 
     19 */ 
     20$old = $GLOBALS['phpgw_info']['flags']; 
     21$GLOBALS['phpgw_info']['flags'] = array( 
     22        'noheader' => True, 
     23        'nonavbar' => True, 
     24        'currentapp' => 'workflow' 
     25); 
     26/* TODO TODO TODO TODO */ 
     27$base = dirname(dirname(dirname(__FILE__))); 
     28require_once ($base . '/header.inc.php'); 
     29$GLOBALS['phpgw_info']['flags'] = $old; 
     30 
     31 
     32/** 
     33 * Server base path. In this module, we should only use 
     34 * constants defined here. PHPGW_SERVER_ROOT is defined 
     35 * on 'header.inc.php' which is always included by this 
     36 * file. 
    2137 * @name EGW_SERVER_ROOT 
    2238 */ 
    23 define('EGW_SERVER_ROOT', dirname(dirname(dirname(__FILE__)))); 
    24 //define('EGW_SERVER_ROOT', $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT']); 
     39define('EGW_SERVER_ROOT', PHPGW_SERVER_ROOT); 
    2540 
    2641/** 
     
    5166 
    5267 
    53 if (file_exists(EGW_SERVER_ROOT . '/header.session.inc.php')) { 
    54         require_once EGW_SERVER_ROOT . '/header.session.inc.php'; 
    55 } 
    56  
    5768 
    5869/* assure that the correct encondig will be used (e.g string functions) */ 
     
    7081require_once WF_LIB_ROOT . 'factory/WorkflowFactory.php'; 
    7182require_once WF_LIB_ROOT . 'factory/ProcessFactory.php'; 
     83require_once WF_LIB_ROOT . 'settings/Settings.php'; 
     84 
     85Settings::load(); 
    7286 
    7387$GLOBALS['workflow']['workflowObjects'] = Factory::getInstance('WorkflowObjects'); 
  • sandbox/workflow/branches/993/index.php

    r2372 r2418  
    4646        else 
    4747        { 
    48                 $GLOBALS['phpgw']->preferences->read_repository(); 
    4948                $start_tab = $GLOBALS['phpgw_info']['user']['preferences']['workflow']['startpage']; 
    5049                if (is_null($start_tab)) 
Note: See TracChangeset for help on using the changeset viewer.