Index: /trunk/expressoCalendar/inc/class.ui_migration.inc.php
===================================================================
--- /trunk/expressoCalendar/inc/class.ui_migration.inc.php	(revision 6210)
+++ /trunk/expressoCalendar/inc/class.ui_migration.inc.php	(revision 6393)
@@ -20,10 +20,10 @@
 		function __construct()
 		{
-                    include_once dirname(__FILE__ ).'/../../header.inc.php';
-		
-                    if (is_array($_SESSION['phpgw_info']['expresso']['server']))
-                        $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server'];
-                    else
-                    $_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server'];
+			include_once dirname(__FILE__ ).'/../../header.inc.php';
+
+			if (is_array($_SESSION['phpgw_info']['expresso']['server']))
+				$GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server'];
+			else
+			$_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server'];
 					
 			$local = $_SESSION['phpgw_info']['expresso']['server']['db_host'];
@@ -93,29 +93,108 @@
 			}
 		}
+
+                function decode_days_repeat($hex){
+                    $bin = str_split( decbin($hex) );
+
+                    $decoded = array('SU','MO','TU','WE','TH','FR','SA');
+                    $returns = array();
+                    
+                    foreach($bin as $key => $value)
+                        if((int)$value == 1)
+                            $returns[] = $decoded[$key];
+
+                    return implode(',', $returns);
+                }
+                
+		//Repetição de um evento
+		function as_repeat($cal_id, $calendar_object ,$startTime){
+			$sql_select_repeat = "select * from phpgw_cal_repeats where cal_id = ".$cal_id;			
+			$result = pg_query($this->current_base ,$sql_select_repeat);
+				
+			while($repeat = pg_fetch_array($result)){
+				$sql_insert = "insert into calendar_repeat (frequency, dtstart, object_id, until, byday, bymonthday, byyearday, interval) values ( ";
+				$type = '';
+                                $weeklyDays = '';
+                                $byMonthDay = '';
+                                $byYearDay = '';
+				switch($repeat['recur_type']){
+					case 1:
+						$type = 'daily';
+					break;
+					case 2:
+						$type = 'weekly';
+                                                $weeklyDays = $this->decode_days_repeat($repeat['recur_data']);
+					break;
+					case 3:
+					case 4:
+                                                $type = 'monthly';
+                                                $day = new DateTime('@' . (int)$startTime, new DateTimeZone('UTC'));
+                                                $byMonthDay = date_format($day, 'j');        
+					break;
+					case 5:
+						$type = 'yearly';
+                                                $day = new DateTime('@' . (int)$startTime, new DateTimeZone('UTC'));
+                                                $byYearDay = (1 + date_format($day, 'z'));    
+					break;
+				}
+				
+				$sql_insert .= "'".$type."', ";
+				$sql_insert .= "'".$startTime."000', ";
+				$sql_insert .= "'".$calendar_object."', ";  
+				
+                                $sql_insert .= ($repeat['recur_enddate']) == 0 ? ("'', ") : ("'".$repeat['recur_enddate']."000',");
+				$sql_insert .= "'".$weeklyDays."', ";
+                                $sql_insert .= "'".$byMonthDay."', ";
+                                $sql_insert .= "'".$byYearDay."', ";
+                                $sql_insert .= "'".$repeat['recur_interval']."') RETURNING id";
+					
+				$result = pg_query($this->new_base ,$sql_insert);
+				$repeatEvent = pg_fetch_assoc($result);
+
+				if($repeat['recur_exception'] != ''){
+
+					$ocurrences = explode(',', $repeat['recur_exception']);
+
+					foreach($ocurrences as $value){
+						$sql_insert_excepetions = 'insert into calendar_repeat_ocurrence (ocurrence, exception, repeat_id) values ( ';
+						$sql_insert_excepetions .= "'".$value."', ";
+						$sql_insert_excepetions .= "'1', ";
+						$sql_insert_excepetions .= "'".$repeatEvent['id']."' )";
+						pg_query($this->new_base ,$sql_insert_excepetions);
+					}
+				}
+
+				
+				
+			}
+		}
+		
 		//Alarmes de um evento
-		function as_alarm($cal_id, $date_ini, $date_end){
+		function as_alarm($cal_id, $event_id, $date_ini){
 			$sql_select_evento = "select * from phpgw_async where id like '%".$cal_id."%'";			
 			$result = pg_query($this->current_base ,$sql_select_evento);
 				
-			while($evento = pg_fetch_array($result)){			
-				if(!$result['account_id'])
-					continue;
-				$sql_insert = "insert into calendar_alarm (action_id, time, range_end, range_start, unit, participant_id, object_id,sent) values ( ";
+			while($evento = pg_fetch_array($result)){
+                                
+                                $data = unserialize($evento['data']);
+                            
+                                $attendee = pg_query($this->new_base , "select id from calendar_participant where (user_info_id = '".$data['owner']."' AND object_id = '".$event_id."' )");
+                                $attendee = pg_fetch_array($attendee);
+
+                                $offset = ($date_ini - $evento['next']);
+
+				$sql_insert = "insert into calendar_alarm (action_id, unit, alarm_offset, time, participant_id, object_id, sent) values ( ";
 				//action_id
 				$sql_insert .= "1, ";
-				
+				//unit
+				$sql_insert .= "'m', ";
+                                //offset
+				$sql_insert .= "'".$offset."', ";
 				//time
-				$time =  preg_split('/:/', $result['times']);
-				$sql_insert .= substr($time, -1).", ";
-				//range_end
-				$sql_insert .= "'".$date_end."', ";
-				//range_start
-				$sql_insert .= "'".$date_ini."', ";
-				//arrumar unit
-				$sql_insert .= "1, ";
-				//participant_id
-				$sql_insert .= $result['account_id'].", ";
+				$sql_insert .= "'".($offset / 60)."', ";
+                                //participant
+				$sql_insert .= $attendee['id'] .", ";
 				//object_id
-				$sql_insert .= $cal_id.", ";
+				$sql_insert .= $event_id.", ";
 				//sent
 				if($date_ini > time())
@@ -188,5 +267,5 @@
 			//Todo
 			//Implementar Repetição
-						
+
 			$result = pg_query($this->current_base, $sql);
 			while($evento = pg_fetch_array($result)){
@@ -272,6 +351,9 @@
 					$this->as_user_external($evento['cal_id'] ,$calendar['id'], $evento['owner'], $evento['ex_participants']);	
 				
-				//Por equanto desativado
-				//$this->as_alarm($evento['cal_id'], $evento['datetime'],$evento['edatetime']) ;	
+				//Alarmes de eventos
+				$this->as_alarm($evento['cal_id'], $calendar['id'], $evento['datetime']) ;
+                                
+                                //Repetição de um evento
+                                $this->as_repeat($evento['cal_id'] ,$calendar['id'], $evento['datetime']);
 				
 			}
Index: /trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 6369)
+++ /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 6393)
@@ -261,7 +261,9 @@
 	    Controller::begin(array('service' => 'PostgreSQL'));
 
-	    foreach ($result as $id => $res)
-		Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_repeat_occurrence(repeat_id,occurrence)VALUES('" . $id . "','" . implode("'),('" . $id . "', '", $res) . "')");
-
+	    foreach ($result as $id => $res){
+		
+                $ocurrences = array_unique($res);
+                Controller::service('PostgreSQL')->execResultSql("INSERT INTO calendar_repeat_occurrence(repeat_id,occurrence)VALUES('" . $id . "','" . implode("'),('" . $id . "', '", $ocurrences) . "')");
+            }
 	    $data = array();
 
Index: /trunk/prototype/modules/calendar/js/helpers.js
===================================================================
--- /trunk/prototype/modules/calendar/js/helpers.js	(revision 6371)
+++ /trunk/prototype/modules/calendar/js/helpers.js	(revision 6393)
@@ -1411,5 +1411,5 @@
 
 	if(!!data.result && data.result != "[]"){
-	    var newAttach = jQuery.parseJSON(data.result);
+	    var newAttach = (attch = jQuery.parseJSON(data.result)) ? attch : jQuery.parseJSON(data.result[0].activeElement.childNodes[0].data);
 	    $('.attachment-list').append('<input tyepe="hidden" name="attachment[]" value="'+newAttach['attachment'][0][0].id+'"/>');
 	    currentUpload.removeClass('on-complete').parents('p')
@@ -1421,5 +1421,6 @@
 });
 $('.attachments-list .button').button();
-			
+
+if(!!window.FormData)			
 $('#fileupload').bind('fileuploadstart', function () {
     var widget = $(this),
Index: /trunk/prototype/modules/calendar/templates/alarms_add_itemlist.ejs
===================================================================
--- /trunk/prototype/modules/calendar/templates/alarms_add_itemlist.ejs	(revision 5652)
+++ /trunk/prototype/modules/calendar/templates/alarms_add_itemlist.ejs	(revision 6393)
@@ -6,5 +6,5 @@
 				<option value="alert" <%= data.alarm.defaultAlarms[i].type=='alert' ? 'selected="selected"':'' %>>Alerta</option>
 				<option value="mail" <%= data.alarm.defaultAlarms[i].type=='mail' ? 'selected="selected"':'' %>>E-mail</option>
-				<option value="sms" <%= data.alarm.defaultAlarms[i].type=='sms' ? 'selected="selected"':'' %>>SMS</option>
+				<!--<option value="sms" <%= data.alarm.defaultAlarms[i].type=='sms' ? 'selected="selected"':'' %>>SMS</option>-->
 			</select>
 			<input type="text" name="alarmTime[]" class="number input-small" value="<%= data.alarm.defaultAlarms[i].time %>"/>
Index: /trunk/prototype/modules/calendar/templates/event_add.ejs
===================================================================
--- /trunk/prototype/modules/calendar/templates/event_add.ejs	(revision 6369)
+++ /trunk/prototype/modules/calendar/templates/event_add.ejs	(revision 6393)
@@ -9,5 +9,5 @@
 				<input type="hidden" class="id-event" name="idEvent" value="<%= data.event.id %>"/>
 			<% } %>
-                        <% if( data.event.calendar ){ %>
+                        <% if( data.event.id && data.event.calendar ){ %>
 				<input type="hidden" class="last-calendar" name="lastCalendar" value="<%= data.event.calendar %>"/>
 			<% } %>
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 6384)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 6393)
@@ -3001,5 +3001,5 @@
 					attachments: [],
 					isAttendee: true,
-                                        attendee: '',//TODOOOOOO,
+					attendee: '',//TODOOOOOO,
 					calendar: User.preferences.defaultCalendar ? User.preferences.defaultCalendar : Calendar.calendars[0],
 					calendars: Calendar.calendars,
@@ -3011,5 +3011,5 @@
 					startHour: startEvent.toString(User.preferences.hourFormat),
 					endHour: endEvent(startEvent).toString(User.preferences.hourFormat),
-					timezone: User.preferences.defaultCalendar ? Calendar.calendarOf[User.preferences.defaultCalendar].timezone : User.preferences.timezone,
+					timezone: User.preferences.defaultCalendar ? Calendar.signatureOf[User.preferences.defaultCalendar].calendar.timezone : User.preferences.timezone,
 					summary : $("#subject_"+ID).text(),
 					description : $("#body_" + ID).text(),
