[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/syncml/notes/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['export'] = array(
  29      'args' => array('guid', 'contentType'),
  30      'type' => 'string'
  31  );
  32  
  33  $_services['delete'] = array(
  34      'args' => array('guid'),
  35      'type' => 'boolean'
  36  );
  37  
  38  $_services['replace'] = array(
  39      'args' => array('guid', 'content', 'contentType'),
  40      'type' => 'boolean'
  41  );
  42  
  43  
  44  /**
  45   * Returns an array of GUIDs for all notes that the current user is
  46   * authorized to see.
  47   *
  48   * @return array  An array of GUIDs for all notes the user can access.
  49   */
  50  function _egwnotessync_list()
  51  {
  52      $guids = array();
  53  
  54      #Horde::logMessage("SymcML: egwnotessync list ", __FILE__, __LINE__, PEAR_LOG_DEBUG);
  55      
  56      $searchFilter = array
  57      (
  58          'order'        => 'info_datemodified',
  59          'sort'        => 'DESC',
  60          'filter'    => 'own',
  61          'col_filter'    => Array
  62          (
  63              'info_type'    => 'note',
  64          ),
  65      );
  66      
  67      $notes =& ExecMethod('infolog.boinfolog.search',$searchFilter);
  68      
  69      foreach((array)$notes as $note)
  70      {
  71          $guids[] = $GLOBALS['egw']->common->generate_uid('infolog_note',$note['info_id']);
  72      }
  73      return $guids;
  74  }
  75  
  76  /**
  77   * Returns an array of GUIDs for notes that have had $action happen
  78   * since $timestamp.
  79   *
  80   * @param string  $action     The action to check for - add, modify, or delete.
  81   * @param integer $timestamp  The time to start the search.
  82   *
  83   * @return array  An array of GUIDs matching the action and time criteria.
  84   */
  85  function &_egwnotessync_listBy($action, $timestamp)
  86  {
  87      #Horde::logMessage("SymcML: egwnotessync listBy action: $action timestamp: $timestamp", __FILE__, __LINE__, PEAR_LOG_DEBUG);
  88      
  89      $allChangedItems = $GLOBALS['egw']->contenthistory->getHistory('infolog_note', $action, $timestamp);
  90      
  91      if($action == 'delete')
  92      {
  93          return $allChangedItems;    // InfoLog has no further info about deleted entries
  94      }
  95      $boInfolog =& CreateObject('infolog.boinfolog');
  96      $user = $GLOBALS['egw_info']['user']['account_id'];
  97  
  98      $readAbleItems = array();
  99      foreach($allChangedItems as $guid)
 100      {
 101          $uid = $GLOBALS['egw']->common->get_egwId($guid);
 102  
 103          if(($info = $boInfolog->read($uid)) &&        // checks READ rights too and returns false if none
 104              // for filter my = all items the user is responsible for:
 105              //($user == $info['info_owner'] && !count($info['info_responsible']) || in_array($user,$info['info_responsible'])))
 106              // for filter own = all items the user own or is responsible for:
 107              ($user == $info['info_owner'] || in_array($user,$info['info_responsible'])))
 108          {
 109              $readAbleItems[] = $guid;
 110          }
 111      }
 112      return $readAbleItems;
 113  }
 114  
 115  /**
 116   * Import a memo represented in the specified contentType.
 117   *
 118   * @param string $content      The content of the memo.
 119   * @param string $contentType  What format is the data in? Currently supports:
 120   *                             text/plain
 121   *                             text/x-vnote
 122   * @param string $notepad      (optional) The notepad to save the memo on.
 123   *
 124   * @return string  The new GUID, or false on failure.
 125   */
 126  function _egwnotessync_import($content, $contentType, $notepad = null)
 127  {
 128      Horde::logMessage("SymcML: egwnotessync import content: ... contenttype: $contentType", __FILE__, __LINE__, PEAR_LOG_DEBUG);
 129  #    global $prefs;
 130  #    require_once dirname(__FILE__) . '/base.php';
 131  #    require_once 'Horde/History.php';
 132  #    $history = &Horde_History::singleton();
 133  #
 134  #    /* Make sure we have a valid notepad and permissions to edit
 135  #     * it. */
 136  #    if (empty($notepad)) {
 137  #        $notepad = Mnemo::getDefaultNotepad(PERMS_EDIT);
 138  #    }
 139  #
 140  #    if (!array_key_exists($notepad, Mnemo::listNotepads(false, PERMS_EDIT))) {
 141  #        return PEAR::raiseError(_("Permission Denied"));
 142  #    }
 143  #
 144  #    /* Create a Mnemo_Driver instance. */
 145  #    require_once MNEMO_BASE . '/lib/Driver.php';
 146  #    $storage = &Mnemo_Driver::singleton($notepad);
 147  #
 148      $botranslation    =& CreateObject('phpgwapi.translation');
 149      
 150      switch ($contentType) {
 151          case 'text/plain':
 152              $content = $botranslation->convert($content,'utf-8');
 153              $noteId = ExecMethod('infolog.boinfolog.write',array('info_des' => $content, 'info_type' => 'note'));
 154              
 155              break;
 156  
 157          case 'text/x-vnote':
 158              require_once (EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar.php');
 159  
 160              
 161              // Create new note.
 162              $vNote = Horde_iCalendar::newComponent('vnote', $container);
 163              
 164              if (!$vNote->parsevCalendar($content)) {
 165                  return PEAR::raiseError(_("There was an error importing the vNote data."));
 166              }
 167              $vNoteValues = $vNote->getAllAttributes();
 168              
 169              $note['info_type'] = 'note';
 170              foreach($vNoteValues as $vNoteRow)
 171              {
 172                  #if(is_array($vNoteRow))
 173                  #{
 174                  #    foreach($value as $key2 => $value2)
 175                  #    {
 176                  #        Horde::logMessage("SymcML: egwnotessync import vnote $key2 => $value2", __FILE__, __LINE__, PEAR_LOG_DEBUG);
 177                  #    }
 178                  #}
 179                  switch($vNoteRow['name'])
 180                  {
 181                      case 'BODY':
 182                          $note['info_des'] = $vNoteRow['value'];
 183                          break;
 184                      case 'SUMMARY':
 185                          $note['info_subject'] = $vNoteRow['value'];
 186                          break;
 187                  }
 188              }
 189  
 190              $noteId = ExecMethod('infolog.boinfolog.write',$note);
 191  
 192              break;
 193  
 194          default:
 195              return PEAR::raiseError(_("Unsupported Content-Type."));
 196      }
 197      
 198      if (is_a($noteId, 'PEAR_Error')) {
 199          return $noteId;
 200      }
 201  
 202      #Horde::logMessage("SymcML: egwnotessync import imported: ".$GLOBALS['egw']->common->generate_uid('infolog',$noteId), __FILE__, __LINE__, PEAR_LOG_DEBUG);
 203      return $GLOBALS['egw']->common->generate_uid('infolog_note',$noteId);
 204  }
 205  
 206  /**
 207   * Export a memo, identified by GUID, in the requested contentType.
 208   *
 209   * @param string $guid         Identify the memo to export.
 210   * @param mixed  $contentType  What format should the data be in?
 211   *                             Either a string with one of:
 212   *                              'text/plain'
 213   *                              'text/x-vnote'
 214   *                             or an array with options:
 215   *                             'ContentType':  as above
 216   *                             'ENCODING': (optional) character encoding
 217   *                                         for strings fields
 218   *                             'CHARSET':  (optional) charset. Like UTF-8
 219   *
 220   * @return string  The requested data.
 221   */
 222  function _egwnotessync_export($guid, $contentType)
 223  {
 224      Horde::logMessage("SymcML: egwnotessync export guid: $guid contenttype: ".$contentType, __FILE__, __LINE__, PEAR_LOG_DEBUG);
 225  #    require_once dirname(__FILE__) . '/base.php';
 226  #
 227  #    $storage = &Mnemo_Driver::singleton();
 228  #    $memo = $storage->getByGUID($guid);
 229  #    if (is_a($memo, 'PEAR_Error')) {
 230  #        return $memo;
 231  #    }
 232  #
 233  #    if (!array_key_exists($memo['memolist_id'], Mnemo::listNotepads(false, PERMS_EDIT))) {
 234  #        return PEAR::raiseError(_("Permission Denied"));
 235  #    }
 236  #
 237      if (is_array($contentType)) {
 238          $options = $contentType;
 239          $contentType = $options['ContentType'];
 240          unset($options['ContentType']);
 241      } else {
 242          $options = array();
 243      }
 244      
 245      $botranslation =& CreateObject('phpgwapi.translation');
 246      
 247      switch ($contentType) {
 248          case 'text/plain':
 249              if($note = ExecMethod('infolog.boinfolog.read',$GLOBALS['egw']->common->get_egwId($guid)))
 250              {
 251                  $utf8EncodedNote = $botranslation->convert(trim($note['info_des']),$GLOBALS['egw']->translation->charset(),'utf-8');
 252  
 253                  return $utf8EncodedNote;
 254              }
 255              else
 256              {
 257                  return PEAR::raiseError(_("Access Denied"));
 258              }
 259  
 260              break;
 261              
 262          case 'text/x-vnote':
 263              if($note = ExecMethod('infolog.boinfolog.read',$GLOBALS['egw']->common->get_egwId($guid)))
 264              {
 265                  require_once  EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar/vnote.php';
 266              
 267                  // Create the new iCalendar container.
 268                  $vNote = &new Horde_iCalendar_vnote();
 269                  $vNote->setAttribute('VERSION', '1.1');
 270                  #$vNote->setAttribute('PRODID', '-//The Horde Project//Mnemo //EN');
 271                  #$vNote->setAttribute('METHOD', 'PUBLISH');
 272                  #$vNote->setAttribute('BODY',$botranslation->convert(trim($note['info_des']),$GLOBALS['egw']->translation->charset(),'utf-8'));
 273                  $vNote->setAttribute('BODY','ballo');
 274                  $vNote->setAttribute('SUMMARY','sallo');
 275                  #$vNote->setAttribute('DCREATED','20050609T042643');
 276                  #$vNote->setAttribute('LAST-MODIFIED','20050609T082941');
 277                  // Create a new vNote.
 278                  #$vNote = $storage->toiCalendar($memo, $iCal);
 279              
 280                  // Set encoding options for all string values. For vNotes,
 281                  // just BODY.
 282                  #$params['ENCODING'] = 'QUOTED-PRINTABLE';
 283                  #$vNote->setParameter('BODY', $params);
 284              
 285                  return $vNote->exportvCalendar();
 286              }
 287              else
 288              {
 289                  return PEAR::raiseError(_("Access Denied"));
 290              }
 291              
 292              break;
 293              
 294          default:
 295              return PEAR::raiseError(_("Unsupported Content-Type."));
 296      }
 297  }
 298  
 299  /**
 300   * Delete a memo identified by GUID.
 301   *
 302   * @param string | array $guid  Identify the note to delete, either a
 303   *                              single GUID or an array.
 304   *
 305   * @return boolean  Success or failure.
 306   */
 307  function _egwnotessync_delete($guid)
 308  {
 309      // Handle an arrray of GUIDs for convenience of deleting multiple
 310      // notes at once.
 311      if (is_array($guid)) {
 312          foreach ($guid as $g) {
 313              $result = _egwnotessync_delete($guid);
 314              if (is_a($result, 'PEAR_Error')) {
 315                  return $result;
 316              }
 317          }
 318          return true;
 319      }
 320  
 321      #$memo = $storage->getByGUID($guid);
 322      #if (is_a($memo, 'PEAR_Error')) {
 323      #    return $memo;
 324      #}
 325      #
 326      #if (!array_key_exists($memo['memolist_id'], Mnemo::listNotepads(false, PERMS_DELETE))) {
 327      #    return PEAR::raiseError(_("Permission Denied"));
 328      #}
 329      #
 330      
 331      return ExecMethod('infolog.boinfolog.delete',$GLOBALS['egw']->common->get_egwId($guid));
 332  }
 333  
 334  /**
 335   * Replace the memo identified by GUID with the content represented in
 336   * the specified contentType.
 337   *
 338   * @param string $guid         Idenfity the memo to replace.
 339   * @param string $content      The content of the memo.
 340   * @param string $contentType  What format is the data in? Currently supports:
 341   *                             text/plain
 342   *                             text/x-vnote
 343   *
 344   * @return boolean  Success or failure.
 345   */
 346  function _egwnotessync_replace($guid, $content, $contentType)
 347  {
 348      #Horde::logMessage("SymcML: egwnotessync replace guid: $guid", __FILE__, __LINE__, PEAR_LOG_DEBUG);
 349  
 350      #$memo = $storage->getByGUID($guid);
 351      #if (is_a($memo, 'PEAR_Error')) {
 352      #    return $memo;
 353      #}
 354      #
 355      #if (!array_key_exists($memo['memolist_id'], Mnemo::listNotepads(false, PERMS_EDIT))) {
 356      #    return PEAR::raiseError(_("Permission Denied"));
 357      #}
 358      
 359      $botranslation    =& CreateObject('phpgwapi.translation');
 360      
 361      $infoId = $GLOBALS['egw']->common->get_egwId($guid);
 362      
 363      switch ($contentType) {
 364          case 'text/plain':
 365              $content = $botranslation->convert($content,'utf-8');
 366              $result = ExecMethod('infolog.boinfolog.write',array('info_des' => $content, 'info_type' => 'note', 'info_id' => $infoId));
 367              
 368              return $result;
 369  
 370          case 'text/x-vnote':
 371              require_once (EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar.php');
 372              // Create new note.
 373              $vNote = Horde_iCalendar::newComponent('vnote', $container);
 374              
 375              if (!$vNote->parsevCalendar($content)) {
 376                  return PEAR::raiseError(_("There was an error importing the vNote data."));
 377              }
 378              $vNoteValues = $vNote->getAllAttributes();
 379              
 380              $note['info_type'] = 'note';
 381              $note['info_id'] = $infoId;
 382              foreach($vNoteValues as $vNoteRow)
 383              {
 384                  switch($vNoteRow['name'])
 385                  {
 386                      case 'BODY':
 387                          $note['info_des'] = $vNoteRow['value'];
 388                          break;
 389                      case 'SUMMARY':
 390                          $note['info_subject'] = $vNoteRow['value'];
 391                          break;
 392                  }
 393              }
 394  
 395              $result = ExecMethod('infolog.boinfolog.write',$note);
 396              return $result;
 397  
 398          default:
 399              return PEAR::raiseError(_("Unsupported Content-Type."));
 400      }
 401  }


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