Changeset 400 for trunk/contactcenter
- Timestamp:
- 08/14/08 12:17:32 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/contactcenter/inc/class.bo_global_ldap_catalog.inc.php
r388 r400 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 26 // used to determine if a catalog is external … … 41 41 'pgp_key' => true, 42 42 'notes' => true, 43 43 44 44 /* Array fields */ 45 45 'companies' => true, … … 48 48 'connections' => true 49 49 ); 50 50 51 51 /* 52 52 53 53 @function global_ldap_catalog 54 54 @abstract Constructor 55 55 @author Raphael Derosso Pereira 56 @author M ï¿œrio Cï¿œsar Kolling (external catalogs)56 @author Mário César Kolling (external catalogs) 57 57 58 58 @param integer $id_source The ID of the LDAP source … … 67 67 exit('PHP LDAP support Unavailable!'); 68 68 } 69 69 70 70 $this->ldap = CreateObject('contactcenter.bo_ldap_manager'); 71 71 72 72 if ($this->external) 73 73 { … … 92 92 } 93 93 else 94 { 94 { 95 95 $this->trans_table = $this->ldap->get_ldap_fields_association($id_source); 96 96 } 97 97 } 98 98 99 99 /* 100 100 101 101 @function find 102 102 @abstract Searches the LDAP directory for the specified fields with … … 104 104 that matches the rules. 105 105 @author Raphael Derosso Pereira 106 106 107 107 @param array $what The fields to be taken 108 108 @param array $rules The rules to be match. See class.abo_catalog.inc.php … … 113 113 'offset' => (integer) [NOT IMPLEMENTED] 114 114 ) 115 115 116 116 */ 117 117 function find($what, $rules=false, $other=false) 118 118 { 119 119 $restric_fields = $this->get_restrictions_without_branch($rules); 120 120 121 121 $trans_f = $this->translate_fields($what, $restric_fields); 122 122 123 123 foreach($trans_f as $orig => $field_a) 124 124 { … … 128 128 } 129 129 } 130 130 131 131 $fields = array_unique($fields); 132 132 133 133 $filter = $this->process_restrictions($rules, $trans_f); 134 134 135 135 if("ou" === strtolower(substr($this->src_info['context'], 0, 2)) || 136 (trim($rules[4]['value']) != "inetOrgPerson")) 137 { 136 (trim($rules[4]['value']) != "inetOrgPerson")) 137 { 138 138 $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true); 139 139 $result_r = ldap_search($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']); 140 140 } 141 141 else 142 { 142 { 143 143 return false; 144 144 } 145 145 146 146 147 147 if (!$result_r) … … 149 149 return false; 150 150 } 151 151 152 152 if ($other['order']) 153 153 { … … 163 163 } 164 164 } 165 165 166 166 $result_u = ldap_get_entries($ldap, $result_r); 167 167 168 168 $i = 0; 169 169 foreach ($result_u as $index => $result_p) … … 173 173 continue; 174 174 } 175 175 176 176 foreach ($trans_f as $orig => $trans) 177 177 { … … 191 191 $i++; 192 192 } 193 193 194 194 return $return; 195 195 } 196 196 197 197 /* 198 198 199 199 @function translate_fields 200 200 @abstract Return the LDAP objectClass fields that corresponds to the 201 201 specified parameter fields 202 202 @author Raphael Derosso Pereira 203 203 204 204 @param array $fields The fields in the standard ContactCenter format 205 205 @param array $rules The rules 206 206 207 207 */ 208 208 function translate_fields ( $fields, &$restric_fields ) 209 209 { 210 210 $return = array(); 211 211 212 212 $i = 0; 213 213 foreach ($fields as $field) … … 217 217 continue; 218 218 } 219 219 220 220 if (!is_array($this->trans_table[$field])) 221 221 { 222 222 $reference = $this->trans_table[$field]; 223 223 224 224 reset($restric_fields); 225 225 while(list(,$field_r) = each($restric_fields)) … … 243 243 } 244 244 } 245 245 246 246 if (count($return)) 247 247 { 248 248 return $return; 249 249 } 250 250 251 251 return false; 252 252 } 253 253 254 254 /* 255 255 256 256 @function process_restrictions 257 257 @abstract Returns a LDAP filter string that corresponds to the 258 258 specified restriction rules 259 259 @author Raphael Derosso Pereira 260 260 261 261 @param string $rules The restriction rules 262 262 263 263 */ 264 264 function process_restrictions( $rules, &$trans_table, $join_type='&' ) … … 268 268 return null; 269 269 } 270 270 271 271 foreach($rules as $rule_i => $rule) 272 272 { … … 280 280 $join = '|'; 281 281 break; 282 282 283 283 case 'AND': 284 284 $join = '&'; 285 285 break; 286 286 287 287 case 'NOT': 288 288 $join = '!'; 289 289 break; 290 290 291 291 default: 292 292 $join = $join_type; … … 294 294 $return_t[] = $this->process_restrictions($rule['sub_branch'], $trans_table, $join); 295 295 break; 296 296 297 297 case '=': 298 298 if (array_key_exists($rule['field'], $trans_table)) … … 305 305 } 306 306 break; 307 308 case '!=': 307 308 case '!=': 309 309 if (array_key_exists($rule['field'], $trans_table)) 310 310 { … … 316 316 } 317 317 break; 318 318 319 319 case '<=': 320 320 case '<': … … 328 328 } 329 329 break; 330 330 331 331 case '>': 332 332 case '>=': … … 340 340 } 341 341 break; 342 342 343 343 case 'NULL': 344 344 if (array_key_exists($rule['field'], $trans_table)) … … 351 351 } 352 352 break; 353 353 354 354 case 'IN': 355 355 if (array_key_exists($rule['field'], $trans_table)) … … 371 371 $value_1 = strtoupper(str_replace('%', '*', $rule['value'])); 372 372 $value_2 = strtolower($value_1); 373 373 374 374 foreach($trans_table[$rule['field']] as $field) 375 375 { … … 380 380 } 381 381 break; 382 382 383 383 */ case 'LIKE': 384 384 if (array_key_exists($rule['field'], $trans_table)) 385 385 { 386 386 $value = str_replace('%', '*', $rule['value']); 387 387 388 388 foreach($trans_table[$rule['field']] as $field) 389 389 { … … 393 393 } 394 394 break; 395 395 396 396 case 'NOT NULL': 397 397 if (array_key_exists($rule['field'], $trans_table)) … … 404 404 } 405 405 break; 406 406 407 407 case 'NOT IN': 408 408 if (array_key_exists($rule['field'], $trans_table)) … … 424 424 $value_1 = strtoupper(str_replace('%', '*', $rule['value'])); 425 425 $value_2 = strtolower($value_1); 426 426 427 427 foreach($trans_table[$rule['field']] as $field) 428 428 { … … 438 438 { 439 439 $value = str_replace('%', '*', $rule['value']); 440 440 441 441 foreach($trans_table[$rule['field']] as $field) 442 442 { … … 448 448 } 449 449 } 450 450 451 451 if (count($return_t)) 452 452 { … … 466 466 467 467 /*! 468 468 469 469 @function get_restrictions_without_branch 470 470 @abstract Returns an array containing the restrictions ignoring the 471 471 branches 472 472 @author Raphael Derosso Pereira 473 473 474 474 @param array $restrictions The restrictions 475 475 476 476 */ 477 477 function get_restrictions_without_branch(&$restrictions) … … 481 481 return null; 482 482 } 483 483 484 484 $fields = array(); 485 485 486 486 foreach ($restrictions as $restrict_data) 487 487 { … … 491 491 $fields = array_merge($fields, $this->get_restrictions_without_branch($restrict_data['sub_branch'])); 492 492 break; 493 493 494 494 case '=': 495 case '!=': 495 case '!=': 496 496 case '<=': 497 497 case '<': … … 508 508 array_push($fields, $restrict_data); 509 509 break; 510 510 511 511 default: 512 exit('Error in '.__FILE__.' on '.__LINE__.'<br>The restriction type passed was: '.$restrict_data['type']); 513 } 514 } 515 512 exit('Error in '.__FILE__.' on '.__LINE__.'<br>The restriction type passed was: '.$restrict_data['type']); 513 } 514 } 515 516 516 return $fields; 517 517 } 518 519 518 519 520 520 /*********************************************************************\ 521 521 * Methods to Get Data * 522 522 \*********************************************************************/ 523 524 523 524 525 525 /*! 526 526 527 527 @function get_single_entry 528 528 @abstract Returns all information requested about one contact 529 529 @author Raphael Derosso Pereira 530 530 531 531 @param integer $id_contact The contact ID 532 532 @param array $fields The array returned by get_fields with true 533 533 on the fields to be taken. 534 534 535 535 */ 536 536 function get_single_entry ( $id_contact, $fields ) 537 537 { 538 if (!is_array($fields)) 539 { 540 if (is_object($GLOBALS['phpgw']->log)) 538 if (!is_array($fields)) 539 { 540 if (is_object($GLOBALS['phpgw']->log)) 541 541 { 542 542 $GLOBALS['phpgw']->log->message(array( … … 544 544 'line' => __LINE__, 545 545 'file' => __FILE__)); 546 546 547 547 $GLOBALS['phpgw']->log->commit(); 548 548 } 549 else 549 else 550 550 { 551 551 exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); 552 552 } 553 553 } 554 554 555 555 $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'],$this->src_info['acc'],$this->src_info['pw'],true); 556 556 557 557 if (!$ldap) 558 558 { … … 566 566 return false; 567 567 } 568 568 569 569 $first_entry = ldap_first_entry($ldap, $resource); 570 570 $contact = ldap_get_attributes($ldap,$first_entry); 571 if($contact['jpegPhoto']){ 572 $contact['jpegPhoto'] = ldap_get_values_len ($ldap, $first_entry, "jpegPhoto"); 571 if($contact['jpegPhoto']){ 572 $contact['jpegPhoto'] = ldap_get_values_len ($ldap, $first_entry, "jpegPhoto"); 573 573 } 574 574 575 575 // print_r($contact); 576 576 577 577 // $contact_data = $this->fields; 578 578 579 579 foreach($fields as $field => $trueness) 580 580 { … … 584 584 continue; 585 585 } 586 586 587 587 switch ($field) 588 588 { … … 593 593 $l_fields['department'] = $this->trans_table['contact.business_info.department']; 594 594 $l_fields['company_notes'] = $this->trans_table['contact.company.company_notes']; 595 595 596 596 $contact_data['companies'] = array(); 597 597 foreach($l_fields as $l_field => $l_value) … … 601 601 continue; 602 602 } 603 603 604 604 $contact_data['companies']['company1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); 605 605 } 606 606 607 607 if (!(count($contact_data['companies']))) 608 608 { … … 610 610 } 611 611 break; 612 612 613 613 case 'relations': 614 614 unset($l_fields); … … 617 617 unset($contact_data['relations']); 618 618 } 619 619 620 620 $contact_data['relations'] = array(); 621 621 if (!is_array($this->trans_table['contact.contact_related.names_ordered'])) … … 625 625 continue; 626 626 } 627 627 628 628 $i = 1; 629 629 foreach($trans as $l_type => $l_type_fields) … … 633 633 continue; 634 634 } 635 635 636 636 $contact_data['relations']['relation'.$i]['type'] = $l_type; 637 637 $contact_data['relations']['relation'.$i]['names_ordered'] = utf8_decode($contact[$l_type_fields[0]][0]); … … 639 639 } 640 640 } 641 641 642 642 if (!(count($contact_data['relations']))) 643 643 { … … 645 645 } 646 646 break; 647 647 648 648 case 'addresses': 649 649 unset($l_fields); … … 674 674 continue; 675 675 } 676 676 677 677 $i = 1; 678 678 foreach($trans as $l_type => $l_type_fields) … … 682 682 continue; 683 683 } 684 684 685 685 $contact_data['addresses']['address'.$i]['type'] = $l_type; 686 686 $contact_data['addresses']['address'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); … … 693 693 } 694 694 } 695 695 696 696 if (!(count($contact_data['addresses']))) 697 697 { … … 699 699 } 700 700 break; 701 701 702 702 case 'connections': 703 703 $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); … … 720 720 continue; 721 721 } 722 722 723 723 $i = 1; 724 724 foreach($trans as $l_type => $l_type_fields) … … 728 728 continue; 729 729 } 730 730 731 731 switch ($l_type) 732 732 { … … 748 748 } 749 749 } 750 750 751 751 if (!(count($contact_data['connections']))) 752 752 { … … 754 754 } 755 755 break; 756 756 757 757 case 'prefix': 758 758 unset($l_fields); … … 763 763 continue; 764 764 } 765 765 766 766 $contact_data['prefix'] = utf8_decode($contact[$l_fields[0]][0]); 767 767 break; 768 768 769 769 case 'suffix': 770 770 unset($l_fields); … … 775 775 continue; 776 776 } 777 777 778 778 $contact_data['suffix'] = utf8_decode($contact[$l_fields[0]][0]); 779 779 break; 780 780 781 781 case 'status': 782 782 unset($l_fields); … … 787 787 continue; 788 788 } 789 789 790 790 $contact_data['status'] = utf8_decode($contact[$l_fields[0]][0]); 791 791 break; 792 792 793 793 case 'photo': 794 794 unset($l_fields); … … 799 799 continue; 800 800 } 801 801 802 802 $contact_data['photo'] = $contact[$l_fields[0]][0]; 803 break; 803 break; 804 804 805 805 default: … … 811 811 continue; 812 812 } 813 813 814 814 if(count($contact[$l_fields[0]]) > 1) 815 815 { … … 828 828 } 829 829 } 830 830 831 831 if (!is_array($contact_data)) 832 832 { 833 833 return false; 834 834 } 835 835 836 836 return $contact_data; 837 837 } … … 842 842 @abstract Returns all information requested about a bunch of contacts, usually a page 843 843 @author Raphael Derosso Pereira 844 @author M ï¿œrio Cï¿œsar Kolling844 @author Mário César Kolling 845 845 846 846 @param string $filter Filter (returned by generate_filter). … … 1158 1158 return $contacts; 1159 1159 } 1160 1160 1161 1161 function get_multiple_entries ( $id_contacts, $fields, $other_data = false ) 1162 1162 { 1163 1163 if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data))) 1164 1164 { 1165 if (is_object($GLOBALS['phpgw']->log)) 1165 if (is_object($GLOBALS['phpgw']->log)) 1166 1166 { 1167 1167 $GLOBALS['phpgw']->log->message(array( … … 1169 1169 'line' => __LINE__, 1170 1170 'file' => __FILE__)); 1171 1171 1172 1172 $GLOBALS['phpgw']->log->commit(); 1173 1173 } … … 1176 1176 } 1177 1177 } 1178 1178 1179 1179 foreach ($id_contacts as $id) 1180 1180 { 1181 1181 $contacts[$id] = $this->get_single_entry($id,$fields); 1182 1182 } 1183 1183 1184 1184 return $contacts; 1185 1185 1186 1186 // SERPRO 1187 1187 1188 1188 /*$contacts = array(); 1189 1189 1190 1190 if ($other_data) 1191 1191 { … … 1198 1198 1199 1199 return $this->get_all_entries($filter, $fields);*/ 1200 1200 1201 1201 } 1202 1202 … … 1208 1208 $contacts[$id] = $this->get_single_entry($id,$fields); 1209 1209 } 1210 1210 1211 1211 return $contacts; 1212 1212 } 1213 1213 1214 1214 // SERPRO 1215 1215 /* … … 1222 1222 { 1223 1223 1224 // 1225 // N ï¿œo utiliza mais a funᅵᅵo ldap_explode, usa a expressï¿œo regular a seguir para pegar o primeiro1224 // 1225 // Não utiliza mais a função ldap_explode, usa a expressão regular a seguir para pegar o primeiro 1226 1226 // componente da dn 1227 // 1227 // 1228 1228 preg_match('/^(\w*=[^,]*),.*$/', $id_contacts[$i], $cn); 1229 1229 1230 1230 // 1231 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.1232 // posteriormente poderá ser necessário substituir por uma expressão regular mais genérica. 1233 1233 // 1234 1234 … … 1236 1236 { 1237 1237 // 1238 // Esta opera ᅵᅵo resolve o problema causado pela conversï¿œo de caracteres acentuados realizada1239 // pela fun ᅵᅵo ldap_explode_dn(). Talvez seja necessï¿œrio utilizar esta traduᅵᅵo em outros lugares,1240 // neste caso ï¿œ mais apropriado colocar dentro de uma funᅵᅵo.1238 // Esta operação resolve o problema causado pela conversão de caracteres acentuados realizada 1239 // pela função ldap_explode_dn(). Talvez seja necessário utilizar esta tradução em outros lugares, 1240 // neste caso é mais apropriado colocar dentro de uma função. 1241 1241 // 1242 1242 //foreach($cn as $key=>$value){ … … 1282 1282 return null; 1283 1283 } 1284 1284 1285 1285 function get_relations ($id_contact,$extra=false) 1286 1286 { 1287 1287 } 1288 1288 1289 1289 function get_addresses ( $id_contact,$extra=false ) 1290 1290 { 1291 1291 } 1292 1292 1293 1293 function get_connections ( $id_contact,$extra=false ) 1294 1294 { 1295 1295 } 1296 1296 1297 1297 function get_companies ( $id_contact, $extra=false ) 1298 1298 { 1299 1299 } 1300 1300 1301 1301 function get_all_prefixes ( ) 1302 1302 { 1303 1303 } 1304 1304 1305 1305 function get_all_suffixes ( ) 1306 1306 { 1307 1307 } 1308 1308 1309 1309 function get_all_status ( ) 1310 1310 { 1311 1311 } 1312 1312 1313 1313 function get_all_relations_types ( ) 1314 1314 { 1315 1315 } 1316 1316 1317 1317 function get_all_addresses_types ( ) 1318 1318 { 1319 1319 } 1320 1320 1321 1321 function get_all_connections_types ( ) 1322 1322 { 1323 1323 } 1324 1324 1325 1325 function get_vcard ( $id_contact ) 1326 1326 { 1327 1327 } 1328 1329 1330 1331 1328 1329 1330 1331 1332 1332 function get_global_tree ( $root ) 1333 1333 { 1334 1334 } 1335 1335 1336 1336 function get_actual_brach ( ) 1337 1337 { 1338 1338 } 1339 1339 1340 1340 function set_actual_branch ( $branch ) 1341 1341 {
Note: See TracChangeset
for help on using the changeset viewer.