Index: sandbox/webservice/api/adapters/CalendarAdapter.php
===================================================================
--- sandbox/webservice/api/adapters/CalendarAdapter.php	(revision 6423)
+++ sandbox/webservice/api/adapters/CalendarAdapter.php	(revision 6423)
@@ -0,0 +1,19 @@
+<?php
+
+class CalendarAdapter extends ExpressoAdapter {
+	public function __construct($id){
+		parent::__construct($id);
+	}
+
+	protected function getUserId(){
+		return $GLOBALS['phpgw_info']['user']['account_id'];
+	}
+
+	protected function getDb(){
+		return $GLOBALS['phpgw']->db;
+	}
+
+	protected function getTimezoneOffset(){
+		return $GLOBALS['phpgw']->datetime->tz_offset;
+	}
+}
Index: sandbox/webservice/api/config/Tonic.srv
===================================================================
--- sandbox/webservice/api/config/Tonic.srv	(revision 6338)
+++ sandbox/webservice/api/config/Tonic.srv	(revision 6423)
@@ -40,2 +40,5 @@
 [/Catalog/ContactPicture]
 ContactPictureResource = /catalog/ContactPictureResource.php
+
+[/Calendar/Events]
+EventsResource = /calendar/EventsResource.php
Index: sandbox/webservice/api/config/Errors.tsv
===================================================================
--- sandbox/webservice/api/config/Errors.tsv	(revision 6166)
+++ sandbox/webservice/api/config/Errors.tsv	(revision 6423)
@@ -35,2 +35,4 @@
 1012		MAIL_FOLDER_NOT_DELETED			The folder could not be deleted.
 1013		MAIL_FOLDER_LIMIT_REACHED		Folder limit has been reached.
+1014		CALENDAR_INVALID_START_DATE		Invalid start date.
+1015		CALENDAR_INVALID_END_DATE		Invalid end date.
Index: sandbox/webservice/api/rest/dispatch.php
===================================================================
--- sandbox/webservice/api/rest/dispatch.php	(revision 6338)
+++ sandbox/webservice/api/rest/dispatch.php	(revision 6423)
@@ -9,4 +9,5 @@
 require_once(__DIR__."/../adapters/MailAdapter.php");
 require_once(__DIR__."/../adapters/CatalogAdapter.php");
+require_once(__DIR__."/../adapters/CalendarAdapter.php");
 
 // Load all resources
@@ -25,4 +26,5 @@
 require_once(__DIR__."/catalog/ContactsResource.php");
 require_once(__DIR__."/catalog/ContactPictureResource.php");
+require_once(__DIR__."/calendar/EventsResource.php");
 
 //Retrieveing the mapping of the URIs and his respectives classNames and classPath
Index: sandbox/webservice/api/rest/calendar/EventsResource.php
===================================================================
--- sandbox/webservice/api/rest/calendar/EventsResource.php	(revision 6423)
+++ sandbox/webservice/api/rest/calendar/EventsResource.php	(revision 6423)
@@ -0,0 +1,134 @@
+<?php
+
+class EventsResource extends CalendarAdapter {
+	public function post($request){
+		// to Receive POST Params (use $this->params)
+ 		parent::post($request);
+
+		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})?$/';
+
+			if(!preg_match($regex_date, $date_start))
+				Errors::runException("CALENDAR_INVALID_START_DATE");
+
+			if(!preg_match($regex_date, $date_end))
+				Errors::runException("CALENDAR_INVALID_END_DATE");
+
+			// get the start timestamp UNIX from the parameter
+			$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] = $row[$v];
+
+					$events[$id]['eventStartDate'] = date('d/m/Y H:i', $sdate);
+					$events[$id]['eventEndDate']   = date('d/m/Y H:i', $edate);
+					$events[$id]['eventAllDay']    = '0';
+				}
+				// 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));
+
+			$this->setResult($result);
+		}
+		//to Send Response (JSON RPC format)
+		return $this->getResponse();
+	}
+
+}
