Index: /sandbox/webservice/api/rest/calendar/EventsResource.php
===================================================================
--- /sandbox/webservice/api/rest/calendar/EventsResource.php	(revision 7489)
+++ /sandbox/webservice/api/rest/calendar/EventsResource.php	(revision 7740)
@@ -29,8 +29,23 @@
 			
 			$return = array();
-			
-			for( $j = (int)$start_date_arr[2]; $j <= (int)$end_date_arr[2]; $j++ )
+
+
+			$start_year = (int)$start_date_arr[2];
+            $end_year = (int)$end_date_arr[2];
+
+			for( $j = $start_year; $j <= $end_year; $j++ )
 			{
-				for( $i = (int)$start_date_arr[1]; $i <= (int)$end_date_arr[1]; $i++ )
+				$start_month = (int)$start_date_arr[1];
+				$end_month = (int)$end_date_arr[1];
+
+				if ($start_year != $end_year) {
+					if ($j == $start_year) {
+						$end_month = 12;
+					} else {
+						$start_month = 1;
+					}
+				}       
+
+				for( $i = $start_month; $i <= $end_month; $i++ )
 				{
 					if( (int)$i < 10 )
@@ -38,5 +53,6 @@
 					else
 						$result = $this->getEvents($i,$j);
-					
+
+
 					if( count($result) > 0 )
 					{
@@ -46,4 +62,6 @@
 			}
 
+
+
 			if( count($return) > 0 )
 			{
@@ -52,53 +70,60 @@
 				for( $j = 0 ; $j < count( $return); $j++)
 				{
-					foreach( $return[$j] as $key => $value )
+					foreach( $return[$j] as $key => $event )
 					{
-						$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'] )
+
+						foreach ($event as $value) {
+
+
+							$events[$i]['eventID']			= "".$value['id'];
+							$events[$i]['eventDate']		= "".$key;
+							$events[$i]['eventName']		= mb_convert_encoding("".$value['title'],"UTF8","ISO_8859-1");
+							$events[$i]['eventDescription']	= mb_convert_encoding("".$value['description'], "UTF8","ISO_8859-1");
+							$events[$i]['eventLocation']	= mb_convert_encoding("".$value['location'], "UTF8","ISO_8859-1");
+							$events[$i]['eventParticipants']= $value['participants'];
+
+							$starttime	= $this->makeTime($value['start']);
+							$endtime	= $this->makeTime($value['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 )
 							{
-								$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'] );
+								$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( $events[$i-1] && $events[$i-1]['eventAllDay'] == "1" )
+								if( $value['start']['mday'] === $value['end']['mday'] )
 								{
-									$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'] );
+									$hour_start	= (((int)$value['start']['hour'] < 10 ) ? "0".$value['start']['hour'] : $value['start']['hour']).":".(((int)$value['start']['min'] < 10 ) ? "0".$value['start']['min'] : $value['start']['min'] );
+									$hour_end	= (((int)$value['end']['hour'] < 10 ) ? "0".$value['end']['hour'] : $value['end']['hour']).":".(((int)$value['end']['min'] < 10 ) ? "0".$value['end']['min'] : $value['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";
+									if( $events[$i-1] && $events[$i-1]['eventAllDay'] == "1" )
+									{
+										$hour_start	= "00:00";
+										$hour_end	= (((int)$value['end']['hour'] < 10 ) ? "0".$value['end']['hour'] : $value['end']['hour']).":".(((int)$value['end']['min'] < 10 ) ? "0".$value['end']['min'] : $value['end']['min'] );
+									}
+									else
+									{
+										$hour_start	= (((int)$value['start']['hour'] < 10 ) ? "0".$value['start']['hour'] : $value['start']['hour']).":".(((int)$value['start']['min'] < 10 ) ? "0".$value['start']['min'] : $value['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]['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['ex_participants'];
 						}
-						
-						$events[$i++]['eventExParticipants'] = $value[0]['ex_participants'];
+
 					}
+
 				}
 
