[turba] patch: add and update contacts using Turba API
Mikael Geijer
mikael at nufort.net
Fri Oct 3 02:09:05 PDT 2003
Hi Bo.
Looks great, I've implemented my set-functions via the VCard-methods so
it's not exactly the same (although somewhat similar). Provide my diff
shortly.
Cheers
/Mikael
Bo Daley wrote:
>hi all,
>
>There was some discussion recently about adding methods to Turba's API that
>allow contacts to be modified by external apps. The attached patch contains the
>code I've been using to add and modify contacts and clients from another app
>we're working on here. It probably wouldn't need too much more work to do the
>XML-RPC/vcard thing someone was talking about earlier.
>
>hopefully this is useful to someone?
>
>bo.
>
>
>
>------------------------------------------------------------------------
>
>Index: api.php
>===================================================================
>RCS file: /repository/turba/lib/api.php,v
>retrieving revision 1.63
>diff -u -r1.63 api.php
>--- api.php 4 Sep 2003 01:25:10 -0000 1.63
>+++ api.php 3 Oct 2003 07:51:53 -0000
>@@ -58,6 +58,14 @@
> 'args' => array('addressbook', 'key'),
> 'type' => 'array');
>
>+$_services['setContact'] = array(
>+ 'args' => array('addressbook', 'key', 'attributes'),
>+ 'type' => 'array');
>+
>+$_services['addContact'] = array(
>+ 'args' => array('addressbook', 'attributes'),
>+ 'type' => 'string');
>+
> $_services['getClient'] = array(
> 'args' => array('key'),
> 'type' => 'array');
>@@ -66,6 +74,14 @@
> 'args' => array(),
> 'type' => 'string');
>
>+$_services['setClient'] = array(
>+ 'args' => array('key', 'attributes'),
>+ 'type' => 'array');
>+
>+$_services['addClient'] = array(
>+ 'args' => array('attributes'),
>+ 'type' => 'string');
>+
>
> $_services['block'] = array(
> 'args' => array('type', 'params'),
>@@ -500,6 +516,61 @@
> return $result;
> }
>
>+function _turba_setContact($addressbook = '', $key = '', $attributes = array())
>+{
>+ require_once dirname(__FILE__) . '/base.php';
>+ require_once TURBA_BASE . '/lib/Source.php';
>+ global $cfgSources;
>+
>+ $result = null;
>+
>+ if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources) || !isset($cfgSources[$addressbook])) {
>+ return PEAR::raiseError(_("The object you requested does not exist."), 'horde.warning');
>+ }
>+
>+ $driver = &Turba_Source::singleton($addressbook, $cfgSources[$addressbook]);
>+
>+ $object = $driver->getObject($key);
>+ /* Check permissions on this object. */
>+ if (!Turba::checkPermissions($object, 'object', _PERMS_EDIT)) {
>+ $result = PEAR::raiseError(_("You do not have permission to edit this object."), 'horde.warning');
>+ } else {
>+ foreach ($attributes as $info_key => $info_val) {
>+ if ($info_key != '__key') {
>+ $object->setValue($info_key, $info_val);
>+ }
>+ }
>+ $success = $object->store();
>+ if (!is_a($success, 'PEAR_Error')) {
>+ $result = PEAR::raiseError(sprintf(_("Entry for %s updated."), $object->getValue('name')), 'horde.success');
>+ } else {
>+ $result = PEAR::raiseError(sprintf(_("There was an error updating this entry: %s."), $success->getMessage()), 'horde.error');
>+ }
>+ }
>+
>+ return $result;
>+}
>+
>+function _turba_addContact($addressbook = '', $attributes = array())
>+{
>+ require_once dirname(__FILE__) . '/base.php';
>+ require_once TURBA_BASE . '/lib/Source.php';
>+ global $cfgSources;
>+
>+ $key = null;
>+
>+ if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources) || !isset($cfgSources[$addressbook])) {
>+ return PEAR::raiseError(_("The source you requested does not exist."), 'horde.warning');
>+ }
>+
>+ $driver = &Turba_Source::singleton($addressbook, $cfgSources[$addressbook]);
>+
>+ /* Create Object. */
>+ $key = $driver->addObject($attributes);
>+
>+ return $key;
>+}
>+
> function _turba_getClient($key = '')
> {
> global $conf;
>@@ -512,6 +583,18 @@
> {
> global $conf;
> return $conf['client']['addressbook'];
>+}
>+
>+function _turba_setClient($key = '', $attributes = array())
>+{
>+ $addressbook = $GLOBALS['registry']->call('clients/getClientSource', array());
>+ return $GLOBALS['registry']->call('clients/setContact', array($addressbook, $key, $attributes));
>+}
>+
>+function _turba_addClient($attributes = array())
>+{
>+ $addressbook = $GLOBALS['registry']->call('clients/getClientSource', array());
>+ return $GLOBALS['registry']->call('clients/addContact', array($addressbook, $attributes));
> }
>
> function _turba_getFieldById($source, $id, $field)
>
>
>------------------------------------------------------------------------
>
>
>
>
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=- Mikael Geijer, nufort HB (nufort.net), Oebb AB (oebb.net)
=- mobile: +46 70 7455239 office +46 70 7455239
=- email: mikael at nufort.net
=- snail: Kyrklunden 8, 122 32 Enskede, Sweden
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=
More information about the turba
mailing list