Index: trunk/expressoAdmin1_2/inc/class.uishared_accounts.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.uishared_accounts.inc.php	(revision 5133)
+++ trunk/expressoAdmin1_2/inc/class.uishared_accounts.inc.php	(revision 5804)
@@ -51,4 +51,9 @@
 			$contexts = $acl['contexts'];
                         
+                        // Loading Config Module
+                        $conf = CreateObject('phpgwapi.config','phpgwapi');
+                        $conf->read_repository();
+                        $config = $conf->config_data;  
+                        
 			foreach ($acl['contexts_display'] as $index=>$tmp_context) {
 				$context_display .= '<br>'.$tmp_context;
@@ -100,5 +105,7 @@
                             'changequote_disabled' => $this->functions->check_acl($account_lid,'edit_shared_accounts_quote') ? '' : 'readonly',
                             'disabled_empty_inbox' => $this->functions->check_acl($account_lid,'empty_shared_accounts_inbox') ? '' : 'disabled',
-                            'display_quota_used' => 'none'
+                            'display_quota_used' => 'none',
+                            'aclExpressoCalendar' => (isset($config['defaultCalendar']) && ($config['defaultCalendar'] == 'expressoCalendar')) ? '' : 'none',
+                            'aclCalendar' => (isset($config['defaultCalendar']) && ($config['defaultCalendar'] == 'calendar')) ? '' : 'none'
                         );
                         $p->set_var($var);
@@ -107,7 +114,7 @@
 			
 			$var = Array(
-				'th_bg'						=> $GLOBALS['phpgw_info']['theme']['th_bg'],
-				'back_url'					=> $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
-				'context_display'			=> $context_display,
+				'th_bg'	=> $GLOBALS['phpgw_info']['theme']['th_bg'],
+				'back_url' => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
+				'context_display' => $context_display,
 				'shared_accounts_modal' => $shared_accounts_modal_tpl,                                
 				'onclick_create_shared_account' => "modal(\"$modal_id\",\"create\")"
Index: trunk/expressoAdmin1_2/js/jscode/shared_accounts.js
===================================================================
--- trunk/expressoAdmin1_2/js/jscode/shared_accounts.js	(revision 5589)
+++ trunk/expressoAdmin1_2/js/jscode/shared_accounts.js	(revision 5804)
@@ -168,4 +168,5 @@
 		Element('em_input_saveAcl').checked = false;
 		Element('em_input_folderAcl').checked = false;
+                
                 Element('em_input_readCalendar').checked = false;
                 Element('em_input_writeCalendar').checked = false;
@@ -173,4 +174,11 @@
                 Element('em_input_deleteCalendar').checked = false;
                 Element('em_input_restrictCalendar').checked = false;
+                
+                Element('em_input_readExpressoCalendar').checked = false;
+                Element('em_input_writeExpressoCalendar').checked = false;
+                Element('em_input_freebusyExpressoCalendar').checked = false;
+                Element('em_input_deleteExpressoCalendar').checked = false;
+                
+                
         Element('em_input_sendAcl').disabled = true;
         select_owners = Element('ea_select_owners');
@@ -182,7 +190,9 @@
 {
 	select_owners = Element('ea_select_owners');
+        
+        var user = '';
 	for(var i = 0;i < select_owners.options.length; i++)
 		if(select_owners.options[i].selected){
-                        var user = select_owners.options[i].value;
+                        user = select_owners.options[i].value;
                         delete sharemailbox.ownersAcl[user];
                        sharemailbox.ownersCalendarAcl[user] = '';
@@ -193,7 +203,27 @@
        if(select_owners.options.length > 0 ){
             select_owners.options[0].selected = true;
-            var user = select_owners.options[0].value;
+            user = select_owners.options[0].value;
             sharemailbox.getaclfromuser(user);
        }
+       
+       if(sharemailbox.ownersExpressoCalendarAcl){
+
+            delete sharemailbox.ownersExpressoCalendarAcl[user];
+
+            var sharedUser = DataLayer.get('user', {filter: ['=','mail',$('#mail').val()]});
+            var signature = DataLayer.get('calendarSignature', {filter: ['=','user', sharedUser[0].id]});
+
+            var usuario = DataLayer.get('user', {filter: ['AND', ['=','uid',user], ['*','mail',user] ]});
+            var calendarPermission = DataLayer.get('calendarToPermission', {filter: ['AND', ['=','calendar',signature[0].calendar], ['=','user',usuario[0].id] ] });
+
+            var signatureUser = DataLayer.get('calendarSignature', {filter: ['AND', ['=','calendar', signature[0].calendar], ['=','user', usuario[0].id ] ]});
+
+            DataLayer.remove('calendarSignature', signatureUser[0].id);
+            DataLayer.remove('calendarToPermission', calendarPermission[0].id);
+
+        }
+       
+       
+       
 }
 
@@ -261,7 +291,9 @@
             Element('desc').value = data.description;
             //Necessario, pois o IE6 tem um bug que não exibe as novas opções se o innerHTML estava vazio
-            Element('ea_select_owners').innerHTML = '&nbsp;' + data.owners_options;
-            Element('ea_select_owners').outerHTML = Element('ea_select_owners').outerHTML;
-
+            
+            if(data.owners_options){
+                Element('ea_select_owners').innerHTML = '&nbsp;' + data.owners_options;
+                Element('ea_select_owners').outerHTML = Element('ea_select_owners').outerHTML;
+            }
             Element('display_empty_inbox').style.display = data.display_empty_inbox;
             if( data.allow_edit_shared_account_acl == "0"){
@@ -283,9 +315,35 @@
                         sharemailbox.ownersCalendarAcl = new Array();
             if( data.owners && data.owners != "undefined" && data.owners_acl != "undefined" ){ 
-				for (i=0; i<data.owners.length; i++){
-						sharemailbox.ownersAcl[ data.owners[i] ] = data.owners_acl[i];	
-                                                sharemailbox.ownersCalendarAcl[ data.owners[i] ] = data.owners_calendar_acl[i];
-				}
+                for (i=0; i<data.owners.length; i++){
+                                sharemailbox.ownersAcl[ data.owners[i] ] = data.owners_acl[i];	
+                                sharemailbox.ownersCalendarAcl[ data.owners[i] ] = data.owners_calendar_acl[i];
+                }
             }
+
+            //new API compatibility
+            var signature = DataLayer.get('calendarSignature', {filter: ['=','user', data.uidnumber]});
+            if(!!signature){
+                sharemailbox.currentPemissions[data.uidnumber] = true;
+                var calendarPermission = DataLayer.get('calendarToPermission:detail', {filter: ['=','calendar',signature[0].calendar], criteria:{deepness: 2}});
+                if(calendarPermission){
+                    var owners_options = '';
+                    for (i=0; i < calendarPermission.length; i++){
+                        sharemailbox.ownersExpressoCalendarAcl[ calendarPermission[i].user.uid ] = calendarPermission[i].aclValues;
+                        owners_options += '<option value='+calendarPermission[i].user.uid+'>'+calendarPermission[i].user.name+'</option>'
+                        sharemailbox.currentPemissions[calendarPermission[i].user.uid] = calendarPermission[i].id;
+                    }
+
+
+                    delete sharemailbox.currentPemissions[undefined];
+                    delete sharemailbox.currentPemissions[undefined];
+
+                    Element('ea_select_owners').innerHTML = '&nbsp;' + owners_options;
+                    Element('ea_select_owners').outerHTML = Element('ea_select_owners').outerHTML;
+                    
+                }
+        
+            }
+            
+            
 		}
 		else
@@ -304,15 +362,88 @@
 	else   form = document.forms["shared_accounts_form"];
         
-         hidden_owners_calendar_acl = Element('owners_calendar_acls');
+        hidden_owners_calendar_acl = Element('owners_calendar_acls');
 	hidden_owners_acl = Element('owners_acls');
 	select_owners = Element('ea_select_owners');
 	for(var i = 0;i < select_owners.options.length; i++){		
-		var user = select_owners.options[i].value;                
-		select_owners.options[i].value = user;
-		}
+            var user = select_owners.options[i].value;                
+            select_owners.options[i].value = user;
+        }
         hidden_owners_acl.value =  admin_connector.serialize(sharemailbox.ownersAcl);
+        
+        if(sharemailbox.ownersExpressoCalendarAcl){
+            
+            var calback = function(){
+                var sharedUser = DataLayer.get('user', {filter: ['=','mail',$('#mail').val()]});
+
+                if(!!sharedUser && $.isArray(sharedUser))
+                    sharedUser = sharedUser[0];
+
+                if(!!!sharemailbox.currentPemissions[sharedUser.id])
+                    DataLayer.put('calendarSignature', {
+                        user: sharedUser.id,
+                        calendar:  {
+                            timezone: 'America/Sao_Paulo',
+                            name: $('#cn').val(),
+                            location : $('#cn').val(),
+                            description : $('#cn').val()
+                            },
+                        isOwner:  '1',
+                        fontColor:  '000000',
+                        backgroundColor: 'f1efac',
+                        borderColor: 'eddb21'
+                    });
+
+                var returns = function(data){
+                    
+                    
+                    var calendar = '';
+                    
+                    if(data){
+                        for(var i in data)
+                            if(i.indexOf('calendar:') >= 0)
+                                calendar = data[i].id;
+                    }else{
+                        calendar = DataLayer.get('calendarSignature', {filter: ['=','user', sharedUser.id]});
+                        calendar = calendar[0].calendar;
+                    }
+                    
+                $.each(sharemailbox.ownersExpressoCalendarAcl, function(user, acl) {
+
+                        var usuario = DataLayer.get('user', {filter: ['AND', ['=','uid',user], ['*','mail',user] ]});
+
+                        if($.isArray(usuario))
+                            usuario = usuario[0];
+
+                        
+                        DataLayer.put('calendarToPermission', DataLayer.merge({
+                            user:  usuario.id,
+                            type: '0',
+                            acl: acl,
+                            calendar: calendar
+                        }, !!sharemailbox.currentPemissions[usuario.uid] ? {id: sharemailbox.currentPemissions[usuario.uid]} : {}));
+                        
+                        if(!!!sharemailbox.currentPemissions[usuario.uid])
+                            DataLayer.put('calendarSignature', {
+                                user: usuario.id,
+                                calendar:  calendar,
+                                isOwner:  '0',
+                                fontColor:  '000000',
+                                backgroundColor: 'f1efac',
+                                borderColor: 'eddb21'
+                            });
+
+                    })
+                    DataLayer.commit();  
+                };
+                if(!!sharemailbox.currentPemissions[sharedUser.id])
+                    returns(false);
+                else
+                    DataLayer.commit(false, false, returns);
+            }
+        }
         hidden_owners_calendar_acl.value =  admin_connector.serialize(sharemailbox.ownersCalendarAcl);
 	cExecuteForm ("$this.shared_accounts.save", form, handler_save_shared_accounts);
         get_shared_accounts(Element('ea_shared_account_search').value);
+        calback();
 }
 
@@ -364,4 +495,6 @@
 		this.ownersAcl = new Array();
                 this.ownersCalendarAcl = new Array();
+                this.ownersExpressoCalendarAcl = {};
+                this.currentPemissions = {};
 	}
 
@@ -409,7 +542,38 @@
                 Element('em_input_restrictCalendar').checked = false;
 
+                Element('em_input_readExpressoCalendar').checked = false;
+                Element('em_input_writeExpressoCalendar').checked = false;
+                Element('em_input_freebusyExpressoCalendar').checked = false;
+                Element('em_input_deleteExpressoCalendar').checked = false;
+
                 Element('em_input_editCalendar').disabled = true;
                 Element('em_input_deleteCalendar').disabled = true;
                 Element('em_input_restrictCalendar').disabled = true;
+                
+                
+                if(this.ownersExpressoCalendarAcl[user])
+                {
+                    if (this.ownersExpressoCalendarAcl[user].indexOf('r') >= 0)
+                    {
+                            Element('em_input_readExpressoCalendar').checked = true;
+                            Element('em_input_writeExpressoCalendar').checked = false;
+                            Element('em_input_freebusyExpressoCalendar').checked = false;
+                            Element('em_input_deleteExpressoCalendar').checked = false;
+                            
+                    }
+                    if (this.ownersExpressoCalendarAcl[user].indexOf('w') >= 0)
+                    {
+                            Element('em_input_writeExpressoCalendar').checked = true;
+                    }
+                    if (this.ownersExpressoCalendarAcl[user].indexOf('d') >= 0)
+                    {
+                            Element('em_input_deleteExpressoCalendar').checked = true;
+                    }
+                    if (this.ownersExpressoCalendarAcl[user].indexOf('b') >= 0)
+                    {
+                            Element('em_input_freebusyExpressoCalendar').checked = true;
+                    }
+                }
+                
 		
                 if(this.ownersCalendarAcl[user])
@@ -418,20 +582,28 @@
                     {
                             Element('em_input_readCalendar').checked = true;
-
                             Element('em_input_editCalendar').disabled = false;
                             Element('em_input_deleteCalendar').disabled = false;
                             Element('em_input_restrictCalendar').disabled = false;
+                            
+                            Element('em_input_readExpressoCalendar').checked = true;
+                            Element('em_input_writeExpressoCalendar').checked = false;
+                            Element('em_input_freebusyExpressoCalendar').checked = false;
+                            Element('em_input_deleteExpressoCalendar').checked = false;
+                            
                     }
                     if (this.ownersCalendarAcl[user].indexOf('2-',0) >= 0)
                     {
                             Element('em_input_writeCalendar').checked = true;
+                            Element('em_input_writeExpressoCalendar').checked = true;
                     }
                     if (this.ownersCalendarAcl[user].indexOf('4-',0) >= 0)
                     {
                             Element('em_input_editCalendar').checked = true;
+                            Element('em_input_writeExpressoCalendar').checked = true;
                     }
                     if (this.ownersCalendarAcl[user].indexOf('8-',0) >= 0)
                     {
                             Element('em_input_deleteCalendar').checked = true;
+                            Element('em_input_deleteExpressoCalendar').checked = true;
                     }
                     if (this.ownersCalendarAcl[user].indexOf('16-',0) >= 0)
@@ -535,4 +707,6 @@
 		var acl		= '';
 		var select 	= Element('ea_select_owners');
+                
+                sharemailbox.ownersExpressoCalendarAcl = false;
 
 		if(select.selectedIndex == "-1"){
@@ -556,9 +730,9 @@
                         Element('em_input_deleteCalendar').disabled = false;
                         Element('em_input_restrictCalendar').disabled = false;
-
+                        
                         if (Element('em_input_editCalendar').checked)
                                 acl += '4-';
 
-                        if (Element('em_input_deleteCalendar').checked)
+                        if (Element('em_input_deleteCalendar').checked )
                                 acl += '8-';
 
@@ -574,11 +748,77 @@
                         Element('em_input_deleteCalendar').checked = false;
                         Element('em_input_restrictCalendar').checked = false;
-                    }
-
-                    if (Element('em_input_writeCalendar').checked)
+                        
+                    }
+
+                    if (Element('em_input_writeCalendar').checked || Element('em_input_writeExpressoCalendar').checked)
                             acl += '2-';
 
 
                     this.ownersCalendarAcl[user] = acl;
+                }
+	}
+        
+        cShareMailbox.prototype.setExpressoCalendaraclfromuser = function()
+	{
+		var acl		= '';
+		var select 	= Element('ea_select_owners');
+                
+                sharemailbox.ownersCalendarAcl = false;
+
+		if(select.selectedIndex == "-1"){
+			alert("Selecione antes um usuario!");
+			return false;
+		}
+                
+                for(var k = 0; k < select.options.length; k ++ )
+                {
+                    if(select.options[k].selected !== true ) continue;
+                    
+                    acl = '';
+                    var user = select.options[k].value;
+                    
+                    if(Element('em_input_freebusyExpressoCalendar').checked)
+                    {
+                        Element('em_input_writeExpressoCalendar').disabled = true;
+                        Element('em_input_deleteExpressoCalendar').disabled = true;
+                        Element('em_input_readExpressoCalendar').disabled = true;
+                        Element('em_input_writeExpressoCalendar').checked = false;
+                        Element('em_input_deleteExpressoCalendar').checked = false;
+                        Element('em_input_readExpressoCalendar').checked = false;
+                                              
+                        
+                        acl += 'b'
+                    }
+                    else
+                    {
+                        Element('em_input_readExpressoCalendar').disabled = false;
+                        if (Element('em_input_readExpressoCalendar').checked)
+                        {
+                            acl += 'r';
+
+                            Element('em_input_writeExpressoCalendar').disabled = false;
+                            Element('em_input_deleteExpressoCalendar').disabled = false;
+                            //Element('em_input_freebusyExpressoCalendar').disabled = false;
+
+                            if (Element('em_input_writeExpressoCalendar').checked)
+                                    acl += 'w';
+
+                            if (Element('em_input_deleteExpressoCalendar').checked)
+                                    acl += 'd';
+
+                        }
+                        else
+                        {
+                            Element('em_input_writeExpressoCalendar').disabled = true;
+                            Element('em_input_deleteExpressoCalendar').disabled = true;
+                            //Element('em_input_freebusyExpressoCalendar').disabled = true;
+                            Element('em_input_writeExpressoCalendar').checked = false;
+                            Element('em_input_deleteExpressoCalendar').checked = false;
+                           // Element('em_input_freebusyExpressoCalendar').checked = false;
+                        }
+
+                    }
+                    
+                    this.ownersExpressoCalendarAcl[user] = acl;
                 }
 	}
@@ -650,4 +890,5 @@
 		Element('em_input_saveAcl').checked = false;
 		Element('em_input_folderAcl').checked = false;
+                
                 Element('em_input_readCalendar').checked = false;
                 Element('em_input_writeCalendar').checked = false;
@@ -655,4 +896,9 @@
                 Element('em_input_deleteCalendar').checked = false;
                 Element('em_input_restrictCalendar').checked = false;
+                
+                Element('em_input_readExpressoCalendar').disabled = true;
+                Element('em_input_writeExpressoCalendar').disabled = true;
+                Element('em_input_deleteExpressoCalendar').disabled = true;
+                Element('em_input_readExpressoCalendar').disabled = true;
 	}
 	
Index: trunk/expressoAdmin1_2/js/jscode/assing_calendar.js
===================================================================
--- trunk/expressoAdmin1_2/js/jscode/assing_calendar.js	(revision 5804)
+++ trunk/expressoAdmin1_2/js/jscode/assing_calendar.js	(revision 5804)
@@ -0,0 +1,346 @@
+function assing_calendar_user(path){
+        
+        path = !!path ? path : 'templates/default/';
+    	var html = DataLayer.render(path+'assing_calendar.ejs', {});	
+	
+	//Variaval global para manipulação dos usuários
+	//melhor perforface
+	currentUsers = {};
+	currentUsers[User.me.id] = true;
+        
+        searchType = 'calendar';
+	
+	if (!UI.dialogs.assingCalendar) {
+			UI.dialogs.assingCalendar = jQuery('#assingCalendar').append('<div title="Compatilhamento de Agenda" class="assing-calendar active"> <div>').find('.assing-calendar.active').html(html).dialog({
+				resizable: false, 
+				modal:true, 
+				autoOpen: false,
+				width:620, 
+				position: 'center', 
+				close: function(event, ui) {
+					//Implementações de cancelar
+					currentUsers = {};
+				}
+			});
+		} else {
+			UI.dialogs.assingCalendar.html(html);
+		}		
+		
+		UI.dialogs.assingCalendar.find('.button').button()
+		.filter('.cancel').click(function(evt){
+			UI.dialogs.assingCalendar.dialog("close");
+		}).end()
+		.filter('.save').click(function(evt){
+			//TODO - API ainda não suporta
+			//UI.dialogs.assingCalendar.find('form').submit();
+                        var calendarSelected = UI.dialogs.assingCalendar.find('dd.calendar input[name="calendarId"]').val();
+			var save = function(){
+				if($('li.not-user').length == 0)
+				$.each(UI.dialogs.assingCalendar.find('.user-list li.new'), function( i , element ){
+					var user = $(element).find('input[name="user[]"]').val();
+					var acl = $(element).find('input[name="attendeeAcl[]"]').val()+'p';
+					if(acl == "")
+                                            return true;
+					
+                                        DataLayer.put('calendarToPermission', {calendar: calendarSelected, type: 0, user: user, acl: acl});
+
+                                        DataLayer.put('calendarSignature', 
+                                        {
+                                            calendar: calendarSelected, 
+                                            isOwner: 0, 
+                                            user: user, 
+                                            fontColor: '120d0d', 
+                                            backgroundColor: 'e36d76', 
+                                            borderColor: 'd5130b' 
+                                        });
+				});
+                                
+                                $.each(UI.dialogs.assingCalendar.find('.user-list li.current'), function( i , element ){
+                                    
+                                    var user = $(element).find('input[name="user[]"]').val();
+                                    var acl = $(element).find('input[name="attendeeAcl[]"]').val()+'p';
+                                    var id = $(element).find('input[name="permission[]"]').val();
+                                    if(acl == "")
+                                        DataLayer.remove('calendarToPermission', id);
+					
+                                    DataLayer.put('calendarToPermission', {id: id, calendar: calendarSelected, type: 0, user: user, acl: acl});
+                                    
+                                });
+				
+                                DataLayer.commit(false, false, function(data){
+					UI.dialogs.assingCalendar.dialog("close");
+				});
+			};
+
+			if(!!UI.dialogs.assingCalendar.find('.user-list li input[name="attendeeAcl[]"][value=""]').length){
+				$.Zebra_Dialog('Alguns usuários estão sem permissões e serão automáticamente removidos, deseja continuar ?', {
+					'type':     'question',
+					'overlay_opacity': '0.5',
+					'buttons':  ['Continuar', 'Cancelar'],
+					'onClose':  function(clicked) {
+						if(clicked == 'Continuar') {
+							save();
+						}
+					}
+				});
+			}else
+				save();		
+		});
+		
+		UI.dialogs.assingCalendar.find('.add-user-search .ui-icon-search').click(function(event) {
+			UI.dialogs.assingCalendar.find('.add-user-search input').keydown();
+		});
+		
+		var incompatibleAcl = function (obj, acls, buttons){
+			for (var i = 0; i < acls.length; i++){
+				var objremove = obj.parent().find('.'+buttons[i]+'');
+				if(objremove.hasClass('attendee-permissions-change-button'))
+					changeAcl(objremove, acls[i]);
+			}
+		}
+
+		var removeAcl = function(current, acl){
+			var acls = '';
+			for(var i = 0; i < current.length; i++)
+				if(current.charAt(i) != acl)
+					acls += current.charAt(i) ;
+			return acls;
+		}
+
+		var dependsAcl = function(obj, acls, buttons){
+			for (var i = 0; i < acls.length; i++){
+				var objremove = obj.parent().find('.'+buttons[i]+'');
+				if(!objremove.hasClass('attendee-permissions-change-button'))
+					changeAcl(objremove, acls[i]);
+			}
+		}
+		
+		var changeAcl = function(obj, acl){
+			if(obj.hasClass('attendee-permissions-change-button')){
+				 obj.parent().siblings('input[name="attendeeAcl[]"]').val(removeAcl( obj.parent().siblings('input[name="attendeeAcl[]"]').val(), acl)) ; 
+			}else{
+				var acls = obj.parent().siblings('input[name="attendeeAcl[]"]').val();
+				obj.parent().siblings('input[name="attendeeAcl[]"]').val(acls + acl);
+			}
+			obj.toggleClass('attendee-permissions-change-button')
+			.find('span:first').toggleClass('attendee-permissions-change').end();  
+		}
+		
+		
+		UI.dialogs.assingCalendar.find('.add-user-search input').keydown(function(event) {
+			if(event.keyCode == '13' || typeof(event.keyCode) == 'undefined') {
+                            
+                                var result = '';
+                                var group  = '';
+                                if(searchType == 'calendar')
+                                    result = DataLayer.get('calendarToPermission', {filter: ['AND', ['=','type','1'], ['OR', ['i*','name', $(this).val()], ['i*', 'description', $(this).val()] ] ] , criteria: {deepness: 2}});
+                                else{
+                                    result = DataLayer.get('user', ["*", "name", $(this).val()], true);
+                                    group = DataLayer.get('group', ["*", "name", $(this).val()], true); 
+				
+                                    if(!!group){
+                                        if(!!result)
+                                                DataLayer.merge(result, group);
+                                        else
+                                                result = group;
+                                    }
+                                }
+                                /**
+				* TODO: trocar por template
+				*/
+				UI.dialogs.assingCalendar.find('ul.search-result-list').empty().css('overflow', 'hidden');
+				if (!result) {
+					UI.dialogs.assingCalendar.find('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>');
+				}
+
+                                if(searchType == 'calendar')
+                                     for(i=0; i<result.length; i++){
+                                    	result[i].name = result[i].calendar.name;
+                                        result[i].id = result[i].calendar.id;
+                                        result[i].enabled = true;
+                                     }
+                                else
+                                    for(i=0; i<result.length; i++)
+                                    	result[i].enabled = currentUsers[result[i].id] ? false : true;
+
+				UI.dialogs.assingCalendar.find('ul.search-result-list').append(DataLayer.render( path+'participants_search_itemlist.ejs', result));
+
+				UI.dialogs.assingCalendar.find('ul.search-result-list li').click(function(event, ui){
+					if ($(event.target).is('input')) {
+                                             old_item = $(event.target).parents('li');
+                                             
+                                             if(searchType == 'calendar'){
+                                                 
+                                                 searchType = 'user';
+                                                 
+                                                 UI.dialogs.assingCalendar.find('dd.calendar input[name="calendarId"]').val(old_item.find('.id').html());
+                                                 
+                                                 //TODO - Trocar por template
+                                                 UI.dialogs.assingCalendar.find('dd.calendar ul').append('<li class="calendar-selected">' + old_item.find('.name').html() +
+                                                 '<a class="button tiny removeCalendar"></a></li>');
+                                             
+                                             
+                                                 var currentData = DataLayer.get('calendarToPermission:detail', {filter: ['AND', ['=','calendar', old_item.find('.id').html()], ['i*','acl','p'] ],  criteria: {deepness: 2}})
+                                                 
+                                                 if(currentData){
+                                                     for(var i = 0; i < currentData.length; i++){
+                                                         
+                                                         currentUsers[currentData[i].user.id] = currentData[i].user;
+                                                         
+                                                         UI.dialogs.assingCalendar.find('dd.calendar-list ul.user-list')
+                                                        .append(DataLayer.render(path+'user_shared_add_itemlist.ejs', [{id: currentData[i].user.id, name: currentData[i].user.name, mail: currentData[i].user.mail, isCurrent: true, permission: currentData[i].id}]))
+                                                        .scrollTo('max');
+
+                                                        $('li.not-user').remove();
+                                                        callbackSharedCotactsAdd();
+                                                        
+                                                        for (var f in currentData[i].acl){
+                                                            if(currentData[i].acl[f]){
+                                                                    UI.dialogs.assingCalendar.find('.'+f+':last').toggleClass('attendee-permissions-change-button')
+                                                                    .find('span:first').toggleClass('attendee-permissions-change').end();  
+                                                            }
+                                                        }
+                                                         
+                                                     }
+                                                     
+                                                 }
+
+                                                 UI.dialogs.assingCalendar.find('.removeCalendar').button({
+                                                        icons: {
+                                                                primary: "ui-icon-close"
+                                                        },
+                                                        text: false
+                                                }).click(function(evt){
+                                                        $(this).parents('li').remove();
+                                                        searchType = 'calendar';
+                                                        
+                                                        UI.dialogs.assingCalendar.find('ul.search-result-list li').remove();
+                                                        UI.dialogs.assingCalendar.find('dt.add-user.search').html('Pesquisa agendas');
+                                                 });
+                                                 
+                                                 UI.dialogs.assingCalendar.find('ul.search-result-list li').remove();
+                                                 UI.dialogs.assingCalendar.find('dt.add-user.search').html('Pesquisa usuários');
+                                                 
+                                                 
+                                             }else{
+						
+						var id = old_item.find('.id').html();
+						
+						currentUsers [id] = {
+							id: id,
+							name: old_item.find('.name').html(),
+							mail: old_item.find('.mail').html()
+						};
+											
+						UI.dialogs.assingCalendar.find('dd.calendar-list ul.user-list')
+						.append(DataLayer.render(path+'user_shared_add_itemlist.ejs', [{id: id, name: currentUsers [id] .name, mail: currentUsers [id] .mail}]))
+						.scrollTo('max');
+						
+						$('li.not-user').remove();
+						callbackSharedCotactsAdd();
+						old_item.remove();
+                                            }
+					}
+				});
+				event.preventDefault();
+			}
+		});
+
+		var callbackSharedCotactsAdd = function(event){
+			UI.dialogs.assingCalendar.find('.button').filter(".read.new").button({
+				icons: {
+					primary: "ui-icon-circle-zoomin"
+				},
+				text: false
+			}).click(function () {
+				incompatibleAcl($(this), ['b'], ['busy']);
+				changeAcl($(this), 'r');
+			})
+			.addClass('tiny disable ui-button-disabled ui-state-disabled')
+			.removeClass('new').end()
+			
+			.filter(".write.new").button({
+				icons: {
+					primary: "ui-icon-key"
+				},
+				text: false
+			}).click(function () {
+				incompatibleAcl($(this), ['b'], ['busy']);
+				dependsAcl($(this), ['r'], ['read']);
+				changeAcl($(this), 'w');
+			})
+			.addClass('tiny disable ui-button-disabled ui-state-disabled')
+			.removeClass('new').end()
+			
+			.filter(".remove.new").button({
+				icons: {
+					primary: "ui-icon-trash"
+				},
+				text: false
+			}).click(function () {
+				incompatibleAcl($(this), ['b'], ['busy']);
+				dependsAcl($(this), ['r'], ['read']);
+				changeAcl($(this), 'd');
+			})
+			.addClass('tiny disable ui-button-disabled ui-state-disabled')
+			.removeClass('new').end()
+			
+			.filter(".busy.new").button({
+				icons: {
+					primary: "ui-icon-clock"
+				},
+				text: false
+			}).click(function () {
+				//Remove incompativbilidade de acls
+				incompatibleAcl($(this), ['r', 'w', 'd', 's' ], ['read', 'write', 'remove', 'shared']);
+				changeAcl($(this), 'b');
+			})
+			.addClass('tiny disable ui-button-disabled ui-state-disabled')
+			.removeClass('new').end()
+			
+			.filter(".shared.new").button({
+				icons: {
+					primary: "ui-icon-transferthick-e-w"
+				},
+				text: false
+			}).click(function () {
+				incompatibleAcl($(this), ['b',], ['busy']);
+				dependsAcl($(this), ['r'], ['read']);
+				changeAcl($(this), 's');
+			})
+			.addClass('tiny disable ui-button-disabled ui-state-disabled')
+			.removeClass('new').end()
+
+			.filter(".close.new").button({
+				icons: {
+					primary: "ui-icon-close"
+				},
+				text: false
+			}).click(function () {
+				currentUsers[$(this).parents().find('input[name="user[]"]').val()] = false;
+                                var id = false;
+                                
+                                if(id = $(this).parents().find('input[name="permission[]"]').val())
+                                    DataLayer.remove('calendarToPermission', id);
+                                
+				$(this).parents('li').remove();
+			})
+			.addClass('tiny disable ui-button-disabled ui-state-disabled')
+			.removeClass('new').end();
+
+		UI.dialogs.assingCalendar.find('.user-list li').hover(
+			function () {
+				$(this).addClass("hover-user");
+				$(this).find('.button').removeClass('disable ui-button-disabled ui-state-disabled').end()
+				.find('.user-acls-shared-calendar').addClass('hover-user');
+			},
+			function () {
+				$(this).removeClass("hover-user");
+				$(this).find('.button').addClass('disable ui-button-disabled ui-state-disabled').end()
+				.find('.user-acls-shared-calendar').removeClass('hover-user');;
+			}
+		);		
+	}
+	UI.dialogs.assingCalendar.dialog('open');
+}
+
Index: trunk/expressoAdmin1_2/index.php
===================================================================
--- trunk/expressoAdmin1_2/index.php	(revision 5133)
+++ trunk/expressoAdmin1_2/index.php	(revision 5804)
@@ -9,5 +9,39 @@
 	*  option) any later version.														 *
 	\*************************************************************************************/
-	$debug = false;	
+	
+        echo '
+            <link rel="Stylesheet" type="text/css" href="../prototype/plugins/jquery/jquery-ui.css" />					
+    
+            <script type="text/javascript" src="../prototype/plugins/jquery/jquery.min.js"></script>
+        
+            <script type="text/javascript" src="../prototype/plugins/jquery/jquery-ui.min.js"></script>
+            <script type="text/javascript" src="../prototype/plugins/jquery/jquery-ui.custom.min.js"></script>
+            <script src="../prototype/plugins/json2/json2.js" language="javascript"></script>
+            <script src="../prototype/plugins/ejs/ejs.js" language="javascript"></script>
+            <script src="../prototype/plugins/store/jquery.store.js" language="javascript"></script>
+            
+            <script src="../prototype/api/datalayer.js" language="javascript"></script>	
+           
+            <link rel="stylesheet" type="text/css" href="../prototype/plugins/zebradialog/css/zebra_dialog.css"></link>
+
+            <script type="text/javascript" src="../prototype/plugins/zebradialog/javascript/zebra_dialog.js"></script>
+            <script language="javascript">DataLayer.dispatchPath = "../prototype/";</script>
+            <script type="text/javascript" src="../prototype/plugins/datejs/date-pt-BR.js"></script>
+            <script type="text/javascript" src="../prototype/plugins/datejs/sugarpak.js"></script>
+            <script type="text/javascript" src="../prototype/plugins/datejs/parser.js"></script>
+
+            <script type="text/javascript" src="../prototype/modules/calendar/js/timezone.js"></script>	
+            
+            <script type="text/javascript" src="../prototype/modules/calendar/js/calendar.codecs.js"></script>
+            
+            <script type="text/javascript" src="js/jscode/assing_calendar.js"></script>
+            <script type="text/javascript" src="../prototype/plugins/scrollto/jquery.scrollTo.js"></script>
+
+            <link rel="stylesheet" type="text/css" href="../prototype/modules/calendar/css/layout.css" />
+            <link rel="stylesheet" type="text/css" href="../prototype/modules/calendar/css/style.css" />
+            <link rel="stylesheet" type="text/css" href="templates/default/assing_calendar.css" />
+        ';
+
+        $debug = false;	
 	$time_start = microtime(true);
 
@@ -20,4 +54,5 @@
 	
 	$current_config = $c->config_data;
+                  
 	$ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
 	$boemailadmin	= CreateObject('emailadmin.bo');
@@ -41,4 +76,5 @@
 		'lang_messages_size'    => lang('Messages Size'),
 		'lang_institutional_accounts'=> lang('Institutional Accounts'),
+                'lang_assing_calendar' => lang('Assign default calendar for user'),
 		'lang_user_groups'		=> lang('User Groups'),
 		'lang_email_lists'		=> lang('Email Lists'),
Index: trunk/expressoAdmin1_2/templates/default/shared_accounts.tpl
===================================================================
--- trunk/expressoAdmin1_2/templates/default/shared_accounts.tpl	(revision 5133)
+++ trunk/expressoAdmin1_2/templates/default/shared_accounts.tpl	(revision 5804)
@@ -1,4 +1,26 @@
 <!-- BEGIN body -->
-	<link rel="stylesheet" type="text/css" href="./expressoAdmin1_2/templates/default/shared_accounts.css">
+	<link rel="stylesheet" type="text/css" href="./expressoAdmin1_2/templates/default/shared_accounts.css"/>
+        
+        
+        <link rel="Stylesheet" type="text/css" href="prototype/plugins/jquery/jquery-ui.css" />					
+    
+        <script type="text/javascript" src="prototype/plugins/jquery/jquery.min.js"></script>
+
+        <script type="text/javascript" src="prototype/plugins/jquery/jquery-ui.min.js"></script>
+        <script type="text/javascript" src="prototype/plugins/jquery/jquery-ui.custom.min.js"></script>
+        <script src="prototype/plugins/json2/json2.js" language="javascript"></script>
+        <script src="prototype/plugins/store/jquery.store.js" language="javascript"></script>
+
+        <script src="prototype/api/datalayer.js" language="javascript"></script>	
+
+        <script language="javascript">DataLayer.dispatchPath = "prototype/";</script>
+        <script type="text/javascript" src="prototype/plugins/datejs/date-pt-BR.js"></script>
+        <script type="text/javascript" src="prototype/plugins/datejs/sugarpak.js"></script>
+        <script type="text/javascript" src="prototype/plugins/datejs/parser.js"></script>
+
+        <script type="text/javascript" src="prototype/modules/calendar/js/timezone.js"></script>	
+
+        <script type="text/javascript" src="prototype/modules/calendar/js/calendar.codecs.js"></script>
+
 	<div style="display:none" id="{modal_id}">{shared_accounts_modal}</div>
 
Index: trunk/expressoAdmin1_2/templates/default/assing_calendar.css
===================================================================
--- trunk/expressoAdmin1_2/templates/default/assing_calendar.css	(revision 5804)
+++ trunk/expressoAdmin1_2/templates/default/assing_calendar.css	(revision 5804)
@@ -0,0 +1,29 @@
+div.assing-calendar fieldset.remove-border{border: 0px !important; padding: 0px;}
+div.assing-calendar dd{margin: 0 0 0 0 !important;}
+div.assing-calendar dl{margin: 5px !important;}
+
+div.assing-calendar fieldset.add-user-search{width: 234px;}
+div.assing-calendar input.search{width: 210px;}
+
+div.assing-calendar dt.calendar-list.calendar-name{width: 70px;}
+
+div.assing-calendar{overflow: hidden !important;}
+
+div.assing-calendar div.menu-container.footer-container{margin: 2px 0 -12px 0 !important;}
+div.assing-calendar ul.search-result-list,div.assing-calendar ul.user-list{margin-left: -54px !important; width: 252px !important;      }
+div.assing-calendar ul li{overflow: hidden !important;}
+div.assing-calendar li.not-user{margin: 0 0 0 20px !important;}
+div.assing-calendar fieldset.add-user-search{margin: 0 0 5px -10px !important;}
+
+div.assing-calendar dd.add-user {height: 290px !important;}
+
+div.assing-calendar dd.calendar-list li{height: 20px !important; margin: 0 0 0 10px !important;}
+
+div.assing-calendar dd.calendar-list li div{display: block !important;}
+
+div.assing-calendar dd.calendar{height: 24px;}
+
+div.assing-calendar li.calendar-selected{margin: -13px 0 0 -40px}
+div.assing-calendar li.calendar-selected a {margin: 0 0 -2px 15px;}
+
+div.assing-calendar dd.calendar-list li.user-list{width: 333px;}
Index: trunk/expressoAdmin1_2/templates/default/shared_accounts_modal.tpl
===================================================================
--- trunk/expressoAdmin1_2/templates/default/shared_accounts_modal.tpl	(revision 5133)
+++ trunk/expressoAdmin1_2/templates/default/shared_accounts_modal.tpl	(revision 5804)
@@ -47,5 +47,5 @@
 						
 		<td width="15%" valign="bottom" align="center" bgcolor="#DDDDDD" style="padding-bottom: 5px;">
-                    <table align="center">
+                    <table align="center" style="display: {aclCalendar}">
                         <tbody>
                                 <tr>
@@ -66,4 +66,23 @@
 				<tr >
                                     <td>{lang_restrict}</td><td><input type="checkbox" name="checkAttr" id ="em_input_restrictCalendar" onclick="return sharemailbox.setCalendaraclfromuser();" /><img title="{lang_this_user_will_can_read_restrict_events_at_the_mailbox_calendar}." src="./expressoAdmin1_2/templates/default/images/ajuda.jpg"></td>
+				</tr>
+                            </tbody>
+                    </table>
+                    <table align="center" style="display: {aclExpressoCalendar}">
+                        <tbody>
+                                <tr>
+                                    <td colspan="2" width="125"><b>{lang_calendar}:</b></td>
+                                </tr>
+                                <tr>
+                                    <td>{lang_read}</td><td><input type="checkbox" name="checkAttr" id ="em_input_readExpressoCalendar" onclick="return sharemailbox.setExpressoCalendaraclfromuser();" /><img title="{lang_this_user_will_can_read_events_at_the_mailbox_calendar}." src="./expressoAdmin1_2/templates/default/images/ajuda.jpg"></td>
+				</tr>
+				<tr >
+                                    <td>{lang_write}</td><td><input type="checkbox" name="checkAttr" id ="em_input_writeExpressoCalendar" onclick="return sharemailbox.setExpressoCalendaraclfromuser();" /><img title="{lang_this_user_will_can_create_events_at_the_mailbox_calendar}." src="./expressoAdmin1_2/templates/default/images/ajuda.jpg"></td>
+				</tr>
+				<tr>
+                                    <td>{lang_exclusion}</td><td><input type="checkbox" name="checkAttr" id ="em_input_deleteExpressoCalendar" onclick="return sharemailbox.setExpressoCalendaraclfromuser();" /><img title="{lang_this_user_will_can_delete_events_at_the_mailbox_calendar}." src="./expressoAdmin1_2/templates/default/images/ajuda.jpg"></td>
+                                </tr>
+                                <tr >
+                                    <td>{lang_freebusy}</td><td><input type="checkbox" name="checkAttr" id ="em_input_freebusyExpressoCalendar" onclick="return sharemailbox.setExpressoCalendaraclfromuser();" /><img title="{lang_this_user_will_can_read_restrict_events_at_the_mailbox_calendar}." src="./expressoAdmin1_2/templates/default/images/ajuda.jpg"></td>
 				</tr>
                             </tbody>
Index: trunk/expressoAdmin1_2/templates/default/participants_search_itemlist.ejs
===================================================================
--- trunk/expressoAdmin1_2/templates/default/participants_search_itemlist.ejs	(revision 5804)
+++ trunk/expressoAdmin1_2/templates/default/participants_search_itemlist.ejs	(revision 5804)
@@ -0,0 +1,9 @@
+<% for (var i=0; i < data.length; i++) { %>
+<li class="ui-widget-content" style="width:6000px;" title="<%=data[i]['name']%>">
+	<input type="checkbox" name="opcao" <%= (data[i].enabled) ?  '' : 'disabled="disabled"' %> />
+	<input type="hidden" value="<%=data[i]['id']%>" />
+	<label class="name"><%=data[i]['name']%></label>
+	<label class="mail hidden"><%=data[i]['mail']%></label>
+	<label class="id hidden"><%=data[i]['id']%></label>
+</li>
+<% } %>
Index: trunk/expressoAdmin1_2/templates/default/assing_calendar.ejs
===================================================================
--- trunk/expressoAdmin1_2/templates/default/assing_calendar.ejs	(revision 5804)
+++ trunk/expressoAdmin1_2/templates/default/assing_calendar.ejs	(revision 5804)
@@ -0,0 +1,69 @@
+<fieldset class="assing-calendar-configure remove-border">
+	<form method="POST" action="" class="form-addevent content">
+            <fieldset class="remove-border">
+		<dl class="block-user-list users-list">
+			
+                    <dt class="calendar-list calendar-name">Calendario</dt>
+                    <dd class="calendar">
+                        <input type="hidden" name="calendarId" value=""/>
+                        <ul class="calendarName"></ul>        
+                    </dd>
+			
+			<dt class="<%=data.calendar ? "user-list" : "calendar-list"%>"><%=data.calendar ? 'Compartilhar com' : 'Agendas Selecionadas'%></dt>
+			<dd class="<%=data.calendar ? "user-list" : "calendar-list"%>">
+				<ul class="user-list">
+				<% if (false) {
+					for (var i=0; i< data.event.user.length; i++) {%>
+						<li class="user"> 
+							<div style="overflow:hidden; width:100%; display:table;">
+								<input type="checkbox" value="">
+								<input type="hidden" name="user[]" value="">
+								<label class="name"></label>
+								<label class="mail"></label>
+							</div> 
+							<div class="assing-acl">
+									<a class="button edit user-options-button-edit new">Editar permissões</a>
+									<a class="button close new">Remover</a>
+							</div>
+						</li>	
+					<%} 
+				} else { %>
+					<li class="not-user"><%=data.calendar ? "Não compartilhado." : "Nenhuma agenda selecionada"%></li>
+				<% } %>
+				</ul>
+			</dd>	
+		</dl>
+
+		<%if(data.calendar){%>
+			<dl class="block-public-calendar">
+				<dt class="calendar-public">Agenda pública</dt>
+				<dd class="calendar-public">
+						<ul>
+							<input type="checkbox" name="isPublic"/><label>Pública</label>
+							<input type="checkbox" name="busy" class="free-busy hidden"/><label class="free-busy hidden">Livre/Ocupado</label>
+						</ul>
+				</dd>
+			</dl>
+		<%}%>
+		<dl class="block-add-user search ">
+			<dt class="add-user search">Pesquisar agendas</dt>
+			<dd class="add-user">
+				<fieldset class="block-add-user" title="Usuários">
+					<fieldset class="add-user-search search-field ui-corner-all">
+						<input class="search" type="text" />
+						<span class="ui-icon ui-icon-search"></span>
+						
+					</fieldset>
+					<ul class="search-result-list ui-corner-all">
+
+					</ul>
+				</fieldset>
+			</dd>
+		</dl>
+	</fieldset>
+	<div class="menu-container footer-container menu-addevent">
+		<a class="button cancel" href="#">Cancelar</a>
+	    <a class="button save" href="#">Salvar</a>
+    </div>
+	</form>
+</fieldset>
Index: trunk/expressoAdmin1_2/templates/default/index.tpl
===================================================================
--- trunk/expressoAdmin1_2/templates/default/index.tpl	(revision 5133)
+++ trunk/expressoAdmin1_2/templates/default/index.tpl	(revision 5804)
@@ -31,4 +31,12 @@
   		<td>
   			<a href="../index.php?menuaction=expressoAdmin1_2.uishared_accounts.index">{lang_shared_accounts}</a>
+  		</td>
+  	</tr>
+        <tr>
+		<td width="1%" align="center">
+			<img src='./templates/default/images/calendar.png'>
+  		</td>
+  		<td>
+                    <a href="#" onclick="assing_calendar_user()">{lang_assing_calendar}</a>
   		</td>
   	</tr>  
@@ -100,3 +108,4 @@
 	</tr>
 </table>
+                <input type="hidden" id="assingCalendar"/>
 <!-- END body -->
Index: trunk/expressoAdmin1_2/templates/default/user_shared_add_itemlist.ejs
===================================================================
--- trunk/expressoAdmin1_2/templates/default/user_shared_add_itemlist.ejs	(revision 5804)
+++ trunk/expressoAdmin1_2/templates/default/user_shared_add_itemlist.ejs	(revision 5804)
@@ -0,0 +1,34 @@
+<li class="user-list <%=data[0].isCurrent ? 'current' : 'new' %>"> 
+	<div style="overflow:hidden; width:100%; display:table;">
+		<%if(data[0].isCalendar){%>
+			<div class="user-acls-shared-calendar calendar">
+					<a class="button close new">Remover</a>
+			</div>
+			
+			<input type="checkbox" name="idPermission" value="<%=data[0].idPermission%>">
+			<input type="hidden" name="calendar[]" value="<%=data[0].id%>">
+			<input type="hidden" name="type[]" value="<%=data[0].type%>">
+			<label title="<%=data[0].description%>" class="name"><%= data[0].name ? data[0].name : '' %></label>
+		<%}else{%>
+			<div class="user-acls-shared-calendar">
+					<a class="button read user-options-button-view new">Ver</a>
+					<a class="button write user-options-button-edit-new new">Criar/Editar</a>
+					<a class="button remove user-options-button-remove new">Excluir</a>
+					<a class="button busy user-options-button-free-bussy new">Livre/Ocupado</a>
+					<a class="button shared user-options-button-shared new">Compartilhar</a>
+					<a class="button close new">Remover</a>
+			</div>
+		
+		<input type="checkbox" value="<%=data[0].id%>">
+		
+		<input type="hidden" name="user[]" value="<%=data[0].id%>">
+		<input type="hidden" name="attendeeAcl[]" value="<%=data[0].aclValue%>">
+		<%if(data[0].isCurrent){%>
+                    <input type="hidden" name="permission[]" value="<%=data[0].permission%>">
+                <%}%>
+		<label title="<%=data[0].name%>" class="name"><%= data[0].name ? data[0].name : '' %></label>
+		<label title="<%=data[0].mail%>" class="mail <%= data[0].name ? 'hidden' : ''%>"><%= data[0].mail ? data[0].mail : '' %></label>
+		<%}%>
+	</div>
+	
+</li>
