/** * 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; }
/** * 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; }
/** * 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; }
/** * 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')); }
/** * 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; }
/** * 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); }
/** * 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; }