/**
* The required files
*/
require_once(HTML_BASE_COMMON_PATH.'/Html.php');
require_once(HTML_FORM_COMPONENT_PATH.'/Hidden.php');
require_once(HTML_UTIL_COMPONENT_PATH.'/Params.php');
/**
* Create the hidden fields used in a form
* <code>
* Usage:
* $keyValue = array();
* $hiddens = new Hiddens($keyValue,$title);
* print $hiddens->getHtml();
* Or
* Hiddens::display($keyValue,$title);
* </code>
* @package form
*/
class Hiddens extends Html {
/**
* @var array $keyValue Optionally array of key value pairs, or empty
*/
var $keyValue = '';
/**
* @var String $title The title for the next command to execute
*/
var $title = '';
/**
* @var String $debug The debug text to use, if any
*/
var $debug = '';
/**
* Constructor
* @param array $keyValue Optionally array of key value pairs, or empty
* @param String $title The title for the next command to execute
* @param String $debug The debug text to use, if any
*/
function Hiddens($keyValue=array(),$title='',$debug='') {
$this->Html();
$this->keyValue = $keyValue;
$this->title = $title;
$this->debug = $debug;
}
/**
* Get the html for the specified hidden field
* @param String $name The name of the request key
* @param String $const The const string of the request key
* @param array $keyValue Optionally array of key value pairs, or empty
* @param array $vars The request array send as a GET or POST
* @param String $title The title for the hidden field
* @return String The html
*/
function getHidden($name,$const,$keyValue,$vars,$title='') {
$html = '';
if (defined($name) && !empty($vars[$const])) {
if (!array_key_exists($const,$keyValue)) {
if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
$title = $title!=''?$title." $name":$name;
}
if (Params::validate($const,$vars[$const])) {
$hidden = new Hidden($const,$vars[$const],$title);
$html .= $hidden->getHtml();
} else {
$html .= "Params::validate($name) failed<br />\r\n";
}
} else {
if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
$html = "<!-- DEBUG: $name already defined -->\r\n";
}
}
} else {
if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
//$html = "<!-- DEBUG: $name -->\r\n";
}
}
return $html;
}
/**
* Get the html for all the hidden fields
* @see Params
* @param array $vars The request array send as a GET or POST
* @return String The html
*/
function getHiddens($vars) {
$html = '';
$keyValue = $this->keyValue;
foreach($keyValue as $key=>$value) {
if ($value!='') {
if (Params::validate($key,$value)) {
$title = $this->title;
if ($this->debug!='') {
$title .= ' ('.$this->debug.')';
}
$hidden = new Hidden($key,$value,$title);
$html .= $hidden->getHtml();
} else {
$html .= "Params::validate($key) failed<br />\r\n";
}
}
}
// REQUEST_COMMAND is Added in the form where the Buttons are defined etc.
//$html .= $this->getHidden('REQUEST_COMMAND',REQUEST_COMMAND,$keyValue,$vars,$this->title);
$html .= $this->getHidden('REQUEST_NEXT',REQUEST_NEXT,$keyValue,$vars,$this->title);
// CMS
$html .= $this->getHidden('REQUEST_PAGE_DOMAINNAME',REQUEST_PAGE_DOMAINNAME,$keyValue,$vars);
/**
* Returns the html for all the hidden fields for a form
* @return String The html
*/
function getHiddenFields() {
return $this->getHiddens($_SERVER['REQUEST_METHOD']===REQUEST_METHOD_POST?$_POST:$_GET);
}
/**
* Get the complete html for the hidden fields in a form
* @return String The html
*/
function getHtml() {
$html = $this->html;
if (defined('DEBUG_LEVEL') && (DEBUG_LEVEL & DEBUG_LEVEL_SHOW_DECRYPT) && $this->debug!='') {
$html .= "<!-- ".$this->getClassName()." ".$this->debug." -->\r\n";
}
$html .= $this->getHiddenFields();
return $html;
}
/**
* Display html
* <code>
* Usage:
* Hiddens::display($keyValue, $title, $debug);
* </code>
* @static
* @param array $keyValue Optionally array of key value pairs, or empty
* @param String $title The title for the next command to execute
* @param String $debug The debug text, if any
*/
function display($keyValue=array(), $title='', $debug='') {
$html = new Hiddens($keyValue, $title, $debug);
$html->addHtml();
}
}
?>