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 */ |
---|
89 | $this->cache['DBGalaxia'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); |
---|
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 | ); |
---|
100 | Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBGalaxia']); |
---|
101 | $this->cache['DBGalaxia']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBGalaxia']->Link_ID); |
---|
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 | { |
---|
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 | |
---|
137 | /* connect to the database */ |
---|
138 | $this->cache['DBExpresso'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); |
---|
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 | ); |
---|
149 | Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBExpresso']); |
---|
150 | $this->cache['DBExpresso']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBExpresso']->Link_ID); |
---|
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 */ |
---|
179 | $this->cache['DBWorkflow'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); |
---|
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 | ); |
---|
190 | Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBWorkflow']); |
---|
191 | $this->cache['DBWorkflow']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBWorkflow']->Link_ID); |
---|
192 | } |
---|
193 | |
---|
194 | return $this->cache['DBWorkflow']; |
---|
195 | } |
---|
196 | |
---|
197 | /** |
---|
198 | * Retorna um recurso de LDAP |
---|
199 | * @param bool $useCCParams Indica se deve usar os parâmetros do Contact Center |
---|
200 | * @return resource O recurso LDAP |
---|
201 | * @access public |
---|
202 | */ |
---|
203 | function &getLDAP($useCCParams = false) |
---|
204 | { |
---|
205 | if (!isset($this->cache['ldap'])) |
---|
206 | { |
---|
207 | /* make sure the environment is set */ |
---|
208 | $this->assureEnvironment(); |
---|
209 | |
---|
210 | if($useCCParams) |
---|
211 | { |
---|
212 | /* get the contact center's connection parameters */ |
---|
213 | $ajaxConfig = &Factory::newInstance('ajax_config', 'contactcenter'); |
---|
214 | $config = $ajaxConfig->read_repository(); |
---|
215 | |
---|
216 | $ldapConfigValues['ldap_host'] = $config['cc_ldap_host0']; |
---|
217 | $ldapConfigValues['ldap_user'] = $config['cc_ldap_browse_dn0']; |
---|
218 | $ldapConfigValues['ldap_password'] = $config['cc_ldap_pw0']; |
---|
219 | $ldapConfigValues['ldap_follow_referrals'] = 1; |
---|
220 | } |
---|
221 | else |
---|
222 | { |
---|
223 | /* check where the connection parameters are */ |
---|
224 | $connectionInfo = (isset($GLOBALS['phpgw_info']['server']['ldap_host'])) ? |
---|
225 | $GLOBALS['phpgw_info']['server'] : |
---|
226 | $_SESSION['phpgw_info']['workflow']['server']; |
---|
227 | |
---|
228 | /* load required information */ |
---|
229 | $ldapConfigValues = galaxia_get_config_values(array('ldap_host' => '', 'ldap_user' => '', 'ldap_password'=> '', 'ldap_follow_referrals' => '')); |
---|
230 | if (empty($ldapConfigValues['ldap_host'])) |
---|
231 | $ldapConfigValues['ldap_host'] = $connectionInfo['ldap_host']; |
---|
232 | } |
---|
233 | |
---|
234 | /* connect to the LDAP server */ |
---|
235 | $this->cache['ldap'] = ldap_connect($ldapConfigValues['ldap_host']); |
---|
236 | |
---|
237 | /* configure the connection */ |
---|
238 | ldap_set_option($this->cache['ldap'], LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
239 | ldap_set_option($this->cache['ldap'], LDAP_OPT_REFERRALS, ($ldapConfigValues['ldap_follow_referrals'] == 1) ? 1 : 0); |
---|
240 | |
---|
241 | /* if username and password are available, bind the connection */ |
---|
242 | if ((!empty($ldapConfigValues['ldap_user'])) && (!empty($ldapConfigValues['ldap_password']))) |
---|
243 | ldap_bind($this->cache['ldap'], $ldapConfigValues['ldap_user'], $ldapConfigValues['ldap_password']); |
---|
244 | } |
---|
245 | |
---|
246 | return $this->cache['ldap']; |
---|
247 | } |
---|
248 | } |
---|
249 | ?> |
---|