Index: /trunk/phpgwapi/inc/class.db.inc.php
===================================================================
--- /trunk/phpgwapi/inc/class.db.inc.php	(revision 2)
+++ /trunk/phpgwapi/inc/class.db.inc.php	(revision 1280)
@@ -1134,4 +1134,16 @@
 		}
 
+		function persist_shared_groups($location,$account_id)
+		{
+
+			$sql = "delete from phpgw_cc_contact_grps where oid in (
+				select A.oid from phpgw_cc_contact_grps A inner join phpgw_cc_groups B on A.id_group=B.id_group 
+				inner join phpgw_cc_contact_conns C on A.id_connection=C.id_connection 
+				inner join phpgw_cc_contact D on C.id_contact=D.id_contact
+				where B.owner=$location and D.id_owner=$account_id );";
+
+			return $this->query($sql);
+		}
+
 		/**
 		* Updates the data of one or more rows in a table, all data is quoted according to it's type
Index: /trunk/phpgwapi/inc/class.acl.inc.php
===================================================================
--- /trunk/phpgwapi/inc/class.acl.inc.php	(revision 2)
+++ /trunk/phpgwapi/inc/class.acl.inc.php	(revision 1280)
@@ -194,5 +194,10 @@
 			return $this->data;
 		}
-
+		
+		function persist_shared_groups($location)
+		{
+			$this->db->persist_shared_groups($location,$this->account_id);
+		}
+		
 		/*!
 		@function delete
Index: /trunk/contactcenter/inc/class.so_group.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.so_group.inc.php	(revision 752)
+++ /trunk/contactcenter/inc/class.so_group.inc.php	(revision 1280)
@@ -107,12 +107,25 @@
 		}
 		
-		
-		function selectAllContacts( $field = false )
-		{
-						
-			$query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value , B.id_typeof_contact_connection from phpgw_cc_contact A,'.
-			'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
-			'A.id_contact = B.id_contact and B.id_connection = C.id_connection and '.
-			'A.id_owner ='.$this->owner.' and C.connection_is_default = true ';
+		//Owner = null means the owner setted on constructor.
+		function selectAllContacts( $field = false ,$shared_from=null)
+		{
+			if($shared_from==null) {		
+				$query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value , B.id_typeof_contact_connection from phpgw_cc_contact A,'.
+				'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
+				'A.id_contact = B.id_contact and B.id_connection = C.id_connection and '.
+				'A.id_owner ='.$this->owner.' and C.connection_is_default = true ';
+			}
+			else {
+				$sub_query = 'select A.id_related from phpgw_cc_contact_rels A,phpgw_acl B
+							  where B.acl_location!=\'run\' and A.id_contact = B.acl_location::bigint and A.id_related = B.acl_account and 
+							  B.acl_appname = \'contactcenter\' and B.acl_rights & 1 <> 0 
+							  and A.id_typeof_contact_relation=1 and A.id_contact = '.$shared_from.' and A.id_related='.$this->owner;
+				
+				$query = 'select C.id_connection, A.id_contact, A.names_ordered, C.connection_value , B.id_typeof_contact_connection from phpgw_cc_contact A,'.
+				'phpgw_cc_contact_conns B, phpgw_cc_connections C where '.
+				'A.id_contact = B.id_contact and B.id_connection = C.id_connection and '.
+				'A.id_owner in ('.$shared_from.',('.$sub_query.'))'.
+				' and C.connection_is_default = true ';
+			}
 
 			if ( $field == 'only_email' )
@@ -256,5 +269,6 @@
 			'A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
 			'and B.id_typeof_contact_connection = 1 and '.
-			'A.id_owner ='.$this->owner.' and D.id_connection = C.id_connection and D.id_group = '.$id_group.
+			//'A.id_owner ='.$this->owner.' and D.id_connection = C.id_connection and D.id_group = '.$id_group.
+			' D.id_connection = C.id_connection and D.id_group = '.$id_group. //If I have the group ID, why ask about owner?
 			' order by A.names_ordered';
 						
Index: /trunk/contactcenter/inc/class.bo_group.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.bo_group.inc.php	(revision 702)
+++ /trunk/contactcenter/inc/class.bo_group.inc.php	(revision 1280)
@@ -36,7 +36,7 @@
 		}
 		
-		function get_all_contacts($field = false){
+		function get_all_contacts($field = false,$owner=null){
 		
-			$result = $this-> so -> selectAllContacts($field);
+			$result = $this-> so -> selectAllContacts($field,$owner);
 			return $result;
 		}
Index: /trunk/contactcenter/inc/class.ui_data.inc.php
===================================================================
--- /trunk/contactcenter/inc/class.ui_data.inc.php	(revision 962)
+++ /trunk/contactcenter/inc/class.ui_data.inc.php	(revision 1280)
@@ -312,5 +312,5 @@
 				
 				case 'get_group':
-					return $this->get_group_data($_GET['id']);
+					return $this->get_group_data($_GET['id'],isset($_GET['shared_from'])?$_GET['shared_from']:null);
 					
 				case 'get_contact_full_add_const':
@@ -1160,4 +1160,5 @@
 							$final[3][$i][5] = lang('Shared').": ".$owner_names[$owners[$i]]['cn'];
 							$final[3][$i][6] = $owner_names[$owners[$i]]['uid'];
+							$final[3][$i][7] = $owners[$i]; //uidNumber
 						}						
 						$i++;							
@@ -1313,5 +1314,5 @@
 		
 		*/		
-		function get_group_data($id)
+		function get_group_data($id,$shared_from=null)
 		{
 			$this->bo->catalog = CreateObject('contactcenter.bo_group_manager');
@@ -1326,5 +1327,5 @@
 			$boGroup = CreateObject('contactcenter.bo_group');
 						
-			$all_contacts = $boGroup->get_all_contacts('only_email');
+			$all_contacts = $boGroup->get_all_contacts('only_email',$shared_from);
 			
 			$contact_options = "";
Index: /trunk/contactcenter/js/cc.js
===================================================================
--- /trunk/contactcenter/js/cc.js	(revision 880)
+++ /trunk/contactcenter/js/cc.js	(revision 1280)
@@ -195,6 +195,6 @@
 }
 
-function editSharedGroup(id){
-	populateEditGroup(id, 'shared');	
+function editSharedGroup(id,shared){
+	populateEditSharedGroup(id, shared);	
 }
 
@@ -312,4 +312,8 @@
 function populateEditGroup (id)
 {
+	populateEditSharedGroup(id,false);
+}
+
+function populateEditSharedGroup(id,shared) {
 	var handler = function(responseText)
 	{			
@@ -345,5 +349,8 @@
 	
 	ccAddGroup.clear(true);				
-	Connector.newRequest('populateEditGroup', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_group&id='+id, 'GET', handler);
+	if(!shared)
+		Connector.newRequest('populateEditGroup', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_group&id='+id, 'GET', handler);
+	else
+		Connector.newRequest('populateEditGroup', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_group&id='+id+'&shared_from='+shared, 'GET', handler);
 }
 
@@ -2084,11 +2091,10 @@
 	
 				if (type == "shared_groups") {
-					/* Edição de grupos compartilhados está com problema. Desabilitado temporariamente.
+					
 					if (data[3][pos][4] & 4)
-						eval("document.getElementById(id + ':cc_card_edit').onclick = function(){editSharedGroup(Element('"+id+"' + ':cc_id').value);};");
-					else
-					*/ 
-					document.getElementById(id + ':cc_card_edit').onclick = function(){	alert(Element('cc_msg_unavailable').value); };
-					
+						eval("document.getElementById(id + ':cc_card_edit').onclick = function(){editSharedGroup(Element('"+id+"' + ':cc_id').value,"+data[3][pos][7]+");};");
+					else 
+						document.getElementById(id + ':cc_card_edit').onclick = function(){	alert(Element('cc_msg_not_allowed').value); };
+										
 					if (data[3][pos][4] & 8) 
 						eval("document.getElementById(id + ':cc_card_remove').onclick = function(){removeEntry(Element('" + id + "' + ':cc_id').value,'groups');};");
Index: /trunk/preferences/inc/class.uiaclprefs2.inc.php
===================================================================
--- /trunk/preferences/inc/class.uiaclprefs2.inc.php	(revision 496)
+++ /trunk/preferences/inc/class.uiaclprefs2.inc.php	(revision 1280)
@@ -101,9 +101,26 @@
 				$to_remove = unserialize(urldecode($processed));
 
-				for($i=0;$i<count($to_remove);$i++)				
-					$this->acl->delete($GLOBALS['phpgw_info']['flags']['currentapp'],$to_remove[$i]);
-				
+				/* User records */
+				$user_variable = $_POST['u_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
 				/* Group records */
 				$group_variable = $_POST['g_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
+				$keys_to_keep = array();
+				if(!empty($user_variable)) {
+					foreach($user_variable as $key_user=>$value) {
+						$temp = explode("_",$key_user);
+						$keys_to_keep[(int)$temp[0]] = 1;
+					}
+				}
+				
+				for($i=0;$i<count($to_remove);$i++) {
+					
+					if(!array_key_exists((int)$to_remove[$i],$keys_to_keep)) {
+						$this->acl->persist_shared_groups($to_remove[$i]);
+					}		
+					$this->acl->delete($GLOBALS['phpgw_info']['flags']['currentapp'],$to_remove[$i]);
+				}
+				
+				/* Group records */
+				//$group_variable = $_POST['g_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
 
 				if (!$group_variable)				
@@ -120,9 +137,13 @@
 					if($is_group)
 						$rights &= ~PHPGW_ACL_PRIVATE;
+					if(array_key_exists($user_id,$keys_to_keep))
+						if(($rights & 1) == 0) {
+							$this->acl->persist_shared_groups($user_id);
+						}
 					$this->acl->add($GLOBALS['phpgw_info']['flags']['currentapp'],$group_id,$rights);
 				}
 
 				/* User records */
-				$user_variable = $_POST['u_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
+				//$user_variable = $_POST['u_'.$GLOBALS['phpgw_info']['flags']['currentapp']];
 
 				if (!$user_variable)				
