From a93461b231fb94f3a6a9df09a30557732201ddcc Mon Sep 17 00:00:00 2001
From: Antonio Gallo <tonicucoz@gmail.com>
Date: Mon, 14 Oct 2013 16:06:56 +0000
Subject: added new EasyGiant Library

---
 h-source/Library/Form/Form.php | 73 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 64 insertions(+), 9 deletions(-)

(limited to 'h-source/Library/Form/Form.php')

diff --git a/h-source/Library/Form/Form.php b/h-source/Library/Form/Form.php
index a1a9fda..d1899a4 100755
--- a/h-source/Library/Form/Form.php
+++ b/h-source/Library/Form/Form.php
@@ -97,7 +97,7 @@ class Form_Form {
 
 	//function to create the HTML of the form
 	//$values: an associative array ('entryName'=>'value')
-	//$subset: subset to print
+	//$subset: subset to print (comma seprated list of string or array)
 	public function render($values = null, $subset = null)
 	{
 		
@@ -116,23 +116,78 @@ class Form_Form {
 		$fenctype = isset($this->enctype) ? " enctype=".$this->enctype." " : null;
 		$htmlForm = "<form $fname $fclass $fid action='".Url::getRoot($this->action)."' method='".$this->method."' $fenctype>\n";
 
-		$subset = (isset($subset)) ? explode(',',$subset) : array_keys($values);
+		if (!isset($subset))
+		{
+			$subset = array_keys($values);
+		}
+		else
+		{
+			$subset = !is_array($subset) ? explode(',',$subset) : $subset;
+		}
+// 		$subset = (isset($subset)) ? explode(',',$subset) : array_keys($values);
 		
-		foreach ($subset as $entry)
+		//first cicle: write the HTML of tabs if there are any
+		$tabsHtml = null;
+		$fCount = 0;
+		foreach ($subset as $key => $entry)
 		{
-
-			if (array_key_exists($entry,$this->entry))
+			if (is_array($entry))
 			{
-				$value = array_key_exists($entry,$values) ? $values[$entry] : $this->entry[$entry]->defaultValue;
-				$htmlForm .= $this->entry[$entry]->render($value);
+				$currClass = $fCount === 0 ? "current_tab" : null;
+				$cleanKey = encode($key);
+				$tabsHtml .= "\t<li class='form_tab_li $currClass'><a rel='tab_$cleanKey' class='form_tab_a form_tab_a_$cleanKey' href='#'>$key</a></li>\n";
+				$fCount++;
+			}
+		}
+		if (isset($tabsHtml))
+		{
+			$htmlForm .= "<ul class='form_tab_ul'>\n$tabsHtml\n</ul>\n";
+		}
+		
+		$fCount = 0;
+		foreach ($subset as $k => $entry)
+		{
+			
+			$cleanK = encode($k);
+			if (!is_array($entry))
+			{
+				if (array_key_exists($entry,$this->entry))
+				{
+					$value = array_key_exists($entry,$values) ? $values[$entry] : $this->entry[$entry]->defaultValue;
+					$htmlForm .= $this->entry[$entry]->render($value);
+				}
+			}
+			else
+			{
+				$tHtml = null;
+				$displClass = $fCount === 0 ? null : "display_none";
+				foreach ($entry as $e)
+				{
+					if (array_key_exists($e,$this->entry))
+					{
+						$value = array_key_exists($e,$values) ? $values[$e] : $this->entry[$e]->defaultValue;
+						$tHtml .= $this->entry[$e]->render($value);
+					}
+				}
+				$htmlForm .= "<div id='tab_$cleanK' class='tab_description_item $displClass'>$tHtml</div>";
+				$fCount++;
 			}
-
 		}
 		
+		$htmlForm .= "<div class='submit_entry'>";
 		foreach ($this->submit as $name => $value)
 		{
-			$htmlForm .= "<div class='inputEntry'>\n<input id='".$name."' type='submit' name='$name' value='$value'>\n</div>\n";
+			if (!is_array($value))
+			{
+				$htmlForm .= "<span class='submit_entry_$value'>".Html_Form::submit($name, $value, null, $name)."</span>";
+			}
+			else
+			{
+				array_unshift($value,$name);
+				$htmlForm .= call_user_func_array(array("Html_Form","submit"),$value);
+			}
 		}
+		$htmlForm .= "</div>";
 		$htmlForm .= "</form>\n";
 		return $htmlForm;
 	}
-- 
cgit v1.2.3