eGroupWare PHP Cross Reference Groupware Applications

Source: /admin/inc/class.uiconfig.inc.php - 281 lines - 8048 bytes - Summary - Text - Print

Description: EGgroupware admin - site configuration

   1  <?php
   2  /**
   3   * EGgroupware admin - site configuration
   4   *
   5   * @link http://www.egroupware.org
   6   * @author Miles Lott <milos@groupwhere.org>
   7   * @package admin
   8   * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
   9   * @version $Id$
  10   */
  11  
  12  /**
  13   * Site configuration for all apps using an $app/templates/default/config.tpl
  14   */
  15  class uiconfig
  16  {
  17      var $public_functions = array('index' => True);
  18  
  19  	function index($params=null)
  20      {
  21          // allowing inline js
  22          egw_framework::csp_script_src_attrs('unsafe-inline');
  23  
  24          // for POST requests validate CSRF token (or terminate request)
  25          if ($_SERVER['REQUEST_METHOD'] == 'POST')
  26          {
  27              egw_csrf::validate($_POST['csrf_token'], __CLASS__);
  28          }
  29  
  30          if (empty($_GET['appname']) && isset($params['appname']))
  31          {
  32              $_appname = $params['appname'];
  33          }
  34          else
  35          {
  36              //_debug_array($params);
  37              $_appname = $_GET['appname'];
  38          }
  39          if ($GLOBALS['egw']->acl->check('site_config_acce',1,'admin'))
  40          {
  41              egw::redirect_link('/index.php');
  42          }
  43  
  44          // load the translations of the app we show too, so they dont need to be in admin!
  45          if ($_appname != 'admin')
  46          {
  47              translation::add_app($_appname);
  48          }
  49  
  50          if(get_magic_quotes_gpc() && is_array($_POST['newsettings']))
  51          {
  52              $_POST['newsettings'] = array_stripslashes($_POST['newsettings']);
  53          }
  54  
  55          switch($_appname)
  56          {
  57              case 'admin':
  58              case 'addressbook':
  59              case 'calendar':
  60              case 'preferences':
  61                  /*
  62                  Other special apps can go here for now, e.g.:
  63                  case 'bogusappname':
  64                  */
  65                  $appname = $_appname;
  66                  $config_appname = 'phpgwapi';
  67                  break;
  68              case 'phpgwapi':
  69              case '':
  70                  /* This keeps the admin from getting into what is a setup-only config */
  71                  egw::redirect_link('/admin/index.php');
  72                  break;
  73              default:
  74                  $appname = $_appname;
  75                  $config_appname = $appname;
  76                  break;
  77          }
  78          if (ob_get_contents()) ob_end_flush(); // if there is output in buffer, flush it now.
  79          $t = new Template(common::get_tpl_dir($appname));
  80          $t->set_unknowns('keep');
  81          $t->set_file(array('config' => 'config.tpl'));
  82          $t->set_block('config','header','header');
  83  
  84          // fix header templates missing essential parts like display of validation errors
  85          $header = $t->get_var('header');
  86          if (strpos($header, '{hidden_vars}') === false)
  87          {
  88              if (strpos($header, '<table'))
  89              {
  90                  list($header, $table) = explode('<table', $header);
  91                  $header .= "{hidden_vars}\n<table".$table;
  92              }
  93              else
  94              {
  95                  $header .= "{hidden_vars}\n";
  96              }
  97          }
  98          $t->set_var('header', $header);
  99  
 100          $t->set_block('config','body','body');
 101          $t->set_block('config','footer','footer');
 102  
 103          // fix footer submit buttons to just {submit} {cancel}
 104          $t->set_var('footer', preg_replace('/<input[^>]+value="{lang_(submit|cancel)}"[^>]*>/', '{$1}', $t->get_var('footer')));
 105  
 106          $c = new config($config_appname);
 107          $c->read_repository();
 108          if ($_POST['cancel'] || ($_POST['submit'] || $_POST['save'] || $_POST['apply']) && $GLOBALS['egw']->acl->check('site_config_acce',2,'admin'))
 109          {
 110              egw::redirect_link('/admin/index.php?ajax=true');
 111          }
 112  
 113          if ($_POST['submit'] || $_POST['save'] || $_POST['apply'])
 114          {
 115              /* Load hook file with functions to validate each config (one/none/all) */
 116              $GLOBALS['egw']->hooks->single('config_validate',$appname);
 117  
 118              foreach($_POST['newsettings'] as $key => $config)
 119              {
 120                  if ($config)
 121                  {
 122                      $c->config_data[$key] = $config;
 123                      if (in_array($key, (array)$GLOBALS['egw_info']['server']['found_validation_hook'], true) && function_exists($key))
 124                      {
 125                          call_user_func($key,$config);
 126                          if($GLOBALS['config_error'])
 127                          {
 128                              $errors .= lang($GLOBALS['config_error']) . "\n";
 129                              $GLOBALS['config_error'] = False;
 130                          }
 131                      }
 132                  }
 133                  /* don't erase passwords, since we also don't print them */
 134                  elseif(strpos($key,'passwd') === false && strpos($key,'password') === false && strpos($key,'root_pw') === false)
 135                  {
 136                      unset($c->config_data[$key]);
 137                  }
 138              }
 139              if(in_array('final_validation', (array)$GLOBALS['egw_info']['server']['found_validation_hook']) &&
 140                  function_exists('final_validation'))
 141              {
 142                  final_validation($_POST['newsettings']);
 143                  if($GLOBALS['config_error'])
 144                  {
 145                      $errors .= lang($GLOBALS['config_error']) . "\n";
 146                      $GLOBALS['config_error'] = False;
 147                  }
 148                  unset($GLOBALS['egw_info']['server']['found_validation_hook']);
 149              }
 150  
 151              $c->save_repository();
 152  
 153              if(!$errors && !$_POST['apply'])
 154              {
 155                  egw_framework::message(lang('Configuration saved.'), 'success');
 156                  egw::redirect_link('/index.php', array(
 157                      'menuaction' => 'admin.admin_ui.index',
 158                      'ajax' => 'true'
 159                  ), 'admin');
 160              }
 161          }
 162  
 163          $t->set_var('error','');
 164          if($errors)
 165          {
 166              egw_framework::message(lang('Error') . ': ' . $errors, 'error');
 167              unset($errors);
 168              unset($GLOBALS['config_error']);
 169          }
 170          elseif ($_POST['apply'])
 171          {
 172              egw_framework::message(lang('Configuration saved.'), 'success');
 173          }
 174          $t->set_var('title',lang('Site Configuration'));
 175          $t->set_var('action_url',$GLOBALS['egw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname));
 176          $t->set_var('th_bg',     $GLOBALS['egw_info']['theme']['th_bg']);
 177          $t->set_var('th_text',   $GLOBALS['egw_info']['theme']['th_text']);
 178          $t->set_var('row_on',    $GLOBALS['egw_info']['theme']['row_on']);
 179          $t->set_var('row_off',   $GLOBALS['egw_info']['theme']['row_off']);
 180          $t->set_var('hidden_vars', html::input_hidden('csrf_token', egw_csrf::token(__CLASS__)));
 181  
 182          $vars = $t->get_undefined('body');
 183  
 184          if ($GLOBALS['egw']->hooks->single('config',$appname))    // reload the config-values, they might have changed
 185          {
 186              $c->read_repository();
 187          }
 188          foreach($vars as $value)
 189          {
 190              $valarray = explode('_',$value);
 191              $type = array_shift($valarray);
 192              $newval = implode(' ',$valarray);
 193  
 194              switch ($type)
 195              {
 196                  case 'lang':
 197                      $t->set_var($value,lang($newval));
 198                      break;
 199                  case 'value':
 200                      $newval = str_replace(' ','_',$newval);
 201                      /* Don't show passwords in the form */
 202                      if(strpos($value,'passwd') !== false || strpos($value,'password') !== false || strpos($value,'root_pw') !== false)
 203                      {
 204                          $t->set_var($value,'');
 205                      }
 206                      else
 207                      {
 208                          $t->set_var($value,$c->config_data[$newval]);
 209                      }
 210                      break;
 211                  /*
 212                  case 'checked':
 213                      $newval = str_replace(' ','_',$newval);
 214                      if ($c->config_data[$newval])
 215                      {
 216                          $t->set_var($value,' checked');
 217                      }
 218                      else
 219                      {
 220                          $t->set_var($value,'');
 221                      }
 222                      break;
 223                  */
 224                  case 'selected':
 225                      $configs = array();
 226                      $newvals = explode(' ',$newval);
 227                      $setting = end($newvals);
 228                      for ($i=0;$i<(count($newvals) - 1); $i++)
 229                      {
 230                          $configs[] = $newvals[$i];
 231                      }
 232                      $config = implode('_',$configs);
 233                      /* echo $config . '=' . $c->config_data[$config]; */
 234                      if ($c->config_data[$config] == $setting)
 235                      {
 236                          $t->set_var($value,' selected');
 237                      }
 238                      else
 239                      {
 240                          $t->set_var($value,'');
 241                      }
 242                      break;
 243                  case 'hook':
 244                      $newval = str_replace(' ','_',$newval);
 245                      if(function_exists($newval))
 246                      {
 247                          $t->set_var($value,$newval($c->config_data));
 248                      }
 249                      else
 250                      {
 251                          $t->set_var($value,'');
 252                      }
 253                      break;
 254                  case 'call':    // eg. call_class::method or call_app.class.method
 255                      $newval = str_replace(' ','_',$newval);
 256                      $t->set_var($value,ExecMethod($newval,$c->config_data));
 257                      break;
 258                  default:
 259                      $t->set_var($value,'');
 260                      break;
 261              }
 262          }
 263          $t->set_var('submit', '<div class="dialogFooterToolbar" style="text-align: left">'.
 264              ($GLOBALS['egw']->acl->check('site_config_acce',2,'admin') ? '' :
 265                  html::submit_button('save', 'Save')."\n".
 266                  html::submit_button('apply', 'Apply')));
 267          $t->set_var('cancel', html::submit_button('cancel', 'Cancel').'</div>');
 268  
 269          $GLOBALS['egw_info']['flags']['app_header'] = lang('Site configuration').
 270              ($appname != 'admin' ? ': '.lang($appname) : '');
 271  
 272          // render the page
 273          $GLOBALS['egw']->framework->render(
 274              '<div id="admin-config-'.$appname.'" class="admin-config">'.
 275              $t->parse('out','header').
 276              $t->fp('out','body').
 277              $t->fp('out','footer').'</div>',
 278              null,true
 279          );
 280      }
 281  }

title

Description

title

Description

title

Description

title

title

Body