<?php

	/********************* caldav GLUE render logic ****************************
	 *
	 * According to the render type will display required xml output.
	 * Currently only supports ajaxcal method of xml rendering
	 *
	 * I need to be refactored into the model !
	 *
	 *
	 * $this->account				- the current username@pop3host
	 * $this->event_entries 		- the array of entries for the specified date
	 * 		Format:
	 * 			$this->event_entries[]['id'] 				- id number of the event 
	 *														  (prepended with p=private/s=shared/
	 *														  inside the view example:p1/p2/s1/etc)
	 * 			$this->event_entries[]['DateStartCal'] 		- start of the appointment
	 * 			$this->event_entries[]['DateStartTime']		- start time during the start date
	 * 			$this->event_entries[]['DateEndCal']			- end of the appointment
	 * 			$this->event_entries[]['DateEndTime']		- end time during the end date
	 * 			$this->event_entries[]['Title']				- umm.. the title !
	 * $this->func					- view function to execute
	 * 
 	 ***************************************************************************/

	
	/*********************************************** MAIN ***************************************************/
	// lets assign some local vars to make life easier
	$func = $this->func;
	$extended = $this->extended;
	
	if(!$this->json)
	{
		header("Content-Type: text/xml");
print <<<EOF
<?xml version="1.0" encoding="utf-8"?>
EOF;
	}
	if ( $func == 'total')
	{
  		$this->calendar->print_total( $this->params['total'] );
 	}
	if ( $func == 'calname')
	{
  		$this->calendar->print_calnames( $this->calNames, $this->json);
 	}
 	else if ( $func == 'getusers' )
 	{
 		$this->calendar->print_users( $this->user_entries, $this->json );
 	}
	else if ( $func == 'freebusy' || $func == 'ajaxcal' || $func == 'overview')
	{
		$overview = false;
		if ($func == 'overview')
			$overview = true;
		$this->calendar->print_cal($func, $this->params['md5client'], "$this->account", $this->event_entries, $this->params['DateAlert'], $this->json, $this->params['start'], $this->params['end'], $overview, $this->timezone, $extended);
	}
	else if ( $func == "mkcal" || $func == "delcal" || $func == "updatecalname" || $func == "updatecalcolor")
	{
		if(!isset($this->params['ctag'])) $this->params['ctag'] = '';
		if(!isset($this->params['etag'])) $this->params['etag'] = '';
		if(!isset($this->params['name'])) $this->params['name'] = '';
		if(!isset($this->params['description'])) $this->params['description'] = '';
		if(!isset($this->params['color'])) $this->params['color'] = '';
		if(!isset($this->params['order'])) $this->params['order'] = '';
		if(!isset($this->params['calendar_owner'])) $this->params['calendar_owner'] = '';
		if(!isset($this->params['account'])) $this->params['account'] = '';
		if(!isset($this->params['principal_url'])) $this->params['principal_url'] = '';
		if(!isset($this->json)) $this->json = 0;
		
		$this->calendar->print_mkcal($this->params['ctag'], $this->params['etag'], $this->params['relative_href'], 0, $this->params['name'],$this->params['description'],$this->params['color'], $this->params['order'], $this->params['calendar_owner'], $this->params['account'], $this->json, $this->params['principal_url']);
	}
	else if ( $func == "add" || $func == "delete" || $func == "updatecal" || $func == "checkuser" || $func == "adduser" || $func == "deluser")
	{
		$this->calendar->print_return_code($this->params['id'], $this->params['status'], $this->json);
 	}
