From 42c62cb041a2b2b95c9cda0c20fcf70334fd244c Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 1 Nov 2011 09:32:21 +0000 Subject: Rewl og krat... needs cleaning up - after port to GIT. --- utils/forms.php | 66 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 14 deletions(-) (limited to 'utils/forms.php') diff --git a/utils/forms.php b/utils/forms.php index 39e1a4c..d6fdada 100644 --- a/utils/forms.php +++ b/utils/forms.php @@ -89,14 +89,19 @@ class CheckBox { { $this->label = $label; $this->name = $name; - $this->value = $value; + if($value == true || $value == "on" || $value == "true" || $value == "yes") + $this->value = "checked "; + else + $this->value = ""; } public function render($indent = "") { $str = $indent . "
\n"; - $str .= $indent . "
". xmlenc($this->label) ."
\n"; - $str .= $indent . "
name."]\" value=\"".xmlenc($this->value)."\"/>
\n"; + $str .= $indent . "
". xmlenc($this->label) ."
\n"; + $str .= $indent . "
". + "name."]\" ".$this->value."value=\"on\"/>". + "
\n"; $str .= $indent . "
\n"; return $str; } @@ -132,7 +137,7 @@ class ComboBox { class Hidden { public $values; - + public function Hidden($values) { $this->values = $values; @@ -280,13 +285,14 @@ class ImageComboBox { class ListEditor { public $label, $name, $namewidget, $valuewidget, $values; - public function ListEditor($label, $name, $namewidget, $valuewidget, $values = array()) + public function ListEditor($label, $name, $namewidget, $valuewidget, $values = array(), $commalist = false) { $this->label = $label; $this->name = $name; $this->namewidget = $namewidget; $this->valuewidget = $valuewidget; $this->values = $values; + $this->commalist = $commalist; } public function render($indent = "") @@ -354,11 +360,17 @@ class ListEditor { $str .= $indent . "}\n"; $str .= $indent . "//-->\n"; $str .= $indent . "\n"; - $str .= $indent . "name."[]\">\n"; + if($this->values) { + if($this->commalist) { + foreach($this->values as $val) { + $str .= $indent . " \n"; + } + } else { + foreach($this->values as $key => $val) { + $str .= $indent . " \n"; + } + } } $str .= $indent . "
\n"; $str .= $indent . "
/\

\n"; @@ -373,12 +385,38 @@ class ListEditor { public function splitValues($values) { $out = array(); - foreach($values as $value) { - $vals = explode(":", $value); - $out[$vals[0]]=$vals[1]; - } + if($values) { + foreach($values as $value) { + $vals = explode(":", $value); + + /* + $out[$vals[0]]=$vals[1]; + */ + + $_keys = array_keys($out); + $_vals = array_values($out); + + array_push($_keys, $vals[0]); + array_push($_vals, $vals[1]); + + $out = array_combine($_keys, $_vals); + } + } return $out; } + + function combineValues($values) + { + $out = array(); + if($values) { + foreach($values as $k => $v) { + $value = $k.":".$v; + array_push($out, $value); + } + } + return $out; + } + } class MultiList { -- cgit v1.2.3