[ghelda-devel] [27] Allow array values in $_POST (aka for arrayed values)

[ Thread Index | Date Index | More lists.tuxfamily.org/ghelda-devel Archives ]


Revision: 27
Author:   odyx
Date:     2009-04-29 14:27:33 +0200 (Wed, 29 Apr 2009)

Log Message:
-----------
Allow array values in $_POST (aka for arrayed values)

Modified Paths:
--------------
    trunk/inc/outputs/xHTML.class.php


Modified: trunk/inc/outputs/xHTML.class.php
===================================================================
--- trunk/inc/outputs/xHTML.class.php	2009-04-29 12:27:29 UTC (rev 26)
+++ trunk/inc/outputs/xHTML.class.php	2009-04-29 12:27:33 UTC (rev 27)
@@ -372,8 +372,8 @@
 	
 					// Add the "_old" hidden stag
 					$paramsArray['type'] = 'hidden';
-					$paramsArray['name'] = $fieldName.'_old';
-					$paramsArray['id'] = $fieldName.'_old';
+					$paramsArray['name'] = $this->appendOld($fieldName);
+					$paramsArray['id'] = $this->appendOld($fieldName);
 					$field .= $this->stag('input',$paramsArray);
 	
 	
@@ -414,8 +414,8 @@
 					$field = $this->stag('input',$paramsArray);
 					// Add the "_old" hidden stag
 					$paramsArray['type'] = 'hidden';
-					$paramsArray['name'] = $fieldName.'_old';
-					$paramsArray['id'] = $fieldName.'_old';
+					$paramsArray['name'] = $this->appendOld($fieldName);
+					$paramsArray['id'] = $this->appendOld($fieldName);
 					unset($paramsArray['maxlength']);
 					$field .= LB.$this->stag('input',$paramsArray);
 	
@@ -441,8 +441,8 @@
 					$fields .= $this->xdate($fieldProperties,$fieldsContents[$fieldName_],$fieldName,$paramsArray);
 					// Add the "_old" hidden stag
 					$paramsArray['type'] = 'hidden';
-					$paramsArray['name'] = $fieldName.'_old';
-					$paramsArray['id'] = $fieldName.'_old';
+					$paramsArray['name'] = $this->appendOld($fieldName);
+					$paramsArray['id'] = $this->appendOld($fieldName);
 					$paramsArray['value'] = $this->formatDateSimple($fieldsContents[$fieldName_]);
 					$fields .= LB.$this->stag('input',$paramsArray);
 				} elseif(stripos($fieldProperties['type'],'enum') !== false) {
@@ -466,8 +466,8 @@
 					}
 					// Add the "_old" hidden stag
 					$paramsArray['type'] = 'hidden';
-					$paramsArray['name'] = $fieldName.'_old';
-					$paramsArray['id'] = $fieldName.'_old';
+					$paramsArray['name'] = $this->appendOld($fieldName);
+					$paramsArray['id'] = $this->appendOld($fieldName);
 					$paramsArray['value'] = $fieldsContents[$fieldName_];
 					unset($paramsArray['checked']);
 					$field .= LB.$this->stag('input',$paramsArray);
@@ -665,7 +665,7 @@
 				if(!is_null($options_selected) && in_array($value,$options_selected)) {
 					$attributes['selected'] = 'selected';
 				}
-				$optionsTxt .= $this->tag('option',array_key_exists('name',$name) ? $name['name'] : $name,$attributes); // Add "true" at the end for easier formatting
+				$optionsTxt .= $this->tag('option',is_array($name) && array_key_exists('name',$name) ? $name['name'] : $name,$attributes); // Add "true" at the end for easier formatting
 			}
 		} else {
 			// Go along all the optgroups
@@ -684,7 +684,7 @@
 					if(!is_null($options_selected) && in_array($value,$options_selected)) {
 						$attributes['selected'] = 'selected';
 					}
-					$optionsInTxt .= $this->tag('option',array_key_exists('name',$name) ? $name['name'] : $name,$attributes); // Add "true" at the end for easier formatting
+					$optionsInTxt .= $this->tag('option', is_array($name) && array_key_exists('name',$name) ? $name['name'] : $name,$attributes); // Add "true" at the end for easier formatting
 				}
 				$optionsTxt .= $this->mark('optgroup',$optionsInTxt,$opt_attributes);
 			}
@@ -695,15 +695,15 @@
 	private function xdate($fieldProperties,$fieldContent,$fieldName,$paramsArray)
 	{
 		// $fieldContent = $fieldsContents[$fieldName];
-		$label = $this->tag('label',$fieldProperties['name'],array('for'=>$fieldName.'_year'));
+		$label = $this->tag('label',$fieldProperties['name'],array('for'=>$this->appendOld($fieldName,'_year')));
 		$formattedDate = T_('%YEAR%-%MONTH%-%DAY%');
 		preg_match("`([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})`", $fieldContent, $regs);
 		$dateOptions = array_key_exists('error',$fieldProperties) ? ($fieldProperties['error'] ? array("class" => "input_error") : array() ) : array();
 		// Get the global lists
 		global $DAYS,$MONTHS,$YEARS;
-		$year  = $this->select($YEARS,$regs[1],array_merge($paramsArray,array('name'=>$fieldName.'_year')));
-		$month = $this->select($MONTHS,$regs[2],array_merge($paramsArray,array('name'=>$fieldName.'_month')));
-		$day   = $this->select($DAYS,$regs[3],array_merge($paramsArray,array('name'=>$fieldName.'_day')));
+		$year  = $this->select($YEARS,$regs[1],array_merge($paramsArray,array('name'=>$this->appendOld($fieldName,'_year'))));
+		$month = $this->select($MONTHS,$regs[2],array_merge($paramsArray,array('name'=>$this->appendOld($fieldName,'_month'))));
+		$day   = $this->select($DAYS,$regs[3],array_merge($paramsArray,array('name'=>$this->appendOld($fieldName,'_day'))));
 		
 		$formattedDate = str_replace('%YEAR%',$year,$formattedDate);
 		$formattedDate = str_replace('%MONTH%',$month,$formattedDate);
@@ -753,5 +753,17 @@
 		}
 	}
 
+	/**
+	* appendOld
+	* Appends "_old" at the end of the fieldName (or smarter)
+	*/
+	private function appendOld($name,$to_append = "_old")
+	{
+		if( ($crochet = strpos($name,"[")) )
+			return substr($name,0,$crochet).$to_append.substr($name,$crochet);
+		else
+			return $name.$to_append;
+	}
+
 }	
 ?>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/