Added a draft for the search view.
authorGunnar Wrobel <p@rdus.de>
Tue, 28 Apr 2009 20:53:51 +0000 (22:53 +0200)
committerGunnar Wrobel <p@rdus.de>
Tue, 28 Apr 2009 20:53:51 +0000 (22:53 +0200)
koward/app/controllers/ApplicationController.php
koward/app/views/Object/search.html.php [new file with mode: 0644]
koward/config/search.php [new file with mode: 0644]
koward/lib/Form/Search.php [new file with mode: 0644]

index 55cfd47..212890b 100644 (file)
@@ -30,11 +30,11 @@ class Koward_ApplicationController extends Horde_Controller_Base
                    _("_Objects"), 'user.png', $registry->getImageDir('horde'));
         $menu->add($this->urlFor(array('controller' => 'object', 'action' => 'edit')),
                    _("_Add"), 'plus.png', $registry->getImageDir('horde'));
-        $menu->add(Horde::applicationUrl('search'), _("_Search"), 'search.png', $registry->getImageDir('horde'));
+        $menu->add($this->urlFor(array('controller' => 'object', 'action' => 'search')),
+                   _("_Search"), 'search.png', $registry->getImageDir('horde'));
         $menu->add(Horde::applicationUrl('Queries'), _("_Queries"), 'query.png', $registry->getImageDir('koward'));
         $menu->add($this->urlFor(array('controller' => 'check', 'action' => 'show')),
                    _("_Test"), 'problem.png', $registry->getImageDir('horde'));
-
         return $menu;
     }
 }
diff --git a/koward/app/views/Object/search.html.php b/koward/app/views/Object/search.html.php
new file mode 100644 (file)
index 0000000..3059c8e
--- /dev/null
@@ -0,0 +1,40 @@
+<?= $this->renderPartial('header'); ?>
+<?= $this->renderPartial('menu'); ?>
+<?php if (empty($this->objectlist)): ?>
+  <?= $this->form->renderActive(new Horde_Form_Renderer(), $this->vars,
+                                $this->post, 'post'); ?>
+<?php else: ?>
+<table cellspacing="0" width="100%" class="linedRow">
+ <thead>
+  <tr>
+   <th class="item" width="1%"><?php echo Horde::img('edit.png', _("Edit"), '', $GLOBALS['registry']->getImageDir('horde')) ?></th>
+   <th class="item" width="1%"><?php echo Horde::img('delete.png', _("Delete"), '', $GLOBALS['registry']->getImageDir('horde')) ?></th>
+   <?php foreach ($this->attributes as $attribute => $info): ?>
+     <th class="item leftAlign" width="<?php echo $info['width'] ?>%" nowrap="nowrap"><?= $info['title'] ?></th>
+   <?php endforeach; ?>
+  </tr>
+ </thead>
+ <tbody>
+  <?php foreach ($this->objectlist as $dn => $info): ?>
+  <tr>
+   <td>
+    <?= $info['edit_url'] ?>
+   </td> 
+   <td>
+    <?= $info['delete_url'] ?>
+   </td> 
+   <?php foreach ($this->attributes as $attribute => $ainfo): ?>
+   <td>
+   <?php if (!empty($ainfo['link_view'])): ?>
+   <?= $info['view_url'] . $this->escape($info[$attribute]) . '</a>'; ?>
+   <?php else: ?>
+    <?= $this->escape($info[$attribute]) ?>
+   <?php endif; ?>
+   </td> 
+   <?php endforeach; ?>
+  </tr> 
+  <?php endforeach; ?>
+ </tbody>
+</table>
+
+<?php endif; ?>
diff --git a/koward/config/search.php b/koward/config/search.php
new file mode 100644 (file)
index 0000000..fb6264f
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+$search = array(
+    'fields' => array(
+        'givenName' => array(
+            'label' => _("First Name"),
+            'type' => 'text',
+            'params' => array('regex' => '', 'size' => 40, 'maxlength' => 255)
+        ),
+    )
+);
+
+if (file_exists(dirname(__FILE__) . '/search.local.php')) {
+    require_once(dirname(__FILE__) . '/search.local.php');
+}
diff --git a/koward/lib/Form/Search.php b/koward/lib/Form/Search.php
new file mode 100644 (file)
index 0000000..7e8a8a7
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+/**
+ * @package Koward
+ */
+
+/**
+ * @package Koward
+ */
+class Koward_Form_Search extends Horde_Form {
+
+    /**
+     * The link to the application driver.
+     *
+     * @var Koward_Koward
+     */
+    protected $koward;
+
+    public function __construct(&$vars, &$object, $params = array())
+    {
+        $this->koward = &Koward_Koward::singleton();
+
+        $this->object = &$object;
+
+        parent::Horde_Form($vars);
+
+        $type = false;
+
+        $this->setButtons(_("Search"));
+        $this->_addFields($this->koward->search);
+    }
+
+
+    /**
+     * Sort fields for an object type
+     */
+    function _sortFields($a, $b)
+    {
+        if ($a['order'] == -1) {
+            return 1;
+        }
+        if ($b['order'] == -1) {
+            return -1;
+        }
+        if ($a['order'] == $b['order']) {
+            return 0;
+        }
+        return ($a['order'] < $b['order']) ? -1 : 1;
+    }
+
+    /**
+     * Set up the Horde_Form fields for the attributes of this object type.
+     */
+    function _addFields($config)
+    {
+        // Now run through and add the form variables.
+        $tabs   = isset($config['tabs']) ? $config['tabs'] : array('' => $config['fields']);
+
+        foreach ($tabs as $tab => $tab_fields) {
+            if (!empty($tab)) {
+                $this->setSection($tab, $tab);
+            }
+            foreach ($tab_fields as $key => $field) {
+                if (!in_array($key, array_keys($config['fields']))) {
+                    continue;
+                }
+                $attribute = $field;
+                $params = isset($attribute['params']) ? $attribute['params'] : array();
+                $desc = isset($attribute['desc']) ? $attribute['desc'] : null;
+
+                $v = &$this->addVariable($attribute['label'], 'object[' . $key . ']', $attribute['type'], $attribute['required'], null, $desc, $params);
+            }
+
+            if (isset($attribute['default'])) {
+                $v->setDefault($attribute['default']);
+            }
+        }
+    }
+
+    function &execute()
+    {
+        $this->getInfo($this->_vars, $info);
+        if (isset($info['object'])) {
+            $search_criteria = array();
+            foreach ($info['object'] as $key => $value) {
+                if (!empty($value)) {
+                    $search_criteria[] = array('field' => $key,
+                                               'op'    => 'contains',
+                                               'test' => $value);
+                }
+            }
+            $search_criteria = array('AND' => $search_criteria);
+            $criteria = array('AND' => array($search_criteria,
+                                             $this->koward->search['criteria']));
+            $filter = $this->koward->getServer()->searchQuery($criteria);
+            $params = array('scope' => 'sub',
+                            'attributes' => array('dn'));
+            return $this->koward->getServer()->search($filter, $params);
+        }
+    }
+}