* * See the enclosed file COPYING for license information (GPL). If you did not * receive this file, see http://www.fsf.org/copyleft/gpl.html. */ define('TURBA_BASE', dirname(__FILE__)); require_once TURBA_BASE . '/lib/base.php'; require_once HORDE_LIBS . 'Horde/Form.php'; require_once TURBA_BASE . '/lib/Renderer.php'; require_once TURBA_BASE . '/lib/Source.php'; require_once TURBA_BASE . '/lib/ObjectView.php'; require_once HORDE_LIBS . 'Horde/Variables.php'; $renderer = &new Turba_Renderer(); $vars = &Variables::getDefaultVariables(); $url = $vars->get('url'); $source = $vars->get('source'); if ($source === null || !isset($cfgSources[$source])) { $notification->push(_("The contact you requested does not exist.")); header('Location: ' . Horde::applicationUrl($prefs->getValue('initial_page'), true)); exit; } $driver = &Turba_Source::singleton($source, $cfgSources[$source]); /* Set the contact from the key requested. */ $key = $vars->get('key'); $object = $driver->getObject($key); if (is_a($object, 'PEAR_Error')) { $notification->push($object->getMessage(), 'horde.error'); header('Location: ' . Horde::applicationUrl($prefs->getValue('initial_page'), true)); exit; } /* Check permissions on this contact. */ $editdone = false; if (!Turba::checkPermissions($object, 'object', PERMS_EDIT)) { if (!Turba::checkPermissions($object, 'object', PERMS_READ)) { $notification->push(_("You do not have permission to view this contact."), 'horde.error'); header('Location: ' . Horde::applicationUrl($prefs->getValue('initial_page'), true)); exit; } else { $notification->push(_("You only have permission to view this contact."), 'horde.error'); $editdone = true; } } $title = sprintf(_("Edit entry for %s"), $object->getValue('name')); /* Get the form object. */ $form = &Horde_Form::singleton('', $vars, $title); $form->setButtons(_("Save"), true); $form->addHidden('', 'url', 'text', false); $form->addHidden('', 'source', 'text', true); $form->addHidden('', 'key', 'text', false); $renderer->setObject($object); $view = &new Turba_ObjectView($object); $view->setupForm($form); if ($form->validate($vars)) { /* Form valid, save data. */ $form->getInfo($vars, $info); /* Update Contact. */ foreach ($info['object'] as $info_key => $info_val) { if ($info_key != '__key') { $object->setValue($info_key, $info_val); } } $success = $object->store(); $key = $object->getValue('__key'); if (!is_a($success, 'PEAR_Error')) { $notification->push(sprintf(_("Entry for %s updated."), $object->getValue('name')), 'horde.success'); $form->setTitle(sprintf(_("Edit entry for %s"), $object->getValue('name'))); $editdone = true; } else { Horde::logMessage($key, __FILE__, __LINE__, PEAR_LOG_ERR); $notification->push(sprintf(_("There was an error updating this entry: %s"), $success->getMessage()), 'horde.error'); } } else { $vars = array(); foreach ($object->attributes as $info_key => $info_val) { $vars[$info_key] = $object->getValue($info_key); } $vars = &new Variables(array('object' => $vars)); $vars->set('url', $url); $vars->set('source', $source); $vars->set('key', $key); } if ($editdone) { if (empty($info['url'])) { $uri = Horde::applicationUrl('display.php', true); $uri = Util::addParameter($uri, array('source' => $info['source'], 'key' => $key)); } else { $uri = $info['url']; } header('Location: ' . $uri); exit; } $notification->push('var i = 0; while (document.forms[0].elements[i].type == \'hidden\') i++; document.forms[0].elements[i].focus();', 'javascript'); require TURBA_TEMPLATES . '/common-header.inc'; Turba::menu(); $form->renderActive($renderer, $vars, 'edit.php', 'post'); require $registry->getParam('templates', 'horde') . '/common-footer.inc';