Index: /sandbox/webservice/api/rest/dispatch.php
===================================================================
--- /sandbox/webservice/api/rest/dispatch.php	(revision 6495)
+++ /sandbox/webservice/api/rest/dispatch.php	(revision 7463)
@@ -12,4 +12,5 @@
 
 // Load all resources
+require_once(__DIR__."/availableServers/AvailableServersResource.php");
 require_once(__DIR__."/core/ExpressoVersionResource.php");
 require_once(__DIR__."/core/LoginResource.php");
@@ -35,4 +36,5 @@
 
 foreach( $config as $uri => $classFile )
+{
 	foreach( $classFile as $className => $filePath )
 	{
@@ -45,6 +47,8 @@
 			'autoload' => $autoload
 	));
+}
 	
 try {
+
 	$resource = $request->loadResource();
 	$response = $resource->exec($request);
Index: /sandbox/webservice/api/rest/calendar/EventsResource.php
===================================================================
--- /sandbox/webservice/api/rest/calendar/EventsResource.php	(revision 6515)
+++ /sandbox/webservice/api/rest/calendar/EventsResource.php	(revision 7463)
@@ -6,12 +6,9 @@
  		parent::post($request);
 
-		if($this-> isLoggedIn())
+		if( $this->isLoggedIn() )
 		{
-			$user_id     = $this->getUserId();
-			$tz_offset   = $this->getTimezoneOffset();
 			$date_start  = $this->getParam('dateStart');
 			$date_end    = $this->getParam('dateEnd');
-			$split_event = $this->getParam('splitEvent');	// Boolean 1 or 0 - if you want to split the events that last for more than 1 day
-
+			
 			// check the dates parameters formats (ex: 31/12/2012 23:59:59, but the time is optional)
 			$regex_date  = '/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/([12][0-9]{3})( ([01][0-9]|2[0-3])(:[0-5][0-9]){2})?$/';
@@ -26,109 +23,94 @@
 			$start_arr      = explode(' ', $date_start);
 			$start_date_arr = explode('/', $start_arr[0]);
-			$start_time_arr = !empty($start_arr[1]) ? explode(':', $start_arr[1]) : array('00', '00', '00');
-			$datetime       = mktime($start_time_arr[0],$start_time_arr[1],$start_time_arr[2],$start_date_arr[1],$start_date_arr[0],$start_date_arr[2]) - ($tz_offset);
 
 			// get the end timestamp UNIX from the parameter
 			$end_arr        = explode(' ', $date_end);
 			$end_date_arr   = explode('/', $end_arr[0]);
-			$end_time_arr   = !empty($end_arr[1]) ? explode(':', $end_arr[1]) : array('23', '59', '59');
-			$edatetime      = mktime($end_time_arr[0],$end_time_arr[1],$end_time_arr[2],$end_date_arr[1],$end_date_arr[0],$end_date_arr[2]) - ($tz_offset);
-
-			$sql  =  'SELECT DISTINCT '
-					.'phpgw_cal.cal_id, '
-					.'phpgw_cal.datetime, '
-					.'phpgw_cal.edatetime, '
-					.'phpgw_cal.title, '
-					.'phpgw_cal.description, '
-					.'phpgw_cal.location '
-					.'FROM phpgw_cal_user, phpgw_cal '
-					.'WHERE (phpgw_cal_user.cal_id = phpgw_cal.cal_id) ';
-
-			// user clauses
-			$sql .= ' AND (phpgw_cal_user.cal_login = ' . $user_id . ' OR (phpgw_cal.owner = ' . $user_id . ')) ';
-
-			// date range clauses
-			$sql .= ' AND ( '
-						.'   ( (phpgw_cal.datetime >= '.$datetime.') AND (phpgw_cal.edatetime <= '.$edatetime.') ) '
-						.'OR ( (phpgw_cal.datetime <= '.$datetime.') AND (phpgw_cal.edatetime >= '.$edatetime.') ) '
-						.'OR ( (phpgw_cal.datetime >= '.$datetime.') AND (phpgw_cal.datetime <= '.$edatetime.') AND (phpgw_cal.edatetime >= '.$edatetime.') ) '
-						.'OR ( (phpgw_cal.datetime <= '.$datetime.') AND (phpgw_cal.edatetime >= '.$datetime.') AND (phpgw_cal.edatetime <= '.$edatetime.') ) '
-					.') ';
-
-			$sql .= ' ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC ';
-
-			if (!$this->getDb()->query($sql))
-				return false;
-
-			$events = array();
-			while($this->getDb()->next_record()) {
-				$row   = $this->getDb()->row();
-				$id    = $row['cal_id'];
-				$sdate = $row['datetime']  + ($tz_offset);
-				$edate = $row['edatetime'] + ($tz_offset);
-				$datetime  += ($tz_offset);
-				$edatetime += ($tz_offset);
-
-				$association_arr = array(
-							'eventID'          => 'cal_id',
-							'eventName'        => 'title',
-							'eventDescription' => 'description',
-							'eventLocation'    => 'location'
-						);
-
-				// if the event starts and ends in the same day OR the user does not want to split the event,
-				// return the event in only one register
-				if(date('d/m/Y', $sdate) == date('d/m/Y', $edate) || !$split_event){
-					foreach($association_arr AS $k => $v)
-						$events[$id][$k] = mb_convert_encoding($row[$v],"UTF8", "ISO_8859-1");
-
-					$events[$id]['eventStartDate'] = date('d/m/Y H:i', $sdate);
-					$events[$id]['eventEndDate']   = date('d/m/Y H:i', $edate);
-					$events[$id]['eventAllDay']    = '0';
+			
+			$return = array();
+			
+			for( $j = (int)$start_date_arr[2]; $j <= (int)$end_date_arr[2]; $j++ )
+			{
+				for( $i = (int)$start_date_arr[1]; $i <= (int)$end_date_arr[1]; $i++ )
+				{
+					if( (int)$i < 10 )
+						$result = $this->getEvents("0".$i,$j);
+					else
+						$result = $this->getEvents($i,$j);
+					
+					if( count($result) > 0 )
+					{
+						$return[] = $result;
+					}
 				}
-				// if the event lasts for more than one day AND the user wants it splitted day by day,
-				// return the event splitted into as many parts of the array as the days remaining
-				else{
-					// walk through the event date range, adding one register for each day
-					$step_date     = $sdate;
-					$step_date_ymd = date('Ymd', $step_date);
-					while($step_date_ymd <= date('Ymd', $edate) && $step_date_ymd <= date('Ymd', $edatetime)){
-						if($step_date_ymd >= date('Ymd', $datetime) && $step_date_ymd <= date('Ymd', $edatetime)){
-							foreach($association_arr AS $k => $v)
-								$events_tmp[$k] = $row[$v];
-
-							// the first day of the event
-							if($step_date == $sdate){
-								$events_tmp['eventStartDate'] = date('d/m/Y H:i',   $sdate);
-								$events_tmp['eventEndDate']   = date('d/m/Y 23:59', $sdate);
-								$events_tmp['eventAllDay']    = '0';
-							}
-							// the last day of the event
-							elseif($step_date_ymd == date('Ymd', $edate)){
-								$events_tmp['eventStartDate'] = date('d/m/Y 00:00', $edate);
-								$events_tmp['eventEndDate']   = date('d/m/Y H:i',   $edate);
-								$events_tmp['eventAllDay']    = '0';
-							}
-							// the other days
-							else{
-								$events_tmp['eventStartDate'] = date('d/m/Y 00:00', $step_date);
-								$events_tmp['eventEndDate']   = date('d/m/Y 23:59', $step_date);
-								$events_tmp['eventAllDay']    = '1';
-							}
-							$events[$id.$step_date_ymd] = $events_tmp;
-						}
-						$step_date     = strtotime("+1 day", $step_date);
-						$step_date_ymd = date('Ymd', $step_date);
-					}
- 				}
 			}
 
-			$result = array ('events' => array_values($events));
+			if( count($return) > 0 )
+			{
+				$i = 0;
+				
+				for( $j = 0 ; $j < count( $return); $j++)
+				{
+					foreach( $return[$j] as $key => $value )
+					{
+						$events[$i]['eventID']			= "".$value[0]['id'];
+						$events[$i]['eventDate']		= "".$key;
+						$events[$i]['eventName']		= mb_convert_encoding("".$value[0]['title'],"UTF8","ISO_8859-1");
+						$events[$i]['eventDescription']	= mb_convert_encoding("".$value[0]['description'], "UTF8","ISO_8859-1");
+						$events[$i]['eventLocation']	= mb_convert_encoding("".$value[0]['location'], "UTF8","ISO_8859-1");
+						$events[$i]['eventParticipants']= $value[0]['participants'];
+						
+						$starttime 	= $this->makeTime($value[0]['start']);
+						$endtime 	= $this->makeTime($value[0]['end']);
+						$actualdate = mktime(0,0,0,substr($key,4,2),substr($key, 6 ),substr($key,0,4));
+						$rawdate_offset = $actualdate - $this->getTimezoneOffset();
+						$nextday = mktime(0,0,0,substr($key,4,2),substr($key, 6 )+1,substr($key,0,4)) - $this->getTimezoneOffset();
+						
+						if( $starttime <= $rawdate_offset && $endtime >= $nextday - 60 )
+						{
+							$events[$i]['eventStartDate']	= substr($key, 6 )."/".substr($key,4,2)."/".substr($key,0,4)." 00:00";
+							$events[$i]['eventEndDate']		= substr($key, 6 )."/".substr($key,4,2)."/".substr($key,0,4)." 23:59";
+							$events[$i]['eventAllDay']		= "1";
+						}
+						else
+						{
+							if( $value[0]['start']['mday'] === $value[0]['end']['mday'] )
+							{
+								$hour_start	= (((int)$value[0]['start']['hour'] < 10 ) ? "0".$value[0]['start']['hour'] : $value[0]['start']['hour']).":".(((int)$value[0]['start']['min'] < 10 ) ? "0".$value[0]['start']['min'] : $value[0]['start']['min'] );
+								$hour_end	= (((int)$value[0]['end']['hour'] < 10 ) ? "0".$value[0]['end']['hour'] : $value[0]['end']['hour']).":".(((int)$value[0]['end']['min'] < 10 ) ? "0".$value[0]['end']['min'] : $value[0]['end']['min'] );
+							}
+							else
+							{
+								if( $events[$i-1] && $events[$i-1]['eventAllDay'] == "1" )
+								{
+									$hour_start	= "00:00";
+									$hour_end	= (((int)$value[0]['end']['hour'] < 10 ) ? "0".$value[0]['end']['hour'] : $value[0]['end']['hour']).":".(((int)$value[0]['end']['min'] < 10 ) ? "0".$value[0]['end']['min'] : $value[0]['end']['min'] );
+								}
+								else
+								{
+									$hour_start	= (((int)$value[0]['start']['hour'] < 10 ) ? "0".$value[0]['start']['hour'] : $value[0]['start']['hour']).":".(((int)$value[0]['start']['min'] < 10 ) ? "0".$value[0]['start']['min'] : $value[0]['start']['min'] );
+									$hour_end	= "23:59";
+								}
+							}
+								
+							$events[$i]['eventStartDate']	= substr($key, 6 )."/".substr($key,4,2)."/".substr($key,0,4)." ".$hour_start;
+							$events[$i]['eventEndDate']		= substr($key, 6 )."/".substr($key,4,2)."/".substr($key,0,4)." ".$hour_end;
+							$events[$i]['eventAllDay']		= "0";
+						}
+						
+						$events[$i++]['eventExParticipants'] = $value[0]['ex_participants'];
+					}
+				}
 
-			$this->setResult($result);
+				$this->setResult(array('events' => $events));
+			}
+			else
+			{
+				$this->setResult(array('events' => array()));
+			}
 		}
+
 		//to Send Response (JSON RPC format)
 		return $this->getResponse();
 	}
-
 }
Index: /sandbox/webservice/api/rest/availableServers/AvailableServersResource.php
===================================================================
--- /sandbox/webservice/api/rest/availableServers/AvailableServersResource.php	(revision 7463)
+++ /sandbox/webservice/api/rest/availableServers/AvailableServersResource.php	(revision 7463)
@@ -0,0 +1,65 @@
+<?php
+/**
+ * @uri /AvailableServers
+ */
+class AvailableServersResource extends Resource {
+
+	function post($request){
+		return $this->get($request);
+	}
+	
+	function get($request){
+
+		$error = null;		
+		parse_str($request->data, &$data);
+				
+		if( file_exists(__DIR__ . '/../../config/REST.ini') )
+		{
+			$restServers = parse_ini_file( __DIR__ . '/../../config/REST.ini', true );
+			
+			foreach( $restServers as $key => $value)
+			{
+				if(substr( $key, 0, 11 ) == "ServersRest")
+				{
+					$servers[] = $value;
+				}
+			}
+		}
+		else{
+			$error = array("code" => "001", "message" => "The servers list was not found.");
+		}
+
+		function cmp($a, $b)
+		{
+			return strcmp(strtolower($a["serverName"]), strtolower($b["serverName"]));
+		}
+	
+		if(count($servers) > 0){
+			usort($servers, "cmp");
+		}
+
+		$response = new Response($request);
+		$response->code = Response::OK;
+		$response->addHeader('content-type', 'application/json');
+				
+		$body = array();
+		
+		if($data['id']){
+			$body['id'] = $data['id']; 
+		}
+		if($servers){
+			$body['result'] = array( "servers" => $servers);
+		}
+		elseif($error){
+			$body['error'] = $error;
+		}
+		else{
+			$body['error'] = "OBJETO SEM RESULT E SEM ERRO REPORTADO.";
+		}
+						
+		$response->body = json_encode($body);
+			
+		return $response;
+	}		
+
+}
Index: /sandbox/webservice/api/rest/catalog/ContactsResource.php
===================================================================
--- /sandbox/webservice/api/rest/catalog/ContactsResource.php	(revision 6191)
+++ /sandbox/webservice/api/rest/catalog/ContactsResource.php	(revision 7463)
@@ -61,4 +61,5 @@
 				}
 			}
+			
 			$result = array ('contacts' => array_values($contacts));
 			$this->setResult($result);
