Location: PHPKode > projects > O - OpenSource GroupWare > osgw/calendar/classes/class.format.php
<?php
/**************************************************************************
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   @Authors:	Ryan Thompson(hide@address.com)
***************************************************************************/
/*$Id: class.format.php,v 1.21 2004/05/29 01:14:32 rthomp Exp $*/
class format
{
	var $format_day;
	var $format_month;
	var $format_year;
	var $size;
	var $buffer = 0;
	var $time_style;
	var $week_start;
	var $display;
	
	/*!
		@function format()
		@author Ryan Thompson
		@abstract Sets variables for formatting
		@version 0.1
		@params $size
		@params $month
		@return TRUE
		@since 07-04-2004
	*/
	function format($size, $month, $day, $year)
	{
		$this->format_month = $month;
		$this->format_day = $day;
		$this->format_year = $year;
		$this->size = $size;
		
		return TRUE;
	}

	/*!
		@function calendar_header()
		@author Ryan Thompson
		@abstract Retrieves default view from preferences
		@version 0.1
		@params $links - Only used for large display
		@return $cal_header
		@since 07-04-2004
	*/	
	function calendar_header($links = NULL, $file, $display_view)
	{
		GLOBAL $O, $html, $layout, $lang, $date;
		
		if($display_view == 'month')
		{
			$month_name = explode(':', $lang->msgs['long_months']);
		
			$header_text = $month_name[$this->format_month];
		} elseif ($display_view == 'day')
		{
			$weekdays = explode(':', $lang->msgs['long_weekdays']);
			
			$header_text .= date($date->long_date, mktime(0,0,0, $this->format_month, $this->format_day, $this->format_year));
		} elseif($display_view = 'week')
		{
			$start = date($date->long_date, $this->week_start);
			$end = date($date->long_date, $this->week_start + (DAY_SEC * 6));
			$header_text .= $start ." - ". $end;
		}
		
		$file = "{$layout->service_theme}/$file";
		switch($this->size)
		{
			case 'small':
				return $html->create_list(
				array("DISPLAY_MONTH"=>
				$O->create_link("/calendar/index.php?v=2&d={$this->format_day}&m={$this->format_month}&y={$this->format_year}", 
				$header_text, "{$this->size}_header_month"),
					"FORM_LINK"=>$_SERVER['PHP_SELF']),
					$file);	
			break;
			case 'large':
			
				return $html->create_list(
				array("DISPLAY_MONTH"=>$header_text,
						"PREV_LINK"=>$links['prev'],
						"NEXT_LINK"=>$links['next'],
					"FORM_LINK"=>$_SERVER['PHP_SELF']),
					$file);	
			break;
			
		}
	}
	
	/*!
		@function calendar_footer()
		@author Ryan Thompson
		@abstract Creates footer for calendar
		@version 0.1
		@return $cal_footer
		@since 07-04-2004
	*/	
	function calendar_footer()
	{
		GLOBAL $html, $layout, $lang;

		switch($this->size)
		{
			case 'small':
				return $html->create_list(
				array(),
					"{$layout->service_theme}/cal_footer_small.html");
			
			case 'large':
				return $html->create_list(
				array(),
					"{$layout->service_theme}/cal_footer_small.html");
			
		}
	}
	
	/*!
		@function fill_empty_cells()
		@author Ryan Thompson
		@abstract Creates filler cells for empty dates
		@version 0.1
		@params $count
		@return $empty_cells
		@since 07-04-2004
	*/	
	function fill_empty_cells($count)
	{
		GLOBAL $layout, $html;
		$i = 0;
		$empty_cells = NULL;
			
		while($i < $count)
		{
			$empty_cells .= $html->create_list(
					array("DAY"=>'','EVENTS'=>'','BIRTHDAY'=>'','HOLIDAYS'=>'','STYLE'=>''),
					"{$layout->service_theme}/cal_{$this->size}_cell.html");
			$i++;
		} 
		
		return $empty_cells;
		
	}
	
	/*!
		@function format_cell()
		@author Ryan Thompson
		@abstract Creates a formated cell with a date
		@version 0.1
		@param $day
		@param $events
		@return $cell
		@since 07-04-2004
	*/	
	function format_cell($day, $event_list = NULL, $holidays = NULL, $birthdays = NULL)
	{
		GLOBAL $O, $html, $layout, $date;	
		if(!is_null($event_list) && is_array($event_list))
		{
			if($this->size != 'small')
			{
				foreach($event_list AS $key => $value)
				{
					$title = date($date->time, $value['evt_start']) . ' - '. date($date->time, $value['evt_end']);
					$link = $O->create_link("/calendar/view_event.php?id={$value['event_id']}", $value['subject'], $this->size."_events", "title=\"$title\"");
					$formatted_events .= $link;
					$formatted_events .= "<br />";
				}
			
			}
			$style = "{$this->size}_events";
			

		}
		
		if($day == date('j') && $this->format_month == date('n') && $this->format_year == date('Y'))
		{
			$style = "{$this->size}_today";
			
		} elseif(!isset($style)) {
			$style = "{$this->size}_cell";
		}
			
		$day_link = $O->create_link("/calendar/create_event.php?v={$_GET['v']}&d={$day}&m={$this->format_month}&y={$this->format_year}"
			, $day, "$style");
		if(is_array($holidays))
		{
			foreach($holidays AS $key=>$value)
			{
				$holidays = $value['holiday'];
			}	
		}
		if(!is_null($birthdays['address_id']))
		{
			
			//Change edit_contact to view_contact once contact service has been updated
			$bd_img = $O->create_image("/calendar/themes/{$layout->user_theme}/birthday.gif",
				"{$birthdays['lastname']},{$birthdays['firstname']}", $style, 'right');
			$bd = $O->create_link("/contacts/edit_contact.php?id={$birthdays['address_id']}", $bd_img, $style);
		}
		return $html->create_list(
					array("DAY"=>"&nbsp;".$day_link,
						'EVENTS'=>$formatted_events,
						'BIRTHDAY'=>$bd,
						'HOLIDAYS'=>$holidays,
						'STYLE'=>"$style"),
					"{$layout->service_theme}/cal_{$this->size}_cell.html");
	}
	
	
	/*!
		@function weekdays()
		@author Ryan Thompson
		@abstract Creates Weekdays List
		@version 0.1
		@return $weekdays
		@since 07-04-2004
	*/	
	function weekdays()
	{
		GLOBAL $html, $layout, $lang;	
		
		if($this->size == 'small')
		{
			$weekdays_list = explode(':', $lang->get_msg('short_weekdays','gl'));	
		} else {
			$weekdays_list = explode(':', $lang->get_msg('long_weekdays','gl'));
		}
		$i = 0;
		$weekdays = NULL;
		while($i < 7)
		{
		
			$weekdays .= $html->create_list(
					array("DAY"=>$weekdays_list[$i], 'STYLE'=>"{$this->size}_weekdays",'EVENTS'=>'','BIRTHDAY'=>'','HOLIDAYS'=>''),
					"{$layout->service_theme}/cal_{$this->size}_cell.html");
			$i++;
		}
	
		return $weekdays;	
	}
	
	/*!
		@function create_time_cell()
		@author Ryan Thompson
		@abstract Creates a cell for day view with the time increment
		@version 0.1
		@params $working_time
		@return $cell
		@since 06-05-2004
	*/
	function create_time_cell($working_time)
	{
		GLOBAL $layout, $html;	
		$this->time_style = $html->list_class($this->time_style);		
		return $html->create_list(
					array("TIME"=>"&nbsp;".$working_time,'STYLE'=>"$this->time_style"),
					"{$layout->service_theme}/day_time_cell.html");
	}
	
	/*!
		@function create_event_cell()
		@author Ryan Thompson
		@abstract Creates a cell for day view with the time increment
		@version 0.1
		@param $event
		@param $buffer;
		@return $cell
		@since 06-05-2004
	*/
	function create_event_cell($event, $buffer)
	{
		GLOBAL $layout, $html, $O;
		
		if(!is_null($event))
		{
			$event_style = "day_event";
			$this->buffer = $buffer -1;
			
			$subject = $O->create_link("/calendar/view_event.php?id={$event['event_id']}", $event['subject'], $event_style);
			if($this->display != 'week')
			{
				$times = " - (". date('H:i', $event['evt_start']) ." - ". date('H:i', $event['evt_end']) .")";
			}
			return $html->create_list(
					array("EVENT"=>"&nbsp; $subject$times" ,'STYLE'=>"$event_style", "ROW_SPAN"=>$buffer),
					"{$layout->service_theme}/day_event_cell.html");
		} else {
			
				
			if($this->buffer == 0) 
			{
				$style = $html->list_class($style);
				$empty_event = $html->create_list(
					array("EVENT"=>"&nbsp;",'STYLE'=>"{$style}", "ROW_SPAN"=>'1'),
					"{$layout->service_theme}/day_event_cell.html");	
			
			} else {
			
				$this->buffer--;
			}
			
			return $empty_event;
		}
	}


}
Return current item: O - OpenSource GroupWare