2013-04-28 16:52:41 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware: Preferences app UI for settings/preferences
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <rb@stylite.de>
|
|
|
|
* @package preferences
|
|
|
|
* @copyright (c) 2013 by Ralf Becker <rb@stylite.de>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once EGW_INCLUDE_ROOT.'/etemplate/inc/class.etemplate.inc.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UI for settings / preferences
|
|
|
|
*/
|
|
|
|
class preferences_settings
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Methods callable via menuaction
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $public_functions = array(
|
|
|
|
'index' => true,
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* App we work on
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $appname = 'preferences';
|
|
|
|
/**
|
|
|
|
* Preferences read by call_hook
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $settings = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit preferences
|
|
|
|
*
|
|
|
|
* @param array $content=null
|
|
|
|
* @param string $msg=''
|
|
|
|
*/
|
|
|
|
function index(array $content=null, $msg='')
|
|
|
|
{
|
2013-05-03 17:29:34 +02:00
|
|
|
$tpl = new etemplate('preferences.settings');
|
2013-04-28 16:52:41 +02:00
|
|
|
if (!is_array($content))
|
|
|
|
{
|
2013-05-03 17:25:11 +02:00
|
|
|
$appname = isset($_GET['appname']) && $_GET['appname'] != 'preferences' ? $_GET['appname'] : 'common';
|
2013-05-03 15:08:08 +02:00
|
|
|
$type = 'user';
|
|
|
|
$account_id = $GLOBALS['egw_info']['user']['account_id'];
|
|
|
|
if ($GLOBALS['egw_info']['user']['apps']['admin'] &&
|
|
|
|
isset($_GET['account_id']) && (int)$_GET['account_id'] &&
|
|
|
|
$GLOBALS['egw']->accounts->exists((int)$_GET['account_id']))
|
2013-04-28 16:52:41 +02:00
|
|
|
{
|
2013-05-03 15:08:08 +02:00
|
|
|
$account_id = (int)$_GET['account_id'];
|
|
|
|
$type = $_GET['account_id'] < 0 ? 'group' : 'user';
|
2013-04-28 16:52:41 +02:00
|
|
|
}
|
2013-05-03 15:08:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-09 12:41:38 +02:00
|
|
|
//error_log(__METHOD__."(".array2string($content).")");
|
2013-05-03 15:08:08 +02:00
|
|
|
if ($content['button'])
|
2013-04-28 16:52:41 +02:00
|
|
|
{
|
2013-05-03 15:08:08 +02:00
|
|
|
list($button) = each($content['button']);
|
|
|
|
switch($button)
|
2013-04-28 16:52:41 +02:00
|
|
|
{
|
2013-05-03 15:08:08 +02:00
|
|
|
case 'save':
|
|
|
|
case 'apply':
|
|
|
|
// ToDo: save preferences
|
2013-05-03 17:25:11 +02:00
|
|
|
$appname = $content['old_appname'] ? $content['old_appname'] : 'common';
|
|
|
|
list($type,$account_id) = explode(':', $content['old_type']);
|
2013-05-10 09:50:30 +02:00
|
|
|
// merge prefs of all tabs together again
|
|
|
|
$prefs = array();
|
|
|
|
foreach($content as $name => $val)
|
|
|
|
{
|
|
|
|
if (is_array($val) && strpos($name, 'tab') === 0)
|
|
|
|
{
|
|
|
|
$prefs = array_merge($prefs, $val);
|
|
|
|
}
|
|
|
|
}
|
2013-05-10 19:22:14 +02:00
|
|
|
//error_log(__METHOD__."() button=$button, content=".array2string($content).' --> prefs='.array2string($prefs));;;
|
|
|
|
if ($account_id && $account_id != $GLOBALS['egw']->preferences->get_account_id())
|
2013-05-03 17:25:11 +02:00
|
|
|
{
|
2013-05-10 19:22:14 +02:00
|
|
|
$GLOBALS['egw']->preferences->set_account_id($account_id);
|
2013-05-03 17:25:11 +02:00
|
|
|
$GLOBALS['egw']->preferences->read_repository();
|
|
|
|
}
|
|
|
|
$attribute = $type == 'group' ? 'user' : $type;
|
2013-05-10 09:50:30 +02:00
|
|
|
if (!($msg=$this->process_array($GLOBALS['egw']->preferences->$attribute, $prefs, $content['types'], $appname, $attribute)))
|
2013-05-03 17:25:11 +02:00
|
|
|
{
|
|
|
|
$msg = lang('Preferences saved.'); //.array2string($prefs);
|
|
|
|
}
|
2013-05-03 15:08:08 +02:00
|
|
|
if ($button == 'apply') break;
|
|
|
|
// fall throught
|
|
|
|
case 'cancel':
|
|
|
|
egw::redirect_link('/preferences/index.php');
|
|
|
|
}
|
|
|
|
}
|
2013-05-03 17:25:11 +02:00
|
|
|
$appname = $content['appname'] ? $content['appname'] : 'common';
|
|
|
|
list($type,$account_id) = explode(':', $content['type']);
|
2013-05-03 15:08:08 +02:00
|
|
|
//_debug_array($prefs);
|
|
|
|
}
|
2013-05-10 19:22:14 +02:00
|
|
|
if ($account_id && $account_id != $GLOBALS['egw']->preferences->get_account_id())
|
2013-05-03 15:08:08 +02:00
|
|
|
{
|
2013-05-10 19:22:14 +02:00
|
|
|
$GLOBALS['egw']->preferences->set_account_id($account_id);
|
2013-05-03 15:08:08 +02:00
|
|
|
$GLOBALS['egw']->preferences->read_repository();
|
|
|
|
}
|
2013-05-10 20:00:33 +02:00
|
|
|
$preserve = array('types' => array());
|
2013-05-10 10:24:15 +02:00
|
|
|
if ($content['old_appname'] == $content['appname']) $old_tab = $content['tabs'];
|
2013-05-10 09:50:30 +02:00
|
|
|
$content = $this->get_content($appname, $type, $sel_options, $readonlys, $preserve['types'], $tpl);
|
2013-05-10 20:00:33 +02:00
|
|
|
$preserve['appname'] = $preserve['old_appname'] = $content['appname'];
|
|
|
|
$preserve['type'] = $preserve['old_type'] = $content['type'];
|
2013-05-10 10:24:15 +02:00
|
|
|
if (isset($old_tab)) $content['tabs'] = $old_tab;
|
2013-05-10 09:50:30 +02:00
|
|
|
|
|
|
|
// if not just saved, call validation before, to be able to show failed validation of current prefs
|
|
|
|
if (!isset($button))
|
|
|
|
{
|
|
|
|
$attribute = $type == 'group' ? 'user' : $type;
|
|
|
|
$msg = $this->process_array($GLOBALS['egw']->preferences->$attribute,
|
2013-05-10 19:22:14 +02:00
|
|
|
(array)$GLOBALS['egw']->preferences->{$attribute}[$appname], $preserve['types'], $appname, $attribute, true);
|
2013-05-10 09:50:30 +02:00
|
|
|
}
|
|
|
|
$content['msg'] = $msg;
|
|
|
|
|
|
|
|
$tpl->exec('preferences.preferences_settings.index', $content, $sel_options, $readonlys, $preserve);
|
2013-05-03 15:08:08 +02:00
|
|
|
}
|
|
|
|
|
2013-05-03 17:25:11 +02:00
|
|
|
/**
|
|
|
|
* Verify and save preferences
|
|
|
|
*
|
2013-05-10 09:50:30 +02:00
|
|
|
* @param array &$repository values get updated here
|
|
|
|
* @param array $values new values
|
|
|
|
* @param array $types setting-name => type
|
2013-05-03 17:25:11 +02:00
|
|
|
* @param string $appname appname or 'common'
|
2013-05-10 09:50:30 +02:00
|
|
|
* @param string $type 'user', 'default', 'forced'
|
2013-05-03 17:25:11 +02:00
|
|
|
* @param boolean $only_verify=false
|
|
|
|
* @return string with verification error or null on success
|
|
|
|
*/
|
2013-05-10 09:50:30 +02:00
|
|
|
function process_array(array &$repository, array $values, array $types=null, $appname, $type, $only_verify=false)
|
2013-05-03 17:25:11 +02:00
|
|
|
{
|
|
|
|
//_debug_array($repository);
|
|
|
|
$prefs = &$repository[$appname];
|
|
|
|
|
|
|
|
unset($prefs['']);
|
|
|
|
//_debug_array($values);exit;
|
|
|
|
foreach($values as $var => $value)
|
|
|
|
{
|
2013-05-10 09:50:30 +02:00
|
|
|
// type specific validation
|
|
|
|
switch((string)$types[$var])
|
2013-05-03 17:25:11 +02:00
|
|
|
{
|
2013-05-10 09:50:30 +02:00
|
|
|
case 'password': // dont write empty password-fields
|
|
|
|
if (empty($value)) continue 2;
|
|
|
|
break;
|
|
|
|
case 'vfs_file':
|
|
|
|
case 'vfs_dir':
|
|
|
|
case 'vfs_dirs':
|
|
|
|
if ($value === '')
|
2013-05-03 17:25:11 +02:00
|
|
|
{
|
2013-05-10 09:50:30 +02:00
|
|
|
// empty is always allowed
|
|
|
|
|
|
|
|
// If forced, empty == not set
|
|
|
|
if($type == 'forced')
|
2013-05-03 17:25:11 +02:00
|
|
|
{
|
2013-05-10 09:50:30 +02:00
|
|
|
unset($prefs[$var]);
|
|
|
|
// need to call preferences::delete, to also set affective prefs!
|
|
|
|
if (!$only_verify) $GLOBALS['egw']->preferences->delete($appname, $var, $type);
|
|
|
|
continue 2;
|
2013-05-03 17:25:11 +02:00
|
|
|
}
|
|
|
|
}
|
2013-05-10 09:50:30 +02:00
|
|
|
elseif ($types[$var] == 'vfs_file')
|
2013-05-03 17:25:11 +02:00
|
|
|
{
|
2013-05-10 09:50:30 +02:00
|
|
|
if ($value[0] != '/' || !egw_vfs::stat($value) || egw_vfs::is_dir($value))
|
2013-05-03 17:25:11 +02:00
|
|
|
{
|
2013-05-10 09:50:30 +02:00
|
|
|
$error = lang('%1 is no existing vfs file!',htmlspecialchars($value));
|
2013-05-03 17:25:11 +02:00
|
|
|
}
|
2013-05-10 09:50:30 +02:00
|
|
|
}
|
|
|
|
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($types[$var] == 'vfs_dir' ? array($value) : preg_split('/[,\s]+\//', $value) as $n => $dir)
|
2013-05-03 17:25:11 +02:00
|
|
|
{
|
2013-05-10 09:50:30 +02:00
|
|
|
if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split
|
|
|
|
if ($dir[0] != '/' || !egw_vfs::stat($dir) || !egw_vfs::is_dir($dir))
|
2013-05-03 17:25:11 +02:00
|
|
|
{
|
2013-05-10 09:50:30 +02:00
|
|
|
$error .= ($error ? ' ' : '').lang('%1 is no existing vfs directory!',$dir);
|
2013-05-03 17:25:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-10 09:50:30 +02:00
|
|
|
break;
|
2013-05-10 17:56:35 +02:00
|
|
|
case 'Array': // notify
|
2013-05-10 09:50:30 +02:00
|
|
|
$value = $GLOBALS['egw']->preferences->lang_notify($value, $types[$var], True);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($value) && $value !== '' && $value !== '**NULL**')
|
|
|
|
{
|
|
|
|
if (is_array($value)) $value = implode(',',$value); // multiselect
|
|
|
|
|
2013-05-03 17:25:11 +02:00
|
|
|
$prefs[$var] = $value;
|
|
|
|
|
|
|
|
// 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]);
|
2013-05-10 09:50:30 +02:00
|
|
|
|
2013-05-03 17:25:11 +02:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2013-05-03 15:08:08 +02:00
|
|
|
/**
|
|
|
|
* Get content, sel_options and readonlys for given appname and type
|
|
|
|
*
|
2013-05-03 17:25:11 +02:00
|
|
|
* @param string $appname appname or 'common'
|
2013-05-03 15:08:08 +02:00
|
|
|
* @param string $type
|
|
|
|
* @param array &$sel_options
|
|
|
|
* @param array &$readonlys
|
2013-05-10 09:50:30 +02:00
|
|
|
* @param array &$types on return setting-name => setting-type
|
2013-05-03 15:08:08 +02:00
|
|
|
* @param etemplate $tpl
|
|
|
|
* @throws egw_exception_wrong_parameter
|
|
|
|
* @return array content
|
|
|
|
*/
|
2013-05-10 09:50:30 +02:00
|
|
|
function get_content($appname, $type, &$sel_options, &$readonlys, &$types, $tpl)
|
2013-05-03 15:08:08 +02:00
|
|
|
{
|
|
|
|
if (!$this->call_hook($appname, $type))
|
|
|
|
{
|
2013-05-03 17:25:11 +02:00
|
|
|
throw new egw_exception_wrong_parameter("Could not find settings for application: ".$appname);
|
2013-05-03 15:08:08 +02:00
|
|
|
}
|
|
|
|
$attribute = $type == 'group' ? 'user' : $type;
|
2013-05-10 19:22:14 +02:00
|
|
|
//error_log(__METHOD__."('$appname', '$type' ) attribute='$attribute', preferences->account_id=".$GLOBALS['egw']->preferences->get_account_id());
|
2013-05-03 15:08:08 +02:00
|
|
|
|
|
|
|
//_debug_array($this->settings); exit;
|
|
|
|
$sel_options = $readonlys = $content = $tabs = array();
|
|
|
|
// disable all but first tab and name current tab "tab1", for apps not using sections
|
|
|
|
$tab = 'tab1';
|
|
|
|
foreach($this->settings as $setting)
|
|
|
|
{
|
|
|
|
if (!is_array($setting)) continue;
|
|
|
|
if ($type != 'forced' && !empty($GLOBALS['egw']->preferences->forced[$appname][$setting['name']]))
|
|
|
|
{
|
|
|
|
continue; // forced preferences are not displayed, unless we edit them
|
|
|
|
}
|
2013-05-10 09:50:30 +02:00
|
|
|
$types[$setting['name']] = $old_type = $setting['type'];
|
|
|
|
|
|
|
|
switch($old_type)
|
2013-05-03 15:08:08 +02:00
|
|
|
{
|
|
|
|
case 'section':
|
|
|
|
$tab = 'tab'.(1+count($tabs));
|
2013-05-09 11:38:12 +02:00
|
|
|
$tabs[] = array(
|
|
|
|
'id' => $tab,
|
|
|
|
'template' => 'preferences.settings.tab1',
|
|
|
|
'label' => $setting['title'],
|
|
|
|
);
|
2013-05-03 15:08:08 +02:00
|
|
|
// fall through
|
|
|
|
case 'subsection': // is in old code, but never seen it used
|
|
|
|
continue 2;
|
2013-04-28 16:52:41 +02:00
|
|
|
|
2013-05-10 09:50:30 +02:00
|
|
|
case 'notify':
|
2013-05-10 17:56:35 +02:00
|
|
|
$vars = $GLOBALS['egw']->preferences->vars;
|
|
|
|
if (is_array($setting['values'])) $vars += $setting['values'];
|
|
|
|
$GLOBALS['egw']->preferences->{$attribute}[$appname][$setting['name']] =
|
|
|
|
$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"
|
2013-05-10 18:39:42 +02:00
|
|
|
if ($setting['help'] && ($setting['run_lang'] || !isset($setting['run_lang'])))
|
2013-05-10 17:56:35 +02:00
|
|
|
{
|
|
|
|
$setting['help'] = lang($setting['help']);
|
|
|
|
}
|
|
|
|
$setting['help'] .= '<p><b>'.lang('Substitutions and their meanings:').'</b>';
|
|
|
|
foreach($vars as $var => $var_help)
|
|
|
|
{
|
|
|
|
$lname = ($lname = lang($var)) == $var.'*' ? $var : $lname;
|
|
|
|
$setting['help'] .= "<br>\n".'<b>$$'.$lname.'$$</b>: '.$var_help;
|
|
|
|
}
|
|
|
|
$setting['help'] .= "</p>\n";
|
2013-05-10 18:39:42 +02:00
|
|
|
$setting['run_lang'] = false; // already done now
|
2013-05-10 17:56:35 +02:00
|
|
|
// handle as textarea
|
2013-05-10 09:50:30 +02:00
|
|
|
case 'textarea':
|
|
|
|
$setting['type'] = is_a($tpl, 'etemplate_old') ? 'textarea' : 'textbox';
|
|
|
|
$tpl->setElementAttribute($tab.'['.$setting['name'].']', 'multiline', 'true');
|
2013-05-10 10:24:15 +02:00
|
|
|
// anyway setting via css: width: 99%, height: 5em
|
|
|
|
// for old eT use size attribute
|
|
|
|
if (is_a($tpl, 'etemplate_old') && (!empty($setting['cols']) || !empty($setting['rows'])))
|
|
|
|
{
|
|
|
|
$setting['size'] = $setting['rows'].','.$setting['cols'];
|
|
|
|
}
|
2013-05-10 09:50:30 +02:00
|
|
|
break;
|
2013-05-03 17:25:11 +02:00
|
|
|
case 'password':
|
2013-05-03 15:08:08 +02:00
|
|
|
case 'vfs_file':
|
|
|
|
case 'vfs_dir':
|
|
|
|
case 'vfs_dirs':
|
|
|
|
case 'input':
|
|
|
|
$setting['type'] = 'textbox';
|
|
|
|
break;
|
|
|
|
case 'check':
|
|
|
|
$setting['type'] = 'select';
|
|
|
|
$setting['values'] = array('1' => lang('yes'), '0' => lang('no'));
|
|
|
|
break;
|
|
|
|
case 'multiselect':
|
|
|
|
$setting['type'] = 'select';
|
|
|
|
$tpl->setElementAttribute($tab.'['.$setting['name'].']', 'multiple', 5);
|
|
|
|
if (!isset($setting['size'])) $setting['size'] = '5'; // old eT
|
|
|
|
break;
|
|
|
|
case 'color':
|
|
|
|
$setting['type'] = 'colorpicker';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// move values/options to sel_options array
|
|
|
|
if (isset($setting['values']) && is_array($setting['values']))
|
|
|
|
{
|
2013-05-10 17:56:35 +02:00
|
|
|
if ($old_type != 'multiselect' && $old_type != 'notify')
|
2013-05-03 15:08:08 +02:00
|
|
|
{
|
|
|
|
switch($type)
|
|
|
|
{
|
|
|
|
case 'user':
|
|
|
|
$setting['values'] = array('' => lang('Use default'))+$setting['values'];
|
|
|
|
break;
|
2013-05-03 17:25:11 +02:00
|
|
|
case 'default':
|
|
|
|
case 'group':
|
|
|
|
$setting['values'] = array('' => lang('No default'))+$setting['values'];
|
|
|
|
break;
|
2013-05-03 15:08:08 +02:00
|
|
|
case 'forced';
|
2013-05-03 17:25:11 +02:00
|
|
|
$setting['values'] = array('**NULL**' => lang('Users choice'))+$setting['values'];
|
2013-05-03 15:08:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// need to call fix_encoded_options manually, as id is not matching because of autorepeat
|
|
|
|
etemplate_widget_menupopup::fix_encoded_options($setting['values']);
|
|
|
|
$sel_options[$setting['name']] = $setting['values'];
|
|
|
|
}
|
|
|
|
if ($type == 'user')
|
|
|
|
{
|
2013-05-10 19:22:14 +02:00
|
|
|
$default = $GLOBALS['egw']->preferences->group[$appname][$setting['name']] ?
|
|
|
|
$GLOBALS['egw']->preferences->group[$appname][$setting['name']] :
|
|
|
|
$GLOBALS['egw']->preferences->default[$appname][$setting['name']];
|
|
|
|
|
2013-05-03 15:08:08 +02:00
|
|
|
if (isset($setting['values']) && (string)$setting['values'][$default] !== '')
|
|
|
|
{
|
|
|
|
$default = $setting['values'][$default];
|
2013-04-28 16:52:41 +02:00
|
|
|
}
|
2013-05-03 15:08:08 +02:00
|
|
|
elseif (strpos($default, ',') !== false)
|
2013-04-28 16:52:41 +02:00
|
|
|
{
|
2013-05-03 15:08:08 +02:00
|
|
|
$values = array();
|
|
|
|
foreach(explode(',', $default) as $value)
|
|
|
|
{
|
|
|
|
if (isset($setting['values'][$value])) $values[] = $setting['values'][$value];
|
|
|
|
}
|
|
|
|
if ($values) $default = implode(', ', $values);
|
2013-04-28 16:52:41 +02:00
|
|
|
}
|
2013-05-10 18:39:42 +02:00
|
|
|
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']);
|
2013-04-28 16:52:41 +02:00
|
|
|
}
|
2013-05-03 15:08:08 +02:00
|
|
|
$content[$tab][] = array(
|
2013-05-10 09:50:30 +02:00
|
|
|
'name' => $setting['name'],
|
|
|
|
'type' => $setting['type'],
|
|
|
|
'label' => preg_replace('|<br[ /]*>|i', "\n", $setting['label']),
|
2013-05-10 17:56:35 +02:00
|
|
|
'help' => lang($setting['help']), // is html
|
2013-05-10 09:50:30 +02:00
|
|
|
'size' => $setting['size'], // old eT
|
|
|
|
'default' => !empty($default) ? lang('Default').': '.$default : null,
|
|
|
|
'onchange' => $setting['onchange'],
|
2013-05-03 15:08:08 +02:00
|
|
|
);
|
2013-05-10 20:00:33 +02:00
|
|
|
//error_log("appname=$appname, attribute=$attribute, setting=".array2string($setting));
|
2013-05-03 15:08:08 +02:00
|
|
|
$content[$tab][$setting['name']] = $GLOBALS['egw']->preferences->{$attribute}[$appname][$setting['name']];
|
|
|
|
//if ($old_type == 'multiselect') $content[$tab][$setting['name']] = explode(',', $content[$tab][$setting['name']]);
|
|
|
|
}
|
2013-05-09 11:38:12 +02:00
|
|
|
// defining used tabs on run-time
|
|
|
|
if ($tabs) $tpl->setElementAttribute('tabs', 'tabs', $tabs);
|
2013-05-03 15:08:08 +02:00
|
|
|
|
|
|
|
$content['appname'] = $appname;
|
|
|
|
$sel_options['appname'] = array();
|
|
|
|
foreach($GLOBALS['egw']->hooks->hook_implemented('settings') as $app)
|
|
|
|
{
|
|
|
|
if ($app != 'preferences' && $GLOBALS['egw_info']['apps'][$app])
|
|
|
|
{
|
|
|
|
$sel_options['appname'][$app] = $GLOBALS['egw_info']['apps'][$app]['title'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
natcasesort($sel_options['appname']);
|
|
|
|
|
2013-05-03 17:25:11 +02:00
|
|
|
$sel_options['type'] = array(
|
|
|
|
'user' => 'Your preferences',
|
|
|
|
'default' => 'Default preferences',
|
|
|
|
'forced' => 'Forced preferences',
|
|
|
|
);
|
2013-05-03 15:08:08 +02:00
|
|
|
if ($GLOBALS['egw_info']['apps']['admin'])
|
|
|
|
{
|
|
|
|
$content['type'] = $type;
|
2013-05-10 19:22:14 +02:00
|
|
|
if (($id = $GLOBALS['egw']->preferences->get_account_id()) != $GLOBALS['egw_info']['user']['account_id'])
|
2013-05-03 15:08:08 +02:00
|
|
|
{
|
2013-05-10 19:22:14 +02:00
|
|
|
$content['type'] .= ':'.$id;
|
2013-05-03 15:08:08 +02:00
|
|
|
$sel_options['type'][$content['type']] = common::grab_owner_name($GLOBALS['egw']->preferences->account_id);
|
|
|
|
}
|
|
|
|
foreach($GLOBALS['egw']->accounts->search(array('type' => 'groups', 'sort' => 'account_lid')) as $account_id => $group)
|
|
|
|
{
|
2013-05-03 17:25:11 +02:00
|
|
|
$sel_options['type']['group:'.$account_id] = lang('Preferences').' '.common::display_fullname($group['account_lid'], '', '', $account_id);
|
2013-05-03 15:08:08 +02:00
|
|
|
}
|
2013-04-28 16:52:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-03 15:08:08 +02:00
|
|
|
$content['type'] = 'user';
|
2013-05-03 17:25:11 +02:00
|
|
|
$readonlys['type'] = true;
|
2013-04-28 16:52:41 +02:00
|
|
|
}
|
2013-05-03 15:08:08 +02:00
|
|
|
//_debug_array($content); exit;
|
|
|
|
//_debug_array($sel_options); //exit;
|
|
|
|
return $content;
|
2013-04-28 16:52:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get preferences by calling various hooks to supply them
|
|
|
|
*
|
|
|
|
* Sets $this->appname and $this->settings
|
|
|
|
*
|
2013-05-03 17:25:11 +02:00
|
|
|
* @param string $appname appname or 'common'
|
|
|
|
* @param string $type='user' 'default' or 'forced'
|
2013-04-28 16:52:41 +02:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2013-05-03 15:08:08 +02:00
|
|
|
protected function call_hook($appname, $type='user')
|
2013-04-28 16:52:41 +02:00
|
|
|
{
|
2013-05-03 17:25:11 +02:00
|
|
|
$this->appname = $appname == 'common' ? 'preferences' : $appname;
|
2013-04-28 16:52:41 +02:00
|
|
|
|
|
|
|
translation::add_app($this->appname);
|
|
|
|
if($this->appname != 'preferences')
|
|
|
|
{
|
|
|
|
translation::add_app('preferences'); // we need the prefs translations too
|
|
|
|
}
|
|
|
|
|
2013-05-03 15:08:08 +02:00
|
|
|
// make type available, to hooks from applications can use it, eg. activesync
|
|
|
|
$GLOBALS['type'] = $type;
|
|
|
|
|
2013-04-28 16:52:41 +02:00
|
|
|
// 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)
|
|
|
|
{
|
2013-05-03 15:08:08 +02:00
|
|
|
$this->settings = array_merge($this->settings, $settings);
|
2013-04-28 16:52:41 +02:00
|
|
|
}
|
|
|
|
elseif(isset($GLOBALS['settings']) && is_array($GLOBALS['settings']) && $GLOBALS['settings'])
|
|
|
|
{
|
2013-05-03 15:08:08 +02:00
|
|
|
$this->settings = array_merge($this->settings, $GLOBALS['settings']);
|
2013-04-28 16:52:41 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|