[ Index ]
 

Code source de Horde 3.1.3

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

title

Body

[fermer]

/services/portal/ -> syncml.php (source)

   1  <?php
   2  /**
   3   * $Horde: horde/services/portal/syncml.php,v 1.3.2.6 2006/05/29 16:40:49 jan Exp $
   4   *
   5   * Copyright 2005-2006 Karsten Fourmont <karsten@horde.org>
   6   *
   7   * See the enclosed file COPYING for license information (LGPL). If you
   8   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
   9   */
  10  
  11  function loadCategories($device)
  12  {
  13      global $dt, $categoriesMap, $missingServerCategories;
  14      $map = $dt->getObject($device
  15                             . ':categories');
  16      if (is_a($map, 'PEAR_Error')) {
  17          return false;
  18      }
  19  
  20      $categoriesMap = $map->get('map');
  21      $missingServerCategories = $map->get('missingServerCategories');
  22  
  23      return true;
  24  }
  25  
  26  function storeCategories($device)
  27  {
  28      global $dt, $categoriesMap, $missingServerCategories;
  29  
  30      if (!is_array($categoriesMap)) {
  31          return; // nothing to do
  32      }
  33  
  34      $map = &new DataTreeObject($device . ':categories');
  35      $map->set('map', $categoriesMap);
  36      $map->set('missingServerCategories', $missingServerCategories);
  37  
  38      $r = $dt->add($map);
  39      if (is_a($r, 'PEAR_Error')) {
  40          // Object already exists: update instead.
  41          $r = $dt->updateData($map);
  42      }
  43  }
  44  
  45  @define('HORDE_BASE', dirname(__FILE__) . '/../..');
  46  require_once  HORDE_BASE . '/lib/base.php';
  47  require_once 'Horde/Prefs/UI.php';
  48  
  49  if (!Auth::isAuthenticated()) {
  50      Horde::authenticationFailureRedirect();
  51  }
  52  
  53  $driver = $GLOBALS['conf']['datatree']['driver'];
  54  $params = Horde::getDriverConfig('datatree', $driver);
  55  $params = array_merge($params, array( 'group' => 'syncml' ));
  56  
  57  $dt = &DataTree::singleton($driver, $params);
  58  
  59  /* Username is used as root for syncml datatree.  (For historic
  60   * reasons.) */
  61  $username = Auth::getAuth();
  62  $group = 'syncml'; // preference group
  63  
  64  $actionID = Util::getFormData('actionID');
  65  switch ($actionID) {
  66  case 'deleteanchor':
  67      $deviceid = Util::getFormData('deviceid');
  68      $db = Util::getFormData('db');
  69      $id = $username . ':' . $deviceid . ':summary:' . $db;
  70      $id = $dt->remove($id,false);
  71      if (is_a($id, 'PEAR_Error')) {
  72          $notification->push(sprintf(_("Error deleting sync anchor: %s"), $id->getMessage()),
  73                              'horde.error');
  74      } else {
  75          $notification->push(_("$id Sync anchor for device '$deviceid' database '$db' deleted."),
  76                              'horde.success');
  77      }
  78      break;
  79  
  80  case 'deletelog':
  81      $id = $dt->remove('previousSyncLog', false);
  82      if (is_a($id, 'PEAR_Error')) {
  83          $notification->push(sprintf(_("Error deleting sync log: %s"), $id->getMessage()),
  84                              'horde.error');
  85      } else {
  86          $notification->push(_("Sync log deleted"),
  87                              'horde.success');
  88      }
  89      break;
  90  
  91   case 'update_categories':
  92      $device = Util::getFormData('device');
  93      loadCategories($device);
  94  
  95      foreach ($_POST as $key => $value) {
  96          if (substr($key, 0, 9) == 'category:') {
  97              $category = substr($key,9);
  98              list(,$category) = explode(':', $key,2);
  99              $value = Util::getFormData($key);
 100              $categoriesMap[$category] = $value;
 101              unset($missingServerCategories[$value]);
 102          }
 103      }
 104      storeCategories($device);
 105      $notification->push(_("Mappings stored."));
 106  
 107      break;
 108  }
 109  
 110  /* Show the header. */
 111  require_once 'Horde/Prefs/UI.php';
 112  require HORDE_BASE . '/config/prefs.php';
 113  $app = 'horde';
 114  
 115  Prefs_UI::handleForm($group, $prefs);
 116  Prefs_UI::generateHeader($group);
 117  
 118  // @todo: move this to template
 119  ?>
 120  
 121  <form method="post" name="prefs" action="<?php echo Horde::ApplicationURL('/services/prefs.php') ?>">
 122  <input type="hidden" name="actionID" value="update_prefs" />
 123  <input type="hidden" name="group" value="<?php echo $group ?>" />
 124  <input type="hidden" name="app" value="horde" />
 125  Sorry, no configurable options yet.
 126  See <a href="http://wiki.horde.org/SyncHowTo">Sync HowTo</a> for further information.
 127  <?php /* $helplink=''; $pref='syncml_create_log'; require $registry->get('templates', 'horde') . '/prefs/checkbox.inc' */ ?>
 128  
 129  <p class="nowrap">
 130   <input type="submit" class="button" value="Save Options" />
 131   <input type="reset" class="button" value="Undo Changes" />
 132   <input type="button" class="button" value="Return to Options" onclick="document.prefs.actionID.value=0; document.prefs.group.value=''; document.prefs.submit();" />
 133  </p>
 134  </form>
 135  <?php
 136  $id = $dt->getId($username);
 137  $devices = $dt->getById(DATATREE_FORMAT_FLAT, $id, true, DATATREE_ROOT, 1);
 138  if (is_array($devices) && count($devices) > 1) {
 139      array_shift($devices);
 140  
 141  // @todo: move to template
 142  ?>
 143  <div class="header">
 144   <?php echo Horde::link(Horde::selfURL(), _("Refresh")) . Horde::img('reload.png', _("Reload"), '', $registry->getImageDir('horde')) ?></a>
 145   Timestamps of successful sync sessions
 146  </div>
 147  <table class="striped" >
 148   <tr>
 149    <th>Device</th><th>Database</th><th>Server-TS</th><th>Client-TS</th>
 150    <th>Delete</th>
 151   </tr>
 152  
 153  <?php
 154      foreach ($devices as $device) {
 155          $tmp = explode(':', $device);
 156          $device_name = array_pop($tmp);
 157  
 158          $id = $dt->getId($device . ':summary');
 159          if (is_a($id, 'PEAR_Error')) {
 160              continue;
 161          }
 162          $summaries = $dt->getById(DATATREE_FORMAT_TREE, $id, false,
 163                                    DATATREE_ROOT, 2);
 164  
 165          if (is_array($summaries[$id])) {
 166              $o = & $dt->getObjects(array_keys($summaries[$id]));
 167  
 168              foreach ($o as $oo) {
 169                  $t = explode(':', $oo->getName());
 170                  $db = array_pop($t);
 171                  $sa = $oo->get('ServerAnchor');
 172                  $ca = $oo->get("ClientAnchor");
 173  
 174                  // @todo: move to template
 175                  echo '<tr><td>' . $device_name . '</td><td>' . $db . '</td><td>' .
 176                      strftime($prefs->getValue('date_format') . ' %H:%M', array_pop($sa)) .
 177                      '</td><td>' . array_pop($ca) . '</td><td>' .
 178                      '<form method="post"><input type="hidden" name="deviceid" value="' .
 179                      $device_name . '"/>' .
 180                      '<input type="hidden" name="actionID" value="deleteanchor" />' .
 181                      '<input type="hidden" name="db" value="' . $db . '" />' .
 182                      '<input type="submit" class="button" value="Delete" /></form>' .
 183                      '</td></tr>';
 184              }
 185          }
 186      }
 187      echo '</table>';
 188  }
 189  
 190  // Category handling.
 191  require_once  'Horde/Prefs/CategoryManager.php';
 192  $cManager = &new Prefs_CategoryManager();
 193  
 194  foreach ($devices as $device) {
 195      $tmp = explode(':', $device);
 196      $device_name = array_pop($tmp);
 197  
 198      if (!loadCategories($device)) {
 199          continue;
 200      }
 201  //var_dump($clien
 202      $i = 0;
 203  // @todo: move to template
 204  ?>
 205  <form method="post" name="prefs" action="<?php echo Horde::selfURL() ?>">
 206  <input type="hidden" name="actionID" value="update_categories" />
 207  <input type="hidden" name="device" value="<?php echo $device ?>" />
 208  
 209  <div class="header">
 210   <?php echo Horde::link(Horde::selfURL(), _("Refresh")) . Horde::img('reload.png', _("Reload"), '', $registry->getImageDir('horde')) ?></a>
 211   Mapping of Categories for Device <?php echo $device_name ?>
 212  </div>
 213  <table class="striped" >
 214  <tr><th>Device Category</th><th>Horde Category</th>
 215  <th>Summary of last encountered entry</th></tr>
 216  <?php
 217      foreach ($categoriesMap as $key => $value) {
 218          echo "<tr class=\"item" . (++$i % 2) . "\"><td>"
 219          . $key. '</td><td>';
 220          $v = is_array($value) ? '' : $value;
 221          echo $cManager->getSelect('category:' . $key, $v);
 222          echo '</td><td>';
 223          if (is_array($value)) {
 224              echo $value[0];
 225          } else {
 226              echo "&nbsp;";
 227          }
 228          echo '</td></tr>';
 229  
 230      }
 231      foreach ($missingServerCategories as $key => $value) {
 232          echo '<tr><td><em>to be defined</em></td><td>' . $key . '</td><td>' . $value . '</td></tr>';
 233      }
 234  
 235      echo "</table>\n";
 236      echo '<input type="submit" class="button" value="Update Categories" /></form>';
 237  }
 238  
 239  /* Display log of previous sync. */
 240  $name = 'previousSyncLog';
 241  $info = &$dt->getObject($name);
 242  
 243  if (!is_a($info, 'PEAR_Error') && is_array($log = $info->get('log'))) {
 244      // @todo move to template
 245  ?>
 246  <div class="header">
 247   <?php echo _("Log of previous sync session") ?>
 248   <?php echo Horde::link(Horde::selfURL(), _("Refresh")) . Horde::img('reload.png', _("Refresh")) ?></a>
 249   <form method="post">
 250    <input type="hidden" name="actionID" value="deletelog" />
 251    <input type="submit" class="button" value="<?php echo _("Delete Log") ?>" />
 252   </form>
 253  </div>
 254  
 255  <table class="striped" width="100%">
 256   <tr class="nowrap">
 257    <th width="5%"><?php echo _("Time") ?></th><th><?php echo _("Level") ?></th><th><?php echo _("File") ?></th><th><?php echo _("Message") ?></th>
 258   </tr>
 259  <?php foreach ($log as $logentry): ?>
 260   <tr>
 261    <td>
 262     <?php echo strftime($prefs->getValue('date_format') . ' %H:%M:%S', $logentry['ts']) ?>
 263    </td>
 264    <td>
 265     <?php echo htmlspecialchars($logentry['level']) ?>
 266    </td>
 267    <td>
 268    <?php
 269    if (preg_match('/\/SyncML\.php$/', $logentry['file'])) {
 270        $file = 'framework/SyncML/SyncML.php';
 271    } else {
 272        $file = preg_replace('/^.*\/SyncML\/(.*)$/', 'framework/SyncML/SyncML/$1', $logentry['file']);
 273    }
 274    echo Horde::link('http://cvs.horde.org/co.php/'
 275                     . $file  . '?r=HEAD#' . trim($logentry['line']), '', '', 'cvs')
 276        . preg_replace('/^.*\/([^\/]*)$/', '$1', $logentry['file'])
 277        . ':' . trim($logentry['line'])
 278    ?>
 279    </td>
 280    <td>
 281     <?php echo htmlspecialchars($logentry['message']) ?>
 282    </td>
 283   </tr>
 284  <?php endforeach; ?>
 285  </table>
 286  
 287  <?php
 288  }
 289  
 290  require  HORDE_TEMPLATES . '/common-footer.inc';


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