Author: Chuck Hagenbuch (chuck@horde.org)
Author: Jon Parise (jon@csh.rit.edu)
コード例 #1
0
ファイル: Contact.php プロジェクト: jubinpatel/horde
 /**
  * @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');
         }
     }
 }
コード例 #2
0
ファイル: EditContact.php プロジェクト: DSNS-LAB/Dmail
 public function html($active = true)
 {
     global $browser, $vars;
     if (!$this->contact) {
         echo '<h3>' . _("The requested contact was not found.") . '</h3>';
         return;
     }
     if (!$this->contact->hasPermission(Horde_Perms::EDIT)) {
         if (!$this->contact->hasPermission(Horde_Perms::READ)) {
             echo '<h3>' . _("You do not have permission to view this contact.") . '</h3>';
             return;
         } else {
             echo '<h3>' . _("You only have permission to view this contact.") . '</h3>';
             return;
         }
     }
     echo '<div id="EditContact"' . ($active ? '' : ' style="display:none"') . '>';
     $form = new Turba_Form_EditContact($vars, $this->contact);
     $form->renderActive($form->getRenderer(), $vars, Horde::url('edit.php'), 'post');
     echo '</div>';
     if ($active && $browser->hasFeature('dom')) {
         if ($this->contact->hasPermission(Horde_Perms::READ)) {
             $view = new Turba_View_Contact($this->contact);
             $view->html(false);
         }
         if ($this->contact->hasPermission(Horde_Perms::DELETE)) {
             $delete = new Turba_View_DeleteContact($this->contact);
             $delete->html(false);
         }
     }
 }
コード例 #3
0
ファイル: EditContact.php プロジェクト: jubinpatel/horde
 /**
  */
 public function renderActive($renderer, $vars, $action, $method)
 {
     parent::renderActive($renderer, $vars, $action, $method);
     if ($this->_contact->isGroup()) {
         $edit_url = Horde::url('browse.php')->add(array('key' => $this->_contact->getValue('__key'), 'source' => $this->_contact->getSource()));
         echo '<div class="editGroupMembers">' . Horde::link($edit_url) . '<span class="iconImg groupImg"></span>' . _("Edit/View Contact List Members") . '</a>' . '</div>';
     }
 }
コード例 #4
0
ファイル: AddContact.php プロジェクト: kossamums/horde
 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');
 }
コード例 #5
0
ファイル: DeleteContact.php プロジェクト: DSNS-LAB/Dmail
    public function html($active = true)
    {
        if (!$this->contact) {
            echo '<h3>' . _("The requested contact was not found.") . '</h3>';
            return;
        }
        if (!$this->contact->hasPermission(Horde_Perms::DELETE)) {
            if (!$this->contact->hasPermission(Horde_Perms::READ)) {
                echo '<h3>' . _("You do not have permission to view this contact.") . '</h3>';
                return;
            } else {
                echo '<h3>' . _("You only have permission to view this contact.") . '</h3>';
                return;
            }
        }
        echo '<div id="DeleteContact"' . ($active ? '' : ' style="display:none"') . '>';
        ?>
        <form action="<?php 
        echo Horde::url('delete.php');
        ?>
" method="post">
        <?php 
        echo Horde_Util::formInput();
        ?>
        <input type="hidden" name="url" value="<?php 
        echo htmlspecialchars(Horde_Util::getFormData('url'));
        ?>
" />
        <input type="hidden" name="source" value="<?php 
        echo htmlspecialchars($this->contact->driver->getName());
        ?>
" />
        <input type="hidden" name="key" value="<?php 
        echo htmlspecialchars($this->contact->getValue('__key'));
        ?>
" />
        <div class="headerbox" style="padding: 8px">
         <p><?php 
        echo _("Permanently delete this contact?");
        ?>
</p>
         <input type="submit" class="horde-delete" name="delete" value="<?php 
        echo _("Delete");
        ?>
" />
        </div>
        </form>
        </div>
        <?php 
        if ($active && $GLOBALS['browser']->hasFeature('dom')) {
            if ($this->contact->hasPermission(Horde_Perms::READ)) {
                $view = new Turba_View_Contact($this->contact);
                $view->html(false);
            }
            if ($this->contact->hasPermission(Horde_Perms::EDIT)) {
                $delete = new Turba_View_EditContact($this->contact);
                $delete->html(false);
            }
        }
    }
コード例 #6
0
ファイル: Contact.php プロジェクト: jubinpatel/horde
 public function html($active = true)
 {
     global $browser, $conf, $registry;
     if (!$this->contact || !$this->contact->hasPermission(Horde_Perms::READ)) {
         echo '<h3>' . _("The requested contact was not found.") . '</h3>';
         return;
     }
     $vars = new Horde_Variables();
     $form = new Turba_Form_Contact($vars, $this->contact);
     $form->setOpenSection(Horde_Util::getFormData('section', 0));
     /* Get the contact's history. */
     $history = $this->contact->getHistory();
     foreach ($history as $what => $when) {
         $v = $form->addVariable($what == 'created' ? _("Created") : _("Last Modified"), 'object[__' . $what . ']', 'text', false, false);
         $v->disable();
         $vars->set('object[__' . $what . ']', $when);
     }
     echo '<div id="Contact"' . ($active ? '' : ' style="display:none"') . '>';
     $form->renderInactive($form->getRenderer(), $vars);
     /* Comments. */
     if (!empty($conf['comments']['allow']) && $registry->hasMethod('forums/doComments')) {
         try {
             $comments = $registry->call('forums/doComments', array('turba', $this->contact->driver->getName() . '.' . $this->contact->getValue('__key'), 'commentCallback'));
         } catch (Horde_Exception $e) {
             Horde::log($e, 'DEBUG');
             $comments = array();
         }
     }
     if (!empty($comments['threads'])) {
         echo '<br />' . $comments['threads'];
     }
     if (!empty($comments['comments'])) {
         echo '<br />' . $comments['comments'];
     }
     echo '</div>';
     if ($active && $browser->hasFeature('dom')) {
         if ($this->contact->hasPermission(Horde_Perms::EDIT)) {
             $edit = new Turba_View_EditContact($this->contact);
             $edit->html(false);
         }
         if ($this->contact->hasPermission(Horde_Perms::DELETE)) {
             $delete = new Turba_View_DeleteContact($this->contact);
             $delete->html(false);
         }
     }
 }
コード例 #7
0
ファイル: Turba.php プロジェクト: jubinpatel/horde
 /**
  * Formats the name according to the user's preference.
  *
  * If the format is 'none', the full name with all parts is returned. If
  * the format is 'last_first' or 'first_last', only the first name and
  * last name are returned.
  *
  * @param Turba_Object $ob     The object to get a name from.
  * @param string $name_format  The formatting. One of 'none', 'last_first'
  *                             or 'first_last'. Defaults to the user
  *                             preference.
  *
  * @return string  The formatted name, either "Firstname Lastname"
  *                 or "Lastname, Firstname" depending on $name_format or
  *                 the user's preference.
  */
 public static function formatName(Turba_Object $ob, $name_format = null)
 {
     if (!$name_format) {
         if (!isset(self::$_cache['defaultFormat'])) {
             self::$_cache['defaultFormat'] = $GLOBALS['prefs']->getValue('name_format');
         }
         $name_format = self::$_cache['defaultFormat'];
     }
     /* If no formatting, return original name. */
     if (!in_array($name_format, array('first_last', 'last_first'))) {
         return $ob->getValue('name');
     }
     /* See if we have the name fields split out explicitly. */
     if ($ob->hasValue('firstname') && $ob->hasValue('lastname')) {
         return $name_format == 'last_first' ? $ob->getValue('lastname') . ', ' . $ob->getValue('firstname') : $ob->getValue('firstname') . ' ' . $ob->getValue('lastname');
     }
     /* One field, we'll have to guess. */
     $name = $ob->getValue('name');
     $lastname = self::guessLastname($name);
     if ($name_format == 'last_first' && !is_int(strpos($name, ',')) && Horde_String::length($name) > Horde_String::length($lastname)) {
         return $lastname . ', ' . preg_replace('/\\s+' . preg_quote($lastname, '/') . '/', '', $name);
     }
     if ($name_format == 'first_last' && is_int(strpos($name, ',')) && Horde_String::length($name) > Horde_String::length($lastname)) {
         return preg_replace('/' . preg_quote($lastname, '/') . ',\\s*/', '', $name) . ' ' . $lastname;
     }
     return $name;
 }
コード例 #8
0
ファイル: Sql.php プロジェクト: jubinpatel/horde
 /**
  * Saves the specified object in the SQL database.
  *
  * @param Turba_Object $object  The object to save.
  *
  * @return string  The object id, possibly updated.
  * @throws Turba_Exception
  */
 protected function _save(Turba_Object $object)
 {
     list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
     $attributes = $this->toDriverKeys($object->getAttributes());
     $blob_fields = $this->toDriverKeys($this->getBlobs());
     $date_fields = $this->toDriverKeys($this->getDateFields());
     $where = $object_key . ' = ?';
     unset($attributes[$object_key]);
     list($fields, $values) = $this->_prepareWrite($attributes, $blob_fields, $date_fields);
     $values[] = $object_id;
     $query = 'UPDATE ' . $this->_params['table'] . ' SET ' . implode(' = ?, ', $fields) . ' = ? WHERE ' . $where;
     try {
         $this->_db->update($query, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Turba_Exception(_("Server error when saving data."));
     }
     return $object_id;
 }
コード例 #9
0
ファイル: Sql.php プロジェクト: raz0rsdge/horde
 /**
  * Saves the specified object in the SQL database.
  *
  * @param Turba_Object $object  The object to save.
  *
  * @return string  The object id, possibly updated.
  * @throws Turba_Exception
  */
 protected function _save(Turba_Object $object)
 {
     list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
     $attributes = $this->toDriverKeys($object->getAttributes());
     $blob_fields = $this->toDriverKeys($this->getBlobs());
     $date_fields = $this->toDriverKeys($this->getDateFields());
     unset($attributes[$object_key]);
     list($fields, $values) = $this->_prepareWrite($attributes, $blob_fields, $date_fields);
     try {
         $this->_db->updateBlob($this->_params['table'], array_combine($fields, $values), array($object_key . ' = ?', array($object_id)));
     } catch (Horde_Db_Exception $e) {
         throw new Turba_Exception(_("Server error when saving data."));
     }
     return $object_id;
 }
コード例 #10
0
ファイル: Kolab.php プロジェクト: DSNS-LAB/Dmail
 /**
  * Saves the specified object in the SQL database.
  *
  * @param Turba_Object $object  The object to save
  *
  * @return string  The object id, possibly updated.
  * @throws Turba_Exception
  */
 protected function _save(Turba_Object $object)
 {
     $this->connect();
     return $this->_store($this->toDriverKeys($object->getAttributes()), $object->getValue('__uid'));
 }
コード例 #11
0
ファイル: Imsp.php プロジェクト: DSNS-LAB/Dmail
 /**
  * Saves the specified object to the IMSP server.
  *
  * @param Turba_Object $object  The object to save/update.
  *
  * @return string  The object id, possibly updated.
  * @throws Turba_Exception
  */
 protected function _save($object)
 {
     list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
     $attributes = $this->toDriverKeys($object->getAttributes());
     /* Check if the key changed, because IMSP will just write out
      * a new entry without removing the previous one. */
     if ($attributes['name'] != $this->_makeKey($attributes)) {
         $this->_delete($object_key, $attributes['name']);
         $attributes['name'] = $this->_makeKey($attributes);
         $object_id = $attributes['name'];
     }
     $this->_add($attributes);
     return $object_id;
 }
コード例 #12
0
ファイル: Group.php プロジェクト: DSNS-LAB/Dmail
 /**
  * Constructs a new Turba_Object_Group.
  *
  * @param Turba_Driver $driver  The driver object that this group comes
  *                              from.
  * @param array $attributes     Hash of attributes for this group.
  * @param array $options        Hash of options for this object. @since
  *                              Turba 4.2
  */
 public function __construct(Turba_Driver $driver, array $attributes = array(), array $options = array())
 {
     parent::__construct($driver, $attributes, $options);
     $this->attributes['__type'] = 'Group';
 }
コード例 #13
0
ファイル: Driver.php プロジェクト: DSNS-LAB/Dmail
 /**
  * Convert the contact to an ActiveSync contact message
  *
  * @param Turba_Object $object  The turba object to convert
  * @param array $options        Options:
  *   - protocolversion: (float)  The EAS version to support
  *                      DEFAULT: 2.5
  *   - bodyprefs: (array)  A BODYPREFERENCE array.
  *                DEFAULT: none (No body prefs enforced).
  *   - truncation: (integer)  Truncate event body to this length
  *                 DEFAULT: none (No truncation).
  *   - device: (Horde_ActiveSync_Device) The device object.
  *
  * @return Horde_ActiveSync_Message_Contact
  */
 public function toASContact(Turba_Object $object, array $options = array())
 {
     global $injector;
     $message = new Horde_ActiveSync_Message_Contact(array('logger' => $injector->getInstance('Horde_Log_Logger'), 'protocolversion' => $options['protocolversion'], 'device' => !empty($options['device']) ? $options['device'] : null));
     $hash = $object->getAttributes();
     if (!isset($hash['lastname']) && isset($hash['name'])) {
         $this->_guessName($hash);
     }
     // Ensure we have at least a good guess as to separate address fields.
     // Not ideal, but EAS does not have a single "address" field so we must
     // map "common" to either home or work. I choose home since
     // work/non-personal installs will be more likely to have separated
     // address fields.
     if (!empty($hash['commonAddress'])) {
         if (!isset($hash['commonStreet'])) {
             $hash['commonStreet'] = $hash['commonHome'];
         }
         foreach (array('Address', 'Street', 'POBox', 'Extended', 'City', 'Province', 'PostalCode', 'Country') as $field) {
             $hash['home' . $field] = $hash['common' . $field];
         }
     } else {
         if (isset($hash['homeAddress']) && !isset($hash['homeStreet'])) {
             $hash['homeStreet'] = $hash['homeAddress'];
         }
         if (isset($hash['workAddress']) && !isset($hash['workStreet'])) {
             $hash['workStreet'] = $hash['workAddress'];
         }
     }
     $hooks = $injector->getInstance('Horde_Core_Hooks');
     $decode_hook = $hooks->hookExists('decode_attribute', 'turba');
     foreach ($hash as $field => $value) {
         if ($decode_hook) {
             try {
                 $value = $hooks->callHook('decode_attribute', 'turba', array($field, $value, $object));
             } catch (Turba_Exception $e) {
                 Horde::log($e);
             }
         }
         if (isset(self::$_asMap[$field])) {
             try {
                 $message->{self::$_asMap[$field]} = $value;
             } catch (InvalidArgumentException $e) {
             }
             continue;
         }
         switch ($field) {
             case 'photo':
                 $message->picture = base64_encode($value);
                 break;
             case 'homeCountry':
                 $message->homecountry = !empty($hash['homeCountryFree']) ? $hash['homeCountryFree'] : !empty($hash['homeCountry']) ? Horde_Nls::getCountryISO($hash['homeCountry']) : null;
                 break;
             case 'otherCountry':
                 $message->othercountry = !empty($hash['otherCountryFree']) ? $hash['otherCountryFree'] : !empty($hash['otherCountry']) ? Horde_Nls::getCountryISO($hash['otherCountry']) : null;
                 break;
             case 'workCountry':
                 $message->businesscountry = !empty($hash['workCountryFree']) ? $hash['workCountryFree'] : !empty($hash['workCountry']) ? Horde_Nls::getCountryISO($hash['workCountry']) : null;
                 break;
             case 'email':
                 $message->email1address = $value;
                 break;
             case 'homeEmail':
                 $message->email2address = $value;
                 break;
             case 'workEmail':
                 $message->email3address = $value;
                 break;
             case 'emails':
                 $address = 1;
                 foreach (explode(',', $value) as $email) {
                     while ($address <= 3 && $message->{'email' . $address . 'address'}) {
                         $address++;
                     }
                     if ($address > 3) {
                         break;
                     }
                     $message->{'email' . $address . 'address'} = $email;
                     $address++;
                 }
                 break;
             case 'children':
                 // Children FROM horde are a simple string value. Even though EAS
                 // uses an array stucture to pass them, we pass as a single
                 // string since we can't assure what delimter the user will
                 // use and (at least in some languages) a comma can be used
                 // within a full name.
                 $message->children = array($value);
                 break;
             case 'notes':
                 if ($options['protocolversion'] > Horde_ActiveSync::VERSION_TWOFIVE) {
                     $bp = $options['bodyprefs'];
                     $note = new Horde_ActiveSync_Message_AirSyncBaseBody();
                     // No HTML supported in Turba's notes. Always use plaintext.
                     $note->type = Horde_ActiveSync::BODYPREF_TYPE_PLAIN;
                     if (isset($bp[Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['truncationsize'])) {
                         if (Horde_String::length($value) > $bp[Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['truncationsize']) {
                             $note->data = Horde_String::substr($value, 0, $bp[Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['truncationsize']);
                             $note->truncated = 1;
                         } else {
                             $note->data = $value;
                         }
                         $note->estimateddatasize = Horde_String::length($value);
                     }
                     $message->airsyncbasebody = $note;
                 } else {
                     // EAS 2.5
                     $message->body = $value;
                     $message->bodysize = strlen($message->body);
                     $message->bodytruncated = 0;
                 }
                 break;
             case 'birthday':
             case 'anniversary':
                 if (!empty($value) && $value != '0000-00-00') {
                     try {
                         $date = new Horde_Date($value);
                     } catch (Horde_Date_Exception $e) {
                         $message->{$field} = null;
                     }
                     // Some sanity checking to make sure the date was
                     // successfully parsed.
                     if ($date->month != 0) {
                         $message->{$field} = $date;
                     } else {
                         $message->{$field} = null;
                     }
                 } else {
                     $message->{$field} = null;
                 }
                 break;
         }
     }
     /* Get tags. */
     $message->categories = explode(',', $object->getValue('__tags'));
     if (empty($this->fileas)) {
         $message->fileas = Turba::formatName($object);
     }
     return $message;
 }
コード例 #14
0
ファイル: List.php プロジェクト: jubinpatel/horde
 /**
  * Usort helper function.
  *
  * Compares two Turba_Objects based on the member variable
  * $_usortCriteria, taking care to sort numerically if it is an integer
  * field.
  *
  * @param Turba_Object $a  The first Turba_Object to compare.
  * @param Turba_Object $b  The second Turba_Object to compare.
  *
  * @return integer  Comparison of the two field values.
  */
 protected function _cmp(Turba_Object $a, Turba_Object $b)
 {
     foreach ($this->_usortCriteria as $field) {
         $f = $field['field'];
         switch ($field['sortmethod']) {
             case 'int':
                 $result = $a->getValue($f) > $b->getValue($f) ? 1 : -1;
                 break;
             case 'text':
                 if (!isset($a->sortValue[$f])) {
                     $a->sortValue[$f] = Horde_String::lower($a->getValue($f), true, 'UTF-8');
                 }
                 if (!isset($b->sortValue[$f])) {
                     $b->sortValue[$f] = Horde_String::lower($b->getValue($f), true, 'UTF-8');
                 }
                 // Use strcoll for locale-safe comparisons.
                 $result = strcoll($a->sortValue[$f], $b->sortValue[$f]);
                 break;
         }
         if ($result != 0) {
             return ($field['ascending'] ? 1 : -1) * $result;
         }
     }
     return 0;
 }
コード例 #15
0
ファイル: Ldap.php プロジェクト: DSNS-LAB/Dmail
 /**
  * Modifies the specified entry in the LDAP directory.
  *
  * @param Turba_Object $object  The object we wish to save.
  *
  * @return string  The object id, possibly updated.
  * @throw Turba_Exception
  */
 protected function _save(Turba_Object $object)
 {
     $this->_connect();
     list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
     $attributes = $this->toDriverKeys($object->getAttributes());
     /* Get the old entry so that we can access the old
      * values. These are needed so that we can delete any
      * attributes that have been removed by using ldap_mod_del. */
     if (empty($this->_params['objectclass'])) {
         $filter = null;
     } else {
         $filter = (string) Horde_Ldap_Filter::build(array('objectclass' => $this->_params['objectclass']), 'or');
     }
     $oldres = @ldap_read($this->_ds, Horde_String::convertCharset($object_id, 'UTF-8', $this->_params['charset']), $filter, array_merge(array_keys($attributes), array('objectclass')));
     $info = ldap_get_attributes($this->_ds, ldap_first_entry($this->_ds, $oldres));
     if ($this->_params['version'] == 3 && Horde_String::lower(str_replace(array(',', '"'), array('\\2C', ''), $this->_makeKey($attributes))) != Horde_String::lower(str_replace(',', '\\2C', $object_id))) {
         /* Need to rename the object. */
         $newrdn = $this->_makeRDN($attributes);
         if ($newrdn == '') {
             throw new Turba_Exception(_("Missing DN in LDAP source configuration."));
         }
         if (ldap_rename($this->_ds, Horde_String::convertCharset($object_id, 'UTF-8', $this->_params['charset']), Horde_String::convertCharset($newrdn, 'UTF-8', $this->_params['charset']), $this->_params['root'], true)) {
             $object_id = $newrdn . ',' . $this->_params['root'];
         } else {
             throw new Turba_Exception(sprintf(_("Failed to change name: (%s) %s; Old DN = %s, New DN = %s, Root = %s"), ldap_errno($this->_ds), ldap_error($this->_ds), $object_id, $newrdn, $this->_params['root']));
         }
     }
     /* Work only with lowercase keys. */
     $info = array_change_key_case($info, CASE_LOWER);
     $attributes = array_change_key_case($attributes, CASE_LOWER);
     foreach ($info as $key => $var) {
         $oldval = null;
         /* Check to see if the old value and the new value are
          * different and that the new value is empty. If so then
          * we use ldap_mod_del to delete the attribute. */
         if (isset($attributes[$key]) && $var[0] != $attributes[$key] && $attributes[$key] == '') {
             $oldval[$key] = $var[0];
             if (!@ldap_mod_del($this->_ds, Horde_String::convertCharset($object_id, 'UTF-8', $this->_params['charset']), $oldval)) {
                 throw new Turba_Exception(sprintf(_("Modify failed: (%s) %s"), ldap_errno($this->_ds), ldap_error($this->_ds)));
             }
             unset($attributes[$key]);
         } elseif (isset($attributes[$key]) && $var[0] == $attributes[$key]) {
             /* Drop unchanged elements from list of attributes to write. */
             unset($attributes[$key]);
         }
     }
     unset($attributes[Horde_String::lower($object_key)]);
     $this->_encodeAttributes($attributes);
     $attributes = array_filter($attributes, array($this, '_emptyAttributeFilter'));
     /* Modify objectclasses only if they really changed. */
     $oldClasses = array_map(array('Horde_String', 'lower'), $info['objectclass']);
     array_shift($oldClasses);
     $attributes['objectclass'] = array_unique(array_map('strtolower', array_merge($info['objectclass'], $this->_params['objectclass'])));
     unset($attributes['objectclass']['count']);
     $attributes['objectclass'] = array_values($attributes['objectclass']);
     /* Do not handle object classes unless they have changed. */
     if (!array_diff($oldClasses, $attributes['objectclass'])) {
         unset($attributes['objectclass']);
     }
     if (!@ldap_modify($this->_ds, Horde_String::convertCharset($object_id, 'UTF-8', $this->_params['charset']), $attributes)) {
         throw new Turba_Exception(sprintf(_("Modify failed: (%s) %s"), ldap_errno($this->_ds), ldap_error($this->_ds)));
     }
     return $object_id;
 }
コード例 #16
0
ファイル: Object.php プロジェクト: raz0rsdge/horde
 /**
  * Merges another contact into this one by filling empty fields of this
  * contact with values from the other.
  *
  * @param Turba_Object $contact  Another contact.
  */
 public function merge(Turba_Object $contact)
 {
     foreach (array_keys($contact->attributes) as $attribute) {
         if (!$this->hasValue($attribute) && $contact->hasValue($attribute)) {
             $this->setValue($attribute, $contact->getValue($attribute));
         }
     }
 }
コード例 #17
0
ファイル: Prefs.php プロジェクト: horde/horde
 /**
  * Saves the specified object in the preferences.
  *
  * @param Turba_Object $object TODO
  */
 function _save($object)
 {
     list(, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
     $attributes = $this->toDriverKeys($object->getAttributes());
     $book = $this->_getAddressBook();
     $book[$object_id] = $attributes;
     $this->_setAddressBook($book);
 }