X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/098a79f0819ebb89b7d48df4a6b154af4560f68e..9a23a8c0a51b7ec38a96f525484134f3cb85dc7e:/WEB-INF/lib/form/CheckboxGroup.class.php diff --git a/WEB-INF/lib/form/CheckboxGroup.class.php b/WEB-INF/lib/form/CheckboxGroup.class.php new file mode 100644 index 00000000..6fef2317 --- /dev/null +++ b/WEB-INF/lib/form/CheckboxGroup.class.php @@ -0,0 +1,163 @@ +mName = $name; + $this->mValue = $value; + } + + function setChecked($value) { $this->mChecked = $value; } + function isChecked() { return $this->mChecked; } + + function setData($value) { $this->mOptions = $value; } + function getData() { return $this->mOptions; } + + function setDataKeys($keys) { $this->mDataKeys = $keys; $this->mDataDeep = 2; } + function getDataKeys() { return $this->mDataKeys; } + + function setLayout($value) { $this->mLayout = $value; } + function getLayout() { return $this->mLayout; } + + function setGroupIn($value) { $this->mGroupIn = $value; if ($this->mGroupIn<1) $this->mGroupIn = 1;} + function getGroupIn() { return $this->mGroupIn; } + + function setLocalization($i18n) { + FormElement::setLocalization($i18n); + $this->lSelAll = $i18n->getKey('label.select_all'); + $this->lSelNone = $i18n->getKey('label.select_none'); + } + + function toStringControl() { + if (!$this->isRenderable()) return ""; + + if ($this->mId=="") $this->mId = $this->mName; + + $renderArray = array(); + $renderCols = 0; + $renderRows = 0; + + if ($this->mLayout=="H") { + $i = 0; + if (is_array($this->mOptions)) { + $renderCols = $this->mGroupIn; + $renderRows = ceil(count($this->mOptions) / $this->mGroupIn); + $col = $row = 0; + foreach ($this->mOptions as $optkey=>$optval) { + if ($this->mDataDeep>1) { + $optkey = $optval[$this->mDataKeys[0]]; + $optval = $optval[$this->mDataKeys[1]]; + } + $html = "mName[]\" id=\"$this->mId"."_".$i."\""; + if (is_array($this->mValue)) { + foreach ($this->mValue as $value) { + if (($value == $optkey) && ($value != null)) + $html .= " checked=\"true\""; + } + } + $html .= " value=\"".htmlspecialchars($optkey)."\"> "; + $renderArray[$col][$row] = $html; + + $col++; + if ($col==$this->mGroupIn) { $col = 0; $row++; } + $i++; + } + } + } + + if ($this->mLayout=="V") { + $i = 0; + if (is_array($this->mOptions)) { + $renderCols = ceil(count($this->mOptions) / $this->mGroupIn); + $renderRows = $this->mGroupIn; + $col = $row = 0; + foreach ($this->mOptions as $optkey=>$optval) { + if ($this->mDataDeep>1) { + $optkey = $optval[$this->mDataKeys[0]]; + $optval = $optval[$this->mDataKeys[1]]; + } + $html = "mName[]\" id=\"$this->mId"."_".$i."\""; + if (is_array($this->mValue)) { + foreach ($this->mValue as $value) { + if (($value == $optkey) && ($value != null)) + $html .= " checked=\"true\""; + } + } + $html .= " value=\"".htmlspecialchars($optkey)."\"> "; + $renderArray[$col][$row] = $html; + + $row++; + if ($row==$this->mGroupIn) { $row = 0; $col++; } + $i++; + } + } + } + + + $html = "\n\t
| \n"; + $html .= ''.$this->lSelAll.' / '.$this->lSelNone.''; + $html .= " | |
";
+ $html .= "\n\t
|