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 array $vars Array of form variables * @param Turba_Object $contact */ public function __construct($vars, Turba_Object $contact, $tabs = true, $title = null) { global $injector, $notification; if (is_null($title)) { $title = 'Turba_View_Contact'; } parent::__construct($vars, '', $title); /* Get the values through the Turba_Object class. */ $object = array(); foreach (array_keys($contact->driver->getCriteria()) as $info_key) { $object[$info_key] = $contact->getValue($info_key); } /* Get tags. */ if (($tagger = $injector->getInstance('Turba_Tagger')) && !$tagger instanceof Horde_Core_Tagger_Null && ($uid = $contact->getValue('__uid'))) { $object['__tags'] = implode(', ', $tagger->getTags($uid, 'contact')); } $vars->set('object', $object); $this->_addFields($contact, $tabs); /* List files. */ if (!$contact->vfsInit() instanceof Horde_Vfs_Null) { try { $files = $contact->listFiles(); $this->addVariable(_("Files"), '__vfs', 'html', false); $vars->set('__vfs', implode('<br />', array_map(array($contact, 'vfsEditUrl'), $files))); } catch (Turba_Exception $e) { $notification->push($files, 'horde.error'); } } }
/** * @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()); }