[795] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * -------------------------------------------- * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**************************************************************************/ |
---|
| 11 | |
---|
| 12 | /** |
---|
| 13 | * Provê objetos de multipropósito do Workflow |
---|
| 14 | * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com |
---|
| 15 | * @version 1.0 |
---|
| 16 | * @package Workflow |
---|
| 17 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 18 | */ |
---|
| 19 | class WorkflowObjects |
---|
| 20 | { |
---|
| 21 | /** |
---|
| 22 | * @var array $cache Cache de objetos |
---|
| 23 | * @access private |
---|
| 24 | */ |
---|
| 25 | private $cache; |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * Construtor da classe |
---|
| 29 | * @return object |
---|
| 30 | * @access public |
---|
| 31 | */ |
---|
| 32 | function WorkflowObjects() |
---|
| 33 | { |
---|
| 34 | $this->cache = array(); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | * Monta o ambiente requerido pelos métodos (somente se for necessário) |
---|
| 39 | * @param bool $requireGalaxia Indica que os métodos da engine Galaxia são necessários |
---|
| 40 | * @return void |
---|
| 41 | * @access public |
---|
| 42 | */ |
---|
| 43 | private function assureEnvironment($requireGalaxia = true) |
---|
| 44 | { |
---|
| 45 | if (!defined('PHPGW_API_INC')) |
---|
| 46 | define('PHPGW_API_INC', dirname(__FILE__) . '/../../phpgwapi/inc'); |
---|
| 47 | |
---|
| 48 | if ($requireGalaxia) |
---|
| 49 | { |
---|
| 50 | if (!function_exists('galaxia_get_config_values')) |
---|
| 51 | { |
---|
| 52 | require_once 'engine/config.ajax.inc.php' ; |
---|
| 53 | require_once 'engine/class.ajax_config.inc.php' ; |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | * Retorna uma conexão com o banco de dados do Galaxia (normalmente associado ao banco de dados do Expresso (eGroupWare)) |
---|
| 60 | * @return object O objeto de acesso a banco de dados, já conectado |
---|
| 61 | * @access public |
---|
| 62 | */ |
---|
| 63 | function &getDBGalaxia() |
---|
| 64 | { |
---|
| 65 | if (!isset($this->cache['DBGalaxia'])) |
---|
| 66 | { |
---|
| 67 | /* make sure the environment is set */ |
---|
| 68 | $this->assureEnvironment(); |
---|
| 69 | |
---|
| 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 | |
---|
| 80 | /* check if all configuration is OK */ |
---|
| 81 | $dedicatedDB = true; |
---|
| 82 | foreach ($dbConfigValues as $configName => $configValue) |
---|
| 83 | if (empty($configValue) && ($configName != 'workflow_database_password')) |
---|
| 84 | $dedicatedDB = false; |
---|
| 85 | |
---|
| 86 | if ($dedicatedDB) |
---|
| 87 | { |
---|
| 88 | /* connect to the database */ |
---|
[2372] | 89 | $this->cache['DBGalaxia'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); |
---|
[795] | 90 | $this->cache['DBGalaxia']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */ |
---|
| 91 | $this->cache['DBGalaxia']->Halt_On_Error = 'no'; |
---|
| 92 | $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'] |
---|
| 99 | ); |
---|
[2372] | 100 | Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBGalaxia']); |
---|
| 101 | $this->cache['DBGalaxia']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBGalaxia']->Link_ID); |
---|
[795] | 102 | } |
---|
| 103 | else |
---|
| 104 | $this->cache['DBGalaxia'] = &$this->getDBExpresso(); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | return $this->cache['DBGalaxia']; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /** |
---|
| 111 | * Retorna uma conexão com o banco de dados do Expresso (eGroupWare) |
---|
| 112 | * @return object O objeto de acesso a banco de dados, já conectado |
---|
| 113 | * @access public |
---|
| 114 | */ |
---|
| 115 | function &getDBExpresso() |
---|
| 116 | { |
---|
| 117 | if (!isset($this->cache['DBExpresso'])) |
---|
| 118 | { |
---|
| 119 | /* make sure the environment is set */ |
---|
| 120 | $this->assureEnvironment(false); |
---|
| 121 | |
---|
| 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 | { |
---|
[2372] | 130 | Factory::getInstance('WorkflowMacro')->prepareEnvironment(); |
---|
[795] | 131 | if (isset($GLOBALS['phpgw_info']['server'])) |
---|
| 132 | $connectionInfo = $GLOBALS['phpgw_info']['server']; |
---|
| 133 | else |
---|
| 134 | return false; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | /* connect to the database */ |
---|
[2372] | 138 | $this->cache['DBExpresso'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); |
---|
[795] | 139 | $this->cache['DBExpresso']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */ |
---|
| 140 | $this->cache['DBExpresso']->Halt_On_Error = 'no'; |
---|
| 141 | $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'] |
---|
| 148 | ); |
---|
[2372] | 149 | Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBExpresso']); |
---|
| 150 | $this->cache['DBExpresso']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBExpresso']->Link_ID); |
---|
[795] | 151 | } |
---|
| 152 | |
---|
| 153 | return $this->cache['DBExpresso']; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | /** |
---|
| 157 | * Retorna uma conexão com o banco de dados do Workflow |
---|
| 158 | * @return object O objeto de acesso a banco de dados, já conectado |
---|
| 159 | * @access public |
---|
| 160 | */ |
---|
| 161 | function &getDBWorkflow() |
---|
| 162 | { |
---|
| 163 | if (!isset($this->cache['DBWorkflow'])) |
---|
| 164 | { |
---|
| 165 | /* make sure the environment is set */ |
---|
| 166 | $this->assureEnvironment(); |
---|
| 167 | |
---|
| 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 | |
---|
| 178 | /* connect to the database */ |
---|
[2372] | 179 | $this->cache['DBWorkflow'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); |
---|
[795] | 180 | $this->cache['DBWorkflow']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */ |
---|
| 181 | $this->cache['DBWorkflow']->Halt_On_Error = 'no'; |
---|
| 182 | $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'] |
---|
| 189 | ); |
---|
[2372] | 190 | Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBWorkflow']); |
---|
| 191 | $this->cache['DBWorkflow']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBWorkflow']->Link_ID); |
---|
[795] | 192 | } |
---|
| 193 | |
---|
| 194 | return $this->cache['DBWorkflow']; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | /** |
---|
| 198 | * Retorna um recurso de LDAP |
---|
| 199 | * @return resource O recurso LDAP |
---|
| 200 | * @access public |
---|
| 201 | */ |
---|
| 202 | function &getLDAP() |
---|
| 203 | { |
---|
| 204 | if (!isset($this->cache['ldap'])) |
---|
| 205 | { |
---|
| 206 | /* make sure the environment is set */ |
---|
| 207 | $this->assureEnvironment(); |
---|
| 208 | |
---|
| 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']; |
---|
| 218 | |
---|
| 219 | /* connect to the LDAP server */ |
---|
| 220 | $this->cache['ldap'] = ldap_connect($ldapConfigValues['ldap_host']); |
---|
| 221 | |
---|
| 222 | /* configure the connection */ |
---|
| 223 | 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); |
---|
| 225 | |
---|
| 226 | /* 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']); |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | return $this->cache['ldap']; |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | ?> |
---|