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') { if (!empty($info_val['file'])) { $this->_contact->setValue($info_key, file_get_contents($info_val['file'])); $this->_contact->setValue($info_key . 'type', $info_val['type']); } if (!empty($info_val['orig_file'])) { $this->_contact->setValue($info_key . '_orig', file_get_contents($info_val['orig_file'])); } } 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::log($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'); }
public function execute() { global $attributes, $notification; if (!$this->validate($this->_vars)) { throw new Turba_Exception('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 ($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); } } } try { $this->_contact->store(); } catch (Turba_Exception $e) { Horde::log($e, 'ERR'); $notification->push(_("There was an error saving the contact. Contact your system administrator for further help."), 'horde.error'); throw $e; } if (isset($info['vfs'])) { try { $this->_contact->addFile($info['vfs']); $notification->push(sprintf(_("\"%s\" updated."), $this->_contact->getValue('name')), 'horde.success'); } catch (Turba_Exception $e) { $notification->push(sprintf(_("\"%s\" updated, but saving the uploaded file failed: %s"), $this->_contact->getValue('name'), $e->getMessage()), 'horde.warning'); } } else { $notification->push(sprintf(_("\"%s\" updated."), $this->_contact->getValue('name')), 'horde.success'); } return true; }