function index() { $errors = ''; $referer = phpgw::get_var('referer', 'url', 'GET'); if ($referer) { $_redir = $referer; $GLOBALS['phpgw']->session->appsession('session_data', 'admin_config', $referer); } else { $referer = $GLOBALS['phpgw']->session->appsession('session_data', 'admin_config'); if ($referer == -1) { $referer = ''; } $_redir = $referer ? $referer : $GLOBALS['phpgw']->link('/admin/index.php'); } $appname = phpgw::get_var('appname', 'string', 'GET'); $GLOBALS['phpgw_info']['flags']['menu_selection'] = "admin::{$appname}::index"; $GLOBALS['phpgw_info']['apps']['manual']['app'] = $appname; // override the appname fetched from the referer for the manual. switch ($appname) { case 'admin': //case 'preferences': //$appname = 'preferences'; //case 'preferences': //$appname = 'preferences'; case 'addressbook': case 'calendar': case 'email': case 'nntp': /* Other special apps can go here for now, e.g.: case 'bogusappname': */ $config_appname = 'phpgwapi'; break; case 'phpgwapi': case '': /* This keeps the admin from getting into what is a setup-only config */ Header('Location: ' . $_redir); break; default: $config_appname = $appname; break; } $t =& $GLOBALS['phpgw']->template; $t->set_root($GLOBALS['phpgw']->common->get_tpl_dir($appname)); $t->set_file(array('config' => 'config.tpl')); $t->set_block('config', 'body', 'body'); $c = CreateObject('phpgwapi.config', $config_appname); $c->read(); if ($c->config_data) { $current_config = $c->config_data; } if (isset($_POST['cancel']) && $_POST['cancel']) { Header('Location: ' . str_replace('&', '&', $_redir)); } $errors = ''; if (isset($_POST['submit']) && $_POST['submit']) { /* Load hook file with functions to validate each config (one/none/all) */ $GLOBALS['phpgw']->hooks->single('config_validate', $appname); while (list($key, $config) = each($_POST['newsettings'])) { if ($config) { if (isset($GLOBALS['phpgw_info']['server']['found_validation_hook']) && $GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists($key)) { call_user_func($key, $config); if ($GLOBALS['config_error']) { $errors .= lang($GLOBALS['config_error']) . ' '; $GLOBALS['config_error'] = False; } else { $c->config_data[$key] = $config; } } else { $c->config_data[$key] = $config; } } else { /* don't erase passwords, since we also don't print them */ if (!preg_match('/passwd/', $key) && !preg_match('/password/', $key) && !preg_match('/root_pw/', $key)) { unset($c->config_data[$key]); } } } if (isset($GLOBALS['phpgw_info']['server']['found_validation_hook']) && $GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists('final_validation')) { final_validation($newsettings); if ($GLOBALS['config_error']) { $errors .= lang($GLOBALS['config_error']) . ' '; $GLOBALS['config_error'] = False; } unset($GLOBALS['phpgw_info']['server']['found_validation_hook']); } $c->save_repository(True); if (!$errors) { $GLOBALS['phpgw']->session->appsession('session_data', 'admin_config', -1); Header('Location: ' . $_redir); $GLOBALS['phpgw_info']['flags']['nodisplay'] = true; exit; } } if (isset($errors) && $errors) { $t->set_var(array('error' => lang('Error: %1', $errors), 'error_class' => 'error')); unset($errors); unset($GLOBALS['config_error']); } else { $t->set_var(array('error' => '', 'error_class' => '')); } $t->set_var(array('action_url' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'admin.uiconfig.index', 'appname' => $appname)), 'lang_cancel' => lang('cancel'), 'lang_submit' => lang('save'), 'title' => lang('Site Configuration'))); // $t->unknown_regexp = 'loose'; $vars = $t->get_undefined('body'); // $t->unknown_regexp = ''; $GLOBALS['phpgw']->hooks->single('config', $appname); if (is_array($vars)) { foreach ($vars as $value) { $valarray = explode('_', $value); $type = $valarray[0]; $new = $newval = ''; while ($chunk = next($valarray)) { $new[] = $chunk; } $newval = implode(' ', $new); switch ($type) { case 'lang': $t->set_var($value, $GLOBALS['phpgw']->translation->translate($newval, array(), false, $appname)); break; case 'value': $newval = preg_replace('/ /', '_', $newval); /* Don't show passwords in the form */ if (!isset($current_config[$newval]) || preg_match('/passwd/', $value) || preg_match('/password/', $value) || preg_match('/root_pw/', $value)) { $t->set_var($value, ''); } else { $t->set_var($value, isset($current_config[$newval]) ? $current_config[$newval] : ''); } break; case 'checked': /* '+' is used as a delimiter for the check value */ list($newvalue, $check) = preg_split('/\\+/', $newval); $newval = preg_replace('/ /', '_', $newvalue); if ($current_config[$newval] == $check) { $t->set_var($value, ' checked'); } else { $t->set_var($value, ''); } break; case 'selected': $configs = array(); $config = ''; $newvals = explode(' ', $newval); $setting = end($newvals); for ($i = 0; $i < count($newvals) - 1; $i++) { $configs[] = $newvals[$i]; } $config = implode('_', $configs); /* echo $config . '=' . $current_config[$config]; */ if (isset($current_config[$config]) && $current_config[$config] == $setting) { $t->set_var($value, ' selected'); } else { $t->set_var($value, ''); } break; case 'hook': $newval = preg_replace('/ /', '_', $newval); if (function_exists($newval)) { $t->set_var($value, $newval($current_config)); } else { $t->set_var($value, ''); } break; default: $t->set_var($value, ''); break; } } } $GLOBALS['phpgw']->common->phpgw_header(true); $t->pfp('out', 'config'); }
function index() { if ($GLOBALS['phpgw']->acl->check('site_config_access', 1, 'admin')) { $GLOBALS['phpgw']->redirect_link('/index.php'); } if (get_magic_quotes_gpc() && is_array($_POST['newsettings'])) { $_POST['newsettings'] = array_map("stripslashes", $_POST['newsettings']); } switch ($_GET['appname']) { case 'admin': case 'addressbook': case 'calendar': case 'email': case 'nntp': /* Other special apps can go here for now, e.g.: case 'bogusappname': */ $appname = $_GET['appname']; $config_appname = 'phpgwapi'; break; case 'phpgwapi': case '': /* This keeps the admin from getting into what is a setup-only config */ $GLOBALS['phpgw']->redirect_link('/admin/index.php'); break; default: $appname = $_GET['appname']; $config_appname = $appname; break; } $t = CreateObject('phpgwapi.Template', $GLOBALS['phpgw']->common->get_tpl_dir($appname)); $t->set_unknowns('keep'); $t->set_file(array('config' => 'config.tpl')); $t->set_block('config', 'header', 'header'); $t->set_block('config', 'body', 'body'); $t->set_block('config', 'footer', 'footer'); $c = CreateObject('phpgwapi.config', $config_appname); $c->read_repository(); if ($c->config_data) { $current_config = $c->config_data; } if ($_POST['cancel'] || $_POST['submit'] && $GLOBALS['phpgw']->acl->check('site_config_access', 2, 'admin')) { $GLOBALS['phpgw']->redirect_link('/admin/index.php'); } if ($_POST['submit']) { /* Load hook file with functions to validate each config (one/none/all) */ $GLOBALS['phpgw']->hooks->single('config_validate', $appname); foreach ($_POST['newsettings'] as $key => $config) { if ($config) { if ($GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists($key)) { call_user_func($key, $config); if ($GLOBALS['config_error']) { $errors .= lang($GLOBALS['config_error']) . ' '; $GLOBALS['config_error'] = False; } else { $c->config_data[$key] = $config; } } else { $c->config_data[$key] = $config; } } else { /* don't erase passwords, since we also don't print them */ if (!ereg('passwd', $key) && !ereg('password', $key) && !ereg('root_pw', $key)) { unset($c->config_data[$key]); } } } if ($GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists('final_validation')) { final_validation($newsettings); if ($GLOBALS['config_error']) { $errors .= lang($GLOBALS['config_error']) . ' '; $GLOBALS['config_error'] = False; } unset($GLOBALS['phpgw_info']['server']['found_validation_hook']); } $c->save_repository(); if (!$errors) { $GLOBALS['phpgw']->redirect_link('/admin/index.php'); } } if ($errors) { $t->set_var('error', lang('Error') . ': ' . $errors); $t->set_var('th_err', '#FF8888'); unset($errors); unset($GLOBALS['config_error']); } else { $t->set_var('error', ''); $t->set_var('th_err', $GLOBALS['phpgw_info']['theme']['th_bg']); } if (!@is_object($GLOBALS['phpgw']->js)) { $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); } $GLOBALS['phpgw']->js->validate_file('jscode', 'openwindow', 'admin'); $GLOBALS['phpgw']->common->phpgw_header(); echo parse_navbar(); $t->set_var('title', lang('Site Configuration')); $t->set_var('action_url', $GLOBALS['phpgw']->link('/index.php', 'menuaction=admin.uiconfig.index&appname=' . $appname)); $t->set_var('th_bg', $GLOBALS['phpgw_info']['theme']['th_bg']); $t->set_var('th_text', $GLOBALS['phpgw_info']['theme']['th_text']); $t->set_var('row_on', $GLOBALS['phpgw_info']['theme']['row_on']); $t->set_var('row_off', $GLOBALS['phpgw_info']['theme']['row_off']); $t->pparse('out', 'header'); $vars = $t->get_undefined('body'); $GLOBALS['phpgw']->hooks->single('config', $appname); foreach ($vars as $value) { $valarray = explode('_', $value); $type = array_shift($valarray); $newval = implode(' ', $valarray); switch ($type) { case 'lang': $t->set_var($value, lang($newval)); break; case 'value': $newval = str_replace(' ', '_', $newval); /* Don't show passwords in the form */ if (ereg('passwd', $value) || ereg('password', $value) || ereg('root_pw', $value)) { $t->set_var($value, ''); } else { $t->set_var($value, $current_config[$newval]); } break; /* case 'checked': $newval = str_replace(' ','_',$newval); if ($current_config[$newval]) { $t->set_var($value,' checked'); } else { $t->set_var($value,''); } break; */ /* case 'checked': $newval = str_replace(' ','_',$newval); if ($current_config[$newval]) { $t->set_var($value,' checked'); } else { $t->set_var($value,''); } break; */ case 'selected': $configs = array(); $config = ''; $newvals = explode(' ', $newval); $setting = end($newvals); for ($i = 0; $i < count($newvals) - 1; $i++) { $configs[] = $newvals[$i]; } $config = implode('_', $configs); /* echo $config . '=' . $current_config[$config]; */ if ($current_config[$config] == $setting) { $t->set_var($value, ' selected'); } else { $t->set_var($value, ''); } break; case 'hook': $newval = str_replace(' ', '_', $newval); if (function_exists($newval)) { $t->set_var($value, $newval($current_config)); } else { $t->set_var($value, ''); } break; default: $t->set_var($value, ''); break; } } $t->pfp('out', 'body'); $t->set_var('lang_submit', $GLOBALS['phpgw']->acl->check('site_config_access', 2, 'admin') ? lang('Cancel') : lang('Save')); $t->set_var('lang_cancel', lang('Cancel')); $t->pfp('out', 'footer'); }