[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/preferences/inc/ -> class.bosettings.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare - Preferences                                                 *
   4      * http://www.egroupware.org                                                *
   5      * --------------------------------------------                             *
   6      *  This program is free software; you can redistribute it and/or modify it *
   7      *  under the terms of the GNU General Public License as published by the   *
   8      *  Free Software Foundation; either version 2 of the License, or (at your  *
   9      *  option) any later version.                                              *
  10      \**************************************************************************/
  11  
  12      /* $Id: class.bosettings.inc.php 19663 2005-11-08 09:42:42Z ralfbecker $ */
  13  
  14      class bosettings
  15      {
  16          var $xmlrpc = False;
  17          var $session_data = array();
  18          var $settings = array();
  19          var $prefs = array();
  20          var $appname = '';
  21          var $debug = False;
  22  
  23          var $public_functions = array(
  24              'read' => True,
  25              'process_array' => True
  26          );
  27  
  28          var $xml_functions  = array();
  29          var $xmlrpc_methods = array();
  30          var $soap_functions = array(
  31              'read' => array(
  32                  'in'  => array('int','int','struct','string','int'),
  33                  'out' => array('array')
  34              ),
  35              'process_array' => array(
  36                  'in'  => array('int','struct'),
  37                  'out' => array('array')
  38              ),
  39              'list_methods' => array(
  40                  'in' => array('string'),
  41                  'out' => array('struct')
  42              )
  43          );
  44  
  45  		function bosettings($appname='')
  46          {
  47              $this->xmlrpc = @is_object($GLOBALS['server']) && $GLOBALS['server']->last_method;
  48              $this->session_data = $GLOBALS['egw']->session->appsession('session_data','preferences');
  49  
  50              $this->appname = $appname;
  51          }
  52  
  53  		function save_session($appname,$type,$show_help,$prefix,$notifies='',$referer='')
  54          {
  55              $GLOBALS['egw']->session->appsession('session_data','preferences',array(
  56                  'type'      => $type,    // save our state in the app-session
  57                  'show_help' => $show_help,
  58                  'prefix'    => $prefix,
  59                  'appname'   => $appname,        // we use this to reset prefix on appname-change
  60                  'notifies'  => $notifies,
  61                  'referer'   => $referer ? $referer : $this->session_data['referer'],
  62              ));
  63          }
  64  
  65  		function call_hook($appname)
  66          {
  67              $this->appname = $appname;
  68  
  69              $GLOBALS['egw']->translation->add_app($this->appname);
  70              if($this->appname != 'preferences')
  71              {
  72                  $GLOBALS['egw']->translation->add_app('preferences');    // we need the prefs translations too
  73              }
  74  
  75              if(!$GLOBALS['egw']->hooks->single('settings',$this->appname))
  76              {
  77                  return False;
  78              }
  79              $this->settings = array_merge($this->settings,$GLOBALS['settings']);
  80  
  81              /* Remove ui-only settings */
  82              if($this->xmlrpc)
  83              {
  84                  foreach($this->settings as $key => $valarray)
  85                  {
  86                      if(!$valarray['xmlrpc'])
  87                      {
  88                          unset($this->settings[$key]);
  89                      }
  90                  }
  91              }
  92              else
  93              {
  94                  /* Here we include the settings hook file for the current template, if it exists.
  95                       This is not handled by the hooks class and is only valid if not using xml-rpc.
  96                   */
  97                  $tmpl_settings = EGW_TEMPLATE_DIR . '/hook_settings.inc.php';
  98                  if($this->appname == 'preferences' && file_exists($tmpl_settings))
  99                  {
 100                      include($tmpl_settings);
 101                      $this->settings = array_merge($this->settings,$GLOBALS['settings']);
 102                  }
 103              }
 104              if($this->debug)
 105              {
 106              //    _debug_array($this->settings);
 107              }
 108              return True;
 109          }
 110  
 111  		function read($app,$prefix='',$type='user')
 112          {
 113              switch($type)    // set up some class vars to be used when processing the hooks
 114              {
 115                  case 'forced':
 116                      $this->prefs = &$GLOBALS['egw']->preferences->forced[$this->check_app()];
 117                      break;
 118                  case 'default':
 119                      $this->prefs = &$GLOBALS['egw']->preferences->default[$this->check_app()];
 120                      break;
 121                  default:
 122                      $this->prefs = &$GLOBALS['egw']->preferences->user[$this->check_app()];
 123                      // use prefix if given in the url, used for email extra-accounts
 124                      if($prefix != '')
 125                      {
 126                          $prefix_arr = explode('/',$prefix);
 127                          foreach($prefix_arr as $pre)
 128                          {
 129                              $this->prefs = &$this->prefs[$pre];
 130                          }
 131                      }
 132              }
 133              if($this->debug)
 134              {
 135                  echo 'Preferences array:' . "\n";
 136                  _debug_array($this->prefs);
 137              }
 138              /* Ensure that a struct will be returned via xml-rpc (this might change) */
 139              if($this->xmlrpc)
 140              {
 141                  return $this->prefs;
 142              }
 143              else
 144              {
 145                  return False;
 146              }
 147          }
 148  
 149  		function _write($appname,$prefix,$type='user')
 150          {
 151          }
 152  
 153  		function process_array(&$repository,$array,$notifies,$type,$prefix='')
 154          {
 155              //_debug_array($repository);
 156              $appname = $this->check_app();
 157              $prefs = &$repository[$appname];
 158  
 159              if($prefix != '')
 160              {
 161                  $prefix_arr = explode('/',$prefix);
 162                  foreach($prefix_arr as $pre)
 163                  {
 164                      $prefs = &$prefs[$pre];
 165                  }
 166              }
 167              unset($prefs['']);
 168              //_debug_array($array);exit;
 169              while(is_array($array) && list($var,$value) = each($array))
 170              {
 171                  if(isset($value) && $value != '' && $value != '**NULL**')
 172                  {
 173                      if(is_array($value))
 174                      {
 175                          $value = $value['pw'];
 176                          if(empty($value))
 177                          {
 178                              continue;    // dont write empty password-fields
 179                          }
 180                      }
 181                      $prefs[$var] = get_magic_quotes_gpc() ? stripslashes($value) : $value;
 182  
 183                      if($notifies[$var])    // need to translate the key-words back
 184                      {
 185                          $prefs[$var] = $GLOBALS['egw']->preferences->lang_notify($prefs[$var],$notifies[$var],True);
 186                      }
 187                  }
 188                  else
 189                  {
 190                      unset($prefs[$var]);
 191                  }
 192              }
 193              //echo "prefix='$prefix', prefs=<pre>"; print_r($repository[$_appname]); echo "</pre>\n";
 194  
 195              // the following hook can be used to verify the prefs
 196              // if you return something else than False, it is treated as an error-msg and
 197              // displayed to the user (the prefs are not saved)
 198              //
 199              if($error = $GLOBALS['egw']->hooks->single(array(
 200                  'location' => 'verify_settings',
 201                  'prefs'    => $repository[$appname],
 202                  'prefix'   => $prefix,
 203                  'type'     => $type
 204                  ),
 205                  $appname
 206              ))
 207              {
 208                  return $error;
 209              }
 210  
 211              $GLOBALS['egw']->preferences->save_repository(True,$type);
 212  
 213              return $this->prefs;
 214          }
 215  
 216  		function check_app()
 217          {
 218              if($this->appname == 'preferences')
 219              {
 220                  return 'common';
 221              }
 222              else
 223              {
 224                  return $this->appname;
 225              }
 226          }
 227  
 228          /* TODO these need work and may change without notice.  Please remove this line when this is settled. */
 229  		function list_methods($_type='xmlrpc')
 230          {
 231              /*
 232                  This handles introspection or discovery by the logged in client,
 233                  in which case the input might be an array.  The server always calls
 234                  this function to fill the server dispatch map using a string.
 235              */
 236              if(is_array($_type))
 237              {
 238                  $_type = $_type['type'] ? $_type['type'] : $_type[0];
 239              }
 240              switch($_type)
 241              {
 242                  case 'xmlrpc':
 243                      $xml_functions = array(
 244                          'read' => array(
 245                              'function'  => 'read',
 246                              'signature' => array(array(xmlrpcStruct,xmlrpcString,xmlrpcString,xmlrpcString)),
 247                              'docstring' => lang('Read prefs for the specified application.')
 248                          ),
 249                          'write' => array(
 250                              'function'  => 'process_array',
 251                              'signature' => array(array(xmlrpcStruct,xmlrpcStruct,xmlrpcStruct,xmlrpcStruct,xmlrpcString,xmlrpcString)),
 252                              'docstring' => lang('Write prefs for the specified application.')
 253                          ),
 254                          'list_methods' => array(
 255                              'function'  => 'list_methods',
 256                              'signature' => array(array(xmlrpcStruct,xmlrpcString)),
 257                              'docstring' => lang('Read this list of methods.')
 258                          )
 259                      );
 260                      return $xml_functions;
 261                      break;
 262                  case 'soap':
 263                      return $this->soap_functions;
 264                      break;
 265                  default:
 266                      return array();
 267                      break;
 268              }
 269          }
 270      }


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