Ignore:
Timestamp:
10/08/13 16:20:46 (11 years ago)
Author:
douglas
Message:

Ticket #0000 - Copiadas as alterações do Trunk. Versão final 2.5.1.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5/prototype/modules/calendar/interceptors/DBMapping.php

    r8059 r8232  
    164164 
    165165    public function encodeSignatureAlarmType(&$uri, &$params, &$criteria, $original) { 
    166             $params['type'] = self::codeAlarmType($params['type']);  
    167     }  
    168   
    169     public function schedulableSecurity(&$uri, &$params, &$criteria, $original)  
     166            $params['type'] = self::codeAlarmType($params['type']); 
     167    } 
     168 
     169    public function schedulableSecurity(&$uri, &$params, &$criteria, $original) 
    170170    { 
    171   
    172         if( !isset($criteria['filter'][1]) || !$criteria['filter'][1] == 'uid')  
    173         {  
    174             $security = 'schedulable.id = calendarToSchedulable.schedulable';  
    175             $security .= ' AND calendar.id = calendarToSchedulable.calendar';  
    176             $security .= ' AND calendar.id = calendarSignature.calendar';  
    177             $security .= ' AND calendarSignature.user = ' . base64_encode(Config::me('uidNumber'));  
    178   
    179             $criteria['condition'] = $security;  
    180         }  
    181    
    182     }  
    183   
    184     public function calendarSecurity(&$uri, &$params, &$criteria, $original)  
    185     {  
    186         $security = 'calendar.id = calendarSignature.calendar';  
    187         $security .= ' AND calendarSignature.user = ' . base64_encode(Config::me('uidNumber'));  
    188   
    189         $criteria['condition'] = $security;  
    190     }  
    191   
    192     public function calendarSignatureSecurity(&$uri, &$params, &$criteria, $original)  
    193     {  
    194 //        $security = 'calendarSignature.user = ' . base64_encode(Config::me('uidNumber'));  
    195 //  
    196 //        $criteria['condition'] = $security;  
     171 
     172        if( !isset($criteria['filter'][1]) || !$criteria['filter'][1] == 'uid') 
     173        { 
     174            $security = 'schedulable.id = calendarToSchedulable.schedulable'; 
     175            $security .= ' AND calendar.id = calendarToSchedulable.calendar'; 
     176            $security .= ' AND calendar.id = calendarSignature.calendar'; 
     177            $security .= ' AND calendarSignature.user = ' . base64_encode(Config::me('uidNumber')); 
     178 
     179            $criteria['condition'] = $security; 
     180        } 
     181 
     182    } 
     183 
     184    public function calendarSecurity(&$uri, &$params, &$criteria, $original) 
     185    { 
     186        $security = 'calendar.id = calendarSignature.calendar'; 
     187        $security .= ' AND calendarSignature.user = ' . base64_encode(Config::me('uidNumber')); 
     188 
     189        $criteria['condition'] = $security; 
     190    } 
     191 
     192    public function calendarSignatureSecurity(&$uri, &$params, &$criteria, $original) 
     193    { 
     194//        $security = 'calendarSignature.user = ' . base64_encode(Config::me('uidNumber')); 
     195// 
     196//        $criteria['condition'] = $security; 
    197197    } 
    198198 
     
    347347        if (isset($original['properties']['exceptions'])) { 
    348348            $exceptions = explode(',', $original['properties']['exceptions']); 
    349             $event = Controller::read(array('concept' => 'schedulable', 'id' => $repeat['schedulable']));  
    350   
    351         if(array_key_exists(0, $event)) $event = $event[0];  
    352   
    353         $date = new DateTime('now', new DateTimeZone('UTC'));  
    354   
    355         foreach($exceptions as &$e){  
    356             $date->setTimestamp((int) ($e / 1000));  
    357             $date->setTimezone( new DateTimeZone( $event['timezone'] ));  
    358             $e = ($date->getTimestamp() - $date->getOffset()).'000';  
    359         }  
    360   
    361         unset($repeat['exceptions']);  
     349            $event = Controller::read(array('concept' => 'schedulable', 'id' => $repeat['schedulable'])); 
     350 
     351        if(array_key_exists(0, $event)) $event = $event[0]; 
     352 
     353        $date = new DateTime('now', new DateTimeZone('UTC')); 
     354 
     355        foreach($exceptions as &$e){ 
     356            $date->setTimestamp((int) ($e / 1000)); 
     357            $date->setTimezone( new DateTimeZone( $event['timezone'] )); 
     358            $e = ($date->getTimestamp() - $date->getOffset()).'000'; 
     359        } 
     360 
     361        unset($repeat['exceptions']); 
    362362        } 
    363363 
    364     unset($repeat['schedulable']);  
    365   
    366     $lastExceptions = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('AND', array('=', 'repeat', $id), array('=', 'exception', 1))));  
     364    unset($repeat['schedulable']); 
     365 
     366    $lastExceptions = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('AND', array('=', 'repeat', $id), array('=', 'exception', 1)))); 
    367367 
    368368        //Recurepa as execeções anteriores caso exista 
     
    379379        else if(!empty($exceptions)) 
    380380            Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_repeat_occurrence(repeat_id,exception,occurrence)VALUES ('" . $id . "','1','" . implode("'),('" . $id . "','1','", $exceptions) . "')" ); 
    381     }  
     381    } 
    382382 
    383383    public function checkOccurrences($start, $end, $calendarIds) { 
     
    428428 
    429429            foreach ($result as $id => $res){ 
    430   
    431             $ocurrences = array_unique($res);  
    432   
    433             /*  
    434              * Check current range decoded  
    435              * */  
    436             $current = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('=', 'repeat', $id)));  
    437             $toDiff = array();  
    438   
    439             if(!empty($current))  
    440                 foreach($current as $c) $toDiff[] = $c['occurrence'];  
    441   
    442             $ocurrences = array_diff($ocurrences, $toDiff);  
    443   
    444             if(!empty($ocurrences))  
     430 
     431            $ocurrences = array_unique($res); 
     432 
     433            /* 
     434             * Check current range decoded 
     435             * */ 
     436            $current = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('=', 'repeat', $id))); 
     437            $toDiff = array(); 
     438 
     439            if(!empty($current)) 
     440                foreach($current as $c) $toDiff[] = $c['occurrence']; 
     441 
     442            $ocurrences = array_diff($ocurrences, $toDiff); 
     443 
     444            if(!empty($ocurrences)) 
    445445                Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_repeat_occurrence(repeat_id,occurrence)VALUES('" . $id . "','" . implode("'),('" . $id . "', '", $ocurrences) . "')"); 
    446   
    447         }  
     446 
     447        } 
    448448            $data = array(); 
    449449 
     
    471471        $result = array(); 
    472472        $params = array(); 
    473     $realResult = array();  
     473    $realResult = array(); 
    474474        foreach ($return as $ret) { 
    475475            $currentId = $ret['schedulable']; 
     
    483483        } 
    484484 
    485     foreach($result as $i => $v)  
    486     {  
    487         $calendarToCalendarObj = self::schedulable2calendarToObject($v['id']);  
    488             foreach($calendarToCalendarObj as $vv)  
    489             {  
    490                 $v['calendar'] = $vv['calendar_id'];  
    491                 $realResult[] = $v;  
    492             }  
    493     }  
    494   
    495         return( $realResult );  
     485    foreach($result as $i => $v) 
     486    { 
     487        $calendarToCalendarObj = self::schedulable2calendarToObject($v['id']); 
     488            foreach($calendarToCalendarObj as $vv) 
     489            { 
     490                $v['calendar'] = $vv['calendar_id']; 
     491                $realResult[] = $v; 
     492            } 
     493    } 
     494 
     495        return( $realResult ); 
    496496    } 
    497497 
     
    633633            //necessário para atulizar a atividade de composta pela tarefa aqui sendo atualizada 
    634634            if(isset($criteria['historic']['startTime']) || isset($criteria['historic']['endTime'])){ 
    635                 /*  
    636                  * Verify current task is built-in activity  
    637                  * */  
     635                /* 
     636                 * Verify current task is built-in activity 
     637                 * */ 
    638638                $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'task', $uri['id']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2)); 
    639639                if(!empty($taskToActivity)){ 
     
    641641                    $isAllDay = 1; 
    642642 
    643                     /*  
    644                      * Get all task in activity  
    645                      * */  
    646                     $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'activity', $taskToActivity[0]['activity']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2));  
    647   
     643                    /* 
     644                     * Get all task in activity 
     645                     * */ 
     646                    $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'activity', $taskToActivity[0]['activity']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2)); 
     647 
    648648                    if(!empty($activity)){ 
    649649                        $start = $params['startTime']; 
    650650                        $end = $params['endTime']; 
    651651                        foreach($taskToActivity as $t){ 
    652   
    653   
    654                             if($t['task']['id'] != $params['id']){  
    655                                 $start = $t['task']['startTime'] < $start ? $t['task']['startTime'] : $start;  
    656                                 $end = $t['task']['endTime'] > $end ? $t['task']['endTime'] : $end;  
    657                                 $isAllDay = (($isAllDay == 1) && ($t['task']['allDay'] == '1')) ? 1 : 0;  
    658                             }  
     652 
     653 
     654                            if($t['task']['id'] != $params['id']){ 
     655                                $start = $t['task']['startTime'] < $start ? $t['task']['startTime'] : $start; 
     656                                $end = $t['task']['endTime'] > $end ? $t['task']['endTime'] : $end; 
     657                                $isAllDay = (($isAllDay == 1) && ($t['task']['allDay'] == '1')) ? 1 : 0; 
     658                            } 
    659659                        } 
    660660 
     
    680680                } 
    681681            } 
    682             /*  
    683              * Clean historic not used  
    684              * */  
     682            /* 
     683             * Clean historic not used 
     684             * */ 
    685685            unset($criteria['historic']['endTime']); 
    686686            unset($criteria['historic']['rangeEnd']); 
     
    771771            } 
    772772        } 
    773     }  
    774   
    775     static function autoImportCalendar(&$uri, &$params, &$criteria, $original){  
    776         $autoCommit = Controller::service('PostgreSQL')->execResultSql('Select config_value FROM phpgw_config WHERE config_app = \'expressoCalendar\' AND config_name = \'expressoCalendar_autoImportCalendars\'');  
    777   
    778   
    779         if(isset($autoCommit[0]) && $autoCommit[0]['config_value'] == 'true')  
    780         {  
    781             if(isset($original['properties']) && isset($original['properties']['user'])  && isset($original['properties']['isOrganizer']) &&  $original['properties']['isOrganizer'] != '1')  
    782             {  
    783                 $defaultCalendar = Controller::find(array('concept' => 'modulePreference'), array('value') , array('filter' => array( 'and' , array('=' , 'name' , 'dafaultImportCalendar') , array('=' , 'module' , 'expressoCalendar') , array('=' , 'user' , $original['properties']['user'])  )) );  
    784                 if(isset($defaultCalendar[0]) && $defaultCalendar[0]['value'] > 0)  
    785                 {  
    786                     Controller::create(array('concept' => 'calendarToSchedulable'),  
    787                         array('schedulable' => $original['properties']['schedulable'],  
    788                             'calendar' => $defaultCalendar[0]['value']  
    789                         )  
    790                     );  
    791                 }  
    792             }  
    793         }  
     773    } 
     774 
     775    static function autoImportCalendar(&$uri, &$params, &$criteria, $original){ 
     776        $autoCommit = Controller::service('PostgreSQL')->execResultSql('Select config_value FROM phpgw_config WHERE config_app = \'expressoCalendar\' AND config_name = \'expressoCalendar_autoImportCalendars\''); 
     777 
     778 
     779        if(isset($autoCommit[0]) && $autoCommit[0]['config_value'] == 'true') 
     780        { 
     781            if(isset($original['properties']) && isset($original['properties']['user'])  && isset($original['properties']['isOrganizer']) &&  $original['properties']['isOrganizer'] != '1') 
     782            { 
     783                $defaultCalendar = Controller::find(array('concept' => 'modulePreference'), array('value') , array('filter' => array( 'and' , array('=' , 'name' , 'dafaultImportCalendar') , array('=' , 'module' , 'expressoCalendar') , array('=' , 'user' , $original['properties']['user'])  )) ); 
     784                if(isset($defaultCalendar[0]) && $defaultCalendar[0]['value'] > 0) 
     785                { 
     786                    Controller::create(array('concept' => 'calendarToSchedulable'), 
     787                        array('schedulable' => $original['properties']['schedulable'], 
     788                            'calendar' => $defaultCalendar[0]['value'] 
     789                        ) 
     790                    ); 
     791                } 
     792            } 
     793        } 
    794794    } 
    795795 
     
    913913    } 
    914914 
    915     public function getCalendarTask( $task ){  
    916   
    917         $sql = 'select co.calendar_id as "calendar" from calendar_to_calendar_object as "co", calendar_signature as "cs" where cs.user_uidnumber = '. Config::me('uidNumber')  
    918             .' AND cs.is_owner = 1 AND cs.calendar_id = co.calendar_id AND co.calendar_object_id = '. $task;  
    919   
    920   
    921         $returns = Controller::service('PostgreSQL')->execResultSql($sql);  
    922   
    923         return $returns[0]['calendar'];  
    924     }  
    925   
     915    public function getCalendarTask( $task ){ 
     916 
     917        $sql = 'select co.calendar_id as "calendar" from calendar_to_calendar_object as "co", calendar_signature as "cs" where cs.user_uidnumber = '. Config::me('uidNumber') 
     918            .' AND cs.is_owner = 1 AND cs.calendar_id = co.calendar_id AND co.calendar_object_id = '. $task; 
     919 
     920 
     921        $returns = Controller::service('PostgreSQL')->execResultSql($sql); 
     922 
     923        return $returns[0]['calendar']; 
     924    } 
     925 
    926926    //TODO: Remover apos suporte a deepness na api  
    927927    public function deepnessFindTask(&$uri, &$result, &$criteria, $original) { 
    928         if (isset($criteria['deepness']) && $criteria['deepness'] != 0){  
    929   
    930             foreach($result as &$value){  
    931   
     928        if (isset($criteria['deepness']) && $criteria['deepness'] != 0){ 
     929 
     930            foreach($result as &$value){ 
     931 
    932932                $value['task'] = Controller::read(array('concept' => 'schedulable', 'id' => $value['task'])); 
    933                 $value['task']['calendar'] = self::getCalendarTask( $value['task']['id'] );  
    934             }  
    935   
    936             return $result;  
    937         }  
     933                $value['task']['calendar'] = self::getCalendarTask( $value['task']['id'] ); 
     934            } 
     935 
     936            return $result; 
     937        } 
    938938    } 
    939939 
     
    972972                .'calendar_object.tzid as "timezone", calendar_to_calendar_object.calendar_id as "calendar" ' 
    973973                .'FROM calendar_object, calendar_to_calendar_object ' 
    974                 .'WHERE ( calendar_object.id = '. $criteria['schedulable'] .' AND calendar_to_calendar_object.calendar_object_id = calendar_object.id'  
    975                 .' AND calendar_to_calendar_object.calendar_id IN (select calendar_id from calendar_signature where calendar_signature.user_uidnumber = '. Config::me('uidNumber') .' )         )';  
     974                .'WHERE ( calendar_object.id = '. $criteria['schedulable'] .' AND calendar_to_calendar_object.calendar_object_id = calendar_object.id' 
     975                .' AND calendar_to_calendar_object.calendar_id IN (select calendar_id from calendar_signature where calendar_signature.user_uidnumber = '. Config::me('uidNumber') .' )         )'; 
    976976 
    977977            $params = Controller::service('PostgreSQL')->execResultSql($sql); 
    978   
    979             foreach( $params as &$event ){  
    980   
    981   
    982                 if(isset( $event['repeat'] ) && isset( $event['repeat']['id'] ) ){  
    983                     $occurrences = Controller::service('PostgreSQL')->execResultSql('SELECT DISTINCT occurrence FROM calendar_object as "c", calendar_repeat_occurrence as "o", calendar_repeat as "r" WHERE r.object_id = '. $event['id'] .' AND o.repeat_id = r.id ' );  
    984   
    985                     if($occurrences){  
    986                         $event['occurrences'] = array();  
    987   
    988                         foreach($occurrences as $o)  
    989                             $event['occurrences'][] = $o['occurrence'];  
    990                     }else  
    991                         unset( $event['occurrences'] );  
    992                 }  
    993             }  
     978 
     979            foreach( $params as &$event ){ 
     980 
     981 
     982                if(isset( $event['repeat'] ) && isset( $event['repeat']['id'] ) ){ 
     983                    $occurrences = Controller::service('PostgreSQL')->execResultSql('SELECT DISTINCT occurrence FROM calendar_object as "c", calendar_repeat_occurrence as "o", calendar_repeat as "r" WHERE r.object_id = '. $event['id'] .' AND o.repeat_id = r.id ' ); 
     984 
     985                    if($occurrences){ 
     986                        $event['occurrences'] = array(); 
     987 
     988                        foreach($occurrences as $o) 
     989                            $event['occurrences'][] = $o['occurrence']; 
     990                    }else 
     991                        unset( $event['occurrences'] ); 
     992                } 
     993            } 
    994994 
    995995            $params = self::deepnessFindEvent($uri, $params, $criteria, $original); 
     
    10471047                if(isset( $v['occurrences'] ) && count( $v['occurrences'] ) > 0){ 
    10481048 
    1049                     $date->setTimestamp((int) ($v['startTime'] / 1000));  
    1050                     $date->setTimezone( new DateTimeZone( $v['timezone'] ));  
    1051   
     1049                    $date->setTimestamp((int) ($v['startTime'] / 1000)); 
     1050                    $date->setTimezone( new DateTimeZone( $v['timezone'] )); 
     1051 
    10521052                    foreach( $result[$i]['occurrences'] as &$o){ 
    10531053 
    1054                         $o = ($o + $date->getOffset()).'000';  
     1054                        $o = ($o + $date->getOffset()).'000'; 
    10551055 
    10561056                    } 
     
    14211421 
    14221422            Controller::delete(array('concept' => 'calendar', 'id' => $signature['calendar'])); 
    1423   
    1424         $autoCommit = Controller::service('PostgreSQL')->execResultSql('Select config_value FROM phpgw_config WHERE config_app = \'expressoCalendar\' AND config_name = \'expressoCalendar_autoImportCalendars\'');  
    1425   
    1426         if(isset($autoCommit[0]) && $autoCommit[0]['config_value'] == 'true')  
    1427         {  
    1428             $defaultCalendar = Controller::find(array('concept' => 'modulePreference'), array('value','id') , array('filter' => array( 'and' , array('=' , 'name' , 'dafaultImportCalendar') , array('=' , 'module' , 'expressoCalendar') , array('=' , 'user' , $signature['user'])  )) );  
    1429   
    1430   
    1431             if(isset($defaultCalendar[0])  && $defaultCalendar[0]['value'] == $signature['calendar'] )  
    1432             {  
    1433                 Controller::delete(array('concept' => 'modulePreference', 'id' => $defaultCalendar[0]['id']));  
    1434             }  
    1435         }  
    1436   
    1437         $permissions = Controller::find(array('concept' => 'calendarToPermission'), array('id'), array('filter' => array('=', 'calendar', $signature['calendar'])));  
    1438   
     1423 
     1424        $autoCommit = Controller::service('PostgreSQL')->execResultSql('Select config_value FROM phpgw_config WHERE config_app = \'expressoCalendar\' AND config_name = \'expressoCalendar_autoImportCalendars\''); 
     1425 
     1426        if(isset($autoCommit[0]) && $autoCommit[0]['config_value'] == 'true') 
     1427        { 
     1428            $defaultCalendar = Controller::find(array('concept' => 'modulePreference'), array('value','id') , array('filter' => array( 'and' , array('=' , 'name' , 'dafaultImportCalendar') , array('=' , 'module' , 'expressoCalendar') , array('=' , 'user' , $signature['user'])  )) ); 
     1429 
     1430 
     1431            if(isset($defaultCalendar[0])  && $defaultCalendar[0]['value'] == $signature['calendar'] ) 
     1432            { 
     1433                Controller::delete(array('concept' => 'modulePreference', 'id' => $defaultCalendar[0]['id'])); 
     1434            } 
     1435        } 
     1436 
     1437        $permissions = Controller::find(array('concept' => 'calendarToPermission'), array('id'), array('filter' => array('=', 'calendar', $signature['calendar']))); 
     1438 
    14391439                if($permissions && count($permissions) > 0){ 
    14401440                        $ids = array(); 
     
    15831583                } 
    15841584 
    1585                 if($i == 0)  
    1586                 {  
    1587                     $pref = array();  
    1588                     $pref['user'] = $_SESSION['wallet']['user']['uidNumber'];  
    1589                     $pref['value'] = $calCreated['id'];  
    1590                     $pref['name'] = 'dafaultImportCalendar' ;  
    1591                     $pref['module'] = 'expressoCalendar';  
    1592                     Controller::create(array('concept' => 'modulePreference'), $pref);  
    1593                 }  
    1594   
     1585                if($i == 0) 
     1586                { 
     1587                    $pref = array(); 
     1588                    $pref['user'] = $_SESSION['wallet']['user']['uidNumber']; 
     1589                    $pref['value'] = $calCreated['id']; 
     1590                    $pref['name'] = 'dafaultImportCalendar' ; 
     1591                    $pref['module'] = 'expressoCalendar'; 
     1592                    Controller::create(array('concept' => 'modulePreference'), $pref); 
     1593                } 
     1594 
    15951595                } 
    15961596            } else { 
     
    16141614 
    16151615                $sigCreated = Controller::create(array('concept' => 'calendarSignature'), $sig); 
    1616   
    1617   
    1618             $pref = array();  
    1619             $pref['user'] = $_SESSION['wallet']['user']['uidNumber'];  
    1620             $pref['value'] = $calCreated['id'];  
    1621             $pref['name'] = 'dafaultImportCalendar' ;  
    1622             $pref['module'] = 'expressoCalendar';  
    1623             Controller::create(array('concept' => 'modulePreference'), $pref);  
    1624   
    1625   
     1616 
     1617 
     1618            $pref = array(); 
     1619            $pref['user'] = $_SESSION['wallet']['user']['uidNumber']; 
     1620            $pref['value'] = $calCreated['id']; 
     1621            $pref['name'] = 'dafaultImportCalendar' ; 
     1622            $pref['module'] = 'expressoCalendar'; 
     1623            Controller::create(array('concept' => 'modulePreference'), $pref); 
     1624 
     1625 
    16261626        } 
    16271627     
     
    16341634    //TODO - Criar conceito separado para participantes externos e remover o criterio notExternal 
    16351635    public function findExternalPaticipants(&$uri, &$result, &$criteria, $original) { 
    1636         if (Config::me('uidNumber') && !isset($criteria['notExternal'])) {  
    1637             $newuri['concept'] = 'user';  
    1638             $newuri['service'] = 'PostgreSQL';  
    1639   
    1640             $newCriteria = $original['criteria'];  
    1641             $valid = true;  
    1642   
    1643             $newCriteria['filter'] = array('AND', $newCriteria['filter'], array('=', 'owner', Config::me('uidNumber')));  
    1644             $externalUsers = Controller::find($newuri, $original['properties'] ? $original['properties'] : null, $newCriteria );  
    1645   
    1646             if (!is_array($result))  
    1647                 $result = array();  
    1648   
    1649             if (is_array($externalUsers)) {  
    1650                 foreach ($externalUsers as $i => $v)  
    1651                     $externalUsers[$i]['isExternal'] = '1';  
    1652             }  
    1653             else  
    1654                 $externalUsers = array();  
    1655   
    1656             $result = array_merge($result, $externalUsers);  
    1657   
    1658   
    1659             if(isset($original['criteria']['externalCatalogs']) &&  $original['criteria']['externalCatalogs'] == true)  
    1660             {  
    1661                 $externalCatalogs = self::findExternalCatalogContacts($original['criteria']['filter'][2]);  
    1662   
    1663                 foreach($externalCatalogs as $i => $v)  
    1664                 {  
    1665                     $exist = false;  
    1666                     foreach($result as $vv)  
    1667                     {  
    1668                         if($v['mail'] == $vv['mail'] )  
    1669                             $exist = true;  
    1670                     }  
    1671                     if(!$exist)  
    1672                         $result[] = $v;  
    1673                 }  
    1674             }  
    1675   
    1676   
    1677             if(isset($original['criteria']['personalContacts']) &&  $original['criteria']['personalContacts'] == true)  
    1678             {  
    1679                 $personalContacts = self::findPersonalContacts($original['criteria']['filter'][2]);  
    1680   
    1681                 foreach($personalContacts as $i => $v)  
    1682                 {  
    1683                     $exist = false;  
    1684                     foreach($result as $vv)  
    1685                     {  
    1686                         if($v['mail'] == $vv['mail'] )  
    1687                             $exist = true;  
    1688                     }  
    1689                     if(!$exist)  
    1690                         $result[] = $v;  
    1691                 }  
    1692             }  
    1693   
    1694             return $result ;  
    1695         }  
     1636        if (Config::me('uidNumber') && !isset($criteria['notExternal'])) { 
     1637            $newuri['concept'] = 'user'; 
     1638            $newuri['service'] = 'PostgreSQL'; 
     1639 
     1640            $newCriteria = $original['criteria']; 
     1641            $valid = true; 
     1642 
     1643            $newCriteria['filter'] = array('AND', $newCriteria['filter'], array('=', 'owner', Config::me('uidNumber'))); 
     1644            $externalUsers = Controller::find($newuri, $original['properties'] ? $original['properties'] : null, $newCriteria ); 
     1645 
     1646            if (!is_array($result)) 
     1647                $result = array(); 
     1648 
     1649            if (is_array($externalUsers)) { 
     1650                foreach ($externalUsers as $i => $v) 
     1651                    $externalUsers[$i]['isExternal'] = '1'; 
     1652            } 
     1653            else 
     1654                $externalUsers = array(); 
     1655 
     1656            $result = array_merge($result, $externalUsers); 
     1657 
     1658 
     1659            if(isset($original['criteria']['externalCatalogs']) &&  $original['criteria']['externalCatalogs'] == true) 
     1660            { 
     1661                $externalCatalogs = self::findExternalCatalogContacts($original['criteria']['filter'][2]); 
     1662 
     1663                foreach($externalCatalogs as $i => $v) 
     1664                { 
     1665                    $exist = false; 
     1666                    foreach($result as $vv) 
     1667                    { 
     1668                        if($v['mail'] == $vv['mail'] ) 
     1669                            $exist = true; 
     1670                    } 
     1671                    if(!$exist) 
     1672                        $result[] = $v; 
     1673                } 
     1674            } 
     1675 
     1676 
     1677            if(isset($original['criteria']['personalContacts']) &&  $original['criteria']['personalContacts'] == true) 
     1678            { 
     1679                $personalContacts = self::findPersonalContacts($original['criteria']['filter'][2]); 
     1680 
     1681                foreach($personalContacts as $i => $v) 
     1682                { 
     1683                    $exist = false; 
     1684                    foreach($result as $vv) 
     1685                    { 
     1686                        if($v['mail'] == $vv['mail'] ) 
     1687                            $exist = true; 
     1688                    } 
     1689                    if(!$exist) 
     1690                        $result[] = $v; 
     1691                } 
     1692            } 
     1693 
     1694            return $result ; 
     1695        } 
    16961696    } 
    16971697 
     
    18121812            && ($timestamp >= ~PHP_INT_MAX); 
    18131813    } 
    1814   
    1815     static function findExternalCatalogContacts( $search )  
    1816     {  
    1817             $result = array();  
    1818             $external_srcs = array();  
    1819             $external_mappings = array();  
    1820   
    1821             include_once dirname(__DIR__) .'/../../../contactcenter/setup/external_catalogs.inc.php';  
    1822   
    1823             $search = str_replace(' ', '*', $search) ;  
    1824             $search = '*' . $search . '*';  
    1825   
    1826             foreach($external_srcs as $i => $v)  
    1827             {  
    1828                 $con = ldap_connect($v['host']);  
    1829   
    1830                 ldap_set_option( $con , LDAP_OPT_PROTOCOL_VERSION , 3 );  
    1831   
    1832                 if( isset( $v['acc'] ) && isset( $v['pw'] ) )  
    1833                     ldap_bind( $con, $v['acc'], $v['pw'] );  
    1834   
    1835                 $fields = array();  
    1836                 $fields[] = $external_mappings[$i]['contact.names_ordered'][0];  
    1837                 $fields[] = $external_mappings[$i]['contact.connection.typeof_connection.contact_connection_type_name']['email'][0];  
    1838   
    1839                 $ldapFilter = '(&(objectClass='.$v['obj'].')(|('.$fields[0].'='.$search.')('.$fields[1].'='.$search.')))';  
    1840                 $sr =  ldap_search( $con, utf8_encode($v['dn']) , $ldapFilter , $fields );  
    1841                 if($sr)  
    1842                 {  
    1843                     $search = ldap_get_entries($con, $sr);  
    1844   
    1845                     for ($j = 0; $j < $search["count"]; ++$j) {  
    1846                         $tmp = array();  
    1847                         $tmp['name'] = $search[$j][$fields[0]][0];  
    1848                         $tmp['mail'] = $search[$j][$fields[1]][0];  
    1849                         $tmp['isExternal'] = '1';  
    1850   
    1851                         $result[] = $tmp;  
    1852                     }  
    1853                 }  
    1854             }  
    1855             return $result;  
    1856     }  
    1857   
    1858     static function findPersonalContacts($search_for)  
    1859     {  
    1860   
    1861               $query = 'select'  
    1862   
    1863                 . ' C.id_connection,'  
    1864                 . ' A.id_contact,'  
    1865                 . ' A.names_ordered,'  
    1866                 . ' A.alias,'  
    1867                 . ' A.birthdate,'  
    1868                 . ' A.sex,'  
    1869                 . ' A.pgp_key,'  
    1870                 . ' A.notes,'  
    1871                 . ' A.web_page,'  
    1872                 . ' A.corporate_name,'  
    1873                 . ' A.job_title,'  
    1874                 . ' A.department,'  
    1875                 . ' C.connection_name,'  
    1876                 . ' C.connection_value,'  
    1877                 . ' B.id_typeof_contact_connection,'  
    1878                 . ' phpgw_cc_contact_addrs.id_typeof_contact_address,'  
    1879                 . ' phpgw_cc_addresses.address1,'  
    1880                 . ' phpgw_cc_addresses.address2,'  
    1881                 . ' phpgw_cc_addresses.complement,'  
    1882                 . ' phpgw_cc_addresses.postal_code,'  
    1883                 . ' phpgw_cc_city.city_name,'  
    1884                 . ' phpgw_cc_state.state_name,'  
    1885                 . ' phpgw_cc_addresses.id_country'  
    1886             ;  
    1887   
    1888             $query .= ' from'  
    1889                 . ' phpgw_cc_contact A'  
    1890                 . ' inner join phpgw_cc_contact_conns B on ( A.id_contact = B.id_contact )'  
    1891                 . ' inner join phpgw_cc_connections C on ( B.id_connection = C.id_connection )'  
    1892                 . ' left join phpgw_cc_contact_addrs on ( A.id_contact = phpgw_cc_contact_addrs.id_contact )'  
    1893                 . ' left join phpgw_cc_addresses on ( phpgw_cc_contact_addrs.id_address = phpgw_cc_addresses.id_address )'  
    1894                 . ' left join phpgw_cc_city on ( phpgw_cc_addresses.id_city = phpgw_cc_city.id_city )'  
    1895                 . ' left join phpgw_cc_state on ( phpgw_cc_addresses.id_state = phpgw_cc_state.id_state)'  
    1896             ;  
    1897   
    1898             $query .= ' where '  
    1899                 . 'A.id_owner=' . Config::me('uidNumber')  
    1900                 . ' and lower(translate(names_ordered, \'áàâãäéèêëíìïóòôõöúùûüÁÀÂÃÄÉÈÊËÍÌÏÓÒÔÕÖÚÙÛÜçÇñÑ\',\'aaaaaeeeeiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN\'))'  
    1901                 . ' LIKE lower(translate(\'%' . $search_for . '%\', \'áàâãäéèêëíìïóòôõöúùûüÁÀÂÃÄÉÈÊËÍÌÏÓÒÔÕÖÚÙÛÜçÇñÑ\',\'aaaaaeeeeiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN\'))';  
    1902   
    1903             //Se não existir parametro na busca, limita os usuarios no resultado da pesquisa.  
    1904             if(!$search_for){  
    1905                 $query .= 'LIMIT 11';  
    1906             }  
    1907   
    1908             $r = Controller::service('PostgreSQL')->execResultSql($query);  
    1909   
    1910   
    1911             $all_contacts = array();  
    1912             foreach( $r as $i => $object )  
    1913             {  
    1914                 if ( ! array_key_exists( $object[ 'id_contact' ], $all_contacts ) )  
    1915                     $all_contacts[ $object[ 'id_contact' ] ] = array(  
    1916                         'connection_value' => '',  
    1917                         'telephonenumber' => '',  
    1918                         'mobile' => '',  
    1919                         'cn' => '',  
    1920                         'id_contact' => '',  
    1921                         'id_connection' => '',  
    1922                         'alias' => '',  
    1923                         'birthdate' => '',  
    1924                         'sex' => '',  
    1925                         'pgp_key' => '',  
    1926                         'notes' => '',  
    1927                         'web_page' => '',  
    1928                         'corporate_name' => '',  
    1929                         'job_title' => '',  
    1930                         'department' => '',  
    1931                         'mail' => '',  
    1932                         'aternative-mail' => '',  
    1933                         'business-phone' => '',  
    1934                         'business-address' => '',  
    1935                         'business-complement' => '',  
    1936                         'business-postal_code' => '',  
    1937                         'business-city_name' => '',  
    1938                         'business-state_name' => '',  
    1939                         'business-id_country' => '',  
    1940                         'business-fax' => '',  
    1941                         'business-pager' => '',  
    1942                         'business-mobile' => '',  
    1943                         'business-address-2' => '',  
    1944                         'home-phone' => '',  
    1945                         'home-address' => '',  
    1946                         'home-complement' => '',  
    1947                         'home-postal_code' => '',  
    1948                         'home-city_name' => '',  
    1949                         'home-state_name' => '',  
    1950                         'home-fax' => '',  
    1951                         'home-pager' => '',  
    1952                         'home-address-2' => ''  
    1953   
    1954   
    1955                     );  
    1956   
    1957                 switch( $object[ 'id_typeof_contact_connection' ] )  
    1958                 {  
    1959                     case 1 :  
    1960                         $all_contacts[ $object[ 'id_contact' ] ][ 'connection_value' ] = $object[ 'connection_value' ];  
    1961                         switch ( strtolower( $object[ 'connection_name' ] ) )  
    1962                         {  
    1963                             case 'alternativo' :  
    1964                                 $all_contacts[ $object[ 'id_contact' ] ][ 'alternative-mail' ] = $object[ 'connection_value' ];  
    1965                                 break;  
    1966                             case 'principal' :  
    1967                                 $all_contacts[ $object[ 'id_contact' ] ][ 'mail' ] = $object[ 'connection_value' ];  
    1968                                 break;  
    1969                         }  
    1970                         break;  
    1971                     case 2 :  
    1972                         $all_contacts[ $object[ 'id_contact' ] ][ 'telephonenumber' ] = $object[ 'connection_value' ];  
    1973                         switch ( strtolower( $object[ 'connection_name' ] ) )  
    1974                         {  
    1975                             case 'casa' :  
    1976                                 $all_contacts[ $object[ 'id_contact' ] ][ 'home-phone' ] = $object[ 'connection_value' ];  
    1977                                 break;  
    1978                             case 'celular' :  
    1979                                 $all_contacts[ $object[ 'id_contact' ] ][ 'mobile' ] = $object[ 'connection_value' ];  
    1980                                 break;  
    1981                             case 'trabalho' :  
    1982                                 $all_contacts[ $object[ 'id_contact' ] ][ 'business-phone' ] = $object[ 'connection_value' ];  
    1983                                 break;  
    1984                             case 'fax' :  
    1985                                 $all_contacts[ $object[ 'id_contact' ] ][ 'home-fax' ] = $object[ 'connection_value' ];  
    1986                                 break;  
    1987                             case 'pager' :  
    1988                                 $all_contacts[ $object[ 'id_contact' ] ][ 'home-pager' ] = $object[ 'connection_value' ];  
    1989                                 break;  
    1990                             case 'celular corporativo' :  
    1991                                 $all_contacts[ $object[ 'id_contact' ] ][ 'business-mobile' ] = $object[ 'connection_value' ];  
    1992                                 break;  
    1993                             case 'pager corporativo' :  
    1994                                 $all_contacts[ $object[ 'id_contact' ] ][ 'business-pager' ] = $object[ 'connection_value' ];  
    1995                                 break;  
    1996                             case 'fax corporativo' :  
    1997                                 $all_contacts[ $object[ 'id_contact' ] ][ 'business-fax' ] = $object[ 'connection_value' ];  
    1998                                 break;  
    1999                         }  
    2000                         break;  
    2001                 }  
    2002   
    2003                 $all_contacts[ $object[ 'id_contact' ] ][ 'cn' ] = utf8_encode($object[ 'names_ordered' ]);  
    2004                 $all_contacts[ $object[ 'id_contact' ] ][ 'id_contact' ]    = $object[ 'id_contact' ];  
    2005                 $all_contacts[ $object[ 'id_contact' ] ][ 'id_connection' ] = $object[ 'id_connection' ];  
    2006                 $all_contacts[ $object[ 'id_contact' ] ][ 'alias' ]         = $object[ 'alias' ];  
    2007                 $all_contacts[ $object[ 'id_contact' ] ][ 'birthdate' ]         = $object[ 'birthdate' ];  
    2008                 $all_contacts[ $object[ 'id_contact' ] ][ 'sex' ]               = $object[ 'sex' ];  
    2009                 $all_contacts[ $object[ 'id_contact' ] ][ 'pgp_key' ]           = $object[ 'pgp_key' ];  
    2010                 $all_contacts[ $object[ 'id_contact' ] ][ 'notes' ]         = $object[ 'notes' ];  
    2011                 $all_contacts[ $object[ 'id_contact' ] ][ 'web_page' ]          = $object[ 'web_page' ];  
    2012                 $all_contacts[ $object[ 'id_contact' ] ][ 'corporate_name' ]= $object[ 'corporate_name' ];  
    2013                 $all_contacts[ $object[ 'id_contact' ] ][ 'job_title' ]         = $object[ 'job_title' ];  
    2014                 $all_contacts[ $object[ 'id_contact' ] ][ 'department' ]    = $object[ 'department' ];  
    2015   
    2016                 switch( $object[ 'id_typeof_contact_address' ] )  
    2017                 {  
    2018                     case 1 :  
    2019                         $all_contacts[ $object[ 'id_contact' ] ][ 'business-address' ]     = $object[ 'address1' ];  
    2020                         $all_contacts[ $object[ 'id_contact' ] ][ 'business-address-2' ]   = $object[ 'address2' ];  
    2021                         $all_contacts[ $object[ 'id_contact' ] ][ 'business-complement' ]  = $object[ 'complement' ];  
    2022                         $all_contacts[ $object[ 'id_contact' ] ][ 'business-postal_code' ] = $object[ 'postal_code' ];  
    2023                         $all_contacts[ $object[ 'id_contact' ] ][ 'business-city_name' ]   = $object[ 'city_name' ];  
    2024                         $all_contacts[ $object[ 'id_contact' ] ][ 'business-state_name' ]  = $object[ 'state_name' ];  
    2025                         $all_contacts[ $object[ 'id_contact' ] ][ 'business-id_country' ]  = $object[ 'id_country' ];  
    2026                         break;  
    2027                     case 2 :  
    2028                         $all_contacts[ $object[ 'id_contact' ] ][ 'home-address' ]     = $object[ 'address1' ];  
    2029                         $all_contacts[ $object[ 'id_contact' ] ][ 'home-address-2' ]   = $object[ 'address2' ];  
    2030                         $all_contacts[ $object[ 'id_contact' ] ][ 'home-complement' ]  = $object[ 'complement' ];  
    2031                         $all_contacts[ $object[ 'id_contact' ] ][ 'home-postal_code' ] = $object[ 'postal_code' ];  
    2032                         $all_contacts[ $object[ 'id_contact' ] ][ 'home-city_name' ]   = $object[ 'city_name' ];  
    2033                         $all_contacts[ $object[ 'id_contact' ] ][ 'home-state_name' ]  = $object[ 'state_name' ];  
    2034                         $all_contacts[ $object[ 'id_contact' ] ][ 'home-id_country' ]  = $object[ 'id_country' ];  
    2035                         break;  
    2036                 }  
    2037             }  
    2038             $all = array_values($all_contacts);  
    2039   
    2040             $result = array();  
    2041             foreach($all as $i => $v)  
    2042             {  
    2043                 if(!$v['mail']) continue;  
    2044   
    2045                 $tmp = array();  
    2046                 $tmp['mail'] = $v['mail'];  
    2047                 $tmp['name'] = $v['cn'];  
    2048                 $tmp['isExternal'] = '1';  
    2049                 $result[] = $tmp;  
    2050             }  
    2051   
    2052             return $result;  
    2053   
    2054     }  
     1814 
     1815    static function findExternalCatalogContacts( $search ) 
     1816    { 
     1817            $result = array(); 
     1818            $external_srcs = array(); 
     1819            $external_mappings = array(); 
     1820 
     1821            include_once dirname(__DIR__) .'/../../../contactcenter/setup/external_catalogs.inc.php'; 
     1822 
     1823            $search = str_replace(' ', '*', $search) ; 
     1824            $search = '*' . $search . '*'; 
     1825 
     1826            foreach($external_srcs as $i => $v) 
     1827            { 
     1828                $con = ldap_connect($v['host']); 
     1829 
     1830                ldap_set_option( $con , LDAP_OPT_PROTOCOL_VERSION , 3 ); 
     1831 
     1832                if( isset( $v['acc'] ) && isset( $v['pw'] ) ) 
     1833                    ldap_bind( $con, $v['acc'], $v['pw'] ); 
     1834 
     1835                $fields = array(); 
     1836                $fields[] = $external_mappings[$i]['contact.names_ordered'][0]; 
     1837                $fields[] = $external_mappings[$i]['contact.connection.typeof_connection.contact_connection_type_name']['email'][0]; 
     1838 
     1839                $ldapFilter = '(&(objectClass='.$v['obj'].')(|('.$fields[0].'='.$search.')('.$fields[1].'='.$search.')))'; 
     1840                $sr =  ldap_search( $con, utf8_encode($v['dn']) , $ldapFilter , $fields ); 
     1841                if($sr) 
     1842                { 
     1843                    $search = ldap_get_entries($con, $sr); 
     1844 
     1845                    for ($j = 0; $j < $search["count"]; ++$j) { 
     1846                        $tmp = array(); 
     1847                        $tmp['name'] = $search[$j][$fields[0]][0]; 
     1848                        $tmp['mail'] = $search[$j][$fields[1]][0]; 
     1849                        $tmp['isExternal'] = '1'; 
     1850 
     1851                        $result[] = $tmp; 
     1852                    } 
     1853                } 
     1854            } 
     1855            return $result; 
     1856    } 
     1857 
     1858    static function findPersonalContacts($search_for) 
     1859    { 
     1860 
     1861              $query = 'select' 
     1862 
     1863                . ' C.id_connection,' 
     1864                . ' A.id_contact,' 
     1865                . ' A.names_ordered,' 
     1866                . ' A.alias,' 
     1867                . ' A.birthdate,' 
     1868                . ' A.sex,' 
     1869                . ' A.pgp_key,' 
     1870                . ' A.notes,' 
     1871                . ' A.web_page,' 
     1872                . ' A.corporate_name,' 
     1873                . ' A.job_title,' 
     1874                . ' A.department,' 
     1875                . ' C.connection_name,' 
     1876                . ' C.connection_value,' 
     1877                . ' B.id_typeof_contact_connection,' 
     1878                . ' phpgw_cc_contact_addrs.id_typeof_contact_address,' 
     1879                . ' phpgw_cc_addresses.address1,' 
     1880                . ' phpgw_cc_addresses.address2,' 
     1881                . ' phpgw_cc_addresses.complement,' 
     1882                . ' phpgw_cc_addresses.postal_code,' 
     1883                . ' phpgw_cc_city.city_name,' 
     1884                . ' phpgw_cc_state.state_name,' 
     1885                . ' phpgw_cc_addresses.id_country' 
     1886            ; 
     1887 
     1888            $query .= ' from' 
     1889                . ' phpgw_cc_contact A' 
     1890                . ' inner join phpgw_cc_contact_conns B on ( A.id_contact = B.id_contact )' 
     1891                . ' inner join phpgw_cc_connections C on ( B.id_connection = C.id_connection )' 
     1892                . ' left join phpgw_cc_contact_addrs on ( A.id_contact = phpgw_cc_contact_addrs.id_contact )' 
     1893                . ' left join phpgw_cc_addresses on ( phpgw_cc_contact_addrs.id_address = phpgw_cc_addresses.id_address )' 
     1894                . ' left join phpgw_cc_city on ( phpgw_cc_addresses.id_city = phpgw_cc_city.id_city )' 
     1895                . ' left join phpgw_cc_state on ( phpgw_cc_addresses.id_state = phpgw_cc_state.id_state)' 
     1896            ; 
     1897 
     1898            $query .= ' where ' 
     1899                . 'A.id_owner=' . Config::me('uidNumber') 
     1900                . ' and lower(translate(names_ordered, \'áàâãäéèêëíìïóòôõöúùûüÁÀÂÃÄÉÈÊËÍÌÏÓÒÔÕÖÚÙÛÜçÇñÑ\',\'aaaaaeeeeiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN\'))' 
     1901                . ' LIKE lower(translate(\'%' . $search_for . '%\', \'áàâãäéèêëíìïóòôõöúùûüÁÀÂÃÄÉÈÊËÍÌÏÓÒÔÕÖÚÙÛÜçÇñÑ\',\'aaaaaeeeeiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN\'))'; 
     1902 
     1903            //Se não existir parametro na busca, limita os usuarios no resultado da pesquisa. 
     1904            if(!$search_for){ 
     1905                $query .= 'LIMIT 11'; 
     1906            } 
     1907 
     1908            $r = Controller::service('PostgreSQL')->execResultSql($query); 
     1909 
     1910 
     1911            $all_contacts = array(); 
     1912            foreach( $r as $i => $object ) 
     1913            { 
     1914                if ( ! array_key_exists( $object[ 'id_contact' ], $all_contacts ) ) 
     1915                    $all_contacts[ $object[ 'id_contact' ] ] = array( 
     1916                        'connection_value' => '', 
     1917                        'telephonenumber' => '', 
     1918                        'mobile' => '', 
     1919                        'cn' => '', 
     1920                        'id_contact' => '', 
     1921                        'id_connection' => '', 
     1922                        'alias' => '', 
     1923                        'birthdate' => '', 
     1924                        'sex' => '', 
     1925                        'pgp_key' => '', 
     1926                        'notes' => '', 
     1927                        'web_page' => '', 
     1928                        'corporate_name' => '', 
     1929                        'job_title' => '', 
     1930                        'department' => '', 
     1931                        'mail' => '', 
     1932                        'aternative-mail' => '', 
     1933                        'business-phone' => '', 
     1934                        'business-address' => '', 
     1935                        'business-complement' => '', 
     1936                        'business-postal_code' => '', 
     1937                        'business-city_name' => '', 
     1938                        'business-state_name' => '', 
     1939                        'business-id_country' => '', 
     1940                        'business-fax' => '', 
     1941                        'business-pager' => '', 
     1942                        'business-mobile' => '', 
     1943                        'business-address-2' => '', 
     1944                        'home-phone' => '', 
     1945                        'home-address' => '', 
     1946                        'home-complement' => '', 
     1947                        'home-postal_code' => '', 
     1948                        'home-city_name' => '', 
     1949                        'home-state_name' => '', 
     1950                        'home-fax' => '', 
     1951                        'home-pager' => '', 
     1952                        'home-address-2' => '' 
     1953 
     1954 
     1955                    ); 
     1956 
     1957                switch( $object[ 'id_typeof_contact_connection' ] ) 
     1958                { 
     1959                    case 1 : 
     1960                        $all_contacts[ $object[ 'id_contact' ] ][ 'connection_value' ] = $object[ 'connection_value' ]; 
     1961                        switch ( strtolower( $object[ 'connection_name' ] ) ) 
     1962                        { 
     1963                            case 'alternativo' : 
     1964                                $all_contacts[ $object[ 'id_contact' ] ][ 'alternative-mail' ] = $object[ 'connection_value' ]; 
     1965                                break; 
     1966                            case 'principal' : 
     1967                                $all_contacts[ $object[ 'id_contact' ] ][ 'mail' ] = $object[ 'connection_value' ]; 
     1968                                break; 
     1969                        } 
     1970                        break; 
     1971                    case 2 : 
     1972                        $all_contacts[ $object[ 'id_contact' ] ][ 'telephonenumber' ] = $object[ 'connection_value' ]; 
     1973                        switch ( strtolower( $object[ 'connection_name' ] ) ) 
     1974                        { 
     1975                            case 'casa' : 
     1976                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-phone' ] = $object[ 'connection_value' ]; 
     1977                                break; 
     1978                            case 'celular' : 
     1979                                $all_contacts[ $object[ 'id_contact' ] ][ 'mobile' ] = $object[ 'connection_value' ]; 
     1980                                break; 
     1981                            case 'trabalho' : 
     1982                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-phone' ] = $object[ 'connection_value' ]; 
     1983                                break; 
     1984                            case 'fax' : 
     1985                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-fax' ] = $object[ 'connection_value' ]; 
     1986                                break; 
     1987                            case 'pager' : 
     1988                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-pager' ] = $object[ 'connection_value' ]; 
     1989                                break; 
     1990                            case 'celular corporativo' : 
     1991                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-mobile' ] = $object[ 'connection_value' ]; 
     1992                                break; 
     1993                            case 'pager corporativo' : 
     1994                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-pager' ] = $object[ 'connection_value' ]; 
     1995                                break; 
     1996                            case 'fax corporativo' : 
     1997                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-fax' ] = $object[ 'connection_value' ]; 
     1998                                break; 
     1999                        } 
     2000                        break; 
     2001                } 
     2002 
     2003                $all_contacts[ $object[ 'id_contact' ] ][ 'cn' ] = utf8_encode($object[ 'names_ordered' ]); 
     2004                $all_contacts[ $object[ 'id_contact' ] ][ 'id_contact' ]    = $object[ 'id_contact' ]; 
     2005                $all_contacts[ $object[ 'id_contact' ] ][ 'id_connection' ] = $object[ 'id_connection' ]; 
     2006                $all_contacts[ $object[ 'id_contact' ] ][ 'alias' ]         = $object[ 'alias' ]; 
     2007                $all_contacts[ $object[ 'id_contact' ] ][ 'birthdate' ]         = $object[ 'birthdate' ]; 
     2008                $all_contacts[ $object[ 'id_contact' ] ][ 'sex' ]               = $object[ 'sex' ]; 
     2009                $all_contacts[ $object[ 'id_contact' ] ][ 'pgp_key' ]           = $object[ 'pgp_key' ]; 
     2010                $all_contacts[ $object[ 'id_contact' ] ][ 'notes' ]         = $object[ 'notes' ]; 
     2011                $all_contacts[ $object[ 'id_contact' ] ][ 'web_page' ]          = $object[ 'web_page' ]; 
     2012                $all_contacts[ $object[ 'id_contact' ] ][ 'corporate_name' ]= $object[ 'corporate_name' ]; 
     2013                $all_contacts[ $object[ 'id_contact' ] ][ 'job_title' ]         = $object[ 'job_title' ]; 
     2014                $all_contacts[ $object[ 'id_contact' ] ][ 'department' ]    = $object[ 'department' ]; 
     2015 
     2016                switch( $object[ 'id_typeof_contact_address' ] ) 
     2017                { 
     2018                    case 1 : 
     2019                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-address' ]     = $object[ 'address1' ]; 
     2020                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-address-2' ]   = $object[ 'address2' ]; 
     2021                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-complement' ]  = $object[ 'complement' ]; 
     2022                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-postal_code' ] = $object[ 'postal_code' ]; 
     2023                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-city_name' ]   = $object[ 'city_name' ]; 
     2024                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-state_name' ]  = $object[ 'state_name' ]; 
     2025                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-id_country' ]  = $object[ 'id_country' ]; 
     2026                        break; 
     2027                    case 2 : 
     2028                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-address' ]     = $object[ 'address1' ]; 
     2029                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-address-2' ]   = $object[ 'address2' ]; 
     2030                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-complement' ]  = $object[ 'complement' ]; 
     2031                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-postal_code' ] = $object[ 'postal_code' ]; 
     2032                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-city_name' ]   = $object[ 'city_name' ]; 
     2033                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-state_name' ]  = $object[ 'state_name' ]; 
     2034                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-id_country' ]  = $object[ 'id_country' ]; 
     2035                        break; 
     2036                } 
     2037            } 
     2038            $all = array_values($all_contacts); 
     2039 
     2040            $result = array(); 
     2041            foreach($all as $i => $v) 
     2042            { 
     2043                if(!$v['mail']) continue; 
     2044 
     2045                $tmp = array(); 
     2046                $tmp['mail'] = $v['mail']; 
     2047                $tmp['name'] = $v['cn']; 
     2048                $tmp['isExternal'] = '1'; 
     2049                $result[] = $tmp; 
     2050            } 
     2051 
     2052            return $result; 
     2053 
     2054    } 
    20552055} 
    20562056 
Note: See TracChangeset for help on using the changeset viewer.