diff --git a/preferences/inc/class.preferences_hooks.inc.php b/preferences/inc/class.preferences_hooks.inc.php index d94c9620c4..69f0fef770 100644 --- a/preferences/inc/class.preferences_hooks.inc.php +++ b/preferences/inc/class.preferences_hooks.inc.php @@ -446,6 +446,8 @@ class preferences_hooks } $file['common preferences'] = $GLOBALS['egw']->link('/index.php','menuaction=preferences.uisettings.index&appname=preferences'); + $file['new settings'] = $GLOBALS['egw']->link('/index.php','menuaction=preferences.preferences_settings.index&appname=preferences'); + display_section('preferences',$file); } diff --git a/preferences/inc/class.preferences_settings.inc.php b/preferences/inc/class.preferences_settings.inc.php new file mode 100644 index 0000000000..4fb0a71d15 --- /dev/null +++ b/preferences/inc/class.preferences_settings.inc.php @@ -0,0 +1,205 @@ + + * @package preferences + * @copyright (c) 2013 by Ralf Becker + * @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='') + { + $tpl = new etemplate_new('preferences.settings'); + if (!is_array($content)) + { + $appname = isset($_GET['appname']) ? $_GET['appname'] : 'preferences'; + if (!$this->call_hook($appname)) + { + throw new egw_exception_wrong_parameter("Could not find settings for application: ".$_GET['appname']); + } + //_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'; + $readonlys['tabs'] = array( + 'tab2' => true, + 'tab3' => true, + 'tab4' => true, + 'tab5' => true, + ); + + foreach($this->settings as $setting) + { + if (!is_array($setting)) continue; + switch($setting['type']) + { + case 'section': + $tabs[] = $setting['title']; + $tab = 'tab'.count($tabs); + $tpl->setElementAttribute($tab, 'label', $setting['title']); + $readonlys['tabs'][$tab] = false; + // fall through + case 'subsection': // is in old code, but never seen it used + continue 2; + + case 'input': + $setting['type'] = 'textbox'; + break; + case 'check': + $setting['type'] = 'select'; + $setting['values'] = array('no', 'yes'); + break; + case 'multiselect': + $setting['type'] = 'select'; + break; + case 'color': + $setting['type'] = 'colorpicker'; + break; + } + // move values/options to sel_options array + if (isset($setting['values']) && is_array($setting['values'])) + { + // 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[$tab][count($content[$tab]).'[value]'] = $setting['values']; + unset($setting['values']); + } + $content[$tab][] = $setting; + } + //_debug_array($content); exit; + //_debug_array($sel_options); exit; + } + else + { + $this->appname = $content['appname']; + } + $tpl->exec('preferences.preferences_settings.index', $content, $sel_options, $readonlys, $content); + } + + /** + * Get preferences by calling various hooks to supply them + * + * Sets $this->appname and $this->settings + * + * @param string $appname + * @return boolean + */ + protected 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 "

".__METHOD__."($appname) $this->appname/$appname/$name=$default NOT yet set!

\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; + } +} diff --git a/preferences/templates/default/app.css b/preferences/templates/default/app.css new file mode 100644 index 0000000000..43061f9f83 --- /dev/null +++ b/preferences/templates/default/app.css @@ -0,0 +1,33 @@ +/** + * EGroupware - CSS Styles used by preferences app + * + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package preferences + * @link http://www.egroupware.org + * @author Ralf Becker + * @version $Id$ + */ + +table.prefTable { + width: 100%; +} +tr.prefRow { + position: relative; +} +td.prefName, td.prefValue { + width: 50%; +} +.prefHelp { + position: absolute; + display: none; + width: 98%; + background-color: lightyellow; + border: 1px solid black; + border-radius: 10px; + padding: 5px; + margin-top: 5px; +} +tr.prefRow:hover .prefHelp { + display: block; + z-index: 10; /* FF: displays it under next prefName without */ +} \ No newline at end of file diff --git a/preferences/templates/default/settings.xet b/preferences/templates/default/settings.xet new file mode 100644 index 0000000000..11624c770f --- /dev/null +++ b/preferences/templates/default/settings.xet @@ -0,0 +1,113 @@ + + + + + + + + +