library. The application itself is still in a rather rough state.
class ObjectController extends Koward_ApplicationController
{
+ var $object_type;
+ var $objectlist;
+ var $attributes;
+ var $tabs;
+ var $object;
+ var $post;
+
public function listall()
{
require_once 'Horde/UI/Tabs.php';
$this->object_type = $this->params->get('id', $this->types[0]);
- if (isset($this->koward->objects[$this->object_type])) {
- $this->attributes = $this->koward->objects[$this->object_type]['attributes'];
+ if (isset($this->koward->objects[$this->object_type]['list_attributes'])) {
+ $this->attributes = $this->koward->objects[$this->object_type]['list_attributes'];
+ } else if (isset($this->koward->objects[$this->object_type]['attributes']['fields'])) {
+ $this->attributes = $this->koward->objects[$this->object_type]['attributes']['fields'];
+ } else {
+ $this->koward->notification->push(sprintf('No attributes have been defined for the list view of objects with type %s.',
+ $this->object_type),
+ 'horde.error');
+ }
+
+ if (isset($this->attributes)
+ && isset($this->koward->objects[$this->object_type])) {
$params = array('attributes' => array_keys($this->attributes));
- $this->objectlist = $this->koward->server->listHash($this->object_type,
- $params);
+ $class = $this->koward->objects[$this->object_type]['class'];
+ $this->objectlist = $this->koward->server->listHash($class,
+ $params);
foreach ($this->objectlist as $uid => $info) {
$this->objectlist[$uid]['edit_url'] = Horde::link(
$this->urlFor(array('controller' => 'object',
'action' => 'view',
'id' => $uid)), _("View"));
}
- } else {
- $this->objectlist = 'Unkown object type.';
}
+
$this->tabs = new Horde_UI_Tabs(null, Variables::getDefaultVariables());
foreach ($this->koward->objects as $key => $configuration) {
$this->tabs->addTab($configuration['list_label'],
if ($this->form->validate()) {
$object = $this->form->execute();
- header('Location: ' . $this->urlFor(array('controller' => 'object',
- 'action' => 'view',
- 'id' => $object->get(Horde_Koward_Server_Object::ATTRIBUTE_UID))));
- exit;
+ if (!empty($object)) {
+ header('Location: ' . $this->urlFor(array('controller' => 'object',
+ 'action' => 'view',
+ 'id' => $object->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID))));
+ exit;
+ }
}
} catch (Exception $e) {
$this->koward->notification->push($e->getMessage(), 'horde.error');
<?= $this->tabs->render($this->object_type); ?>
+<?php if (isset($this->objectlist)): ?>
+
<table cellspacing="0" width="100%" class="linedRow">
<thead>
<tr>
<?php endforeach; ?>
</tbody>
</table>
+<?php endif; ?>
--- /dev/null
+<?php
+
+$labels['givenName'] = _("First name");
+$labels['middleNames'] = _("Additional names");
+$labels['sn'] = _("Last name");
+$labels['kolabSalutation'] = _("Salutation");
<?php
-$objects['Horde_Kolab_Server_Object'] = array(
+$objects['object'] = array(
+ 'class' => 'Horde_Kolab_Server_Object',
'label' => _("Object"),
'list_label' => _("Objects"),
'attributes' => array(
- 'id' => array(
- 'title' => _("Object id"),
- 'width' => 80,
- 'link_view'=> true,
+ 'override' => true,
+ 'fields' => array(
+ 'id' => array(
+ 'title' => _("Object id"),
+ 'width' => 80,
+ 'link_view'=> true,
+ ),
),
),
);
-$objects['Horde_Kolab_Server_Object_Kolab_User'] = array(
+$objects['user'] = array(
+ 'class' => 'Horde_Kolab_Server_Object_Kolab_User',
'label' => _("User"),
'list_label' => _("Users"),
'attributes' => array(
+ 'override' => true,
+ 'fields' => array(
+ 'sn' => array(
+ 'title' => _("Last name"),
+ 'width' => 20,
+ ),
+ 'givenName' => array(
+ 'title' => _("First name"),
+ 'width' => 20,
+ ),
+ 'mail' => array(
+ 'title' => _("E-mail"),
+ 'width' => 20,
+ 'link_view'=> true,
+ ),
+ 'uid' => array(
+ 'title' => _("User ID"),
+ 'width' => 20,
+ ),
+ ),
+ ),
+);
+
+$objects['admin'] = array(
+ 'class' => 'Horde_Kolab_Server_Object_Kolab_Administrator',
+ 'label' => _("Administrator"),
+ 'list_label' => _("Administrators"),
+ 'attributes' => array(
+ ),
+);
+
+$objects['kolabuser'] = array(
+ 'class' => 'Horde_Kolab_Server_Object_Kolab_User',
+ 'preferred' => true,
+ 'label' => _("Kolab user"),
+ 'list_label' => _("Kolab users"),
+ 'list_attributes' => array(
'sn' => array(
'title' => _("Last name"),
'width' => 20,
'width' => 20,
),
),
-);
-
-$objects['Horde_Kolab_Server_Object_Kolab_Administrator'] = array(
- 'label' => _("Administrator"),
- 'list_label' => _("Administrators"),
'attributes' => array(
+ 'hide' => array(
+ 'objectClass',
+ 'userPassword',
+ 'seeAlso',
+ 'x121Address',
+ 'registeredAddress',
+ 'destinationIndicator',
+ 'preferredDeliveryMethod',
+ 'telexNumber',
+ 'teletexTerminalIdentifier',
+ 'internationaliSDNNumber',
+ 'kolabEncryptedPassword',
+ 'kolabHomeMTA',
+ 'kolabDelegate',
+ ),
+ 'order' => array(
+ 'mail' => 1,
+ 'kolabSalutation' => 2,
+ 'givenName' => 3,
+ 'middleNames' => 4,
+ 'sn' => 5,
+ ),
+ 'labels' => array(
+ 'mail' => _("Account ID"),
+ ),
+ 'fields' => array(
+ 'kolabSalutation' => array(
+ 'label' => _("Salutation"),
+ 'type' => 'enum',
+ 'params' => array('values' => array(_("Mr.") => _("Mr."),
+ _("Mrs.") => _("Mrs.")),
+ 'prompt' => true),
+ ),
+ ),
),
);
parent::Horde_Form($vars);
+ $type = false;
+
if (empty($this->object)) {
$title = _("Add Object");
$this->setButtons(_("Add"));
$vars->get($v->getVarName()) != $vars->get('__old_' . $v->getVarName())) {
$this->koward->notification->push(sprintf(_("Selected object type \"%s\"."), $object_conf[$vars->get('type')]['label']), 'horde.message');
}
+
+ $type = $vars->get('type');
} else {
$title = _("Edit Object");
- $type = get_class($this->object);
+ $class_name = get_class($this->object);
+ foreach ($this->koward->objects as $name => $config) {
+ if ($config['class'] == $class_name) {
+ $type = $name;
+ if (!empty($config['preferred'])) {
+ break;
+ }
+ }
+ }
+ if (empty($type)) {
+ throw new Koward_Exception('Undefined object class!');
+ }
if (!$this->isSubmitted()) {
$vars->set('type', $type);
- $keys = array_keys($this->koward->objects[$type]['attributes']);
+ $keys = array_keys($this->_getFields($this->koward->objects[$type]));
$vars->set('object', $this->object->toHash($keys));
- $this->setButtons(_("Edit"));
+ $this->setButtons(true);
}
}
$this->setTitle($title);
- $type = $vars->get('type');
- if (isset($type)) {
+ if (!empty($type)) {
$this->_addFields($this->koward->objects[$type]);
}
}
/**
+ * Get the fields for an object type
+ */
+ function _getFields($config)
+ {
+ if (isset($config['attributes']['fields']) && !empty($config['attribute']['override'])) {
+ return $config['attributes']['fields'];
+ } else {
+ list($attributes, $attribute_map) = $this->koward->server->getAttributes($config['class']);
+
+ if (isset($config['attributes']['show'])) {
+ $akeys = $config['attributes']['show'];
+ } else {
+ $akeys = array_keys($attributes);
+ if (isset($config['attributes']['hide'])) {
+ $akeys = array_diff($akeys, $config['attributes']['hide']);
+ }
+ }
+
+ foreach ($akeys as $key) {
+ if (isset($config['attributes']['hide'])
+ && in_array($key, $config['attributes']['hide'])) {
+ continue;
+ }
+ if (isset($config['attributes']['fields'][$key])) {
+ $form_attributes[$key] = $config['attributes']['fields'][$key];
+ } else {
+ $form_attributes[$key] = array(
+ 'type' => 'text',
+ 'required' => in_array($key, $attribute_map['required']),
+ 'readonly' => in_array($key, $attribute_map['locked']),
+ 'params' => array('regex' => '', 'size' => 40, 'maxlength' => 255)
+ );
+ }
+ if (isset($config['attributes']['order'][$key])) {
+ $form_attributes[$key]['order'] = $config['attributes']['order'][$key];
+ } else {
+ $form_attributes[$key]['order'] = -1;
+ }
+ if (isset($config['attributes']['labels'][$key])) {
+ $form_attributes[$key]['label'] = $config['attributes']['labels'][$key];
+ } else if (isset($this->koward->labels[$key])) {
+ $form_attributes[$key]['label'] = $this->koward->labels[$key];
+ } else {
+ $form_attributes[$key]['label'] = $key;
+ }
+ }
+ uasort($form_attributes, array($this, '_sortFields'));
+ return $form_attributes;
+ }
+ return array();
+ }
+
+ /**
+ * 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.
- $fields = isset($config['attributes']) ? $config['attributes'] : array();
+ $fields = $this->_getFields($config);
$tabs = isset($config['tabs']) ? $config['tabs'] : array('' => $fields);
foreach ($tabs as $tab => $tab_fields) {
$this->setSection($tab, $tab);
}
foreach ($tab_fields as $key => $field) {
- if (!in_array($key, array_keys($fields)) ||
- !isset($this->koward->attributes[$key])) {
+ if (!in_array($key, array_keys($fields))
+ // || !isset($this->koward->attributes[$key])
+ ) {
continue;
}
-
- $attribute = $this->koward->attributes[$key];
+ $attribute = $field;
+ // $attribute = $this->koward->attributes[$key];
$params = isset($attribute['params']) ? $attribute['params'] : array();
$desc = isset($attribute['desc']) ? $attribute['desc'] : null;
if (isset($info['object'])) {
if (empty($this->object)) {
if (isset($info['type'])) {
- $object = $this->koward->server->add(array_merge(array('type' => $info['type']),
+ if (isset($this->koward->objects[$info['type']]['class'])) {
+ $class = $this->koward->objects[$info['type']]['class'];
+ } else {
+ throw new Koward_Exception(sprintf('Invalid type \"%s\" specified!',
+ $info['type']));
+ }
+ $object = $this->koward->server->add(array_merge(array('type' => $class),
$info['object']));
$this->koward->notification->push(_("Successfully added the object."),
'horde.message');
$this->conf = Horde::loadConfiguration('conf.php', 'conf');
$this->objects = Horde::loadConfiguration('objects.php', 'objects');
$this->attributes = Horde::loadConfiguration('attributes.php', 'attributes');
- $this->server = Horde_Kolab_Server::singleton();
+ $this->labels = Horde::loadConfiguration('labels.php', 'labels');
+ $this->server = Horde_Kolab_Server::singleton(array('user' => Auth::getAuth(),
+ 'pass' => Auth::getCredential('password')));
}
/**