<?PHP

class title{

	var $elem = array();

	function elem($type, $name=''){

		$this->elemType = $type;
		array_push($this->elem, array($type => array('name' => $name)));
		return $this;
	}

	function href($attr){

		$this->elem[count($this->elem)-1][$this->elemType]['href'] = $attr;
		return $this;
	}

	function cssClass($attr){

		$this->elem[count($this->elem)-1][$this->elemType]['class'] = $attr;
		return $this;
	}

	function style($attr){

		$this->elem[count($this->elem)-1][$this->elemType]['style'] = $attr;
		return $this;
	}

	function type($attr){

		$this->elem[count($this->elem)-1][$this->elemType]['type'] = $attr;
		return $this;
	}

	function name($attr){

		$this->elem[count($this->elem)-1][$this->elemType]['name'] = $attr;
		return $this;
	}

	function value($attr){

		$this->elem[count($this->elem)-1][$this->elemType]['value'] = $attr;
		return $this;
	}

	function method($attr){

		$this->elem[count($this->elem)-1][$this->elemType]['method'] = $attr;
		return $this;
	}

	function createAttributes($attr){

		$html = '';
		unset($attr['name']);
		//unset($attr['value']);

		foreach($attr as $type => $value){

			$html .= ' '.$type.'="'.$value.'"';
		}
		return $html;
	}

	function create($title, $appendDashboard = true){

		$html = '<input type="hidden" name="model" value="'.$_GET['model'].'"><input type="hidden" name="page" value="'.$_GET['page'].'">';
		if($appendDashboard)
			array_push($this->elem, array('a' => array('name' => 'Dashboard', 'href' => './')));

		foreach($this->elem as $v){

			foreach($v as $elem => $attr){

				switch($elem){

					case 'a':

						$html .= '<a'.$this->createAttributes($attr).'>'.$attr['name'].'</a>';
					break;

					case 'form':

						$html .= '<form'.$this->createAttributes($attr).'>';
					break;

					case 'form-end':
					case '/form':

						$html .= '</form>';
					break;

					case 'input':

						$html .= '<input name="'.$attr['name'].'"'.$this->createAttributes($attr).'/>';
					break;
				}
			}
		}
		echo '<div class="desktitle"><div class="title">'.$title.'</div><div class="link"><form>'.$html.'</form></div><div style="clear:both;"></div></div>';
	}
}

?>