From 9d8691e3c6ad7ca18c1656a84baa2087d37723c6 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Tue, 28 Apr 2009 22:55:44 +0200 Subject: [PATCH] Added searching. Finished deletion of objects. Allowed object actions. --- koward/app/controllers/ObjectController.php | 127 +++++++++++++++++++++++++--- 1 file changed, 115 insertions(+), 12 deletions(-) diff --git a/koward/app/controllers/ObjectController.php b/koward/app/controllers/ObjectController.php index 3dff2fea5..e93f5e623 100644 --- a/koward/app/controllers/ObjectController.php +++ b/koward/app/controllers/ObjectController.php @@ -23,7 +23,6 @@ class ObjectController extends Koward_ApplicationController { require_once 'Horde/UI/Tabs.php'; require_once 'Horde/Variables.php'; - require_once 'Horde/Util.php'; $this->object_type = $this->params->get('id', $this->types[0]); @@ -85,17 +84,31 @@ class ObjectController extends Koward_ApplicationController 'horde.error'); } else { $this->object = $this->koward->getObject($this->params->id); - if (empty($this->params->submit)) { - $this->token = $this->koward->getRequestToken('object.delete'); - } else { - $this->koward->checkRequestToken('object.delete', $this->params->token); - $this->object->delete(); - $this->koward->notification->push(sprintf(_("Successfully deleted the object \"%s\""), - $this->params->id), - 'horde.message'); + $this->submit_url = $this->urlFor(array('controller' => 'object', + 'action' => 'delete', + 'id' => $this->params->id, + 'token' => $this->koward->getRequestToken('object.delete'))); + $this->return_url = $this->urlFor(array('controller' => 'object', + 'action' => 'listall')); + + if (!empty($this->params->token)) { + if (is_array($this->params->token) && count($this->params->token) == 1) { + $token = $this->params->token[0]; + } else { + $token = $this->params->token; + } + $this->koward->checkRequestToken('object.delete', $token); + $result = $this->object->delete(); + if ($result === true) { + $this->koward->notification->push(sprintf(_("Successfully deleted the object \"%s\""), + $this->params->id), + 'horde.message'); + } else { + $this->koward->notification->push(_("Failed to delete the object."), + 'horde.error'); + } header('Location: ' . $this->urlFor(array('controller' => 'object', - 'action' => 'listall', - 'id' => get_class($this->object)))); + 'action' => 'listall'))); exit; } } @@ -113,9 +126,23 @@ class ObjectController extends Koward_ApplicationController $this->koward->notification->push(_("The object that should be viewed has not been specified."), 'horde.error'); } else { + require_once 'Horde/Variables.php'; + $this->object = $this->koward->getObject($this->params->id); - require_once 'Horde/Variables.php'; + $actions = $this->object->getActions(); + if (!empty($actions)) { + $this->actions = new Koward_Form_Actions($this->object); + + $this->post = $this->urlFor(array('controller' => 'object', + 'action' => 'view', + 'id' => $this->params->id)); + + if ($this->actions->validate()) { + $this->actions->execute(); + } + } + $this->vars = Variables::getDefaultVariables(); $this->form = new Koward_Form_Object($this->vars, $this->object, array('title' => _("View object"))); @@ -126,6 +153,8 @@ class ObjectController extends Koward_ApplicationController _("Edit")) . Horde::img('edit.png', _("Edit"), '', $GLOBALS['registry']->getImageDir('horde')) . ''; + + } } catch (Exception $e) { $this->koward->notification->push($e->getMessage(), 'horde.error'); @@ -145,6 +174,15 @@ class ObjectController extends Koward_ApplicationController require_once 'Horde/Variables.php'; $this->vars = Variables::getDefaultVariables(); + foreach ($this->params as $key => $value) { + if (!$this->vars->exists($key)) { + if (is_array($value) && count($value) == 1) { + $this->vars->set($key, $value[0]); + } else { + $this->vars->set($key, $value); + } + } + } $this->form = new Koward_Form_Object($this->vars, $this->object); if ($this->form->validate()) { @@ -167,4 +205,69 @@ class ObjectController extends Koward_ApplicationController $this->render(); } + + public function search() + { + try { + require_once 'Horde/Variables.php'; + $this->vars = Variables::getDefaultVariables(); + $this->form = new Koward_Form_Search($this->vars, $this->object); + + if ($this->form->validate()) { + $result = $this->form->execute(); + + $uids = array_keys($result); + + if (count($uids) == 1) { + header('Location: ' . $this->urlFor(array('controller' => 'object', + 'action' => 'view', + 'id' => $uids[0]))); + exit; + } else if (count($uids) == 0) { + $this->koward->notification->push(_("No results found!"), 'horde.message'); + } else { + if (isset($this->koward->search['list_attributes'])) { + $this->attributes = $this->koward->search['list_attributes']; + } else { + $this->attributes = array( + '__id' => array( + 'title' => _("Kennung"), + 'width' => 100, + 'link_view'=> true, + ) + ); + } + foreach ($result as $uid => $info) { + $this->objectlist[$uid]['edit_url'] = Horde::link( + $this->urlFor(array('controller' => 'object', + 'action' => 'edit', + 'id' => $uid)), + _("Edit")) . Horde::img('edit.png', _("Edit"), '', + $GLOBALS['registry']->getImageDir('horde')) + . ''; + $this->objectlist[$uid]['delete_url'] = Horde::link( + $this->urlFor(array('controller' => 'object', + 'action' => 'delete', + 'id' => $uid)), + _("Delete")) . Horde::img('delete.png', _("Delete"), '', + $GLOBALS['registry']->getImageDir('horde')) + . ''; + $this->objectlist[$uid]['view_url'] = Horde::link( + $this->urlFor(array('controller' => 'object', + 'action' => 'view', + 'id' => $uid)), _("View")); + $this->objectlist[$uid]['__id'] = $uid; + } + } + } + } catch (Exception $e) { + $this->koward->notification->push($e->getMessage(), 'horde.error'); + } + + $this->post = $this->urlFor(array('controller' => 'object', + 'action' => 'search')); + + $this->render(); + } + } \ No newline at end of file -- 2.11.0