Turba_Form_EditContact::execute PHP Method

execute() public method

public execute ( )
    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;
    }

Usage Example

Example #1
0
 public function execute()
 {
     parent::execute();
     $this->getInfo($this->_vars, $info);
     $next_page = Horde::url('edit.php', true)->add(array('source' => $info['source'], 'original_source' => $info['original_source'], 'objectkeys' => $info['objectkeys'], 'url' => $info['url'], 'actionID' => 'groupedit'));
     $objectkey = array_search($info['source'] . ':' . $info['key'], $info['objectkeys']);
     $submitbutton = $this->_vars->get('submitbutton');
     if ($submitbutton == _("Finish")) {
         $next_page = Horde::url('browse.php', true);
         if ($info['original_source'] == '**search') {
             $next_page->add('key', $info['original_source']);
         } else {
             $next_page->add('source', $info['original_source']);
         }
     } elseif ($submitbutton == _("Previous") && $info['source'] . ':' . $info['key'] != $info['objectkeys'][0]) {
         /* Previous contact */
         list(, $previous_key) = explode(':', $info['objectkeys'][$objectkey - 1]);
         $next_page->add('key', $previous_key);
         if ($this->getOpenSection()) {
             $next_page->add('__formOpenSection', $this->getOpenSection());
         }
     } elseif ($submitbutton == _("Next") && $info['source'] . ':' . $info['key'] != $info['objectkeys'][count($info['objectkeys']) - 1]) {
         /* Next contact */
         list(, $next_key) = explode(':', $info['objectkeys'][$objectkey + 1]);
         $next_page->add('key', $next_key);
         if ($this->getOpenSection()) {
             $next_page->add('__formOpenSection', $this->getOpenSection());
         }
     }
     $next_page->redirect();
 }