Changeset 284 for trunk/contactcenter/inc/class.bo_contactcenter.inc.php
- Timestamp:
- 05/21/08 16:56:17 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/contactcenter/inc/class.bo_contactcenter.inc.php
r2 r284 5 5 * Written by: * 6 6 * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * 7 * sponsored by Thyamad - http://www.thyamad.com 7 * sponsored by Thyamad - http://www.thyamad.com * 8 8 * ------------------------------------------------------------------------- * 9 9 * This program is free software; you can redistribute it and/or modify it * … … 25 25 */ 26 26 var $catalog; 27 27 28 28 /*! 29 29 The Security Manager 30 30 */ 31 31 var $security; 32 32 33 33 34 34 function bo_contactcenter($catalog=false) … … 37 37 $this->catalog_level = $GLOBALS['phpgw']->session->appsession('bo_contactcenter.catalog_level','contactcenter'); 38 38 $this->security = CreateObject('contactcenter.bo_security_manager'); 39 39 40 40 if ($catalog) 41 41 { … … 56 56 } 57 57 } 58 59 /*! 60 58 59 /* 60 * 61 * @function is_external 62 * @author Mário César Kolling <mario.kolling@serpro.gov.br> 63 * @abstract Verify if a catalog is external 64 * @param (mixed) an catalog array or a catalog tree level, a string in the form 0.sublevel.subsublevel 65 * @return (boolean) true if it is an external catalog false otherwise 66 * 67 */ 68 69 function is_external($catalog) 70 { 71 if (is_array($catalog)) 72 { 73 $level = $this->get_level_by_branch($catalog, $this->tree['branches']); 74 } 75 else 76 { 77 $level = $catalog; 78 } 79 80 $lvl_vector = explode('.', $level); 81 $id = $lvl_vector[1]; 82 83 if ($this->tree['branches'][$id]['external']) 84 { 85 return true; 86 } 87 88 return false; 89 90 } 91 92 /* 93 function get_letters_filter($catalog) 94 { 95 96 } 97 98 function get_numbers_filter($catalog) 99 { 100 101 } 102 103 function get_search_filter($catalog) 104 { 105 106 } 107 */ 108 109 /*! 110 61 111 @function find 62 112 @abstract Performs a search in the DB based on the parameters 63 113 @author Raphael Derosso Pereira (algorithm and code) 64 114 @author Vinicius Cubas Brand (algorithm) 65 115 66 116 @param array $what The list of fields to be returned. The format is: 67 117 $what = array( … … 69 119 'contact.names_ordered' 70 120 ); 71 121 72 122 @param array $rules The restrictions. 73 123 74 124 The restrictions format is quite complicated, but is very complete. 75 125 As defined here, there is the possibility to do almost any type of 76 126 search (tell me if you can't do any). For example, imagine the 77 127 following search: 78 128 79 129 and(a,or(d,e,and(f,g))) 80 130 81 131 That is represented by the folloowing tree: 82 132 83 133 and 84 134 | … … 98 148 The rules that should be passed to the find function for this tree 99 149 is: 100 150 101 151 $rules = array( 102 152 0 => array( … … 139 189 ); 140 190 141 142 The restriction type can be: =, !=, <=, <, >, >=, NULL, IN, LIKE, 191 192 The restriction type can be: =, !=, <=, <, >, >=, NULL, IN, LIKE, 143 193 NOT NULL, NOT IN, NOT LIKE 144 194 Value of branch can be AND, OR, NOT 145 146 @param array $other Other parameter to the search 195 196 @param array $other Other parameter to the search 147 197 $other = array( 148 198 'offset' => (int), … … 154 204 155 205 @return array $array[<field_name>][<row_number>] 156 206 157 207 */ 158 208 function find($what, $rules=false, $other=false) … … 160 210 return $this->catalog->find($what, $rules, $other); 161 211 } 162 163 /*! 164 212 213 /*! 214 165 215 @function get_catalog_tree 166 216 @abstract Returns an array describing the available … … 168 218 values and types 169 219 @author Raphael Derosso Pereira 220 @author Mário César Kolling (external catalogs and optimizations) 170 221 171 222 @param (string) $level The level to be taken 172 223 @param (boolean) $recursive Retrive the whole tree from 173 224 the level specified until the leaves 174 225 175 226 @return The format of the return is: 176 227 $return = array( … … 195 246 1 => array(...),... 196 247 ); 197 248 198 249 <branch_type> can be 'catalog_group', 'catalog' or 'view'; 199 <branch_class> is the name of the class that is capable of 250 <branch_class> is the name of the class that is capable of 200 251 handling the information for this catalog/view 201 252 <branch_class_args> is an array that holds the arguments to … … 203 254 <brach_find_args> is the string that should precede the search 204 255 string 205 206 If the branch is actually a leaf, than 'sub_branch' is false; 207 208 256 257 If the branch is actually a leaf, than 'sub_branch' is false; 258 259 209 260 TODO: This method is hard-coded, but it should grab the tree 210 261 from the DB using the View Manager... … … 218 269 return $this->tree['branches']; 219 270 } 220 271 272 $lvl_vector = explode('.', $level); 273 $id = $lvl_vector[1]; 274 221 275 $branch =& $this->get_branch_by_level($level); 222 276 $info = $this->get_info_by_level($level); 223 277 224 278 if ($branch['type'] === 'unknown') 225 279 { … … 227 281 { 228 282 $ldap = CreateObject('contactcenter.bo_ldap_manager'); 229 $new_branch = $ldap->get_ldap_tree($info['src'], $branch['value'], $recursive); 230 283 284 if ($this->tree['branches'][$id]['external']) 285 { 286 // if it's an external catalog 287 $new_branch = $ldap->get_external_ldap_tree($info['src'], $branch['value'], $recursive); 288 } 289 else 290 { 291 // if it's not an external catalog 292 $new_branch = $ldap->get_ldap_tree($info['src'], $branch['value'], $recursive); 293 } 294 231 295 if ($new_branch) 232 296 { 297 if (!empty($new_branch['timeout']) && !empty($new_branch['msg'])) 298 { 299 return $new_branch; 300 } 301 302 // Necessary for the new way the catalog tree is built at initialization 303 $new_branch['name'] = $branch['name']; 304 $new_branch['external'] = $branch['external']; 233 305 $branch = $new_branch; 306 234 307 } 235 308 else … … 239 312 } 240 313 $GLOBALS['phpgw']->session->appsession('bo_contactcenter.tree','contactcenter',$this->tree); 241 242 314 return $branch; 243 315 } … … 246 318 return $branch; 247 319 } 248 320 249 321 return false; 250 322 } 251 323 252 324 if ($level !== '0') 253 325 { 254 326 return false; 255 327 } 256 328 257 329 $this->tree = array( 258 330 0 => array( … … 275 347 'sub_branch' => false 276 348 ),*/ 277 349 278 350 1 => array( 279 351 'name' => lang('Groups'), … … 281 353 'class' => 'bo_group_manager', 282 354 'icon' => 'people-mini.png', 283 'sub_branch' => False 355 'sub_branch' => False 284 356 ) 285 357 ) 286 358 ); 287 359 288 360 $ldap = CreateObject('contactcenter.bo_ldap_manager'); 289 361 $ldap_srcs = $ldap->get_all_ldap_sources(); 290 362 291 363 if ($ldap_srcs) 292 364 { … … 297 369 if (($tree = $ldap->get_ldap_tree($id, $ldap_srcs[$id]['dn'], $recursive))) 298 370 { 371 // It isn't used anymore, but does no harm! 372 // It may be usefull later for use with search timeouts, or another ldap error 373 if (array_key_exists('error_msg', $tree)) 374 { 375 if (isset($this->tree['branches']['msg'])) 376 { 377 $this->tree['branches']['msg'] .= "\n" . lang('Catalog %1 not showed due to error: ' . 378 $tree['error_msg'], $ldap_srcs[$id]['name']); 379 } 380 else 381 { 382 $this->tree['branches']['msg'] = lang('Catalog %1 not showed due to error: ' . 383 $tree['error_msg'], $ldap_srcs[$id]['name']); 384 } 385 } 386 else 387 { 388 $tree['name'] = $ldap_srcs[$id]['name']; 389 $tree['external'] = false; 390 array_push($this->tree['branches'], $tree); 391 $this->tree[$i]['type'] = 'ldap'; 392 $this->tree[$i]['src'] = $id; 393 } 394 395 } 396 $i++; 397 } 398 } 399 400 // external LDAP sources 401 $ldap_srcs = $ldap->get_external_ldap_sources(); 402 403 if ($ldap_srcs) 404 { 405 $i = count($this->tree); 406 407 reset($ldap_srcs); 408 409 while (list($id,) = each($ldap_srcs)) 410 { 411 // External catalogs are now identified as type unknown during initialization. An optimization change. 412 413 /* 414 if (($tree = $ldap->get_external_ldap_tree($id, $ldap_srcs[$id]['dn'], $recursive))) 415 { 416 if (array_key_exists('error_msg', $tree)) 417 { 418 if (isset($this->tree['branches']['msg'])) 419 { 420 $this->tree['branches']['msg'] .= "\n" . lang('Catalog %1 not showed due to error: ' . 421 $tree['error_msg'], $ldap_srcs[$id]['name']); 422 } 423 else 424 { 425 $this->tree['branches']['msg'] = lang('Catalog %1 not showed due to error: ' . 426 $tree['error_msg'], $ldap_srcs[$id]['name']); 427 } 428 } 429 430 else 431 { 432 */ 299 433 $tree['name'] = $ldap_srcs[$id]['name']; 434 $tree['type'] = 'unknown'; 435 $tree['value'] = $ldap_srcs[$id]['dn']; 436 $tree['external'] = true; 437 //$tree['sub_branch'] = false; 300 438 array_push($this->tree['branches'], $tree); 301 439 $this->tree[$i]['type'] = 'ldap'; 302 440 $this->tree[$i]['src'] = $id; 303 } 441 // } 442 //} 304 443 $i++; 305 444 } 306 445 } 307 446 308 447 $GLOBALS['phpgw']->session->appsession('bo_contactcenter.tree','contactcenter',$this->tree); 309 448 return $this->tree['branches']; 310 } 311 312 /*! 313 449 //return null; 450 } 451 452 /*! 453 314 454 @function get_branch_by_level 315 455 @abstract Returns the branch and it's informations given the level 316 456 @author Raphael Derosso Pereira 317 457 318 458 @param (string) $level The level to be used 319 459 320 460 */ 321 461 function & get_branch_by_level($level) … … 323 463 $path = @explode('.',$level); 324 464 $n_ways = count($path); 325 465 326 466 if ($n_ways <= 1) 327 467 { 328 468 return false; 329 469 } 330 470 331 471 $code = '$branch =& $this->tree[\'branches\']'; 332 472 for ($i = 1; $i < $n_ways-1; $i++) … … 338 478 //echo 'Codigo: '.$code.'<br>'; 339 479 eval($code); 340 480 341 481 return $branch; 342 482 } 343 483 344 484 /*! 345 485 346 486 @function get_info_by_level 347 487 @abstract Returns the information about the catalog, given the level … … 355 495 $path = @explode('.',$level); 356 496 $n_ways = count($path); 357 497 358 498 if ($n_ways <= 1) 359 499 { 360 500 return false; 361 501 } 362 502 363 503 $info = $this->tree[$path[1]]; 364 504 365 505 return $info; 366 506 } … … 413 553 414 554 $search = $this->get_level_by_branch($catalog, $bcatalog['sub_branch'], (string) $level); 415 555 416 556 if ($search !== false) 417 557 { … … 427 567 return false; 428 568 } 429 430 /*! 431 569 570 /*! 571 432 572 @function get_actual_catalog 433 @abstract Returns the information about the Catalog that is 573 @abstract Returns the information about the Catalog that is 434 574 instantiated 435 575 436 576 @author Raphael Derosso Pereira 437 577 438 578 */ 439 579 function get_actual_catalog() … … 442 582 return $catalog; 443 583 } 444 445 /*! 446 584 585 /*! 586 447 587 @function set_catalog 448 588 @abstract Sets the actual catalog 449 589 @author Raphael Derosso Pereira 450 590 451 591 @param array $to_catalog The catalog in the format returned by 452 592 get_available_tree or the level 453 593 454 594 */ 455 595 function set_catalog(& $to_catalog ) … … 477 617 $level = $this->get_level_by_branch($to_catalog, $this->tree['branches']); 478 618 } 479 619 620 $lvl_vector = explode('.', $level); 621 $id = $lvl_vector[1]; 622 480 623 switch($catalog['type']) 481 624 { … … 499 642 $call .= ','.implode(',',$args); 500 643 } 501 644 502 645 $call .= ');'; 503 646 504 647 // print_r($catalog); 505 648 // echo '<br><br><b>Setando Catalogo '.$catalog['name'].': </b>'.$call.'<br>'; 506 649 507 650 eval($call); 508 651 509 652 return $catalog; 510 653 511 654 default: return false; 512 655 } 513 656 } 514 657 515 658 516 659 … … 518 661 * Methods to set general fields * 519 662 \*********************************************************************/ 520 521 /*! 522 663 664 /*! 665 523 666 @function add_vcard 524 667 @abstract Insert a VCard to the squema … … 526 669 @param string $uploaded_file The path to the file that were 527 670 uploaded. 528 671 529 672 */ 530 673 function add_vcard ( $uploaded_file ) … … 533 676 534 677 535 678 536 679 /*********************************************************************\ 537 680 * Methods to get general data * 538 681 \*********************************************************************/ 539 682 540 683 } 541 684 ?>
Note: See TracChangeset
for help on using the changeset viewer.