* @license http://www.contenido.org/license/LIZENZ.txt * @link http://www.4fb.de * @link http://www.contenido.org * * {@internal * created 2004-08-04 * modified 2010-05-11, Dominik Ziegler, removed output of "foo" * * $Id: class.widgets.views.php 160 2012-11-27 21:08:41Z oldperl $ * }} * */ if (!defined('CON_FRAMEWORK')) { die('Illegal call'); } /** * Contenido Table view * * @author Timo A. Hummel */ class cTableView { var $items; var $captions; var $id; var $rownames; var $formname; var $formmethod; var $formaction; var $formvars; var $tableid; var $tablebordercolor; var $header; var $cancelLink; var $submitjs; function UI_Table_Form($name, $action = "", $method = "post") { global $sess, $cfg; $this->formname = $name; if ($action == "") { $this->formaction = "main.php"; } else { $this->formaction = $action; } $this->formmethod = $method; $this->tableid = ""; $this->tablebordercolor = $cfg['color']['table_border']; $this->setAccessKey('s'); $this->custom = array(); $this->setActionButton("submit", "images/but_ok.gif", i18n("Save changes"), "s"); } function setVar($name, $value) { $this->formvars[$name] = $value; } function add($caption, $field, $rowname = "") { if (is_array($field)) { foreach ($field as $value) { if (is_object($value) && method_exists($value, "render")) { $n .= $value->render(); } else { $n .= $value; } } $field = $n; } if (is_object($field) && method_exists($field, "render")) { $n = $field->render(); $field = $n; } if ($field == "") { $field = " "; } if ($caption == "") { $caption = " "; } $this->id++; $this->items[$this->id] = $field; $this->captions[$this->id] = $caption; if ($rowname == "") { $rowname = $this->id; } $this->rownames[$this->id] = $rowname; } function addCancel($link) { $this->cancelLink = $link; } function addHeader($header) { $this->header = $header; } function setSubmitJS($js) { $this->submitjs = $js; } function setAccessKey($key) { $this->accessKey = $key; } function setActionEvent($id, $event) { $this->custom[$id]["event"] = $event; } function setActionButton($id, $image, $description = "", $accesskey = false, $action = false) { $this->custom[$id]["image"] = $image; $this->custom[$id]["type"] = "actionsetter"; $this->custom[$id]["action"] = $action; $this->custom[$id]["description"] = $description; $this->custom[$id]["accesskey"] = $accesskey; $this->custom[$id]["event"] = ""; } function unsetActionButton($id) { unset($this->custom[$id]); } function render($return = true) { global $sess, $cfg; $tpl = new Template; $extra = ""; $form = '
' . "\n"; $this->formvars["contenido"] = $sess->id; if (is_array($this->formvars)) { foreach ($this->formvars as $key => $value) { $form .= '' . "\n"; } } if (!array_key_exists("action", $this->formvars)) { $form .= ''; } $tpl->set('s', 'FORM', $form); $tpl->set('s', 'ID', $this->tableid); $tpl->set('s', 'BORDERCOLOR', $this->tablebordercolor); if ($this->header != "") { $header = ''; $header .= '' . $this->header . ''; } $tpl->set('s', 'HEADER', $header); $dark = false; if (is_array($this->items)) { foreach ($this->items as $key => $value) { $tpl->set('d', 'CATNAME', $this->captions[$key]); $tpl->set('d', 'CATFIELD', $value); $tpl->set('d', 'ROWNAME', $this->rownames[$key]); $dark = !$dark; if ($dark) { $bgColor = $cfg["color"]["table_dark"]; } else { $bgColor = $cfg["color"]["table_light"]; } $tpl->set('d', 'BGCOLOR', $bgColor); $tpl->set('d', 'BORDERCOLOR', $this->tablebordercolor); $tpl->next(); } } $tpl->set('s', 'CONTENIDOPATH', $cfg["path"]["contenido_fullhtml"]); if ($this->cancelLink != "") { $img = ''; $tpl->set('s', 'CANCELLINK', '' . $img . ''); } else { $tpl->set('s', 'CANCELLINK', ''); } if ($this->submitjs != "") { $extra .= 'onclick="' . $this->submitjs . '"'; } if ($this->accesskey != "") { $tpl->set('s', 'KEY', $this->accesskey); } else { $tpl->set('s', 'KEY', ''); } $tpl->set('s', 'EXTRA', $extra); $custombuttons = ""; foreach ($this->custom as $key => $value) { if ($value["accesskey"] != "") { $accesskey = 'accesskey="' . $value["accesskey"] . '"'; } else { $accesskey = ""; } $onclick = ""; if ($value["action"] !== false) { $onclick = 'document.forms[\'' . $this->formname . '\'].elements[\'action\'].value = \'' . $value["action"] . '\';'; } if ($value["event"] != "") { $onclick .= $value["event"]; } $custombuttons .= ''; } $tpl->set('s', 'EXTRABUTTONS', $custombuttons); $rendered = $tpl->generate($cfg["path"]["contenido"] . $cfg['path']['templates'] . $cfg['templates']['generic_table_form'], true); if ($return == true) { return ($rendered); } else { echo $rendered; } } }