Changeset 2085


Ignore:
Timestamp:
02/26/10 10:56:36 (14 years ago)
Author:
pedroerp
Message:

Ticket #928 - Adicionando suporte a buscas por telefone no organograma.

Location:
trunk/workflow
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/workflow/inc/class.bo_userinterface.inc.php

    r1470 r2085  
    927927                        return $checkWarnings; 
    928928 
    929                 $result = $this->so->searchEmployee($params['searchTerm'], $this->organizationInfo['organizacao_id']); 
    930                 $this->disconnect_all(); 
    931  
    932                 if ($result === false) 
     929                $result = array(); 
     930 
     931                /* do the search */ 
     932                $result['bytelephone'] = $this->so->searchEmployeeByTelephone($params['searchTerm'], $this->organizationInfo['organizacao_id']); 
     933                $result['employees'] = $this->so->searchEmployeeByName($params['searchTerm'], $this->organizationInfo['organizacao_id']); 
     934                $result['bygroup'] = $this->so->searchEmployeeByArea($params['searchTerm'], $this->organizationInfo['organizacao_id']); 
     935 
     936                $this->disconnect_all(); 
     937 
     938                /* if all searches returned false */ 
     939                if (!is_array($result['employees']) and 
     940                        !is_array($result['bygroup']) and 
     941                        !is_array($result['bytelephone'])) 
    933942                        return array('error' => 'O sistema de busca não pode ser utilizado para sua organização'); 
    934  
    935                 $sort_function = create_function('$a,$b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);'); 
    936  
    937                 usort($result['employees'], $sort_function ); 
    938                 usort($result['bygroup'], $sort_function ); 
    939943 
    940944                return $result; 
  • trunk/workflow/inc/class.so_userinterface.inc.php

    r2056 r2085  
    343343 
    344344        /** 
    345          * Search Employee 
     345         * Search Employee by Name 
    346346         * @param int $searchTerm term to search 
    347347         * @param int $organizationID  Id of organization 
     
    349349         * @access public 
    350350         */ 
    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 */ 
     351        function searchEmployeeByName($searchTerm, $organizationID) 
     352        { 
     353                /* get ldap connection */ 
    358354                $ldap = &$GLOBALS['workflow']['workflowObjects']->getLDAP(); 
    359355 
     
    361357                $fullSearch = false; 
    362358 
    363                 if(count($searchTermExploded) > 0){ 
    364                         for($i=1; $i<count($searchTermExploded); $i++){ 
    365                                 if(strlen($searchTermExploded[$i]) > 2){ 
     359                if (count($searchTermExploded) > 0){ 
     360                        for ($i=1; $i<count($searchTermExploded); $i++) { 
     361                                if (strlen($searchTermExploded[$i]) > 2) { 
    366362                                        $fullSearch = true; 
    367363                                } 
    368364                        } 
    369365 
    370                         if($fullSearch){ 
     366                        if ($fullSearch){ 
    371367                                $searchTerm = implode("*", $searchTermExploded); 
    372368                        } 
    373369                } 
    374370 
     371                /* searching employees by name in the ldap server */ 
    375372                $list = @ldap_search($ldap, $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(cn=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber')); 
    376373                if ($list === false) 
    377374                        return false; 
    378375 
     376                /* parsing ldap result */ 
    379377                $entries = ldap_get_entries($ldap, $list); 
    380                 $employeesID = array(); 
     378                $ldapResult = array(); 
     379 
    381380                for ($i = 0; $i < $entries['count']; $i++) 
    382381                        $ldapResult[$entries[$i]['uidnumber'][0]] = array('cn' => $entries[$i]['cn'][0], 'telephoneNumber' => $entries[$i]['telephonenumber'][0]); 
    383382 
     383                /* no records found. bye. */ 
     384                if (count($ldapResult) == 0) 
     385                        return array(); 
     386 
    384387                $uids = implode( ',', array_keys( $ldapResult ) ); 
    385388 
    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']; 
    412                         } 
    413                         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         } 
     389                /* searching for aditional employee information */ 
     390                $query  = "SELECT "; 
     391                $query .= "             f.funcionario_id AS funcionario_id, f.area_id AS area_id, a.sigla AS area "; 
     392                $query .= " FROM "; 
     393                $query .= "                     funcionario f "; 
     394                $query .= "             INNER JOIN "; 
     395                $query .= "                     area a USING (area_id) "; 
     396                $query .= "             INNER JOIN "; 
     397                $query .= "                     funcionario_status s ON ((f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = 'S')) "; 
     398                $query .= " WHERE "; 
     399                $query .= "             (f.organizacao_id = ?) "; 
     400                $query .= "     AND "; 
     401                $query .= "             (f.funcionario_id IN ({$uids})) "; 
     402 
     403                $result = $this->db->query($query, array($organizationID))->GetArray(-1); 
     404                $employees = array(); 
     405 
     406                /* filling return array with employee's information */ 
     407                for ($i = 0; $i < count($result); $i++) { 
     408                        $employees []= array( 
     409                                        'area'                          => $result[$i]['area'], 
     410                                        'area_id'                       => $result[$i]['area_id'], 
     411                                        'funcionario_id'        => $result[$i]['funcionario_id'], 
     412                                        'cn'                            => $ldapResult[$result[$i]['funcionario_id']]['cn'], 
     413                                        'telephoneNumber'       => empty($ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']) ? '': $ldapResult[$result[$i]['funcionario_id']]['telephoneNumber'] 
     414                        ); 
     415                } 
     416 
     417                /* sorting by name (cn) */ 
     418        $sort_function = create_function('$a, $b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);'); 
     419        usort($employees, $sort_function ); 
     420 
     421                return $employees; 
     422        } 
     423 
     424        /** 
     425         * Search Employee by Area 
     426         * @param int $searchTerm term to search 
     427         * @param int $organizationID  Id of organization 
     428         * @return array employee data information 
     429         * @access public 
     430         */ 
     431        function searchEmployeeByArea($searchTerm, $organizationID) 
     432        { 
     433                /* get ldap connection */ 
     434                $ldap = &$GLOBALS['workflow']['workflowObjects']->getLDAP(); 
     435 
     436                /* makes no sense search for an area if the string has more than one word */ 
     437                if (count(explode(" ", $searchTerm)) > 1) 
     438                        return array(); 
     439 
     440                /* searching for employees in areas that match 'searchTerm' */ 
     441                $query  = "SELECT "; 
     442                $query .= "             f.funcionario_id AS funcionario_id, f.area_id AS area_id, a.sigla AS area "; 
     443                $query .= " FROM "; 
     444                $query .= "                     funcionario f "; 
     445                $query .= "             INNER JOIN "; 
     446                $query .= "                     area a USING (area_id) "; 
     447                $query .= "             INNER JOIN "; 
     448                $query .= "                     funcionario_status s ON ((f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = 'S')) "; 
     449                $query .= " WHERE "; 
     450                $query .= "             (f.organizacao_id = ?) "; 
     451                $query .= "     AND "; 
     452                $query .= "             (UPPER(a.sigla) LIKE UPPER(?)) "; 
     453 
     454                $result = $this->db->query($query, array($organizationID, '%'.$searchTerm.'%'))->GetArray(-1); 
     455         
     456                /* no records found. bye */ 
     457                if (count($result) == 0) 
     458                        return array(); 
     459 
     460                /* creating the ldap query */ 
     461                $ldap_query = '(&(|'; 
     462                for ($i = 0; $i < count($result); $i++) { 
     463                        $ldap_query .= '(uidNumber=' . $result[$i]['funcionario_id'] . ')'; 
     464                } 
     465                $ldap_query .= ')(phpgwAccountType=u))'; 
     466 
     467                /* executing it */ 
     468                $list = @ldap_search($ldap, $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getLDAPContext(), $ldap_query, array('uidNumber', 'cn', 'telephoneNumber')); 
     469                $entries = ldap_get_entries($ldap, $list); 
     470 
     471                /* parsing result */ 
     472                $ldapResult = array(); 
     473                for ($i = 0; $i < $entries['count']; $i++) 
     474                        $ldapResult[$entries[$i]['uidnumber'][0]] = array('cn' => $entries[$i]['cn'][0], 'telephoneNumber' => $entries[$i]['telephonenumber'][0]); 
     475 
     476                /* filling return array with employee's information */ 
     477                $employees = array(); 
     478                for ($i = 0; $i < count($result); $i++) { 
     479                        $employees []= array( 
     480                                        'area'                          => $result[$i]['area'], 
     481                                        'area_id'                       => $result[$i]['area_id'], 
     482                                        'funcionario_id'        => $result[$i]['funcionario_id'], 
     483                                        'cn'                            => empty($ldapResult[$result[$i]['funcionario_id']]['cn']) ? $result[$i]['funcionario_id'] : $ldapResult[$result[$i]['funcionario_id']]['cn'], 
     484                                        'telephoneNumber'       => empty($ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']) ? '': $ldapResult[$result[$i]['funcionario_id']]['telephoneNumber'] 
     485                        ); 
     486                } 
     487 
     488                /* sorting by name (cn) */ 
     489        $sort_function = create_function('$a, $b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);'); 
     490        usort($employees, $sort_function ); 
     491 
     492                return $employees; 
     493        } 
     494 
     495        /** 
     496         * Search Employee by Telephone 
     497         * @param int $searchTerm term to search 
     498         * @param int $organizationID  Id of organization 
     499         * @return array employee data information 
     500         * @access public 
     501         */ 
     502        function searchEmployeeByTelephone($searchTerm, $organizationID) 
     503        { 
     504                /* we will just excute it if we just get numbers and '-' */ 
     505                if (!preg_match('/^[0-9-]+$/', $searchTerm)) 
     506                        return array(); 
     507 
     508                /* get ldap connection */ 
     509                $ldap = &$GLOBALS['workflow']['workflowObjects']->getLDAP(); 
     510 
     511                /* searching employees by telephoneNumber in the ldap server */ 
     512                $list = @ldap_search($ldap, $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getLDAPContext(), ('(&(telephoneNumber=*' . $searchTerm . '*)(phpgwaccounttype=u))'), array('uidNumber', 'cn', 'telephoneNumber')); 
     513 
     514                if (!$list) return false; 
     515 
     516                /* parsing ldap result */ 
     517                $entries = ldap_get_entries($ldap, $list); 
     518                $ldapResult = array(); 
     519 
     520                for ($i = 0; $i < $entries['count']; $i++) 
     521                        $ldapResult[$entries[$i]['uidnumber'][0]] = array('cn' => $entries[$i]['cn'][0], 'telephoneNumber' => $entries[$i]['telephonenumber'][0]); 
     522 
     523                /* no records found. bye. */ 
     524                if (count($ldapResult) == 0) 
     525                        return array(); 
     526 
     527                $uids = implode( ',', array_keys( $ldapResult ) ); 
     528 
     529                /* searching for aditional employee information */ 
     530                $query  = "SELECT "; 
     531                $query .= "             f.funcionario_id AS funcionario_id, f.area_id AS area_id, a.sigla AS area "; 
     532                $query .= " FROM "; 
     533                $query .= "                     funcionario f "; 
     534                $query .= "             INNER JOIN "; 
     535                $query .= "                     area a USING (area_id) "; 
     536                $query .= "             INNER JOIN "; 
     537                $query .= "                     funcionario_status s ON ((f.funcionario_status_id = s.funcionario_status_id) AND (s.exibir = 'S')) "; 
     538                $query .= " WHERE "; 
     539                $query .= "             (f.organizacao_id = ?) "; 
     540                $query .= "     AND "; 
     541                $query .= "             (f.funcionario_id IN ({$uids})) "; 
     542 
     543                $result = $this->db->query($query, array($organizationID))->GetArray(-1); 
     544                $employees = array(); 
     545 
     546                /* filling return array with employee's information */ 
     547                for ($i = 0; $i < count($result); $i++) { 
     548                        $employees []= array( 
     549                                        'area'                          => $result[$i]['area'], 
     550                                        'area_id'                       => $result[$i]['area_id'], 
     551                                        'funcionario_id'        => $result[$i]['funcionario_id'], 
     552                                        'cn'                            => $ldapResult[$result[$i]['funcionario_id']]['cn'], 
     553                                        'telephoneNumber'       => empty($ldapResult[$result[$i]['funcionario_id']]['telephoneNumber']) ? '': $ldapResult[$result[$i]['funcionario_id']]['telephoneNumber'] 
     554                        ); 
     555                } 
     556 
     557                /* sorting by name (cn) */ 
     558        $sort_function = create_function('$a, $b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);'); 
     559        usort($employees, $sort_function ); 
     560 
     561                return $employees; 
     562        } 
     563 
    444564 
    445565        /** 
  • trunk/workflow/js/userinterface/orgchart.js

    r2042 r2085  
    4545        content += '</select></a></li>'; 
    4646        content += '<li><a href="#" onclick="window.open(\'' + enderecoImagem + '\', \'extwindow\'); return false;"><img src="templateFile.php?file=images/Process.gif">&nbsp;&nbsp;Gráfico</a></li>'; 
    47         content += '<li><a><input type="text" name="search_term" id="search_term" onkeypress="if (((event.which) ? event.which : event.keyCode) == 13) $(\'search_span\').onclick(); return true;" /><span id="search_span" style="cursor: pointer;" onclick="tmp = $$(\'div#orgchartAreas a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); orgchartSearchEmployee($F(\'search_term\')); return false;">&nbsp;busca</span></a></li>'; 
     47        content += '<li><a><input type="text" name="search_term" id="search_term" onkeypress="if (((event.which) ? event.which : event.keyCode) == 13) $(\'search_span\').onclick(); return true;" /><span id="search_span" style="cursor: pointer;" onclick="tmp = $$(\'div#orgchartAreas a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); orgchartSearchEmployee($F(\'search_term\')); return false;">&nbsp;busca&nbsp;</span><img src="templateFile.php?file=images/help.png" title="Informe o nome, área ou telefone a ser pesquisado." style="cursor: help" /></a></li>'; 
    4848        content += '<li><a href="#" onclick="printArea(); return false;"><img src="templateFile.php?file=images/imprimir.png" width="16">&nbsp;&nbsp;Imprimir</a></li>'; 
    4949        content += '</ul>'; 
     
    296296 
    297297        /* no employee to list */ 
    298         if ( ( ! data['employees'] || data['employees'].length == 0 ) && ( ! data['bygroup'] || data['bygroup'].length == 0 ) ) 
     298        if ( ( ! data['employees'] || data['employees'].length == 0 ) &&  
     299                 ( ! data['bygroup'] || data['bygroup'].length == 0 ) && 
     300                 ( ! data['bytelephone'] || data['bytelephone'].length == 0 ) ) 
    299301        { 
    300302                div.innerHTML = '<br/><br/><center><strong>Nenhum registro encontrado</strong></center>'; 
     
    479481                        div.innerHTML += '</center><span style="color:red">Busca pelo nome: ' + searchTerm.toUpperCase( ) + '</span>' + content; 
    480482 
     483                // printing records found by group 
    481484                if ( data['bygroup'] && data['bygroup'].length ) 
    482485                { 
     
    486489                        if ( content ) 
    487490                                div.innerHTML += '<br/><br/><span style="color:red">Busca pelo setor: ' + searchTerm.toUpperCase( ) + '</span><br/>' + content; 
     491                } 
     492 
     493                // printing records found by telephoneNumber 
     494                if ( data['bytelephone'] && data['bytelephone'].length ) 
     495                { 
     496                        employees = [ ]; 
     497                        employees[ 'employees' ] = data['bytelephone']; 
     498                        content = printEmployeesHandler( employees, 'returnResult' ); 
     499                        if ( content ) 
     500                                div.innerHTML += '<br/><br/><span style="color:red">Busca pelo telefone: ' + searchTerm.toUpperCase( ) + '</span><br/>' + content; 
    488501                } 
    489502 
Note: See TracChangeset for help on using the changeset viewer.