From 22701ce83f19dcdf918beb22de99f446e87fd725 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 20 Apr 2016 18:52:55 +0000 Subject: [PATCH] WIP et2 based site configuration --- admin/inc/class.admin_config.inc.php | 157 ++++++++++++++ admin/templates/default/app.css | 8 + admin/templates/default/config.tpl | 2 +- admin/templates/default/config.xet | 263 +++++++++++++++++++++++ admin/templates/pixelegg/app.css | 7 + api/js/etemplate/et2_widget_selectbox.js | 9 +- doc/config2xet.php | 174 +++++++++++++++ 7 files changed, 617 insertions(+), 3 deletions(-) create mode 100644 admin/inc/class.admin_config.inc.php create mode 100644 admin/templates/default/config.xet create mode 100644 doc/config2xet.php diff --git a/admin/inc/class.admin_config.inc.php b/admin/inc/class.admin_config.inc.php new file mode 100644 index 0000000000..30b1f767e7 --- /dev/null +++ b/admin/inc/class.admin_config.inc.php @@ -0,0 +1,157 @@ + + * @package admin + * @copyright (c) 2016 by Ralf Becker + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ + +use EGroupware\Api; + +/** + * New site configuration for all apps using eTemplate2 $app/templates/default/config.xet + */ +class admin_config +{ + var $public_functions = array('index' => True); + + function index($_content=null) + { + if (is_array($_content)) + { + $_appname = $_content['appname']; + } + elseif (!empty($_GET['appname']) && isset($GLOBALS['egw_info']['apps'][$_GET['appname']])) + { + $_appname = $_GET['appname']; + } + else + { + throw new Api\Exception\WrongParameter("Wrong or missing appname parameter!"); + } + if ($GLOBALS['egw']->acl->check('site_config_acce',1,'admin')) + { + egw::redirect_link('/index.php'); + } + + // load the translations of the app we show too, so they dont need to be in admin! + if ($_appname != 'admin') + { + Api\Translation::add_app($_appname); + } + + switch($_appname) + { + case 'admin': + case 'addressbook': + case 'calendar': + case 'preferences': + $appname = $_appname; + $config_appname = 'phpgwapi'; + break; + case 'phpgwapi': + case '': + /* This keeps the admin from getting into what is a setup-only config */ + egw::redirect_link('/admin/index.php'); + break; + default: + $appname = $_appname; + $config_appname = $appname; + break; + } + + $c = new Api\Config($config_appname); + $c->read_repository(); + if ($_content['cancel'] || ($_content['save'] || $_content['apply']) && $GLOBALS['egw']->acl->check('site_config_acce',2,'admin')) + { + egw::redirect_link('/admin/index.php?ajax=true'); + } + + if ($_content['save'] || $_content['apply']) + { + // support old validation hooks + $_POST = array('newsettings' => &$_content['newsettings']); + + /* Load hook file with functions to validate each config (one/none/all) */ + Api\Hooks::single(array( + 'location' => 'config_validate', + )+$_content['newsettings'], $appname); + + foreach($_content['newsettings'] as $key => $config) + { + if ($config) + { + $c->config_data[$key] = $config; + if (in_array($key, (array)$GLOBALS['egw_info']['server']['found_validation_hook'], true) && function_exists($key)) + { + call_user_func($key, $config, $c); + if($GLOBALS['config_error']) + { + $errors .= lang($GLOBALS['config_error']) . "\n"; + $GLOBALS['config_error'] = False; + } + } + } + // don't erase passwords, since we also don't print them + elseif(strpos($key,'passwd') === false && strpos($key,'password') === false && strpos($key,'root_pw') === false) + { + unset($c->config_data[$key]); + } + } + if(in_array('final_validation', (array)$GLOBALS['egw_info']['server']['found_validation_hook']) && + function_exists('final_validation')) + { + final_validation($_content['newsettings']); + if($GLOBALS['config_error']) + { + $errors .= lang($GLOBALS['config_error']) . "\n"; + $GLOBALS['config_error'] = False; + } + unset($GLOBALS['egw_info']['server']['found_validation_hook']); + } + + $c->save_repository(); + + if(!$errors && !$_content['apply']) + { + egw_framework::message(lang('Configuration saved.'), 'success'); + egw::redirect_link('/index.php', array( + 'menuaction' => 'admin.admin_ui.index', + 'ajax' => 'true' + ), 'admin'); + } + } + + if($errors) + { + egw_framework::message(lang('Error') . ': ' . $errors, 'error'); + unset($errors); + unset($GLOBALS['config_error']); + } + elseif ($_content['apply']) + { + egw_framework::message(lang('Configuration saved.'), 'success'); + } + + Api\Hooks::single('config', $appname); + + $tmpl = new Api\Etemplate($appname.'.config'); + $path = (parse_url($tmpl->rel_path, PHP_URL_SCHEME) !== 'vfs' ? EGW_SERVER_ROOT : '').$tmpl->rel_path; + $content = array('newsettings' => array()); + $config = $c->read_repository(); + + // for security reasons we do not send all config to client-side, but only ones mentioned in templates + $matches = null; + preg_match_all('/id="newsettings\[([^]]+)\]"/', file_get_contents($path), $matches, PREG_PATTERN_ORDER); + foreach($matches[1] as $name) + { + $content['newsettings'][$name] = $config[$name]; + } + + $tmpl->exec('admin.admin_config.index', $content, array(), array(), array('appname' => $appname)); + } +} diff --git a/admin/templates/default/app.css b/admin/templates/default/app.css index 6b65e9ffaa..306a0d259a 100644 --- a/admin/templates/default/app.css +++ b/admin/templates/default/app.css @@ -153,3 +153,11 @@ span#admin-mailaccount_acc_id { select#admin-mailaccount_ident_id { width: 95%; } + +/** + * new et2 site configuration + */ +table.admin-config td.subHeader span { + font-weight: bold; + font-size: 110%; +} \ No newline at end of file diff --git a/admin/templates/default/config.tpl b/admin/templates/default/config.tpl index 8b343bbb80..1e43ca785d 100644 --- a/admin/templates/default/config.tpl +++ b/admin/templates/default/config.tpl @@ -233,7 +233,7 @@ {lang_Passwords_require_a_minimum_number_of_characters}: