1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * Expresso Livre * |
---|
4 | * http://www.expressolivre.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 | require_once(dirname(__FILE__).'/../../services/class.servicelocator.php'); |
---|
13 | include_once("class.imap_functions.inc.php"); |
---|
14 | include_once("class.functions.inc.php"); |
---|
15 | |
---|
16 | function ldapRebind($ldap_connection, $ldap_url) |
---|
17 | { |
---|
18 | @ldap_bind($ldap_connection, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); |
---|
19 | } |
---|
20 | |
---|
21 | class ldap_functions |
---|
22 | { |
---|
23 | var $ds; |
---|
24 | var $ldap_host; |
---|
25 | var $ldap_context; |
---|
26 | var $imap; |
---|
27 | var $external_srcs; |
---|
28 | var $max_result; |
---|
29 | var $functions; |
---|
30 | var $ldapService; |
---|
31 | |
---|
32 | function ldap_functions(){ |
---|
33 | // todo: Page Configuration for External Catalogs. |
---|
34 | @include("../contactcenter/setup/external_catalogs.inc.php"); |
---|
35 | $this->ldapService = ServiceLocator::getService('ldap'); |
---|
36 | if(isset($external_srcs)) |
---|
37 | $this->external_srcs = $external_srcs; |
---|
38 | $this->max_result = $this->ldapService->limit; |
---|
39 | $this->functions = new functions(); |
---|
40 | } |
---|
41 | // Using ContactCenter configuration. |
---|
42 | function ldapConnect($refer = false,$catalog = 0){ |
---|
43 | if ($catalog > 0 && is_array($this->external_srcs)){ |
---|
44 | $this->ldap_host = $this->external_srcs[$catalog]['host']; |
---|
45 | $this->ldap_context = $this->external_srcs[$catalog]['dn']; |
---|
46 | $this->bind_dn = $this->external_srcs[$catalog]['acc']; |
---|
47 | $this->bind_dn_pw = $this->external_srcs[$catalog]['pw']; |
---|
48 | $this->object_class = $this->external_srcs[$catalog]['obj']; |
---|
49 | $this->base_dn = $this->external_srcs[$catalog]['dn']; |
---|
50 | $this->branch = $this->external_srcs[$catalog]['branch']; |
---|
51 | }else { |
---|
52 | $this->ldap_host = $_SESSION['phpgw_info']['expressomail']['ldap_server']['host']; |
---|
53 | $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; |
---|
54 | $this->bind_dn = $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc']; |
---|
55 | $this->bind_dn_pw = $_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']; |
---|
56 | $this->branch = 'ou'; |
---|
57 | } |
---|
58 | |
---|
59 | $this->ds = ldap_connect($this->ldap_host); |
---|
60 | ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
61 | ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer); |
---|
62 | if ($refer) { |
---|
63 | ldap_set_rebind_proc($this->ds, ldapRebind); |
---|
64 | } |
---|
65 | @ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw ); |
---|
66 | } |
---|
67 | |
---|
68 | //Teste jakjr retornando o DS |
---|
69 | function ldapConnect2($refer = false){ |
---|
70 | $ds = ldap_connect($_SESSION['phpgw_info']['expressomail']['ldap_server']['host']); |
---|
71 | |
---|
72 | if (!$ds) |
---|
73 | return false; |
---|
74 | |
---|
75 | ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
76 | ldap_set_option($ds, LDAP_OPT_REFERRALS, $refer); |
---|
77 | if ($refer) |
---|
78 | ldap_set_rebind_proc($ds, 'rebind'); |
---|
79 | @ldap_bind($ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); |
---|
80 | |
---|
81 | return $ds; |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | // usa o host e context do setup. |
---|
86 | function ldapRootConnect($refer = false){ |
---|
87 | $this->ldap_host = $_SESSION['phpgw_info']['expressomail']['server']['ldap_host']; |
---|
88 | $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context']; |
---|
89 | |
---|
90 | if($_SESSION['phpgw_info']['expressomail']['server']['ldap_master_host'] && |
---|
91 | $_SESSION['phpgw_info']['expressomail']['server']['ldap_master_root_dn'] && |
---|
92 | $_SESSION['phpgw_info']['expressomail']['server']['ldap_master_root_pw']) { |
---|
93 | $this->ds = ldap_connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_master_host']); |
---|
94 | ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
95 | ldap_set_option($this->ds, LDAP_OPT_REFERRALS,0); |
---|
96 | ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_master_root_dn'], $_SESSION['phpgw_info']['expressomail']['server']['ldap_master_root_pw']); |
---|
97 | }else{ |
---|
98 | $this->ds = ldap_connect($this->ldap_host); |
---|
99 | ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
100 | ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer); |
---|
101 | ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | function quicksearch($params) |
---|
106 | { |
---|
107 | include_once("class.functions.inc.php"); |
---|
108 | $functions = new functions; |
---|
109 | |
---|
110 | $field = $params['field']; |
---|
111 | $ID = $params['ID']; |
---|
112 | |
---|
113 | $ldapService = ServiceLocator::getService('ldap'); |
---|
114 | $filter = $ldapService->getSearchFilter($params['search_for']); |
---|
115 | |
---|
116 | $contacts_result = array(); |
---|
117 | $contacts_result['field'] = $field; |
---|
118 | $contacts_result['ID'] = $ID; |
---|
119 | $search_for = utf8_encode($params['search_for']); |
---|
120 | |
---|
121 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info']) |
---|
122 | $extendedinfo=true; |
---|
123 | else |
---|
124 | $extendedinfo=false; |
---|
125 | |
---|
126 | // follow the referral |
---|
127 | $this->ldapConnect(true); |
---|
128 | |
---|
129 | if ($this->ds) |
---|
130 | { |
---|
131 | $ldapService->connection = $this->ds; |
---|
132 | if($extendedinfo) |
---|
133 | $justthese = array("cn", "mail", "telephonenumber", "uid","uidNumber", "mobile", "phpgwaccountvisible", "employeenumber", "ou"); |
---|
134 | else |
---|
135 | $justthese = array("cn", "mail", "telephoneNumber", "phpgwAccountVisible", "uidNumber","uid"); |
---|
136 | $types = false; |
---|
137 | |
---|
138 | if( $field == 'null' || $ID == 'null' ) |
---|
139 | { |
---|
140 | $justthese[] = "jpegphoto"; |
---|
141 | $types = 'u'; |
---|
142 | } |
---|
143 | |
---|
144 | $filter = $ldapService->getSearchFilter( $params['search_for'], $types ); |
---|
145 | |
---|
146 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result); |
---|
147 | |
---|
148 | if(!$sr) |
---|
149 | return null; |
---|
150 | |
---|
151 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
152 | |
---|
153 | $info = ldap_get_entries($this->ds, $sr); |
---|
154 | |
---|
155 | // New search only on user sector |
---|
156 | if ($count_entries == $this->max_result) |
---|
157 | { |
---|
158 | $overload = $count_entries; |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | $catalogsNum=count($this->external_srcs); |
---|
163 | for ($i=0; $i<=$catalogsNum; $i++) { |
---|
164 | if ($this->external_srcs[$i]["quicksearch"]) { |
---|
165 | $this->ldapConnect(true,$i); |
---|
166 | $filter="(|(cn=*$search_for*)(mail=*$search_for*))"; |
---|
167 | if($extendedinfo) |
---|
168 | $justthese = array("cn", "mail", "telephonenumber", "uid","uidNumber", "mobile", "phpgwaccountvisible", "employeenumber", "ou"); |
---|
169 | else |
---|
170 | $justthese = array("cn", "mail", "telephoneNumber", "phpgwAccountVisible","uidNumber", "uid"); |
---|
171 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1); |
---|
172 | if(!$sr) |
---|
173 | return null; |
---|
174 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
175 | $search = ldap_get_entries($this->ds, $sr); |
---|
176 | for ($j=0; $j<$search["count"]; $j++) { |
---|
177 | $info[] = $search[$j]; |
---|
178 | } |
---|
179 | $info["count"] = count($info)-1; |
---|
180 | } |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | $tmp = array(); |
---|
185 | $tmp_users_from_user_org = array(); |
---|
186 | |
---|
187 | for ($i=0; $i<$info["count"]; $i++) |
---|
188 | { |
---|
189 | $key = $info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]; |
---|
190 | |
---|
191 | if (/*(!$quickSearch_only_in_userSector) &&*/ preg_match("/$user_sector_dn/i", $info[$i]['dn'])) |
---|
192 | { |
---|
193 | $tmp_users_from_user_org[$key] = utf8_decode($info[$i]["cn"][0]); |
---|
194 | continue; |
---|
195 | } |
---|
196 | |
---|
197 | $tmp[$key] = utf8_decode($info[$i]["cn"][0]); |
---|
198 | } |
---|
199 | |
---|
200 | natcasesort($tmp_users_from_user_org); |
---|
201 | natcasesort($tmp); |
---|
202 | |
---|
203 | if (($field != 'null') && ($ID != 'null')) |
---|
204 | { |
---|
205 | $i = 0; |
---|
206 | |
---|
207 | $tmp = array_merge($tmp, $tmp_users_from_user_org); |
---|
208 | natcasesort($tmp); |
---|
209 | |
---|
210 | foreach ($tmp as $info => $cn) |
---|
211 | { |
---|
212 | $contacts_result[$i] = array(); |
---|
213 | $contacts_result[$i]["cn"] = $cn; |
---|
214 | list ($contacts_result[$i]["mail"], $contacts_result[$i]["phone"], $contacts_result[$i]["mobile"], $contacts_result[$i]["uid"], $contacts_result[$i]["jpegphoto"], $contacts_result[$i]["employeenumber"], $contacts_result[$i]["ou"]) = split ('%', $info); |
---|
215 | $i++; |
---|
216 | } |
---|
217 | $contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector; |
---|
218 | $contacts_result['maxResult'] = $ldapService->limit; |
---|
219 | } |
---|
220 | else |
---|
221 | { |
---|
222 | $options_users_from_user_org = ''; |
---|
223 | $options = ''; |
---|
224 | |
---|
225 | |
---|
226 | $i = 0; |
---|
227 | foreach ($tmp_users_from_user_org as $info => $cn) |
---|
228 | { |
---|
229 | $contacts_result[$i] = array(); |
---|
230 | $options_users_from_user_org .= $this->make_quicksearch_card($info, $cn); |
---|
231 | $i++; |
---|
232 | } |
---|
233 | |
---|
234 | |
---|
235 | foreach ($tmp as $info => $cn) |
---|
236 | { |
---|
237 | $contacts_result[$i] = array(); |
---|
238 | $options .= $this->make_quicksearch_card($info, $cn); |
---|
239 | $i++; |
---|
240 | } |
---|
241 | |
---|
242 | |
---|
243 | if (($options_users_from_user_org != '') && ($options != '')) |
---|
244 | { |
---|
245 | $head_option0 = |
---|
246 | '<tr class="quicksearchcontacts_unselected">' . |
---|
247 | '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' . |
---|
248 | $this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']'; |
---|
249 | '</td>' . |
---|
250 | '</tr>'; |
---|
251 | |
---|
252 | $head_option1 = |
---|
253 | '<tr class="quicksearchcontacts_unselected">' . |
---|
254 | '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' . |
---|
255 | $this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']'; |
---|
256 | '</td>' . |
---|
257 | '</tr>'; |
---|
258 | } |
---|
259 | |
---|
260 | $head_option = ''; |
---|
261 | |
---|
262 | if( $overload ) |
---|
263 | $head_option = '<tr class="quicksearchcontacts_unselected">' . |
---|
264 | '<td colspan="2" width="100%" align="center" style="background:#EEEEEE; color: red;"><B>' .str_replace('%1', $this->max_result, $this->functions->getLang('More than %1 results. Please, try to refine your search.')) . '</B> '. |
---|
265 | '</td>' . |
---|
266 | '</tr>'; |
---|
267 | |
---|
268 | $contacts_result = $head_option.$head_option0 . $options_users_from_user_org . $head_option1. $options; |
---|
269 | |
---|
270 | } |
---|
271 | } |
---|
272 | |
---|
273 | ldap_close($this->ds); |
---|
274 | |
---|
275 | return $contacts_result; |
---|
276 | } |
---|
277 | |
---|
278 | |
---|
279 | /** |
---|
280 | * Método que faz o roteamento entre os métodos de busca (Catálogo pessoal, global e todos) |
---|
281 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
282 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
283 | * @sponsor Caixa Econômica Federal |
---|
284 | * @author Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br> |
---|
285 | * @param <array> <$param> <parametros vindos do cliente> |
---|
286 | */ |
---|
287 | function quicksearchcontact($params) |
---|
288 | { |
---|
289 | if(array_key_exists('Type', $params)){ |
---|
290 | return $this->quickSearch($params); |
---|
291 | } |
---|
292 | |
---|
293 | $modal = false; |
---|
294 | if($params['catalog']) |
---|
295 | $modal = true; |
---|
296 | |
---|
297 | include_once dirname(__FILE__). '/../../header.inc.php'; |
---|
298 | |
---|
299 | if($modal) |
---|
300 | { |
---|
301 | if($params['catalog'] == "global") |
---|
302 | { |
---|
303 | return $this->quickSearchGlobal($params); |
---|
304 | } |
---|
305 | else |
---|
306 | { |
---|
307 | if($params['catalog'] == "personal") |
---|
308 | return $this->quickSearchPersonal($params); |
---|
309 | else |
---|
310 | return $this->quickSearchAll($params); |
---|
311 | } |
---|
312 | } |
---|
313 | else |
---|
314 | { |
---|
315 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['catalog_search'] == "global") |
---|
316 | { |
---|
317 | return $this->quickSearchGlobal($params); |
---|
318 | } |
---|
319 | else |
---|
320 | { |
---|
321 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['catalog_search'] == "personal") |
---|
322 | return $this->quickSearchPersonal($params); |
---|
323 | else |
---|
324 | //Veirifica se quem chamou foi o campo de pesquisa rápida Expresso_Mail |
---|
325 | if(($params['field'] == 'null') && ($params['ID'] == 'null')) |
---|
326 | return $this->quickSearch($params); |
---|
327 | else |
---|
328 | return $this->quickSearchAll($params); |
---|
329 | } |
---|
330 | } |
---|
331 | } |
---|
332 | |
---|
333 | |
---|
334 | |
---|
335 | /** |
---|
336 | * Método que faz a busca de usuários em todos os catálogos |
---|
337 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
338 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
339 | * @sponsor Caixa Econômica Federal |
---|
340 | * @author Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br> |
---|
341 | * @param <array> <$param> <parametros vindos do cliente> |
---|
342 | * @return <array> <$retorno> <Array com os usuários de todos os catálogos, de acordo com o parâmetro> |
---|
343 | */ |
---|
344 | function quickSearchAll($params) |
---|
345 | { |
---|
346 | |
---|
347 | $retorno_personal = $this->quickSearchPersonal($params); |
---|
348 | $retorno_global = $this->quickSearchGlobal($params); |
---|
349 | //$retorno = $retorno_personal + $retorno_global; |
---|
350 | $retorno = array_merge($retorno_personal, $retorno_global); |
---|
351 | |
---|
352 | $retorno['type_catalog'] = "A"; |
---|
353 | $retorno['search_for'] = $params['search_for']; |
---|
354 | return $retorno; |
---|
355 | } |
---|
356 | |
---|
357 | |
---|
358 | /** |
---|
359 | * Método que faz a busca de usuários no Catálogo Pessoal |
---|
360 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
361 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
362 | * @sponsor Caixa Econômica Federal |
---|
363 | * @author Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br> |
---|
364 | * @param <array> <$param> <parametros vindos do cliente> |
---|
365 | * @return <array> <$retorno> <Array com os usuários do Catálogo Pessoal, de acordo com o parâmetro> |
---|
366 | */ |
---|
367 | function quickSearchPersonal($params, $all=false) |
---|
368 | { |
---|
369 | $results = array(); |
---|
370 | $DBService = ServiceLocator::getService('db'); |
---|
371 | $results = $DBService->search_contacts($params['search_for']); |
---|
372 | $results2 = array(); |
---|
373 | $results2 = $DBService->search_groups($params['search_for']); |
---|
374 | |
---|
375 | if(is_array($results)){ |
---|
376 | if(is_array($results2)){ |
---|
377 | $results = array_merge($results, $results2); |
---|
378 | } |
---|
379 | } |
---|
380 | else if(is_array($results2)){ |
---|
381 | $results = $results2; |
---|
382 | } |
---|
383 | |
---|
384 | if(!$all) |
---|
385 | $results['type_catalog'] = "P"; |
---|
386 | |
---|
387 | foreach($results as $i=>$value) |
---|
388 | $results[$i]['type_contact'] = "P"; |
---|
389 | |
---|
390 | $results['search_for'] = $params['search_for']; |
---|
391 | |
---|
392 | return $results; |
---|
393 | } |
---|
394 | |
---|
395 | |
---|
396 | /** |
---|
397 | * Método que faz a busca de usuários no Catálogo Geral |
---|
398 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
399 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
400 | * @sponsor Caixa Econômica Federal |
---|
401 | * @author Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br> |
---|
402 | * @param <array> <$param> <parametros vindos do cliente> |
---|
403 | * @return <array> <$retorno> <Array com os usuários do Catálogo Global, de acordo com o parâmetro> |
---|
404 | */ |
---|
405 | function quickSearchGlobal($params, $all=false) |
---|
406 | { |
---|
407 | include_once dirname(__FILE__). '/../../header.inc.php'; |
---|
408 | $c = CreateObject('phpgwapi.config','contactcenter'); |
---|
409 | $all_data = $c->read_repository(); |
---|
410 | |
---|
411 | $searchable_fields = array(); |
---|
412 | foreach($all_data as $index => $value) |
---|
413 | { |
---|
414 | $parts = explode('_', $index); |
---|
415 | if (is_numeric($parts[3]) && $parts[1]=='attribute') |
---|
416 | { |
---|
417 | if($parts[2] == 'searchable' /*&& $value == 'true'*/) |
---|
418 | $searchable_fields[$all_data['cc_attribute_ldapname_' . $parts[3]]] = $all_data['cc_attribute_name_' . $parts[3]]; |
---|
419 | } |
---|
420 | } |
---|
421 | include_once("class.functions.inc.php"); |
---|
422 | $functions = new functions; |
---|
423 | $field = $params['field']; |
---|
424 | $ID = $params['ID']; |
---|
425 | $ldapService = ServiceLocator::getService('ldap'); |
---|
426 | $filter = $ldapService->getSearchFilter($params['search_for']); |
---|
427 | |
---|
428 | $contacts_result = array(); |
---|
429 | $contacts_result['field'] = $field; |
---|
430 | $contacts_result['ID'] = $ID; |
---|
431 | $search_for = utf8_encode($params['search_for']); |
---|
432 | |
---|
433 | $this->ldapConnect(true); |
---|
434 | if ($this->ds) |
---|
435 | { |
---|
436 | $ldapService->connection = $this->ds; |
---|
437 | $campos_extras = ''; |
---|
438 | $justthese = array("cn", "mail", "telephonenumber", "mobile", "phpgwaccountvisible", "uid", "employeenumber", "ou"); |
---|
439 | foreach($searchable_fields as $fields_ldap => $value_field) |
---|
440 | { |
---|
441 | $campos_extras .= $fields_ldap . "|" . $value_field . "#"; |
---|
442 | array_push($justthese, $fields_ldap); |
---|
443 | } |
---|
444 | $types = false; |
---|
445 | |
---|
446 | $campos_extras = substr($campos_extras,0,-1); |
---|
447 | |
---|
448 | if($field == 'null' || $ID == 'null') |
---|
449 | { |
---|
450 | $justthese[] = "jpegphoto"; |
---|
451 | $types = 'u'; |
---|
452 | } |
---|
453 | $filter = $ldapService->getSearchFilter($params['search_for'], $types); |
---|
454 | // Retirei o this->max_result, que limitava a busca. Agora ta retornando tudo amigo. |
---|
455 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result); |
---|
456 | |
---|
457 | if(!$sr) |
---|
458 | return null; |
---|
459 | |
---|
460 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
461 | $info = ldap_get_entries($this->ds, $sr); |
---|
462 | $info_return = $info; |
---|
463 | //if($campos_extras != '') |
---|
464 | //array_push($info_return, $campos_extras); |
---|
465 | } |
---|
466 | ldap_close($this->ds); |
---|
467 | |
---|
468 | //Busca em Catalagos externos |
---|
469 | $catalogsNum=count($this->external_srcs); |
---|
470 | for ($i=0; $i<=$catalogsNum; $i++) { |
---|
471 | if ($this->external_srcs[$i]["quicksearch"]) |
---|
472 | { |
---|
473 | $this->ldapConnect(true,$i); |
---|
474 | $filter="(|(cn=*$search_for*)(mail=*$search_for*))"; |
---|
475 | $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou"); |
---|
476 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1); |
---|
477 | if(!$sr) |
---|
478 | return null; |
---|
479 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
480 | $search = ldap_get_entries($this->ds, $sr); |
---|
481 | for ($j=0; $j<$search["count"]; $j++) { |
---|
482 | $info_return[] = $search[$j]; |
---|
483 | } |
---|
484 | $info_return["count"] = count($info_return)-1; |
---|
485 | } |
---|
486 | } |
---|
487 | //---------------------------------------------------------------// |
---|
488 | |
---|
489 | if($all == false) |
---|
490 | $info_return['type_catalog'] = "G"; |
---|
491 | |
---|
492 | $info_return['extra_ldap_fields'] = $campos_extras; |
---|
493 | |
---|
494 | foreach($info_return as $i=>$value) |
---|
495 | $info_return[$i]['type_contact'] = "G"; |
---|
496 | |
---|
497 | $info_return['search_for'] = $params['search_for']; |
---|
498 | return $info_return; |
---|
499 | } |
---|
500 | |
---|
501 | function make_quicksearch_card($info, $cn) |
---|
502 | { |
---|
503 | include_once("class.functions.inc.php"); |
---|
504 | $functions = new functions; |
---|
505 | |
---|
506 | $contacts_result = array(); |
---|
507 | $contacts_result["cn"] = $cn; |
---|
508 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info']) |
---|
509 | $extendedinfo=true; |
---|
510 | else |
---|
511 | $extendedinfo=false; |
---|
512 | |
---|
513 | list ($contacts_result["mail"], $contacts_result["phone"], $contacts_result["mobile"], $contacts_result["uid"], $contacts_result["jpegphoto"], $contacts_result["employeenumber"], $contacts_result["ou"]) = split ('%', $info); |
---|
514 | |
---|
515 | if ($contacts_result['jpegphoto']) |
---|
516 | $photo_link = '<img src="./inc/show_user_photo.php?mail='.$contacts_result['mail'].'">'; |
---|
517 | else |
---|
518 | $photo_link = '<img src="./templates/default/images/photo.jpg">'; |
---|
519 | |
---|
520 | $phoneUser = $contacts_result['phone']; |
---|
521 | |
---|
522 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['voip_enabled'] && $phoneUser) { |
---|
523 | $phoneUser = '<a title="'.$this->functions->getLang("Call to Comercial Number").'" href="#" onclick="InfoContact.connectVoip(\''.$phoneUser.'\',\'com\')">'.$phoneUser.'</a>'; |
---|
524 | if($contacts_result['mobile']){ |
---|
525 | $phoneUser .= ' / <a title="'.$this->functions->getLang("Call to Mobile Number").'" href="#" onclick="InfoContact.connectVoip(\''.$contacts_result['mobile'].'\',\'mob\')">'.$contacts_result['mobile'].'</a>'; |
---|
526 | } |
---|
527 | } |
---|
528 | //verifica de existe o celular do funcionario ($contacts_result["mobile"]), se nao, $phoneUser fica vazia; |
---|
529 | |
---|
530 | $mobileUser = $contacts_result["mobile"]; |
---|
531 | if($mobileUser && !$voipMobile) { |
---|
532 | $phoneUser .= " / $mobileUser"; |
---|
533 | } |
---|
534 | $empNumber = $contacts_result["employeenumber"]; |
---|
535 | $uid = $contacts_result["uid"]; |
---|
536 | if($empNumber) { |
---|
537 | $empNumber = "$empNumber - "; |
---|
538 | } |
---|
539 | else if($uid){ |
---|
540 | $uid = "$uid - "; |
---|
541 | } |
---|
542 | $ou = $contacts_result["ou"]; |
---|
543 | if($ou) { |
---|
544 | $ou = "<br/>$ou" ; |
---|
545 | } |
---|
546 | |
---|
547 | // Begin: nickname, firstname and lastname for QuickAdd. |
---|
548 | $fn = $contacts_result["cn"]; |
---|
549 | $array_name = explode(" ", $fn); |
---|
550 | if(count($array_name) > 1){ |
---|
551 | $fn = $array_name[0]; |
---|
552 | array_shift($array_name); |
---|
553 | $sn = implode(" ",$array_name); |
---|
554 | } |
---|
555 | // End: |
---|
556 | $option = |
---|
557 | '<tr class="quicksearchcontacts_unselected">' . |
---|
558 | '<td class="cc" width="1%">' . |
---|
559 | '<a title="'.$this->functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' . |
---|
560 | $photo_link . |
---|
561 | '</a>' . |
---|
562 | '</td>' . |
---|
563 | '<td class="cc">' . |
---|
564 | '<span name="cn">' . ($empNumber != "" ? $empNumber : $uid) . $contacts_result['cn'] . '</span>' . '<br>' . |
---|
565 | '<a title="'.$functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' . |
---|
566 | '<font color=blue>' . |
---|
567 | '<span name="mail">' . $contacts_result['mail'] . '</span></a></font>'. |
---|
568 | '<img src="templates/default/images/user_card.png" style="cursor: pointer;" title="'.$this->functions->getLang("Add Contact").'" onclick="javascript:connector.loadScript(\'ccQuickAdd\');ccQuickAddOne.showList(\''.$fn.','.$fn.','.$sn.','.$contacts_result["mail"].'\')">'. |
---|
569 | '<br>' . |
---|
570 | $phoneUser . |
---|
571 | $ou . |
---|
572 | '</td>' . |
---|
573 | '</tr>'; |
---|
574 | return $option; |
---|
575 | } |
---|
576 | |
---|
577 | function get_catalogs(){ |
---|
578 | $catalogs = array(); |
---|
579 | $catalogs[0] = $this->functions->getLang("Global Catalog"); |
---|
580 | if($this->external_srcs) |
---|
581 | foreach ($this->external_srcs as $key => $valor ){ |
---|
582 | $catalogs[$key] = $valor['name']; |
---|
583 | } |
---|
584 | return $catalogs; |
---|
585 | } |
---|
586 | function get_organizations($params){ |
---|
587 | $organizations = array(); |
---|
588 | $params['referral']?$referral = $params['referral']:$referral = false; |
---|
589 | $cat = $params['catalog']; |
---|
590 | |
---|
591 | $this->ldapConnect($referral,$cat); |
---|
592 | |
---|
593 | if($this->branch != '') { |
---|
594 | $filter="(&(".$this->branch."=*)(!(phpgwAccountVisible=-1)))"; |
---|
595 | $justthese = array("$this->branch"); |
---|
596 | $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); |
---|
597 | $info = ldap_get_entries($this->ds, $sr); |
---|
598 | |
---|
599 | if($info["count"] == 0) |
---|
600 | { |
---|
601 | $organizations[0]['ou'] = $this->ldap_context; |
---|
602 | } |
---|
603 | |
---|
604 | for ($i=0; $i<$info["count"]; $i++) |
---|
605 | $organizations[$i] = $info[$i]["ou"][0]; |
---|
606 | |
---|
607 | ldap_close($this->ds); |
---|
608 | sort($organizations); |
---|
609 | return $organizations; |
---|
610 | }else{ |
---|
611 | return null; |
---|
612 | } |
---|
613 | } |
---|
614 | function get_organizations2($params){ |
---|
615 | $organizations = array(); |
---|
616 | $referral = $params['referral']; |
---|
617 | $this->ldapRootConnect($referral); |
---|
618 | if ($this->ds) { |
---|
619 | $filter="(&(objectClass=organizationalUnit)(!(phpgwAccountVisible=-1)))"; |
---|
620 | $justthese = array("ou"); |
---|
621 | $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); |
---|
622 | $info = ldap_get_entries($this->ds, $sr); |
---|
623 | |
---|
624 | |
---|
625 | if($info["count"] == 0) |
---|
626 | { |
---|
627 | $organizations[0]['ou'] = $this->ldap_context; |
---|
628 | $organizations[0]['dn'] = $this->ldap_context; |
---|
629 | } |
---|
630 | else{ |
---|
631 | for ($i=0; $i<$info["count"]; $i++) |
---|
632 | { |
---|
633 | $organizations[$i]['ou'] = $info[$i]["ou"][0]; |
---|
634 | $organizations[$i]['dn'] = $info[$i]["dn"]; |
---|
635 | } |
---|
636 | } |
---|
637 | ldap_close($this->ds); |
---|
638 | sort($organizations); |
---|
639 | } |
---|
640 | return $organizations; |
---|
641 | } |
---|
642 | //Busca usuarios de um contexto e ja retorna as options do select - usado por template serpro; |
---|
643 | function search_users($params) |
---|
644 | { |
---|
645 | $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner']; |
---|
646 | $ldapService = ServiceLocator::getService('ldap'); |
---|
647 | $ldapService->connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_host'], |
---|
648 | $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'], |
---|
649 | $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); |
---|
650 | |
---|
651 | $groups = $ldapService->accountSearch($params['filter'], array("gidNumber","cn", 'uid'), $params['context'] , 'g', 'cn'); |
---|
652 | $users = $ldapService->accountSearch($params['filter'], array("uidNumber","cn", 'uid'), $params['context'] , 'u', 'cn'); |
---|
653 | $compartilhadas = $ldapService->accountSearch($params['filter'], array("uidNumber","cn",'uid'), $params['context'] , 's', 'cn'); |
---|
654 | |
---|
655 | |
---|
656 | $group_options = array(); |
---|
657 | $user_options = array(); |
---|
658 | $shared_options = array(); |
---|
659 | |
---|
660 | foreach($groups as $group) |
---|
661 | { |
---|
662 | $group_options[] = '"'.$group['gidnumber'].'U'.'":"'.$group['cn'].' ('.$group['uid'].')"'; |
---|
663 | } |
---|
664 | foreach($users as $user) |
---|
665 | { |
---|
666 | if($owner != $user['uidnumber']) |
---|
667 | $user_options[] = '"'.$user['uidnumber'].'U'.'":"'.$user['cn'].' ('.$user['uid'].')"'; |
---|
668 | } |
---|
669 | foreach($compartilhadas as $shared) |
---|
670 | { |
---|
671 | if($owner != $shared['uidnumber']) |
---|
672 | $shared_options[] = '"'.$shared['uidnumber'].'U'.'":"'.$shared['cn'].' ('.$shared['uid'].')"'; |
---|
673 | } |
---|
674 | |
---|
675 | $user_options = '{'.implode( ',', $user_options ).'}'; |
---|
676 | $group_options = '{'.implode( ',', $group_options ).'}'; |
---|
677 | $shared_options = '{'.implode( ',', $shared_options ).'}'; |
---|
678 | |
---|
679 | return '{"users":'.$user_options.',"groups":'.$group_options.',"shared":'. $shared_options .'}'; |
---|
680 | } |
---|
681 | |
---|
682 | function catalogsearch($params) |
---|
683 | { |
---|
684 | $ldapService = ServiceLocator::getService('ldap'); |
---|
685 | $filter = $ldapService->getSearchFilter($params['search_for'],array('u','l','s')); |
---|
686 | |
---|
687 | $catalog = $params['catalog']; |
---|
688 | $error = False; |
---|
689 | |
---|
690 | //if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info']) |
---|
691 | //$extendedinfo=true; |
---|
692 | //else |
---|
693 | //$extendedinfo=false; |
---|
694 | |
---|
695 | |
---|
696 | $this->ldapConnect(true,$catalog); |
---|
697 | |
---|
698 | $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context; |
---|
699 | |
---|
700 | if ($this->ds) { |
---|
701 | $justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou"); |
---|
702 | $sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $ldapService->limit+1); |
---|
703 | |
---|
704 | if(!$sr) |
---|
705 | return null; |
---|
706 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
707 | if ($count_entries > $ldapService->limit){ |
---|
708 | $info = null; |
---|
709 | $error = True; |
---|
710 | } |
---|
711 | else |
---|
712 | $info = ldap_get_entries($this->ds, $sr); |
---|
713 | |
---|
714 | ldap_close($this->ds); |
---|
715 | |
---|
716 | $u_tmp = array(); |
---|
717 | $g_tmp = array(); |
---|
718 | |
---|
719 | for ($i=0; $i<$info["count"]; $i++){ |
---|
720 | if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'U') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) |
---|
721 | //aqui eh feita a concatenacao do departamento ao cn; |
---|
722 | $u_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]). '%' . $info[$i]["ou"][0]; |
---|
723 | if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) |
---|
724 | $g_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]); |
---|
725 | } |
---|
726 | |
---|
727 | natcasesort($u_tmp); |
---|
728 | natcasesort($g_tmp); |
---|
729 | |
---|
730 | $i = 0; |
---|
731 | $users = array(); |
---|
732 | |
---|
733 | foreach ($u_tmp as $mail => $cn){ |
---|
734 | |
---|
735 | $tmp = explode("%", $cn); //explode o cn pelo caracter "%" e joga em $tmp; |
---|
736 | $name = $tmp[0]; //pega o primeiro item (cn) do vetor resultante do explode acima; |
---|
737 | $department = $tmp[1]; //pega o segundo item (ou) do vetor resultanto do explode acima; |
---|
738 | $users[$i++] = array("name" => $name, "email" => $mail, "department" => $department); |
---|
739 | |
---|
740 | } |
---|
741 | unset($u_tmp); |
---|
742 | |
---|
743 | $i = 0; |
---|
744 | $groups = array(); |
---|
745 | |
---|
746 | foreach ($g_tmp as $mail => $cn){ |
---|
747 | $groups[$i++] = array("name" => $cn, "email" => $mail); |
---|
748 | } |
---|
749 | unset($g_tmp); |
---|
750 | |
---|
751 | return array('users' => $users, 'groups' => $groups, 'error' => $error,'maxResult' => $ldapService->limit); |
---|
752 | }else |
---|
753 | return null; |
---|
754 | } |
---|
755 | |
---|
756 | function get_emails_ldap(){ |
---|
757 | |
---|
758 | $result['mail']= array(); |
---|
759 | $result['mailalter']= array(); |
---|
760 | $user = $_SESSION['phpgw_info']['expressomail']['user']['account_lid']; |
---|
761 | $this->ldapRootConnect(false); |
---|
762 | if ($this->ds) { |
---|
763 | $filter="uid=".$user; |
---|
764 | $justthese = array("mail","mailAlternateAddress"); |
---|
765 | $sr = ldap_search($this->ds,$this->ldap_context, $filter, $justthese); |
---|
766 | $ent = ldap_get_entries($this->ds, $sr); |
---|
767 | ldap_close($this->ds); |
---|
768 | |
---|
769 | for ($i=0; $i<$ent["count"]; $i++){ |
---|
770 | $result['mail'][] = $ent[$i]["mail"][0]; |
---|
771 | $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0]; |
---|
772 | } |
---|
773 | } |
---|
774 | return $result; |
---|
775 | } |
---|
776 | |
---|
777 | //Busca usuarios de um contexto e ja retorna as options do select; |
---|
778 | function get_available_users($params) |
---|
779 | { |
---|
780 | $this->ldapRootConnect(); |
---|
781 | //Monta lista de Grupos e Usuarios |
---|
782 | $users = Array(); |
---|
783 | $groups = Array(); |
---|
784 | $user_context= $params['context']; |
---|
785 | $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner']; |
---|
786 | |
---|
787 | if ($this->ds) |
---|
788 | { |
---|
789 | $justthese = array("gidNumber","cn"); |
---|
790 | if ($params['type'] == 'search') |
---|
791 | $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
792 | else |
---|
793 | $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
794 | $info = ldap_get_entries($this->ds, $sr); |
---|
795 | for ($i=0; $i<$info["count"]; $i++) |
---|
796 | $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name' => $uids=$info[$i]["cn"][0], 'type' => g); |
---|
797 | $justthese = array("phpgwaccountvisible","uidNumber","cn"); |
---|
798 | if ($params['type'] == 'search') |
---|
799 | $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
800 | else |
---|
801 | $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
802 | |
---|
803 | $info = ldap_get_entries($this->ds, $sr); |
---|
804 | for ($i=0; $i<$info["count"]; $i++) |
---|
805 | { |
---|
806 | if ($info[$i]["phpgwaccountvisible"][0] == '-1') |
---|
807 | continue; |
---|
808 | $users[$uids=$info[$i]["uidnumber"][0]] = Array('name' => $uids=$info[$i]["cn"][0], 'type' => u); |
---|
809 | } |
---|
810 | } |
---|
811 | ldap_close($this->ds); |
---|
812 | |
---|
813 | @asort($users); |
---|
814 | @reset($users); |
---|
815 | @asort($groups); |
---|
816 | @reset($groups); |
---|
817 | $user_options =''; |
---|
818 | $group_options =''; |
---|
819 | |
---|
820 | foreach($groups as $id => $user_array) { |
---|
821 | $newId = $id.'U'; |
---|
822 | $group_options .= '<option value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n"; |
---|
823 | } |
---|
824 | foreach($users as $id => $user_array) { |
---|
825 | if($owner != $id){ |
---|
826 | $newId = $id.'U'; |
---|
827 | $user_options .= '<option value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n"; |
---|
828 | } |
---|
829 | } |
---|
830 | return array("users" => $user_options, "groups" => $group_options); |
---|
831 | } |
---|
832 | |
---|
833 | //Busca usuarios de um contexto e ja retorna as options do select; |
---|
834 | function get_available_users2($params) |
---|
835 | { |
---|
836 | $ldapService = ServiceLocator::getService('ldap'); |
---|
837 | $ldapService->connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_host'], |
---|
838 | $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'], |
---|
839 | $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); |
---|
840 | |
---|
841 | $entries = $ldapService->accountSearch($params['sentence'], array('cn', 'uid'), $params['context'], 'u', 'cn'); |
---|
842 | |
---|
843 | $options = array(); |
---|
844 | |
---|
845 | foreach ($entries as $value) |
---|
846 | $options[] = '"'.$value['uid'].'"'.':'.'"'.$value['cn'].'"'; |
---|
847 | |
---|
848 | return "{".implode(',',$options)."}"; |
---|
849 | } |
---|
850 | |
---|
851 | function uid2cn($uid) |
---|
852 | { |
---|
853 | // do not follow the referral |
---|
854 | $this->ldapRootConnect(false); |
---|
855 | if ($this->ds) |
---|
856 | { |
---|
857 | $filter="(&(phpgwAccountType=u)(uid=$uid))"; |
---|
858 | $justthese = array("cn"); |
---|
859 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
860 | if(!$sr) |
---|
861 | return false; |
---|
862 | $info = ldap_get_entries($this->ds, $sr); |
---|
863 | return utf8_decode($info[0]["cn"][0]); |
---|
864 | } |
---|
865 | return false; |
---|
866 | } |
---|
867 | function uidnumber2uid($uidnumber) |
---|
868 | { |
---|
869 | // do not follow the referral |
---|
870 | $this->ldapRootConnect(false); |
---|
871 | if ($this->ds) |
---|
872 | { |
---|
873 | $filter="(&(phpgwAccountType=u)(uidnumber=$uidnumber))"; |
---|
874 | $justthese = array("uid"); |
---|
875 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
876 | if(!$sr) |
---|
877 | return false; |
---|
878 | $info = ldap_get_entries($this->ds, $sr); |
---|
879 | return $info[0]["uid"][0]; |
---|
880 | } |
---|
881 | return false; |
---|
882 | } |
---|
883 | function getSharedUsersFrom($params){ |
---|
884 | $filter = ''; |
---|
885 | //Added to save if must save sent messages in shared folder |
---|
886 | $acl_save_sent_in_shared = array(); |
---|
887 | |
---|
888 | if($params['uids']) { |
---|
889 | $uids = explode(";",$params['uids']); |
---|
890 | $this->imap = new imap_functions(); |
---|
891 | foreach($uids as $index => $uid){ |
---|
892 | |
---|
893 | $params = array(); |
---|
894 | //Added to save if user has create permission |
---|
895 | $acl_create_message = array(); |
---|
896 | $user_arr = array(); |
---|
897 | $user_arr['user'] = $uid; |
---|
898 | $user_arr['getShared'] = true; |
---|
899 | $acl = $this->imap->getaclfromuser( $user_arr ); |
---|
900 | |
---|
901 | if($acl[$uid] != 'false'){ |
---|
902 | if ( preg_match("/[pa]+.*[pa]+/",$acl[$uid])){ |
---|
903 | $filter .= "(uid=$uid)"; |
---|
904 | $acl_save_sent_in_shared[] =$uid; |
---|
905 | } |
---|
906 | } |
---|
907 | } |
---|
908 | } |
---|
909 | |
---|
910 | $this->ldapRootConnect(false); |
---|
911 | if ($this->ds) { |
---|
912 | $justthese = array("cn","mail","uid"); |
---|
913 | if($filter) { |
---|
914 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s))(|$filter))"; |
---|
915 | $sr = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
916 | ldap_sort($this->ds,$sr,"cn"); |
---|
917 | $info = ldap_get_entries($this->ds, $sr); |
---|
918 | $var = print_r($acl_save_sent_in_shared, true); |
---|
919 | for ($i = 0;$i < $info["count"]; $i++){ |
---|
920 | $info[$i]['cn'][0] = utf8_decode($info[$i]['cn'][0]); |
---|
921 | //verify if user has permission to save sent messages in a shared folder |
---|
922 | if ( in_array( $info[$i]['uid'][0],$acl_save_sent_in_shared) ){ |
---|
923 | $info[$i]['save_shared'][0] = 'y'; |
---|
924 | } else $info[$i]['save_shared'][0] = 'n'; |
---|
925 | } |
---|
926 | } |
---|
927 | |
---|
928 | $info['myname'] = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
929 | |
---|
930 | //Find institucional_account. |
---|
931 | $filter="(&(phpgwAccountType=i)(mailForwardingAddress=".$_SESSION['phpgw_info']['expressomail']['user']['email']."))"; |
---|
932 | $sr = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
933 | ## |
---|
934 | # @AUTHOR Rodrigo Souza dos Santos |
---|
935 | # @DATE 2008/09/17 |
---|
936 | # @BRIEF Changing to ensure that the variable session is always with due value. |
---|
937 | ## |
---|
938 | if(ldap_count_entries($this->ds,$sr)) |
---|
939 | { |
---|
940 | ldap_sort($this->ds,$sr,"cn"); |
---|
941 | $result = ldap_get_entries($this->ds, $sr); |
---|
942 | for ($j = 0;$j < $result["count"]; $j++){ |
---|
943 | $info[$i]['cn'][0] = utf8_decode($result[$j]['cn'][0]); |
---|
944 | $info[$i]['mail'][0] = $result[$j]['mail'][0]; |
---|
945 | $info[$i]['save_shared'][0] = 'n'; |
---|
946 | $info[$i++]['uid'][0] = $result[$j]['uid'][0]; |
---|
947 | } |
---|
948 | } |
---|
949 | |
---|
950 | $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] = $info; |
---|
951 | return $info; |
---|
952 | } |
---|
953 | } |
---|
954 | |
---|
955 | function getUserByEmail($params) |
---|
956 | { |
---|
957 | $expires = 60*60*24*30; /* 30 days */ |
---|
958 | header("Cache-Control: maxage=".$expires); |
---|
959 | header("Pragma: public"); |
---|
960 | header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); |
---|
961 | $filter="(&(phpgwAccountType=u)(mail=" . $params['email'] . "))"; |
---|
962 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; |
---|
963 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info']) |
---|
964 | $extendedinfo=true; |
---|
965 | else |
---|
966 | $extendedinfo=false; |
---|
967 | |
---|
968 | if($extendedinfo) |
---|
969 | $justthese = array("cn","uid","telephoneNumber","jpegPhoto","mobile","ou","employeeNumber"); |
---|
970 | else |
---|
971 | $justthese = array("cn","uid","telephoneNumber","jpegPhoto","mobile"); |
---|
972 | |
---|
973 | // Follow the referral |
---|
974 | $ds = $this->ldapConnect2(true); |
---|
975 | if ($ds) |
---|
976 | { |
---|
977 | $sr=@ldap_search($ds, $ldap_context, $filter, $justthese); |
---|
978 | |
---|
979 | if (!$sr) |
---|
980 | return null; |
---|
981 | |
---|
982 | $entry = ldap_first_entry($ds, $sr); |
---|
983 | |
---|
984 | if($entry) { |
---|
985 | $obj = array("cn" => utf8_decode(current(ldap_get_values($ds, $entry, "cn"))), |
---|
986 | "email" => $params['email'], |
---|
987 | "uid" => ldap_get_values($ds, $entry, "uid"), |
---|
988 | "type" => "global", |
---|
989 | "mobile" => @ldap_get_values($ds, $entry, "mobile"), |
---|
990 | "telefone" => @ldap_get_values($ds, $entry, "telephonenumber"), |
---|
991 | "ou" => @ldap_get_values($ds, $entry, "ou"), |
---|
992 | "employeeNumber" => @ldap_get_values($ds, $entry, "employeeNumber") |
---|
993 | ); |
---|
994 | |
---|
995 | $_SESSION['phpgw_info']['expressomail']['contact_photo'] = @ldap_get_values_len($ds, $entry, "jpegphoto"); |
---|
996 | ldap_close($ds); |
---|
997 | return $obj; |
---|
998 | } |
---|
999 | } |
---|
1000 | return null; |
---|
1001 | } |
---|
1002 | |
---|
1003 | function uid2uidnumber($uid) |
---|
1004 | { |
---|
1005 | // do not follow the referral |
---|
1006 | $this->ldapRootConnect(false); |
---|
1007 | if ($this->ds) |
---|
1008 | { |
---|
1009 | $filter="(&(phpgwAccountType=u)(uid=$uid))"; |
---|
1010 | $justthese = array("uidnumber"); |
---|
1011 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
1012 | if(!$sr) |
---|
1013 | return false; |
---|
1014 | $info = ldap_get_entries($this->ds, $sr); |
---|
1015 | return $info[0]["uidnumber"][0]; |
---|
1016 | } |
---|
1017 | return false; |
---|
1018 | } |
---|
1019 | |
---|
1020 | function get_user_groups($uid) |
---|
1021 | { |
---|
1022 | |
---|
1023 | $organizations = array(); |
---|
1024 | |
---|
1025 | $this->ldapRootConnect(); |
---|
1026 | |
---|
1027 | $justthese = array("gidnumber","cn"); |
---|
1028 | $filter="(&(phpgwAccountType=g)(memberuid=".$uid."))"; |
---|
1029 | |
---|
1030 | $search = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
1031 | |
---|
1032 | $result = array(); |
---|
1033 | $entries = ldap_get_entries($this->ds, $search); |
---|
1034 | |
---|
1035 | |
---|
1036 | for ($i=0; $i<$entries['count']; $i++) |
---|
1037 | { |
---|
1038 | $result[ $entries[$i]['gidnumber'][0] ] = $entries[$i]['cn'][0]; |
---|
1039 | } |
---|
1040 | |
---|
1041 | return $result; |
---|
1042 | } |
---|
1043 | |
---|
1044 | function getMailByUid($pUid) |
---|
1045 | { |
---|
1046 | // do not follow the referral |
---|
1047 | $this->ldapRootConnect(false); |
---|
1048 | if ($this->ds) |
---|
1049 | { |
---|
1050 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s)(phpgwAccountType=l))(uid=$pUid))"; |
---|
1051 | $justthese = array("mail"); |
---|
1052 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
1053 | if(!$sr) |
---|
1054 | return false; |
---|
1055 | $info = ldap_get_entries($this->ds, $sr); |
---|
1056 | |
---|
1057 | |
---|
1058 | return utf8_decode($info[0]["mail"][0]); |
---|
1059 | } |
---|
1060 | return false; |
---|
1061 | } |
---|
1062 | |
---|
1063 | function mail2uid($mail) |
---|
1064 | { |
---|
1065 | if(!$this-ds) |
---|
1066 | $this->ldapRootConnect(false); |
---|
1067 | |
---|
1068 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s)(phpgwAccountType=i)(phpgwAccountType=g))(mail=$mail))"; |
---|
1069 | $justthese = array("uid"); |
---|
1070 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
1071 | if(!$sr) |
---|
1072 | return false; |
---|
1073 | $info = ldap_get_entries($this->ds, $sr); |
---|
1074 | return $info[0]["uid"][0]; |
---|
1075 | } |
---|
1076 | |
---|
1077 | |
---|
1078 | /** |
---|
1079 | * Retorna as contas compartilhas |
---|
1080 | * @param string $toaddress emails |
---|
1081 | * @param string $ccaddress emails |
---|
1082 | * @param string $ccoaddress emails |
---|
1083 | * @param array $groups array com os grupos que o usuario pertence |
---|
1084 | * @return array |
---|
1085 | */ |
---|
1086 | function returnSharedsAccounts($toaddress,$ccaddress,$ccoaddress) |
---|
1087 | { |
---|
1088 | |
---|
1089 | $arrayAllAddres = array(); |
---|
1090 | $arrayAllAddres = array_merge($arrayAllAddres , explode(',',$toaddress)); |
---|
1091 | $arrayAllAddres = array_merge($arrayAllAddres, explode(',',$ccaddress)); |
---|
1092 | $arrayAllAddres = array_merge($arrayAllAddres, explode(',',$ccoaddress)); |
---|
1093 | |
---|
1094 | $mailsArray = array(); |
---|
1095 | |
---|
1096 | foreach ($arrayAllAddres as $toAddres) |
---|
1097 | { |
---|
1098 | |
---|
1099 | if(strchr($toAddres,'@') && strchr($toAddres,'<') && strchr($toAddres,'>')) |
---|
1100 | { |
---|
1101 | $alias = substr($toAddres, strpos($toAddres,'<'), strpos($toAddres,'>')); |
---|
1102 | $alias = str_replace('<','', str_replace('>','',$alias)); |
---|
1103 | array_push($mailsArray, $alias); |
---|
1104 | } |
---|
1105 | else if(strchr($toAddres,'@')) |
---|
1106 | { |
---|
1107 | array_push($mailsArray, $toAddres); |
---|
1108 | } |
---|
1109 | } |
---|
1110 | $arraySharedAccounts = array(); |
---|
1111 | |
---|
1112 | $conexao = $this->ldapConnect2(true); |
---|
1113 | |
---|
1114 | |
---|
1115 | $mailFilter = ''; |
---|
1116 | |
---|
1117 | foreach ($mailsArray as $mail) |
---|
1118 | $mailFilter .= '(|(mail='.$mail.')(mailAlternateAddress='.$mail.'))'; |
---|
1119 | |
---|
1120 | |
---|
1121 | $filter = '(&(phpgwAccountType=s)(|'.$mailFilter.') )'; |
---|
1122 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context']; |
---|
1123 | $justthese = array('cn','uid','mail'); |
---|
1124 | |
---|
1125 | if ($conexao) |
---|
1126 | { |
---|
1127 | $search = @ldap_search($conexao, $ldap_context, $filter, $justthese); |
---|
1128 | if($search) |
---|
1129 | { |
---|
1130 | $results = ldap_get_entries($conexao, $search); |
---|
1131 | |
---|
1132 | foreach ($results as $result) |
---|
1133 | { |
---|
1134 | if($result['mail'][0]) |
---|
1135 | array_push($arraySharedAccounts, $result['mail'][0]); |
---|
1136 | } |
---|
1137 | } |
---|
1138 | |
---|
1139 | } |
---|
1140 | |
---|
1141 | return $arraySharedAccounts; |
---|
1142 | } |
---|
1143 | /** |
---|
1144 | * Verifica se um email é uma conta compartilhada |
---|
1145 | * |
---|
1146 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
1147 | * @author Cons?rcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
1148 | * @author Cristiano Corrêa Schmidt |
---|
1149 | * @param String $mail Email a ser verificado |
---|
1150 | * @return bolean |
---|
1151 | * @access public |
---|
1152 | */ |
---|
1153 | function isSharedAccountByMail($mail) |
---|
1154 | { |
---|
1155 | $return = false; |
---|
1156 | $conexao = $this->ldapConnect2(true); |
---|
1157 | $filter = '(&(phpgwAccountType=s)(mail='.$mail.'))'; |
---|
1158 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context']; |
---|
1159 | $justthese = array('cn','uid','mail'); |
---|
1160 | if ($conexao) |
---|
1161 | { |
---|
1162 | $search = @ldap_search($conexao, $ldap_context, $filter, $justthese); |
---|
1163 | if(ldap_count_entries ($conexao , $search)) |
---|
1164 | $return = true; |
---|
1165 | } |
---|
1166 | |
---|
1167 | return $return; |
---|
1168 | } |
---|
1169 | |
---|
1170 | function save_telephoneNumber($params){ |
---|
1171 | $return = array(); |
---|
1172 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['blockpersonaldata']){ |
---|
1173 | $return['error'] = $this->functions->getLang("You can't modify your Commercial Telephone."); |
---|
1174 | return $return; |
---|
1175 | } |
---|
1176 | $old_telephone = 0; |
---|
1177 | $pattern = '/\([0-9]{2,3}\)[0-9]{4}-[0-9]{4}$/'; |
---|
1178 | if ((strlen($params['number']) != 0) && (!preg_match($pattern, $params['number']))) |
---|
1179 | { |
---|
1180 | $return['error'] = $this->functions->getLang('The format of telephone number is invalid'); |
---|
1181 | return $return; |
---|
1182 | } |
---|
1183 | if($params['number'] != $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number']) { |
---|
1184 | $old_telephone = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number']; |
---|
1185 | $this->ldapRootConnect(false); |
---|
1186 | if(strlen($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number']) == 0) { |
---|
1187 | $info['telephonenumber'] = $params['number']; |
---|
1188 | $result = @ldap_mod_add($this->ds, $_SESSION['phpgw_info']['expressomail']['user']['account_dn'], $info); |
---|
1189 | } |
---|
1190 | else { |
---|
1191 | $info['telephonenumber'] = $params['number']; |
---|
1192 | $result = @ldap_mod_replace($this->ds, $_SESSION['phpgw_info']['expressomail']['user']['account_dn'], $info); |
---|
1193 | } |
---|
1194 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'] = $info['telephonenumber']; |
---|
1195 | // Log updated telephone number by user action |
---|
1196 | include_once('class.db_functions.inc.php'); |
---|
1197 | $db_functions = new db_functions(); |
---|
1198 | $db_functions->write_log('modified user telephone',"User changed its own telephone number in preferences $old_telephone => ".$info['telephonenumber']); |
---|
1199 | unset($info['telephonenumber']); |
---|
1200 | } |
---|
1201 | return $return['ok'] = true; |
---|
1202 | } |
---|
1203 | } |
---|
1204 | ?> |
---|