- Timestamp:
- 05/23/08 17:10:39 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/contactcenter/inc/class.bo_global_ldap_catalog.inc.php
r284 r285 16 16 */ 17 17 include_once('class.abo_catalog.inc.php'); 18 18 19 19 class bo_global_ldap_catalog extends abo_catalog 20 20 { 21 21 var $ldap; 22 22 23 23 var $src_info; 24 24 25 25 var $trans_table; 26 27 26 // used to determine if a catalog is external 28 27 var $external; 29 30 28 var $fields = array( 31 29 'id_contact' => true, … … 43 41 'pgp_key' => true, 44 42 'notes' => true, 45 'department' => true, 46 47 'empNumber' => true, 48 43 49 44 /* Array fields */ 50 45 'companies' => true, … … 53 48 'connections' => true 54 49 ); 55 50 56 51 /* 57 52 58 53 @function global_ldap_catalog 59 54 @abstract Constructor … … 64 59 @param string $context Ldap bind DN 65 60 @param integer $external 0 = internal catalog, 1 = external catalog 66 67 61 */ 68 62 function bo_global_ldap_catalog ( $id_source, $context, $external = 0 ) 69 63 { 70 71 64 $this->external = $external; 72 73 65 if (!function_exists('ldap_search')) 74 66 { 75 67 exit('PHP LDAP support Unavailable!'); 76 68 } 77 69 78 70 $this->ldap = CreateObject('contactcenter.bo_ldap_manager'); 79 71 80 72 if ($this->external) 81 73 { … … 100 92 } 101 93 else 102 { 94 { 103 95 $this->trans_table = $this->ldap->get_ldap_fields_association($id_source); 104 96 } 105 97 } 106 98 107 99 /* 108 100 109 101 @function find 110 102 @abstract Searches the LDAP directory for the specified fields with … … 112 104 that matches the rules. 113 105 @author Raphael Derosso Pereira 114 106 115 107 @param array $what The fields to be taken 116 108 @param array $rules The rules to be match. See class.abo_catalog.inc.php … … 121 113 'offset' => (integer) [NOT IMPLEMENTED] 122 114 ) 123 115 124 116 */ 125 117 function find($what, $rules=false, $other=false) 126 118 { 127 119 $restric_fields = $this->get_restrictions_without_branch($rules); 128 120 129 121 $trans_f = $this->translate_fields($what, $restric_fields); 130 122 131 123 foreach($trans_f as $orig => $field_a) 132 124 { … … 136 128 } 137 129 } 138 130 139 131 $fields = array_unique($fields); 140 132 141 133 $filter = $this->process_restrictions($rules, $trans_f); 142 134 143 135 if(strstr($this->src_info['context'], "ldap://")) { 144 136 $refer_context = str_replace("??base","",preg_replace('!^(ldap://[^/]+)/(.*$)!', '\\2', $this->src_info['context'])); 145 $host = preg_replace('!^(ldap://[^/]+)/.*$!', '\\1', $this->src_info['context']); 137 $host = preg_replace('!^(ldap://[^/]+)/.*$!', '\\1', $this->src_info['context']); 146 138 $this->src_info['host'] = $host; 147 $this->src_info['acc'] = ''; 148 $this->src_info['pw'] = ''; 149 } 150 151 $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true); 152 153 if (!$ldap) 154 { 139 } 140 141 if($refer_context || "ou" === strtolower(substr($this->src_info['context'], 0, 2))) 142 { 143 $followReferral = false; 144 } 145 elseif(trim($rules[4]['value']) != "inetOrgPerson") 146 { 147 $followReferral = true; 148 } 149 else 150 { 155 151 return false; 156 152 } 157 158 if (!$this->external) 159 { 160 $fields[] ='phpgwAccountVisible'; 161 } 162 163 $result_r = @ldap_search($ldap ,($refer_context ? $refer_context : $this->src_info['context']), $filter, $fields, 0); 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); 164 156 165 157 if (!$result_r) … … 167 159 return false; 168 160 } 169 161 170 162 if ($other['order']) 171 163 { … … 181 173 } 182 174 } 183 175 184 176 $result_u = ldap_get_entries($ldap, $result_r); 185 177 186 178 $i = 0; 187 179 foreach ($result_u as $index => $result_p) … … 191 183 continue; 192 184 } 193 185 194 186 foreach ($trans_f as $orig => $trans) 195 187 { … … 209 201 $i++; 210 202 } 211 203 212 204 return $return; 213 205 } 214 206 215 207 /* 216 208 217 209 @function translate_fields 218 210 @abstract Return the LDAP objectClass fields that corresponds to the 219 211 specified parameter fields 220 212 @author Raphael Derosso Pereira 221 213 222 214 @param array $fields The fields in the standard ContactCenter format 223 215 @param array $rules The rules 224 216 225 217 */ 226 218 function translate_fields ( $fields, &$restric_fields ) 227 219 { 228 220 $return = array(); 229 221 230 222 $i = 0; 231 223 foreach ($fields as $field) … … 235 227 continue; 236 228 } 237 229 238 230 if (!is_array($this->trans_table[$field])) 239 231 { 240 232 $reference = $this->trans_table[$field]; 241 233 242 234 reset($restric_fields); 243 235 while(list(,$field_r) = each($restric_fields)) 244 236 { 245 246 237 if ($field_r['field'] === $reference and array_key_exists($field_r['value'], $this->trans_table[$reference])) 247 238 { … … 252 243 else 253 244 { 254 255 245 if (!is_array($return[$field])) 256 246 { … … 263 253 } 264 254 } 265 255 266 256 if (count($return)) 267 257 { 268 258 return $return; 269 259 } 270 260 271 261 return false; 272 262 } 273 263 274 264 /* 275 265 276 266 @function process_restrictions 277 267 @abstract Returns a LDAP filter string that corresponds to the 278 268 specified restriction rules 279 269 @author Raphael Derosso Pereira 280 270 281 271 @param string $rules The restriction rules 282 272 283 273 */ 284 274 function process_restrictions( $rules, &$trans_table, $join_type='&' ) … … 288 278 return null; 289 279 } 290 280 291 281 foreach($rules as $rule_i => $rule) 292 282 { … … 300 290 $join = '|'; 301 291 break; 302 292 303 293 case 'AND': 304 294 $join = '&'; 305 295 break; 306 296 307 297 case 'NOT': 308 298 $join = '!'; 309 299 break; 310 300 311 301 default: 312 302 $join = $join_type; … … 314 304 $return_t[] = $this->process_restrictions($rule['sub_branch'], $trans_table, $join); 315 305 break; 316 306 317 307 case '=': 318 308 if (array_key_exists($rule['field'], $trans_table)) … … 325 315 } 326 316 break; 327 328 case '!=': 317 318 case '!=': 329 319 if (array_key_exists($rule['field'], $trans_table)) 330 320 { … … 336 326 } 337 327 break; 338 328 339 329 case '<=': 340 330 case '<': … … 348 338 } 349 339 break; 350 340 351 341 case '>': 352 342 case '>=': … … 360 350 } 361 351 break; 362 352 363 353 case 'NULL': 364 354 if (array_key_exists($rule['field'], $trans_table)) … … 371 361 } 372 362 break; 373 363 374 364 case 'IN': 375 365 if (array_key_exists($rule['field'], $trans_table)) … … 391 381 $value_1 = strtoupper(str_replace('%', '*', $rule['value'])); 392 382 $value_2 = strtolower($value_1); 393 383 394 384 foreach($trans_table[$rule['field']] as $field) 395 385 { … … 400 390 } 401 391 break; 402 392 403 393 */ case 'LIKE': 404 394 if (array_key_exists($rule['field'], $trans_table)) 405 395 { 406 396 $value = str_replace('%', '*', $rule['value']); 407 397 408 398 foreach($trans_table[$rule['field']] as $field) 409 399 { … … 413 403 } 414 404 break; 415 405 416 406 case 'NOT NULL': 417 407 if (array_key_exists($rule['field'], $trans_table)) … … 424 414 } 425 415 break; 426 416 427 417 case 'NOT IN': 428 418 if (array_key_exists($rule['field'], $trans_table)) … … 444 434 $value_1 = strtoupper(str_replace('%', '*', $rule['value'])); 445 435 $value_2 = strtolower($value_1); 446 436 447 437 foreach($trans_table[$rule['field']] as $field) 448 438 { … … 458 448 { 459 449 $value = str_replace('%', '*', $rule['value']); 460 450 461 451 foreach($trans_table[$rule['field']] as $field) 462 452 { … … 468 458 } 469 459 } 470 460 471 461 if (count($return_t)) 472 462 { … … 486 476 487 477 /*! 488 478 489 479 @function get_restrictions_without_branch 490 480 @abstract Returns an array containing the restrictions ignoring the 491 481 branches 492 482 @author Raphael Derosso Pereira 493 483 494 484 @param array $restrictions The restrictions 495 485 496 486 */ 497 487 function get_restrictions_without_branch(&$restrictions) … … 501 491 return null; 502 492 } 503 493 504 494 $fields = array(); 505 495 506 496 foreach ($restrictions as $restrict_data) 507 497 { … … 511 501 $fields = array_merge($fields, $this->get_restrictions_without_branch($restrict_data['sub_branch'])); 512 502 break; 513 503 514 504 case '=': 515 case '!=': 505 case '!=': 516 506 case '<=': 517 507 case '<': … … 528 518 array_push($fields, $restrict_data); 529 519 break; 530 520 531 521 default: 532 exit('Error in '.__FILE__.' on '.__LINE__.'<br>The restriction type passed was: '.$restrict_data['type']); 533 } 534 } 535 522 exit('Error in '.__FILE__.' on '.__LINE__.'<br>The restriction type passed was: '.$restrict_data['type']); 523 } 524 } 525 536 526 return $fields; 537 527 } 538 539 528 529 540 530 /*********************************************************************\ 541 531 * Methods to Get Data * 542 532 \*********************************************************************/ 543 544 533 534 545 535 /*! 546 536 547 537 @function get_single_entry 548 538 @abstract Returns all information requested about one contact 549 539 @author Raphael Derosso Pereira 550 540 551 541 @param integer $id_contact The contact ID 552 542 @param array $fields The array returned by get_fields with true 553 543 on the fields to be taken. 554 544 555 545 */ 556 546 function get_single_entry ( $id_contact, $fields ) 557 547 { 558 if (!is_array($fields)) 559 { 560 if (is_object($GLOBALS['phpgw']->log)) 548 if (!is_array($fields)) 549 { 550 if (is_object($GLOBALS['phpgw']->log)) 561 551 { 562 552 $GLOBALS['phpgw']->log->message(array( … … 564 554 'line' => __LINE__, 565 555 'file' => __FILE__)); 566 556 567 557 $GLOBALS['phpgw']->log->commit(); 568 558 } 569 else 559 else 570 560 { 571 561 exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); 572 562 } 573 563 } 574 564 575 565 $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'],$this->src_info['acc'],$this->src_info['pw'],true); 576 566 577 567 if (!$ldap) 578 568 { 579 569 return false; 580 570 } 581 571 582 572 $resource = ldap_read($ldap, $id_contact, 'objectClass='.$this->src_info['obj']); 583 573 $n_entries = ldap_count_entries($ldap, $resource); … … 586 576 return false; 587 577 } 588 578 589 579 $first_entry = ldap_first_entry($ldap, $resource); 590 580 $contact = ldap_get_attributes($ldap,$first_entry); 591 if($contact['jpegPhoto']){ 592 $contact['jpegPhoto'] = ldap_get_values_len ($ldap, $first_entry, "jpegPhoto"); 581 if($contact['jpegPhoto']){ 582 $contact['jpegPhoto'] = ldap_get_values_len ($ldap, $first_entry, "jpegPhoto"); 593 583 } 594 584 595 585 // print_r($contact); 596 586 597 587 // $contact_data = $this->fields; 598 588 599 589 foreach($fields as $field => $trueness) 600 590 { … … 604 594 continue; 605 595 } 606 596 607 597 switch ($field) 608 598 { … … 613 603 $l_fields['department'] = $this->trans_table['contact.business_info.department']; 614 604 $l_fields['company_notes'] = $this->trans_table['contact.company.company_notes']; 615 605 616 606 $contact_data['companies'] = array(); 617 607 foreach($l_fields as $l_field => $l_value) … … 621 611 continue; 622 612 } 623 613 624 614 $contact_data['companies']['company1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); 625 615 } 626 616 627 617 if (!(count($contact_data['companies']))) 628 618 { … … 630 620 } 631 621 break; 632 622 633 623 case 'relations': 634 624 unset($l_fields); … … 637 627 unset($contact_data['relations']); 638 628 } 639 629 640 630 $contact_data['relations'] = array(); 641 631 if (!is_array($this->trans_table['contact.contact_related.names_ordered'])) … … 645 635 continue; 646 636 } 647 637 648 638 $i = 1; 649 639 foreach($trans as $l_type => $l_type_fields) … … 653 643 continue; 654 644 } 655 645 656 646 $contact_data['relations']['relation'.$i]['type'] = $l_type; 657 647 $contact_data['relations']['relation'.$i]['names_ordered'] = utf8_decode($contact[$l_type_fields[0]][0]); … … 659 649 } 660 650 } 661 651 662 652 if (!(count($contact_data['relations']))) 663 653 { … … 665 655 } 666 656 break; 667 657 668 658 case 'addresses': 669 659 unset($l_fields); … … 694 684 continue; 695 685 } 696 686 697 687 $i = 1; 698 688 foreach($trans as $l_type => $l_type_fields) … … 702 692 continue; 703 693 } 704 694 705 695 $contact_data['addresses']['address'.$i]['type'] = $l_type; 706 696 $contact_data['addresses']['address'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); … … 713 703 } 714 704 } 715 705 716 706 if (!(count($contact_data['addresses']))) 717 707 { … … 719 709 } 720 710 break; 721 711 722 712 case 'connections': 723 713 $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); … … 740 730 continue; 741 731 } 742 732 743 733 $i = 1; 744 734 foreach($trans as $l_type => $l_type_fields) … … 748 738 continue; 749 739 } 750 740 751 741 switch ($l_type) 752 742 { … … 768 758 } 769 759 } 770 760 771 761 if (!(count($contact_data['connections']))) 772 762 { … … 774 764 } 775 765 break; 776 766 777 767 case 'prefix': 778 768 unset($l_fields); … … 783 773 continue; 784 774 } 785 775 786 776 $contact_data['prefix'] = utf8_decode($contact[$l_fields[0]][0]); 787 777 break; 788 778 789 779 case 'suffix': 790 780 unset($l_fields); … … 795 785 continue; 796 786 } 797 787 798 788 $contact_data['suffix'] = utf8_decode($contact[$l_fields[0]][0]); 799 789 break; 800 790 801 791 case 'status': 802 792 unset($l_fields); … … 807 797 continue; 808 798 } 809 799 810 800 $contact_data['status'] = utf8_decode($contact[$l_fields[0]][0]); 811 801 break; 812 802 813 803 case 'photo': 814 804 unset($l_fields); … … 819 809 continue; 820 810 } 821 811 822 812 $contact_data['photo'] = $contact[$l_fields[0]][0]; 823 break; 813 break; 824 814 825 815 default: … … 831 821 continue; 832 822 } 833 823 834 824 if(count($contact[$l_fields[0]]) > 1) 835 825 { … … 848 838 } 849 839 } 850 840 851 841 if (!is_array($contact_data)) 852 842 { 853 843 return false; 854 844 } 855 845 856 846 return $contact_data; 857 847 } 858 848 //SERPRO 859 849 /*! 860 850 … … 932 922 $l_fields['department'] = $this->trans_table['contact.business_info.department']; 933 923 $l_fields['company_notes'] = $this->trans_table['contact.company.company_notes']; 934 935 ///Relaciona o array com o atributo 'employeeNumber' do RHDS936 $l_fields['empNumber'] = $this->trans_table['contact.business_info.empNumber'];937 924 938 925 $contact_data['companies'] = array(); … … 1181 1168 return $contacts; 1182 1169 } 1183 1170 1184 1171 function get_multiple_entries ( $id_contacts, $fields, $other_data = false ) 1185 1172 { 1186 1173 if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data))) 1187 1174 { 1188 if (is_object($GLOBALS['phpgw']->log)) 1175 if (is_object($GLOBALS['phpgw']->log)) 1189 1176 { 1190 1177 $GLOBALS['phpgw']->log->message(array( … … 1192 1179 'line' => __LINE__, 1193 1180 'file' => __FILE__)); 1194 1181 1195 1182 $GLOBALS['phpgw']->log->commit(); 1196 1183 } … … 1199 1186 } 1200 1187 } 1201 1202 $contacts = array(); 1203 1188 1189 foreach ($id_contacts as $id) 1190 { 1191 $contacts[$id] = $this->get_single_entry($id,$fields); 1192 } 1193 1194 return $contacts; 1195 1196 // SERPRO 1197 1198 /*$contacts = array(); 1199 1204 1200 if ($other_data) 1205 1201 { … … 1211 1207 //$teste = $this->get_all_entries($filter, $fields); 1212 1208 1213 return $this->get_all_entries($filter, $fields); 1214 } 1215 1209 return $this->get_all_entries($filter, $fields);*/ 1210 1211 } 1212 1213 // CELEPAR 1214 function generate_filter($id_contacts) 1215 { 1216 if (($size = count($id_contacts))) 1217 { 1218 $contacts[$id] = $this->get_single_entry($id,$fields); 1219 } 1220 1221 return $contacts; 1222 } 1223 1224 // SERPRO 1225 /* 1216 1226 function generate_filter($id_contacts) 1217 1227 { … … 1222 1232 { 1223 1233 1224 / *1225 *Não utiliza mais a função ldap_explode, usa a expressão regular a seguir para pegar o primeiro1226 *componente da dn1227 */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 // 1228 1238 preg_match('/^(\w*=[^,]*),.*$/', $id_contacts[$i], $cn); 1229 1239 1230 /* 1231 * Adicionados os str_replace para adicionar caracteres de escape em frente aos caracteres '(' e ')', 1232 * posteriormente poderá ser necessário substituir por uma expressão regular mais genérica. 1233 */ 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 1234 1245 if ($cn[1]) 1235 1246 { 1236 / *1237 *Esta operação resolve o problema causado pela conversão de caracteres acentuados realizada1238 *pela função ldap_explode_dn(). Talvez seja necessário utilizar esta tradução em outros lugares,1239 *neste caso é mais apropriado colocar dentro de uma função.1240 */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 // 1241 1252 //foreach($cn as $key=>$value){ 1242 1253 // $cn[$key]=preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $value); … … 1252 1263 1253 1264 } 1265 */ 1254 1266 1255 1267 function get_all_entries_ids () … … 1280 1292 return null; 1281 1293 } 1282 1294 1283 1295 function get_relations ($id_contact,$extra=false) 1284 1296 { 1285 1297 } 1286 1298 1287 1299 function get_addresses ( $id_contact,$extra=false ) 1288 1300 { 1289 1301 } 1290 1302 1291 1303 function get_connections ( $id_contact,$extra=false ) 1292 1304 { 1293 1305 } 1294 1306 1295 1307 function get_companies ( $id_contact, $extra=false ) 1296 1308 { 1297 1309 } 1298 1310 1299 1311 function get_all_prefixes ( ) 1300 1312 { 1301 1313 } 1302 1314 1303 1315 function get_all_suffixes ( ) 1304 1316 { 1305 1317 } 1306 1318 1307 1319 function get_all_status ( ) 1308 1320 { 1309 1321 } 1310 1322 1311 1323 function get_all_relations_types ( ) 1312 1324 { 1313 1325 } 1314 1326 1315 1327 function get_all_addresses_types ( ) 1316 1328 { 1317 1329 } 1318 1330 1319 1331 function get_all_connections_types ( ) 1320 1332 { 1321 1333 } 1322 1334 1323 1335 function get_vcard ( $id_contact ) 1324 1336 { 1325 1337 } 1326 1327 1328 1329 1338 1339 1340 1341 1330 1342 function get_global_tree ( $root ) 1331 1343 { 1332 1344 } 1333 1345 1334 1346 function get_actual_brach ( ) 1335 1347 { 1336 1348 } 1337 1349 1338 1350 function set_actual_branch ( $branch ) 1339 1351 {
Note: See TracChangeset
for help on using the changeset viewer.