The form to allow object actions.
authorGunnar Wrobel <p@rdus.de>
Tue, 28 Apr 2009 20:57:16 +0000 (22:57 +0200)
committerGunnar Wrobel <p@rdus.de>
Tue, 28 Apr 2009 20:57:16 +0000 (22:57 +0200)
koward/lib/Form/Actions.php [new file with mode: 0644]

diff --git a/koward/lib/Form/Actions.php b/koward/lib/Form/Actions.php
new file mode 100644 (file)
index 0000000..73cd952
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/**
+ * @package Koward
+ */
+
+/**
+ * @package Koward
+ */
+class Koward_Form_Actions extends Horde_Form {
+
+    /**
+     * The link to the application driver.
+     *
+     * @var Koward_Koward
+     */
+    protected $koward;
+
+    public function __construct(&$object)
+    {
+        $this->koward = &Koward_Koward::singleton();
+
+        $this->object = &$object;
+
+        parent::Horde_Form(Variables::getDefaultVariables());
+
+        $this->setTitle(_("Object actions"));
+
+        $class_name = get_class($this->object);
+        foreach ($this->koward->objects as $name => $config) {
+            if ($config['class'] == $class_name) {
+                $this->type = $name;
+                if (!empty($config['preferred'])) {
+                    break;
+                }
+            }
+        }
+
+        $buttons = array();
+        foreach ($this->object->getActions() as $action) {
+            if (isset($this->koward->objects[$this->type]['actions'][$action])) {
+                $buttons[] = $this->koward->objects[$this->type]['actions'][$action];
+            }
+        }
+
+        if (!empty($buttons)) {
+            $this->setButtons($buttons);
+        }
+    }
+
+    function &execute()
+    {
+        require_once 'Horde/Util.php';
+
+        $submit = Util::getFormData('submitbutton');
+        if (!empty($submit)) {
+            foreach ($this->koward->objects[$this->type]['actions'] as $action => $label) {
+                if ($submit == $label) {
+                    $this->object->$action();
+                }
+            }
+        }
+    }
+}