[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/syncml/contacts/lib/ -> api.php (source)

   1  <?php
   2  /**
   3   * Mnemo external API interface.
   4   *
   5   * $Horde: mnemo/lib/api.php,v 1.52 2004/09/14 04:27:07 chuck Exp $
   6   *
   7   * This file defines Mnemo's external API interface. Other
   8   * applications can interact with Mnemo through this API.
   9   *
  10   * @package Mnemo
  11   */
  12  
  13  $_services['list'] = array(
  14      'args' => array(),
  15      'type' => 'stringArray'
  16  );
  17  
  18  $_services['listBy'] = array(
  19      'args' => array('action', 'timestamp'),
  20      'type' => 'stringArray'
  21  );
  22  
  23  $_services['import'] = array(
  24      'args' => array('content', 'contentType'),
  25      'type' => 'integer'
  26  );
  27  
  28  $_services['search'] = array(
  29      'args' => array('content', 'contentType'),
  30      'type' => 'integer'
  31  );
  32  
  33  $_services['export'] = array(
  34      'args' => array('guid', 'contentType'),
  35      'type' => 'string'
  36  );
  37  
  38  $_services['delete'] = array(
  39      'args' => array('guid'),
  40      'type' => 'boolean'
  41  );
  42  
  43  $_services['replace'] = array(
  44      'args' => array('guid', 'content', 'contentType'),
  45      'type' => 'boolean'
  46  );
  47  
  48  
  49  /**
  50   * Returns an array of GUIDs for all notes that the current user is
  51   * authorized to see.
  52   *
  53   * @return array  An array of GUIDs for all notes the user can access.
  54   */
  55  function _egwcontactssync_list()
  56  {
  57      $guids = array();
  58      
  59      #Horde::logMessage("SymcML: egwcontactssync list ", __FILE__, __LINE__, PEAR_LOG_DEBUG);
  60      
  61      $allContacts = ExecMethod('addressbook.vcaladdressbook.read_entries',array());
  62  
  63      #Horde::logMessage("SymcML: egwcontactssync list ", __FILE__, __LINE__, PEAR_LOG_DEBUG);
  64  
  65      foreach((array)$allContacts as $contact)
  66      {
  67          $guids[] = $GLOBALS['phpgw']->common->generate_uid('contacts',$contact['id']);
  68      }
  69  
  70      return $guids;
  71  }
  72  
  73  /**
  74   * Returns an array of GUIDs for notes that have had $action happen
  75   * since $timestamp.
  76   *
  77   * @param string  $action     The action to check for - add, modify, or delete.
  78   * @param integer $timestamp  The time to start the search.
  79   *
  80   * @return array  An array of GUIDs matching the action and time criteria.
  81   */
  82  function &_egwcontactssync_listBy($action, $timestamp)
  83  {
  84      // todo
  85      // check for acl
  86      
  87      #Horde::logMessage("SymcML: egwcontactssync listBy action: $action timestamp: $timestamp", __FILE__, __LINE__, PEAR_LOG_DEBUG);
  88  
  89      $allChangedItems = $GLOBALS['phpgw']->contenthistory->getHistory('contacts', $action, $timestamp);
  90  
  91      if($action != 'delete')
  92      {
  93          $vcalAddressBook = CreateObject('addressbook.vcaladdressbook');
  94          $readAbleItems = array();
  95  
  96          // check if we have access to the changed data
  97          // need to get improved in the future
  98          foreach($allChangedItems as $guid)
  99          {
 100              $uid = $GLOBALS['phpgw']->common->get_egwId($guid);
 101              if($vcalAddressBook->check_perms($uid, PHPGW_ACL_READ))
 102              {
 103                  $readAbleItems[] = $guid;
 104              }
 105          }
 106          
 107          return $readAbleItems;
 108      }
 109  
 110      return $allChangedItems;
 111  }
 112  
 113  /**
 114   * Import a memo represented in the specified contentType.
 115   *
 116   * @param string $content      The content of the memo.
 117   * @param string $contentType  What format is the data in? Currently supports:
 118   *                             text/plain
 119   *                             text/x-vnote
 120   * @param string $notepad      (optional) The notepad to save the memo on.
 121   *
 122   * @return string  The new GUID, or false on failure.
 123   */
 124  function _egwcontactssync_import($content, $contentType, $notepad = null)
 125  {
 126      #error_log("SymcML: egwcontactssync import content: ".base64_decode($ccontent)." contentType: $contentType");
 127      Horde::logMessage("SymcML: egwcontactssync import content: $content contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG);
 128  
 129      $state            = $_SESSION['SyncML.state'];
 130      $deviceInfo        = $state->getClientDeviceInfo();
 131  
 132      
 133      switch ($contentType) {
 134          case 'text/x-vcard':
 135              $vcaladdressbook    =& CreateObject('addressbook.vcaladdressbook',true);
 136              $vcaladdressbook->setSupportedFields($deviceInfo['manufacturer'],$deviceInfo['model']);
 137  
 138              $contactId        = $vcaladdressbook->addVCard($content,-1);
 139              break;
 140  
 141          case 'text/x-s4j-sifc':
 142              $sifaddressbook        =& CreateObject('addressbook.sifaddressbook');
 143              $contactId =         $sifaddressbook->addSIF($content,-1);
 144              break;
 145              
 146          default:
 147              return PEAR::raiseError(_("Unsupported Content-Type."));
 148      }
 149      
 150      if (is_a($contactId, 'PEAR_Error')) {
 151          return $contactId;
 152      }
 153  
 154      #Horde::logMessage("SymcML: egwcontactssync import imported: ".$GLOBALS['phpgw']->common->generate_uid('contacts',$contactId), __FILE__, __LINE__, PEAR_LOG_DEBUG);
 155      return $GLOBALS['phpgw']->common->generate_uid('contacts',$contactId);
 156  }
 157  
 158  /**
 159   * Import a memo represented in the specified contentType.
 160   *
 161   * @param string $content      The content of the memo.
 162   * @param string $contentType  What format is the data in? Currently supports:
 163   *                             text/plain
 164   *                             text/x-vnote
 165   * @param string $notepad      (optional) The notepad to save the memo on.
 166   *
 167   * @return string  The new GUID, or false on failure.
 168   */
 169  function _egwcontactssync_search($content, $contentType)
 170  {
 171      #error_log("SymcML: egwcontactssync search content contentType: $contentType");
 172      Horde::logMessage("SymcML: egwcontactssync search content: $content contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG);
 173  
 174      $state            = $_SESSION['SyncML.state'];
 175      $deviceInfo        = $state->getClientDeviceInfo();
 176  
 177      
 178      switch ($contentType) {
 179          case 'text/x-vcard':
 180              $vcaladdressbook    =& CreateObject('addressbook.vcaladdressbook',true);
 181              $vcaladdressbook->setSupportedFields($deviceInfo['manufacturer'],$deviceInfo['model']);
 182  
 183              $contactId        = $vcaladdressbook->search($content);
 184              break;
 185  
 186          case 'text/x-s4j-sifc':
 187              $sifaddressbook        =& CreateObject('addressbook.sifaddressbook');
 188              $contactId =         $sifaddressbook->search($content);
 189              break;
 190              
 191          default:
 192              return PEAR::raiseError(_("Unsupported Content-Type."));
 193      }
 194      
 195      if (is_a($contactId, 'PEAR_Error')) {
 196          return $contactId;
 197      }
 198  
 199      #error_log("SymcML: egwcontactssync search found: $contactId");
 200      Horde::logMessage("SymcML: egwcontactssync search found: ".$GLOBALS['phpgw']->common->generate_uid('contacts',$contactId), __FILE__, __LINE__, PEAR_LOG_DEBUG);
 201      if(!$contactId) {
 202          return false;
 203      } else {
 204          return $GLOBALS['phpgw']->common->generate_uid('contacts',$contactId);
 205      }
 206  }
 207  
 208  /**
 209   * Export a memo, identified by GUID, in the requested contentType.
 210   *
 211   * @param string $guid         Identify the memo to export.
 212   * @param mixed  $contentType  What format should the data be in?
 213   *                             Either a string with one of:
 214   *                              'text/plain'
 215   *                              'text/x-vnote'
 216   *                             or an array with options:
 217   *                             'ContentType':  as above
 218   *                             'ENCODING': (optional) character encoding
 219   *                                         for strings fields
 220   *                             'CHARSET':  (optional) charset. Like UTF-8
 221   *
 222   * @return string  The requested data.
 223   */
 224  function _egwcontactssync_export($guid, $contentType)
 225  {
 226      if (is_array($contentType)) {
 227          $options = $contentType;
 228          $contentType = $options['ContentType'];
 229          unset($options['ContentType']);
 230      } else {
 231          $options = array();
 232      }
 233      
 234      $state        = $_SESSION['SyncML.state'];
 235      $deviceInfo    = $state->getClientDeviceInfo();
 236  
 237      $vcaladdressbook    =& CreateObject('addressbook.vcaladdressbook',True);
 238      $vcaladdressbook->setSupportedFields($deviceInfo['manufacturer'],$deviceInfo['model']);
 239      $contactID        = $GLOBALS['phpgw']->common->get_egwId($guid);
 240      
 241      switch ($contentType) {
 242          case 'text/x-vcard':
 243  
 244              if($vcard = $vcaladdressbook->getVCard($contactID))
 245              {
 246                  return $vcard;
 247              }
 248              else
 249              {
 250                  return PEAR::raiseError(_("Access Denied"));
 251              }
 252              
 253              break;
 254          
 255          default:
 256              #Horde::logMessage("SymcML: export unsupported", __FILE__, __LINE__, PEAR_LOG_DEBUG);
 257              return PEAR::raiseError(_("Unsupported Content-Type."));
 258      }
 259  }
 260  
 261  /**
 262   * Delete a memo identified by GUID.
 263   *
 264   * @param string | array $guid  Identify the note to delete, either a
 265   *                              single GUID or an array.
 266   *
 267   * @return boolean  Success or failure.
 268   */
 269  function _egwcontactssync_delete($guid)
 270  {
 271      // Handle an arrray of GUIDs for convenience of deleting multiple
 272      // contacts at once.
 273      if (is_array($guid)) {
 274          foreach ($guid as $g) {
 275              $result = _egwcontactssync_delete($g);
 276              if (is_a($result, 'PEAR_Error')) {
 277                  return $result;
 278              }
 279          }
 280          
 281          return true;
 282      }
 283      
 284      #if (!array_key_exists($memo['memolist_id'], Mnemo::listNotepads(false, PERMS_DELETE))) {
 285      #    return PEAR::raiseError(_("Permission Denied"));
 286      #}
 287      
 288      return ExecMethod('addressbook.vcaladdressbook.delete_entry',$GLOBALS['phpgw']->common->get_egwId($guid));
 289  }
 290  
 291  /**
 292   * Replace the memo identified by GUID with the content represented in
 293   * the specified contentType.
 294   *
 295   * @param string $guid         Idenfity the memo to replace.
 296   * @param string $content      The content of the memo.
 297   * @param string $contentType  What format is the data in? Currently supports:
 298   *                             text/plain
 299   *                             text/x-vnote
 300   *
 301   * @return boolean  Success or failure.
 302   */
 303  function _egwcontactssync_replace($guid, $content, $contentType)
 304  {
 305      Horde::logMessage("SymcML: egwcontactssync replace guid: $guid with content: $content", __FILE__, __LINE__, PEAR_LOG_DEBUG);
 306      #error_log("SymcML: egwcontactssync replace guid: $guid content: $ccontent contentType: $contentType");
 307      #if (!array_key_exists($memo['memolist_id'], Mnemo::listNotepads(false, PERMS_EDIT))) {
 308      #    return PEAR::raiseError(_("Permission Denied"));
 309      #}
 310  
 311      $state        = $_SESSION['SyncML.state'];
 312      $deviceInfo    = $state->getClientDeviceInfo();
 313  
 314      $contactID = $GLOBALS['phpgw']->common->get_egwId($guid);
 315  
 316      switch ($contentType) {
 317          case 'text/x-vcard':
 318              $vcaladdressbook    =& CreateObject('addressbook.vcaladdressbook',True);
 319              $vcaladdressbook->setSupportedFields($deviceInfo['manufacturer'],$deviceInfo['model']);
 320              $result = $vcaladdressbook->addVCard($content,$contactID);
 321                  
 322                  return $result;
 323                  
 324                  break;
 325                  
 326          case 'text/x-s4j-sifc':
 327              #$tmpfname = tempnam('/tmp/sync/contents','sifcontact_');
 328              #$handle = fopen($tmpfname, "w");
 329              #fwrite($handle, base64_decode($content));
 330              #fclose($handle);
 331  
 332              $sifaddressbook        =& CreateObject('addressbook.sifaddressbook');
 333              $result = $sifaddressbook->addSIF($content,$contactID);
 334              
 335              return $result;
 336              
 337              break;
 338  
 339              default:
 340                  return PEAR::raiseError(_("Unsupported Content-Type."));
 341          }
 342  }
 343  


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7