<?php
class Form {

	private $form;

	public function __construct($arrForm){
		if(is_array($arrForm)){
			$this->form = $arrForm;
		}
	}

	public function exibir(){
		if(is_array($this->form)){

			// inicia form
			echo '<form';
			foreach($this->form['form'] as $attrForm => $valorAttrForm){
				echo ' '.$attrForm.'="'.$valorAttrForm.'"';
			}
			echo '>';
			$this->nl();

			// exibe campos
			foreach($this->form['campos'] as $idCampo => $dadosCampo){

				// inicia div
				echo '<div';
				foreach($dadosCampo['div'] as $attrDiv => $valorAttrDiv){
					echo ' '.$attrDiv.'="'.$valorAttrDiv.'"';
				}
				echo '>';
				$this->nl();

					// label
					$valorLabel = '';
					echo '<label for="'.$idCampo.'"';
					foreach($dadosCampo['label'] as $attrLabel => $valorAttrLabel){
						if($attrLabel == 'valor'){
							$valorLabel = $valorAttrLabel;
						}
						else{
							echo ' '.$attrLabel.'="'.$valorAttrLabel.'"';
						}
					}
					echo '>';
					echo $valorLabel;
					echo '</label>';
					$this->nl();

					// campo
					if($dadosCampo['campo']['type'] == 'select'){
						// select
						echo '<select type="'.$dadosCampo['campo']['type'].'" id="'.$idCampo.'"';
						foreach($dadosCampo['campo'] as $attrCampo => $valorAttrCampo){
							if($attrCampo != 'type'){
								echo ' '.$attrCampo.'="'.$valorAttrCampo.'"';
							}
						}
						echo ' />';

					}
					else if($dadosCampo['campo']['type'] == 'textarea'){
						// textarea

					}
					else{
						echo '<input type="'.$dadosCampo['campo']['type'].'" id="'.$idCampo.'"';
						foreach($dadosCampo['campo'] as $attrCampo => $valorAttrCampo){
							if($attrCampo != 'type'){
								echo ' '.$attrCampo.'="'.$valorAttrCampo.'"';
							}
						}
						echo ' />';
					}
					$this->nl();

				// fecha div
				echo '</div>';
				$this->nl();

			}
			
			// fecha form
			echo '</form>';
			$this->nl();
		}
	}

	// exibe "\n" no codigo-fonte
	private function nl(){
		echo "\n";
	}

}
?>