Index: trunk/calendar/inc/class.bocalendar.inc.php
===================================================================
--- trunk/calendar/inc/class.bocalendar.inc.php	(revision 1492)
+++ trunk/calendar/inc/class.bocalendar.inc.php	(revision 1500)
@@ -379,4 +379,21 @@
 			$this->xmlrpc = is_object($GLOBALS['server']) && $GLOBALS['server']->last_method;
 		}
+
+		function delegar($idDelegador,$idDelegado,$idEvento) {
+
+			$this->so->cal->stream->lock(array("phpgw_cal_user"));
+			$sql = "update phpgw_cal_user set cal_login = $idDelegado,cal_status='U' where cal_id=$idEvento 
+					and cal_login=$idDelegador";
+
+			$this->so->cal->stream->query($sql,__LINE__,__FILE__,0,-1,true);
+
+			$this->so->cal->stream->unlock();
+			$event = $this->so->read_entry($idEvento);
+			/*foreach($event as $id=>$value)
+				echo "<br>".$id."  --  ".$value;
+			exit(0);*/
+			$this->send_update(MSG_ADDED,array($idDelegado => 'U'),$event,$event);
+		}
+
 
 	  function load_lang() {
@@ -3021,4 +3038,9 @@
 																		  		  <input type='hidden' name='cal_id' value=$event[id]>
 																		  		   </form>";
+																				   
+														$lang5 = lang("To Delegate");
+														$varbuttom4 = "<form action='".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.screen_delegate_event&id_event=$event[id]&date=$newall3&delegator=$tmpuid' method='POST'>
+																		  		  <input type='submit' value='$lang5'>
+																		  		   </form>";
 													}
 													else
@@ -3028,4 +3050,5 @@
 															$varbuttom2 = "";
 															$varbuttom3 = "";
+															$varbuttom4 = "";
 													}
 											}
@@ -3075,5 +3098,6 @@
 								'varbuttom1'		=> $varbuttom1,
 								'varbuttom2'		=> $varbuttom2,
-								'varbuttom3'		=> $varbuttom3 
+								'varbuttom3'		=> $varbuttom3,
+								'varbuttom4'		=> $varbuttom4
 								
 							);
Index: trunk/calendar/inc/class.uicalendar.inc.php
===================================================================
--- trunk/calendar/inc/class.uicalendar.inc.php	(revision 1447)
+++ trunk/calendar/inc/class.uicalendar.inc.php	(revision 1500)
@@ -57,4 +57,6 @@
 
 		var $public_functions = array(
+			'screen_delegate_event' => True,
+			'delegate_event' => True,
 			'mini_calendar' => True,
 			'index' => True,
@@ -163,4 +165,81 @@
 		}
 
+		function screen_delegate_event($params=NULL) {
+			$module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
+
+			$sb = CreateObject('phpgwapi.sbox2');
+			$jscal = CreateObject('phpgwapi.jscalendar');	// before phpgw_header() !!!
+			unset($GLOBALS['phpgw_info']['flags']['noheader']);
+			unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
+			$GLOBALS['phpgw_info']['flags']['noappheader'] = True;
+			$GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
+			$GLOBALS['phpgw_info']['flags']['app_header'] = $event['id'] ? lang('Calendar - Edit') : lang('Calendar - Add');
+			$GLOBALS['phpgw']->common->phpgw_header();
+			
+			$ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
+			$_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];
+			$_SESSION['phpgw_info']['expressomail']['user']['owner'] = $event['owner'];
+			$_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
+			$_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;		
+			$context = $GLOBALS['phpgw_info']['server']['ldap_context'];
+			$user_context = array();
+			foreach(explode(",",$GLOBALS['phpgw_info']['user']['account_dn']) as $i => $dn_part){
+				if($i)
+					$user_context[] = $dn_part;
+			}
+			// Prepara o contexto do usuario com sua OU raiz, pois ele pode pertencer a uma OU de nivel N.
+			$user_ou = explode(",",str_replace($context,"",implode(",",$user_context)));								
+			$user_context = trim(strtolower($user_ou[count($user_ou) - 2].",".$context));
+			// Fim		
+			// Verifica o tipo da visualização da árvore LDAP, configurado no admin da Agenda
+			$recursive = $GLOBALS['phpgw_info']['server']['cal_type_tree_participants'] == '1' ? true : false;
+			$combo_org = $this->get_organizations(trim(strtolower($context)),$user_context, $recursive);
+
+			$var = array(
+				"module_name" => $module_name,
+				"lang_loading" => lang("Loading"),
+				"lang_searching" => lang("Searching"),
+				"lang_users" => lang("Users"),
+				"lang_groups" => lang("Groups"),
+				"recursive" => ($recursive)?"":"search",
+				"options" => $combo_org	,
+				"id_event" => $_REQUEST["id_event"],
+				"delegator" => $_REQUEST["delegator"],
+				"lang_avaliable_users" => lang("Available Users and Groups"),
+				"lang_search_for" => lang("Search for"),
+				"lang_ou" => lang("Organization"),
+				"date" => $_REQUEST["date"],
+				"Delegate" => lang("Delegate"),
+				'url_template' => 'calendar/templates/'.$_SESSION['phpgw_info']['calendar']['user']['preferences']['common']['template_set']
+			);	
+			
+			if(isset($_REQUEST["error"]))
+				$var['error_msg'] = lang("Problems delegating. Make sure you haven't delegated to a person that was also invited to the meeting");
+				
+			$template = CreateObject('phpgwapi.Template',$this->template_dir);
+			$template->set_file(
+								array(
+									"screen"=>"delegate.tpl"
+									)
+							   );
+			$template->set_var($var);
+			print $template->fp('out','screen');
+		}
+
+
+		function delegate_event($params=NULL) {
+			$ldap = CreateObject('expressoMail1_2.ldap_functions');
+			$delegated = $ldap->uid2uidnumber($_REQUEST['delegated']);
+			try {
+				$this->bo->delegar($_REQUEST['delegator'],
+						$delegated,$_REQUEST['event']);
+				header("Location: index.php?menuaction=calendar.uicalendar.day&date=".$_REQUEST['date']);								
+			}catch(Exception $e) {
+				header("Location: index.php?menuaction=calendar.uicalendar.screen_delegate_event&id_event=". $_REQUEST["event"]."&delegator=".$_REQUEST["delegator"]."&date=".$_REQUEST["date"]."&error=1");
+			}
+
+			
+		}
+
 		/* Public functions */
 
@@ -4236,4 +4315,5 @@
 				{
 					$vars['participants']['data'][$user] = $parts[1].' (<a href="'.$this->page('edit_status','&cal_id='.$event['id'].'&owner='.$user).'">'.$parts[2].'</a>)';
+					$vars['participants']['data'][$user].='&nbsp;(<a href=\'index.php?menuaction=calendar.uicalendar.screen_delegate_event&id_event='.$event['id'].'&delegator='.$user.'&date='.$_REQUEST["date"].'\'>'.lang("Delegate event").'</a>)';
 				}
 			}
Index: trunk/calendar/templates/classic/delegate.tpl
===================================================================
--- trunk/calendar/templates/classic/delegate.tpl	(revision 1500)
+++ trunk/calendar/templates/classic/delegate.tpl	(revision 1500)
@@ -0,0 +1,54 @@
+<script type="text/javascript" src="phpgwapi/js/wz_dragdrop/wz_dragdrop.js"></script>
+<script type="text/javascript" src="phpgwapi/js/dJSWin/dJSWin.js"></script>
+<script src='{url_template}/js/edit_exmail.js' type='text/javascript'></script>
+<script src='{module_name}/inc/load_lang.php' type='text/javascript'></script>
+<script src='{module_name}/js/connector.js' type='text/javascript'></script>
+<script type='text/javascript'>var DEFAULT_URL = '{module_name}/controller.php?action=';</script> 
+<font color="#FF0000">{error_msg}</font>
+<form action="index.php">
+<input type="hidden" id="txt_loading" value="{lang_loading}">
+<input type="hidden" id="txt_searching" value="{lang_searching}">
+<input type="hidden" id="txt_users" value="{lang_users}">
+<input type="hidden" id="txt_groups" value="{lang_groups}">
+
+<input type="hidden" name="menuaction" value="calendar.uicalendar.delegate_event">
+<input type="hidden" name="event" value="{id_event}">
+<input type="hidden" name="delegator" value="{delegator}">
+<input type="hidden" name="date" value="{date}">
+<table>
+	<tr>
+		<td>
+			{lang_ou}
+		</td>
+		<td>
+			<select name="org_context" id="combo_org" onchange="javascript:get_available_only_users('{module_name}',this.value,'{recursive}');">{options}</select>
+		</td>
+	</tr>
+	<tr>
+		<td colspan='2'><font color="red"><span id="cal_span_searching">&nbsp;</span></font></td>
+	</tr>
+	<tr>
+		<td>
+			{lang_search_for}
+		</td>
+		<td>
+			<input value="" id="cal_input_searchUser" size="35" autocomplete="off" onkeyup="javascript:optionFinderTimeout(this,0)"><br>
+		</td>
+	</tr>
+	<tr>
+		<td colspan='2'>
+			{lang_avaliable_users}<br>
+			<select name="delegated" id="user_list_in" style="width: 300px" size="13"></select>'
+		</td>
+	</tr>
+	<tr>
+		<td colspan='2'>
+			<input type="submit" value="{Delegate}">
+		</td>
+	</tr>
+	
+</table>
+</form>
+<script type='text/javascript'>
+	setTimeout("get_available_only_users('{module_name}',document.getElementById('combo_org').value,'{recursive}');",1000);
+</script>
Index: trunk/calendar/templates/classic/js/edit_exmail.js
===================================================================
--- trunk/calendar/templates/classic/js/edit_exmail.js	(revision 1267)
+++ trunk/calendar/templates/classic/js/edit_exmail.js	(revision 1500)
@@ -21,5 +21,66 @@
 var agt = navigator.userAgent.toLowerCase();
 var is_firefox_0 = agt.indexOf('firefox/1.0') != -1 && agt.indexOf('firefox/0.') ? true : false;
- 
+
+function optionFinderTimeout(obj)
+{
+	clearTimeout(finderTimeout);	
+	var oWait = document.getElementById("cal_span_searching");
+	oWait.innerHTML = document.getElementById("txt_searching").value + '...';
+	var finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
+}
+function optionFinder(id) {
+	var oWait = document.getElementById("cal_span_searching");
+	var oText = document.getElementById(id);			
+	var select_available_users_tmp = document.getElementById('user_list_in')
+	for(var i = 0;i < select_available_users_tmp.options.length; i++)
+		select_available_users_tmp.options[i--] = null;
+
+	var RegExp_name = new RegExp("\\b"+oText.value, "i");
+
+	for(i = 0; i < select_available_users_clone.length; i++){
+		if (RegExp_name.test(select_available_users_clone[i].text) || select_available_users_clone[i].value =="-1")
+		{
+			sel = select_available_users_tmp.options;
+			option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);
+			if( select_available_users_clone[i].value == "-1") option.disabled = true;
+			sel[sel.length] = option;
+		}
+	}	
+	oWait.innerHTML = '&nbsp;';
+}	
+	
+/*
+	Semelhante a função get_avaiable_users, porém trás apenas usuários, ignorando os grupos...
+*/
+function get_available_only_users(path,context,type) {
+	var handler_get_available_users2 = function(data)
+	{	
+		select_available_users = document.getElementById('user_list_in');
+		
+		for(var i=0; i<select_available_users.options.length; i++){
+			select_available_users.options[i] = null;
+			i--;
+		}
+		var options = '###';
+		if (data) {
+			
+			options += '<option  value="-1" disabled>------------------- '+document.getElementById("txt_users").value+' ------------------ </option>' + data;
+			
+			if(is_firefox_0)
+				fixBugInnerSelect(select_available_users,options);
+			else
+				select_available_users.innerHTML = options;
+
+			select_available_users.outerHTML = select_available_users.outerHTML;
+			select_available_users.disabled = false;
+			select_available_users_clone = document.getElementById('user_list_in').cloneNode(true);
+			document.getElementById('cal_input_searchUser').value = '';
+		}
+	}	
+
+	document.getElementById('combo_org').value = context;
+	cExecute (path+'.ldap_functions.get_available_users2&valueAsUidNum=1&context='+context+'&type='+type, handler_get_available_users2);	
+}
+
 function get_available_users(filter,autoSearch)
 //function get_available_users(path,context,type)
@@ -210,5 +271,5 @@
 	loadScript(path+"/js/common_functions.js");
 	loadScript(path+"/js/QuickCatalogSearch.js");
-	loadScript("calendar/templates/classic/js/over_fn_exmail.js");
+	loadScript("calendar/templates/default/js/over_fn_exmail.js");
 	if(!contacts)
 		cExecute (path+'.db_functions.get_dropdown_contacts', save_contacts);
@@ -389,2 +450,3 @@
 	}
 };
+
Index: trunk/calendar/templates/default/delegate.tpl
===================================================================
--- trunk/calendar/templates/default/delegate.tpl	(revision 1500)
+++ trunk/calendar/templates/default/delegate.tpl	(revision 1500)
@@ -0,0 +1,54 @@
+<script type="text/javascript" src="phpgwapi/js/wz_dragdrop/wz_dragdrop.js"></script>
+<script type="text/javascript" src="phpgwapi/js/dJSWin/dJSWin.js"></script>
+<script src='{url_template}/js/edit_exmail.js' type='text/javascript'></script>
+<script src='{module_name}/inc/load_lang.php' type='text/javascript'></script>
+<script src='{module_name}/js/connector.js' type='text/javascript'></script>
+<script type='text/javascript'>var DEFAULT_URL = '{module_name}/controller.php?action=';</script> 
+<font color="#FF0000">{error_msg}</font>
+<form action="index.php">
+<input type="hidden" id="txt_loading" value="{lang_loading}">
+<input type="hidden" id="txt_searching" value="{lang_searching}">
+<input type="hidden" id="txt_users" value="{lang_users}">
+<input type="hidden" id="txt_groups" value="{lang_groups}">
+
+<input type="hidden" name="menuaction" value="calendar.uicalendar.delegate_event">
+<input type="hidden" name="event" value="{id_event}">
+<input type="hidden" name="delegator" value="{delegator}">
+<input type="hidden" name="date" value="{date}">
+<table>
+	<tr>
+		<td>
+			{lang_ou}
+		</td>
+		<td>
+			<select name="org_context" id="combo_org" onchange="javascript:get_available_only_users('{module_name}',this.value,'{recursive}');">{options}</select>
+		</td>
+	</tr>
+	<tr>
+		<td colspan='2'><font color="red"><span id="cal_span_searching">&nbsp;</span></font></td>
+	</tr>
+	<tr>
+		<td>
+			{lang_search_for}
+		</td>
+		<td>
+			<input value="" id="cal_input_searchUser" size="35" autocomplete="off" onkeyup="javascript:optionFinderTimeout(this,0)"><br>
+		</td>
+	</tr>
+	<tr>
+		<td colspan='2'>
+			{lang_avaliable_users}<br>
+			<select name="delegated" id="user_list_in" style="width: 300px" size="13"></select>'
+		</td>
+	</tr>
+	<tr>
+		<td colspan='2'>
+			<input type="submit" value="{Delegate}">
+		</td>
+	</tr>
+	
+</table>
+</form>
+<script type='text/javascript'>
+	setTimeout("get_available_only_users('{module_name}',document.getElementById('combo_org').value,'{recursive}');",1000);
+</script>
Index: trunk/calendar/templates/default/js/edit_exmail.js
===================================================================
--- trunk/calendar/templates/default/js/edit_exmail.js	(revision 1268)
+++ trunk/calendar/templates/default/js/edit_exmail.js	(revision 1500)
@@ -21,5 +21,38 @@
 var agt = navigator.userAgent.toLowerCase();
 var is_firefox_0 = agt.indexOf('firefox/1.0') != -1 && agt.indexOf('firefox/0.') ? true : false;
- 
+	
+/*
+	Semelhante a função get_avaiable_users, porém trás apenas usuários, ignorando os grupos...
+*/
+function get_available_only_users(path,context,type) {
+	var handler_get_available_users2 = function(data)
+	{	
+		select_available_users = document.getElementById('user_list_in');
+		
+		for(var i=0; i<select_available_users.options.length; i++){
+			select_available_users.options[i] = null;
+			i--;
+		}
+		var options = '###';
+		if (data) {
+			
+			options += '<option  value="-1" disabled>------------------- '+document.getElementById("txt_users").value+' ------------------ </option>' + data;
+			
+			if(is_firefox_0)
+				fixBugInnerSelect(select_available_users,options);
+			else
+				select_available_users.innerHTML = options;
+
+			select_available_users.outerHTML = select_available_users.outerHTML;
+			select_available_users.disabled = false;
+			select_available_users_clone = document.getElementById('user_list_in').cloneNode(true);
+			document.getElementById('cal_input_searchUser').value = '';
+		}
+	}	
+
+	document.getElementById('combo_org').value = context;
+	cExecute (path+'.ldap_functions.get_available_users2&valueAsUidNum=1&context='+context+'&type='+type, handler_get_available_users2);	
+}
+
 function get_available_users(filter,autoSearch)
 //function get_available_users(path,context,type)
@@ -389,2 +422,3 @@
 	}
 };
+
