Index: branches/2.5/prototype/modules/calendar/interceptors/Notifications.php
===================================================================
--- branches/2.5/prototype/modules/calendar/interceptors/Notifications.php	(revision 8003)
+++ branches/2.5/prototype/modules/calendar/interceptors/Notifications.php	(revision 8232)
@@ -34,6 +34,6 @@
 	if (Config::regGet('noAlarm') !== false)
 	    return; //Escapa notificações caso a flag de noAlarm esteja ativa.
- 
- 
+
+
 
 	$organizers = array(); //Cache Organizadores
@@ -99,5 +99,5 @@
 	    $psUpdated = Controller::find(array('concept' => 'participant'), false, array('deepness' => '1', 'filter' => array('IN', 'id', $updated)));
 
- 
+
 	    foreach ($psUpdated as $i => $pUpdated) {
 		if ($pUpdated['isOrganizer'] == '1' && $pUpdated['delegatedFrom'] == '0'){
@@ -491,14 +491,14 @@
 
 	    if (count($part) > 0)
-        { 
-            $from = false; 
-            foreach($schedulable['participants'] as $v) 
-            { 
-                if($v['isOrganizer'] == 1) 
-                    $from =  $v; 
-            } 
- 
-            self::sendMail($data, $ical, implode(',', $part), $subject, 'notify_cancel_body' , $from ); 
-        } 
+        {
+            $from = false;
+            foreach($schedulable['participants'] as $v)
+            {
+                if($v['isOrganizer'] == 1)
+                    $from =  $v;
+            }
+
+            self::sendMail($data, $ical, implode(',', $part), $subject, 'notify_cancel_body' , $from );
+        }
 	}
     }
@@ -522,14 +522,14 @@
 	    $method = 'CANCEL';
 	    $notificationType = 'Cancelamento de Calendario';
-            $part = 'me'; 
-            self::mountStruture($schedulable['id'], $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); 
- 
-        $from = false; 
-        foreach($schedulable['participants'] as $v) 
-        { 
-            if($v['isOrganizer'] == 1) 
-                $from =  $v; 
-        } 
-            self::sendMail($data, $ical, $participant['user']['mail'], $subject, 'notify_cancel_body' , $from); 
+	    $part = 'me';
+	    self::mountStruture($schedulable['id'], $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType);
+
+        $from = false;
+        foreach($schedulable['participants'] as $v)
+        {
+            if($v['isOrganizer'] == 1)
+                $from =  $v;
+        }
+ 	    self::sendMail($data, $ical, $participant['user']['mail'], $subject, 'notify_cancel_body' , $from);
 	}
     }
Index: branches/2.5/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- branches/2.5/prototype/modules/calendar/interceptors/DBMapping.php	(revision 8059)
+++ branches/2.5/prototype/modules/calendar/interceptors/DBMapping.php	(revision 8232)
@@ -164,35 +164,35 @@
 
     public function encodeSignatureAlarmType(&$uri, &$params, &$criteria, $original) {
-            $params['type'] = self::codeAlarmType($params['type']); 
-    } 
- 
-    public function schedulableSecurity(&$uri, &$params, &$criteria, $original) 
+	    $params['type'] = self::codeAlarmType($params['type']);
+    }
+
+    public function schedulableSecurity(&$uri, &$params, &$criteria, $original)
     {
- 
-        if( !isset($criteria['filter'][1]) || !$criteria['filter'][1] == 'uid') 
-        { 
-            $security = 'schedulable.id = calendarToSchedulable.schedulable'; 
-            $security .= ' AND calendar.id = calendarToSchedulable.calendar'; 
-            $security .= ' AND calendar.id = calendarSignature.calendar'; 
-            $security .= ' AND calendarSignature.user = ' . base64_encode(Config::me('uidNumber')); 
- 
-            $criteria['condition'] = $security; 
-        } 
-  
-    } 
- 
-    public function calendarSecurity(&$uri, &$params, &$criteria, $original) 
-    { 
-        $security = 'calendar.id = calendarSignature.calendar'; 
-        $security .= ' AND calendarSignature.user = ' . base64_encode(Config::me('uidNumber')); 
- 
-        $criteria['condition'] = $security; 
-    } 
- 
-    public function calendarSignatureSecurity(&$uri, &$params, &$criteria, $original) 
-    { 
-//        $security = 'calendarSignature.user = ' . base64_encode(Config::me('uidNumber')); 
-// 
-//        $criteria['condition'] = $security; 
+
+        if( !isset($criteria['filter'][1]) || !$criteria['filter'][1] == 'uid')
+        {
+            $security = 'schedulable.id = calendarToSchedulable.schedulable';
+            $security .= ' AND calendar.id = calendarToSchedulable.calendar';
+            $security .= ' AND calendar.id = calendarSignature.calendar';
+            $security .= ' AND calendarSignature.user = ' . base64_encode(Config::me('uidNumber'));
+
+            $criteria['condition'] = $security;
+        }
+
+    }
+
+    public function calendarSecurity(&$uri, &$params, &$criteria, $original)
+    {
+        $security = 'calendar.id = calendarSignature.calendar';
+        $security .= ' AND calendarSignature.user = ' . base64_encode(Config::me('uidNumber'));
+
+        $criteria['condition'] = $security;
+    }
+
+    public function calendarSignatureSecurity(&$uri, &$params, &$criteria, $original)
+    {
+//        $security = 'calendarSignature.user = ' . base64_encode(Config::me('uidNumber'));
+//
+//        $criteria['condition'] = $security;
     }
 
@@ -347,22 +347,22 @@
 	if (isset($original['properties']['exceptions'])) {
 	    $exceptions = explode(',', $original['properties']['exceptions']);
-            $event = Controller::read(array('concept' => 'schedulable', 'id' => $repeat['schedulable'])); 
- 
-        if(array_key_exists(0, $event)) $event = $event[0]; 
- 
-        $date = new DateTime('now', new DateTimeZone('UTC')); 
- 
-        foreach($exceptions as &$e){ 
-            $date->setTimestamp((int) ($e / 1000)); 
-            $date->setTimezone( new DateTimeZone( $event['timezone'] )); 
-            $e = ($date->getTimestamp() - $date->getOffset()).'000'; 
-        } 
- 
-        unset($repeat['exceptions']); 
+	    $event = Controller::read(array('concept' => 'schedulable', 'id' => $repeat['schedulable']));
+
+        if(array_key_exists(0, $event)) $event = $event[0];
+
+        $date = new DateTime('now', new DateTimeZone('UTC'));
+
+        foreach($exceptions as &$e){
+            $date->setTimestamp((int) ($e / 1000));
+            $date->setTimezone( new DateTimeZone( $event['timezone'] ));
+            $e = ($date->getTimestamp() - $date->getOffset()).'000';
+        }
+
+        unset($repeat['exceptions']);
 	}
 
-    unset($repeat['schedulable']); 
- 
-    $lastExceptions = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('AND', array('=', 'repeat', $id), array('=', 'exception', 1)))); 
+    unset($repeat['schedulable']);
+
+    $lastExceptions = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('AND', array('=', 'repeat', $id), array('=', 'exception', 1))));
 
 	//Recurepa as execeções anteriores caso exista
@@ -379,5 +379,5 @@
 	else if(!empty($exceptions))
 	    Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_repeat_occurrence(repeat_id,exception,occurrence)VALUES ('" . $id . "','1','" . implode("'),('" . $id . "','1','", $exceptions) . "')" );
-    } 
+    }
 
     public function checkOccurrences($start, $end, $calendarIds) {
@@ -428,22 +428,22 @@
 
 	    foreach ($result as $id => $res){
- 
-            $ocurrences = array_unique($res); 
- 
-            /* 
-             * Check current range decoded 
-             * */ 
-            $current = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('=', 'repeat', $id))); 
-            $toDiff = array(); 
- 
-            if(!empty($current)) 
-                foreach($current as $c) $toDiff[] = $c['occurrence']; 
- 
-            $ocurrences = array_diff($ocurrences, $toDiff); 
- 
-            if(!empty($ocurrences)) 
+
+            $ocurrences = array_unique($res);
+
+            /*
+             * Check current range decoded
+             * */
+            $current = Controller::find(array('concept' => 'repeatOccurrence'), array("occurrence"), array('filter' => array('=', 'repeat', $id)));
+            $toDiff = array();
+
+            if(!empty($current))
+                foreach($current as $c) $toDiff[] = $c['occurrence'];
+
+            $ocurrences = array_diff($ocurrences, $toDiff);
+
+            if(!empty($ocurrences))
                 Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_repeat_occurrence(repeat_id,occurrence)VALUES('" . $id . "','" . implode("'),('" . $id . "', '", $ocurrences) . "')");
- 
-        } 
+
+        }
 	    $data = array();
 
@@ -471,5 +471,5 @@
 	$result = array();
 	$params = array();
-    $realResult = array(); 
+    $realResult = array();
 	foreach ($return as $ret) {
 	    $currentId = $ret['schedulable'];
@@ -483,15 +483,15 @@
 	}
 
-    foreach($result as $i => $v) 
-    { 
-        $calendarToCalendarObj = self::schedulable2calendarToObject($v['id']); 
-            foreach($calendarToCalendarObj as $vv) 
-            { 
-                $v['calendar'] = $vv['calendar_id']; 
-                $realResult[] = $v; 
-            } 
-    } 
- 
-        return( $realResult ); 
+    foreach($result as $i => $v)
+    {
+        $calendarToCalendarObj = self::schedulable2calendarToObject($v['id']);
+            foreach($calendarToCalendarObj as $vv)
+            {
+                $v['calendar'] = $vv['calendar_id'];
+                $realResult[] = $v;
+            }
+    }
+
+	return( $realResult );
     }
 
@@ -633,7 +633,7 @@
             //necessário para atulizar a atividade de composta pela tarefa aqui sendo atualizada
             if(isset($criteria['historic']['startTime']) || isset($criteria['historic']['endTime'])){
-                /* 
-                 * Verify current task is built-in activity 
-                 * */ 
+                /*
+                 * Verify current task is built-in activity
+                 * */
                 $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'task', $uri['id']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2));
                 if(!empty($taskToActivity)){
@@ -641,20 +641,20 @@
                     $isAllDay = 1;
 
-                    /* 
-                     * Get all task in activity 
-                     * */ 
-                    $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'activity', $taskToActivity[0]['activity']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2)); 
- 
+                    /*
+                     * Get all task in activity
+                     * */
+                    $taskToActivity = Controller::find(array('concept' => 'taskToActivity'), false, array('filter' => array('AND', array('=', 'activity', $taskToActivity[0]['activity']), array('=', 'owner', Config::me('uidNumber'))), 'deepness' => 2));
+
                     if(!empty($activity)){
                         $start = $params['startTime'];
                         $end = $params['endTime'];
                         foreach($taskToActivity as $t){
- 
- 
-                            if($t['task']['id'] != $params['id']){ 
-                                $start = $t['task']['startTime'] < $start ? $t['task']['startTime'] : $start; 
-                                $end = $t['task']['endTime'] > $end ? $t['task']['endTime'] : $end; 
-                                $isAllDay = (($isAllDay == 1) && ($t['task']['allDay'] == '1')) ? 1 : 0; 
-                            } 
+
+
+                            if($t['task']['id'] != $params['id']){
+                                $start = $t['task']['startTime'] < $start ? $t['task']['startTime'] : $start;
+                                $end = $t['task']['endTime'] > $end ? $t['task']['endTime'] : $end;
+                                $isAllDay = (($isAllDay == 1) && ($t['task']['allDay'] == '1')) ? 1 : 0;
+                            }
                         }
 
@@ -680,7 +680,7 @@
                 }
             }
-            /* 
-             * Clean historic not used 
-             * */ 
+            /*
+             * Clean historic not used
+             * */
             unset($criteria['historic']['endTime']);
             unset($criteria['historic']['rangeEnd']);
@@ -771,25 +771,25 @@
 	    }
 	}
-    } 
- 
-    static function autoImportCalendar(&$uri, &$params, &$criteria, $original){ 
-        $autoCommit = Controller::service('PostgreSQL')->execResultSql('Select config_value FROM phpgw_config WHERE config_app = \'expressoCalendar\' AND config_name = \'expressoCalendar_autoImportCalendars\''); 
- 
- 
-        if(isset($autoCommit[0]) && $autoCommit[0]['config_value'] == 'true') 
-        { 
-            if(isset($original['properties']) && isset($original['properties']['user'])  && isset($original['properties']['isOrganizer']) &&  $original['properties']['isOrganizer'] != '1') 
-            { 
-                $defaultCalendar = Controller::find(array('concept' => 'modulePreference'), array('value') , array('filter' => array( 'and' , array('=' , 'name' , 'dafaultImportCalendar') , array('=' , 'module' , 'expressoCalendar') , array('=' , 'user' , $original['properties']['user'])  )) ); 
-                if(isset($defaultCalendar[0]) && $defaultCalendar[0]['value'] > 0) 
-                { 
-                    Controller::create(array('concept' => 'calendarToSchedulable'), 
-                        array('schedulable' => $original['properties']['schedulable'], 
-                            'calendar' => $defaultCalendar[0]['value'] 
-                        ) 
-                    ); 
-                } 
-            } 
-        } 
+    }
+
+    static function autoImportCalendar(&$uri, &$params, &$criteria, $original){
+        $autoCommit = Controller::service('PostgreSQL')->execResultSql('Select config_value FROM phpgw_config WHERE config_app = \'expressoCalendar\' AND config_name = \'expressoCalendar_autoImportCalendars\'');
+
+
+        if(isset($autoCommit[0]) && $autoCommit[0]['config_value'] == 'true')
+        {
+            if(isset($original['properties']) && isset($original['properties']['user'])  && isset($original['properties']['isOrganizer']) &&  $original['properties']['isOrganizer'] != '1')
+            {
+                $defaultCalendar = Controller::find(array('concept' => 'modulePreference'), array('value') , array('filter' => array( 'and' , array('=' , 'name' , 'dafaultImportCalendar') , array('=' , 'module' , 'expressoCalendar') , array('=' , 'user' , $original['properties']['user'])  )) );
+                if(isset($defaultCalendar[0]) && $defaultCalendar[0]['value'] > 0)
+                {
+                    Controller::create(array('concept' => 'calendarToSchedulable'),
+                        array('schedulable' => $original['properties']['schedulable'],
+                            'calendar' => $defaultCalendar[0]['value']
+                        )
+                    );
+                }
+            }
+        }
     }
 
@@ -913,27 +913,27 @@
     }
 
-    public function getCalendarTask( $task ){ 
- 
-        $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') 
-            .' AND cs.is_owner = 1 AND cs.calendar_id = co.calendar_id AND co.calendar_object_id = '. $task; 
- 
- 
-        $returns = Controller::service('PostgreSQL')->execResultSql($sql); 
- 
-        return $returns[0]['calendar']; 
-    } 
- 
+    public function getCalendarTask( $task ){
+
+        $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')
+            .' AND cs.is_owner = 1 AND cs.calendar_id = co.calendar_id AND co.calendar_object_id = '. $task;
+
+
+        $returns = Controller::service('PostgreSQL')->execResultSql($sql);
+
+        return $returns[0]['calendar'];
+    }
+
     //TODO: Remover apos suporte a deepness na api 
     public function deepnessFindTask(&$uri, &$result, &$criteria, $original) {
-        if (isset($criteria['deepness']) && $criteria['deepness'] != 0){ 
- 
-            foreach($result as &$value){ 
- 
+        if (isset($criteria['deepness']) && $criteria['deepness'] != 0){
+
+            foreach($result as &$value){
+
                 $value['task'] = Controller::read(array('concept' => 'schedulable', 'id' => $value['task']));
-                $value['task']['calendar'] = self::getCalendarTask( $value['task']['id'] ); 
-            } 
- 
-            return $result; 
-        } 
+                $value['task']['calendar'] = self::getCalendarTask( $value['task']['id'] );
+            }
+
+            return $result;
+        }
     }
 
@@ -972,24 +972,24 @@
                 .'calendar_object.tzid as "timezone", calendar_to_calendar_object.calendar_id as "calendar" '
                 .'FROM calendar_object, calendar_to_calendar_object '
-                .'WHERE ( calendar_object.id = '. $criteria['schedulable'] .' AND calendar_to_calendar_object.calendar_object_id = calendar_object.id' 
-                .' AND calendar_to_calendar_object.calendar_id IN (select calendar_id from calendar_signature where calendar_signature.user_uidnumber = '. Config::me('uidNumber') .' )         )'; 
+                .'WHERE ( calendar_object.id = '. $criteria['schedulable'] .' AND calendar_to_calendar_object.calendar_object_id = calendar_object.id'
+                .' AND calendar_to_calendar_object.calendar_id IN (select calendar_id from calendar_signature where calendar_signature.user_uidnumber = '. Config::me('uidNumber') .' )         )';
 
             $params = Controller::service('PostgreSQL')->execResultSql($sql);
- 
-            foreach( $params as &$event ){ 
- 
- 
-                if(isset( $event['repeat'] ) && isset( $event['repeat']['id'] ) ){ 
-                    $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 ' ); 
- 
-                    if($occurrences){ 
-                        $event['occurrences'] = array(); 
- 
-                        foreach($occurrences as $o) 
-                            $event['occurrences'][] = $o['occurrence']; 
-                    }else 
-                        unset( $event['occurrences'] ); 
-                } 
-            } 
+
+            foreach( $params as &$event ){
+
+
+                if(isset( $event['repeat'] ) && isset( $event['repeat']['id'] ) ){
+                    $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 ' );
+
+                    if($occurrences){
+                        $event['occurrences'] = array();
+
+                        foreach($occurrences as $o)
+                            $event['occurrences'][] = $o['occurrence'];
+                    }else
+                        unset( $event['occurrences'] );
+                }
+            }
 
             $params = self::deepnessFindEvent($uri, $params, $criteria, $original);
@@ -1047,10 +1047,10 @@
                 if(isset( $v['occurrences'] ) && count( $v['occurrences'] ) > 0){
 
-                    $date->setTimestamp((int) ($v['startTime'] / 1000)); 
-                    $date->setTimezone( new DateTimeZone( $v['timezone'] )); 
- 
+                    $date->setTimestamp((int) ($v['startTime'] / 1000));
+                    $date->setTimezone( new DateTimeZone( $v['timezone'] ));
+
                     foreach( $result[$i]['occurrences'] as &$o){
 
-                        $o = ($o + $date->getOffset()).'000'; 
+                        $o = ($o + $date->getOffset()).'000';
 
                     }
@@ -1421,20 +1421,20 @@
 
 	    Controller::delete(array('concept' => 'calendar', 'id' => $signature['calendar']));
- 
-        $autoCommit = Controller::service('PostgreSQL')->execResultSql('Select config_value FROM phpgw_config WHERE config_app = \'expressoCalendar\' AND config_name = \'expressoCalendar_autoImportCalendars\''); 
- 
-        if(isset($autoCommit[0]) && $autoCommit[0]['config_value'] == 'true') 
-        { 
-            $defaultCalendar = Controller::find(array('concept' => 'modulePreference'), array('value','id') , array('filter' => array( 'and' , array('=' , 'name' , 'dafaultImportCalendar') , array('=' , 'module' , 'expressoCalendar') , array('=' , 'user' , $signature['user'])  )) ); 
- 
- 
-            if(isset($defaultCalendar[0])  && $defaultCalendar[0]['value'] == $signature['calendar'] ) 
-            { 
-                Controller::delete(array('concept' => 'modulePreference', 'id' => $defaultCalendar[0]['id'])); 
-            } 
-        } 
- 
-        $permissions = Controller::find(array('concept' => 'calendarToPermission'), array('id'), array('filter' => array('=', 'calendar', $signature['calendar']))); 
- 
+
+        $autoCommit = Controller::service('PostgreSQL')->execResultSql('Select config_value FROM phpgw_config WHERE config_app = \'expressoCalendar\' AND config_name = \'expressoCalendar_autoImportCalendars\'');
+
+        if(isset($autoCommit[0]) && $autoCommit[0]['config_value'] == 'true')
+        {
+            $defaultCalendar = Controller::find(array('concept' => 'modulePreference'), array('value','id') , array('filter' => array( 'and' , array('=' , 'name' , 'dafaultImportCalendar') , array('=' , 'module' , 'expressoCalendar') , array('=' , 'user' , $signature['user'])  )) );
+
+
+            if(isset($defaultCalendar[0])  && $defaultCalendar[0]['value'] == $signature['calendar'] )
+            {
+                Controller::delete(array('concept' => 'modulePreference', 'id' => $defaultCalendar[0]['id']));
+            }
+        }
+
+        $permissions = Controller::find(array('concept' => 'calendarToPermission'), array('id'), array('filter' => array('=', 'calendar', $signature['calendar'])));
+
 		if($permissions && count($permissions) > 0){
 			$ids = array();
@@ -1583,14 +1583,14 @@
                 }
 
-                if($i == 0) 
-                { 
-                    $pref = array(); 
-                    $pref['user'] = $_SESSION['wallet']['user']['uidNumber']; 
-                    $pref['value'] = $calCreated['id']; 
-                    $pref['name'] = 'dafaultImportCalendar' ; 
-                    $pref['module'] = 'expressoCalendar'; 
-                    Controller::create(array('concept' => 'modulePreference'), $pref); 
-                } 
- 
+                if($i == 0)
+                {
+                    $pref = array();
+                    $pref['user'] = $_SESSION['wallet']['user']['uidNumber'];
+                    $pref['value'] = $calCreated['id'];
+                    $pref['name'] = 'dafaultImportCalendar' ;
+                    $pref['module'] = 'expressoCalendar';
+                    Controller::create(array('concept' => 'modulePreference'), $pref);
+                }
+
     		}
 	    } else {
@@ -1614,14 +1614,14 @@
 
     		$sigCreated = Controller::create(array('concept' => 'calendarSignature'), $sig);
- 
- 
-            $pref = array(); 
-            $pref['user'] = $_SESSION['wallet']['user']['uidNumber']; 
-            $pref['value'] = $calCreated['id']; 
-            $pref['name'] = 'dafaultImportCalendar' ; 
-            $pref['module'] = 'expressoCalendar'; 
-            Controller::create(array('concept' => 'modulePreference'), $pref); 
- 
- 
+
+
+            $pref = array();
+            $pref['user'] = $_SESSION['wallet']['user']['uidNumber'];
+            $pref['value'] = $calCreated['id'];
+            $pref['name'] = 'dafaultImportCalendar' ;
+            $pref['module'] = 'expressoCalendar';
+            Controller::create(array('concept' => 'modulePreference'), $pref);
+
+
         }
     
@@ -1634,64 +1634,64 @@
     //TODO - Criar conceito separado para participantes externos e remover o criterio notExternal
     public function findExternalPaticipants(&$uri, &$result, &$criteria, $original) {
-        if (Config::me('uidNumber') && !isset($criteria['notExternal'])) { 
-            $newuri['concept'] = 'user'; 
-            $newuri['service'] = 'PostgreSQL'; 
- 
-            $newCriteria = $original['criteria']; 
-            $valid = true; 
- 
-            $newCriteria['filter'] = array('AND', $newCriteria['filter'], array('=', 'owner', Config::me('uidNumber'))); 
-            $externalUsers = Controller::find($newuri, $original['properties'] ? $original['properties'] : null, $newCriteria ); 
- 
-            if (!is_array($result)) 
-                $result = array(); 
- 
-            if (is_array($externalUsers)) { 
-                foreach ($externalUsers as $i => $v) 
-                    $externalUsers[$i]['isExternal'] = '1'; 
-            } 
-            else 
-                $externalUsers = array(); 
- 
-            $result = array_merge($result, $externalUsers); 
- 
- 
-            if(isset($original['criteria']['externalCatalogs']) &&  $original['criteria']['externalCatalogs'] == true) 
-            { 
-                $externalCatalogs = self::findExternalCatalogContacts($original['criteria']['filter'][2]); 
- 
-                foreach($externalCatalogs as $i => $v) 
-                { 
-                    $exist = false; 
-                    foreach($result as $vv) 
-                    { 
-                        if($v['mail'] == $vv['mail'] ) 
-                            $exist = true; 
-                    } 
-                    if(!$exist) 
-                        $result[] = $v; 
-                } 
-            } 
- 
- 
-            if(isset($original['criteria']['personalContacts']) &&  $original['criteria']['personalContacts'] == true) 
-            { 
-                $personalContacts = self::findPersonalContacts($original['criteria']['filter'][2]); 
- 
-                foreach($personalContacts as $i => $v) 
-                { 
-                    $exist = false; 
-                    foreach($result as $vv) 
-                    { 
-                        if($v['mail'] == $vv['mail'] ) 
-                            $exist = true; 
-                    } 
-                    if(!$exist) 
-                        $result[] = $v; 
-                } 
-            } 
- 
-            return $result ; 
-        } 
+        if (Config::me('uidNumber') && !isset($criteria['notExternal'])) {
+            $newuri['concept'] = 'user';
+            $newuri['service'] = 'PostgreSQL';
+
+            $newCriteria = $original['criteria'];
+            $valid = true;
+
+            $newCriteria['filter'] = array('AND', $newCriteria['filter'], array('=', 'owner', Config::me('uidNumber')));
+            $externalUsers = Controller::find($newuri, $original['properties'] ? $original['properties'] : null, $newCriteria );
+
+            if (!is_array($result))
+                $result = array();
+
+            if (is_array($externalUsers)) {
+                foreach ($externalUsers as $i => $v)
+                    $externalUsers[$i]['isExternal'] = '1';
+            }
+            else
+                $externalUsers = array();
+
+            $result = array_merge($result, $externalUsers);
+
+
+            if(isset($original['criteria']['externalCatalogs']) &&  $original['criteria']['externalCatalogs'] == true)
+            {
+                $externalCatalogs = self::findExternalCatalogContacts($original['criteria']['filter'][2]);
+
+                foreach($externalCatalogs as $i => $v)
+                {
+                    $exist = false;
+                    foreach($result as $vv)
+                    {
+                        if($v['mail'] == $vv['mail'] )
+                            $exist = true;
+                    }
+                    if(!$exist)
+                        $result[] = $v;
+                }
+            }
+
+
+            if(isset($original['criteria']['personalContacts']) &&  $original['criteria']['personalContacts'] == true)
+            {
+                $personalContacts = self::findPersonalContacts($original['criteria']['filter'][2]);
+
+                foreach($personalContacts as $i => $v)
+                {
+                    $exist = false;
+                    foreach($result as $vv)
+                    {
+                        if($v['mail'] == $vv['mail'] )
+                            $exist = true;
+                    }
+                    if(!$exist)
+                        $result[] = $v;
+                }
+            }
+
+            return $result ;
+        }
     }
 
@@ -1812,245 +1812,245 @@
             && ($timestamp >= ~PHP_INT_MAX);
     }
- 
-    static function findExternalCatalogContacts( $search ) 
-    { 
-            $result = array(); 
-            $external_srcs = array(); 
-            $external_mappings = array(); 
- 
-            include_once dirname(__DIR__) .'/../../../contactcenter/setup/external_catalogs.inc.php'; 
- 
-            $search = str_replace(' ', '*', $search) ; 
-            $search = '*' . $search . '*'; 
- 
-            foreach($external_srcs as $i => $v) 
-            { 
-                $con = ldap_connect($v['host']); 
- 
-                ldap_set_option( $con , LDAP_OPT_PROTOCOL_VERSION , 3 ); 
- 
-                if( isset( $v['acc'] ) && isset( $v['pw'] ) ) 
-                    ldap_bind( $con, $v['acc'], $v['pw'] ); 
- 
-                $fields = array(); 
-                $fields[] = $external_mappings[$i]['contact.names_ordered'][0]; 
-                $fields[] = $external_mappings[$i]['contact.connection.typeof_connection.contact_connection_type_name']['email'][0]; 
- 
-                $ldapFilter = '(&(objectClass='.$v['obj'].')(|('.$fields[0].'='.$search.')('.$fields[1].'='.$search.')))'; 
-                $sr =  ldap_search( $con, utf8_encode($v['dn']) , $ldapFilter , $fields ); 
-                if($sr) 
-                { 
-                    $search = ldap_get_entries($con, $sr); 
- 
-                    for ($j = 0; $j < $search["count"]; ++$j) { 
-                        $tmp = array(); 
-                        $tmp['name'] = $search[$j][$fields[0]][0]; 
-                        $tmp['mail'] = $search[$j][$fields[1]][0]; 
-                        $tmp['isExternal'] = '1'; 
- 
-                        $result[] = $tmp; 
-                    } 
-                } 
-            } 
-            return $result; 
-    } 
- 
-    static function findPersonalContacts($search_for) 
-    { 
- 
-              $query = 'select' 
- 
-                . ' C.id_connection,' 
-                . ' A.id_contact,' 
-                . ' A.names_ordered,' 
-                . ' A.alias,' 
-                . ' A.birthdate,' 
-                . ' A.sex,' 
-                . ' A.pgp_key,' 
-                . ' A.notes,' 
-                . ' A.web_page,' 
-                . ' A.corporate_name,' 
-                . ' A.job_title,' 
-                . ' A.department,' 
-                . ' C.connection_name,' 
-                . ' C.connection_value,' 
-                . ' B.id_typeof_contact_connection,' 
-                . ' phpgw_cc_contact_addrs.id_typeof_contact_address,' 
-                . ' phpgw_cc_addresses.address1,' 
-                . ' phpgw_cc_addresses.address2,' 
-                . ' phpgw_cc_addresses.complement,' 
-                . ' phpgw_cc_addresses.postal_code,' 
-                . ' phpgw_cc_city.city_name,' 
-                . ' phpgw_cc_state.state_name,' 
-                . ' phpgw_cc_addresses.id_country' 
-            ; 
- 
-            $query .= ' from' 
-                . ' phpgw_cc_contact A' 
-                . ' inner join phpgw_cc_contact_conns B on ( A.id_contact = B.id_contact )' 
-                . ' inner join phpgw_cc_connections C on ( B.id_connection = C.id_connection )' 
-                . ' left join phpgw_cc_contact_addrs on ( A.id_contact = phpgw_cc_contact_addrs.id_contact )' 
-                . ' left join phpgw_cc_addresses on ( phpgw_cc_contact_addrs.id_address = phpgw_cc_addresses.id_address )' 
-                . ' left join phpgw_cc_city on ( phpgw_cc_addresses.id_city = phpgw_cc_city.id_city )' 
-                . ' left join phpgw_cc_state on ( phpgw_cc_addresses.id_state = phpgw_cc_state.id_state)' 
-            ; 
- 
-            $query .= ' where ' 
-                . 'A.id_owner=' . Config::me('uidNumber') 
-                . ' and lower(translate(names_ordered, \'áàâãäéèêëíìïóòôõöúùûüÁÀÂÃÄÉÈÊËÍÌÏÓÒÔÕÖÚÙÛÜçÇñÑ\',\'aaaaaeeeeiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN\'))' 
-                . ' LIKE lower(translate(\'%' . $search_for . '%\', \'áàâãäéèêëíìïóòôõöúùûüÁÀÂÃÄÉÈÊËÍÌÏÓÒÔÕÖÚÙÛÜçÇñÑ\',\'aaaaaeeeeiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN\'))'; 
- 
-            //Se não existir parametro na busca, limita os usuarios no resultado da pesquisa. 
-            if(!$search_for){ 
-                $query .= 'LIMIT 11'; 
-            } 
- 
-            $r = Controller::service('PostgreSQL')->execResultSql($query); 
- 
- 
-            $all_contacts = array(); 
-            foreach( $r as $i => $object ) 
-            { 
-                if ( ! array_key_exists( $object[ 'id_contact' ], $all_contacts ) ) 
-                    $all_contacts[ $object[ 'id_contact' ] ] = array( 
-                        'connection_value' => '', 
-                        'telephonenumber' => '', 
-                        'mobile' => '', 
-                        'cn' => '', 
-                        'id_contact' => '', 
-                        'id_connection' => '', 
-                        'alias' => '', 
-                        'birthdate' => '', 
-                        'sex' => '', 
-                        'pgp_key' => '', 
-                        'notes' => '', 
-                        'web_page' => '', 
-                        'corporate_name' => '', 
-                        'job_title' => '', 
-                        'department' => '', 
-                        'mail' => '', 
-                        'aternative-mail' => '', 
-                        'business-phone' => '', 
-                        'business-address' => '', 
-                        'business-complement' => '', 
-                        'business-postal_code' => '', 
-                        'business-city_name' => '', 
-                        'business-state_name' => '', 
-                        'business-id_country' => '', 
-                        'business-fax' => '', 
-                        'business-pager' => '', 
-                        'business-mobile' => '', 
-                        'business-address-2' => '', 
-                        'home-phone' => '', 
-                        'home-address' => '', 
-                        'home-complement' => '', 
-                        'home-postal_code' => '', 
-                        'home-city_name' => '', 
-                        'home-state_name' => '', 
-                        'home-fax' => '', 
-                        'home-pager' => '', 
-                        'home-address-2' => '' 
- 
- 
-                    ); 
- 
-                switch( $object[ 'id_typeof_contact_connection' ] ) 
-                { 
-                    case 1 : 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'connection_value' ] = $object[ 'connection_value' ]; 
-                        switch ( strtolower( $object[ 'connection_name' ] ) ) 
-                        { 
-                            case 'alternativo' : 
-                                $all_contacts[ $object[ 'id_contact' ] ][ 'alternative-mail' ] = $object[ 'connection_value' ]; 
-                                break; 
-                            case 'principal' : 
-                                $all_contacts[ $object[ 'id_contact' ] ][ 'mail' ] = $object[ 'connection_value' ]; 
-                                break; 
-                        } 
-                        break; 
-                    case 2 : 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'telephonenumber' ] = $object[ 'connection_value' ]; 
-                        switch ( strtolower( $object[ 'connection_name' ] ) ) 
-                        { 
-                            case 'casa' : 
-                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-phone' ] = $object[ 'connection_value' ]; 
-                                break; 
-                            case 'celular' : 
-                                $all_contacts[ $object[ 'id_contact' ] ][ 'mobile' ] = $object[ 'connection_value' ]; 
-                                break; 
-                            case 'trabalho' : 
-                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-phone' ] = $object[ 'connection_value' ]; 
-                                break; 
-                            case 'fax' : 
-                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-fax' ] = $object[ 'connection_value' ]; 
-                                break; 
-                            case 'pager' : 
-                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-pager' ] = $object[ 'connection_value' ]; 
-                                break; 
-                            case 'celular corporativo' : 
-                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-mobile' ] = $object[ 'connection_value' ]; 
-                                break; 
-                            case 'pager corporativo' : 
-                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-pager' ] = $object[ 'connection_value' ]; 
-                                break; 
-                            case 'fax corporativo' : 
-                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-fax' ] = $object[ 'connection_value' ]; 
-                                break; 
-                        } 
-                        break; 
-                } 
- 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'cn' ] = utf8_encode($object[ 'names_ordered' ]); 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'id_contact' ]    = $object[ 'id_contact' ]; 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'id_connection' ] = $object[ 'id_connection' ]; 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'alias' ]         = $object[ 'alias' ]; 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'birthdate' ]         = $object[ 'birthdate' ]; 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'sex' ]               = $object[ 'sex' ]; 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'pgp_key' ]           = $object[ 'pgp_key' ]; 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'notes' ]         = $object[ 'notes' ]; 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'web_page' ]          = $object[ 'web_page' ]; 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'corporate_name' ]= $object[ 'corporate_name' ]; 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'job_title' ]         = $object[ 'job_title' ]; 
-                $all_contacts[ $object[ 'id_contact' ] ][ 'department' ]    = $object[ 'department' ]; 
- 
-                switch( $object[ 'id_typeof_contact_address' ] ) 
-                { 
-                    case 1 : 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-address' ]     = $object[ 'address1' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-address-2' ]   = $object[ 'address2' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-complement' ]  = $object[ 'complement' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-postal_code' ] = $object[ 'postal_code' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-city_name' ]   = $object[ 'city_name' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-state_name' ]  = $object[ 'state_name' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-id_country' ]  = $object[ 'id_country' ]; 
-                        break; 
-                    case 2 : 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-address' ]     = $object[ 'address1' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-address-2' ]   = $object[ 'address2' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-complement' ]  = $object[ 'complement' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-postal_code' ] = $object[ 'postal_code' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-city_name' ]   = $object[ 'city_name' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-state_name' ]  = $object[ 'state_name' ]; 
-                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-id_country' ]  = $object[ 'id_country' ]; 
-                        break; 
-                } 
-            } 
-            $all = array_values($all_contacts); 
- 
-            $result = array(); 
-            foreach($all as $i => $v) 
-            { 
-                if(!$v['mail']) continue; 
- 
-                $tmp = array(); 
-                $tmp['mail'] = $v['mail']; 
-                $tmp['name'] = $v['cn']; 
-                $tmp['isExternal'] = '1'; 
-                $result[] = $tmp; 
-            } 
- 
-            return $result; 
- 
-    } 
+
+    static function findExternalCatalogContacts( $search )
+    {
+            $result = array();
+            $external_srcs = array();
+            $external_mappings = array();
+
+            include_once dirname(__DIR__) .'/../../../contactcenter/setup/external_catalogs.inc.php';
+
+            $search = str_replace(' ', '*', $search) ;
+            $search = '*' . $search . '*';
+
+            foreach($external_srcs as $i => $v)
+            {
+                $con = ldap_connect($v['host']);
+
+                ldap_set_option( $con , LDAP_OPT_PROTOCOL_VERSION , 3 );
+
+                if( isset( $v['acc'] ) && isset( $v['pw'] ) )
+                    ldap_bind( $con, $v['acc'], $v['pw'] );
+
+                $fields = array();
+                $fields[] = $external_mappings[$i]['contact.names_ordered'][0];
+                $fields[] = $external_mappings[$i]['contact.connection.typeof_connection.contact_connection_type_name']['email'][0];
+
+                $ldapFilter = '(&(objectClass='.$v['obj'].')(|('.$fields[0].'='.$search.')('.$fields[1].'='.$search.')))';
+                $sr =  ldap_search( $con, utf8_encode($v['dn']) , $ldapFilter , $fields );
+                if($sr)
+                {
+                    $search = ldap_get_entries($con, $sr);
+
+                    for ($j = 0; $j < $search["count"]; ++$j) {
+                        $tmp = array();
+                        $tmp['name'] = $search[$j][$fields[0]][0];
+                        $tmp['mail'] = $search[$j][$fields[1]][0];
+                        $tmp['isExternal'] = '1';
+
+                        $result[] = $tmp;
+                    }
+                }
+            }
+            return $result;
+    }
+
+    static function findPersonalContacts($search_for)
+    {
+
+              $query = 'select'
+
+                . ' C.id_connection,'
+                . ' A.id_contact,'
+                . ' A.names_ordered,'
+                . ' A.alias,'
+                . ' A.birthdate,'
+                . ' A.sex,'
+                . ' A.pgp_key,'
+                . ' A.notes,'
+                . ' A.web_page,'
+                . ' A.corporate_name,'
+                . ' A.job_title,'
+                . ' A.department,'
+                . ' C.connection_name,'
+                . ' C.connection_value,'
+                . ' B.id_typeof_contact_connection,'
+                . ' phpgw_cc_contact_addrs.id_typeof_contact_address,'
+                . ' phpgw_cc_addresses.address1,'
+                . ' phpgw_cc_addresses.address2,'
+                . ' phpgw_cc_addresses.complement,'
+                . ' phpgw_cc_addresses.postal_code,'
+                . ' phpgw_cc_city.city_name,'
+                . ' phpgw_cc_state.state_name,'
+                . ' phpgw_cc_addresses.id_country'
+            ;
+
+            $query .= ' from'
+                . ' phpgw_cc_contact A'
+                . ' inner join phpgw_cc_contact_conns B on ( A.id_contact = B.id_contact )'
+                . ' inner join phpgw_cc_connections C on ( B.id_connection = C.id_connection )'
+                . ' left join phpgw_cc_contact_addrs on ( A.id_contact = phpgw_cc_contact_addrs.id_contact )'
+                . ' left join phpgw_cc_addresses on ( phpgw_cc_contact_addrs.id_address = phpgw_cc_addresses.id_address )'
+                . ' left join phpgw_cc_city on ( phpgw_cc_addresses.id_city = phpgw_cc_city.id_city )'
+                . ' left join phpgw_cc_state on ( phpgw_cc_addresses.id_state = phpgw_cc_state.id_state)'
+            ;
+
+            $query .= ' where '
+                . 'A.id_owner=' . Config::me('uidNumber')
+                . ' and lower(translate(names_ordered, \'áàâãäéèêëíìïóòôõöúùûüÁÀÂÃÄÉÈÊËÍÌÏÓÒÔÕÖÚÙÛÜçÇñÑ\',\'aaaaaeeeeiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN\'))'
+                . ' LIKE lower(translate(\'%' . $search_for . '%\', \'áàâãäéèêëíìïóòôõöúùûüÁÀÂÃÄÉÈÊËÍÌÏÓÒÔÕÖÚÙÛÜçÇñÑ\',\'aaaaaeeeeiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN\'))';
+
+            //Se não existir parametro na busca, limita os usuarios no resultado da pesquisa.
+            if(!$search_for){
+                $query .= 'LIMIT 11';
+            }
+
+            $r = Controller::service('PostgreSQL')->execResultSql($query);
+
+
+            $all_contacts = array();
+            foreach( $r as $i => $object )
+            {
+                if ( ! array_key_exists( $object[ 'id_contact' ], $all_contacts ) )
+                    $all_contacts[ $object[ 'id_contact' ] ] = array(
+                        'connection_value' => '',
+                        'telephonenumber' => '',
+                        'mobile' => '',
+                        'cn' => '',
+                        'id_contact' => '',
+                        'id_connection' => '',
+                        'alias' => '',
+                        'birthdate' => '',
+                        'sex' => '',
+                        'pgp_key' => '',
+                        'notes' => '',
+                        'web_page' => '',
+                        'corporate_name' => '',
+                        'job_title' => '',
+                        'department' => '',
+                        'mail' => '',
+                        'aternative-mail' => '',
+                        'business-phone' => '',
+                        'business-address' => '',
+                        'business-complement' => '',
+                        'business-postal_code' => '',
+                        'business-city_name' => '',
+                        'business-state_name' => '',
+                        'business-id_country' => '',
+                        'business-fax' => '',
+                        'business-pager' => '',
+                        'business-mobile' => '',
+                        'business-address-2' => '',
+                        'home-phone' => '',
+                        'home-address' => '',
+                        'home-complement' => '',
+                        'home-postal_code' => '',
+                        'home-city_name' => '',
+                        'home-state_name' => '',
+                        'home-fax' => '',
+                        'home-pager' => '',
+                        'home-address-2' => ''
+
+
+                    );
+
+                switch( $object[ 'id_typeof_contact_connection' ] )
+                {
+                    case 1 :
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'connection_value' ] = $object[ 'connection_value' ];
+                        switch ( strtolower( $object[ 'connection_name' ] ) )
+                        {
+                            case 'alternativo' :
+                                $all_contacts[ $object[ 'id_contact' ] ][ 'alternative-mail' ] = $object[ 'connection_value' ];
+                                break;
+                            case 'principal' :
+                                $all_contacts[ $object[ 'id_contact' ] ][ 'mail' ] = $object[ 'connection_value' ];
+                                break;
+                        }
+                        break;
+                    case 2 :
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'telephonenumber' ] = $object[ 'connection_value' ];
+                        switch ( strtolower( $object[ 'connection_name' ] ) )
+                        {
+                            case 'casa' :
+                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-phone' ] = $object[ 'connection_value' ];
+                                break;
+                            case 'celular' :
+                                $all_contacts[ $object[ 'id_contact' ] ][ 'mobile' ] = $object[ 'connection_value' ];
+                                break;
+                            case 'trabalho' :
+                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-phone' ] = $object[ 'connection_value' ];
+                                break;
+                            case 'fax' :
+                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-fax' ] = $object[ 'connection_value' ];
+                                break;
+                            case 'pager' :
+                                $all_contacts[ $object[ 'id_contact' ] ][ 'home-pager' ] = $object[ 'connection_value' ];
+                                break;
+                            case 'celular corporativo' :
+                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-mobile' ] = $object[ 'connection_value' ];
+                                break;
+                            case 'pager corporativo' :
+                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-pager' ] = $object[ 'connection_value' ];
+                                break;
+                            case 'fax corporativo' :
+                                $all_contacts[ $object[ 'id_contact' ] ][ 'business-fax' ] = $object[ 'connection_value' ];
+                                break;
+                        }
+                        break;
+                }
+
+                $all_contacts[ $object[ 'id_contact' ] ][ 'cn' ] = utf8_encode($object[ 'names_ordered' ]);
+                $all_contacts[ $object[ 'id_contact' ] ][ 'id_contact' ]    = $object[ 'id_contact' ];
+                $all_contacts[ $object[ 'id_contact' ] ][ 'id_connection' ] = $object[ 'id_connection' ];
+                $all_contacts[ $object[ 'id_contact' ] ][ 'alias' ]         = $object[ 'alias' ];
+                $all_contacts[ $object[ 'id_contact' ] ][ 'birthdate' ] 	= $object[ 'birthdate' ];
+                $all_contacts[ $object[ 'id_contact' ] ][ 'sex' ]    		= $object[ 'sex' ];
+                $all_contacts[ $object[ 'id_contact' ] ][ 'pgp_key' ] 		= $object[ 'pgp_key' ];
+                $all_contacts[ $object[ 'id_contact' ] ][ 'notes' ]         = $object[ 'notes' ];
+                $all_contacts[ $object[ 'id_contact' ] ][ 'web_page' ] 		= $object[ 'web_page' ];
+                $all_contacts[ $object[ 'id_contact' ] ][ 'corporate_name' ]= $object[ 'corporate_name' ];
+                $all_contacts[ $object[ 'id_contact' ] ][ 'job_title' ] 	= $object[ 'job_title' ];
+                $all_contacts[ $object[ 'id_contact' ] ][ 'department' ]    = $object[ 'department' ];
+
+                switch( $object[ 'id_typeof_contact_address' ] )
+                {
+                    case 1 :
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-address' ]     = $object[ 'address1' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-address-2' ]   = $object[ 'address2' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-complement' ]  = $object[ 'complement' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-postal_code' ] = $object[ 'postal_code' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-city_name' ]   = $object[ 'city_name' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-state_name' ]  = $object[ 'state_name' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'business-id_country' ]  = $object[ 'id_country' ];
+                        break;
+                    case 2 :
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-address' ]     = $object[ 'address1' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-address-2' ]   = $object[ 'address2' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-complement' ]  = $object[ 'complement' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-postal_code' ] = $object[ 'postal_code' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-city_name' ]   = $object[ 'city_name' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-state_name' ]  = $object[ 'state_name' ];
+                        $all_contacts[ $object[ 'id_contact' ] ][ 'home-id_country' ]  = $object[ 'id_country' ];
+                        break;
+                }
+            }
+            $all = array_values($all_contacts);
+
+            $result = array();
+            foreach($all as $i => $v)
+            {
+                if(!$v['mail']) continue;
+
+                $tmp = array();
+                $tmp['mail'] = $v['mail'];
+                $tmp['name'] = $v['cn'];
+                $tmp['isExternal'] = '1';
+                $result[] = $tmp;
+            }
+
+            return $result;
+
+    }
 }
 
Index: branches/2.5/prototype/modules/calendar/interceptors/DAViCalAdapter.php
===================================================================
--- branches/2.5/prototype/modules/calendar/interceptors/DAViCalAdapter.php	(revision 7799)
+++ branches/2.5/prototype/modules/calendar/interceptors/DAViCalAdapter.php	(revision 8232)
@@ -206,5 +206,5 @@
         {  
             $args =  Controller::parse( array( 'service' => 'iCal' ) , $data , $params);
-            ob_start(); 
+            ob_start();
             include ROOTPATH.'/Sync.php';
             ob_end_clean();
