Return to Snippet

Revision: 21640
at December 17, 2009 00:15 by mpcircuitry


Initial Code
<?

class HTML_DISPLAY
{
	public function __construct($cols=3)
	{
		$this->tabCount = 0;
		$this->columns = $cols;
	}
	public function tableStart($border=0, $width="100%", $cellSpacing=2, $cellPadding=0)
	{
		if ($width != "")
		{
			$width = "width=\"$width\"";
		}
		if ($this->columns != 0)
		{
			$cols = "cols=\"$this->columns\"";
		}
		$this->tabRight();
		echo $this->printTabs()."<table border=\"$border\" $width  cellpadding=\"$cellSpacing\" cellspacing=\"$cellPadding\">".$this->newLine;
	}
	
	public function tableStop()
	{
		echo $this->printTabs()."</table>".$this->newLine ;
		$this->tabLeft();
	}
	
	public function formStart($formName, $action="", $method="post", $target="")
	{
	
		if ($target != "")
		{
			$target = "target=\$target\"";
		}
		$this->tabRight();
		$this->formName = $formName;
		
		echo $this->printTabs()."<form name=\"$formName\" method=\"$method\" action=\"$action\"  $target>".$this->newLine;
	}

	public function formStop()
	{
		echo $this->printTabs()."</form>".$this->newLine;
		$this->tabLeft();
	}
	
	
	public function submitButton($type=1)
	{
		if ($type == 1)
		{
			$txt="Submit Answers";
		}
		elseif($type == 2)
		{
			$txt="Next ->";
		}
		else
		{
			$txt="Submit";
		}
		echo "<input type=\"submit\" name=\"$txt\" value=\"$txt\" />";
	}
	
	public function clearButton()
	{
		echo "<input name=\"Clear\" type=\"Reset\" id=\"Clear\" value=\"Clear\" />";
	}
	
	public function button($id, $display, $class="", $java="", $show=TRUE)
	{
		if ($class!= "")
		{
			$class = "class=\"$class\"";
		}
		
		$buttonText = "<input type=\"button\" id=\"$id\" name=\"$id\" $class $java value=\"$display\"/>";
		if($show)
		{
			echo $buttonText;
		}
		else
		{
			return $buttonText;
		}
	}
	
	public function hiddenField($div, $text="")
	{
		echo "<input id=\"$div\" type=\"hidden\" name=\"$div\" $text/>";
	}

	public function rowStart($class="")
	{
		if ($class != "")
		{
			$class = " class=\"$class\"";
		}

		$this->tabRight();
		echo $this->printTabs()."<tr $class>".$this->newLine;
	}
	
	public function rowStop()
	{
		echo $this->printTabs()."</tr>".$this->newLine;
		$this->tabLeft();
	}
	
	public function colStart($width, $colSpan=1, $rowSpan=1, $class=NULL)
	{
		$this->tabRight();
		$width = $width==""?$width:"width=\"$width%\"";
		echo $this->printTabs()."<td $width colspan=\"$colSpan\" rowspan=\"$rowSpan\" valign=\"top\" align=\"left\"";
		
		if (!is_null($class))
		{
			echo " class=\"$class\"";
		}
		echo " >".$this->newLine;
	}
	
	public function colStop()
	{
		echo $this->printTabs()."</td>".$this->newLine;
		$this->tabLeft();
	}
	
	public function colHeaderStart($width, $colSpan=1, $rowSpan=1,  $class=NULL)
	{
		$this->tabRight();
		echo $this->printTabs()."<th width=\"$width%\" colspan=\"$colSpan\" rowspan=\"$rowSpan\" valign=\"top\" ";
		
		if (!is_null($class))
		{
			echo " class=\"$class\"";
		}
		echo " >".$this->newLine;	}
	
	public function colHeaderStop()
	{
		echo $this->printTabs()."</th>".$this->newLine;
		$this->tabLeft();
	}



	public function insertRadioButton($divID, $radioText, $value="", $javaScript="", $showText=TRUE, $checked="")
	{
		
		$textForFrontEnd = $radioText;
		if ($value=="")
		{
			$value=$radioText;
		}
		
		if (!$showText)
		{
			$textForFrontEnd = "";
		}
		
		$this->tabRight();
		echo $this->printTabs()."<label>".
			"<input name=\"$divID\" id=\"$divID\" type=\"radio\" value=\"$value\" $checked $javaScript>".
			"$textForFrontEnd</label>".$this->newLine;
		$this->tabLeft();
	}



	public function dropDownListStart($divID, $javaScript=NULL)
	{
		
	    $this->tabRight();
		echo $this->printTabs()."<select id=\"$divID\" name=\"$divID\" $javaScript>".$this->newLine;
		$this->tabRight();
	}
	
	public function dropDownListIetm ($value, $displayText, $selected="", $class=NULL)
	{		
     	echo $this->printTabs()."<option value=\"".strtoupper($value)."\" $selected ".
		($class!=NULL?"class=\"$class\"":"").">$displayText</option>".$this->newLine;
	 
	}
	
	public function dropDownListStop()
	{
		$this->tabLeft();
    	echo $this->printTabs()."</select>".$this->newLine;
		$this->tabLeft();
	}
	
	
	
	
	
	public function insertTextBox($div, $question, $charactersPerLine=25, $charLength=255, $text="", $multiline=FALSE, $password=FALSE)
	{
		$this->divArray[$this->formName][$div] =sizeof($this->divArray[$this->formName])+1;
		
		if ($multiline)
		{
			//multi-line
			$strTextBox =  "<textarea name=\"$div\" cols=\"$charactersPerLine\">$text</textarea>";
		}
		else
		{
			//single line
			$strTextBox = "<input name=\"$div\" id=\"$div\" type=\"text\" size=\"$charactersPerLine\" maxlength=\"$charLength\" $text/>";
		}
		
		echo $strTextBox;
	}
	
	public function insertPasswordBox($div, $charactersPerLine=25, $charLength=255)
	{
		
		$strTextBox = "<input name=\"$div\" id=\"$div\" type=\"password\" size=\"$charactersPerLine\" maxlength=\"$charLength\"/>";
		
		echo $strTextBox;
	}
	
	
	public function tabRight()
	{
		$this->tabCount++;	
	}
	
	public function tabLeft()
	{
		if ($this->tabCount > 0)
		{
			--$this->tabCount;
		}
	}
	
	public function printTabs()
	{
		$tempTabs = "";
		
		for ($i = 0; $i < $this->tabCount; ++$i)
		{
			$tempTabs .= $this->tab;
		}
		
		return $tempTabs;
	}
	
	public function linkTo($link, $linkText, $target="", $class="")
	{
		if ($target != "")
		{
			$target = "target=\"$target\"";
		}
		if ($class != "")
		{
			$class = "class=\"$class\"";
		}
		
		echo "<a href=\"$link\" $target $class>$linkText</a>";
	}
	
	public function divDisplayed()
	{
		/*
		echo "<br>";
		$pageKeys = array_keys($this->divArray);
		for ($i = 0; $i < sizeof($this->divArray); ++$i)
		{
			$page = $pageKeys[$i];
			$columnKeys = array_keys($this->divArray[$page]);
			for($j = 0; $j < sizeof($this->divArray[$page]); ++$j)
			{
				echo "$page|".$columnKeys[$j]."|".($j+1)."<br>";
			}
		}
		*/
	}
	
	
	protected $newLine = "\n";
	protected $tab = "\t";
	protected $tabCount;
	protected $columns;
	
	
	protected $formName;
	protected $divArray;
}

?>

Initial URL

                                

Initial Description
A PHP class that creates html controls

Initial Title
HTML Class for PHP

Initial Tags
php, html

Initial Language
PHP