/usr/share/horde/turba/lib/Form/AddContact.php is in php-horde-turba 4.1.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <?php
/**
* @package Turba
*/
class Turba_Form_AddContact extends Turba_Form_ContactBase
{
protected $_contact = null;
public function __construct($vars, Turba_Object $contact)
{
// @TODO: $addSources should be injected
global $addSources, $notification;
parent::__construct($vars, '', 'turba_form_addcontact');
$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);
}
}
public function validate()
{
if (!$this->_vars->get('source')) {
return false;
}
return parent::validate($this->_vars);
}
public function execute()
{
// @TODO $driver should be injected, or at the very least, obtained
// via the injector
global $driver, $notification;
/* Form valid, save data. */
$this->getInfo($this->_vars, $info);
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. */
try {
$key = $driver->add($contact);
} catch (Turba_Exception $e) {
Horde::logMessage($e, 'ERR');
$key = null;
}
if ($key) {
// Try 3 times to get the new entry. We retry to allow setups like
// LDAP replication to work.
for ($i = 0; $i < 3; ++$i) {
try {
$ob = $driver->getObject($key);
$notification->push(sprintf(_("%s added."), $ob->getValue('name')), 'horde.success');
$url = empty($info['url'])
? $ob->url('Contact', true)
: new Horde_Url($info['url']);
$url->redirect();
} catch (Horde_Exception_NotFound $e) {
}
sleep(1);
}
}
$notification->push(_("There was an error adding the new contact. Contact your system administrator for further help."), 'horde.error');
}
}
|