Changeset 3167 for branches/2.2/workflow/inc/class.so_userinterface.inc.php
- Timestamp:
- 08/17/10 16:17:12 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/workflow/inc/class.so_userinterface.inc.php
r1470 r3167 1 1 <?php 2 require_once($_SESSION['phpgw_info']['workflow']['phpgw_api_inc'] . '/class.config.inc.php');3 2 4 3 /** … … 22 21 function so_userinterface() 23 22 { 24 $this->db = &$GLOBALS['workflow']['workflowObjects']->getDBWorkflow()->Link_ID;23 $this->db =& Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Link_ID; 25 24 $this->db->SetFetchMode(ADODB_FETCH_ASSOC); 26 25 } … … 61 60 $oldDB = $GLOBALS['phpgw']->db; 62 61 $GLOBALS['phpgw']->db = $GLOBALS['ajax']->db; 63 $config = new config('workflow');62 $config = &Factory::getInstance('config', 'workflow'); 64 63 $configValues = $config->read_repository(); 65 64 $submasksString = $configValues['intranet_subnetworks']; … … 93 92 if (!empty($externalApplicationsID)) 94 93 { 95 $result = $GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID->query("SELECT DISTINCT external_application_id, name, address, image, authentication, intranet_only FROM egw_wf_external_application WHERE (external_application_id IN (" . implode(', ', $externalApplicationsID) . ")) ORDER BY name");94 $result = Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID->query("SELECT DISTINCT external_application_id, name, address, image, authentication, intranet_only FROM egw_wf_external_application WHERE (external_application_id IN (" . implode(', ', $externalApplicationsID) . ")) ORDER BY name"); 96 95 $preOutput = $result->GetArray(-1); 97 96 … … 234 233 235 234 /* gather some info from the area */ 236 $areaInfo = $this->db->query('SELECT COALESCE( titular_funcionario_id, -1) AS titular_funcionario_id, COALESCE(substituto_funcionario_id, -1) AS substituto_funcionario_id FROM area WHERE (organizacao_id = ?) AND (area_id = ?)', array($organizationID, $areaID))->GetArray(-1);235 $areaInfo = $this->db->query('SELECT COALESCE(a.titular_funcionario_id, -1) AS titular_funcionario_id, COALESCE(s.funcionario_id, -1) AS substituto_funcionario_id FROM area a LEFT OUTER JOIN substituicao s ON ((a.area_id = s.area_id) AND (CURRENT_DATE BETWEEN s.data_inicio AND s.data_fim)) WHERE (a.organizacao_id = ?) AND (a.area_id = ?)', array($organizationID, $areaID))->GetArray(-1); 237 236 if (empty($areaInfo)) 238 237 return false; … … 245 244 246 245 $employees = $result->GetArray(-1); 247 $cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');246 $cachedLDAP = Factory::newInstance('CachedLDAP'); 248 247 $cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_NORMAL); 249 248 $categoriesCount = array(); … … 318 317 319 318 $employees = $result->GetArray(-1); 320 $cachedLDAP = $GLOBALS['workflow']['factory']->newInstance('CachedLDAP');319 $cachedLDAP = Factory::newInstance('CachedLDAP'); 321 320 $cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_NORMAL); 322 321 for ($i = 0; $i < count($employees); $i++) … … 334 333 { 335 334 $employees[$i]['telephoneNumber'] = is_null($entry['telephonenumber']) ? '' : $entry['telephonenumber']; 336 $employees[$i]['cn'] = is_null($entry['cn']) ? '' : $entry['cn'] . (is_null($entry['last_update']) ? ' <font color="red">( excluído)</font>' : '');335 $employees[$i]['cn'] = is_null($entry['cn']) ? '' : $entry['cn'] . (is_null($entry['last_update']) ? ' <font color="red">(inativo)</font>' : ''); 337 336 } 338 337 } … … 343 342 344 343 /** 345 * Search Employee 344 * Search Employee by Name 346 345 * @param int $searchTerm term to search 347 346 * @param int $organizationID Id of organization … … 349 348 * @access public 350 349 */ 351 function searchEmployee($searchTerm, $organizationID) 352 { 353 /* initialize some variables */ 354 $output = array('employees' => array(), 'bygroup' => array( ) ); 355 $ldapResult = array(); 356 357 /* search for the $searchTerm in the LDAP */ 358 $ldap = &$GLOBALS['workflow']['workflowObjects']->getLDAP(); 350 function searchEmployeeByName($searchTerm, $organizationID) 351 { 352 /* get ldap connection */ 353 $ldap = &Factory::getInstance('WorkflowObjects')->getLDAP(); 359 354 360 355 $searchTermExploded = explode(" ", $searchTerm); 361 356 $fullSearch = false; 362 357 363 if (count($searchTermExploded) > 0){364 for ($i=1; $i<count($searchTermExploded); $i++){365 if (strlen($searchTermExploded[$i]) > 2){358 if (count($searchTermExploded) > 0){ 359 for ($i=1; $i<count($searchTermExploded); $i++) { 360 if (strlen($searchTermExploded[$i]) > 2) { 366 361 $fullSearch = true; 367 362 } 368 363 } 369 364 370 if ($fullSearch){365 if ($fullSearch){ 371 366 $searchTerm = implode("*", $searchTermExploded); 372 367 } 373 368 } 374 369 375 $list = @ldap_search($ldap, $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(cn=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber')); 370 /* searching employees by name in the ldap server */ 371 $list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(cn=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber')); 376 372 if ($list === false) 377 373 return false; 378 374 375 /* parsing ldap result */ 379 376 $entries = ldap_get_entries($ldap, $list); 380 $employeesID = array(); 377 $ldapResult = array(); 378 381 379 for ($i = 0; $i < $entries['count']; $i++) 382 380 $ldapResult[$entries[$i]['uidnumber'][0]] = array('cn' => $entries[$i]['cn'][0], 'telephoneNumber' => $entries[$i]['telephonenumber'][0]); 383 381 382 /* no records found. bye. */ 383 if (count($ldapResult) == 0) 384 return array(); 385 384 386 $uids = implode( ',', array_keys( $ldapResult ) ); 385 387 386 /* load employee information */ 387 $query = 'SELECT f.funcionario_id AS funcionario_id, f.area_id AS area_id, a.sigla AS area'; 388 $query .= ' FROM funcionario f, area a, funcionario_status s'; 389 $query .= " WHERE (f.area_id = a.area_id) AND (f.organizacao_id = {$organizationID})"; 390 $query .= " AND (" . ( ( ! empty( $uids ) ) ? "f.funcionario_id IN ({$uids}) OR " : '' ); 391 $query .= " a.sigla LIKE UPPER(?))"; 392 $query .= " AND (f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = 'S')"; 393 $query .= " ORDER BY a.sigla asc"; 394 395 $result = $this->db->query($query, array( "%{$searchTerm}%" ) ); 396 397 if ( ! $result ) 398 return array( ); 399 400 $uids = array( ); 401 402 $employees = $result->GetArray(-1); 403 for ($i = 0; $i < count($employees); $i++) 404 { 405 for ($j = 0; $j < $result->_numOfFields; $j++) 406 unset($employees[$i][$j]); 407 408 if ( array_key_exists( $employees[$i]['funcionario_id'], $ldapResult ) ) 409 { 410 $employees[$i]['cn'] = is_null($ldapResult[$employees[$i]['funcionario_id']]['cn']) ? '' : $ldapResult[$employees[$i]['funcionario_id']]['cn']; 411 $employees[$i]['telephoneNumber'] = is_null($ldapResult[$employees[$i]['funcionario_id']]['telephoneNumber']) ? '' : $ldapResult[$employees[$i]['funcionario_id']]['telephoneNumber']; 388 /* searching for aditional employee information */ 389 $query = "SELECT "; 390 $query .= " f.funcionario_id AS funcionario_id, f.area_id AS area_id, a.sigla AS area "; 391 $query .= " FROM "; 392 $query .= " funcionario f "; 393 $query .= " INNER JOIN "; 394 $query .= " area a USING (area_id) "; 395 $query .= " INNER JOIN "; 396 $query .= " funcionario_status s ON ((f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = 'S')) "; 397 $query .= " WHERE "; 398 $query .= " (f.organizacao_id = ?) "; 399 $query .= " AND "; 400 $query .= " (f.funcionario_id IN ({$uids})) "; 401 402 $result = $this->db->query($query, array($organizationID))->GetArray(-1); 403 $employees = array(); 404 405 /* filling return array with employee's information */ 406 for ($i = 0; $i < count($result); $i++) { 407 $employees []= array( 408 'area' => $result[$i]['area'], 409 'area_id' => $result[$i]['area_id'], 410 'funcionario_id' => $result[$i]['funcionario_id'], 411 'cn' => $ldapResult[$result[$i]['funcionario_id']]['cn'], 412 'telephoneNumber' => empty($ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']) ? '': $ldapResult[$result[$i]['funcionario_id']]['telephoneNumber'] 413 ); 414 } 415 416 /* sorting by name (cn) */ 417 $sort_function = create_function('$a, $b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);'); 418 usort($employees, $sort_function ); 419 420 return $employees; 421 } 422 423 /** 424 * Search Employee by Area 425 * @param int $searchTerm term to search 426 * @param int $organizationID Id of organization 427 * @return array employee data information 428 * @access public 429 */ 430 function searchEmployeeByArea($searchTerm, $organizationID) 431 { 432 /* get ldap connection */ 433 $ldap = &Factory::getInstance('WorkflowObjects')->getLDAP(); 434 435 /* makes no sense search for an area if the string has more than one word */ 436 if (count(explode(" ", $searchTerm)) > 1) 437 return array(); 438 439 /* searching for employees in areas that match 'searchTerm' */ 440 $query = "SELECT "; 441 $query .= " f.funcionario_id AS funcionario_id, f.area_id AS area_id, a.sigla AS area "; 442 $query .= " FROM "; 443 $query .= " funcionario f "; 444 $query .= " INNER JOIN "; 445 $query .= " area a USING (area_id) "; 446 $query .= " INNER JOIN "; 447 $query .= " funcionario_status s ON ((f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = 'S')) "; 448 $query .= " WHERE "; 449 $query .= " (f.organizacao_id = ?) "; 450 $query .= " AND "; 451 $query .= " (UPPER(a.sigla) LIKE UPPER(?)) "; 452 453 $result = $this->db->query($query, array($organizationID, '%'.$searchTerm.'%'))->GetArray(-1); 454 455 /* no records found. bye */ 456 if (count($result) == 0) 457 return array(); 458 459 /* creating the ldap query */ 460 $ldap_query = '(&(|'; 461 for ($i = 0; $i < count($result); $i++) { 462 $ldap_query .= '(uidNumber=' . $result[$i]['funcionario_id'] . ')'; 463 } 464 $ldap_query .= ')(phpgwAccountType=u))'; 465 466 /* executing it */ 467 $list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), $ldap_query, array('uidNumber', 'cn', 'telephoneNumber')); 468 $entries = ldap_get_entries($ldap, $list); 469 470 /* parsing result */ 471 $ldapResult = array(); 472 for ($i = 0; $i < $entries['count']; $i++) 473 $ldapResult[$entries[$i]['uidnumber'][0]] = array('cn' => $entries[$i]['cn'][0], 'telephoneNumber' => $entries[$i]['telephonenumber'][0]); 474 475 /* we will need to search into database 'cache' for users deleted in ldap */ 476 $cachedLDAP = Factory::newInstance( 'CachedLDAP' ); 477 $cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_DATABASE ); 478 479 /* filling return array with employee's information */ 480 $employees = array(); 481 for ($i = 0; $i < count($result); $i++) { 482 483 $employee = array(); 484 485 /* user deleted in ldap. Let's try to find him into database 'cache' */ 486 if (empty($ldapResult[$result[$i]['funcionario_id']]['cn'])) { 487 $entry = $cachedLDAP->getEntryByID($result[$i]['funcionario_id']); 488 489 $employee['removed'] = is_null($entry['last_update']); 490 491 if ($entry && !empty($entry['cn'])) 492 $employee['cn'] = $entry['cn']; 493 /* we cant find it anywhere */ 494 else 495 $employee['cn'] = $result[$i]['funcionario_id']; 412 496 } 413 497 else 414 { 415 $employees[$i]['cn'] = $employees[$i]['funcionario_id']; 416 $employees[$i]['telephoneNumber'] = ''; 417 418 $output['bygroup'][ $employees[$i]['funcionario_id'] ] = $employees[ $i ]; 419 array_splice( $employees, $i--, 1 ); 420 } 421 } 422 423 if ( count( $output['bygroup'] ) ) 424 { 425 $list = ldap_search($ldap, $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(|(uidNumber=' . implode( ')(uidNumber=', array_keys( $output['bygroup'] ) ) . '))(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber')); 426 427 if ( $list !== false ) 428 { 429 $entries = ldap_get_entries($ldap, $list); 430 431 for ( $i = 0; $i < $entries[ 'count' ]; $i++ ) 432 { 433 $output[ 'bygroup' ][ $entries[$i]['uidnumber'][0] ][ 'cn' ] = $entries[$i]['cn'][0]; 434 $output[ 'bygroup' ][ $entries[$i]['uidnumber'][0] ][ 'telephoneNumber' ] = $entries[$i]['telephonenumber'][0]; 435 } 436 } 437 } 438 439 $output[ 'bygroup' ] = array_values( $output[ 'bygroup' ] ); 440 $output[ 'employees' ] = $employees; 441 442 return $output; 443 } 498 $employee['cn'] = $ldapResult[$result[$i]['funcionario_id']]['cn']; 499 500 $employee['area'] = $result[$i]['area']; 501 $employee['area_id'] = $result[$i]['area_id']; 502 $employee['funcionario_id'] = $result[$i]['funcionario_id']; 503 $employee['telephoneNumber'] = empty($ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']) ? '': $ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']; 504 505 $employees []= $employee; 506 } 507 508 /* sorting by name (cn) */ 509 $sort_function = create_function('$a, $b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);'); 510 usort($employees, $sort_function ); 511 512 return $employees; 513 } 514 515 /** 516 * Search Employee by Telephone 517 * @param int $searchTerm term to search 518 * @param int $organizationID Id of organization 519 * @return array employee data information 520 * @access public 521 */ 522 function searchEmployeeByTelephone($searchTerm, $organizationID) 523 { 524 /* we will just excute it if we just get numbers and '-' */ 525 if (!preg_match('/^[0-9-]+$/', $searchTerm)) 526 return array(); 527 528 /* get ldap connection */ 529 $ldap = &Factory::getInstance('WorkflowObjects')->getLDAP(); 530 531 /* searching employees by telephoneNumber in the ldap server */ 532 $list = @ldap_search($ldap, Factory::getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(telephoneNumber=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber')); 533 534 if (!$list) return false; 535 536 /* parsing ldap result */ 537 $entries = ldap_get_entries($ldap, $list); 538 $ldapResult = array(); 539 540 for ($i = 0; $i < $entries['count']; $i++) 541 $ldapResult[$entries[$i]['uidnumber'][0]] = array('cn' => $entries[$i]['cn'][0], 'telephoneNumber' => $entries[$i]['telephonenumber'][0]); 542 543 /* no records found. bye. */ 544 if (count($ldapResult) == 0) 545 return array(); 546 547 $uids = implode( ',', array_keys( $ldapResult ) ); 548 549 /* searching for aditional employee information */ 550 $query = "SELECT "; 551 $query .= " f.funcionario_id AS funcionario_id, f.area_id AS area_id, a.sigla AS area "; 552 $query .= " FROM "; 553 $query .= " funcionario f "; 554 $query .= " INNER JOIN "; 555 $query .= " area a USING (area_id) "; 556 $query .= " INNER JOIN "; 557 $query .= " funcionario_status s ON ((f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = 'S')) "; 558 $query .= " WHERE "; 559 $query .= " (f.organizacao_id = ?) "; 560 $query .= " AND "; 561 $query .= " (f.funcionario_id IN ({$uids})) "; 562 563 $result = $this->db->query($query, array($organizationID))->GetArray(-1); 564 $employees = array(); 565 566 /* filling return array with employee's information */ 567 for ($i = 0; $i < count($result); $i++) { 568 $employees []= array( 569 'area' => $result[$i]['area'], 570 'area_id' => $result[$i]['area_id'], 571 'funcionario_id' => $result[$i]['funcionario_id'], 572 'cn' => $ldapResult[$result[$i]['funcionario_id']]['cn'], 573 'telephoneNumber' => empty($ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']) ? '': $ldapResult[$result[$i]['funcionario_id']]['telephoneNumber'] 574 ); 575 } 576 577 /* sorting by name (cn) */ 578 $sort_function = create_function('$a, $b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);'); 579 usort($employees, $sort_function ); 580 581 return $employees; 582 } 583 444 584 445 585 /** … … 453 593 function getEmployeeInfo($employeeID, $organizationID) 454 594 { 455 require_once dirname(__FILE__) . '/class.so_orgchart.inc.php'; 456 457 $SOOrgchart = new so_orgchart(); 595 $SOOrgchart = &Factory::getInstance('so_orgchart'); 458 596 $SOOrgchart->setExternalCalls(true); 459 597 $output = $SOOrgchart->getEmployeeInfo($employeeID, $organizationID); … … 473 611 function getAreaInfo($areaID, $organizationID) 474 612 { 475 require_once dirname(__FILE__) . '/class.so_orgchart.inc.php'; 476 477 $SOOrgchart = new so_orgchart(); 613 $SOOrgchart = &Factory::getInstance('so_orgchart'); 478 614 $SOOrgchart->setExternalCalls(true); 479 615 $output = $SOOrgchart->getAreaInfo($areaID, $organizationID); … … 509 645 function getAreaWithSubtituteBoss( $organizationID ) 510 646 { 511 $result = $this -> db -> query( "SELECT sigla as area, titular_funcionario_id as titular, substituto_funcionario_id as substituto FROM area WHERE (organizacao_id = ?) and substituto_funcionario_id is not nullORDER BY area", array( $organizationID ) );512 513 $cachedLDAP = $GLOBALS[ 'workflow' ][ 'factory' ] ->newInstance( 'CachedLDAP' );647 $result = $this -> db -> query( "SELECT a.sigla as area, a.titular_funcionario_id as titular, s.funcionario_id as substituto, s.data_inicio, s.data_fim FROM area a INNER JOIN substituicao s ON ((a.area_id = s.area_id) AND (CURRENT_DATE BETWEEN s.data_inicio AND s.data_fim)) WHERE (organizacao_id = ?) ORDER BY area", array( $organizationID ) ); 648 649 $cachedLDAP = Factory::newInstance( 'CachedLDAP' ); 514 650 $cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_LDAP_DATABASE ); 515 651 … … 527 663 if ( $entry && ( ! is_null( $entry[ 'cn' ] ) ) ) 528 664 $output[ $i ][ 'substituto' ] = $entry[ 'cn' ]; 665 666 $output[$i]['data_inicio'] = implode('/', array_reverse(explode('-', $output[$i]['data_inicio']))); 667 $output[$i]['data_fim'] = implode('/', array_reverse(explode('-', $output[$i]['data_fim']))); 529 668 } 530 669 … … 575 714 576 715 $employees = $result -> GetArray( -1 ); 577 $cachedLDAP = $GLOBALS[ 'workflow' ][ 'factory' ] ->newInstance( 'CachedLDAP' );716 $cachedLDAP = Factory::newInstance( 'CachedLDAP' ); 578 717 $cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_NORMAL ); 579 718 … … 647 786 $employees = $result -> GetArray( -1 ); 648 787 649 $cachedLDAP = $GLOBALS[ 'workflow' ][ 'factory' ] ->newInstance( 'CachedLDAP' );788 $cachedLDAP = Factory::newInstance( 'CachedLDAP' ); 650 789 $cachedLDAP -> setOperationMode( $cachedLDAP -> OPERATION_MODE_NORMAL ); 651 790 … … 673 812 usort( $employees, create_function( '$a,$b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);' ) ); 674 813 675 $paging = $GLOBALS['workflow']['factory']->newInstance('Paging', 50, $_POST);814 $paging = Factory::newInstance('Paging', 50, $_POST); 676 815 $employees = $paging->restrictItems( $employees ); 677 816
Note: See TracChangeset
for help on using the changeset viewer.