Index: /trunk/prototype/services/iCal.php
===================================================================
--- /trunk/prototype/services/iCal.php	(revision 6248)
+++ /trunk/prototype/services/iCal.php	(revision 6295)
@@ -248,7 +248,11 @@
 				    $calendarToSchedulable['schedulable'] = $schedulable['id'];
 				    $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable;
-
+    
 				    if (isset($params['status'])) {
-					$pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']);
+					if(isset($params['fromPermission'])){					    
+					    $signaturesOfOwner = Controller::Read(array('concept' => 'calendarSignature'), false, array('filter' => array('AND', array('=', 'calendar', $params['fromPermission']) , array('=','isOwner','1')), 'deepness' => 2 ));					    
+					    $pID = self::_getParticipantByMail($signaturesOfOwner[0]['user']['mail'], $schedulable['participants']);
+					}else
+					    $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']);
 					$interation['participant://' . $pID]['status'] = $params['status'];
 				    }
@@ -265,5 +269,9 @@
 
 				    if (isset($params['status'])) {
-					$pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']);
+					if(isset($params['fromPermission'])){					    
+					    $signaturesOfOwner = Controller::Read(array('concept' => 'calendarSignature'), false, array('filter' => array('AND', array('=', 'calendar', $params['fromPermission']) , array('=','isOwner','1')), 'deepness' => 2 ));
+					    $pID = self::_getParticipantByMail($signaturesOfOwner[0]['user']['mail'], $schedulable['participants']);
+					}else
+					    $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']);
 					//Verifica a importação de eventos em que não participo
 					if ($pID) {
@@ -566,6 +574,7 @@
 					    $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE;
 				    }
-				if (!$isParticipant)
-				    $interation = ICAL_ACTION_ORGANIZER_NONE;
+				if (!$isParticipant){
+				      $interation = self::_checkParticipantByPermissions($schedulable);
+				    }
 			    }else
 				$interation = ICAL_ACTION_IMPORT;
@@ -651,4 +660,27 @@
     }
 
+    private static function _checkParticipantByPermissions($schedulable) {
+
+	$calendarIds = Controller::find(array('concept' => 'calendarSignature'), array('calendar'), array('filter' => array('AND', array('=','isOwner','0'), array('=', 'user', Config::me("uidNumber")))));
+
+	if($calendarIds && isset($calendarIds[0])){
+	    $ids = array();
+	    foreach($calendarIds as $value)
+		    array_push($ids, $value['calendar']);
+
+	    $signaturesOfOwners = Controller::find(array('concept' => 'calendarSignature'), false, array('filter' => array('AND', array('IN', 'calendar', $ids) , array('=','isOwner','1')), 'deepness' => 2 ));
+	    
+	    foreach($signaturesOfOwners as $value){
+		if(self::_getParticipantByMail($value['user']['mail'], $schedulable['participants'])){
+		    $eventoFromCalendar = Controller::read( array( 'concept' => 'calendarToSchedulable') , false, array('filter' => array('AND', array('=','schedulable',$schedulable['id']), array('=','calendar', $value['calendar']['id']))));
+
+		    return  ($eventoFromCalendar && isset($eventoFromCalendar[0])) ? ICAL_ACTION_NONE_FROM_PERMISSION : array('action' => ICAL_ACTION_IMPORT_FROM_PERMISSION, 'calendar' => $value['calendar']['id'] );
+		}
+	    }    
+	}
+	return ICAL_ACTION_ORGANIZER_NONE;
+    }
+    
+    
     private static function _getParticipantByMail($mail, &$participants) {
 	if ($participants && $participants != '')
Index: /trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 6286)
+++ /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 6295)
@@ -819,6 +819,6 @@
 	//Veirifica pois o usuário pode ter varias assinaturas mas não ser dona de nenhuma
 	if (count($result) > 0) {
-	    foreach ($result as $key) {
-		if ($key['isOwner'] != 0)
+	    foreach ($result as $value) {
+		if (isset($value['isOwner']) && $value['isOwner'] != 0)
 		    $isValidSignature = true;
 	    }
Index: /trunk/prototype/modules/calendar/constants.php
===================================================================
--- /trunk/prototype/modules/calendar/constants.php	(revision 5879)
+++ /trunk/prototype/modules/calendar/constants.php	(revision 6295)
@@ -31,4 +31,6 @@
 define('ICAL_ACTION_ORGANIZER_UPDATE', 8);
 define('ICAL_ACTION_ORGANIZER_NONE', 9);
+define('ICAL_ACTION_IMPORT_FROM_PERMISSION', 10);
+define('ICAL_ACTION_NONE_FROM_PERMISSION', 11);
 
 define('ATTENDEE_ACL_ORGANIZATION', 'o');
Index: /trunk/prototype/modules/calendar/js/calendar.codecs.js
===================================================================
--- /trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 6286)
+++ /trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 6295)
@@ -656,5 +656,5 @@
 			    })
 			};
-			me.id = attend.id;
+			me = attend;
 			return(null);
 		    };
@@ -685,16 +685,9 @@
 		alarms: !!participantInfo.user ? participantInfo.user.alarms : [],
 		status: !!participantInfo.user ? participantInfo.user.status : 1,
-		acl: isShared ? constantAcl(Calendar.signatureOf[objEvent.calendar].permission.aclValues) : (!!participantInfo.user ? constantAcl(participantInfo.user.acl) : ( ( !objEvent.id || isAttendee ) ? constantAcl( 'rowi' ) : constantAcl( 'r' ))),
+		acl: constantAcl(me.acl || 'roiw'),
 		isShared: isShared,
 		isAttendee: (isAttendee ? true : (objEvent.id && isShared ? false : true)),
-		me: ((!objEvent.id) || ( objEvent.id && isAttendee)) ? (!!participantInfo.user ? DataLayer.merge(participantInfo.user, me) : DataLayer.merge(isShared ? participantInfo.organizer :  me, {
-		    acl:  !isShared ? 'rowi' : Calendar.signatureOf[objEvent.calendar].permission.aclValues, 
-		    delegatedFrom: 0, 
-		    receiveNotification: 1
-		})) : (DataLayer.merge( ( participantInfo.organizer || me), {
-		    acl: 'r'
-		} ) ),
+		me: me,
 		delegatedFrom: delegatedFrom,
-				
 		statusParticipants: statusParticipants
 	    };
Index: /trunk/prototype/modules/calendar/templates/attendee_add.ejs
===================================================================
--- /trunk/prototype/modules/calendar/templates/attendee_add.ejs	(revision 6066)
+++ /trunk/prototype/modules/calendar/templates/attendee_add.ejs	(revision 6295)
@@ -39,5 +39,5 @@
 		<dd class="attendee-list">
 			<ul class="attendee-list">
-				<li class="organizer <%= (data.event.acl.organization || !data.event.isAttendee) ? "hidden" : "" %>"> 
+				<li class="organizer <%= (data.event.acl.organization) ? "hidden" : "" %>"> 
 					<div style="overflow:hidden; width:100%; display:table;">
 						<span class="space-status ui-icon <%=iconStatus[data.event.organizer.status]%>" title="<%=legendStatus[data.event.organizer.status]%>"></span>
Index: /trunk/expressoMail1_2/inc/class.db_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.db_functions.inc.php	(revision 6105)
+++ /trunk/expressoMail1_2/inc/class.db_functions.inc.php	(revision 6295)
@@ -434,6 +434,7 @@
 				$_REQUEST['params']['calendar'] = $params['selected'];
 				$_REQUEST['readable'] = $params['readable'] ? true : false;
-                $_REQUEST['analize'] = isset($params['analize']) ? true : false;
+				$_REQUEST['analize'] = isset($params['analize']) ? true : false;
 				$_REQUEST['params']['status'] = $params['status'];
+				$_REQUEST['params']['fromPermission'] = $params['fromPermission'];
 				$_REQUEST['params']['owner'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];
 				if(isset($params['acceptedSuggestion'])){
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 6288)
+++ /trunk/expressoMail1_2/js/main.js	(revision 6295)
@@ -3617,42 +3617,51 @@
 
 					var createDialog = function(typeImport, propaget){
-							
+					    
+						if(typeof(typeImport) == "object"){
+						    var calendarPermission = typeImport.calendar;
+						    typeImport = typeImport.action;
+						}
+						
 						switch(parseInt(typeImport)){
 						case 1:
 						case 7:
-							$("#select-agenda").html('');
-								for(var id in Calendar.calendars){
-										var doc = document .createElement("OPTION");
-										doc.value = Calendar.calendars[id].id;
-										doc.innerHTML = Calendar.calendars[id].name;
-										$("#select-agenda").append(doc);
-									  
-								};
-								$("#import-dialog" ).dialog({
-									buttons: {
-										Cancel: function() {
-												$( this ).dialog( "close" );
-										},
-										"Importar" : function(){
-
-											 $.ajax({
-													 url: "controller.php?action="+import_url+'&from_ajax=true&selected='+$("#select-agenda option:selected").val()+'&status='+$("#select-status option:selected").val(),
-													 success: function(msg){
-
-															var alt = ( (msg = connector.unserialize(msg)) == "ok") ? "Importado com sucesso para " : "Ocorreu um erro ao importar o evento para a agenda ";
-															alert( alt + $("#select-agenda option:selected").text() );
-													}
-												});
-										
-											$( this ).dialog( "close" );
-										}
+						case 10:
+						    $("#select-agenda").html('');
+
+						    var shared = '', options = '';
+
+						    if(typeImport == 10){
+							shared = '&fromPermission='+calendarPermission;
+							
+							options += '<option value="'+calendarPermission+'">'+Calendar.signatureOf[calendarPermission].calendar.name+'</option>'
+						    }else{
+							for(var id in Calendar.calendars)
+							   options += '<option value="'+Calendar.calendars[id].id+'">'+Calendar.calendars[id].name+'</option>';
+
+							$("#select-agenda").append(options);
+						    }
+						    $("#import-dialog" ).dialog({
+							buttons: {
+							    Cancel: function() {
+								$( this ).dialog( "close" );
+							    },
+							    "Importar" : function(){
+								    $.ajax({
+									url: "controller.php?action="+import_url+'&from_ajax=true&selected='+$("#select-agenda option:selected").val()+'&status='+$("#select-status option:selected").val()+shared,
+									success: function(msg){
+									    var alt = ( (msg = connector.unserialize(msg)) == "ok") ? "Importado com sucesso para " : "Ocorreu um erro ao importar o evento para a agenda ";
+									    alert( alt + $("#select-agenda option:selected").text() );
 									}
-								 });
-                                                                 
-                                                                 if(typeImport == 7){
-                                                                     $("#import-dialog").find('#select-status option[value=1]').attr('selected','selected').trigger('change');
-                                                                     $("#import-dialog").find('#select-status').attr('disabled','disabled');
-                                                                 }
-							break;
+								    });
+								    $( this ).dialog( "close" );
+							    }
+							}
+							});
+
+							if(typeImport == 7){
+							    $("#import-dialog").find('#select-status option[value=1]').attr('selected','selected').trigger('change');
+							    $("#import-dialog").find('#select-status').attr('disabled','disabled');
+							}
+						    break;
 						case 3:
 							$.ajax({
@@ -3686,4 +3695,8 @@
 						case 9:
 							alert('Seu evento não possui alterações!');
+							return;
+							break;
+						case 11:
+							alert('Este evento já fora importando por algum dos particpantes e já se encontra disponível em sua agenda compartilhada!');
 							return;
 							break;
