1: <?php
2: 3: 4: 5: 6:
7: class Turba_Form_EditContact extends Turba_Form_ContactBase
8: {
9: 10: 11: 12:
13: protected $_contact;
14:
15: 16: 17: 18:
19: public function __construct($vars, Turba_Object $contact)
20: {
21: global $conf;
22:
23: parent::__construct($vars, '', 'Turba_View_EditContact');
24: $this->_contact = $contact;
25:
26: $this->setButtons(_("Save"));
27: $this->addHidden('', 'url', 'text', false);
28: $this->addHidden('', 'source', 'text', true);
29: $this->addHidden('', 'key', 'text', false);
30:
31: parent::_addFields($this->_contact);
32:
33: $this->addVariable(_("Add file"), 'vfs', 'file', false);
34:
35: $object_values = $vars->get('object');
36: $object_keys = array_keys($contact->attributes);
37: foreach ($object_keys as $info_key) {
38: if (!isset($object_values[$info_key])) {
39: $object_values[$info_key] = $contact->getValue($info_key);
40: }
41: }
42: $vars->set('object', $object_values);
43: $vars->set('source', $contact->getSource());
44: }
45:
46: public function execute()
47: {
48: global $conf, $notification;
49:
50: if (!$this->validate($this->_vars)) {
51: throw new Turba_Exception('Invalid');
52: }
53:
54:
55: $this->getInfo($this->_vars, $info);
56:
57:
58: foreach ($info['object'] as $info_key => $info_val) {
59: if ($info_key != '__key') {
60: if ($GLOBALS['attributes'][$info_key]['type'] == 'image' && !empty($info_val['file'])) {
61: $this->_contact->setValue($info_key, file_get_contents($info_val['file']));
62: if (isset($info_val['type'])) {
63: $this->_contact->setValue($info_key . 'type', $info_val['type']);
64: }
65: } else {
66: $this->_contact->setValue($info_key, $info_val);
67: }
68: }
69: }
70:
71: try {
72: $this->_contact->store();
73: } catch (Turba_Exception $e) {
74: Horde::logMessage($e, 'ERR');
75: $notification->push(_("There was an error saving the contact. Contact your system administrator for further help."), 'horde.error');
76: throw $e;
77: }
78:
79: if (isset($info['vfs'])) {
80: try {
81: $this->_contact->addFile($info['vfs']);
82: $notification->push(sprintf(_("\"%s\" updated."), $this->_contact->getValue('name')), 'horde.success');
83: } catch (Turba_Exception $e) {
84: $notification->push(sprintf(_("\"%s\" updated, but saving the uploaded file failed: %s"), $this->_contact->getValue('name'), $e->getMessage()), 'horde.warning');
85: }
86: } else {
87: $notification->push(sprintf(_("\"%s\" updated."), $this->_contact->getValue('name')), 'horde.success');
88: }
89:
90: return true;
91: }
92:
93: 94:
95: public function renderActive($renderer, $vars, $action, $method)
96: {
97: parent::renderActive($renderer, $vars, $action, $method);
98:
99: if ($this->_contact->isGroup()) {
100: $edit_url = Horde::url('browse.php')->add(array(
101: 'key' => $this->_contact->getValue('__key'),
102: 'source' => $this->_contact->getSource()
103: ));
104:
105: echo '<div class="editGroupMembers">' .
106: Horde::link($edit_url) . '<span class="iconImg groupImg"></span>' . _("Edit/View Group Members") . '</a>' .
107: '</div>';
108: }
109: }
110:
111: }
112: