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