public function __construct($vars, Turba_Object $contact = null) { // @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); } }
/** * @param Turba_Object $contact * @param array $vars */ public function __construct($vars, Turba_Object $contact) { global $injector; parent::__construct($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 (!$contact->vfsInit() instanceof Horde_Vfs_Null) { $this->addVariable(_("Add file"), 'vfs', 'file', false); } $object_values = $vars->get('object'); $object_keys = array_keys($contact->attributes); $object_keys[] = '__tags'; 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()); }