X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/098a79f0819ebb89b7d48df4a6b154af4560f68e..9a23a8c0a51b7ec38a96f525484134f3cb85dc7e:/WEB-INF/lib/form/Table.class.php diff --git a/WEB-INF/lib/form/Table.class.php b/WEB-INF/lib/form/Table.class.php new file mode 100644 index 00000000..89f6543f --- /dev/null +++ b/WEB-INF/lib/form/Table.class.php @@ -0,0 +1,226 @@ +mName = $name; + $this->mValue = $value; + } + + function setKeyField($value) { + $this->mKeyField = $value; + } + + function setData($data) { + if (is_array($data) && isset($data[0]) && is_array($data[0])) + $this->mData = &$data; + } + + function addColumn($column) { + if ($column != null) $column->setTable($this); + $this->mColumns[] = &$column; + } + + function setInteractive($value) { $this->mInteractive = $value; } + function isInteractive() { return $this->mInteractive; } + + function setIAScript($value) { $this->mIAScript = $value; } + function getIAScript() { return $this->mIAScript; } + + function setWidth($value) { $this->mWidth = $value; } + function getWidth() { return $this->mWidth; } + + function setTableOptions($value) { $this->mTableOptions = $value; } + function getTableOptions() { return $this->mTableOptions; } + + function setRowOptions($value) { $this->mRowOptions = $value; } + function getRowOptions() { return $this->mRowOptions; } + + function setHeaderOptions($value) { $this->mHeaderOptions = $value; } + function getHeaderOptions() { return $this->mHeaderOptions; } + + function getValueAt($rowindex, $colindex) { + if (!$this->mProccessed) $this->_process(); + return @$this->mData[$rowindex][$this->mColumnFields[$colindex]]; + } + + function getValueAtName($rowindex,$fieldname) { + if (!$this->mProccessed) $this->_process(); + return @$this->mData[$rowindex][$fieldname]; + } + + function _process() { + $this->mProccessed = true; + + if ($this->mInteractive) { + // Add a column of clickable checkboxes. + $column = new TableColumn("","getName()."_all\" onclick=\"setAll(this.checked)\">"); + import('form.CheckboxCellRenderer'); + $cb = new CheckboxCellRenderer(); + if ($this->getIAScript()) $cb->setOnChangeAdd($this->getIAScript()."(this)"); + $column->setRenderer($cb); + $column->setTable($this); + array_unshift($this->mColumns, $column); + } + + foreach ($this->mColumns as $column) { + $this->mColumnFields[] = $column->getField(); + $this->mHeaders[] = $column->getHeader(); + } + } + + function toStringControl() { + if (!$this->isRenderable()) return ""; + if (!$this->mProccessed) $this->_process(); + + $html = ""; + if ($this->mInteractive) $html .= $this->_addJavaScript(); + + $html .= "mTableOptions) > 0) { + foreach ($this->mTableOptions as $k=>$v) { + $html .= " $k=\"$v\""; + } + } else { + $html .= " border=\"1\""; + } + if ($this->mWidth!="") $html .= " width=\"".$this->mWidth."\""; + $html .= ">\n"; + + // Print headers. + if (($this->mInteractive && (count($this->mHeaders) > 1)) || (!$this->mInteractive && (count($this->mHeaders) > 0))) { + $html .= "mRowOptions) > 0) { + foreach ($this->mRowOptions as $k=>$v) { + $html .= " $k=\"$v\""; + } + } + $html .= ">\n"; + foreach ($this->mHeaders as $header) { + $html .= "mHeaderOptions) > 0) { + foreach ($this->mHeaderOptions as $k=>$v) { + $html .= " $k=\"$v\""; + } + } + $html .= ">$header\n"; + } + $html .= "\n"; + } + + // Print rows. + for ($row = 0; $row < count($this->mData); $row++) { + $html .= "\nmBgColor."\" onmouseover=\"setRowBackground(this, '".$this->mBgColorOver."')\" onmouseout=\"setRowBackground(this, null)\">\n"; + for ($col = 0; $col < $this->getColumnCount(); $col++) { + if (0 == $col && strtolower(get_class($this->mColumns[$col]->getRenderer())) == 'checkboxcellrenderer') { + // Checkbox for the row. Determine if selected. + $selected = false; + if (is_array($this->mValue)) { + foreach ($this->mValue as $p) { + if ($p == $this->mData[$row][$this->mKeyField]) { + $selected = true; + break; + } + } + } + // Render control checkbox. + $html .= $this->mColumns[$col]->renderCell($this->mData[$row][$this->mKeyField], $row, $col, $selected); + } else { + // Render regular cell. + $html .= $this->mColumns[$col]->renderCell($this->getValueAt($row, $col), $row, $col); + } + } + $html .= "\n"; + } + + $html .= ""; + return $html; + } + + function getColumnCount() { + return count($this->mColumns); + } + + function _addJavaScript() { + $html = "\n"; + + return $html; + } +} +?> \ No newline at end of file