Index: branches/2.4/prototype/rest/catalog/DynamicContactsResource.php
===================================================================
--- branches/2.4/prototype/rest/catalog/DynamicContactsResource.php	(revision 6754)
+++ branches/2.4/prototype/rest/catalog/DynamicContactsResource.php	(revision 6819)
@@ -290,20 +290,45 @@
     private function isEnabledDynamicContacts($user){
 
-	$sql = 'SELECT preference_value '.
-		'FROM phpgw_preferences '.
-		'WHERE preference_app = \'expressoMail\' AND '.
-			'preference_owner = ' . $user;
-
-	$preference = Controller::service('PostgreSQL')->execResultSql($sql, true);
-
-	if(count($preference) > 0 && isset($preference['preference_value'])){
-		$preference = unserialize( $preference['preference_value'] );
-
-		if(isset($preference['use_dynamic_contacts'])){
-			$preference = $preference['use_dynamic_contacts'];
-			return ($preference == '1');
-		}
-	}
-	return false;
+				//recuperando as preferencias (suas preferencias, preferencia padrão, preferencia obrigatoria) 
+                //dos contatos dinamicos 
+        $sql = 'SELECT preference_owner, preference_value '. 
+                'FROM phpgw_preferences '. 
+                'WHERE preference_app = \'expressoMail\' AND '. 
+                        'preference_owner in (-1,-2, ' . $user . ')'; 
+ 
+        $preferences = Controller::service('PostgreSQL')->execResultSql($sql); 
+ 
+                $array = array(); 
+        if(count($preferences) > 0){ 
+                        foreach($preferences as $preference){ 
+                                //recupera a preferencia 
+                $preference_value = unserialize( $preference['preference_value'] ); 
+                 
+                                //gera um array com o owner e o valor da preferencia: 
+                                //true: SIM  (1) 
+                                //false: NAO (0) 
+                                //null: escolha pelo usuario/ usar padrao / sem padrao 
+                                $value = null; 
+                                if(isset($preference_value['use_dynamic_contacts'])){ 
+                                        $value = (isset($preference_value['use_dynamic_contacts'])) ? $preference_value['use_dynamic_contacts'] == '1' : false; 
+                                } 
+                                $array[ $preference['preference_owner'] ] = $value; 
+                        } 
+        } 
+ 
+                //preferencia obrigatoria (SIM) 
+                if(array_key_exists(-1,$array) && $array[-1]){ 
+                        return true; 
+				}
+				//preferencia do user (SIM) 
+                else if(array_key_exists($user,$array) && $array[$user] ){ 
+                        return true; 
+                } 
+                //preferencia padrao (SIM) escolhida pelo user 
+                else if(array_key_exists($user, $array) && $array[$user] === null && 
+                        array_key_exists(-2, $array) && $array[-2]){ 
+                        return true; 
+                } 
+                return false;
     }
 
Index: branches/2.4/prototype/rest/catalog/UserContactsResource.php
===================================================================
--- branches/2.4/prototype/rest/catalog/UserContactsResource.php	(revision 6754)
+++ branches/2.4/prototype/rest/catalog/UserContactsResource.php	(revision 6819)
@@ -487,22 +487,45 @@
     private function isEnabledDynamicContacts($user){
 
-        $sql = 'SELECT preference_value '.
+        		//recuperando as preferencias (suas preferencias, preferencia padrão, preferencia obrigatoria) 
+ 		        //dos contatos dinamicos 
+ 		$sql = 'SELECT preference_owner, preference_value '.
                 'FROM phpgw_preferences '.
                 'WHERE preference_app = \'expressoMail\' AND '.
-                        'preference_owner = ' . $user;
-
-        $preference = Controller::service('PostgreSQL')->execResultSql($sql, true);
-
-        if(count($preference) > 0 && isset($preference['preference_value'])){
-                $preference = unserialize( $preference['preference_value'] );
-
-                if(isset($preference['use_dynamic_contacts'])){
-                        $preference = $preference['use_dynamic_contacts'];
-                        return ($preference == '1');
-                }
+                        'preference_owner in (-1,-2, ' . $user . ')'; 
+ 		 
+        $preferences = Controller::service('PostgreSQL')->execResultSql($sql); 
+ 
+                $array = array(); 
+        if(count($preferences) > 0){ 
+                        foreach($preferences as $preference){ 
+                                //recupera a preferencia 
+                $preference_value = unserialize( $preference['preference_value'] ); 
+                 
+                                //gera um array com o owner e o valor da preferencia: 
+                                //true: SIM  (1) 
+                                //false: NAO (0) 
+                                //null: escolha pelo usuario/ usar padrao / sem padrao 
+                                $value = null; 
+                                if(isset($preference_value['use_dynamic_contacts'])){ 
+                                        $value = (isset($preference_value['use_dynamic_contacts'])) ? $preference_value['use_dynamic_contacts'] == '1' : false; 
+                                } 
+                                $array[ $preference['preference_owner'] ] = $value; 
+                        } 
         }
+        //preferencia obrigatoria (SIM) 
+        if(array_key_exists(-1,$array) && $array[-1]){ 
+                return true; 
+        } 
+        //preferencia do user (SIM) 
+        else if(array_key_exists($user,$array) && $array[$user] ){ 
+                return true; 
+        } 
+        //preferencia padrao (SIM) escolhida pelo user 
+        else if(array_key_exists($user, $array) && $array[$user] === null && 
+                array_key_exists(-2, $array) && $array[-2]){ 
+                return true; 
+        } 
         return false;
     }
-
 }
 
Index: branches/2.4/prototype/rest/catalog/DynamicContactResource.php
===================================================================
--- branches/2.4/prototype/rest/catalog/DynamicContactResource.php	(revision 6754)
+++ branches/2.4/prototype/rest/catalog/DynamicContactResource.php	(revision 6819)
@@ -331,20 +331,44 @@
     private function isEnabledDynamicContacts($user){
 
-        $sql = 'SELECT preference_value '.
+	        //recuperando as preferencias (suas preferencias, preferencia padrão, preferencia obrigatoria) 
+	 	    //dos contatos dinamicos 
+	 	$sql = 'SELECT preference_owner, preference_value '. 
                 'FROM phpgw_preferences '.
                 'WHERE preference_app = \'expressoMail\' AND '.
-                        'preference_owner = ' . $user;
-
-        $preference = Controller::service('PostgreSQL')->execResultSql($sql, true);
-
-        if(count($preference) > 0 && isset($preference['preference_value'])){
-                $preference = unserialize( $preference['preference_value'] );
-
-                if(isset($preference['use_dynamic_contacts'])){
-                        $preference = $preference['use_dynamic_contacts'];
-                        return ($preference == '1');
-                }
+                        'preference_owner in (-1,-2, ' . $user . ')'; 
+ 		 
+        $preferences = Controller::service('PostgreSQL')->execResultSql($sql); 
+ 
+                $array = array(); 
+        if(count($preferences) > 0){ 
+                        foreach($preferences as $preference){ 
+                            //recupera a preferencia 
+                $preference_value = unserialize( $preference['preference_value'] ); 
+                 
+                                //gera um array com o owner e o valor da preferencia: 
+                                //true: SIM  (1) 
+                                //false: NAO (0) 
+                                //null: escolha pelo usuario/ usar padrao / sem padrao 
+                                $value = null; 
+                                if(isset($preference_value['use_dynamic_contacts'])){ 
+                                        $value = (isset($preference_value['use_dynamic_contacts'])) ? $preference_value['use_dynamic_contacts'] == '1' : false; 
+                                } 
+                                $array[ $preference['preference_owner'] ] = $value; 
+                        }
         }
-        return false;
+		        //preferencia obrigatoria (SIM) 
+                if(array_key_exists(-1,$array) && $array[-1]){ 
+                        return true; 
+                } 
+                //preferencia do user (SIM) 
+                else if(array_key_exists($user,$array) && $array[$user] ){ 
+                        return true; 
+                } 
+                //preferencia padrao (SIM) escolhida pelo user 
+                else if(array_key_exists($user, $array) && $array[$user] === null && 
+                        array_key_exists(-2, $array) && $array[-2]){ 
+                        return true; 
+                } 
+                return false; 
     }
 }
