<?php defined('SYSPATH') OR die('No direct access allowed.');

class formr {

	/**
	 * 
	 *
	 * @param   string   image
	 * @return  string
	 */
	public static function input( $name,  $value = NULL, array $attributes = null )
	{
		$tr_o = "<tr>";
		$tr_c = "</tr>";
		$td_o = "<td class='tabletextbox'>";
		$td_c = "</td>";
		$post = Session::instance()->get("post");
		$errors = Session::instance()->get("errors");
		$error = gen::arr_get($errors, $name);
		$error = $error?"<span class='error'>".$error."</span>":"";
		
		if(gen::arr_get($attributes, 'no_table'))
		{
			$tr_o = "";
			$tr_c = "";
			$td_o = "";
			$td_c = "";
			unset($attributes['no_table']);
		}
		if(!$value)
		{
			if(isset($_POST[$name]))
				$value = $_POST[$name];
			else
				$value = gen::arr_get($post, $name);
		}
		$label = gen::arr_get($attributes, 'label');
		unset($attributes['label']);
		if(!$label)
		{
			$label = $name;
		}
		$label = gen::lang($label).":";
		$return = $tr_o;
		$return .= $td_o.form::label($name, $label).$td_c;
		$return .= $td_o.form::input($name, $value, $attributes).$td_c;
		$return .= $td_o.$error.$td_c.$tr_c;
		return $return;
	}
	/**
	 * 
	 *
	 * @param   string   image
	 * @return  string
	 */
	public static function textarea( $name, $value = NULL, array $attributes = null  )
	{
		
		$tr_o = "<tr>";
		$tr_c = "</tr>";
		$td_o = "<td>";
		$td_c = "</td>";
		$post = Session::instance()->get("post");
		$errors = Session::instance()->get("errors");
		$error = gen::arr_get($errors, $name);
		$error = $error?"<span class='error'>".$error."</span>":"";
		
		if(gen::arr_get($attributes, 'no_table'))
		{
			$tr_o = "";
			$tr_c = "";
			$td_o = "";
			$td_c = "";
			unset($attributes['no_table']);
		}
		if(!$value)
		{
			if(isset($_POST[$name]))
				$value = $_POST[$name];
			else
				$value = gen::arr_get($post, $name);
		}
		$label = gen::arr_get($attributes, 'label');
		unset($attributes['label']);
		if(!$label)
		{
			$label = $name;
		}
		$label = gen::lang($label).":";
		$return = $tr_o;
		$return .= $td_o.form::label($name, $label).$td_c;
		$return .= $td_o.form::textarea($name, $value, $attributes).$td_c;
		$return .= $td_o.$error.$td_c.$tr_c;
		return $return;
	}
	public static function submit( $value="" )
	{
		if(!$value)
			$value = "submit";
		$value = gen::lang($value);
		return '<tr><td></td><td align="right">'.form::submit('submit', $value).'</td><td></td></tr>';
	}
} // End template