1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
<?php
/**
* @package Turba
*
* $Horde: turba/lib/Forms/EditContact.php,v 1.6.2.2 2008/04/17 15:53:54 chuck Exp $
*/
/** 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') {
$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, __FILE__, __LINE__, PEAR_LOG_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();
require_once TURBA_BASE . '/lib/List.php';
require_once TURBA_BASE . '/lib/ListView.php';
$results = new Turba_List($vars->get('objectkeys'));
$listView = new Turba_ListView($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 = 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 = Util::addParameter($next_page, 'key', $info['original_source'], false);
} else {
$next_page = 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 = Util::addParameter($next_page, 'key', $previous_key, false);
if ($this->getOpenSection()) {
$next_page = 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 = Util::addParameter($next_page, 'key', $next_key, false);
if ($this->getOpenSection()) {
$next_page = Util::addParameter($next_page, '__formOpenSection', $this->getOpenSection(), false);
}
}
header('Location: ' . $next_page);
exit;
}
}
|