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 | * @author Pedro Eugenio Rocha - pedro.eugenio.rocha@gmail.com |
---|
16 | * @version 1.0 |
---|
17 | * @package Workflow |
---|
18 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
19 | */ |
---|
20 | class WorkflowObjects |
---|
21 | { |
---|
22 | /** |
---|
23 | * @var array $cache Cache de objetos |
---|
24 | * @access private |
---|
25 | */ |
---|
26 | private $cache = array(); |
---|
27 | |
---|
28 | /** |
---|
29 | * TODO We should remove this method.. |
---|
30 | * Monta o ambiente requerido pelos métodos (somente se for necessário) |
---|
31 | * @param bool $requireGalaxia Indica que os métodos da engine Galaxia são necessários |
---|
32 | * @return void |
---|
33 | * @access public |
---|
34 | */ |
---|
35 | private function assureEnvironment($requireGalaxia = true) |
---|
36 | { |
---|
37 | if (!defined('PHPGW_API_INC')) |
---|
38 | define('PHPGW_API_INC', dirname(__FILE__) . '/../../phpgwapi/inc'); |
---|
39 | |
---|
40 | if ($requireGalaxia) |
---|
41 | { |
---|
42 | if (!function_exists('galaxia_get_config_values')) |
---|
43 | { |
---|
44 | require_once 'engine/config.ajax.inc.php' ; |
---|
45 | require_once 'engine/class.ajax_config.inc.php' ; |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * Retorna uma conexão com o banco de dados do Galaxia (normalmente associado ao banco de dados do Expresso (eGroupWare)) |
---|
52 | * @return object O objeto de acesso a banco de dados, já conectado |
---|
53 | * @access public |
---|
54 | */ |
---|
55 | function &getDBGalaxia() |
---|
56 | { |
---|
57 | if (!isset($this->cache['DBGalaxia'])) |
---|
58 | { |
---|
59 | /* make sure the environment is set */ |
---|
60 | $this->assureEnvironment(); |
---|
61 | |
---|
62 | /* check if all configuration is OK */ |
---|
63 | $dedicatedDB = true; |
---|
64 | |
---|
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? */ |
---|
74 | if ($dedicatedDB) |
---|
75 | { |
---|
76 | /* connect to the database */ |
---|
77 | $this->cache['DBGalaxia'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); |
---|
78 | $this->cache['DBGalaxia']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */ |
---|
79 | $this->cache['DBGalaxia']->Halt_On_Error = 'no'; |
---|
80 | $this->cache['DBGalaxia']->connect( |
---|
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') |
---|
87 | ); |
---|
88 | Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBGalaxia']); |
---|
89 | $this->cache['DBGalaxia']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBGalaxia']->Link_ID); |
---|
90 | } |
---|
91 | else |
---|
92 | $this->cache['DBGalaxia'] = &$this->getDBExpresso(); |
---|
93 | } |
---|
94 | |
---|
95 | return $this->cache['DBGalaxia']; |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * Retorna uma conexão com o banco de dados do Expresso (eGroupWare) |
---|
100 | * @return object O objeto de acesso a banco de dados, já conectado |
---|
101 | * @access public |
---|
102 | */ |
---|
103 | function &getDBExpresso() |
---|
104 | { |
---|
105 | if (!isset($this->cache['DBExpresso'])) |
---|
106 | { |
---|
107 | /* make sure the environment is set */ |
---|
108 | $this->assureEnvironment(false); |
---|
109 | |
---|
110 | /* connect to the database */ |
---|
111 | $this->cache['DBExpresso'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); |
---|
112 | $this->cache['DBExpresso']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */ |
---|
113 | $this->cache['DBExpresso']->Halt_On_Error = 'no'; |
---|
114 | $this->cache['DBExpresso']->connect( |
---|
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') |
---|
121 | ); |
---|
122 | Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBExpresso']); |
---|
123 | $this->cache['DBExpresso']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBExpresso']->Link_ID); |
---|
124 | } |
---|
125 | |
---|
126 | return $this->cache['DBExpresso']; |
---|
127 | } |
---|
128 | |
---|
129 | /** |
---|
130 | * Retorna uma conexão com o banco de dados do Workflow |
---|
131 | * @return object O objeto de acesso a banco de dados, já conectado |
---|
132 | * @access public |
---|
133 | */ |
---|
134 | function &getDBWorkflow() |
---|
135 | { |
---|
136 | if (!isset($this->cache['DBWorkflow'])) |
---|
137 | { |
---|
138 | /* make sure the environment is set */ |
---|
139 | $this->assureEnvironment(); |
---|
140 | |
---|
141 | /* connect to the database */ |
---|
142 | $this->cache['DBWorkflow'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db')); |
---|
143 | $this->cache['DBWorkflow']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */ |
---|
144 | $this->cache['DBWorkflow']->Halt_On_Error = 'no'; |
---|
145 | $this->cache['DBWorkflow']->connect( |
---|
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') |
---|
152 | ); |
---|
153 | Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBWorkflow']); |
---|
154 | $this->cache['DBWorkflow']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBWorkflow']->Link_ID); |
---|
155 | } |
---|
156 | |
---|
157 | return $this->cache['DBWorkflow']; |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * Retorna um recurso de LDAP |
---|
162 | * @return resource O recurso LDAP |
---|
163 | * @access public |
---|
164 | */ |
---|
165 | function &getLDAP() |
---|
166 | { |
---|
167 | if (!isset($this->cache['ldap'])) |
---|
168 | { |
---|
169 | /* make sure the environment is set */ |
---|
170 | $this->assureEnvironment(); |
---|
171 | |
---|
172 | /* which ldap host to connect? */ |
---|
173 | $ldapHost = Settings::get('workflow', 'ldap', 'host'); |
---|
174 | if (empty($ldapHost)) |
---|
175 | $ldapHost = Settings::get('expresso', 'ldap', 'host'); |
---|
176 | |
---|
177 | /* connect to the LDAP server */ |
---|
178 | $this->cache['ldap'] = ldap_connect($ldapHost); |
---|
179 | |
---|
180 | /* configure the connection */ |
---|
181 | ldap_set_option($this->cache['ldap'], LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
182 | ldap_set_option($this->cache['ldap'], LDAP_OPT_REFERRALS, (Settings::get('workflow', 'ldap', 'follow_referrals') == 1) ? 1 : 0); |
---|
183 | |
---|
184 | /* if username and password are available, bind the connection */ |
---|
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 | ); |
---|
191 | } |
---|
192 | |
---|
193 | return $this->cache['ldap']; |
---|
194 | } |
---|
195 | } |
---|
196 | ?> |
---|