[2] | 1 | <?php |
---|
| 2 | /***************************************************************************\ |
---|
| 3 | * eGroupWare - Contacts Center * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * Written by: * |
---|
| 6 | * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * |
---|
| 7 | * ------------------------------------------------------------------------- * |
---|
| 8 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 9 | * under the terms of the GNU General Public License as published by the * |
---|
| 10 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 11 | * option) any later version. * |
---|
| 12 | \***************************************************************************/ |
---|
| 13 | |
---|
| 14 | /* |
---|
| 15 | This class is responsible for manipulating the Global LDAP Contact Manager |
---|
| 16 | */ |
---|
| 17 | include_once('class.abo_catalog.inc.php'); |
---|
[400] | 18 | |
---|
[2] | 19 | class bo_global_ldap_catalog extends abo_catalog |
---|
| 20 | { |
---|
| 21 | var $ldap; |
---|
[400] | 22 | |
---|
[2] | 23 | var $src_info; |
---|
[400] | 24 | |
---|
[2] | 25 | var $trans_table; |
---|
[284] | 26 | // used to determine if a catalog is external |
---|
| 27 | var $external; |
---|
[2] | 28 | var $fields = array( |
---|
| 29 | 'id_contact' => true, |
---|
| 30 | 'status' => true, |
---|
| 31 | 'photo' => true, |
---|
| 32 | 'alias' => true, |
---|
| 33 | 'prefix' => true, |
---|
| 34 | 'given_names' => true, |
---|
| 35 | 'family_names' => true, |
---|
| 36 | 'account_type' => true, |
---|
| 37 | 'names_ordered' => true, |
---|
| 38 | 'suffix' => true, |
---|
| 39 | 'birthdate' => true, |
---|
| 40 | 'sex' => true, |
---|
| 41 | 'pgp_key' => true, |
---|
| 42 | 'notes' => true, |
---|
| 43 | 'companies' => true, |
---|
| 44 | 'relations' => true, |
---|
| 45 | 'addresses' => true, |
---|
| 46 | 'connections' => true |
---|
| 47 | ); |
---|
[400] | 48 | |
---|
[2] | 49 | /* |
---|
[400] | 50 | |
---|
[2] | 51 | @function global_ldap_catalog |
---|
| 52 | @abstract Constructor |
---|
| 53 | @author Raphael Derosso Pereira |
---|
[400] | 54 | @author Mário César Kolling (external catalogs) |
---|
[284] | 55 | |
---|
[2] | 56 | @param integer $id_source The ID of the LDAP source |
---|
[284] | 57 | @param string $context Ldap bind DN |
---|
| 58 | @param integer $external 0 = internal catalog, 1 = external catalog |
---|
[2] | 59 | */ |
---|
[284] | 60 | function bo_global_ldap_catalog ( $id_source, $context, $external = 0 ) |
---|
[2] | 61 | { |
---|
[284] | 62 | $this->external = $external; |
---|
[2] | 63 | if (!function_exists('ldap_search')) |
---|
| 64 | { |
---|
| 65 | exit('PHP LDAP support Unavailable!'); |
---|
| 66 | } |
---|
[400] | 67 | |
---|
[2] | 68 | $this->ldap = CreateObject('contactcenter.bo_ldap_manager'); |
---|
[400] | 69 | |
---|
[284] | 70 | if ($this->external) |
---|
| 71 | { |
---|
| 72 | $all_src = $this->ldap->get_external_ldap_sources(); |
---|
| 73 | } |
---|
| 74 | else |
---|
| 75 | { |
---|
| 76 | $all_src = $this->ldap->get_all_ldap_sources(); |
---|
| 77 | } |
---|
| 78 | |
---|
[2] | 79 | if (!$all_src[$id_source] or !$context) |
---|
| 80 | { |
---|
| 81 | exit('Unavailable LDAP source.'); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | $this->src_info = $all_src[$id_source]; |
---|
| 85 | $this->src_info['context'] = $context; |
---|
[284] | 86 | |
---|
| 87 | if ($this->external) |
---|
| 88 | { |
---|
| 89 | $this->trans_table = $this->ldap->get_external_ldap_fields_association($id_source); |
---|
| 90 | } |
---|
| 91 | else |
---|
[400] | 92 | { |
---|
[284] | 93 | $this->trans_table = $this->ldap->get_ldap_fields_association($id_source); |
---|
| 94 | } |
---|
[2] | 95 | } |
---|
[400] | 96 | |
---|
[2] | 97 | /* |
---|
[400] | 98 | |
---|
[2] | 99 | @function find |
---|
| 100 | @abstract Searches the LDAP directory for the specified fields with |
---|
| 101 | the specified rules and retuns an array containing all the DNs |
---|
| 102 | that matches the rules. |
---|
| 103 | @author Raphael Derosso Pereira |
---|
[400] | 104 | |
---|
[2] | 105 | @param array $what The fields to be taken |
---|
| 106 | @param array $rules The rules to be match. See class.abo_catalog.inc.php |
---|
| 107 | for reference |
---|
| 108 | @param array $other Other parameters: |
---|
| 109 | $return = array( |
---|
| 110 | 'limit' => (integer), |
---|
| 111 | 'offset' => (integer) [NOT IMPLEMENTED] |
---|
| 112 | ) |
---|
[400] | 113 | |
---|
[2] | 114 | */ |
---|
[3211] | 115 | function find($what, $rules=false, $other=false, $area=false, $recursive=false) |
---|
[2] | 116 | { |
---|
| 117 | $restric_fields = $this->get_restrictions_without_branch($rules); |
---|
[400] | 118 | |
---|
[2] | 119 | $trans_f = $this->translate_fields($what, $restric_fields); |
---|
[400] | 120 | |
---|
[2] | 121 | foreach($trans_f as $orig => $field_a) |
---|
| 122 | { |
---|
| 123 | foreach($field_a as $field) |
---|
| 124 | { |
---|
| 125 | $fields[] = $field; |
---|
| 126 | } |
---|
| 127 | } |
---|
[1598] | 128 | |
---|
[2] | 129 | $fields = array_unique($fields); |
---|
[1598] | 130 | |
---|
| 131 | //Testa se a busca foi realizada com aspas |
---|
| 132 | $rules_search = $rules[3]['value']; |
---|
| 133 | $rules_len = (strlen($rules_search)) -1; |
---|
| 134 | |
---|
| 135 | if((($rules_search{1}) == "\"") && (($rules_search{$rules_len -1}) == "\"")){ |
---|
| 136 | $rules_search = substr($rules_search,2,$rules_len-3); |
---|
| 137 | $filter = "(&(|(objectClass=phpgwAccount))(&(!(phpgwAccountVisible=-1)))(|(cn=* $rules_search *)(cn=$rules_search *)(cn=* $rules_search)))"; |
---|
| 138 | } |
---|
| 139 | else{ |
---|
| 140 | $filter = $this->process_restrictions($rules, $trans_f); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | if ($area) |
---|
| 144 | { |
---|
| 145 | $obj = CreateObject('phpgwapi.config','contactcenter'); |
---|
| 146 | $opts = $obj->read_repository(); |
---|
| 147 | $filter = substr($filter,0,-1) .'(' . $opts['cc_ldap_atrib'] . '=*' . $area . '*))'; |
---|
| 148 | $opts = null; |
---|
| 149 | $obj = null; |
---|
| 150 | } |
---|
| 151 | // Find objects where 'mail' attribute is not null. |
---|
[880] | 152 | $filter = "(&".$filter."(mail=*))"; |
---|
[1598] | 153 | |
---|
| 154 | if(strstr($this->src_info['context'], "ldap://")) { |
---|
| 155 | $refer_context = str_replace("??base","",preg_replace('!^(ldap://[^/]+)/(.*$)!', '\\2', $this->src_info['context'])); |
---|
| 156 | $host = preg_replace('!^(ldap://[^/]+)/.*$!', '\\1', $this->src_info['context']); |
---|
| 157 | $this->src_info['host'] = $host; |
---|
| 158 | } |
---|
| 159 | if($refer_context || "ou" === strtolower(substr($this->src_info['context'], 0, 2))) |
---|
| 160 | { |
---|
| 161 | $followReferral = false; |
---|
| 162 | } |
---|
| 163 | elseif(trim($rules[4]['value']) != "inetOrgPerson") |
---|
| 164 | { |
---|
| 165 | $followReferral = true; |
---|
| 166 | } |
---|
[285] | 167 | else |
---|
[400] | 168 | { |
---|
[2] | 169 | return false; |
---|
| 170 | } |
---|
[400] | 171 | |
---|
[3211] | 172 | $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], $followReferral); |
---|
| 173 | $result_r = $recursive ? ldap_search($ldap ,($refer_context ? $refer_context : $this->src_info['context']), $filter, $fields, 0, $this->src_info['max_results']) : |
---|
| 174 | ldap_list($ldap , ($refer_context ? $refer_context : $this->src_info['context']), $filter, $fields, 0, $this->src_info['max_results']); |
---|
[2] | 175 | |
---|
| 176 | if (!$result_r) |
---|
| 177 | { |
---|
| 178 | return false; |
---|
| 179 | } |
---|
[400] | 180 | |
---|
[2] | 181 | if ($other['order']) |
---|
| 182 | { |
---|
| 183 | $sort_f = array($other['order']); |
---|
| 184 | $ldap_sort_by = $this->translate_fields($sort_f, $restric_fields); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | if ($ldap_sort_by) |
---|
| 188 | { |
---|
| 189 | if (!ldap_sort($ldap, $result_r, $ldap_sort_by[$other['order']][0])) |
---|
| 190 | { |
---|
| 191 | return false; |
---|
| 192 | } |
---|
| 193 | } |
---|
[400] | 194 | |
---|
[2] | 195 | $result_u = ldap_get_entries($ldap, $result_r); |
---|
[3135] | 196 | // No entries found. |
---|
| 197 | if(!$result_u) |
---|
| 198 | return true; |
---|
[400] | 199 | |
---|
[2] | 200 | $i = 0; |
---|
| 201 | foreach ($result_u as $index => $result_p) |
---|
| 202 | { |
---|
[284] | 203 | if ($index === 'count' or $index === 'dn' or (!$this->external and $result_p['phpgwaccountvisible'][0] == '-1')) |
---|
[2] | 204 | { |
---|
| 205 | continue; |
---|
| 206 | } |
---|
[400] | 207 | |
---|
[2] | 208 | foreach ($trans_f as $orig => $trans) |
---|
| 209 | { |
---|
| 210 | $orig = substr($orig, strrpos($orig, '.')+1, strlen($orig)); |
---|
| 211 | foreach ($trans as $f) |
---|
| 212 | { |
---|
| 213 | if ($f === 'dn') |
---|
| 214 | { |
---|
| 215 | $return[$i][$orig] = $result_p['dn']; |
---|
| 216 | } |
---|
| 217 | else if ($result_p[$f][0]) |
---|
| 218 | { |
---|
| 219 | $return[$i][$orig] = $result_p[$f][0]; |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | $i++; |
---|
| 224 | } |
---|
[4369] | 225 | if($return) |
---|
| 226 | usort($return, array($this, "compareObjects")); |
---|
[2] | 227 | return $return; |
---|
| 228 | } |
---|
[884] | 229 | // Compare function for usort. |
---|
[1598] | 230 | function compareObjects($a, $b) { |
---|
[884] | 231 | return strnatcasecmp($a['names_ordered'], $b['names_ordered']); |
---|
| 232 | } |
---|
[400] | 233 | |
---|
[2] | 234 | /* |
---|
[400] | 235 | |
---|
[2] | 236 | @function translate_fields |
---|
| 237 | @abstract Return the LDAP objectClass fields that corresponds to the |
---|
| 238 | specified parameter fields |
---|
| 239 | @author Raphael Derosso Pereira |
---|
[400] | 240 | |
---|
[2] | 241 | @param array $fields The fields in the standard ContactCenter format |
---|
| 242 | @param array $rules The rules |
---|
[400] | 243 | |
---|
[2] | 244 | */ |
---|
| 245 | function translate_fields ( $fields, &$restric_fields ) |
---|
| 246 | { |
---|
| 247 | $return = array(); |
---|
[400] | 248 | |
---|
[2] | 249 | $i = 0; |
---|
| 250 | foreach ($fields as $field) |
---|
| 251 | { |
---|
| 252 | if (!array_key_exists($field,$this->trans_table) or !$this->trans_table[$field]) |
---|
| 253 | { |
---|
| 254 | continue; |
---|
| 255 | } |
---|
[400] | 256 | |
---|
[2] | 257 | if (!is_array($this->trans_table[$field])) |
---|
| 258 | { |
---|
| 259 | $reference = $this->trans_table[$field]; |
---|
[400] | 260 | |
---|
[2] | 261 | reset($restric_fields); |
---|
| 262 | while(list(,$field_r) = each($restric_fields)) |
---|
| 263 | { |
---|
| 264 | if ($field_r['field'] === $reference and array_key_exists($field_r['value'], $this->trans_table[$reference])) |
---|
| 265 | { |
---|
| 266 | array_push($return[$field], $this->trans_table[$reference][$field_r['value']]); |
---|
| 267 | } |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | else |
---|
| 271 | { |
---|
| 272 | if (!is_array($return[$field])) |
---|
| 273 | { |
---|
| 274 | $return[$field] = $this->trans_table[$field]; |
---|
| 275 | } |
---|
| 276 | else |
---|
| 277 | { |
---|
| 278 | array_push($return[$field], $this->trans_table[$field]); |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | } |
---|
[400] | 282 | |
---|
[2] | 283 | if (count($return)) |
---|
| 284 | { |
---|
| 285 | return $return; |
---|
| 286 | } |
---|
[400] | 287 | |
---|
[2] | 288 | return false; |
---|
| 289 | } |
---|
[400] | 290 | |
---|
[2] | 291 | /* |
---|
[400] | 292 | |
---|
[2] | 293 | @function process_restrictions |
---|
| 294 | @abstract Returns a LDAP filter string that corresponds to the |
---|
| 295 | specified restriction rules |
---|
| 296 | @author Raphael Derosso Pereira |
---|
[400] | 297 | |
---|
[2] | 298 | @param string $rules The restriction rules |
---|
[400] | 299 | |
---|
[2] | 300 | */ |
---|
| 301 | function process_restrictions( $rules, &$trans_table, $join_type='&' ) |
---|
| 302 | { |
---|
| 303 | if (!is_array($rules) or !count($rules)) |
---|
| 304 | { |
---|
| 305 | return null; |
---|
| 306 | } |
---|
[400] | 307 | |
---|
[2] | 308 | foreach($rules as $rule_i => $rule) |
---|
| 309 | { |
---|
| 310 | $t = array(); |
---|
| 311 | switch($rule['type']) |
---|
| 312 | { |
---|
| 313 | case 'branch': |
---|
| 314 | switch(strtoupper($rule['value'])) |
---|
| 315 | { |
---|
| 316 | case 'OR': |
---|
| 317 | $join = '|'; |
---|
| 318 | break; |
---|
[400] | 319 | |
---|
[2] | 320 | case 'AND': |
---|
| 321 | $join = '&'; |
---|
| 322 | break; |
---|
[400] | 323 | |
---|
[2] | 324 | case 'NOT': |
---|
| 325 | $join = '!'; |
---|
| 326 | break; |
---|
[400] | 327 | |
---|
[2] | 328 | default: |
---|
| 329 | $join = $join_type; |
---|
| 330 | } |
---|
| 331 | $return_t[] = $this->process_restrictions($rule['sub_branch'], $trans_table, $join); |
---|
| 332 | break; |
---|
[400] | 333 | |
---|
[2] | 334 | case '=': |
---|
| 335 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 336 | { |
---|
| 337 | foreach($trans_table[$rule['field']] as $field) |
---|
| 338 | { |
---|
| 339 | $t[] = '('.$field.'='.$rule['value'].')'; |
---|
| 340 | } |
---|
| 341 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 342 | } |
---|
| 343 | break; |
---|
[400] | 344 | |
---|
| 345 | case '!=': |
---|
[2] | 346 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 347 | { |
---|
| 348 | foreach($trans_table[$rule['field']] as $field) |
---|
| 349 | { |
---|
| 350 | $t[] = '(!('.$field.'='.$rule['value'].'))'; |
---|
| 351 | } |
---|
| 352 | $return_t[] = '(&'.implode(' ',$t).')'; |
---|
| 353 | } |
---|
| 354 | break; |
---|
[400] | 355 | |
---|
[2] | 356 | case '<=': |
---|
| 357 | case '<': |
---|
| 358 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 359 | { |
---|
| 360 | foreach($trans_table[$rule['field']] as $field) |
---|
| 361 | { |
---|
| 362 | $t[] = '('.$field.'<='.$rule['value'].')'; |
---|
| 363 | } |
---|
| 364 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 365 | } |
---|
| 366 | break; |
---|
[400] | 367 | |
---|
[2] | 368 | case '>': |
---|
| 369 | case '>=': |
---|
| 370 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 371 | { |
---|
| 372 | foreach($trans_table[$rule['field']] as $field) |
---|
| 373 | { |
---|
| 374 | $t[] = '('.$field.'>='.$rule['value'].')'; |
---|
| 375 | } |
---|
| 376 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 377 | } |
---|
| 378 | break; |
---|
[400] | 379 | |
---|
[2] | 380 | case 'NULL': |
---|
| 381 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 382 | { |
---|
| 383 | foreach($trans_table[$rule['field']] as $field) |
---|
| 384 | { |
---|
| 385 | $t[] = '(!('.$field.'=*'.'))'; |
---|
| 386 | } |
---|
| 387 | $return_t[] = '(&'.implode(' ',$t).')'; |
---|
| 388 | } |
---|
| 389 | break; |
---|
[400] | 390 | |
---|
[2] | 391 | case 'IN': |
---|
| 392 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 393 | { |
---|
| 394 | foreach($trans_table[$rule['field']] as $field) |
---|
| 395 | { |
---|
| 396 | foreach($rule['value'] as $value) |
---|
| 397 | { |
---|
| 398 | $t[] = '('.$field.'='.$value.')'; |
---|
| 399 | } |
---|
| 400 | } |
---|
| 401 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 402 | } |
---|
| 403 | break; |
---|
| 404 | |
---|
| 405 | case 'iLIKE': |
---|
| 406 | /* if (array_key_exists($rule['field'], $trans_table)) |
---|
| 407 | { |
---|
| 408 | $value_1 = strtoupper(str_replace('%', '*', $rule['value'])); |
---|
| 409 | $value_2 = strtolower($value_1); |
---|
[400] | 410 | |
---|
[2] | 411 | foreach($trans_table[$rule['field']] as $field) |
---|
| 412 | { |
---|
| 413 | $t[] = '('.$field.'='.$value_1.')'; |
---|
| 414 | $t[] = '('.$field.'='.$value_2.')'; |
---|
| 415 | } |
---|
| 416 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 417 | } |
---|
| 418 | break; |
---|
[400] | 419 | |
---|
[2] | 420 | */ case 'LIKE': |
---|
| 421 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 422 | { |
---|
| 423 | $value = str_replace('%', '*', $rule['value']); |
---|
[400] | 424 | |
---|
[2] | 425 | foreach($trans_table[$rule['field']] as $field) |
---|
| 426 | { |
---|
| 427 | $t[] = '('.$field.'='.$value.')'; |
---|
| 428 | } |
---|
| 429 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 430 | } |
---|
| 431 | break; |
---|
[400] | 432 | |
---|
[2] | 433 | case 'NOT NULL': |
---|
| 434 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 435 | { |
---|
| 436 | foreach($trans_table[$rule['field']] as $field) |
---|
| 437 | { |
---|
| 438 | $t[] = '('.$field.'=*'.')'; |
---|
| 439 | } |
---|
| 440 | $return_t[] = '(|'.implode(' ',$t).')'; |
---|
| 441 | } |
---|
| 442 | break; |
---|
[400] | 443 | |
---|
[2] | 444 | case 'NOT IN': |
---|
| 445 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 446 | { |
---|
| 447 | foreach($trans_table[$rule['field']] as $field) |
---|
| 448 | { |
---|
| 449 | foreach($rule['value'] as $value) |
---|
| 450 | { |
---|
| 451 | $t[] = '('.$field.'='.$value.')'; |
---|
| 452 | } |
---|
| 453 | } |
---|
| 454 | $return_t[] = '(!(|'.implode('',$t).'))'; |
---|
| 455 | } |
---|
| 456 | break; |
---|
| 457 | |
---|
| 458 | case 'NOT iLIKE': |
---|
| 459 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 460 | { |
---|
| 461 | $value_1 = strtoupper(str_replace('%', '*', $rule['value'])); |
---|
| 462 | $value_2 = strtolower($value_1); |
---|
[400] | 463 | |
---|
[2] | 464 | foreach($trans_table[$rule['field']] as $field) |
---|
| 465 | { |
---|
| 466 | $t[] = '('.$field.'='.$value_1.')'; |
---|
| 467 | $t[] = '('.$field.'='.$value_2.')'; |
---|
| 468 | } |
---|
| 469 | $return_t[] = '(!(|'.implode(' ',$t).'))'; |
---|
| 470 | } |
---|
| 471 | break; |
---|
| 472 | |
---|
| 473 | case 'NOT LIKE': |
---|
| 474 | if (array_key_exists($rule['field'], $trans_table)) |
---|
| 475 | { |
---|
| 476 | $value = str_replace('%', '*', $rule['value']); |
---|
[400] | 477 | |
---|
[2] | 478 | foreach($trans_table[$rule['field']] as $field) |
---|
| 479 | { |
---|
| 480 | $t[] = '('.$field.'='.$value.')'; |
---|
| 481 | } |
---|
| 482 | $return_t[] = '(!(|'.implode(' ',$t).'))'; |
---|
| 483 | } |
---|
| 484 | break; |
---|
| 485 | } |
---|
| 486 | } |
---|
[400] | 487 | |
---|
[2] | 488 | if (count($return_t)) |
---|
| 489 | { |
---|
| 490 | $return = '('.$join_type; |
---|
| 491 | foreach ($return_t as $return_p) |
---|
| 492 | { |
---|
| 493 | $return .= $return_p; |
---|
| 494 | } |
---|
| 495 | $return .= ')'; |
---|
| 496 | } |
---|
| 497 | else |
---|
| 498 | { |
---|
| 499 | $return = null; |
---|
| 500 | } |
---|
| 501 | return $return; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | /*! |
---|
[400] | 505 | |
---|
[2] | 506 | @function get_restrictions_without_branch |
---|
| 507 | @abstract Returns an array containing the restrictions ignoring the |
---|
| 508 | branches |
---|
| 509 | @author Raphael Derosso Pereira |
---|
[400] | 510 | |
---|
[2] | 511 | @param array $restrictions The restrictions |
---|
[400] | 512 | |
---|
[2] | 513 | */ |
---|
| 514 | function get_restrictions_without_branch(&$restrictions) |
---|
| 515 | { |
---|
| 516 | if (!is_array($restrictions)) |
---|
| 517 | { |
---|
| 518 | return null; |
---|
| 519 | } |
---|
[400] | 520 | |
---|
[2] | 521 | $fields = array(); |
---|
[400] | 522 | |
---|
[2] | 523 | foreach ($restrictions as $restrict_data) |
---|
| 524 | { |
---|
| 525 | switch($restrict_data['type']) |
---|
| 526 | { |
---|
| 527 | case 'branch': |
---|
| 528 | $fields = array_merge($fields, $this->get_restrictions_without_branch($restrict_data['sub_branch'])); |
---|
| 529 | break; |
---|
[400] | 530 | |
---|
[2] | 531 | case '=': |
---|
[400] | 532 | case '!=': |
---|
[2] | 533 | case '<=': |
---|
| 534 | case '<': |
---|
| 535 | case '>': |
---|
| 536 | case '>=': |
---|
| 537 | case 'NULL': |
---|
| 538 | case 'IN': |
---|
| 539 | case 'LIKE': |
---|
| 540 | case 'iLIKE': |
---|
| 541 | case 'NOT NULL': |
---|
| 542 | case 'NOT IN': |
---|
| 543 | case 'NOT LIKE': |
---|
| 544 | case 'NOT iLIKE': |
---|
| 545 | array_push($fields, $restrict_data); |
---|
| 546 | break; |
---|
[400] | 547 | |
---|
[2] | 548 | default: |
---|
[400] | 549 | exit('Error in '.__FILE__.' on '.__LINE__.'<br>The restriction type passed was: '.$restrict_data['type']); |
---|
[2] | 550 | } |
---|
| 551 | } |
---|
[400] | 552 | |
---|
[2] | 553 | return $fields; |
---|
| 554 | } |
---|
[400] | 555 | |
---|
| 556 | |
---|
[2] | 557 | /*********************************************************************\ |
---|
| 558 | * Methods to Get Data * |
---|
| 559 | \*********************************************************************/ |
---|
[400] | 560 | |
---|
| 561 | |
---|
[2] | 562 | /*! |
---|
[400] | 563 | |
---|
[2] | 564 | @function get_single_entry |
---|
| 565 | @abstract Returns all information requested about one contact |
---|
| 566 | @author Raphael Derosso Pereira |
---|
[400] | 567 | |
---|
[2] | 568 | @param integer $id_contact The contact ID |
---|
| 569 | @param array $fields The array returned by get_fields with true |
---|
| 570 | on the fields to be taken. |
---|
[400] | 571 | |
---|
[2] | 572 | */ |
---|
[1419] | 573 | function get_single_entry ( $id_contact, $fields, $external=false ) |
---|
[2] | 574 | { |
---|
[400] | 575 | if (!is_array($fields)) |
---|
[2] | 576 | { |
---|
[400] | 577 | if (is_object($GLOBALS['phpgw']->log)) |
---|
[2] | 578 | { |
---|
| 579 | $GLOBALS['phpgw']->log->message(array( |
---|
| 580 | 'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.', |
---|
| 581 | 'line' => __LINE__, |
---|
| 582 | 'file' => __FILE__)); |
---|
[400] | 583 | |
---|
[2] | 584 | $GLOBALS['phpgw']->log->commit(); |
---|
| 585 | } |
---|
[400] | 586 | else |
---|
[2] | 587 | { |
---|
| 588 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 589 | } |
---|
| 590 | } |
---|
[400] | 591 | |
---|
[2] | 592 | $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'],$this->src_info['acc'],$this->src_info['pw'],true); |
---|
[400] | 593 | |
---|
[2] | 594 | if (!$ldap) |
---|
| 595 | { |
---|
| 596 | return false; |
---|
| 597 | } |
---|
[3262] | 598 | |
---|
| 599 | //Alteração feita especificamente para tratar problema da montagem do $id_contact |
---|
[1419] | 600 | if(!$external) |
---|
[3262] | 601 | { |
---|
| 602 | if($this->src_info['montaDN'] == "true") |
---|
| 603 | { |
---|
[1419] | 604 | $id_contact = preg_replace("/dc=(.*)/i",$this->src_info['dn'],$id_contact); |
---|
[3262] | 605 | } |
---|
| 606 | } |
---|
[1419] | 607 | |
---|
[314] | 608 | $resource = @ldap_read($ldap, $id_contact, 'objectClass='.$this->src_info['obj']); |
---|
| 609 | $n_entries = @ldap_count_entries($ldap, $resource); |
---|
[2] | 610 | if ( $n_entries > 1 or $n_entries < 1) |
---|
| 611 | { |
---|
| 612 | return false; |
---|
| 613 | } |
---|
[400] | 614 | |
---|
[2] | 615 | $first_entry = ldap_first_entry($ldap, $resource); |
---|
| 616 | $contact = ldap_get_attributes($ldap,$first_entry); |
---|
[400] | 617 | if($contact['jpegPhoto']){ |
---|
| 618 | $contact['jpegPhoto'] = ldap_get_values_len ($ldap, $first_entry, "jpegPhoto"); |
---|
[2] | 619 | } |
---|
| 620 | |
---|
[1598] | 621 | // print_r($contact); |
---|
[400] | 622 | |
---|
[2] | 623 | // $contact_data = $this->fields; |
---|
[400] | 624 | |
---|
[2] | 625 | foreach($fields as $field => $trueness) |
---|
| 626 | { |
---|
| 627 | if (!$trueness) |
---|
| 628 | { |
---|
| 629 | //unset($contact_data[$field]); |
---|
| 630 | continue; |
---|
| 631 | } |
---|
[400] | 632 | |
---|
[2] | 633 | switch ($field) |
---|
| 634 | { |
---|
| 635 | case 'companies': |
---|
| 636 | unset($l_fields); |
---|
| 637 | $l_fields['company_name'] = $this->trans_table['contact.company.company_name']; |
---|
| 638 | $l_fields['title'] = $this->trans_table['contact.business_info.title']; |
---|
[1598] | 639 | //$l_fields['department'] = $this->trans_table['contact.business_info.department']; |
---|
[2] | 640 | $l_fields['company_notes'] = $this->trans_table['contact.company.company_notes']; |
---|
[1598] | 641 | |
---|
| 642 | //Relaciona o array com o atributo 'ou' do RHDS; tambem verifica se a |
---|
| 643 | //preferencia esta configurada para exibir o campo |
---|
| 644 | if(isset($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['departmentShow']) && $_SESSION['phpgw_info']['user']['preferences']['contactcenter']['departmentShow']) |
---|
| 645 | { |
---|
| 646 | $l_fields['department'] = $this->trans_table['contact.business_info.department']; |
---|
| 647 | } |
---|
| 648 | //Relaciona o array com o atributo 'employeeNumber' do RHDS; tambem verifica se a |
---|
| 649 | //preferencia esta configurada para exibir o campo |
---|
| 650 | if(isset($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['empNumShow']) && $_SESSION['phpgw_info']['user']['preferences']['contactcenter']['empNumShow']) |
---|
| 651 | { |
---|
| 652 | $l_fields['empNumber'] = $this->trans_table['contact.business_info.empNumber']; |
---|
| 653 | } |
---|
| 654 | //Relaciona o array com o atributo 'mobile' do RHDS; tambem verifica se a |
---|
| 655 | //preferencia esta configurada para exibir o campo |
---|
| 656 | if(isset($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['cellShow']) && $_SESSION['phpgw_info']['user']['preferences']['contactcenter']['cellShow']) |
---|
| 657 | { |
---|
| 658 | $l_fields['celPhone'] = $this->trans_table['contact.business_info.celPhone']; |
---|
| 659 | } |
---|
| 660 | |
---|
[2] | 661 | $contact_data['companies'] = array(); |
---|
| 662 | foreach($l_fields as $l_field => $l_value) |
---|
| 663 | { |
---|
| 664 | if (!( $contact[$l_value[0]][0])) |
---|
| 665 | { |
---|
| 666 | continue; |
---|
| 667 | } |
---|
[400] | 668 | |
---|
[284] | 669 | $contact_data['companies']['company1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
[2] | 670 | } |
---|
[400] | 671 | |
---|
[2] | 672 | if (!(count($contact_data['companies']))) |
---|
| 673 | { |
---|
| 674 | unset($contact_data['companies']); |
---|
| 675 | } |
---|
| 676 | break; |
---|
[400] | 677 | |
---|
[2] | 678 | case 'relations': |
---|
| 679 | unset($l_fields); |
---|
| 680 | if (!$this->trans_table['contact.contact_related.names_ordered']) |
---|
| 681 | { |
---|
| 682 | unset($contact_data['relations']); |
---|
| 683 | } |
---|
[400] | 684 | |
---|
[2] | 685 | $contact_data['relations'] = array(); |
---|
| 686 | if (!is_array($this->trans_table['contact.contact_related.names_ordered'])) |
---|
| 687 | { |
---|
| 688 | if (!($trans = $this->trans_table[$this->trans_table['contact.contact_related.names_ordered']])) |
---|
| 689 | { |
---|
| 690 | continue; |
---|
| 691 | } |
---|
[400] | 692 | |
---|
[2] | 693 | $i = 1; |
---|
| 694 | foreach($trans as $l_type => $l_type_fields) |
---|
| 695 | { |
---|
| 696 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 697 | { |
---|
| 698 | continue; |
---|
| 699 | } |
---|
[400] | 700 | |
---|
[2] | 701 | $contact_data['relations']['relation'.$i]['type'] = $l_type; |
---|
[284] | 702 | $contact_data['relations']['relation'.$i]['names_ordered'] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
[2] | 703 | $i++; |
---|
| 704 | } |
---|
| 705 | } |
---|
[400] | 706 | |
---|
[2] | 707 | if (!(count($contact_data['relations']))) |
---|
| 708 | { |
---|
| 709 | unset($contact_data['relations']); |
---|
| 710 | } |
---|
| 711 | break; |
---|
[400] | 712 | |
---|
[2] | 713 | case 'addresses': |
---|
| 714 | unset($l_fields); |
---|
| 715 | $l_fields['address1'] = $this->trans_table['contact.address.address1']; |
---|
| 716 | $l_fields['address2'] = $this->trans_table['contact.address.address2']; |
---|
| 717 | $l_fields['complement'] = $this->trans_table['contact.address.complement']; |
---|
| 718 | $l_fields['address_other'] = $this->trans_table['contact.address.address_other']; |
---|
| 719 | $l_fields['postal_code'] = $this->trans_table['contact.address.postal_code']; |
---|
| 720 | $l_fields['po_box'] = $this->trans_table['contact.address.po_box']; |
---|
| 721 | $l_fields['id_city'] = $this->trans_table['contact.address.city.id_city']; |
---|
| 722 | $l_fields['city_name'] = $this->trans_table['contact.address.city.city_name']; |
---|
| 723 | $l_fields['city_timezone'] = $this->trans_table['contact.address.city.city_timezone']; |
---|
| 724 | $l_fields['city_geo_location'] = $this->trans_table['contact.address.city.city_geo_location']; |
---|
| 725 | $l_fields['id_state'] = $this->trans_table['contact.address.city.state.id_state']; |
---|
| 726 | $l_fields['state_name'] = $this->trans_table['contact.address.city.state.state_name']; |
---|
| 727 | $l_fields['state_symbol'] = $this->trans_table['contact.address.city.state.state_symbol']; |
---|
| 728 | $l_fields['id_country'] = $this->trans_table['contact.address.city.country.id_country']; |
---|
| 729 | $l_fields['country_name'] = $this->trans_table['contact.address.city.country.country_name']; |
---|
| 730 | $l_fields['address_is_default'] = $this->trans_table['contact.address.address_is_default']; |
---|
| 731 | |
---|
| 732 | $contact_data['addresses'] = array(); |
---|
| 733 | foreach($l_fields as $l_field => $l_value) |
---|
| 734 | { |
---|
| 735 | if (!is_array($l_value)) |
---|
| 736 | { |
---|
| 737 | if (!($trans = $this->trans_table[$l_value])) |
---|
| 738 | { |
---|
| 739 | continue; |
---|
| 740 | } |
---|
[400] | 741 | |
---|
[2] | 742 | $i = 1; |
---|
| 743 | foreach($trans as $l_type => $l_type_fields) |
---|
| 744 | { |
---|
| 745 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 746 | { |
---|
| 747 | continue; |
---|
| 748 | } |
---|
[400] | 749 | |
---|
[2] | 750 | $contact_data['addresses']['address'.$i]['type'] = $l_type; |
---|
[284] | 751 | $contact_data['addresses']['address'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
[2] | 752 | $i++; |
---|
| 753 | } |
---|
| 754 | } |
---|
| 755 | else |
---|
| 756 | { |
---|
[284] | 757 | $contact_data['addresses']['address1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
[2] | 758 | } |
---|
| 759 | } |
---|
[400] | 760 | |
---|
[2] | 761 | if (!(count($contact_data['addresses']))) |
---|
| 762 | { |
---|
| 763 | unset($contact_data['addresses']); |
---|
| 764 | } |
---|
| 765 | break; |
---|
[400] | 766 | |
---|
[2] | 767 | case 'connections': |
---|
| 768 | $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); |
---|
| 769 | if (!is_array($preferences)) |
---|
| 770 | { |
---|
| 771 | $preferences['personCardEmail'] = 1; |
---|
| 772 | $preferences['personCardPhone'] = 2; |
---|
| 773 | } |
---|
| 774 | unset($l_fields); |
---|
| 775 | $l_fields['connection_name'] = $this->trans_table['contact.connection.connection_name']; |
---|
| 776 | $l_fields['connection_value'] = $this->trans_table['contact.connection.connection_value']; |
---|
| 777 | |
---|
| 778 | $contact_data['connections'] = array(); |
---|
| 779 | foreach($l_fields as $l_field => $l_value) |
---|
| 780 | { |
---|
| 781 | if (!is_array($l_value)) |
---|
| 782 | { |
---|
| 783 | if (!($trans = $this->trans_table[$l_value])) |
---|
| 784 | { |
---|
| 785 | continue; |
---|
| 786 | } |
---|
[400] | 787 | |
---|
[2] | 788 | $i = 1; |
---|
| 789 | foreach($trans as $l_type => $l_type_fields) |
---|
| 790 | { |
---|
| 791 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 792 | { |
---|
| 793 | continue; |
---|
| 794 | } |
---|
[400] | 795 | |
---|
[2] | 796 | switch ($l_type) |
---|
| 797 | { |
---|
| 798 | case 'email': |
---|
| 799 | $contact_data['connections']['connection'.$i]['id_type'] = $preferences['personCardEmail']; |
---|
| 800 | break; |
---|
| 801 | |
---|
| 802 | default: |
---|
| 803 | $contact_data['connections']['connection'.$i]['id_type'] = $preferences['personCardPhone']; |
---|
| 804 | } |
---|
| 805 | $contact_data['connections']['connection'.$i]['type'] = $l_type; |
---|
[284] | 806 | $contact_data['connections']['connection'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
[2] | 807 | $i++; |
---|
| 808 | } |
---|
| 809 | } |
---|
| 810 | else |
---|
| 811 | { |
---|
[284] | 812 | $contact_data['connections']['connection1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
[2] | 813 | } |
---|
| 814 | } |
---|
[400] | 815 | |
---|
[2] | 816 | if (!(count($contact_data['connections']))) |
---|
| 817 | { |
---|
| 818 | unset($contact_data['connections']); |
---|
| 819 | } |
---|
| 820 | break; |
---|
[400] | 821 | |
---|
[2] | 822 | case 'prefix': |
---|
| 823 | unset($l_fields); |
---|
| 824 | $l_fields = $this->trans_table['contact.prefixes.prefix']; |
---|
| 825 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 826 | { |
---|
| 827 | unset($contact_data['prefix']); |
---|
| 828 | continue; |
---|
| 829 | } |
---|
[400] | 830 | |
---|
[284] | 831 | $contact_data['prefix'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
[2] | 832 | break; |
---|
[400] | 833 | |
---|
[2] | 834 | case 'suffix': |
---|
| 835 | unset($l_fields); |
---|
| 836 | $l_fields = $this->trans_table['contact.suffixes.suffix']; |
---|
| 837 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 838 | { |
---|
| 839 | unset($contact_data['suffix']); |
---|
| 840 | continue; |
---|
| 841 | } |
---|
[400] | 842 | |
---|
[284] | 843 | $contact_data['suffix'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
[2] | 844 | break; |
---|
[400] | 845 | |
---|
[2] | 846 | case 'status': |
---|
| 847 | unset($l_fields); |
---|
| 848 | $l_fields = $this->trans_table['contact.status.status_name']; |
---|
| 849 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 850 | { |
---|
| 851 | unset($contact_data['status']); |
---|
| 852 | continue; |
---|
| 853 | } |
---|
[400] | 854 | |
---|
[284] | 855 | $contact_data['status'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
[2] | 856 | break; |
---|
[400] | 857 | |
---|
[2] | 858 | case 'photo': |
---|
| 859 | unset($l_fields); |
---|
| 860 | $l_fields = $this->trans_table['contact.photo']; |
---|
| 861 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 862 | { |
---|
| 863 | unset($contact_data['photo']); |
---|
| 864 | continue; |
---|
| 865 | } |
---|
[400] | 866 | |
---|
[2] | 867 | $contact_data['photo'] = $contact[$l_fields[0]][0]; |
---|
[400] | 868 | break; |
---|
[2] | 869 | |
---|
| 870 | default: |
---|
| 871 | unset($l_fields); |
---|
| 872 | $l_fields = $this->trans_table['contact.'.$field]; |
---|
| 873 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 874 | { |
---|
| 875 | unset($contact_data[$field]); |
---|
| 876 | continue; |
---|
| 877 | } |
---|
[400] | 878 | |
---|
[2] | 879 | if(count($contact[$l_fields[0]]) > 1) |
---|
[284] | 880 | { |
---|
| 881 | $tmp = array(); |
---|
| 882 | foreach ($contact[$l_fields[0]] as $i => $j) |
---|
| 883 | { |
---|
| 884 | $tmp["$i"] = utf8_decode($j); |
---|
| 885 | } |
---|
| 886 | //$contact_data[$field] = $contact[$l_fields[0]]; |
---|
| 887 | $contact_data[$field] = $tmp; |
---|
| 888 | } |
---|
[2] | 889 | else |
---|
[284] | 890 | $contact_data[$field] = utf8_decode($contact[$l_fields[0]][0]); |
---|
[2] | 891 | |
---|
| 892 | break; |
---|
| 893 | } |
---|
| 894 | } |
---|
[400] | 895 | |
---|
[2] | 896 | if (!is_array($contact_data)) |
---|
| 897 | { |
---|
| 898 | return false; |
---|
| 899 | } |
---|
[400] | 900 | |
---|
[2] | 901 | return $contact_data; |
---|
| 902 | } |
---|
[285] | 903 | //SERPRO |
---|
[284] | 904 | /*! |
---|
| 905 | |
---|
| 906 | @function get_all_entries |
---|
| 907 | @abstract Returns all information requested about a bunch of contacts, usually a page |
---|
| 908 | @author Raphael Derosso Pereira |
---|
[400] | 909 | @author Mário César Kolling |
---|
[284] | 910 | |
---|
| 911 | @param string $filter Filter (returned by generate_filter). |
---|
| 912 | @param array $fields The array returned by get_fields with true |
---|
| 913 | on the fields to be taken. |
---|
| 914 | |
---|
| 915 | */ |
---|
| 916 | function get_all_entries($filter, $fields) |
---|
| 917 | { |
---|
| 918 | if (!is_array($fields)) |
---|
| 919 | { |
---|
| 920 | if (is_object($GLOBALS['phpgw']->log)) |
---|
| 921 | { |
---|
| 922 | $GLOBALS['phpgw']->log->message(array( |
---|
| 923 | 'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.', |
---|
| 924 | 'line' => __LINE__, |
---|
| 925 | 'file' => __FILE__)); |
---|
| 926 | |
---|
| 927 | $GLOBALS['phpgw']->log->commit(); |
---|
| 928 | } |
---|
| 929 | else |
---|
| 930 | { |
---|
| 931 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 932 | } |
---|
| 933 | } |
---|
| 934 | |
---|
| 935 | $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'],$this->src_info['acc'],$this->src_info['pw'],true); |
---|
| 936 | |
---|
| 937 | if (!$ldap) |
---|
| 938 | { |
---|
| 939 | return false; |
---|
| 940 | } |
---|
| 941 | |
---|
| 942 | $resource = @ldap_search($ldap, $this->src_info['dn'], $filter); |
---|
| 943 | $n_entries = @ldap_count_entries($ldap, $resource); |
---|
| 944 | |
---|
| 945 | ldap_sort($ldap, $resource, 'cn'); |
---|
| 946 | |
---|
| 947 | if ( $n_entries < 1) |
---|
| 948 | { |
---|
| 949 | return false; |
---|
| 950 | } |
---|
| 951 | |
---|
| 952 | $contacts = array(); |
---|
| 953 | |
---|
| 954 | for ($entry = ldap_first_entry($ldap, $resource); |
---|
| 955 | $entry != false; |
---|
| 956 | $entry = ldap_next_entry($ldap, $entry)) |
---|
| 957 | { |
---|
| 958 | $contact = ldap_get_attributes($ldap,$entry); |
---|
| 959 | if($contact['jpegPhoto']){ |
---|
| 960 | $contact['jpegPhoto'] = ldap_get_values_len ($ldap, $entry, "jpegPhoto"); |
---|
| 961 | } |
---|
| 962 | |
---|
| 963 | foreach($fields as $field => $trueness) |
---|
| 964 | { |
---|
| 965 | if (!$trueness) |
---|
| 966 | { |
---|
| 967 | //unset($contact_data[$field]); |
---|
| 968 | continue; |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | switch ($field) |
---|
| 972 | { |
---|
| 973 | case 'companies': |
---|
| 974 | unset($l_fields); |
---|
| 975 | $l_fields['company_name'] = $this->trans_table['contact.company.company_name']; |
---|
| 976 | $l_fields['title'] = $this->trans_table['contact.business_info.title']; |
---|
| 977 | $l_fields['department'] = $this->trans_table['contact.business_info.department']; |
---|
| 978 | $l_fields['company_notes'] = $this->trans_table['contact.company.company_notes']; |
---|
| 979 | |
---|
[1598] | 980 | //Relaciona o array com o atributo 'employeeNumber' do RHDS |
---|
| 981 | if(isset($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['empNumberShow']) && $_SESSION['phpgw_info']['user']['preferences']['contactcenter']['empNumberShow']) |
---|
| 982 | { |
---|
| 983 | $l_fields['empNumber'] = $this->trans_table['contact.business_info.empNumber']; |
---|
| 984 | } |
---|
| 985 | |
---|
| 986 | //Relaciona o array com o atributo 'mobile' do RHDS |
---|
| 987 | $l_fields['celPhone'] = $this->trans_table['contact.business_info.celPhone']; |
---|
| 988 | |
---|
[284] | 989 | $contact_data['companies'] = array(); |
---|
| 990 | foreach($l_fields as $l_field => $l_value) |
---|
| 991 | { |
---|
| 992 | if (!( $contact[$l_value[0]][0])) |
---|
| 993 | { |
---|
| 994 | continue; |
---|
| 995 | } |
---|
| 996 | |
---|
| 997 | $contact_data['companies']['company1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
| 998 | } |
---|
| 999 | |
---|
| 1000 | if (!(count($contact_data['companies']))) |
---|
| 1001 | { |
---|
| 1002 | unset($contact_data['companies']); |
---|
| 1003 | } |
---|
| 1004 | break; |
---|
| 1005 | |
---|
| 1006 | case 'relations': |
---|
| 1007 | unset($l_fields); |
---|
| 1008 | if (!$this->trans_table['contact.contact_related.names_ordered']) |
---|
| 1009 | { |
---|
| 1010 | unset($contact_data['relations']); |
---|
| 1011 | } |
---|
| 1012 | |
---|
| 1013 | $contact_data['relations'] = array(); |
---|
| 1014 | if (!is_array($this->trans_table['contact.contact_related.names_ordered'])) |
---|
| 1015 | { |
---|
| 1016 | if (!($trans = $this->trans_table[$this->trans_table['contact.contact_related.names_ordered']])) |
---|
| 1017 | { |
---|
| 1018 | continue; |
---|
| 1019 | } |
---|
| 1020 | |
---|
| 1021 | $i = 1; |
---|
| 1022 | foreach($trans as $l_type => $l_type_fields) |
---|
| 1023 | { |
---|
| 1024 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 1025 | { |
---|
| 1026 | continue; |
---|
| 1027 | } |
---|
| 1028 | |
---|
| 1029 | $contact_data['relations']['relation'.$i]['type'] = $l_type; |
---|
| 1030 | $contact_data['relations']['relation'.$i]['names_ordered'] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
| 1031 | $i++; |
---|
| 1032 | } |
---|
| 1033 | } |
---|
| 1034 | |
---|
| 1035 | if (!(count($contact_data['relations']))) |
---|
| 1036 | { |
---|
| 1037 | unset($contact_data['relations']); |
---|
| 1038 | } |
---|
| 1039 | break; |
---|
| 1040 | |
---|
| 1041 | case 'addresses': |
---|
| 1042 | unset($l_fields); |
---|
| 1043 | $l_fields['address1'] = $this->trans_table['contact.address.address1']; |
---|
| 1044 | $l_fields['address2'] = $this->trans_table['contact.address.address2']; |
---|
| 1045 | $l_fields['complement'] = $this->trans_table['contact.address.complement']; |
---|
| 1046 | $l_fields['address_other'] = $this->trans_table['contact.address.address_other']; |
---|
| 1047 | $l_fields['postal_code'] = $this->trans_table['contact.address.postal_code']; |
---|
| 1048 | $l_fields['po_box'] = $this->trans_table['contact.address.po_box']; |
---|
| 1049 | $l_fields['id_city'] = $this->trans_table['contact.address.city.id_city']; |
---|
| 1050 | $l_fields['city_name'] = $this->trans_table['contact.address.city.city_name']; |
---|
| 1051 | $l_fields['city_timezone'] = $this->trans_table['contact.address.city.city_timezone']; |
---|
| 1052 | $l_fields['city_geo_location'] = $this->trans_table['contact.address.city.city_geo_location']; |
---|
| 1053 | $l_fields['id_state'] = $this->trans_table['contact.address.city.state.id_state']; |
---|
| 1054 | $l_fields['state_name'] = $this->trans_table['contact.address.city.state.state_name']; |
---|
| 1055 | $l_fields['state_symbol'] = $this->trans_table['contact.address.city.state.state_symbol']; |
---|
| 1056 | $l_fields['id_country'] = $this->trans_table['contact.address.city.country.id_country']; |
---|
| 1057 | $l_fields['country_name'] = $this->trans_table['contact.address.city.country.country_name']; |
---|
| 1058 | $l_fields['address_is_default'] = $this->trans_table['contact.address.address_is_default']; |
---|
| 1059 | |
---|
| 1060 | $contact_data['addresses'] = array(); |
---|
| 1061 | foreach($l_fields as $l_field => $l_value) |
---|
| 1062 | { |
---|
| 1063 | if (!is_array($l_value)) |
---|
| 1064 | { |
---|
| 1065 | if (!($trans = $this->trans_table[$l_value])) |
---|
| 1066 | { |
---|
| 1067 | continue; |
---|
| 1068 | } |
---|
| 1069 | |
---|
| 1070 | $i = 1; |
---|
| 1071 | foreach($trans as $l_type => $l_type_fields) |
---|
| 1072 | { |
---|
| 1073 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 1074 | { |
---|
| 1075 | continue; |
---|
| 1076 | } |
---|
| 1077 | |
---|
| 1078 | $contact_data['addresses']['address'.$i]['type'] = $l_type; |
---|
| 1079 | $contact_data['addresses']['address'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
| 1080 | $i++; |
---|
| 1081 | } |
---|
| 1082 | } |
---|
| 1083 | else |
---|
| 1084 | { |
---|
| 1085 | $contact_data['addresses']['address1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
| 1086 | } |
---|
| 1087 | } |
---|
| 1088 | |
---|
| 1089 | if (!(count($contact_data['addresses']))) |
---|
| 1090 | { |
---|
| 1091 | unset($contact_data['addresses']); |
---|
| 1092 | } |
---|
| 1093 | break; |
---|
| 1094 | |
---|
| 1095 | case 'connections': |
---|
| 1096 | $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); |
---|
| 1097 | if (!is_array($preferences)) |
---|
| 1098 | { |
---|
| 1099 | $preferences['personCardEmail'] = 1; |
---|
| 1100 | $preferences['personCardPhone'] = 2; |
---|
| 1101 | } |
---|
| 1102 | unset($l_fields); |
---|
| 1103 | $l_fields['connection_name'] = $this->trans_table['contact.connection.connection_name']; |
---|
| 1104 | $l_fields['connection_value'] = $this->trans_table['contact.connection.connection_value']; |
---|
| 1105 | |
---|
| 1106 | $contact_data['connections'] = array(); |
---|
| 1107 | foreach($l_fields as $l_field => $l_value) |
---|
| 1108 | { |
---|
| 1109 | if (!is_array($l_value)) |
---|
| 1110 | { |
---|
| 1111 | if (!($trans = $this->trans_table[$l_value])) |
---|
| 1112 | { |
---|
| 1113 | continue; |
---|
| 1114 | } |
---|
| 1115 | |
---|
| 1116 | $i = 1; |
---|
| 1117 | foreach($trans as $l_type => $l_type_fields) |
---|
| 1118 | { |
---|
| 1119 | if (!($contact[$l_type_fields[0]][0])) |
---|
| 1120 | { |
---|
| 1121 | continue; |
---|
| 1122 | } |
---|
| 1123 | |
---|
| 1124 | switch ($l_type) |
---|
| 1125 | { |
---|
| 1126 | case 'email': |
---|
| 1127 | $contact_data['connections']['connection'.$i]['id_type'] = $preferences['personCardEmail']; |
---|
| 1128 | break; |
---|
| 1129 | |
---|
| 1130 | default: |
---|
| 1131 | $contact_data['connections']['connection'.$i]['id_type'] = $preferences['personCardPhone']; |
---|
| 1132 | } |
---|
| 1133 | $contact_data['connections']['connection'.$i]['type'] = $l_type; |
---|
| 1134 | $contact_data['connections']['connection'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); |
---|
| 1135 | $i++; |
---|
| 1136 | } |
---|
| 1137 | } |
---|
| 1138 | else |
---|
| 1139 | { |
---|
| 1140 | $contact_data['connections']['connection1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); |
---|
| 1141 | } |
---|
| 1142 | } |
---|
| 1143 | |
---|
| 1144 | if (!(count($contact_data['connections']))) |
---|
| 1145 | { |
---|
| 1146 | unset($contact_data['connections']); |
---|
| 1147 | } |
---|
| 1148 | break; |
---|
| 1149 | |
---|
| 1150 | case 'prefix': |
---|
| 1151 | unset($l_fields); |
---|
| 1152 | $l_fields = $this->trans_table['contact.prefixes.prefix']; |
---|
| 1153 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 1154 | { |
---|
| 1155 | unset($contact_data['prefix']); |
---|
| 1156 | continue; |
---|
| 1157 | } |
---|
| 1158 | |
---|
| 1159 | $contact_data['prefix'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
| 1160 | break; |
---|
| 1161 | |
---|
| 1162 | case 'suffix': |
---|
| 1163 | unset($l_fields); |
---|
| 1164 | $l_fields = $this->trans_table['contact.suffixes.suffix']; |
---|
| 1165 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 1166 | { |
---|
| 1167 | unset($contact_data['suffix']); |
---|
| 1168 | continue; |
---|
| 1169 | } |
---|
| 1170 | |
---|
| 1171 | $contact_data['suffix'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
| 1172 | break; |
---|
| 1173 | |
---|
| 1174 | case 'status': |
---|
| 1175 | unset($l_fields); |
---|
| 1176 | $l_fields = $this->trans_table['contact.status.status_name']; |
---|
| 1177 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 1178 | { |
---|
| 1179 | unset($contact_data['status']); |
---|
| 1180 | continue; |
---|
| 1181 | } |
---|
| 1182 | |
---|
| 1183 | $contact_data['status'] = utf8_decode($contact[$l_fields[0]][0]); |
---|
| 1184 | break; |
---|
| 1185 | |
---|
| 1186 | case 'photo': |
---|
| 1187 | unset($l_fields); |
---|
| 1188 | $l_fields = $this->trans_table['contact.photo']; |
---|
| 1189 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 1190 | { |
---|
| 1191 | unset($contact_data['photo']); |
---|
| 1192 | continue; |
---|
| 1193 | } |
---|
| 1194 | |
---|
| 1195 | $contact_data['photo'] = $contact[$l_fields[0]][0]; |
---|
| 1196 | break; |
---|
| 1197 | |
---|
| 1198 | default: |
---|
| 1199 | unset($l_fields); |
---|
| 1200 | $l_fields = $this->trans_table['contact.'.$field]; |
---|
| 1201 | if (!$l_fields or !$contact[$l_fields[0]][0]) |
---|
| 1202 | { |
---|
| 1203 | unset($contact_data[$field]); |
---|
| 1204 | continue; |
---|
| 1205 | } |
---|
| 1206 | |
---|
| 1207 | if(count($contact[$l_fields[0]]) > 1) |
---|
| 1208 | { |
---|
| 1209 | $tmp = array(); |
---|
| 1210 | foreach ($contact[$l_fields[0]] as $i => $j) |
---|
| 1211 | { |
---|
| 1212 | $tmp["$i"] = utf8_decode($j); |
---|
| 1213 | } |
---|
| 1214 | //$contact_data[$field] = $contact[$l_fields[0]]; |
---|
| 1215 | $contact_data[$field] = $tmp; |
---|
| 1216 | } |
---|
| 1217 | else |
---|
| 1218 | $contact_data[$field] = utf8_decode($contact[$l_fields[0]][0]); |
---|
| 1219 | |
---|
| 1220 | break; |
---|
| 1221 | |
---|
| 1222 | } |
---|
| 1223 | } |
---|
| 1224 | |
---|
| 1225 | if (is_array($contact_data)) |
---|
| 1226 | { |
---|
| 1227 | $contacts[ldap_get_dn($ldap, $entry)] = $contact_data; |
---|
| 1228 | } |
---|
| 1229 | |
---|
| 1230 | } |
---|
| 1231 | |
---|
| 1232 | return $contacts; |
---|
| 1233 | } |
---|
[400] | 1234 | |
---|
[1419] | 1235 | function get_multiple_entries ( $id_contacts, $fields, $other_data = false, $external=false ) |
---|
[2] | 1236 | { |
---|
| 1237 | if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data))) |
---|
| 1238 | { |
---|
[400] | 1239 | if (is_object($GLOBALS['phpgw']->log)) |
---|
[2] | 1240 | { |
---|
| 1241 | $GLOBALS['phpgw']->log->message(array( |
---|
| 1242 | 'text' => 'F-BadcontactcenterParam, wrong get_multiple_entry parameter type.', |
---|
| 1243 | 'line' => __LINE__, |
---|
| 1244 | 'file' => __FILE__)); |
---|
[400] | 1245 | |
---|
[2] | 1246 | $GLOBALS['phpgw']->log->commit(); |
---|
| 1247 | } |
---|
| 1248 | else { |
---|
| 1249 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 1250 | } |
---|
| 1251 | } |
---|
[400] | 1252 | |
---|
[285] | 1253 | foreach ($id_contacts as $id) |
---|
| 1254 | { |
---|
[1419] | 1255 | $contacts[$id] = $this->get_single_entry($id,$fields,$external); |
---|
[285] | 1256 | } |
---|
[400] | 1257 | |
---|
[285] | 1258 | return $contacts; |
---|
[284] | 1259 | |
---|
[285] | 1260 | // SERPRO |
---|
[400] | 1261 | |
---|
[285] | 1262 | /*$contacts = array(); |
---|
[400] | 1263 | |
---|
[2] | 1264 | if ($other_data) |
---|
| 1265 | { |
---|
| 1266 | //TODO |
---|
| 1267 | } |
---|
[284] | 1268 | |
---|
| 1269 | $filter = $this->generate_filter($id_contacts); |
---|
| 1270 | |
---|
| 1271 | //$teste = $this->get_all_entries($filter, $fields); |
---|
| 1272 | |
---|
[285] | 1273 | return $this->get_all_entries($filter, $fields);*/ |
---|
[400] | 1274 | |
---|
[284] | 1275 | } |
---|
| 1276 | |
---|
[285] | 1277 | // CELEPAR |
---|
[284] | 1278 | function generate_filter($id_contacts) |
---|
| 1279 | { |
---|
| 1280 | if (($size = count($id_contacts))) |
---|
[2] | 1281 | { |
---|
[285] | 1282 | $contacts[$id] = $this->get_single_entry($id,$fields); |
---|
| 1283 | } |
---|
[400] | 1284 | |
---|
[285] | 1285 | return $contacts; |
---|
| 1286 | } |
---|
[400] | 1287 | |
---|
[285] | 1288 | // SERPRO |
---|
| 1289 | /* |
---|
| 1290 | function generate_filter($id_contacts) |
---|
| 1291 | { |
---|
| 1292 | if (($size = count($id_contacts))) |
---|
| 1293 | { |
---|
[284] | 1294 | $filter = '(&(objectClass='.$this->src_info['obj'] . ')(|'; |
---|
| 1295 | for ($i = 0; $i < $size; $i++) |
---|
| 1296 | { |
---|
| 1297 | |
---|
[400] | 1298 | // |
---|
| 1299 | // Não utiliza mais a função ldap_explode, usa a expressão regular a seguir para pegar o primeiro |
---|
[285] | 1300 | // componente da dn |
---|
[400] | 1301 | // |
---|
[284] | 1302 | preg_match('/^(\w*=[^,]*),.*$/', $id_contacts[$i], $cn); |
---|
| 1303 | |
---|
[285] | 1304 | // |
---|
| 1305 | // Adicionados os str_replace para adicionar caracteres de escape em frente aos caracteres '(' e ')', |
---|
[400] | 1306 | // posteriormente poderá ser necessário substituir por uma expressão regular mais genérica. |
---|
[285] | 1307 | // |
---|
| 1308 | |
---|
[284] | 1309 | if ($cn[1]) |
---|
| 1310 | { |
---|
[285] | 1311 | // |
---|
[400] | 1312 | // Esta operação resolve o problema causado pela conversão de caracteres acentuados realizada |
---|
| 1313 | // pela função ldap_explode_dn(). Talvez seja necessário utilizar esta tradução em outros lugares, |
---|
| 1314 | // neste caso é mais apropriado colocar dentro de uma função. |
---|
[285] | 1315 | // |
---|
[284] | 1316 | //foreach($cn as $key=>$value){ |
---|
| 1317 | // $cn[$key]=preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $value); |
---|
| 1318 | //} |
---|
| 1319 | |
---|
| 1320 | $filter .= '(' . str_replace(')', '\)', str_replace('(','\(',$cn[1])) . ')'; |
---|
| 1321 | } |
---|
| 1322 | } |
---|
| 1323 | $filter .= '))'; |
---|
[2] | 1324 | } |
---|
[284] | 1325 | |
---|
| 1326 | return $filter; |
---|
| 1327 | |
---|
[2] | 1328 | } |
---|
[285] | 1329 | */ |
---|
[2] | 1330 | |
---|
| 1331 | function get_all_entries_ids () |
---|
| 1332 | { |
---|
| 1333 | $search_fields = array('contact.id_contact', 'contact.names_ordered'); |
---|
| 1334 | $search_rules = array( |
---|
| 1335 | 0 => array( |
---|
| 1336 | 'field' => 'contact.names_ordered', |
---|
| 1337 | 'type' => 'LIKE', |
---|
| 1338 | 'value' => '%' |
---|
| 1339 | ) |
---|
| 1340 | ); |
---|
| 1341 | $search_other = array('order' => 'contact.names_ordered'); |
---|
| 1342 | |
---|
| 1343 | $result_i = $this->find($search_fields, $search_rules, $search_other); |
---|
| 1344 | |
---|
| 1345 | if (is_array($result_i) and count($result_i)) |
---|
| 1346 | { |
---|
| 1347 | $result = array(); |
---|
| 1348 | foreach($result_i as $result_part) |
---|
| 1349 | { |
---|
| 1350 | $result[] = $result_part['id_contact']; |
---|
| 1351 | } |
---|
| 1352 | |
---|
| 1353 | return $result; |
---|
| 1354 | } |
---|
| 1355 | |
---|
| 1356 | return null; |
---|
| 1357 | } |
---|
[400] | 1358 | |
---|
[2] | 1359 | function get_relations ($id_contact,$extra=false) |
---|
| 1360 | { |
---|
| 1361 | } |
---|
[400] | 1362 | |
---|
[2] | 1363 | function get_addresses ( $id_contact,$extra=false ) |
---|
| 1364 | { |
---|
| 1365 | } |
---|
[400] | 1366 | |
---|
[2] | 1367 | function get_connections ( $id_contact,$extra=false ) |
---|
| 1368 | { |
---|
| 1369 | } |
---|
[400] | 1370 | |
---|
[2] | 1371 | function get_companies ( $id_contact, $extra=false ) |
---|
| 1372 | { |
---|
| 1373 | } |
---|
[400] | 1374 | |
---|
[2] | 1375 | function get_all_prefixes ( ) |
---|
| 1376 | { |
---|
| 1377 | } |
---|
[400] | 1378 | |
---|
[2] | 1379 | function get_all_suffixes ( ) |
---|
| 1380 | { |
---|
| 1381 | } |
---|
[400] | 1382 | |
---|
[2] | 1383 | function get_all_status ( ) |
---|
| 1384 | { |
---|
| 1385 | } |
---|
[400] | 1386 | |
---|
[2] | 1387 | function get_all_relations_types ( ) |
---|
| 1388 | { |
---|
| 1389 | } |
---|
[400] | 1390 | |
---|
[2] | 1391 | function get_all_addresses_types ( ) |
---|
| 1392 | { |
---|
| 1393 | } |
---|
[400] | 1394 | |
---|
[2] | 1395 | function get_all_connections_types ( ) |
---|
| 1396 | { |
---|
| 1397 | } |
---|
[400] | 1398 | |
---|
[2] | 1399 | function get_vcard ( $id_contact ) |
---|
| 1400 | { |
---|
| 1401 | } |
---|
[400] | 1402 | |
---|
| 1403 | |
---|
| 1404 | |
---|
| 1405 | |
---|
[2] | 1406 | function get_global_tree ( $root ) |
---|
| 1407 | { |
---|
| 1408 | } |
---|
[400] | 1409 | |
---|
[2] | 1410 | function get_actual_brach ( ) |
---|
| 1411 | { |
---|
| 1412 | } |
---|
[400] | 1413 | |
---|
[2] | 1414 | function set_actual_branch ( $branch ) |
---|
| 1415 | { |
---|
| 1416 | } |
---|
| 1417 | } |
---|
| 1418 | ?> |
---|