require_once dirname(__FILE__) . '/lib/Application.php';
Horde_Registry::appInit('turba');
-require_once TURBA_BASE . '/lib/Forms/AddContact.php';
-
/* Setup some variables. */
$contact = null;
$vars = Horde_Variables::getDefaultVariables();
}
/* Set up the form. */
-$form = new Turba_AddContactForm($vars, $contact);
+$form = new Turba_Form_AddContact($vars, $contact);
/* Validate the form. */
if ($form->validate()) {
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('turba');
-require_once TURBA_BASE . '/lib/Forms/CreateAddressBook.php';
-
// Exit if this isn't an authenticated user, or if there's no source
// configured for shares.
if (!$GLOBALS['registry']->getAuth() || empty($_SESSION['turba']['has_share'])) {
}
$vars = Horde_Variables::getDefaultVariables();
-$form = new Turba_CreateAddressBookForm($vars);
+$form = new Turba_Form_CreateAddressBook($vars);
// Execute if the form is valid.
if ($form->validate($vars)) {
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('turba');
-require_once TURBA_BASE . '/lib/Forms/DeleteAddressBook.php';
-
// Exit if this isn't an authenticated user, or if there's no source
// configured for shares.
if (!$GLOBALS['registry']->getAuth() || empty($_SESSION['turba']['has_share'])) {
exit;
}
-$form = new Turba_DeleteAddressBookForm($vars, $addressbook);
+$form = new Turba_Form_DeleteAddressBook($vars, $addressbook);
// Execute if the form is valid (must pass with POST variables only).
if ($form->validate(new Horde_Variables($_POST))) {
require_once dirname(__FILE__) . '/../lib/Application.php';
Horde_Registry::appInit('turba');
-require_once TURBA_BASE . '/lib/Forms/EditAddressBook.php';
-
// Exit if this isn't an authenticated user, or if there's no source
// configured for shares.
if (!$GLOBALS['registry']->getAuth() || empty($_SESSION['turba']['has_share'])) {
header('Location: ' . Horde::applicationUrl('addressbooks/', true));
exit;
}
-$form = new Turba_EditAddressBookForm($vars, $addressbook);
+$form = new Turba_Form_EditAddressBook($vars, $addressbook);
// Execute if the form is valid.
if ($form->validate($vars)) {
require_once dirname(__FILE__) . '/lib/Application.php';
Horde_Registry::appInit('turba');
-require_once TURBA_BASE . '/lib/Forms/EditContact.php';
-
$listView = null;
$vars = Horde_Variables::getDefaultVariables();
$source = $vars->get('source');
/* Create the edit form. */
if ($groupedit) {
- $form = new Turba_EditContactGroupForm($vars, $contact);
+ $form = new Turba_Form_EditContactGroup($vars, $contact);
} else {
- $form = new Turba_EditContactForm($vars, $contact);
+ $form = new Turba_Form_EditContact($vars, $contact);
}
/* Execute() checks validation first. */
--- /dev/null
+<?php
+/**
+ * @package Turba
+ */
+class Turba_Form_AddContact extends Turba_Form_Contact
+{
+ var $_contact = null;
+
+ public function __construct(&$vars, &$contact)
+ {
+ global $addSources, $notification;
+
+ parent::Horde_Form($vars, _("Add Contact"));
+ $this->_contact = &$contact;
+
+ $this->setButtons(_("Add"));
+ $this->addHidden('', 'url', 'text', false);
+ $this->addHidden('', 'key', 'text', false);
+
+ /* Check if a source selection box is required. */
+ if (count($addSources) > 1) {
+ /* Multiple sources, show a selection box. */
+ $options = array();
+ foreach ($addSources as $key => $config) {
+ $options[$key] = $config['title'];
+ }
+ $v = &$this->addVariable(_("Choose an address book"), 'source', 'enum', true, false, null, array($options, true));
+ $action = Horde_Form_Action::factory('submit');
+ $v->setAction($action);
+ $v->setOption('trackchange', true);
+ if (is_null($vars->get('formname')) &&
+ $vars->get($v->getVarName()) != $vars->get('__old_' . $v->getVarName())) {
+ $notification->push(sprintf(_("Selected address book \"%s\"."), $addSources[$vars->get('source')]['title']), 'horde.message');
+ }
+ } else {
+ /* One source, no selection box but store the value in a
+ * hidden field. */
+ $this->addHidden('', 'source', 'text', true);
+ }
+
+ if ($this->_contact) {
+ parent::_addFields($this->_contact);
+ }
+ }
+
+ function validate()
+ {
+ if (!$this->_vars->get('source')) {
+ return false;
+ }
+ return parent::validate($this->_vars);
+ }
+
+ function execute()
+ {
+ global $driver, $notification;
+
+ /* Form valid, save data. */
+ $this->getInfo($this->_vars, $info);
+ $source = $info['source'];
+ foreach ($info['object'] as $info_key => $info_val) {
+ if ($GLOBALS['attributes'][$info_key]['type'] == 'image' && !empty($info_val['file'])) {
+ $this->_contact->setValue($info_key, file_get_contents($info_val['file']));
+ $this->_contact->setValue($info_key . 'type', $info_val['type']);
+ } else {
+ $this->_contact->setValue($info_key, $info_val);
+ }
+ }
+ $contact = $this->_contact->attributes;
+ unset($contact['__owner']);
+
+ /* Create Contact. */
+ $key = $driver->add($contact);
+ if (is_a($key, 'PEAR_Error')) {
+ Horde::logMessage($key, 'ERR');
+ } else {
+ // Try 3 times to get the new entry. We retry to allow setups like
+ // LDAP replication to work.
+ for ($i = 0; $i < 3; $i++) {
+ $ob = $driver->getObject($key);
+ if (!is_a($ob, 'PEAR_Error')) {
+ $notification->push(sprintf(_("%s added."), $ob->getValue('name')), 'horde.success');
+ header('Location: ' . (!empty($info['url']) ? $info['url'] : $ob->url('Contact', true)));
+ exit;
+ }
+ sleep(1);
+ }
+ Horde::logMessage($ob, 'ERR');
+ }
+
+ $notification->push(_("There was an error adding the new contact. Contact your system administrator for further help."), 'horde.error');
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * @package Turba
+ */
+class Turba_Form_Contact extends Horde_Form
+{
+ public function __construct(&$vars, &$contact)
+ {
+ global $conf, $notification;
+
+ parent::__construct($vars, '', 'Turba_View_Contact');
+
+ /* Get the values through the Turba_Object class. */
+ $object = array();
+ foreach ($contact->driver->getCriteria() as $info_key => $info_val) {
+ $object[$info_key] = $contact->getValue($info_key);
+ }
+ $vars->set('object', $object);
+
+ $this->_addFields($contact);
+
+ /* List files. */
+ $v_params = $GLOBALS['injector']->getInstance('Horde_Vfs')->getConfig('documents');
+ if ($v_params['type'] != 'none') {
+ $files = $contact->listFiles();
+ if (is_a($files, 'PEAR_Error')) {
+ $notification->push($files, 'horde.error');
+ } else {
+ $this->addVariable(_("Files"), '__vfs', 'html', false);
+ $vars->set('__vfs', implode('<br />', array_map(array($contact, 'vfsEditUrl'), $files)));
+ }
+ }
+ }
+
+ /**
+ * Set up the Horde_Form fields for $contact's attributes.
+ */
+ function _addFields($contact)
+ {
+ global $attributes;
+
+ // Run through once to see what form actions, if any, we need
+ // to set up.
+ $actions = array();
+ $map = $contact->driver->map;
+ $fields = array_keys($contact->driver->getCriteria());
+ foreach ($fields as $field) {
+ if (is_array($map[$field])) {
+ foreach ($map[$field]['fields'] as $action_field) {
+ if (!isset($actions[$action_field])) {
+ $actions[$action_field] = array();
+ }
+ $actions[$action_field]['fields'] = $map[$field]['fields'];
+ $actions[$action_field]['format'] = $map[$field]['format'];
+ $actions[$action_field]['target'] = $field;
+ }
+ }
+ }
+
+ // Now run through and add the form variables.
+ $tabs = $contact->driver->tabs;
+ if (!count($tabs)) {
+ $tabs = array('' => $fields);
+ }
+ foreach ($tabs as $tab => $tab_fields) {
+ if (!empty($tab)) {
+ $this->setSection($tab, $tab);
+ }
+ foreach ($tab_fields as $field) {
+ if (!in_array($field, $fields) ||
+ !isset($attributes[$field])) {
+ continue;
+ }
+
+ $attribute = $attributes[$field];
+ $params = isset($attribute['params']) ? $attribute['params'] : array();
+ $desc = isset($attribute['desc']) ? $attribute['desc'] : null;
+
+ if (is_array($map[$field])) {
+ $v = &$this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], false, false, $desc, $params);
+ $v->disable();
+ } else {
+ $readonly = isset($attribute['readonly']) ? $attribute['readonly'] : null;
+ $v = &$this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], $attribute['required'], $readonly, $desc, $params);
+
+ if (!empty($actions[$field])) {
+ $actionfields = array();
+ foreach ($actions[$field]['fields'] as $f) {
+ $actionfields[] = 'object[' . $f . ']';
+ }
+ $a = Horde_Form_Action::factory('updatefield',
+ array('format' => $actions[$field]['format'],
+ 'target' => 'object[' . $actions[$field]['target'] . ']',
+ 'fields' => $actionfields));
+ $v->setAction($a);
+ }
+ }
+
+ if (isset($attribute['default'])) {
+ $v->setDefault($attribute['default']);
+ }
+ }
+ }
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Horde_Form for creating address books.
+ *
+ * See the enclosed file LICENSE for license information (ASL). If you
+ * did not receive this file, see http://www.horde.org/licenses/asl.php.
+ *
+ * @package Turba
+ */
+
+/**
+ * The Turba_Form_CreateAddressBook class provides the form for
+ * creating an address book.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @package Turba
+ */
+class Turba_Form_CreateAddressBook extends Horde_Form
+{
+ public function __construct(&$vars)
+ {
+ parent::__construct($vars, _("Create Address Book"));
+
+ $this->addVariable(_("Name"), 'name', 'text', true);
+ $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
+
+ $this->setButtons(array(_("Create")));
+ }
+
+ function execute()
+ {
+ // Need a clean cfgSources array
+ include TURBA_BASE . '/config/sources.php';
+
+ $driver = Turba_Driver::singleton($cfgSources[$GLOBALS['conf']['shares']['source']]);
+ if ($driver instanceof PEAR_Error) {
+ return $driver;
+ }
+
+ $params = array(
+ 'params' => array('source' => $GLOBALS['conf']['shares']['source']),
+ 'name' => $this->_vars->get('name'),
+ 'desc' => $this->_vars->get('description'),
+ );
+ return $driver->createShare(md5(mt_rand()), $params);
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Horde_Form for deleting address books.
+ *
+ * See the enclosed file LICENSE for license information (ASL). If you
+ * did not receive this file, see http://www.horde.org/licenses/asl.php.
+ *
+ * @package Turba
+ */
+
+/**
+ * The Turba_Form_DeleteAddressbook class provides the form for
+ * deleting an address book.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @package Turba
+ */
+class Turba_Form_DeleteAddressBook extends Horde_Form
+{
+ /**
+ * Address book being deleted
+ */
+ var $_addressbook;
+
+ public function __construct(&$vars, &$addressbook)
+ {
+ $this->_addressbook = &$addressbook;
+ parent::__construct($vars, sprintf(_("Delete %s"), $addressbook->get('name')));
+
+ $this->addHidden('', 'a', 'text', true);
+ $this->addVariable(sprintf(_("Really delete the address book \"%s\"? This cannot be undone and all contacts in this address book will be permanently removed."), $this->_addressbook->get('name')), 'desc', 'description', false);
+
+ $this->setButtons(array(_("Delete"), _("Cancel")));
+ }
+
+ /**
+ * @TODO Remove share from 'addressbooks' pref
+ */
+ function execute()
+ {
+ // If cancel was clicked, return false.
+ if ($this->_vars->get('submitbutton') == _("Cancel")) {
+ return false;
+ }
+
+ if (!$GLOBALS['registry']->getAuth() ||
+ $this->_addressbook->get('owner') != $GLOBALS['registry']->getAuth()) {
+ return PEAR::raiseError(_("You do not have permissions to delete this address book."));
+ }
+
+ $driver = &Turba_Driver::singleton($this->_addressbook->getName());
+ if (is_a($driver, 'PEAR_Error')) {
+ return $driver;
+ }
+
+ // We have a Turba_Driver, try to delete the address book.
+ $result = $driver->deleteAll();
+ if (is_a($result, 'PEAR_Error')) {
+ return $result;
+ }
+
+ // Address book successfully deleted from backend, remove the
+ // share.
+ try {
+ $GLOBALS['turba_shares']->removeShare($this->_addressbook);
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ throw new Turba_Exception($e);
+ }
+
+ if (isset($_SESSION['turba']['source']) && $_SESSION['turba']['source'] == Horde_Util::getFormData('deleteshare')) {
+ unset($_SESSION['turba']['source']);
+ }
+
+ $abooks = json_decode($GLOBALS['prefs']->getValue('addressbooks'));
+ if (($pos = array_search($this->_addressbook->getName(), $abooks)) !== false) {
+ unset($abooks[$pos]);
+ $GLOBALS['prefs']->setValue('addressbooks', json_encode($abooks));
+ }
+
+ return true;
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Horde_Form for editing address books.
+ *
+ * See the enclosed file LICENSE for license information (ASL). If you
+ * did not receive this file, see http://www.horde.org/licenses/asl.php.
+ *
+ * @package Turba
+ */
+
+/**
+ * The Turba_Form_EditAddressBook class provides the form for
+ * editing an address book.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @package Turba
+ */
+class Turba_Form_EditAddressBook extends Horde_Form
+{
+ /**
+ * Address book being edited
+ */
+ var $_addressbook;
+
+ public function __construct(&$vars, &$addressbook)
+ {
+ $this->_addressbook = &$addressbook;
+ parent::__construct($vars, sprintf(_("Edit %s"), $addressbook->get('name')));
+
+ $this->addHidden('', 'a', 'text', true);
+ $this->addVariable(_("Name"), 'name', 'text', true);
+ $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
+
+ $this->setButtons(array(_("Save")));
+ }
+
+ function execute()
+ {
+ $this->_addressbook->set('name', $this->_vars->get('name'));
+ $this->_addressbook->set('desc', $this->_vars->get('description'));
+ $result = $this->_addressbook->save();
+ if (is_a($result, 'PEAR_Error')) {
+ return PEAR::raiseError(sprintf(_("Unable to save address book \"%s\": %s"), $id, $result->getMessage()));
+ }
+ return true;
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * @package Turba
+ */
+class Turba_Form_EditContact extends Turba_Form_Contact
+{
+ var $_source;
+ var $_contact;
+
+ public function __construct(&$vars, &$contact)
+ {
+ global $conf;
+
+ parent::Horde_Form($vars, '', 'Turba_View_EditContact');
+ $this->_contact = &$contact;
+
+ $this->setButtons(_("Save"));
+ $this->addHidden('', 'url', 'text', false);
+ $this->addHidden('', 'source', 'text', true);
+ $this->addHidden('', 'key', 'text', false);
+
+ parent::_addFields($this->_contact);
+
+ if ($conf['documents']['type'] != 'none') {
+ $this->addVariable(_("Add file"), 'vfs', 'file', false);
+ }
+
+ $object_values = $vars->get('object');
+ $object_keys = array_keys($contact->attributes);
+ foreach ($object_keys as $info_key) {
+ if (!isset($object_values[$info_key])) {
+ $object_values[$info_key] = $contact->getValue($info_key);
+ }
+ }
+ $vars->set('object', $object_values);
+ $vars->set('source', $contact->getSource());
+ }
+
+ function getSource()
+ {
+ return $this->_source;
+ }
+
+ function execute()
+ {
+ global $conf, $notification;
+
+ if (!$this->validate($this->_vars)) {
+ return PEAR::raiseError('Invalid');
+ }
+
+ /* Form valid, save data. */
+ $this->getInfo($this->_vars, $info);
+
+ /* Update the contact. */
+ foreach ($info['object'] as $info_key => $info_val) {
+ if ($info_key != '__key') {
+ if ($GLOBALS['attributes'][$info_key]['type'] == 'image' && !empty($info_val['file'])) {
+ $this->_contact->setValue($info_key, file_get_contents($info_val['file']));
+ if (isset($info_val['type'])) {
+ $this->_contact->setValue($info_key . 'type', $info_val['type']);
+ }
+ } else {
+ $this->_contact->setValue($info_key, $info_val);
+ }
+ }
+ }
+
+ $result = $this->_contact->store();
+ if (!is_a($result, 'PEAR_Error')) {
+ if ($conf['documents']['type'] != 'none' && isset($info['vfs'])) {
+ $result = $this->_contact->addFile($info['vfs']);
+ if (is_a($result, 'PEAR_Error')) {
+ $notification->push(sprintf(_("\"%s\" updated, but saving the uploaded file failed: %s"), $this->_contact->getValue('name'), $result->getMessage()), 'horde.warning');
+ } else {
+ $notification->push(sprintf(_("\"%s\" updated."), $this->_contact->getValue('name')), 'horde.success');
+ }
+ } else {
+ $notification->push(sprintf(_("\"%s\" updated."), $this->_contact->getValue('name')), 'horde.success');
+ }
+ return true;
+ } else {
+ Horde::logMessage($result, 'ERR');
+ $notification->push(_("There was an error saving the contact. Contact your system administrator for further help."), 'horde.error');
+ return $result;
+ }
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * @package Turba
+ */
+class Turba_Form_EditContactGroup extends Turba_Form_EditContact
+{
+ public function __construct(&$vars, &$contact)
+ {
+ $this->addHidden('', 'objectkeys', 'text', false);
+ $this->addHidden('', 'original_source', 'text', false);
+ $this->addHidden('', 'actionID', 'text', false);
+
+ parent::Turba_Form_EditContact($vars, $contact);
+ $vars->set('actionID', 'groupedit');
+
+ $objectkeys = $vars->get('objectkeys');
+ $source = $vars->get('source');
+ $key = $vars->get('key');
+ if ($source . ':' . $key == $objectkeys[0]) {
+ /* First contact */
+ $this->setButtons(_("Next"));
+ } elseif ($source . ':' . $key == $objectkeys[count($objectkeys) - 1]) {
+ /* Last contact */
+ $this->setButtons(_("Previous"));
+ } else {
+ /* In between */
+ $this->setButtons(_("Previous"));
+ $this->appendButtons(_("Next"));
+ }
+ $this->appendButtons(_("Finish"));
+ }
+
+ function renderActive($renderer, &$vars, $action, $method)
+ {
+ parent::renderActive($renderer, $vars, $action, $method);
+
+ /* Read the columns to display from the preferences. */
+ $source = $vars->get('source');
+ $sources = Turba::getColumns();
+ $columns = isset($sources[$source]) ? $sources[$source] : array();
+
+ $results = new Turba_List($vars->get('objectkeys'));
+ $listView = new Turba_View_List($results, array('Group' => true), $columns);
+ echo '<br />' . $listView->getPage($numDisplayed);
+ }
+
+ function execute()
+ {
+ $result = parent::execute();
+ if (is_a($result, 'PEAR_Error')) {
+ return $result;
+ }
+
+ $this->getInfo($this->_vars, $info);
+
+ $next_page = Horde::applicationUrl('edit.php', true);
+ $next_page = Horde_Util::addParameter($next_page,
+ array('source' => $info['source'],
+ 'original_source' => $info['original_source'],
+ 'objectkeys' => $info['objectkeys'],
+ 'url' => $info['url'],
+ 'actionID' => 'groupedit'),
+ null, false);
+ $objectkey = array_search($info['source'] . ':' . $info['key'], $info['objectkeys']);
+
+ $submitbutton = $this->_vars->get('submitbutton');
+ if ($submitbutton == _("Finish")) {
+ $next_page = Horde::url('browse.php', true);
+ if ($info['original_source'] == '**search') {
+ $next_page = Horde_Util::addParameter($next_page, 'key', $info['original_source'], false);
+ } else {
+ $next_page = Horde_Util::addParameter($next_page, 'source', $info['original_source'], false);
+ }
+ } elseif ($submitbutton == _("Previous") && $info['source'] . ':' . $info['key'] != $info['objectkeys'][0]) {
+ /* Previous contact */
+ list(, $previous_key) = explode(':', $info['objectkeys'][$objectkey - 1]);
+ $next_page = Horde_Util::addParameter($next_page, 'key', $previous_key, false);
+ if ($this->getOpenSection()) {
+ $next_page = Horde_Util::addParameter($next_page, '__formOpenSection', $this->getOpenSection(), false);
+ }
+ } elseif ($submitbutton == _("Next") &&
+ $info['source'] . ':' . $info['key'] != $info['objectkeys'][count($info['objectkeys']) - 1]) {
+ /* Next contact */
+ list(, $next_key) = explode(':', $info['objectkeys'][$objectkey + 1]);
+ $next_page = Horde_Util::addParameter($next_page, 'key', $next_key, false);
+ if ($this->getOpenSection()) {
+ $next_page = Horde_Util::addParameter($next_page, '__formOpenSection', $this->getOpenSection(), false);
+ }
+ }
+
+ header('Location: ' . $next_page);
+ exit;
+ }
+
+}
+++ /dev/null
-<?php
-/**
- * @package Turba
- */
-
-/** Turba_ContactForm */
-require_once dirname(__FILE__) . '/Contact.php';
-
-/**
- * @package Turba
- */
-class Turba_AddContactForm extends Turba_ContactForm {
-
- var $_contact = null;
-
- function Turba_AddContactForm(&$vars, &$contact)
- {
- global $addSources, $notification;
-
- parent::Horde_Form($vars, _("Add Contact"));
- $this->_contact = &$contact;
-
- $this->setButtons(_("Add"));
- $this->addHidden('', 'url', 'text', false);
- $this->addHidden('', 'key', 'text', false);
-
- /* Check if a source selection box is required. */
- if (count($addSources) > 1) {
- /* Multiple sources, show a selection box. */
- $options = array();
- foreach ($addSources as $key => $config) {
- $options[$key] = $config['title'];
- }
- $v = &$this->addVariable(_("Choose an address book"), 'source', 'enum', true, false, null, array($options, true));
- $action = Horde_Form_Action::factory('submit');
- $v->setAction($action);
- $v->setOption('trackchange', true);
- if (is_null($vars->get('formname')) &&
- $vars->get($v->getVarName()) != $vars->get('__old_' . $v->getVarName())) {
- $notification->push(sprintf(_("Selected address book \"%s\"."), $addSources[$vars->get('source')]['title']), 'horde.message');
- }
- } else {
- /* One source, no selection box but store the value in a
- * hidden field. */
- $this->addHidden('', 'source', 'text', true);
- }
-
- if ($this->_contact) {
- parent::_addFields($this->_contact);
- }
- }
-
- function validate()
- {
- if (!$this->_vars->get('source')) {
- return false;
- }
- return parent::validate($this->_vars);
- }
-
- function execute()
- {
- global $driver, $notification;
-
- /* Form valid, save data. */
- $this->getInfo($this->_vars, $info);
- $source = $info['source'];
- foreach ($info['object'] as $info_key => $info_val) {
- if ($GLOBALS['attributes'][$info_key]['type'] == 'image' && !empty($info_val['file'])) {
- $this->_contact->setValue($info_key, file_get_contents($info_val['file']));
- $this->_contact->setValue($info_key . 'type', $info_val['type']);
- } else {
- $this->_contact->setValue($info_key, $info_val);
- }
- }
- $contact = $this->_contact->attributes;
- unset($contact['__owner']);
-
- /* Create Contact. */
- $key = $driver->add($contact);
- if (is_a($key, 'PEAR_Error')) {
- Horde::logMessage($key, 'ERR');
- } else {
- // Try 3 times to get the new entry. We retry to allow setups like
- // LDAP replication to work.
- for ($i = 0; $i < 3; $i++) {
- $ob = $driver->getObject($key);
- if (!is_a($ob, 'PEAR_Error')) {
- $notification->push(sprintf(_("%s added."), $ob->getValue('name')), 'horde.success');
- header('Location: ' . (!empty($info['url']) ? $info['url'] : $ob->url('Contact', true)));
- exit;
- }
- sleep(1);
- }
- Horde::logMessage($ob, 'ERR');
- }
-
- $notification->push(_("There was an error adding the new contact. Contact your system administrator for further help."), 'horde.error');
- }
-
-}
+++ /dev/null
-<?php
-/**
- * @package Turba
- */
-
-/** Horde_Form_Action */
-require_once 'Horde/Form/Action.php';
-
-/**
- * @package Turba
- */
-class Turba_ContactForm extends Horde_Form {
-
- function Turba_ContactForm(&$vars, &$contact)
- {
- global $conf, $notification;
-
- parent::Horde_Form($vars, '', 'Turba_View_Contact');
-
- /* Get the values through the Turba_Object class. */
- $object = array();
- foreach ($contact->driver->getCriteria() as $info_key => $info_val) {
- $object[$info_key] = $contact->getValue($info_key);
- }
- $vars->set('object', $object);
-
- $this->_addFields($contact);
-
- /* List files. */
- $v_params = $GLOBALS['injector']->getInstance('Horde_Vfs')->getConfig('documents');
- if ($v_params['type'] != 'none') {
- $files = $contact->listFiles();
- if (is_a($files, 'PEAR_Error')) {
- $notification->push($files, 'horde.error');
- } else {
- $this->addVariable(_("Files"), '__vfs', 'html', false);
- $vars->set('__vfs', implode('<br />', array_map(array($contact, 'vfsEditUrl'), $files)));
- }
- }
- }
-
- /**
- * Set up the Horde_Form fields for $contact's attributes.
- */
- function _addFields($contact)
- {
- global $attributes;
-
- // Run through once to see what form actions, if any, we need
- // to set up.
- $actions = array();
- $map = $contact->driver->map;
- $fields = array_keys($contact->driver->getCriteria());
- foreach ($fields as $field) {
- if (is_array($map[$field])) {
- foreach ($map[$field]['fields'] as $action_field) {
- if (!isset($actions[$action_field])) {
- $actions[$action_field] = array();
- }
- $actions[$action_field]['fields'] = $map[$field]['fields'];
- $actions[$action_field]['format'] = $map[$field]['format'];
- $actions[$action_field]['target'] = $field;
- }
- }
- }
-
- // Now run through and add the form variables.
- $tabs = $contact->driver->tabs;
- if (!count($tabs)) {
- $tabs = array('' => $fields);
- }
- foreach ($tabs as $tab => $tab_fields) {
- if (!empty($tab)) {
- $this->setSection($tab, $tab);
- }
- foreach ($tab_fields as $field) {
- if (!in_array($field, $fields) ||
- !isset($attributes[$field])) {
- continue;
- }
-
- $attribute = $attributes[$field];
- $params = isset($attribute['params']) ? $attribute['params'] : array();
- $desc = isset($attribute['desc']) ? $attribute['desc'] : null;
-
- if (is_array($map[$field])) {
- $v = &$this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], false, false, $desc, $params);
- $v->disable();
- } else {
- $readonly = isset($attribute['readonly']) ? $attribute['readonly'] : null;
- $v = &$this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], $attribute['required'], $readonly, $desc, $params);
-
- if (!empty($actions[$field])) {
- $actionfields = array();
- foreach ($actions[$field]['fields'] as $f) {
- $actionfields[] = 'object[' . $f . ']';
- }
- $a = Horde_Form_Action::factory('updatefield',
- array('format' => $actions[$field]['format'],
- 'target' => 'object[' . $actions[$field]['target'] . ']',
- 'fields' => $actionfields));
- $v->setAction($a);
- }
- }
-
- if (isset($attribute['default'])) {
- $v->setDefault($attribute['default']);
- }
- }
- }
- }
-
-}
+++ /dev/null
-<?php
-/**
- * Horde_Form for creating address books.
- *
- * See the enclosed file LICENSE for license information (ASL). If you
- * did not receive this file, see http://www.horde.org/licenses/asl.php.
- *
- * @package Turba
- */
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
-/**
- * The Turba_CreateAddressBookForm class provides the form for
- * creating an address book.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package Turba
- */
-class Turba_CreateAddressBookForm extends Horde_Form {
-
- function Turba_CreateAddressBookForm(&$vars)
- {
- parent::Horde_Form($vars, _("Create Address Book"));
-
- $this->addVariable(_("Name"), 'name', 'text', true);
- $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
-
- $this->setButtons(array(_("Create")));
- }
-
- function execute()
- {
- // Need a clean cfgSources array
- include TURBA_BASE . '/config/sources.php';
-
- $driver = Turba_Driver::singleton($cfgSources[$GLOBALS['conf']['shares']['source']]);
- if ($driver instanceof PEAR_Error) {
- return $driver;
- }
-
- $params = array(
- 'params' => array('source' => $GLOBALS['conf']['shares']['source']),
- 'name' => $this->_vars->get('name'),
- 'desc' => $this->_vars->get('description'),
- );
- return $driver->createShare(md5(mt_rand()), $params);
- }
-
-}
+++ /dev/null
-<?php
-/**
- * Horde_Form for deleting address books.
- *
- * See the enclosed file LICENSE for license information (ASL). If you
- * did not receive this file, see http://www.horde.org/licenses/asl.php.
- *
- * @package Turba
- */
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
-/**
- * The Turba_DeleteAddressbookForm class provides the form for
- * deleting an address book.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package Turba
- */
-class Turba_DeleteAddressBookForm extends Horde_Form {
-
- /**
- * Address book being deleted
- */
- var $_addressbook;
-
- function Turba_DeleteAddressBookForm(&$vars, &$addressbook)
- {
- $this->_addressbook = &$addressbook;
- parent::Horde_Form($vars, sprintf(_("Delete %s"), $addressbook->get('name')));
-
- $this->addHidden('', 'a', 'text', true);
- $this->addVariable(sprintf(_("Really delete the address book \"%s\"? This cannot be undone and all contacts in this address book will be permanently removed."), $this->_addressbook->get('name')), 'desc', 'description', false);
-
- $this->setButtons(array(_("Delete"), _("Cancel")));
- }
-
- /**
- * @TODO Remove share from 'addressbooks' pref
- */
- function execute()
- {
- // If cancel was clicked, return false.
- if ($this->_vars->get('submitbutton') == _("Cancel")) {
- return false;
- }
-
- if (!$GLOBALS['registry']->getAuth() ||
- $this->_addressbook->get('owner') != $GLOBALS['registry']->getAuth()) {
- return PEAR::raiseError(_("You do not have permissions to delete this address book."));
- }
-
- $driver = &Turba_Driver::singleton($this->_addressbook->getName());
- if (is_a($driver, 'PEAR_Error')) {
- return $driver;
- }
-
- // We have a Turba_Driver, try to delete the address book.
- $result = $driver->deleteAll();
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
-
- // Address book successfully deleted from backend, remove the
- // share.
- try {
- $GLOBALS['turba_shares']->removeShare($this->_addressbook);
- } catch (Horde_Share_Exception $e) {
- Horde::logMessage($e->getMessage(), 'ERR');
- throw new Turba_Exception($e);
- }
-
- if (isset($_SESSION['turba']['source']) && $_SESSION['turba']['source'] == Horde_Util::getFormData('deleteshare')) {
- unset($_SESSION['turba']['source']);
- }
-
- $abooks = json_decode($GLOBALS['prefs']->getValue('addressbooks'));
- if (($pos = array_search($this->_addressbook->getName(), $abooks)) !== false) {
- unset($abooks[$pos]);
- $GLOBALS['prefs']->setValue('addressbooks', json_encode($abooks));
- }
-
- return true;
- }
-
-}
+++ /dev/null
-<?php
-/**
- * Horde_Form for editing address books.
- *
- * See the enclosed file LICENSE for license information (ASL). If you
- * did not receive this file, see http://www.horde.org/licenses/asl.php.
- *
- * @package Turba
- */
-
-/** Horde_Form_Renderer */
-require_once 'Horde/Form/Renderer.php';
-
-/**
- * The Turba_EditAddressBookForm class provides the form for
- * editing an address book.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package Turba
- */
-class Turba_EditAddressBookForm extends Horde_Form {
-
- /**
- * Address book being edited
- */
- var $_addressbook;
-
- function Turba_EditAddressBookForm(&$vars, &$addressbook)
- {
- $this->_addressbook = &$addressbook;
- parent::Horde_Form($vars, sprintf(_("Edit %s"), $addressbook->get('name')));
-
- $this->addHidden('', 'a', 'text', true);
- $this->addVariable(_("Name"), 'name', 'text', true);
- $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
-
- $this->setButtons(array(_("Save")));
- }
-
- function execute()
- {
- $this->_addressbook->set('name', $this->_vars->get('name'));
- $this->_addressbook->set('desc', $this->_vars->get('description'));
- $result = $this->_addressbook->save();
- if (is_a($result, 'PEAR_Error')) {
- return PEAR::raiseError(sprintf(_("Unable to save address book \"%s\": %s"), $id, $result->getMessage()));
- }
- return true;
- }
-
-}
+++ /dev/null
-<?php
-/**
- * @package Turba
- */
-
-/** Turba_ContactForm */
-require_once dirname(__FILE__) . '/Contact.php';
-
-/**
- * @package Turba
- */
-class Turba_EditContactForm extends Turba_ContactForm {
-
- var $_source;
- var $_contact;
-
- function Turba_EditContactForm(&$vars, &$contact)
- {
- global $conf;
-
- parent::Horde_Form($vars, '', 'Turba_View_EditContact');
- $this->_contact = &$contact;
-
- $this->setButtons(_("Save"));
- $this->addHidden('', 'url', 'text', false);
- $this->addHidden('', 'source', 'text', true);
- $this->addHidden('', 'key', 'text', false);
-
- parent::_addFields($this->_contact);
-
- if ($conf['documents']['type'] != 'none') {
- $this->addVariable(_("Add file"), 'vfs', 'file', false);
- }
-
- $object_values = $vars->get('object');
- $object_keys = array_keys($contact->attributes);
- foreach ($object_keys as $info_key) {
- if (!isset($object_values[$info_key])) {
- $object_values[$info_key] = $contact->getValue($info_key);
- }
- }
- $vars->set('object', $object_values);
- $vars->set('source', $contact->getSource());
- }
-
- function getSource()
- {
- return $this->_source;
- }
-
- function execute()
- {
- global $conf, $notification;
-
- if (!$this->validate($this->_vars)) {
- return PEAR::raiseError('Invalid');
- }
-
- /* Form valid, save data. */
- $this->getInfo($this->_vars, $info);
-
- /* Update the contact. */
- foreach ($info['object'] as $info_key => $info_val) {
- if ($info_key != '__key') {
- if ($GLOBALS['attributes'][$info_key]['type'] == 'image' && !empty($info_val['file'])) {
- $this->_contact->setValue($info_key, file_get_contents($info_val['file']));
- if (isset($info_val['type'])) {
- $this->_contact->setValue($info_key . 'type', $info_val['type']);
- }
- } else {
- $this->_contact->setValue($info_key, $info_val);
- }
- }
- }
-
- $result = $this->_contact->store();
- if (!is_a($result, 'PEAR_Error')) {
- if ($conf['documents']['type'] != 'none' && isset($info['vfs'])) {
- $result = $this->_contact->addFile($info['vfs']);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push(sprintf(_("\"%s\" updated, but saving the uploaded file failed: %s"), $this->_contact->getValue('name'), $result->getMessage()), 'horde.warning');
- } else {
- $notification->push(sprintf(_("\"%s\" updated."), $this->_contact->getValue('name')), 'horde.success');
- }
- } else {
- $notification->push(sprintf(_("\"%s\" updated."), $this->_contact->getValue('name')), 'horde.success');
- }
- return true;
- } else {
- Horde::logMessage($result, 'ERR');
- $notification->push(_("There was an error saving the contact. Contact your system administrator for further help."), 'horde.error');
- return $result;
- }
- }
-
-}
-
-/**
- * @package Turba
- */
-class Turba_EditContactGroupForm extends Turba_EditContactForm {
-
- function Turba_EditContactGroupForm(&$vars, &$contact)
- {
- $this->addHidden('', 'objectkeys', 'text', false);
- $this->addHidden('', 'original_source', 'text', false);
- $this->addHidden('', 'actionID', 'text', false);
-
- parent::Turba_EditContactForm($vars, $contact);
- $vars->set('actionID', 'groupedit');
-
- $objectkeys = $vars->get('objectkeys');
- $source = $vars->get('source');
- $key = $vars->get('key');
- if ($source . ':' . $key == $objectkeys[0]) {
- /* First contact */
- $this->setButtons(_("Next"));
- } elseif ($source . ':' . $key == $objectkeys[count($objectkeys) - 1]) {
- /* Last contact */
- $this->setButtons(_("Previous"));
- } else {
- /* In between */
- $this->setButtons(_("Previous"));
- $this->appendButtons(_("Next"));
- }
- $this->appendButtons(_("Finish"));
- }
-
- function renderActive($renderer, &$vars, $action, $method)
- {
- parent::renderActive($renderer, $vars, $action, $method);
-
- /* Read the columns to display from the preferences. */
- $source = $vars->get('source');
- $sources = Turba::getColumns();
- $columns = isset($sources[$source]) ? $sources[$source] : array();
-
- $results = new Turba_List($vars->get('objectkeys'));
- $listView = new Turba_View_List($results, array('Group' => true), $columns);
- echo '<br />' . $listView->getPage($numDisplayed);
- }
-
- function execute()
- {
- $result = parent::execute();
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
-
- $this->getInfo($this->_vars, $info);
-
- $next_page = Horde::applicationUrl('edit.php', true);
- $next_page = Horde_Util::addParameter($next_page,
- array('source' => $info['source'],
- 'original_source' => $info['original_source'],
- 'objectkeys' => $info['objectkeys'],
- 'url' => $info['url'],
- 'actionID' => 'groupedit'),
- null, false);
- $objectkey = array_search($info['source'] . ':' . $info['key'], $info['objectkeys']);
-
- $submitbutton = $this->_vars->get('submitbutton');
- if ($submitbutton == _("Finish")) {
- $next_page = Horde::url('browse.php', true);
- if ($info['original_source'] == '**search') {
- $next_page = Horde_Util::addParameter($next_page, 'key', $info['original_source'], false);
- } else {
- $next_page = Horde_Util::addParameter($next_page, 'source', $info['original_source'], false);
- }
- } elseif ($submitbutton == _("Previous") && $info['source'] . ':' . $info['key'] != $info['objectkeys'][0]) {
- /* Previous contact */
- list(, $previous_key) = explode(':', $info['objectkeys'][$objectkey - 1]);
- $next_page = Horde_Util::addParameter($next_page, 'key', $previous_key, false);
- if ($this->getOpenSection()) {
- $next_page = Horde_Util::addParameter($next_page, '__formOpenSection', $this->getOpenSection(), false);
- }
- } elseif ($submitbutton == _("Next") &&
- $info['source'] . ':' . $info['key'] != $info['objectkeys'][count($info['objectkeys']) - 1]) {
- /* Next contact */
- list(, $next_key) = explode(':', $info['objectkeys'][$objectkey + 1]);
- $next_page = Horde_Util::addParameter($next_page, 'key', $next_key, false);
- if ($this->getOpenSection()) {
- $next_page = Horde_Util::addParameter($next_page, '__formOpenSection', $this->getOpenSection(), false);
- }
- }
-
- header('Location: ' . $next_page);
- exit;
- }
-
-}
<?php
-/** Turba_ContactForm */
-require_once TURBA_BASE . '/lib/Forms/Contact.php';
-
/**
* The Turba_View_Contact:: class provides an API for viewing events.
*
}
$vars = new Horde_Variables();
- $form = new Turba_ContactForm($vars, $this->contact);
+ $form = new Turba_Form_Contact($vars, $this->contact);
$userId = $GLOBALS['registry']->getAuth();
/* Get the contact's history. */
<?php
-/** Turba_EditContactForm */
-require_once TURBA_BASE . '/lib/Forms/EditContact.php';
-
/**
* The Turba_View_EditContact:: class provides an API for viewing events.
*
}
echo '<div id="EditContact"' . ($active ? '' : ' style="display:none"') . '>';
- $form = &new Turba_EditContactForm($vars, $this->contact);
+ $form = &new Turba_Form_EditContact($vars, $this->contact);
$form->renderActive(new Horde_Form_Renderer, $vars, 'edit.php', 'post');
echo '</div>';