[ Index ]
 

Code source de Horde 3.1.3

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

title

Body

[fermer]

/lib/Net/IMSP/ -> Utils.php (source)

   1  <?php
   2  /**
   3   * Net_IMSP_Utils::
   4   *
   5   * $Horde: framework/Net_IMSP/IMSP/Utils.php,v 1.3.10.7 2006/01/01 21:28:28 jan Exp $
   6   *
   7   * Copyright 2003-2006 Michael Rubinsky <mrubinsk@horde.org>
   8   *
   9   * See the enclosed file COPYING for license information (LGPL). If you
  10   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  11   *
  12   * @author  Michael Rubinsky <mrubinsk@horde.org>
  13   * @package Net_IMSP
  14   */
  15  class Net_IMSP_Utils {
  16  
  17      /**
  18       * Utility function to retrieve the names of all the address books
  19       * that the user has access to, along with the acl for those
  20       * books.  For information about the $serverInfo array see
  21       * turba/config/sources.php as this is the cfgSources[] entry for
  22       * the address books.
  23       *
  24       * @param array $serverInfo  Information about the server
  25       *                           and the current user.
  26       *
  27       * @return array  Information about all the address books or PEAR_Error.
  28       */
  29      function getAllBooks($serverInfo)
  30      {
  31          require_once 'Net/IMSP.php';
  32          $foundDefault = false;
  33          $results = array();
  34          $imsp = &Net_IMSP::singleton('Book', $serverInfo['params']);
  35          $result = $imsp->init();
  36  
  37          if (is_a($result, 'PEAR_Error')) {
  38              return $result;
  39          }
  40  
  41          $books = $imsp->getAddressBookList();
  42          if (is_a($books, 'PEAR_Error')) {
  43              return $books;
  44          }
  45  
  46          $bCount = count($books);
  47          for ($i = 0; $i < $bCount; $i++) {
  48              $newBook = $serverInfo;
  49              if ($books[$i] != $serverInfo['params']['username']) {
  50                  $newBook['title'] = 'IMSP_' . $books[$i];
  51                  $newBook['params']['name'] = $books[$i];
  52                  $newBook['params']['is_root'] = false;
  53                  $newBook['params']['my_rights'] = $imsp->myRights($books[$i]);
  54              } else {
  55                  $foundDefault = true;
  56                  $newBook['params']['my_rights'] = $imsp->myRights($books[$i]);
  57              }
  58              $results[] = $newBook;
  59          }
  60          /* If there is no default address book (named username) then we should create one. */
  61          if (!$foundDefault) {
  62              $result = $imsp->createAddressBook($serverInfo['params']['username']);
  63              if (is_a($result, 'PEAR_Error')) {
  64                  return PEAR::raiseError('Login to IMSP host failed.' .
  65                                          ': Default address book is missing and could not be created.');
  66              }
  67          }
  68          return $results;
  69      }
  70  
  71      /**
  72       * Utility function to make it easier for client applications to delete
  73       * address books without having to create imsp drivers.  The $source array
  74       * is a horde/turba style $cfgSources entry for the address book being
  75       * deleted.
  76       *
  77       * @param array $source  Information about the address book being deleted.
  78       *
  79       * @return mixed  True on success or PEAR_Error on failure.
  80       */
  81      function deleteBook($source)
  82      {
  83          require_once 'Net/IMSP.php';
  84          $imsp = &Net_IMSP::singleton('Book', $source['params']);
  85          $result = $imsp->init();
  86          if (is_a($result, 'PEAR_Error')) {
  87              return $result;
  88          }
  89          $result = $imsp->deleteAddressBook($source['params']['name']);
  90          if (is_a($result, 'PEAR_Error')) {
  91              return $result;
  92          }
  93          return true;
  94      }
  95  
  96      /**
  97       * Utility function to help clients create new address books without having
  98       * to create an imsp driver instance first.
  99       *
 100       * @param array $source    Information about the user's default IMSP
 101       *                         address book.
 102       * @param string $newName  The name of the new address book.  Note that this
 103       *                         is automatically qualified with the user's name
 104       *                         so should not be passed as a fully qualified IMSP
 105       *                         address book name.
 106       *
 107       * @return mixed  true on success or PEAR_Error on failure.
 108       */
 109       function createBook($source, $newName)
 110      {
 111          require_once 'Net/IMSP.php';
 112          $imsp = &Net_IMSP::singleton('Book', $source['params']);
 113          $result = $imsp->init();
 114          if (is_a($result, 'PEAR_Error')) {
 115              return $result;
 116          }
 117          $name = $source['params']['username'] . '.' . $newName;
 118          $result = $imsp->createAddressBook($name);
 119          if (is_a($result, 'PEAR_Error')) {
 120              return $result;
 121          }
 122          return true;
 123      }
 124  }


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