Index: trunk/jabberit_messenger/inc/getphoto.php
===================================================================
--- trunk/jabberit_messenger/inc/getphoto.php	(revision 551)
+++ trunk/jabberit_messenger/inc/getphoto.php	(revision 697)
@@ -176,21 +176,22 @@
 		$photoHeight = 90;
 		$newImage = imagecreatetruecolor($photoWidth,$photoHeight);		
-		
+
 		if($photo)
 		{
 			$photo = imagecreatefromstring($photo);
-			$trans = imagecolortransparent($photo);
 			imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
-			imagepng($newImage);
-			imagedestroy($newImage);
 		}
 		else
 		{
 			$photo = @imagecreatefrompng("../templates/default/images/photo.png");
-			$trans = imagecolortransparent($photo);
 			imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
-			imagepng($newImage);
-			imagedestroy($newImage);
-		}
+		}
+
+		ob_start();
+		imagepng($newImage);
+		$imagePhoto = ob_get_contents();
+		imagedestroy($newImage);
+		ob_end_clean();
+		printf("%s",base64_encode($imagePhoto));
 	}
 	else
Index: trunk/jabberit_messenger/inc/controller.xml
===================================================================
--- trunk/jabberit_messenger/inc/controller.xml	(revision 563)
+++ trunk/jabberit_messenger/inc/controller.xml	(revision 697)
@@ -33,10 +33,13 @@
 			<item ref="contacts_im" alias="getParticipantsExternal" class="contacts_im" method="getParticipantsExternal" prefix="class." suffix=".inc.php"/>
 			<item ref="contacts_im" alias="list_contacts" class="contacts_im" method="list_contacts" prefix="class." suffix=".inc.php"/>
+			<item ref="contacts_im" alias="verifyAddNewContact" class="contacts_im" method="verifyAddNewContact" prefix="class." suffix=".inc.php"/>
 			<item ref="db_im" alias="getPreferences" class="db_im" method="getPreferences" prefix="class." suffix=".inc.php"/>
 			<item ref="db_im" alias="setAttributesLdap" class="db_im" method="setAttributesLdap" prefix="class." suffix=".inc.php"/>
 			<item ref="db_im" alias="setPreferences" class="db_im" method="setPreferences" prefix="class." suffix=".inc.php"/>
 			<item ref="db_im" alias="setUseParticipantsExternal" class="db_im" method="setUseParticipantsExternal" prefix="class." suffix=".inc.php"/>
+			<item ref="db_im" alias="setOuGroupsLocked" class="db_im" method="setOuGroupsLocked" prefix="class." suffix=".inc.php"/>
 			<item ref="db_im" alias="setOrganization" class="db_im" method="setOrganization" prefix="class." suffix=".inc.php"/>
 			<item ref="db_im" alias="removeAttributesLdap" class="db_im" method="removeAttributesLdap" prefix="class." suffix=".inc.php"/>
+			<item ref="db_im" alias="removeOuGroupsLocked" class="db_im" method="removeOuGroupsLocked" prefix="class." suffix=".inc.php"/>
 			<item ref="db_im" alias="removeParticipantsExternal" class="db_im" method="removeParticipantsExternal" prefix="class." suffix=".inc.php"/>
 			<item ref="ldap_im" alias="list_organizations_ldap" class="ldap_im" method="list_organizations_ldap" prefix="class." suffix=".inc.php"/>
Index: trunk/jabberit_messenger/inc/class.uienabledgroups.inc.php
===================================================================
--- trunk/jabberit_messenger/inc/class.uienabledgroups.inc.php	(revision 697)
+++ trunk/jabberit_messenger/inc/class.uienabledgroups.inc.php	(revision 697)
@@ -0,0 +1,168 @@
+<?php
+  /***************************************************************************\
+  *  Expresso - Expresso Messenger                                            *
+  *  	- Alexandre Correia / Rodrigo Souza							          *
+  * ------------------------------------------------------------------------- *
+  *  This program is free software; you can redistribute it and/or modify it  *
+  *  under the terms of the GNU General Public License as published by the    *
+  *  Free Software Foundation; either version 2 of the License, or (at your   *
+  *  option) any later version.                                               *
+  \***************************************************************************/
+  
+require_once "class.boenabledgroups.inc.php";
+
+class uienabledgroups
+{
+	private $bo;
+	
+	public $public_functions = array(
+		'backPage'  => True,
+		'editGroups' => True,
+		'getGroups' => True,
+	);
+	
+	function __construct()
+	{
+		$this->bo = new boenabledgroups();
+	}
+	
+	public final function backPage()
+	{
+		echo "<pre>";
+		print_r($_POST);
+		echo "</pre>";
+	}	
+
+	public final function editGroups()
+	{
+		if($_GET['menuaction'])
+		{
+			if($GLOBALS['phpgw']->acl->check('applications_access',1,'admin'))
+			{
+				$GLOBALS['phpgw']->redirect_link('/index.php');
+			}		
+			
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('Admin') .' - ' . 'Liberar Organizações para grupos restritos';
+	
+			$GLOBALS['phpgw']->common->phpgw_header();
+			echo parse_navbar();
+	
+			$webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url'];
+			$webserver_url = ( !empty($webserver_url) ) ? $webserver_url : '/';
+	
+			if(strrpos($webserver_url,'/') === false || strrpos($webserver_url,'/') != (strlen($webserver_url)-1))
+				$webserver_url .= '/';
+	
+			// Load Language;
+			require_once "load_lang.php";
+			
+			// Load Ldap;
+			require_once "class.ldap_im.inc.php";
+			
+			$ldap = new ldap_im();
+			
+			$ous = "<option value='-1'>-- ".lang('Select Organization')." --</option>";	
+			if( ($LdapOus = $ldap->listOrganizationsLdap()) )
+			{
+				foreach($LdapOus as $tmp )
+					$ous .= "<option value='".$tmp."'>".$tmp."</option>";
+			}
+
+			$group = unserialize($_GET['groups']);
+			$valueGroupsOrganizations = "";
+			
+			if( $group[2] )
+			{
+				$ou_groups = explode(",",$group[2]);
+			
+				natcasesort($ou_groups);
+			
+				foreach($ou_groups as $tmp)
+				{
+					$valueGroupsOrganizations .= "<tr id='".$tmp."'>";
+					$valueGroupsOrganizations .= "<td align='left' class='row_on'>".$tmp."</td>";
+					$valueGroupsOrganizations .= "<td align='left' class='row_on' style='width:30% !important'><a href='javascript:constructScript.removeOrgGroupsLocked(\"".$tmp."\");'>Excluir</a></td>";					
+					$valueGroupsOrganizations .= "</tr>";
+				}
+			}
+			
+			
+			$GLOBALS['phpgw']->template->set_file(array('jabberit_messenger'=>'confGroupsLocked.tpl'));
+			$GLOBALS['phpgw']->template->set_block('jabberit_messenger','confGroups');	
+			$var = array(
+							'action_url' => "./index.php?menuaction=jabberit_messenger.uienabledgroups.getGroups",
+							'lang_Back' => "Voltar",	
+							'lang_Cadastrar_Organizacao' => "Cadastrar Organização",	
+							'lang_Delete' => "Excluir",							
+							'lang_Informe_as_Organizacoes' => "Informe as Organizações",
+							'lang_Nome_Grupo' => "Nome do Grupo",
+							'lang_Organizacoes_cadastradas_para_grupo' => "Organizações cadastradas para o grupo",	
+							'lang_Organization' => "Organização",
+							'lang_save' => "Salvar",
+							'value_Groups_Organizations' => $valueGroupsOrganizations,	
+							'value_organizations_ldap' => $ous,							
+							'value_Name_Group' => $group[0],
+							'value_gidNumber' => $group[1],
+						);	
+			$GLOBALS['phpgw']->template->set_var($var);
+			$GLOBALS['phpgw']->template->pparse('out','confGroups');
+		}
+	}
+
+	public final function getGroups()
+	{
+		if($GLOBALS['phpgw']->acl->check('applications_access',1,'admin'))
+		{
+			$GLOBALS['phpgw']->redirect_link('/index.php');
+		}		
+		
+		$GLOBALS['phpgw_info']['flags']['app_header'] = lang('Admin') .' - ' . 'Liberar Organizações para grupos restritos';
+
+		$GLOBALS['phpgw']->common->phpgw_header();
+		echo parse_navbar();
+
+		$webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url'];
+		$webserver_url = ( !empty($webserver_url) ) ? $webserver_url : '/';
+
+		if(strrpos($webserver_url,'/') === false || strrpos($webserver_url,'/') != (strlen($webserver_url)-1))
+			$webserver_url .= '/';
+
+		echo '<script type="text/javascript">var path_jabberit="'.$webserver_url .'"</script>';
+
+		// Load Language;
+		require_once "load_lang.php";
+
+		$groups_locked_jabberit = $this->bo->getGroupsBlocked();
+
+		if(trim($groups_locked_jabberit))
+		{
+			$glocked = explode(';',$GLOBALS['phpgw_info']['server']['groups_locked_jabberit']);
+			$list_groups = "";
+
+			natcasesort($glocked);
+						
+			foreach( $glocked as $tmp )
+			{
+				$groups = explode(":",$tmp);
+				$list_groups .= "<tr class='row_off'>";
+				$list_groups .= "<td width='30%'>".$groups[0]."</td>";
+				$list_groups .= "<td width='55%'>".$groups[2]."</td>";
+				$list_groups .= "<td width='5%' align='center'><a href='./index.php?menuaction=jabberit_messenger.uienabledgroups.editGroups&groups=".serialize($groups)."'>Editar</a></td>";
+				$list_groups .= "</tr>";
+			}
+		}
+
+		$GLOBALS['phpgw']->template->set_file(array('jabberit_messenger'=>'enabled_ou_groups.tpl'));
+		$GLOBALS['phpgw']->template->set_block('jabberit_messenger','enabled_ous');	
+		$var = array(
+						'action_url' => './admin',						
+						'lang_back' => lang("Back"),
+						'list_groups' => (trim($list_groups) != "") ? $list_groups : "",
+					);	
+		$GLOBALS['phpgw']->template->set_var($var);
+		$GLOBALS['phpgw']->template->pparse('out','enabled_ous');
+	}
+}
+
+
+?>
Index: trunk/jabberit_messenger/inc/login.php
===================================================================
--- trunk/jabberit_messenger/inc/login.php	(revision 622)
+++ trunk/jabberit_messenger/inc/login.php	(revision 697)
@@ -80,10 +80,16 @@
 		}
 
+		// Enable Plugins Java;
+		$pluginsJava[] = $path . "applet.jar?" . filemtime("applet.jar");
+		$pluginsJava[] = $path . "plugins/filetransfer.jar?" . filemtime("plugins/filetransfer.jar");
+		$pluginsJava[] = $path . "plugins/xhtml.jar?" . filemtime("plugins/xhtml.jar");
+		
+		for($i = 0; $i < count($pluginsJava); $i++)
+			$javaFiles .= $pluginsJava[$i] . ",";
+
+		// Load Template;
 		$template = new Template('templates/default');
 		$template->set_var("path", $path);
-		$template->set_var("file0", filemtime("applet.jar"));
-		$template->set_var("file1", filemtime("plugins/groupchat.jar"));
-		$template->set_var("file2", filemtime("plugins/sound.jar"));
-		$template->set_var("file3", filemtime("plugins/xhtml.jar"));		
+		$template->set_var("java_files", $javaFiles);
 		$template->set_var("value_server",$_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']);
 		$template->set_var("value_host",$_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']);			
Index: trunk/jabberit_messenger/inc/jabberit_acl.inc.php
===================================================================
--- trunk/jabberit_messenger/inc/jabberit_acl.inc.php	(revision 563)
+++ trunk/jabberit_messenger/inc/jabberit_acl.inc.php	(revision 697)
@@ -55,11 +55,11 @@
 			$ExternalParticipants = implode(",", $ExternalParticipants);
 		}
-					
+		
 		require_once dirname(__FILE__) . '/load_lang.php';
 		
-		print "<script type='text/javascript'>".
-				 "var path_jabberit='".$webserver_url."';".
-			 	 "var externalParticipantsJabberit='".$ExternalParticipants."';".
-			  "</script>";
+		$var_js  = "var path_jabberit='".$webserver_url."';";
+		$var_js	.= "var externalParticipantsJabberit='".$ExternalParticipants."';";
+
+		echo "<script type=\"text/javascript\">".$var_js."</script>";
 
 		$js = array(
Index: trunk/jabberit_messenger/inc/class.contacts_im.inc.php
===================================================================
--- trunk/jabberit_messenger/inc/class.contacts_im.inc.php	(revision 598)
+++ trunk/jabberit_messenger/inc/class.contacts_im.inc.php	(revision 697)
@@ -19,9 +19,19 @@
 	private $ldap;
 	private $db;
-	
+	private $ou_User;
+		
 	public final function __construct()
 	{
 		$this->ldap = new ldap_im();
-		$this->db = new db_im();		
+		$this->db = new db_im();
+
+		$ou_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn'];
+		$ou_User = substr($this->ou_User,strpos($this->ou_User, "ou="));
+		$ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc=")));
+
+		// (OU) User
+		$this->ou_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn'];
+		$this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou="));
+		$this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc=")));
 	}
 
@@ -45,6 +55,9 @@
 		{
 			$groups = explode(":", $tmp);
-			if( array_search($groups[1], $memberShip) !== False)
+			if( array_search($groups[1], $memberShip) !== False )
+			{	
+				$_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked'] = $groups[2]; 
 				return true;
+			}
 		}
 		
@@ -82,5 +95,5 @@
 		return $return;
 	}
-	
+
 	private final function users_auth_im($pName)
 	{   
@@ -88,4 +101,5 @@
         $count = count($array_uids);
         $uids_members = array();
+        $result = array();
         
         for($i = 0; $i < $count ;$i+=50)
@@ -94,17 +108,140 @@
             $filter_uid = implode(")(uidnumber=",$partial_uids);
             $filter_uid = "(uidnumber=". $filter_uid. ")";
-            $result = $this->ldap->list_users_ldap("cn=*".$pName."*", $filter_uid, $this->groupsLocked());
-            if ( is_array($result) )
-            	$uids_members = array_merge($uids_members,$result);            	            
+
+			if( $this->groupsLocked() )
+			{
+	            $orgs[] = $this->ou_User;
+	            $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']); 
+	            
+				foreach( $orgsGroupsLocked as $tmp )
+				{
+					if( $tmp != "" )
+						$orgs[] = "OU=". $tmp;            
+				}
+				
+	            $orgs = array_unique($orgs);
+
+				foreach( $orgs as $tmp )
+					$result[] = $this->ldap->list_users_ldap("cn=*".$pName."*", $filter_uid, $tmp);
+			}
+			else
+	            $result[] = $this->ldap->list_users_ldap("cn=*".$pName."*", $filter_uid);
+        }
+
+        if ( is_array($result) )
+        {
+          	for($i = 0; $i < count($result); $i++)
+           		if(is_array($result[$i]))
+           			$uids_members = array_merge($uids_members,$result[$i]);
+        }
 	        
-	        if(count($uids_members) > 50){
-	        	unset($_SESSION['phpgw_info']['jabberit_messenger']['photo']);	        
-	          	return 'Many Results';
-	        }            
-        }
-        if(count($uids_members) > 0)
+        if( count($uids_members) > 50 )
+        {
+        	unset($_SESSION['phpgw_info']['jabberit_messenger']['photo']);	        
+          	return 'Many Results';
+        }            
+        
+        if( count($uids_members) > 0 )
             return $uids_members;
         else
-            return 0;   
+            return 0;  
+	}
+	
+	public final function verifyAddNewContact($pUid)
+	{
+		$groupsLocked =  explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']);
+		$gidNumbers = array();
+		$uid = $pUid['uid'];
+
+		foreach($groupsLocked as $tmp)
+		{
+			$groups = explode(":", $tmp);
+			$gidNumbers[] = $groups[1];
+		}
+		
+		$filter_gid = implode(")(gidnumber=",$gidNumbers);
+	    $filter_gid = "(gidnumber=". $filter_gid. ")";
+		
+		$result = $this->ldap->list_groups_memberUid($filter_gid);
+
+		if( $result && is_array($result) )
+		{
+			array_shift($result);
+			$i = 0;
+			
+			foreach($result as $value)
+			{
+				$Groups[$i]['dn'] = $value['dn'];
+				$Groups[$i]['gidnumber'] = $value['gidnumber'][0];
+				if(array_key_exists('memberuid',$value))
+				{
+					array_shift($value['memberuid']);
+					$Groups[$i++]['memberuid'] = $value['memberuid'];
+				}
+			}
+
+			$search = array();
+			$search_Gid = array();
+			
+			// Verifica Uid em Grupo Bloqueado
+			foreach($Groups as $value)
+			{			
+				if( array_search( $uid , $value['memberuid'] ) !== false )
+				{
+					$ou = substr($value['dn'],strpos($value['dn'], "ou="));
+					$search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc=")));
+					$search_Gid[] = $value['gidnumber'];
+				}	
+			}
+		}
+
+		if( $this->groupsLocked() )
+		{
+			if( count($search) > 0 )
+			{
+				// Verifica permissões do grupo
+				foreach($groupsLocked as $value)
+				{							
+					$tpGroups = explode(":",$value);
+					if( $tpGroups[1] == $search_Gid[0] )
+					{
+						$ousTp = explode(",",$tpGroups[2]);
+						$ou_User = substr($this->ou_User,3);
+						
+						if( array_search( $ou_User, $ousTp) !== false )
+							return "true";
+					}
+				}
+				return "false";
+			}
+			else
+				return "true";
+		} 
+		else
+		{		
+			// Se Bloqueado verifica o Grupo	
+			if( count($search) > 0 )
+			{
+				if( array_search($this->ou_User, $search) === false )
+				{
+					// Verifica permissões do grupo
+					foreach($groupsLocked as $value)
+					{							
+						$tpGroups = explode(":",$value);
+						if( $tpGroups[1] == $search_Gid[0] )
+						{
+							$ousTp = explode(",",$tpGroups[2]);
+							$ou_User = substr($this->ou_User,3);
+								
+							if( array_search( $ou_User, $ousTp) !== false )
+								return "true";
+						}
+					}
+					return "false";
+				}
+				return "true";
+			}					
+			return "true";
+		}
 	}
 }
Index: trunk/jabberit_messenger/inc/hook_admin.inc.php
===================================================================
--- trunk/jabberit_messenger/inc/hook_admin.inc.php	(revision 563)
+++ trunk/jabberit_messenger/inc/hook_admin.inc.php	(revision 697)
@@ -18,6 +18,6 @@
 		'Configuration of authentication attribute by Organization (OU)' => $GLOBALS['phpgw']->link('/index.php','menuaction=jabberit_messenger.uiconforganization.edit_conf'),
 		'External Participants' => $GLOBALS['phpgw']->link('/index.php','menuaction=jabberit_messenger.uiexternals.editParticipantsExternals'),
-		'Deny module\'s use by group' => $GLOBALS['phpgw']->link('/index.php','menuaction=jabberit_messenger.uigroupslocked.editGroups')
-		
+		'Deny module\'s use by group' => $GLOBALS['phpgw']->link('/index.php','menuaction=jabberit_messenger.uigroupslocked.editGroups'),
+		'Liberar Organizações para grupos restritos' => $GLOBALS['phpgw']->link('/index.php','menuaction=jabberit_messenger.uienabledgroups.getGroups'),
 	);
 
Index: trunk/jabberit_messenger/inc/class.ldap_im.inc.php
===================================================================
--- trunk/jabberit_messenger/inc/class.ldap_im.inc.php	(revision 563)
+++ trunk/jabberit_messenger/inc/class.ldap_im.inc.php	(revision 697)
@@ -35,9 +35,4 @@
 		$this->jid			= $_SESSION['phpgw_info']['jabberit_messenger']['user'];
 		$this->max_result	= 50;
-		
-		// Ou User
-		$this->ou_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn'];
-		$this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou="));
-		$this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc=")));
 	}
 
@@ -85,4 +80,22 @@
 		
 		@ldap_bind($this->ldap,$this->ldap_dn,$this->ldap_pass);
+	}
+
+	public final function list_groups_memberUid($pGroup)
+	{
+		$this->_ldapConnect();
+		
+		if( $this->ldap )
+		{
+			$filter = "(&(objectclass=posixgroup)(|".$pGroup."))";
+			$justthese = array("dn","memberuid","gidnumber");
+			$search = ldap_search($this->ldap,$this->ldap_context,$filter, $justthese);
+			$result = ldap_get_entries($this->ldap,$search);
+			
+			if( $result['count'] > 0 )
+				return $result;
+		}		
+		
+		return false;
 	}
 
@@ -156,5 +169,5 @@
 	}
 
-	public final function list_users_ldap($search, $uidnumber, $groupsDeny)
+	public final function list_users_ldap( $search, $uidnumber, $ous = false )
 	{
 		$this->_connect_ldap();
@@ -166,10 +179,12 @@
 			// SERPRO
 			//$justthese = array("uid","uidNumber","cn","mail","description","phpgwAccountVisible","dn","jpegPhoto");
-			if( $groupsDeny )			
-				$search = ldap_search($this->ldap,$this->ou_User.",".$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1);
+	
+			if( $ous != false )
+				$search = ldap_search($this->ldap,$ous.",".$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1);
 			else
 				$search = ldap_search($this->ldap,$this->ldap_context,$filter,$justthese, 0, $this->max_result + 1);
+
 			$entry1 = ldap_get_entries($this->ldap,$search);
-			$entry = ldap_first_entry( $this->ldap, $search );
+			$entry  = ldap_first_entry($this->ldap,$search);
 		}
 
@@ -297,5 +312,4 @@
 		return $result_groups;
 	}
-
 }
 
Index: trunk/jabberit_messenger/inc/class.db_im.inc.php
===================================================================
--- trunk/jabberit_messenger/inc/class.db_im.inc.php	(revision 622)
+++ trunk/jabberit_messenger/inc/class.db_im.inc.php	(revision 697)
@@ -112,4 +112,29 @@
 	}
 	
+	public final function getGroupsBlocked()
+	{
+		$return = "";
+		
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";	
+			
+			if($this->db->query($query))
+			{
+
+				if ( $this->db->query($query) )
+				{	
+					while($this->db->next_record())
+						$result[] = $this->db->row();
+				}
+				
+				if( count($result) > 0 )
+					$return = $result[0]['config_value'];
+			}
+		}
+		
+		return $return;
+	}
+	
 	public final function getPreferences()
 	{
@@ -126,17 +151,17 @@
 		}
 
-		return "openWindowJabberit:true;openWindowJabberitPopUp:false";
-
+		return "openWindowJabberit:true;openWindowJabberitPopUp:false;flagAwayIM:5";
+		//return "openWindowJabberit:true;openWindowJabberitPopUp:false";		
 	}
 
 	public final function setPreferences($pParam)
 	{
-		$preferences = $preferences1 = $pParam['preferences1'];
+		$preferences = $pParam['preferences1'];
 		
 		if(isset($pParam['preferences2']))
-		{
-			$preferences2 = $pParam['preferences2'];
-			$preferences .= ";". $preferences2;
-		}
+			$preferences .= ";". $pParam['preferences2'];
+		
+		if(isset($pParam['preferences3']))
+			$preferences .= ";". $pParam['preferences3'];
 		
 		$user_id  = $this->user_id;
@@ -291,4 +316,76 @@
 	}
 	
+	public final function setOuGroupsLocked($pGroup)
+	{
+		$group = $pGroup['group'];
+		$gidnumber = $pGroup['gidnumber'];
+		$organization = strtoupper($pGroup['ou']);
+
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";	
+			
+			if($this->db->query($query))
+			{
+
+				if ( $this->db->query($query) )
+				{	
+					while($this->db->next_record())
+						$result[] = $this->db->row();
+				}
+
+				$groupsLocked = explode(";",$result[0]['config_value']);
+					
+				foreach( $groupsLocked as $tmp )
+				{
+					$aux = explode(":", $tmp);
+					if(($group.":".$gidnumber) == ($aux[0].":".$aux[1]))
+					{
+						if( $aux[2] )
+						{
+							$ou_groups = explode(",",$aux[2]);
+							natcasesort($ou_groups);
+							$key = array_search($organization, $ou_groups);
+							
+							if( $key === false )
+								array_push($ou_groups, $organization);
+							
+							$groups .= $group.":".$gidnumber.":";
+							
+							$return = "<return>";						
+							
+							foreach($ou_groups as $tmp)
+							{
+								$return .= "<ou attr='".$tmp."'>".$tmp."</ou>";
+								$groups .= $tmp .",";	
+							}
+							
+							$return .= "</return>";
+							
+							$groups  = substr($groups,0,strlen($groups)-1);
+							$groups .= ";";
+						}
+						else
+						{
+							$groups .= $group.":".$gidnumber.":".$organization.";";
+							$return = "<return><ou attr='".$organization."'>".$organization."</ou></return>";
+						}
+					}
+					else
+						$groups .= $tmp . ";" ;
+				}
+
+				$groups = substr($groups,0,strlen($groups)-1);
+
+				$query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";
+				$this->db->query($query);
+				
+				return $return;
+			}
+		}
+		
+		return false;
+	}
+	
 	public final function setUseParticipantsExternal($pFlag)
 	{
@@ -377,4 +474,62 @@
 	}
 	
+	public final function removeOuGroupsLocked($pGroup)
+	{
+		$group = $pGroup['group'];
+		$gidnumber = $pGroup['gidnumber'];
+		$organization = strtoupper($pGroup['ou']);
+		$return = false;
+		
+		if( $this->db )
+		{
+			$query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";	
+			
+			if($this->db->query($query))
+			{
+
+				if ( $this->db->query($query) )
+				{	
+					while($this->db->next_record())
+						$result[] = $this->db->row();
+				}
+
+				$groupsLocked = explode(";",$result[0]['config_value']);
+				
+				foreach( $groupsLocked as $tmp )
+				{
+					$aux = explode(":",$tmp);
+					
+					if(($group.":".$gidnumber) == ($aux[0].":".$aux[1]))
+					{
+						$ous = explode(",", $aux[2]);
+						$key = array_search($organization, $ous);
+
+						if( $key !== false )
+							unset($ous[$key]);
+
+						$groups .= $group.":".$gidnumber.":";
+						
+						foreach($ous as $ouTmp)
+							$groups .= $ouTmp .",";	
+						
+						$groups  = substr($groups,0,strlen($groups)-1);
+						$groups .= ";";
+					}
+					else
+						$groups .= $tmp . ";" ;									
+				}
+					
+				$groups  = substr($groups,0,strlen($groups)-1);
+			
+				$query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";
+
+				if( $this->db->query($query))
+					$return = true;
+			}
+		}	
+		
+		return $return;
+	}
+	
 	public final function removeAttributesLdap($pOrg)
 	{
Index: trunk/jabberit_messenger/inc/class.boenabledgroups.inc.php
===================================================================
--- trunk/jabberit_messenger/inc/class.boenabledgroups.inc.php	(revision 697)
+++ trunk/jabberit_messenger/inc/class.boenabledgroups.inc.php	(revision 697)
@@ -0,0 +1,31 @@
+<?php
+
+  /***************************************************************************\
+  *  Expresso - Expresso Messenger                                            *
+  *  	- Alexandre Correia / Rodrigo Souza							          *
+  * ------------------------------------------------------------------------- *
+  *  This program is free software; you can redistribute it and/or modify it  *
+  *  under the terms of the GNU General Public License as published by the    *
+  *  Free Software Foundation; either version 2 of the License, or (at your   *
+  *  option) any later version.                                               *
+  \***************************************************************************/
+
+require_once "class.db_im.inc.php";
+require_once "jabberit_sessions.inc.php";
+
+class boenabledgroups
+{
+	private $db;
+	
+	function __construct()
+	{
+		$this->db = new db_im();
+	}
+
+	public final function getGroupsBlocked()
+	{
+		return $this->db->getGroupsBlocked();		
+	}
+}
+
+?>
