Index: trunk/prototype/services/iCal.php
===================================================================
--- trunk/prototype/services/iCal.php	(revision 7695)
+++ trunk/prototype/services/iCal.php	(revision 7702)
@@ -64,5 +64,6 @@
 			    if (( isset($v['repeat']) ) && ( isset($v['repeat']['frequency']) && $v['repeat']['frequency'] && $v['repeat']['frequency'] != 'none' )) 
 				    $vevent->setProperty('rrule', $this->formatIcalRepeat($v['repeat']));
-			    
+
+                $vevent->setProperty('dtstamp', array('timestamp' => ($v['dtstamp'] / 1000) ));
 
 			    if (isset($v['allDay']) && $v['allDay'] == 1)
@@ -200,4 +201,6 @@
                 $eTime->setTimezone($apTimezoneOBJ);
 
+                $vevent->setProperty('dtstamp', array('timestamp' => ($v['dtstamp'] / 1000) ));
+
                 if (isset($v['allDay']) && $v['allDay'] == 1) {
                     $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE"));
@@ -281,4 +284,6 @@
 			    $vevent->setProperty('location', $v['location']);
 			    $vevent->setProperty('tranp', (isset($v['tranparent']) && $v['tranparent'] == TRANSP_TRANSPARENT ) ? 'TRANSPARENT' : 'OPAQUE' );
+
+                $vevent->setProperty('dtstamp', array('timestamp' => ($v['dtstamp'] / 1000) ));
 
 			    $timezone = new DateTimeZone('UTC');
@@ -348,4 +353,6 @@
             $todo->setProperty('status', $this->_getStatusTodo($v['status']));
 
+            $vevent->setProperty('dtstamp', array('timestamp' => ($v['dtstamp'] / 1000) ));
+
             $timezone = new DateTimeZone('UTC');
             $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']);
@@ -543,4 +550,5 @@
 		case 'VEVENT':
 
+
 		    switch ($method) {
 			case 'PUBLISH':
@@ -610,5 +618,7 @@
                             //Verifica a importação de eventos em que não participo
                             if ($pID) {
+
                                 $interation['participant://' . $pID]['status'] = $params['status'];
+
                             }
                         }
@@ -848,6 +858,5 @@
 			    break;
 		    }
-	
-		    
+
 		    $return[] = $interation;
 		    break;
@@ -1562,5 +1571,5 @@
     	$objTimezone = new DateTimeZone($schedulable['timezone']);
 
-    	if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) {
+        if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' ) {
     	    $schedulable['allDay'] = 1;
     	    $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000';
@@ -1667,5 +1676,5 @@
     	    $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser))));
 
-    	    $user = null;
+            $user = null;
     	    if ($intUser && count($intUser) > 0) {
     		$participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0;
@@ -1689,32 +1698,40 @@
 
     	if ($property = $component->getProperty('organizer', FALSE, TRUE)) {
-    	    $participant = array();
+
     	    $mailUser = trim(str_replace('MAILTO:', '', $property['value']));
 
-    	    $participantID = mt_rand() . '2(Formatter)';
-
-    	    $participant['schedulable'] = $eventID;
-    	    $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED;
-    	    $participant['isOrganizer'] = '1';
-    	    $participant['acl'] = 'rowi';
+
+            if($participant = self::_getParticipantByMail($mailUser, $schedulable['participants'], true)){
+
+                $participantID = $participant['id'];
+
+            }else{
+
+                $participant = array();
+
+                $participantID = mt_rand() . '2(Formatter)';
+                $participant['schedulable'] = $eventID;
+                $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED;
+                $participant['isOrganizer'] = '1';
+                $participant['acl'] = 'rowi';
+            }
 
     	    /* Verifica se este usuario é um usuario interno do ldap */
     	    $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser))));
-
     	    $user = null;
     	    if ($intUser && count($intUser) > 0) {
-    		$participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0;
-    		$participant['user'] = $intUser[0]['id'];
+                $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0;
+                $participant['user'] = $intUser[0]['id'];
     	    } else {
-    		$participant['isExternal'] = 1;
-    		/* Gera um randon id para o contexto formater */
-    		$userID = mt_rand() . '4(Formatter)';
-
-    		$user['mail'] = $mailUser;
-    		$user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : '';
-    		$user['participants'] = array($participantID);
-    		$user['isExternal'] = '1';
-    		$participant['user'] = $userID;
-    		$interation['user://' . $userID] = $user;
+                $participant['isExternal'] = 1;
+                /* Gera um randon id para o contexto formater */
+                $userID = mt_rand() . '4(Formatter)';
+
+                $user['mail'] = $mailUser;
+                $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : '';
+                $user['participants'] = array($participantID);
+                $user['isExternal'] = '1';
+                $participant['user'] = $userID;
+                $interation['user://' . $userID] = $user;
     	    }
 
@@ -1828,5 +1845,5 @@
     	$interation['schedulable://' . $eventID] = $schedulable;
 
-    	return $interation;
+        return $interation;
     }
     
@@ -1956,10 +1973,18 @@
 	    $mailUser = trim(str_replace('MAILTO:', '', $property['value']));
 
-	    $participantID = mt_rand() . '2(Formatter)';
-
-	    $participant['schedulable'] = $todoID;
-	    $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED;
-	    $participant['isOrganizer'] = '1';
-	    $participant['acl'] = 'rowi';
+        if($participant = self::_getParticipantByMail($mailUser, $schedulable['participants'], true)){
+
+            $participantID = $participant['id'];
+
+        }else{
+
+            $participant = array();
+
+            $participantID = mt_rand() . '2(Formatter)';
+            $participant['schedulable'] = $todoID;
+            $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED;
+            $participant['isOrganizer'] = '1';
+            $participant['acl'] = 'rowi';
+        }
 
 	    /* Verifica se este usuario é um usuario interno do ldap */
