Index: branches/2.4/prototype/modules/calendar/interceptors/DAViCalAdapter.php
===================================================================
--- branches/2.4/prototype/modules/calendar/interceptors/DAViCalAdapter.php	(revision 6754)
+++ branches/2.4/prototype/modules/calendar/interceptors/DAViCalAdapter.php	(revision 6995)
@@ -52,34 +52,34 @@
     {      
         if( Config::module('useCaldav' , 'expressoCalendar') )
-	{
-	    $calendar = Controller::read( array( 'concept' => 'calendar' , 'id' => $params['calendar'] ));
-	    
-	    if($params['user'] !== '0')
-	    {
-		$user = Controller::read( array( 'concept' => 'user' , 'id' => $params['user'] ));
-		$xmUser =   '<D:href>'.Config::service( 'CalDAV' , 'url' ).'/'.$user['uid'].'/</D:href>';
-	    }
-	    else
-		$xmUser =   '<D:authenticated/>';
-
-	    $xml ="<?xml version=\"1.0\" encoding=\"utf-8\" ?>
-		   <D:acl xmlns:D=\"DAV:\">
-		     <D:ace>
-		       <D:principal>
-			".$xmUser."
-		       </D:principal>
-		       <D:grant>
-			".self::acltToXML($params['acl'])."
-		       </D:grant>
-		     </D:ace>
-		    </D:acl>";	
-	    
-	    ob_start();
-	    require_once ROOTPATH.'/plugins/davicalCliente/caldav-client-v2.php';
-	    $cal = new CalDAVClient( Config::service( 'CalDAV' , 'url' ).'/'.$calendar['location'].'/', Config::me( 'uid' ), Config::me( 'password' ));
-	    $cal->DoXMLRequest('ACL', $xml);
+    {
+        $calendar = Controller::read( array( 'concept' => 'calendar' , 'id' => $params['calendar'] ));
+        
+        if($params['user'] !== '0')
+        {
+        $user = Controller::read( array( 'concept' => 'user' , 'id' => $params['user'] ));
+        $xmUser =   '<D:href>'.Config::service( 'CalDAV' , 'url' ).'/'.$user['uid'].'/</D:href>';
+        }
+        else
+        $xmUser =   '<D:authenticated/>';
+
+        $xml ="<?xml version=\"1.0\" encoding=\"utf-8\" ?>
+           <D:acl xmlns:D=\"DAV:\">
+             <D:ace>
+               <D:principal>
+            ".$xmUser."
+               </D:principal>
+               <D:grant>
+            ".self::acltToXML($params['acl'])."
+               </D:grant>
+             </D:ace>
+            </D:acl>";  
+        
+        ob_start();
+        require_once ROOTPATH.'/plugins/davicalCliente/caldav-client-v2.php';
+        $cal = new CalDAVClient( Config::service( 'CalDAV' , 'url' ).'/'.$calendar['location'].'/', Config::me( 'uid' ), Config::me( 'password' ));
+        $cal->DoXMLRequest('ACL', $xml);
             self::setReadCurrentUserPrivilege(Config::service( 'CalDAV' , 'url' ).'/'.substr($calendar['location'] , 0 , (strpos (  $calendar['location'] ,  '/'  ) + 1 ) ));
-	    ob_end_clean();
-	}
+        ob_end_clean();
+    }
     }
     
@@ -87,36 +87,36 @@
     {      
         if( Config::module('useCaldav' , 'expressoCalendar') )
-	{    
-	    $permision = Controller::read( array( 'concept' => 'calendarToPermission' , 'id' => $params['id'] ));
-	    $calendar = Controller::read( array( 'concept' => 'calendar' , 'id' => $permision['calendar'] ));
-	    
-	    if($permision['user'] !== '0')
-	    {
-		$user = Controller::read( array( 'concept' => 'user' , 'id' => $permision['user'] ));
-		$xmUser =   '<D:href>'.Config::service( 'CalDAV' , 'url' ).'/'.$user['uid'].'/</D:href>';
-	    }
-	    else
-		$xmUser =   '<D:authenticated/>';
-
-		$xml ="<?xml version=\"1.0\" encoding=\"utf-8\" ?>
-		       <D:acl xmlns:D=\"DAV:\">
-			 <D:ace>
-			   <D:principal>
-			    ".$xmUser."
-			   </D:principal>
-			   <D:grant>
-			    ".self::acltToXML($params['acl'])."
-			   </D:grant>
-			 </D:ace>
-			</D:acl>";
-	    
-	    ob_start();
-	    require_once ROOTPATH.'/plugins/davicalCliente/caldav-client-v2.php';
-	    $cal = new CalDAVClient( Config::service( 'CalDAV' , 'url' ).'/'.$calendar['location'].'/', Config::me( 'uid' ), Config::me( 'password' ));
+    {    
+        $permision = Controller::read( array( 'concept' => 'calendarToPermission' , 'id' => $params['id'] ));
+        $calendar = Controller::read( array( 'concept' => 'calendar' , 'id' => $permision['calendar'] ));
+        
+        if($permision['user'] !== '0')
+        {
+        $user = Controller::read( array( 'concept' => 'user' , 'id' => $permision['user'] ));
+        $xmUser =   '<D:href>'.Config::service( 'CalDAV' , 'url' ).'/'.$user['uid'].'/</D:href>';
+        }
+        else
+        $xmUser =   '<D:authenticated/>';
+
+        $xml ="<?xml version=\"1.0\" encoding=\"utf-8\" ?>
+               <D:acl xmlns:D=\"DAV:\">
+             <D:ace>
+               <D:principal>
+                ".$xmUser."
+               </D:principal>
+               <D:grant>
+                ".self::acltToXML($params['acl'])."
+               </D:grant>
+             </D:ace>
+            </D:acl>";
+        
+        ob_start();
+        require_once ROOTPATH.'/plugins/davicalCliente/caldav-client-v2.php';
+        $cal = new CalDAVClient( Config::service( 'CalDAV' , 'url' ).'/'.$calendar['location'].'/', Config::me( 'uid' ), Config::me( 'password' ));
             $cal->DoXMLRequest('ACL', $xml);
             self::setReadCurrentUserPrivilege(Config::service( 'CalDAV' , 'url' ).'/'.substr($calendar['location'] ,  0 ,(strpos (  $calendar['location'] ,  '/'  ) + 1 ) ));
-	    ob_end_clean();
-	    
-	}
+        ob_end_clean();
+        
+    }
     }
     
@@ -128,14 +128,14 @@
         
         $xml ="<?xml version=\"1.0\" encoding=\"utf-8\" ?>
-		       <D:acl xmlns:D=\"DAV:\">
-			 <D:ace>
-			   <D:principal>
-			    <D:authenticated />
-			   </D:principal>
-			   <D:grant>
-			    <D:privilege><D:read-current-user-privilege-set/></D:privilege>
-			   </D:grant>
-			 </D:ace>
-			</D:acl>";
+               <D:acl xmlns:D=\"DAV:\">
+             <D:ace>
+               <D:principal>
+                <D:authenticated />
+               </D:principal>
+               <D:grant>
+                <D:privilege><D:read-current-user-privilege-set/></D:privilege>
+               </D:grant>
+             </D:ace>
+            </D:acl>";
         ob_start();
         require_once ROOTPATH.'/plugins/davicalCliente/caldav-client-v2.php';
@@ -147,42 +147,42 @@
     private static function acltToXML($acls)
     {
-	$array = array();
-	$acls = str_split($acls);
-	
-	foreach ($acls as &$acl)
-	    switch ($acl) 
-	    {
-		case CALENDAR_ACL_WRITE:
-		    $array[] = "<D:privilege><D:bind/></D:privilege>";
-		    $array[] = "<D:privilege><D:write-properties/></D:privilege>";
-		    $array[] = "<D:privilege><D:write-content/></D:privilege>";
-		    $array[] = "<D:privilege><D:unlock/></D:privilege>";
-		    $array[] = "<D:privilege><D:schedule-deliver/></D:privilege>";
-		    $array[] = "<D:privilege><D:schedule-send/></D:privilege>";
-		    break;
-		case CALENDAR_ACL_READ:
-		    $array[] = "<D:privilege><D:read /></D:privilege>";
-		    $array[] = "<D:privilege><D:schedule-query-freebusy /></D:privilege>";
-		    $array[] = "<D:privilege><D:read-free-busy /></D:privilege>";
-		    break;
-		case CALENDAR_ACL_REMOVE:
-		    $array[] = "<D:privilege><D:unbind/></D:privilege>";
-		    break;
-		case CALENDAR_ACL_SHARED:
-		    $array[] = "<D:privilege><D:write-acl/></D:privilege>";
-		    $array[] = "<D:privilege><D:read-acl/></D:privilege>";
-		    $array[] = "<D:privilege><D:read-current-user-privilege-set/></D:privilege>";
-		    break;
-		case CALENDAR_ACL_BUSY:
-		    $array[] = "<D:privilege><D:schedule-query-freebusy/></D:privilege>";
-		    $array[] = "<D:privilege><D:read-free-busy/></D:privilege>";
-		    break;
-	    }	   
-	return implode("\n", $array);
+    $array = array();
+    $acls = str_split($acls);
+    
+    foreach ($acls as &$acl)
+        switch ($acl) 
+        {
+        case CALENDAR_ACL_WRITE:
+            $array[] = "<D:privilege><D:bind/></D:privilege>";
+            $array[] = "<D:privilege><D:write-properties/></D:privilege>";
+            $array[] = "<D:privilege><D:write-content/></D:privilege>";
+            $array[] = "<D:privilege><D:unlock/></D:privilege>";
+            $array[] = "<D:privilege><D:schedule-deliver/></D:privilege>";
+            $array[] = "<D:privilege><D:schedule-send/></D:privilege>";
+            break;
+        case CALENDAR_ACL_READ:
+            $array[] = "<D:privilege><D:read /></D:privilege>";
+            $array[] = "<D:privilege><D:schedule-query-freebusy /></D:privilege>";
+            $array[] = "<D:privilege><D:read-free-busy /></D:privilege>";
+            break;
+        case CALENDAR_ACL_REMOVE:
+            $array[] = "<D:privilege><D:unbind/></D:privilege>";
+            break;
+        case CALENDAR_ACL_SHARED:
+            $array[] = "<D:privilege><D:write-acl/></D:privilege>";
+            $array[] = "<D:privilege><D:read-acl/></D:privilege>";
+            $array[] = "<D:privilege><D:read-current-user-privilege-set/></D:privilege>";
+            break;
+        case CALENDAR_ACL_BUSY:
+            $array[] = "<D:privilege><D:schedule-query-freebusy/></D:privilege>";
+            $array[] = "<D:privilege><D:read-free-busy/></D:privilege>";
+            break;
+        }      
+    return implode("\n", $array);
     }
     
     static function import($data , $params = false)
     {                  
-        $user =  Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$params['owner'])));  
+        $user =  Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$params['owner']) , 'notExternal' => true));  
         $params['owner'] = $user[0]['id'];
         
@@ -214,6 +214,8 @@
     
     static function delete($data , $params = false)
-    {         
-        $user =  Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$params['owner'])));  
+    {   
+
+        $user =  Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$params['owner']) , 'notExternal' => true));
+
         $params['owner'] = $user[0]['id'];
         
@@ -255,5 +257,5 @@
             foreach ($toDelete as $v)
             {
-                 $even = Controller::find(array('concept' => 'schedulable') , false , array ( 'filter' => array('AND', array('=' , 'uid' , $v ), array('=' , 'calendar' , $params['calendar']))) );            
+                 $even = Controller::find(array('concept' => 'schedulable') , false , array ( 'filter' => array('AND', array('=' , 'calendar' , $params['calendar']) , array('=' , 'uid' , $v ) ) ) );            
                  if(is_array($even) && count($even) > 0 )
                        Controller::delete(array('concept' => 'schedulable' , 'id' => $even[0]['id']));
@@ -264,5 +266,5 @@
     static function move($origem , $destino , $owner)
     {  
-        $user =  Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$owner)));  
+        $user =  Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$owner) , 'notExternal' => true));  
         $owner = $user[0]['id'];
         
@@ -341,5 +343,5 @@
     
     static function mkcalendar($location , $name, $description )
-    {	
+    {   
         ob_start();
         require_once ROOTPATH.'/plugins/davicalCliente/caldav-client-v2.php';
