[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/syncml/tasks/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 _egwtaskssync_list()
  56  {
  57      $guids = array();
  58  
  59      Horde::logMessage("SymcML: egwtaskssync list ", __FILE__, __LINE__, PEAR_LOG_DEBUG);
  60      
  61      $searchFilter = array
  62      (
  63          'order'        => 'info_datemodified',
  64          'sort'        => 'DESC',
  65          'filter'    => 'my',        // filter my: entries user is responsible for, filter own: entries the user own or is responsible for
  66          // todo add a filter to limit how far back entries from the past get synced
  67          'col_filter'    => Array
  68          (
  69              'info_type'    => 'task',
  70          ),
  71      );
  72      
  73      $tasks = ExecMethod('infolog.boinfolog.search',$searchFilter);
  74      Horde::logMessage("SymcML: egwtaskssync list found: ".count($tasks), __FILE__, __LINE__, PEAR_LOG_DEBUG);
  75      foreach((array)$tasks as $task)
  76      {
  77          $guids[] = $GLOBALS['egw']->common->generate_uid('infolog_task',$task['info_id']);
  78      }
  79      
  80      return $guids;
  81  }
  82  
  83  /**
  84   * Returns an array of GUIDs for notes that have had $action happen
  85   * since $timestamp.
  86   *
  87   * @param string  $action     The action to check for - add, modify, or delete.
  88   * @param integer $timestamp  The time to start the search.
  89   *
  90   * @return array  An array of GUIDs matching the action and time criteria.
  91   */
  92  function &_egwtaskssync_listBy($action, $timestamp)
  93  {
  94      #Horde::logMessage("SymcML: egwnotessync listBy action: $action timestamp: $timestamp", __FILE__, __LINE__, PEAR_LOG_DEBUG);
  95      
  96      $allChangedItems = $GLOBALS['egw']->contenthistory->getHistory('infolog_task', $action, $timestamp);
  97      
  98      if($action == 'delete')
  99      {
 100          return $allChangedItems;    // InfoLog has no further info about deleted entries
 101      }
 102      $boInfolog =& CreateObject('infolog.boinfolog');
 103      $user = $GLOBALS['egw_info']['user']['account_id'];
 104  
 105      $readAbleItems = array();
 106      foreach($allChangedItems as $guid)
 107      {
 108          $uid = $GLOBALS['egw']->common->get_egwId($guid);
 109  
 110          if(($info = $boInfolog->read($uid)) &&        // checks READ rights too and returns false if none
 111              // for filter my = all items the user is responsible for:
 112              ($user == $info['info_owner'] && !count($info['info_responsible']) || in_array($user,$info['info_responsible'])))
 113              // for filter own = all items the user own or is responsible for:
 114              //($user == $info['info_owner'] || in_array($user,$info['info_responsible'])))
 115          {
 116              $readAbleItems[] = $guid;
 117          }
 118      }
 119      return $readAbleItems;
 120  }
 121  
 122  /**
 123   * Import a memo represented in the specified contentType.
 124   *
 125   * @param string $content      The content of the memo.
 126   * @param string $contentType  What format is the data in? Currently supports:
 127   *                             text/plain
 128   *                             text/x-vnote
 129   * @param string $notepad      (optional) The notepad to save the memo on.
 130   *
 131   * @return string  The new GUID, or false on failure.
 132   */
 133  function _egwtaskssync_import($content, $contentType, $notepad = null)
 134  {
 135      switch ($contentType) {
 136          case 'text/x-vcalendar':
 137              $vcalInfolog    =& CreateObject('infolog.vcalinfolog');
 138  
 139              $taskID = $vcalInfolog->importVTODO($content);
 140  
 141              break;
 142  
 143          default:
 144              return PEAR::raiseError(_("Unsupported Content-Type."));
 145      }
 146      
 147      if (is_a($taskID, 'PEAR_Error')) {
 148          return $taskID;
 149      }
 150  
 151      #Horde::logMessage("SymcML: egwnotessync import imported: ".$GLOBALS['egw']->common->generate_uid('infolog',$noteId), __FILE__, __LINE__, PEAR_LOG_DEBUG);
 152      return $GLOBALS['egw']->common->generate_uid('infolog_task',$taskID);
 153  }
 154  
 155  /**
 156   * Import a memo represented in the specified contentType.
 157   *
 158   * @param string $content      The content of the memo.
 159   * @param string $contentType  What format is the data in? Currently supports:
 160   *                             text/plain
 161   *                             text/x-vnote
 162   * @param string $notepad      (optional) The notepad to save the memo on.
 163   *
 164   * @return string  The new GUID, or false on failure.
 165   */
 166  function _egwtaskssync_search($content, $contentType)
 167  {
 168      switch ($contentType) {
 169          case 'text/x-vcalendar':
 170              $vcalInfolog    =& CreateObject('infolog.vcalinfolog');
 171              $taskID     =  $vcalInfolog->searchVTODO($content);
 172              break;
 173              
 174          default:
 175              return PEAR::raiseError(_("Unsupported Content-Type."));
 176      }
 177      
 178      if (is_a($taskID, 'PEAR_Error')) {
 179          return $taskID;
 180      }
 181  
 182      #error_log("SymcML: egwsiftaskssync search found: $taskID");
 183      #Horde::logMessage("SymcML: egwsiftaskssync import imported: ".$GLOBALS['egw']->common->generate_uid('infolog_task',$taskID), __FILE__, __LINE__, PEAR_LOG_DEBUG);
 184      if(!$taskID) {
 185          return false;
 186      } else {
 187          return $GLOBALS['egw']->common->generate_uid('infolog_task',$taskID);
 188      }
 189  }
 190  
 191  /**
 192   * Export a memo, identified by GUID, in the requested contentType.
 193   *
 194   * @param string $guid         Identify the memo to export.
 195   * @param mixed  $contentType  What format should the data be in?
 196   *                             Either a string with one of:
 197   *                              'text/plain'
 198   *                              'text/x-vnote'
 199   *                             or an array with options:
 200   *                             'ContentType':  as above
 201   *                             'ENCODING': (optional) character encoding
 202   *                                         for strings fields
 203   *                             'CHARSET':  (optional) charset. Like UTF-8
 204   *
 205   * @return string  The requested data.
 206   */
 207  function _egwtaskssync_export($guid, $contentType)
 208  {
 209      if (is_array($contentType)) {
 210          $options = $contentType;
 211          $contentType = $options['ContentType'];
 212          unset($options['ContentType']);
 213      } else {
 214          $options = array();
 215      }
 216  
 217      Horde::logMessage("SymcML: egwtaskssync export guid: $guid contenttype: ".$contentType, __FILE__, __LINE__, PEAR_LOG_DEBUG);
 218      
 219      #$syncProfile    = _egwcalendarsync_getSyncProfile();
 220      $taskID    = $GLOBALS['egw']->common->get_egwId($guid);
 221      
 222      switch ($contentType) {
 223          case 'text/x-vcalendar':
 224              #$boCalendar    =& CreateObject('calendar.boicalendar');
 225              #return $boCalendar->export(array('l_event_id' => $eventID));
 226              $vcalInfolog    =& CreateObject('infolog.vcalinfolog');
 227              return $vcalInfolog->exportVTODO($taskID,'1.0');
 228              
 229              break;
 230          default:
 231              return PEAR::raiseError(_("Unsupported Content-Type."));
 232      }
 233  }
 234  
 235  /**
 236   * Delete a memo identified by GUID.
 237   *
 238   * @param string | array $guid  Identify the note to delete, either a
 239   *                              single GUID or an array.
 240   *
 241   * @return boolean  Success or failure.
 242   */
 243  function _egwtaskssync_delete($guid)
 244  {
 245      // Handle an arrray of GUIDs for convenience of deleting multiple
 246      // contacts at once.
 247      if (is_array($guid)) {
 248          foreach ($guid as $g) {
 249              $result = _egwtaskssync_delete($g);
 250              if (is_a($result, 'PEAR_Error')) {
 251                  return $result;
 252              }
 253          }
 254          
 255          return true;
 256      }
 257      
 258      return ExecMethod('infolog.boinfolog.delete',$GLOBALS['phpgw']->common->get_egwId($guid));
 259  }
 260  
 261  /**
 262   * Replace the memo identified by GUID with the content represented in
 263   * the specified contentType.
 264   *
 265   * @param string $guid         Idenfity the memo to replace.
 266   * @param string $content      The content of the memo.
 267   * @param string $contentType  What format is the data in? Currently supports:
 268   *                             text/plain
 269   *                             text/x-vnote
 270   *
 271   * @return boolean  Success or failure.
 272   */
 273  function _egwtaskssync_replace($guid, $content, $contentType)
 274  {
 275      Horde::logMessage("SymcML: egwtaskssync replace content: $content contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG);
 276      
 277      $taskID = $GLOBALS['egw']->common->get_egwId($guid);
 278  
 279  
 280      switch ($contentType) {
 281          case 'text/x-vcalendar':
 282              $vcalInfolog    =& CreateObject('infolog.vcalinfolog');
 283  
 284              return $vcalInfolog->importVTODO($content, $taskID);
 285  
 286              break;
 287  
 288          default:
 289              return PEAR::raiseError(_("Unsupported Content-Type."));
 290      }
 291  }
 292  
 293  
 294  function _egwtaskssync_getSyncProfile()
 295  {
 296      $syncProfile = 0;
 297  
 298      $state = $_SESSION['SyncML.state'];
 299      $deviceInfo = $state->getClientDeviceInfo();
 300      
 301      Horde::logMessage("SymcML: egwcontactssync remote device: ". $deviceInfo['model'], __FILE__, __LINE__, PEAR_LOG_DEBUG);
 302      
 303      switch($deviceInfo['model'])
 304      {
 305          case 'SySync Client PalmOS PRO':
 306              $syncProfile = 1;
 307              break;
 308      }
 309      
 310      return $syncProfile;
 311  }


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