[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/phpgwapi/inc/horde/Horde/SyncML/Command/ -> Sync.php (source)

   1  <?php
   2  
   3  include_once 'Horde/SyncML/State.php';
   4  include_once 'Horde/SyncML/Command.php';
   5  include_once 'Horde/SyncML/Command/Sync/SyncElement.php';
   6  include_once 'Horde/SyncML/Sync/TwoWaySync.php';
   7  include_once 'Horde/SyncML/Sync/SlowSync.php';
   8  include_once 'Horde/SyncML/Sync/OneWayFromServerSync.php';
   9  
  10  /**
  11   * $Horde: framework/SyncML/SyncML/Command/Sync.php,v 1.17 2004/07/03 15:21:14 chuck Exp $
  12   *
  13   * Copyright 2003-2004 Anthony Mills <amills@pyramid6.com>
  14   *
  15   * See the enclosed file COPYING for license information (LGPL). If you
  16   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  17   *
  18   * @author  Anthony Mills <amills@pyramid6.com>
  19   * @version $Revision: 21249 $
  20   * @since   Horde 3.0
  21   * @package Horde_SyncML
  22   */
  23  class Horde_SyncML_Command_Sync extends Horde_Syncml_Command {
  24  
  25      var $_isInSource;
  26      var $_currentSyncElement;
  27      var $_syncElements = array();
  28      
  29  	function output($currentCmdID, &$output) {
  30      
  31          $state = &$_SESSION['SyncML.state'];
  32          
  33          $attrs = array();
  34          
  35          Horde::logMessage('SyncML: $this->_targetURI = ' . $this->_targetURI, __FILE__, __LINE__, PEAR_LOG_DEBUG);
  36          
  37          $status = &new Horde_SyncML_Command_Status(RESPONSE_OK, 'Sync');
  38          
  39          // $status->setState($state);
  40          
  41          $status->setCmdRef($this->_cmdID);
  42          
  43          if ($this->_targetURI != null) {
  44              $status->setTargetRef((isset($this->_targetURIParameters) ? $this->_targetURI.'?/'.$this->_targetURIParameters : $this->_targetURI));
  45          }
  46          
  47          if ($this->_sourceURI != null) {
  48              $status->setSourceRef($this->_sourceURI);
  49          }
  50          
  51          $currentCmdID = $status->output($currentCmdID, $output);
  52          
  53          if($sync = $state->getSync($this->_targetURI)) {
  54              $currentCmdID = $sync->startSync($currentCmdID, $output);
  55              
  56              foreach ($this->_syncElements as $element) {
  57                  $currentCmdID = $sync->nextSyncCommand($currentCmdID, $element, $output);
  58              }
  59          }
  60  
  61          return $currentCmdID;
  62      }
  63      
  64  	function getTargetURI() {
  65          return $this->_targetURI;
  66      }
  67  
  68      function startElement($uri, $element, $attrs)
  69      {
  70          parent::startElement($uri, $element, $attrs);
  71  
  72          switch ($this->_xmlStack) {
  73          case 2:
  74              if ($element == 'Replace' || $element == 'Add' || $element == 'Delete') {
  75                  $this->_currentSyncElement = &Horde_SyncML_Command_Sync_SyncElement::factory($element);
  76                  // $this->_currentSyncElement->setVersion($this->_version);
  77                  // $this->_currentSyncElement->setCmdRef($this->_cmdID);
  78                  // $this->_currentSyncElement->setMsgID($this->_msgID);
  79              } elseif ($element == 'Target') {
  80                  $this->_isInSource = false;
  81              } else {
  82                  $this->_isInSource = true;
  83              }
  84              break;
  85          }
  86  
  87          if (isset($this->_currentSyncElement)) {
  88              $this->_currentSyncElement->startElement($uri, $element, $attrs);
  89          }
  90      }
  91      
  92      // We create a seperate Sync Element for the Sync Data sent
  93      // from the Server to the client as we want to process the
  94      // client sync information before.
  95  
  96      function syncToClient($currentCmdID, &$output)
  97      {
  98          Horde::logMessage('SyncML: starting sync to client', __FILE__, __LINE__, PEAR_LOG_DEBUG);
  99  
 100          $state = $_SESSION['SyncML.state'];
 101          if($state->getSyncStatus() >= CLIENT_SYNC_ACKNOWLEDGED && $state->getSyncStatus() < SERVER_SYNC_FINNISHED)
 102          {
 103              $deviceInfo = $state->getClientDeviceInfo();
 104          $state->setSyncStatus(SERVER_SYNC_DATA_PENDING);      
 105              $targets = $state->getTargets();
 106              Horde::logMessage('SyncML: starting sync to client '.$targets[0], __FILE__, __LINE__, PEAR_LOG_DEBUG);
 107              $attrs = array();
 108  
 109          foreach($targets as $target)
 110          {
 111                  $sync = $state->getSync($target);
 112              
 113              $output->startElement($state->getURI(), 'Sync', $attrs);
 114              $output->startElement($state->getURI(), 'CmdID', $attrs);
 115              $output->characters($currentCmdID);
 116              $currentCmdID++;
 117              $output->endElement($state->getURI(), 'CmdID');
 118      
 119              $output->startElement($state->getURI(), 'Target', $attrs);
 120              $output->startElement($state->getURI(), 'LocURI', $attrs);
 121              $chars = $sync->_sourceLocURI;
 122              $output->characters($chars);
 123              $output->endElement($state->getURI(), 'LocURI');
 124              $output->endElement($state->getURI(), 'Target');
 125      
 126              $output->startElement($state->getURI(), 'Source', $attrs);
 127              $output->startElement($state->getURI(), 'LocURI', $attrs);
 128              #$chars = $sync->_targetLocURI;
 129              $chars = (isset($sync->_targetLocURIParameters) ? $sync->_targetLocURI.'?/'.$sync->_targetLocURIParameters : $sync->_targetLocURI);
 130              $output->characters($chars);
 131              $output->endElement($state->getURI(), 'LocURI');
 132              $output->endElement($state->getURI(), 'Source');
 133          
 134              if(!$sync->_syncDataLoaded)
 135              {
 136                  $numberOfItems = $sync->loadData();
 137                  if($deviceInfo['supportNumberOfChanges'])
 138                  {
 139                      $output->startElement($state->getURI(), 'NumberOfChanged', $attrs);
 140                      $output->characters($numberOfItems);
 141                      $output->endElement($state->getURI(), 'NumberOfChanged');
 142                  }
 143              }
 144          
 145              $currentCmdID = $sync->endSync($currentCmdID, $output);
 146          
 147              $output->endElement($state->getURI(), 'Sync');
 148              
 149              break;
 150          }
 151      
 152          // no syncs left
 153          if($state->getTargets() === FALSE)
 154              $state->setSyncStatus(SERVER_SYNC_FINNISHED);
 155      
 156          Horde::logMessage('SyncML: syncStatus(server_sync_finnished) '. $state->getSyncStatus, __FILE__, __LINE__, PEAR_LOG_DEBUG);
 157      }    
 158  
 159      return $currentCmdID;
 160      }
 161  
 162      function endElement($uri, $element)
 163      {
 164          if (isset($this->_currentSyncElement)) {
 165              $this->_currentSyncElement->endElement($uri, $element);
 166          }
 167  
 168          switch ($this->_xmlStack) {
 169          case 2:
 170              if ($element == 'Replace' || $element == 'Add' || $element == 'Delete') {
 171                  $this->_syncElements[] = $this->_currentSyncElement;
 172                  unset($this->_currentSyncElement);
 173              }
 174              break;
 175  
 176          case 3:
 177                $state = & $_SESSION['SyncML.state'];
 178                
 179              if ($element == 'LocURI' && !isset($this->_currentSyncElement)) {
 180                  if ($this->_isInSource) {
 181                      $this->_sourceURI = trim($this->_chars);
 182                      $state->_currentSourceURI = $this->_sourceURI;
 183                  } else {
 184                      $this->_targetURI = trim($this->_chars);
 185  
 186                      $targetURIData = explode('?/',trim($this->_chars));
 187  
 188              $this->_targetURI = $targetURIData[0];
 189              $state->_currentTargetURI = $this->_targetURI;
 190              
 191              if(isset($targetURIData[1]))
 192              {
 193                  $this->_targetURIParameters = $targetURIData[1];
 194                  $state->_currentTargetURIParameters = $this->_targetURIParameters;
 195              }
 196                      
 197                  }
 198              }
 199              break;
 200          }
 201  
 202          parent::endElement($uri, $element);
 203          
 204      }
 205  
 206      function characters($str)
 207      {
 208          if (isset($this->_currentSyncElement)) {
 209              $this->_currentSyncElement->characters($str);
 210          } else {
 211              if (isset($this->_chars)) {
 212                  $this->_chars = $this->_chars . $str;
 213              } else {
 214                  $this->_chars = $str;
 215              }
 216          }
 217      }
 218  
 219  }


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