2005-07-23 11:44:46 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* eGroupWare - Preferences *
|
|
|
|
* http://www.egroupware.org *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
class bosettings
|
|
|
|
{
|
|
|
|
var $xmlrpc = False;
|
|
|
|
var $session_data = array();
|
|
|
|
var $settings = array();
|
|
|
|
var $prefs = array();
|
|
|
|
var $appname = '';
|
|
|
|
var $debug = False;
|
|
|
|
|
|
|
|
var $public_functions = array(
|
2005-07-29 14:54:28 +02:00
|
|
|
'read' => True,
|
2005-07-23 11:44:46 +02:00
|
|
|
'process_array' => True
|
|
|
|
);
|
|
|
|
|
|
|
|
var $xml_functions = array();
|
|
|
|
var $xmlrpc_methods = array();
|
|
|
|
var $soap_functions = array(
|
2005-07-29 14:54:28 +02:00
|
|
|
'read' => array(
|
2005-07-23 11:44:46 +02:00
|
|
|
'in' => array('int','int','struct','string','int'),
|
|
|
|
'out' => array('array')
|
|
|
|
),
|
|
|
|
'process_array' => array(
|
|
|
|
'in' => array('int','struct'),
|
|
|
|
'out' => array('array')
|
2005-08-13 16:03:21 +02:00
|
|
|
),
|
|
|
|
'list_methods' => array(
|
|
|
|
'in' => array('string'),
|
|
|
|
'out' => array('struct')
|
2005-07-23 11:44:46 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
function bosettings($appname='')
|
|
|
|
{
|
|
|
|
$this->xmlrpc = @is_object($GLOBALS['server']) && $GLOBALS['server']->last_method;
|
|
|
|
$this->session_data = $GLOBALS['egw']->session->appsession('session_data','preferences');
|
|
|
|
|
2005-07-23 17:47:54 +02:00
|
|
|
$this->appname = $appname;
|
2005-07-23 11:44:46 +02:00
|
|
|
}
|
|
|
|
|
2005-11-08 10:42:42 +01:00
|
|
|
function save_session($appname,$type,$show_help,$prefix,$notifies='',$referer='')
|
2005-07-23 11:44:46 +02:00
|
|
|
{
|
|
|
|
$GLOBALS['egw']->session->appsession('session_data','preferences',array(
|
|
|
|
'type' => $type, // save our state in the app-session
|
|
|
|
'show_help' => $show_help,
|
|
|
|
'prefix' => $prefix,
|
2005-07-23 17:47:54 +02:00
|
|
|
'appname' => $appname, // we use this to reset prefix on appname-change
|
|
|
|
'notifies' => $notifies,
|
2005-11-08 10:42:42 +01:00
|
|
|
'referer' => $referer ? $referer : $this->session_data['referer'],
|
2005-07-23 11:44:46 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
function call_hook($appname)
|
|
|
|
{
|
|
|
|
$this->appname = $appname;
|
|
|
|
|
2009-04-29 08:26:58 +02:00
|
|
|
translation::add_app($this->appname);
|
2005-07-23 11:44:46 +02:00
|
|
|
if($this->appname != 'preferences')
|
|
|
|
{
|
2009-04-29 08:26:58 +02:00
|
|
|
translation::add_app('preferences'); // we need the prefs translations too
|
2005-07-23 11:44:46 +02:00
|
|
|
}
|
|
|
|
|
2010-01-21 03:59:10 +01:00
|
|
|
// calling app specific settings hook
|
2009-04-29 08:26:58 +02:00
|
|
|
$settings = $GLOBALS['egw']->hooks->single('settings',$this->appname);
|
|
|
|
// it either returns the settings or save it in $GLOBALS['settings'] (deprecated!)
|
|
|
|
if (isset($settings) && is_array($settings) && $settings)
|
2005-07-23 17:47:54 +02:00
|
|
|
{
|
2009-04-29 08:26:58 +02:00
|
|
|
$this->settings = array_merge($this->settings,$settings);
|
|
|
|
}
|
|
|
|
elseif(isset($GLOBALS['settings']) && is_array($GLOBALS['settings']) && $GLOBALS['settings'])
|
|
|
|
{
|
|
|
|
$this->settings = array_merge($this->settings,$GLOBALS['settings']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False; // no settings returned
|
2005-07-23 17:47:54 +02:00
|
|
|
}
|
|
|
|
|
2010-01-21 03:59:10 +01:00
|
|
|
// calling settings hook all apps can answer (for a specific app)
|
2010-04-26 17:00:45 +02:00
|
|
|
foreach($GLOBALS['egw']->hooks->process('settings_'.$this->appname,$this->appname,true) as $app => $settings)
|
2010-01-21 03:59:10 +01:00
|
|
|
{
|
|
|
|
if (isset($settings) && is_array($settings) && $settings)
|
|
|
|
{
|
|
|
|
$this->settings = array_merge($this->settings,$settings);
|
|
|
|
}
|
|
|
|
}
|
2005-07-23 11:44:46 +02:00
|
|
|
/* Remove ui-only settings */
|
|
|
|
if($this->xmlrpc)
|
|
|
|
{
|
|
|
|
foreach($this->settings as $key => $valarray)
|
|
|
|
{
|
|
|
|
if(!$valarray['xmlrpc'])
|
|
|
|
{
|
|
|
|
unset($this->settings[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Here we include the settings hook file for the current template, if it exists.
|
2005-10-14 16:31:35 +02:00
|
|
|
This is not handled by the hooks class and is only valid if not using xml-rpc.
|
2005-07-23 11:44:46 +02:00
|
|
|
*/
|
2010-06-09 12:54:22 +02:00
|
|
|
$tmpl_settings = EGW_SERVER_ROOT.$GLOBALS['egw']->framework->template_dir.'/hook_settings.inc.php';
|
2005-07-23 11:44:46 +02:00
|
|
|
if($this->appname == 'preferences' && file_exists($tmpl_settings))
|
|
|
|
{
|
|
|
|
include($tmpl_settings);
|
|
|
|
$this->settings = array_merge($this->settings,$GLOBALS['settings']);
|
|
|
|
}
|
|
|
|
}
|
2010-06-24 09:02:40 +02:00
|
|
|
// check if we have a default/forced value from the settings hook,
|
|
|
|
// which is NOT stored as default currently
|
|
|
|
// --> store it as default, to allow to propagate defaults to existing installations
|
|
|
|
if ($appname == 'preferences') $appname = 'common';
|
|
|
|
foreach ($this->settings as $name => $data)
|
|
|
|
{
|
|
|
|
if ((string)$GLOBALS['egw']->preferences->default[$appname][$name] === '' &&
|
|
|
|
((string)$data['default'] !== '' || (string)$data['forced'] !== ''))
|
|
|
|
{
|
|
|
|
$default = (string)$data['forced'] !== '' ? $data['forced'] : $data['default'];
|
|
|
|
//echo "<p>".__METHOD__."($appname) $this->appname/$appname/$name=$default NOT yet set!</p>\n";
|
|
|
|
$GLOBALS['egw']->preferences->default[$appname][$name] = $default;
|
|
|
|
$need_update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($need_update)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->preferences->save_repository(false,'default',true);
|
|
|
|
}
|
2005-07-23 11:44:46 +02:00
|
|
|
if($this->debug)
|
|
|
|
{
|
2010-06-24 09:02:40 +02:00
|
|
|
_debug_array($this->settings);
|
2005-07-23 11:44:46 +02:00
|
|
|
}
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2005-07-30 12:25:17 +02:00
|
|
|
function read($app,$prefix='',$type='user')
|
2005-07-23 11:44:46 +02:00
|
|
|
{
|
|
|
|
switch($type) // set up some class vars to be used when processing the hooks
|
|
|
|
{
|
|
|
|
case 'forced':
|
|
|
|
$this->prefs = &$GLOBALS['egw']->preferences->forced[$this->check_app()];
|
|
|
|
break;
|
|
|
|
case 'default':
|
|
|
|
$this->prefs = &$GLOBALS['egw']->preferences->default[$this->check_app()];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->prefs = &$GLOBALS['egw']->preferences->user[$this->check_app()];
|
|
|
|
// use prefix if given in the url, used for email extra-accounts
|
|
|
|
if($prefix != '')
|
|
|
|
{
|
|
|
|
$prefix_arr = explode('/',$prefix);
|
|
|
|
foreach($prefix_arr as $pre)
|
|
|
|
{
|
|
|
|
$this->prefs = &$this->prefs[$pre];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($this->debug)
|
|
|
|
{
|
|
|
|
echo 'Preferences array:' . "\n";
|
|
|
|
_debug_array($this->prefs);
|
|
|
|
}
|
2005-07-30 12:25:17 +02:00
|
|
|
/* Ensure that a struct will be returned via xml-rpc (this might change) */
|
|
|
|
if($this->xmlrpc)
|
|
|
|
{
|
|
|
|
return $this->prefs;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2005-07-23 11:44:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function _write($appname,$prefix,$type='user')
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
function process_array(&$repository,$array,$notifies,$type,$prefix='')
|
|
|
|
{
|
|
|
|
//_debug_array($repository);
|
|
|
|
$appname = $this->check_app();
|
|
|
|
$prefs = &$repository[$appname];
|
|
|
|
|
|
|
|
if($prefix != '')
|
|
|
|
{
|
|
|
|
$prefix_arr = explode('/',$prefix);
|
|
|
|
foreach($prefix_arr as $pre)
|
|
|
|
{
|
|
|
|
$prefs = &$prefs[$pre];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($prefs['']);
|
|
|
|
//_debug_array($array);exit;
|
|
|
|
while(is_array($array) && list($var,$value) = each($array))
|
|
|
|
{
|
|
|
|
if(isset($value) && $value != '' && $value != '**NULL**')
|
|
|
|
{
|
2007-10-09 11:38:46 +02:00
|
|
|
if(is_array($value) && !isset($value['pw']))
|
|
|
|
{
|
|
|
|
$value = implode(',',$value); // multiselect
|
|
|
|
}
|
|
|
|
elseif(is_array($value))
|
2005-07-23 11:44:46 +02:00
|
|
|
{
|
|
|
|
$value = $value['pw'];
|
|
|
|
if(empty($value))
|
|
|
|
{
|
|
|
|
continue; // dont write empty password-fields
|
|
|
|
}
|
|
|
|
}
|
2005-07-23 17:47:54 +02:00
|
|
|
$prefs[$var] = get_magic_quotes_gpc() ? stripslashes($value) : $value;
|
2005-07-23 11:44:46 +02:00
|
|
|
|
2005-07-26 15:54:59 +02:00
|
|
|
if($notifies[$var]) // need to translate the key-words back
|
2005-07-23 11:44:46 +02:00
|
|
|
{
|
2005-07-26 15:54:59 +02:00
|
|
|
$prefs[$var] = $GLOBALS['egw']->preferences->lang_notify($prefs[$var],$notifies[$var],True);
|
2005-07-23 11:44:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unset($prefs[$var]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//echo "prefix='$prefix', prefs=<pre>"; print_r($repository[$_appname]); echo "</pre>\n";
|
|
|
|
|
|
|
|
// the following hook can be used to verify the prefs
|
|
|
|
// if you return something else than False, it is treated as an error-msg and
|
|
|
|
// displayed to the user (the prefs are not saved)
|
|
|
|
//
|
|
|
|
if($error = $GLOBALS['egw']->hooks->single(array(
|
|
|
|
'location' => 'verify_settings',
|
|
|
|
'prefs' => $repository[$appname],
|
|
|
|
'prefix' => $prefix,
|
|
|
|
'type' => $type
|
|
|
|
),
|
|
|
|
$appname
|
|
|
|
))
|
|
|
|
{
|
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
|
|
|
|
$GLOBALS['egw']->preferences->save_repository(True,$type);
|
|
|
|
|
2005-07-30 12:25:17 +02:00
|
|
|
return $this->prefs;
|
2005-07-23 11:44:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function check_app()
|
|
|
|
{
|
|
|
|
if($this->appname == 'preferences')
|
|
|
|
{
|
|
|
|
return 'common';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $this->appname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-26 14:21:31 +02:00
|
|
|
/* TODO these need work and may change without notice. Please remove this line when this is settled. */
|
2005-07-23 11:44:46 +02:00
|
|
|
function list_methods($_type='xmlrpc')
|
|
|
|
{
|
|
|
|
/*
|
2005-10-14 16:31:35 +02:00
|
|
|
This handles introspection or discovery by the logged in client,
|
|
|
|
in which case the input might be an array. The server always calls
|
|
|
|
this function to fill the server dispatch map using a string.
|
2005-07-23 11:44:46 +02:00
|
|
|
*/
|
|
|
|
if(is_array($_type))
|
|
|
|
{
|
|
|
|
$_type = $_type['type'] ? $_type['type'] : $_type[0];
|
|
|
|
}
|
|
|
|
switch($_type)
|
|
|
|
{
|
|
|
|
case 'xmlrpc':
|
|
|
|
$xml_functions = array(
|
|
|
|
'read' => array(
|
2005-07-29 14:54:28 +02:00
|
|
|
'function' => 'read',
|
2005-07-23 11:44:46 +02:00
|
|
|
'signature' => array(array(xmlrpcStruct,xmlrpcString,xmlrpcString,xmlrpcString)),
|
|
|
|
'docstring' => lang('Read prefs for the specified application.')
|
2005-07-23 13:19:29 +02:00
|
|
|
),
|
2005-07-23 11:44:46 +02:00
|
|
|
'write' => array(
|
|
|
|
'function' => 'process_array',
|
|
|
|
'signature' => array(array(xmlrpcStruct,xmlrpcStruct,xmlrpcStruct,xmlrpcStruct,xmlrpcString,xmlrpcString)),
|
|
|
|
'docstring' => lang('Write prefs for the specified application.')
|
2005-08-13 16:03:21 +02:00
|
|
|
),
|
|
|
|
'list_methods' => array(
|
|
|
|
'function' => 'list_methods',
|
|
|
|
'signature' => array(array(xmlrpcStruct,xmlrpcString)),
|
|
|
|
'docstring' => lang('Read this list of methods.')
|
2005-07-23 11:44:46 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
return $xml_functions;
|
|
|
|
break;
|
|
|
|
case 'soap':
|
|
|
|
return $this->soap_functions;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return array();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|