[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/phpgwapi/inc/ -> class.xmlrpc_server.inc.php (source)

   1  <?php
   2    /**************************************************************************\
   3    * eGroupWare API - XML-RPC Server                                          *
   4    * ------------------------------------------------------------------------ *
   5    * This library is part of the eGroupWare API                               *
   6    * http://www.egroupware.org/api                                            *
   7    * ------------------------------------------------------------------------ *
   8    * This library is free software; you can redistribute it and/or modify it  *
   9    * under the terms of the GNU Lesser General Public License as published by *
  10    * the Free Software Foundation; either version 2.1 of the License,         *
  11    * or any later version.                                                    *
  12    * This library is distributed in the hope that it will be useful, but      *
  13    * WITHOUT ANY WARRANTY; without even the implied warranty of               *
  14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
  15    * See the GNU Lesser General Public License for more details.              *
  16    * You should have received a copy of the GNU Lesser General Public License *
  17    * along with this library; if not, write to the Free Software Foundation,  *
  18    * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
  19    \**************************************************************************/
  20  
  21    /* $Id: class.xmlrpc_server.inc.php 20295 2006-02-15 12:31:25Z  $ */
  22  
  23      // contains useful functions for xmlrpc methods
  24      class xmlrpc_server_shared
  25      {
  26          var $simpledate = False;
  27  
  28          // convert a date-array or timestamp into a datetime.iso8601 string
  29  		function date2iso8601($date)
  30          {
  31              if (!is_array($date))
  32              {
  33                  if($this->simpledate)
  34                  {
  35                      return date('Ymd\TH:i:s',$date);
  36                  }
  37                  return date('Y-m-d\TH:i:s',$date);
  38              }
  39  
  40              $formatstring = "%04d-%02d-%02dT%02d:%02d:%02d";
  41              if($this->simpledate)
  42              {
  43                  $formatstring = "%04d%02d%02dT%02d:%02d:%02d";
  44              }
  45              return sprintf($formatstring,
  46                  $date['year'],$date['month'],$date['mday'],
  47                  $date['hour'],$date['min'],$date['sec']);
  48          }
  49  
  50          // convert a datetime.iso8601 string into a datearray or timestamp
  51  		function iso86012date($isodate,$timestamp=False)
  52          {
  53              $arr = array();
  54  
  55              if (ereg('^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})$',$isodate,$arr))
  56              {
  57                  // $isodate is simple ISO8601, remove the difference between split and ereg
  58                  array_shift($arr);
  59              }
  60              elseif (($arr = split('[-:T]',$isodate)) && count($arr) == 6)
  61              {
  62                  // $isodate is extended ISO8601, do nothing
  63              }
  64              else
  65              {
  66                  return False;
  67              }
  68  
  69                  foreach(array('year','month','mday','hour','min','sec') as $n => $name)
  70                  {
  71                      $date[$name] = (int)$arr[$n];
  72                  }
  73                  return $timestamp ? mktime($date['hour'],$date['min'],$date['sec'],
  74                      $date['month'],$date['mday'],$date['year']) : $date;
  75              }
  76  
  77          // translate cat-ids to array with id-name pairs
  78  		function cats2xmlrpc($cats)
  79          {
  80              if (!is_object($GLOBALS['egw']->categories))
  81              {
  82                  $GLOBALS['egw']->categories = CreateObject('phpgwapi.categories');
  83              }
  84              $xcats = array();
  85              foreach($cats as $cat)
  86              {
  87                  if ($cat)
  88                  {
  89                      $xcats[$cat] = stripslashes($GLOBALS['egw']->categories->id2name($cat));
  90                  }
  91              }
  92              return $xcats;
  93          }
  94  
  95          // translate cats back to cat-ids, creating / modifying cats on the fly
  96  		function xmlrpc2cats($xcats)
  97          {
  98              if (!is_array($xcats))
  99              {
 100                  $xcats = array();
 101              }
 102              elseif (!is_object($GLOBALS['egw']->categories))
 103              {
 104                  $GLOBALS['egw']->categories = CreateObject('phpgwapi.categories');
 105              }
 106              $cats = array();
 107              foreach($xcats as $cat => $name)
 108              {
 109                  if ($id = $GLOBALS['egw']->categories->name2id($name))
 110                  {
 111                      // existing cat-name use the id
 112                      $cat = $id;
 113                  }
 114                  elseif (!($org_name = stripslashes($GLOBALS['egw']->categories->id2name($cat))) || $org_name == '--')
 115                  {
 116                      // new cat
 117                      $cat = $GLOBALS['egw']->categories->add(array('name' => $name,'parent' => 0));
 118                  }
 119                  elseif ($org_name != $name)
 120                  {
 121                      // cat-name edited
 122                      list($cat_vals) =$GLOBALS['egw']->categories->return_single($cat);
 123                      $cat_vals['name'] = $name;
 124                      $GLOBALS['egw']->categories->edit($cat_vals);
 125                  }
 126                  $cats[] = (int)$cat;
 127              }
 128              return $cats;
 129          }
 130  
 131          // get list (array with id-name pairs) of all cats of $app
 132  		function categories($complete = False,$app = '')
 133          {
 134              if (is_array($complete))
 135              {
 136                  $complete = @$complete[0];
 137              }
 138              if (!$app)
 139              {
 140                  list($app) = explode('.',$this->last_method);
 141              }
 142  
 143              if (!is_object($GLOBALS['egw']->categories))
 144              {
 145                  $GLOBALS['egw']->categories = CreateObject('phpgwapi.categories');
 146              }
 147              if ($GLOBALS['egw']->categories->app_name != $app)
 148              {
 149                  $GLOBALS['egw']->categories->categories('',$app);
 150              }
 151              $cats_arr = $GLOBALS['egw']->categories->return_sorted_array(0,False,'','','',True);
 152              $cats = array();
 153              if (is_array($cats_arr))
 154              {
 155                  foreach($cats_arr as $cat)
 156                  {
 157                      foreach(array('name','description') as $name)
 158                      {
 159                          $cat[$name] = stripslashes($cat[$name]);
 160                      }
 161                      $cats[$cat['id']] = $complete ? $cat : $cat['name'];
 162                  }
 163              }
 164              return $cats;
 165          }
 166  
 167  		function setSimpleDate($enable=True)
 168          {
 169              $this->simpledate = $enable;
 170          }
 171      }
 172  
 173      if(empty($GLOBALS['egw_info']['server']['xmlrpc_type']))
 174      {
 175          $GLOBALS['egw_info']['server']['xmlrpc_type'] = 'php';
 176      }
 177      include_once(EGW_API_INC.SEP.'class.xmlrpc_server_' . $GLOBALS['egw_info']['server']['xmlrpc_type'] . '.inc.php');


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