use new eTemplate preferences

This commit is contained in:
Ralf Becker 2013-05-10 16:39:42 +00:00
parent 26f9fb5cd0
commit a23205060b
5 changed files with 14 additions and 1108 deletions

View File

@ -1484,10 +1484,11 @@ if (!function_exists('display_sidebox'))
/** /**
* echo's out a sidebox menu * echo's out a sidebox menu
* *
* @deprecated use $GLOBALS['egw']->framework::sidebox() * @deprecated use $GLOBALS['egw']->framework->sidebox()
*/ */
function display_sidebox($appname,$menu_title,$file) function display_sidebox($appname,$menu_title,$file)
{ {
$file = str_replace('preferences.uisettings.index', 'preferences.preferences_settings.index', $file);
$GLOBALS['egw']->framework->sidebox($appname,$menu_title,$file); $GLOBALS['egw']->framework->sidebox($appname,$menu_title,$file);
} }
} }

View File

@ -1,380 +0,0 @@
<?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(
'read' => True,
'process_array' => True
);
var $xml_functions = array();
var $xmlrpc_methods = array();
var $soap_functions = array(
'read' => array(
'in' => array('int','int','struct','string','int'),
'out' => array('array')
),
'process_array' => array(
'in' => array('int','struct'),
'out' => array('array')
),
'list_methods' => array(
'in' => array('string'),
'out' => array('struct')
)
);
function bosettings($appname='')
{
$this->xmlrpc = @is_object($GLOBALS['server']) && $GLOBALS['server']->last_method;
$this->session_data = $GLOBALS['egw']->session->appsession('session_data','preferences');
$this->appname = $appname;
}
function save_session($appname,$type,$show_help,$prefix,$notifies='',$referer='')
{
$GLOBALS['egw']->session->appsession('session_data','preferences',array(
'type' => $type, // save our state in the app-session
'show_help' => $show_help,
'prefix' => $prefix,
'appname' => $appname, // we use this to reset prefix on appname-change
'notifies' => $notifies,
'referer' => $referer ? $referer : $this->session_data['referer'],
));
}
function call_hook($appname)
{
$this->appname = $appname;
translation::add_app($this->appname);
if($this->appname != 'preferences')
{
translation::add_app('preferences'); // we need the prefs translations too
}
// calling app specific settings hook
$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)
{
$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
}
// calling settings hook all apps can answer (for a specific app)
foreach($GLOBALS['egw']->hooks->process('settings_'.$this->appname,$this->appname,true) as $app => $settings)
{
if (isset($settings) && is_array($settings) && $settings)
{
$this->settings = array_merge($this->settings,$settings);
}
}
/* 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.
This is not handled by the hooks class and is only valid if not using xml-rpc.
*/
$tmpl_settings = EGW_SERVER_ROOT.$GLOBALS['egw']->framework->template_dir.'/hook_settings.inc.php';
if($this->appname == 'preferences' && file_exists($tmpl_settings))
{
include($tmpl_settings);
$this->settings = array_merge($this->settings,$GLOBALS['settings']);
}
}
// 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)
{
// only set not yet set default prefs, so user is able to unset it again with ""
// (only works with type vfs_*, other types delete empty values!)
if (!isset($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);
}
if($this->debug)
{
_debug_array($this->settings);
}
return True;
}
function read($app,$prefix='',$type='user')
{
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: ' . $app . "/$type\n";
_debug_array($this->prefs);
}
/* Ensure that a struct will be returned via xml-rpc (this might change) */
if($this->xmlrpc)
{
return $this->prefs;
}
else
{
return False;
}
}
function _write($appname,$prefix,$type='user')
{
}
/**
* Verify and save preferences
*
* @param array &$repository
* @param array $array
* @param array $notifies
* @param string $type
* @param boolean $only_verify=false
* @param string $prefix='' deprecated
* @return string with verification error or null on success
*/
function process_array(&$repository, $array, $notifies, $type, $only_verify=false, $prefix='')
{
//_debug_array($repository);
$appname = $this->check_app();
$prefs = &$repository[$appname];
if($prefix != '')
{
// AFAIK this is NOT used anymore, was used in old email app
throw egw_exception_assertion_failed(__METHOD__."(,,$notifies, $type, prefix='$prefix') 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**')
{
if (get_magic_quotes_gpc())
{
$value = is_array($value) ? array_map('stripslashes',$value) : stripslashes($value);
}
if (is_array($value))
{
if (isset($value['pw']))
{
$value = $value['pw'];
if(empty($value))
{
continue; // dont write empty password-fields
}
}
elseif(isset($value[$vfs_type='vfs_file']) || isset($value[$vfs_type='vfs_dir']) || isset($value[$vfs_type='vfs_dirs']))
{
$value = $value[$vfs_type];
if ($value === '')
{
// empty is always allowed
// If forced, empty == not set
if($type == 'forced')
{
unset($prefs[$var]);
// need to call preferences::delete, to also set affective prefs!
if (!$only_verify) $GLOBALS['egw']->preferences->delete($appname, $var, $type);
continue;
}
}
elseif ($vfs_type == 'vfs_file')
{
if ($value[0] != '/' || !egw_vfs::stat($value))
{
$error = lang('%1 is no existing vfs file!',htmlspecialchars($value));
}
}
else
{
// split multiple comma or whitespace separated directories
// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
foreach($vfs_type == 'vfs_dir' ? array($value) : preg_split('/[,\s]+\//', $value) as $n => $dir)
{
if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split
if ($dir[0] != '/' || !egw_vfs::stat($dir) || !egw_vfs::is_dir($dir))
{
$error .= ($error ? ' ' : '').lang('%1 is no existing vfs directory!',$dir);
}
}
}
}
else
{
$value = implode(',',$value); // multiselect
}
}
$prefs[$var] = $value;
if(is_array($notifies) && isset($notifies[$var])) // need to translate the key-words back
{
$prefs[$var] = $GLOBALS['egw']->preferences->lang_notify($prefs[$var],$notifies[$var],True);
}
// need to call preferences::add, to also set affective prefs!
if (!$only_verify) $GLOBALS['egw']->preferences->add($appname, $var, $prefs[$var], $type);
}
else
{
unset($prefs[$var]);
// need to call preferences::delete, to also set affective prefs!
if (!$only_verify) $GLOBALS['egw']->preferences->delete($appname, $var, $type);
}
}
//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;
}
if (!$only_verify) $GLOBALS['egw']->preferences->save_repository(True,$type);
// certain common prefs (language, template, ...) require the session to be re-created
if ($appname == 'common' && !$only_verify)
{
egw::invalidate_session_cache();
}
return null;
}
function check_app()
{
if($this->appname == 'preferences')
{
return 'common';
}
else
{
return $this->appname;
}
}
/* TODO these need work and may change without notice. Please remove this line when this is settled. */
function list_methods($_type='xmlrpc')
{
/*
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.
*/
if(is_array($_type))
{
$_type = $_type['type'] ? $_type['type'] : $_type[0];
}
switch($_type)
{
case 'xmlrpc':
$xml_functions = array(
'read' => array(
'function' => 'read',
'signature' => array(array(xmlrpcStruct,xmlrpcString,xmlrpcString,xmlrpcString)),
'docstring' => lang('Read prefs for the specified application.')
),
'write' => array(
'function' => 'process_array',
'signature' => array(array(xmlrpcStruct,xmlrpcStruct,xmlrpcStruct,xmlrpcStruct,xmlrpcString,xmlrpcString)),
'docstring' => lang('Write prefs for the specified application.')
),
'list_methods' => array(
'function' => 'list_methods',
'signature' => array(array(xmlrpcStruct,xmlrpcString)),
'docstring' => lang('Read this list of methods.')
)
);
return $xml_functions;
break;
case 'soap':
return $this->soap_functions;
break;
default:
return array();
break;
}
}
}

View File

@ -296,7 +296,7 @@ class preferences_settings
$GLOBALS['egw']->preferences->{$attribute}[$appname][$setting['name']] = $GLOBALS['egw']->preferences->{$attribute}[$appname][$setting['name']] =
$GLOBALS['egw']->preferences->lang_notify($GLOBALS['egw']->preferences->{$attribute}[$appname][$setting['name']], $vars); $GLOBALS['egw']->preferences->lang_notify($GLOBALS['egw']->preferences->{$attribute}[$appname][$setting['name']], $vars);
$types[$setting['name']] = $vars; // store vars for re-translation, instead type "notify" $types[$setting['name']] = $vars; // store vars for re-translation, instead type "notify"
if ($setting['help'] && !$setting['no_lang']) if ($setting['help'] && ($setting['run_lang'] || !isset($setting['run_lang'])))
{ {
$setting['help'] = lang($setting['help']); $setting['help'] = lang($setting['help']);
} }
@ -307,6 +307,7 @@ class preferences_settings
$setting['help'] .= "<br>\n".'<b>$$'.$lname.'$$</b>: '.$var_help; $setting['help'] .= "<br>\n".'<b>$$'.$lname.'$$</b>: '.$var_help;
} }
$setting['help'] .= "</p>\n"; $setting['help'] .= "</p>\n";
$setting['run_lang'] = false; // already done now
// handle as textarea // handle as textarea
case 'textarea': case 'textarea':
$setting['type'] = is_a($tpl, 'etemplate_old') ? 'textarea' : 'textbox'; $setting['type'] = is_a($tpl, 'etemplate_old') ? 'textarea' : 'textbox';
@ -377,6 +378,14 @@ class preferences_settings
} }
if ($values) $default = implode(', ', $values); if ($values) $default = implode(', ', $values);
} }
if (is_array($types[$setting['name']])) // translate the substitution names
{
$default = $GLOBALS['egw']->preferences->lang_notify($default, $types[$setting['name']]);
}
}
if ($setting['help'] && ($setting['run_lang'] || !isset($setting['run_lang'])))
{
$setting['help'] = lang($setting['help']);
} }
$content[$tab][] = array( $content[$tab][] = array(
'name' => $setting['name'], 'name' => $setting['name'],

View File

@ -1,726 +0,0 @@
<?php
/**
* EGroupware preferences
*
* @package preferences
* @link http://www.egroupware.org
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
/**
* Preferences UI
*/
class uisettings
{
var $public_functions = array(
'index' => True
);
/**
* Instance of Template class
* @var Template
*/
var $t;
var $list_shown = False;
var $show_help;
var $has_help;
var $prefix = '';
/**
* Instance of business object
*
* @var bosettings
*/
var $bo;
function __construct()
{
$this->bo =& CreateObject('preferences.bosettings',$_GET['appname']);
if($GLOBALS['egw']->acl->check('run',1,'admin'))
{
/* Don't use a global variable for this ... */
define('HAS_ADMIN_RIGHTS',1);
if ((int) $_GET['account_id'])
{
$GLOBALS['egw']->preferences->account_id = (int) $_GET['account_id'];
$GLOBALS['egw']->preferences->read_repository();
}
}
}
/**
* add nation ACL tab to Admin >> Edit user
*/
function edit_user()
{
global $menuData;
$menuData[] = array(
'description' => 'Preferences',
'url' => '/index.php',
'extradata' => 'menuaction=preferences.uisettings.index&appname=preferences'
);
}
function index()
{
// make preferences called via sidebox menu of an app, to behave like a part of that app
$referer = common::get_referer('/preferences/index.php');
// for framed templates, use the index page to return, instead of the referer
if (strpos($referer,'cd=yes') !== false)
{
$referer = substr(egw_framework::index($_GET['appname']),
strlen($GLOBALS['egw_info']['server']['webserver_url']));
}
if (!preg_match('/(preferences.php|menuaction=preferences.uisettings.index)+/i',$referer))
{
$this->bo->session_data['referer'] = $referer;
}
//echo '<p align="right">'."referer='{$this->bo->session_data['referer']}'</p>\n";
if (substr($this->bo->session_data['referer'],0,strlen('/preferences')) != '/preferences')
{
$GLOBALS['egw_info']['flags']['currentapp'] = $_GET['appname'];
}
if($_POST['cancel'])
{
egw::redirect_link($this->bo->session_data['referer']);
}
if (substr($_SERVER['PHP_SELF'],-15) == 'preferences.php')
{
$pref_link = '/preferences/preferences.php';
$link_params = array(
'appname' => $_GET['appname'],
);
}
else
{
$pref_link = '/index.php';
$link_params = array(
'menuaction' => 'preferences.uisettings.index',
'appname' => $_GET['appname'],
);
if ($this->is_admin() && (int) $_GET['account_id'])
{
$link_params['account_id'] = (int) $_GET['account_id'];
}
}
$user = get_var('user',Array('POST'));
$forced = get_var('forced',Array('POST'));
$default = get_var('default',Array('POST'));
$this->t = new Template(common::get_tpl_dir('preferences'),'keep');
$this->t->set_file(array(
'preferences' => 'preferences.tpl'
));
$this->t->set_block('preferences','list','lists');
$this->t->set_block('preferences','row','rowhandle');
$this->t->set_block('preferences','help_row','help_rowhandle');
$this->t->set_block('preferences','section_row','section_rowhandle');
$this->t->set_var(array('rowhandle' => '','help_rowhandle' => '','messages' => '', 'section_rowhandle' => ''));
$this->prefix = get_var('prefix',array('GET'),$this->bo->session_data['appname'] == $_GET['appname'] ? $this->bo->session_data['prefix'] : '');
if($this->is_admin())
{
/* This is where we will keep track of our postion. */
/* Developers won't have to pass around a variable then */
$GLOBALS['type'] = get_var('type',Array('GET','POST'),$this->bo->session_data['type']);
if(empty($GLOBALS['type']))
{
$GLOBALS['type'] = 'user';
}
}
else
{
$GLOBALS['type'] = 'user';
}
$this->show_help = isset($this->bo->session_data['show_help']) && $this->bo->session_data['appname'] == $_GET['appname']
? $this->bo->session_data['show_help']
: (int)$GLOBALS['egw_info']['user']['preferences']['common']['show_help'];
if($toggle_help = get_var('toggle_help','POST'))
{
$this->show_help = (int)(!$this->show_help);
}
$this->has_help = 0;
if($_POST['save'] || $_POST['apply'])
{
if ($this->bo->session_data['notifies']) // notifies NEED the translation for the application loaded
{
translation::add_app($_GET['appname']);
}
/* Don't use a switch here, we need to check some permissions during the ifs */
if($GLOBALS['type'] == 'user' || !($GLOBALS['type']))
{
$error = $this->bo->process_array($GLOBALS['egw']->preferences->user,$user,$this->bo->session_data['notifies'],$GLOBALS['type'],$this->prefix);
}
if($GLOBALS['type'] == 'default' && $this->is_admin())
{
$error = $this->bo->process_array($GLOBALS['egw']->preferences->default, $default,$this->bo->session_data['notifies'],$GLOBALS['type']);
}
if($GLOBALS['type'] == 'forced' && $this->is_admin())
{
$error = $this->bo->process_array($GLOBALS['egw']->preferences->forced, $forced,$this->bo->session_data['notifies'],$GLOBALS['type']);
}
if($GLOBALS['type'] == 'user' && $_GET['appname'] == 'preferences' && $user['show_help'] != '')
{
$this->show_help = $user['show_help']; // use it, if admin changes his help-prefs
}
if($_POST['save'] && !$error)
{
$GLOBALS['egw']->redirect_link($this->bo->session_data['referer']);
}
}
// save our state in the app-session
$this->bo->save_session($_GET['appname'],$GLOBALS['type'],$this->show_help,$this->prefix);
// changes for the admin itself, should have immediate feedback ==> redirect
if(!$error && ($_POST['save'] || $_POST['apply']) && $GLOBALS['type'] == 'user' && $_GET['appname'] == 'preferences')
{
$GLOBALS['egw']->redirect_link($pref_link,$link_params);
}
$this->t->set_var('action_url',$GLOBALS['egw']->link($pref_link,$link_params));
$this->t->set_var('th_bg', $GLOBALS['egw_info']['theme']['th_bg']);
$this->t->set_var('th_text',$GLOBALS['egw_info']['theme']['th_text']);
$this->t->set_var('row_on', $GLOBALS['egw_info']['theme']['row_on']);
$this->t->set_var('row_off',$GLOBALS['egw_info']['theme']['row_off']);
$this->bo->read($this->check_app(),$this->prefix,$GLOBALS['type']);
//echo "prefs=<pre>"; print_r($this->bo->prefs); echo "</pre>\n";
$this->notifies = array();
if(!$this->bo->call_hook($_GET['appname']))
{
throw new egw_exception_wrong_parameter("Could not find settings for application: ".$_GET['appname']);
}
// display verifcation errors also on entering preferences, not only after saving
if (!isset($_POST['save']) && !isset($_POST['apply']))
{
if (!$this->is_admin() || !in_array($GLOBALS['type'], array('user', 'default', 'forced')))
{
$GLOBALS['type'] = 'user';
}
$ignore = array();
$error = $this->bo->process_array($ignore, $this->bo->prefs, array(), $GLOBALS['type'], true);
}
$this->t->set_var('messages',$error);
foreach($this->bo->settings as $key => $valarray)
{
if(!$this->is_admin())
{
if($valarray['admin'])
{
continue;
}
}
unset($valarray['default']); // not longer used as default, since we have default prefs
switch($valarray['type'])
{
case 'section':
$this->create_section($valarray['title']);
break;
case 'subsection':
$this->create_section($valarray['title'],'prefSubSection');
break;
case 'input':
$this->create_input_box(
$valarray['label'],
$valarray['name'],
$valarray['help'],
$valarray['default'],
$valarray['size'],
$valarray['maxsize'],
$valarray['type'],
$valarray['run_lang'] // if run_lang is set and false $valarray['help'] is run through lang()
);
break;
case 'password':
$this->create_password_box(
$valarray['label'],
$valarray['name'],
$valarray['help'],
$valarray['size'],
$valarray['maxsize'],
$valarray['run_lang']
);
break;
case 'text':
$this->create_text_area(
$valarray['label'],
$valarray['name'],
$valarray['rows'],
$valarray['cols'],
$valarray['help'],
$valarray['default'],
$valarray['run_lang']
);
break;
case 'vfs_file':
case 'vfs_dir':
case 'vfs_dirs':
$this->create_vfs_box(
$valarray['type'],
$valarray['label'],
$valarray['name'],
$valarray['help'],
$valarray['default'],
$valarray['size'],
$valarray['run_lang']
);
break;
case 'select':
case 'multiselect':
$this->create_select_box(
$valarray['label'],
$valarray['name'],
$valarray['values'],
$valarray['help'],
$valarray['default'],
$valarray['run_lang'],
$valarray['type'] == 'multiselect',
$valarray['onchange'],
$valarray['style']
);
break;
case 'check':
$this->create_check_box(
$valarray['label'],
$valarray['name'],
$valarray['help'],
$valarray['default'],
$valarray['run_lang']
);
break;
case 'notify':
$this->create_notify(
$valarray['label'],
$valarray['name'],
$valarray['rows'],
$valarray['cols'],
$valarray['help'],
$valarray['default'],
$valarray['values'],
$valarray['subst_help'],
$valarray['run_lang']
);
break;
case 'color':
$this->create_color_box(
$valarray['label'],
$valarray['name'],
$valarray['default'],
$valarray['help'],
$valarray['run_lang'] // if run_lang is set and false $valarray['help'] is run through lang()
);
break;
}
}
$GLOBALS['egw_info']['flags']['app_header'] = ($this->is_admin() && (int) $_GET['account_id'] ?
common::grab_owner_name((int) $_GET['account_id']).': ' : '').($_GET['appname'] == 'preferences' ?
lang('Common preferences') : lang('%1 - Preferences',$GLOBALS['egw_info']['apps'][$_GET['appname']]['title']));
common::egw_header();
echo parse_navbar();
if(count($this->notifies)) // there have been notifies in the hook, we need to save in the session
{
$this->bo->save_session($_GET['appname'],$GLOBALS['type'],$this->show_help,$this->prefix,$this->notifies);
//echo "notifies="; _debug_array($this->notifies);
}
if($this->is_admin())
{
if ((int) $_GET['account_id'])
{
echo '<table><tr valign="top"><td>'."\n".ExecMethod('admin.uimenuclass.createHTMLCode','edit_user')."\n</td>\n<td>".
'<p class="th" style="width: 100%; text-align: left; font-weight: bold; margin-top: 2px; padding: 1px;">'.
lang('Common preferences')."</p>\n";
}
$tabs[] = array(
'label' => (int) $_GET['account_id'] ? common::grab_owner_name($_GET['account_id']) : lang('Your preferences'),
'link' => $GLOBALS['egw']->link($pref_link,$link_params+array('type'=>'user')),
);
$tabs[] = array(
'label' => lang('Default preferences'),
'link' => $GLOBALS['egw']->link($pref_link,$link_params+array('type'=>'default')),
);
$tabs[] = array(
'label' => lang('Forced preferences'),
'link' => $GLOBALS['egw']->link($pref_link,$link_params+array('type'=>'forced')),
);
switch($GLOBALS['type'])
{
case 'user': $selected = 0; break;
case 'default': $selected = 1; break;
case 'forced': $selected = 2; break;
}
$this->t->set_var('tabs',common::create_tabs($tabs,$selected));
}
else
{
$this->t->set_var('tabs','');
}
$this->t->set_var('lang_save', lang('save'));
$this->t->set_var('lang_apply', lang('apply'));
$this->t->set_var('lang_cancel', lang('cancel'));
$this->t->set_var('show_help',(int)$this->show_help);
$this->t->set_var('help_button',$this->has_help ? '<input type="submit" name="toggle_help" value="'.
($this->show_help ? lang('help off') : lang('help')).'">' : '');
if(!$this->list_shown)
{
$this->show_list();
}
$this->t->pfp('phpgw_body','preferences');
if($this->is_admin() && (int) $_GET['account_id'])
{
echo "\n</td></tr></table>\n";
}
//echo '<pre style="text-align: left;">'; print_r($GLOBALS['egw']->preferences->data); echo "</pre>\n";
common::egw_footer();
}
/* Make things a little easier to follow */
/* Some places we will need to change this if they're in common */
function check_app()
{
if($_GET['appname'] == 'preferences')
{
return 'common';
}
else
{
return $_GET['appname'];
}
}
function is_forced_value($_appname,$preference_name)
{
if(isset($GLOBALS['egw']->preferences->forced[$_appname][$preference_name]) && $GLOBALS['type'] != 'forced')
{
return True;
}
else
{
return False;
}
}
function create_password_box($label_name,$preference_name,$help='',$size='',$max_size='',$run_lang=True)
{
$_appname = $this->check_app();
if($this->is_forced_value($_appname,$preference_name))
{
return True;
}
$this->create_input_box($label_name,$preference_name.
($GLOBALS['type'] != 'user' ? '' : '][pw'), // we need to show the default or forced pw, otherwise we are never able to reset it
$help,'',$size,$max_size,'password',$run_lang);
}
function create_vfs_box($type,$label_name,$preference_name,$help='',$default='',$size='',$run_lang=True)
{
$_appname = $this->check_app();
if($this->is_forced_value($_appname,$preference_name))
{
return True;
}
//echo "<p>create_input_box('$label_name', '$preference_name][$type', '$help', '$default', '$size', '', '', $run_lang, '$def_text')</p>\n";
$this->create_input_box($label_name,$preference_name.']['.$type,
$help,$default,$size,'','',$run_lang,$def_text);
}
function create_color_box($label,$name,$default='',$help='',$run_lang=True)
{
if($GLOBALS['type'] == 'user')
{
$_appname = $this->check_app();
$def_text = !$GLOBALS['egw']->preferences->user[$_appname][$name] ? $GLOBALS['egw']->preferences->data[$_appname][$name] : $GLOBALS['egw']->preferences->default[$_appname][$name];
$def_text = preg_match('/^#[0-9A-F]{6}$/i',$def_text) ? ' &nbsp; <i><font size="-1">'.lang('default').':&nbsp;<span style="background-color: '.$def_text.'">'.$def_text.'</span></font></i>' : '';
}
$this->create_input_box($label,$name,$help,$default,'','','color',$run_lang,$def_text);
}
function create_input_box($label,$name,$help='',$default='',$size='',$max_size='',$type='',$run_lang=True,$def_text='')
{
$_appname = $this->check_app();
if($this->is_forced_value($_appname,$name))
{
return True;
}
if($size)
{
$options .= " size='$size'";
}
if($maxsize)
{
$options .= " max='$maxsize'";
}
// remove appended type (eg. "][vfs_file") bevor looking up current value
$_name = preg_replace('/\]\[.*$/','',$name);
if(substr($name, -4) != '][pw' && isset($this->bo->prefs[$_name]) || $GLOBALS['type'] != 'user')
{
$default = $this->bo->prefs[$_name];
}
if($GLOBALS['type'] == 'user' && empty($def_text))
{
$def_text = $GLOBALS['egw']->preferences->default[$_appname][$_name];
if(isset($this->notifies[$name])) // translate the substitution names
{
$def_text = $GLOBALS['egw']->preferences->lang_notify($def_text,$this->notifies[$name]);
}
$def_text = $def_text != '' ? ' <i><font size="-1">'.lang('default').':&nbsp;'.$def_text.'</font></i>' : '';
}
$this->t->set_var('row_value',html::input($GLOBALS['type']."[$name]",$default,$type,$options).$def_text);
$this->t->set_var('row_name',$run_lang !== -1 ? lang($label) : $label);
$GLOBALS['egw']->nextmatchs->template_alternate_row_color($this->t);
$this->t->fp('rows',$this->process_help($help,$run_lang) ? 'help_row' : 'row',True);
}
function process_help($help,$run_lang=True)
{
if(!empty($help))
{
$this->has_help = True;
if($this->show_help)
{
$this->t->set_var('help_value',is_null($run_lang) || $run_lang ? lang($help) : $help);
return True;
}
}
return False;
}
function create_check_box($label,$name,$help='',$default='',$run_lang=True)
{
// checkboxes itself can't be use as they return nothing if uncheckt !!!
if($GLOBALS['type'] != 'user')
{
$default = ''; // no defaults for default or forced prefs
}
if(isset($this->bo->prefs[$name]))
{
$this->bo->prefs[$name] = (string)(int)(!!$this->bo->prefs[$name]); // to care for '' and 'True'
}
return $this->create_select_box($label,$name,array(
'0' => lang('No'),
'1' => lang('Yes')
),$help,$default,$run_lang);
}
function create_option_string($selected,$values)
{
while(is_array($values) && list($var,$value) = each($values))
{
$s .= '<option value="' . $var . '"';
if("$var" == "$selected") // the "'s are necessary to force a string-compare
{
$s .= ' selected="1"';
}
$s .= '>' . $value . '</option>';
}
return $s;
}
/**
* Create different sections with a title
*/
function create_section($title='',$span_class='prefSection')
{
$this->t->set_var('title','<span class="'.$span_class.'">'.lang($title).'</span>');
$this->t->fp('rows','section_row',True);
}
function create_select_box($label,$name,$values,$help='',$default='',$run_lang=True,$multiple=false,$onchange=null,$style='')
{
$_appname = $this->check_app();
if($this->is_forced_value($_appname,$name))
{
return True;
}
if(isset($this->bo->prefs[$name]) || $GLOBALS['type'] != 'user')
{
$default = $this->bo->prefs[$name];
}
//echo "<p>uisettings::create_select_box('$label','$name',".print_r($values,true).",,'$default',$run_lang,$multiple)</p>\n";
if (!$multiple)
{
switch($GLOBALS['type'])
{
case 'user':
$extra = array('' => lang('Use default'));
break;
case 'default':
$extra = array('' => lang('No default'));
break;
case 'forced':
$extra = array('**NULL**' => lang('Users choice'));
break;
}
if (is_array($extra)) $values = $extra + (is_array($values)?$values:array($values));
$select = html::select($GLOBALS['type'].'['.$name.']',$default,$values,true,
$onchange?'onchange="'.str_replace('"','\\"',htmlspecialchars($onchange)).'"':''." style=\"$style\"");
}
else
{
if (!is_array($default)) $default = explode(',',$default);
$select = html::input_hidden($GLOBALS['type'].'['.$name.']','',false); // causes bosettings not to ignore unsetting all
$select .= html::checkbox_multiselect($GLOBALS['type'].'['.$name.']',$default,$values,true,'',min(5,count($values)),
true, $style);
}
if($GLOBALS['type'] == 'user' && (string)$GLOBALS['egw']->preferences->default[$_appname][$name] !== '')
{
// flatten values first (some selectbox values are given multi-dimensional)
foreach($values as $id => $val)
{
if (is_array($val))
{
unset($values[$id]);
$values += $val;
}
}
$default_value = $GLOBALS['egw']->preferences->default[$_appname][$name];
if ($multiple) $default_value = explode(',',$default_value);
$defs = array();
foreach((array)$default_value as $def)
{
if ($values[$def]) $defs[] = $values[$def];
}
$def_text = ' <i><font size="-1">'.lang('default').':&nbsp;'.implode(', ',$defs).'</font></i>';
}
$this->t->set_var('row_value',$select.$def_text);
$this->t->set_var('row_name',$run_lang !== -1 ? lang($label) : $label);
$GLOBALS['egw']->nextmatchs->template_alternate_row_color($this->t);
$this->t->fp('rows',$this->process_help($help,$run_lang) ? 'help_row' : 'row',True);
}
/**
* creates text-area or inputfield with subtitution-variables
*
* @param string $label untranslated label
* @param string $name name of the pref
* @param int $rows of the textarea or input-box ($rows==1)
* @param int $cols of the textarea or input-box ($rows==1)
* @param string $help='' untranslated help-text, run through lang if $run_lang != false
* @param string $default='' default-value
* @param array $vars2='' array with extra substitution-variables of the form key => help-text
* @param boolean $subst_help=true show help about substitues
* @param boolean $run_lang=true should $help help be run through lang()
*/
function create_notify($label,$name,$rows,$cols,$help='',$default='',$vars2='',$subst_help=True,$run_lang=True)
{
$vars = $GLOBALS['egw']->preferences->vars;
if(is_array($vars2))
{
$vars += $vars2;
}
$this->bo->prefs[$name] = $GLOBALS['egw']->preferences->lang_notify($this->bo->prefs[$name],$vars);
$this->notifies[$name] = $vars; // this gets saved in the app_session for re-translation
$help = $help && ($run_lang || is_null($run_lang)) ? lang($help) : $help;
if($subst_help || is_null($subst_help))
{
$help .= '<p><b>'.lang('Substitutions and their meanings:').'</b>';
foreach($vars as $var => $var_help)
{
$lname = ($lname = lang($var)) == $var.'*' ? $var : $lname;
$help .= "<br>\n".'<b>$$'.$lname.'$$</b>: '.$var_help;
}
$help .= "</p>\n";
}
if($row == 1)
{
$this->create_input_box($label,$name,$help,$default,$cols,'','',False);
}
else
{
$this->create_text_area($label,$name,$rows,$cols,$help,$default,False);
}
}
function create_text_area($label,$name,$rows,$cols,$help='',$default='',$run_lang=True)
{
$charSet = translation::charset();
$_appname = $this->check_app();
if($this->is_forced_value($_appname,$name))
{
return True;
}
if(isset($this->bo->prefs[$name]) || $GLOBALS['type'] != 'user')
{
$default = $this->bo->prefs[$name];
}
if($GLOBALS['type'] == 'user')
{
$def_text = !$GLOBALS['egw']->preferences->user[$_appname][$name] ? $GLOBALS['egw']->preferences->data[$_appname][$name] : $GLOBALS['egw']->preferences->default[$_appname][$name];
if(isset($this->notifies[$name])) // translate the substitution names
{
$def_text = $GLOBALS['egw']->preferences->lang_notify($def_text,$this->notifies[$name]);
}
$def_text = $def_text != '' ? '<br><i><font size="-1"><b>'.lang('default').'</b>:<br>'.nl2br($def_text).'</font></i>' : '';
}
$this->t->set_var('row_value',"<textarea rows=\"$rows\" cols=\"$cols\" name=\"${GLOBALS[type]}[$name]\">".
htmlentities($default,ENT_COMPAT,$charSet)."</textarea>$def_text");
$this->t->set_var('row_name',lang($label));
$GLOBALS['egw']->nextmatchs->template_alternate_row_color($this->t);
$this->t->fp('rows',$this->process_help($help,$run_lang) ? 'help_row' : 'row',True);
}
/* Makes the ifs a little nicer, plus ... this will change once the ACL manager is in place */
/* and is able to create less powerfull admins. This will handle the ACL checks for that (jengo) */
function is_admin()
{
if(HAS_ADMIN_RIGHTS == 1 && empty($this->prefix)) // tabs only without prefix
{
return True;
}
else
{
return False;
}
}
function show_list($header='&nbsp;')
{
$this->t->set_var('list_header',$header);
$this->t->parse('lists','list',$this->list_shown);
$this->t->set_var('rows','');
$this->list_shown = True;
}
}

View File

@ -57,6 +57,8 @@ function section_item($pref_link='',$pref_text='')
{ {
global $pref_tpl; global $pref_tpl;
$pref_link = str_replace('preferences.uisettings.index', 'preferences.preferences_settings.index', $pref_link);
$pref_tpl->set_var('pref_link',$pref_link); $pref_tpl->set_var('pref_link',$pref_link);
if (strtolower($pref_text) == 'grant access' && $GLOBALS['egw_info']['server']['deny_user_grants_access']) if (strtolower($pref_text) == 'grant access' && $GLOBALS['egw_info']['server']['deny_user_grants_access'])