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