Location: PHPKode > projects > O - OpenSource GroupWare > osgw/osgw/classes/class.html.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.html.php,v 1.14 2004/05/04 05:32:43 rthomp Exp $*/
class html
{

	function create_filter($user_id, $service, $page, $categories)
	{
		GLOBAL $category, $layout, $lang;
		$filter = $this->create_list(
			array("FILTER"=>$lang->get_msg('filter', 'gl'),
				"STYLE"=>"list_header",
				"CATEGORY_FILTER"=>$category->get_category_select($user_id, $service, $page, $categories, TRUE),
				"PHP_SELF"=> $_SERVER['PHP_SELF']),
			$layout->theme_dir ."/filter.html");
			
		return $filter;
	}
	
	/*!
		@function list_class()
		@author Ryan Thompson
		@abstract Retrieves the alternate to the current class for lists.
		@version 0.1
		@params $class - The current working class
		@return $new_class - The return class for the link
		@since 07-11-2003
	*/
	function list_class($class)
	{
		if($class == 'list_light')
		{
			$new_class = 'list_dark';
		} else {
			$new_class = 'list_light';
		}
		return $new_class;	
	}
	
	/*!
		@function link_stylesheet()
		@author Ryan Thompson
		@abstract Creates a stylesheet link for the header
		@version 0.1
		@params $link - CSS File to link to
		@return $stylesheet
		@since 03-12-2003
	*/
	function link_stylesheet($link)
	{
		return "<link rel=\"stylesheet\" type=\"text/css\" href=\"$link\" />\n";
	}
	
	function create_list($items, $file)
	{
		GLOBAL $error;
	
		if(!$fp = @fopen($file,'r'))
		{
			echo "ERROR";
			//Add Error to database and get error handler to manage
			if($error->debug)
			{
				echo "<br />";
				echo "Can't find file -- $file";
			}
		} else {
			while(!feof($fp))
			{
				$buffer .= fgets($fp, 2048);
			}
			fclose($fp);
		}
		
		foreach($items AS $key=>$value)
		{
			$buffer = str_replace("{".$key ."}", $value, $buffer);
		}
		
		return $buffer;
	}

	function open_table($args)
	{
		$start_table = "<table $args>\n";

		return $start_table;

	}

	
	function close_table()
	{
		return "</table>\n";
	}
	
	function start_row()
	{
		return "<tr>\n";
	}
	
	function end_row()
	{
		return "</tr>\n";
	}
	
	function cell($args, $value)
	{
		return $cell = "<td ". $args .">". $value ."</td>";
	}
	
	
	function delete_confirm($form_link, $service, $data)
	{
		GLOBAL $O, $lang;
		unset($delete);
		
		$i = 0;
		//Serialize/Unserialize doesn't seem to return an array
		//Problem is with strip slashes. I have to get this out of here anyway
		//echo $delete = ;
		/*
		while($i < count($data))
		{
			$delete .= $data[$i];
			if($i != count($data) - 1)
			{
				$delete .= ":";	
			}
			$i++;
		}
	*/
		$confirm = "\n<br />\n";
		$confirm .= "<table style=\"border: 1px solid black\" width=\"350\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n";
		$confirm .= "<tr>\n<td colspan=\"2\" class=\"input_header\" style=\"font-size: 14pt\">\n";
		$confirm .= $lang->get_msg('confirm_title', 'gl');
		$confirm .= "\n</td>\n</tr>\n";
		$confirm .= "<tr>\n<td colspan=\"2\">\n";
		$confirm .= "<form action=\"". $form_link  ."\" method=\"post\">\n";
		$confirm .= "<input type=\"hidden\" name=\"delete_values\" value=". serialize($data) .">\n";
		$confirm .= $lang->get_msg('confirm_message', 'gl');
		//echo "Are you sure you want to delete the selected tasks?";
		$confirm .= "\n</td>\n</tr>\n<tr>\n<td style=\"text-align: center\" width=\"175\">\n";
		
		$confirm .= "<br /><input type=\"submit\" name=\"confirm_delete\" value=\"Yes\" class=\"button1\">\n";
		$confirm .= "<br />&nbsp;\n";
		$confirm .= "</td><td style=\"text-align: center\" width=\"175\">\n";
		$confirm .= "<br /><input type=\"submit\" name=\"cancel\" value=\"No\" class=\"button1\"><br />&nbsp;\n";
		$confirm .= "</form>\n";
		$confirm .= "</td></tr></table>\n";
		$confirm .= "<br />\n";
		
		return $confirm;
		
	}
	
	/*!
		@function message_box()
		@author Ryan Thompson
		@abstract Creates a simple message box
		@version 0.1
		@params $text
		@return $message;
		@since 07-11-2003
	*/	
	function message_box($text)
	{
		GLOBAL $lang;
		$message_box = "<br />";
		$message_box .= "<table style=\"border: 1px solid black\" width=\"350\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
		$message_box .= "<tr><td colspan=\"2\" class=\"input_header\" style=\"font-size: 14pt\">";
		$message_box .= $lang->get_msg('no_items', 'gl');
		$message_box .= "</td></tr>";
		$message_box .= "<tr><td style=\"text-align:center\"><p>";
		
		$message_box .= $text;
		
		
		//echo "Are you sure you want to delete the selected tasks?";
		$message_box .= "</p></td></tr></table>";
		$message_box .= "<br />\n";
		
		return $message_box;
	}

	/*!
		@function select_box()
		@author Ryan Thompson
		@abstract Creates a select box on a form
		@version 0.1
		@params $name - Value for name attribute
		@params $type - 	(count -- values 1-n display 1-n) 
					(value_count -- values 1-n display values in $array) 
					(display_count -- values in array, display 1-n)
					(array -- values / display stored in $array)
		@params $data- Contain min/max and array data if nessacary
		@params $selected - Value to return as selected.
		@return $select_box;
		@since 07-11-2003
	*/
	function select_box($name, $type, $data, $selected = NULL)
	{
		GLOBAL $error;
		//echo $error->debug('date');

		if(!is_array($data))
		{
			return FALSE;
		}
		$select_box = "\n<select name=\"$name\">\n";
		switch($type)
		{
			case 'count':
				$c = 500;		//This can be changed but I don't think any select box would have much more then 500
				$i = $data['min'];
				while($i <= $data['max'])
				{
					$select_box .= "\t<option value=\"$i\"";
					if($i == $selected)
					{
						$select_box .= " selected=\"selected\"";	
					}
					
					$select_box .= ">$i</option>\n";
					
					//A safety for runaway code. I think 500 is a safe number
					if($c < 0)
					{
						die("Runaway Select box");
					}
					$i++;
					$c--;
				}
				
			break;
			case 'value_count':
				foreach($data AS $key => $value)
				{
					if(!empty($value))
					{
						$select_box .= "\t<option value=\"$key\"";
						if($key == $selected)
						{
							$select_box .=  " selected=\"selected\"";
						}
						$select_box .= ">$value</option>\n";
					}
					
				}
			break;
			case 'array':
		
				foreach($data AS $key => $value)
				{
					
			
						$select_box .= "\t<option value=\"$key\"";
						if($key == $selected)
						{
							$select_box .=  " selected=\"selected\"";
						}
						$select_box .= ">$value</option>\n";
				}
			break;
		}
		
		
		
		
		$select_box .= "</select>\n";
		
		
		return $select_box;
	}
	
	

}
Return current item: O - OpenSource GroupWare