[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/setup/ -> config.php (source)

   1  <?php
   2    /**************************************************************************\
   3    * eGroupWare - Setup                                                       *
   4    * http://www.egroupware.org                                                *
   5    * --------------------------------------------                             *
   6    *  This program is free software; you can redistribute it and/or modify it *
   7    *  under the terms of the GNU General Public License as published by the   *
   8    *  Free Software Foundation; either version 2 of the License, or (at your  *
   9    *  option) any later version.                                              *
  10    \**************************************************************************/
  11  
  12    /* $Id: config.php 20462 2006-03-08 09:46:26Z ralfbecker $ */
  13  
  14      $GLOBALS['egw_info'] = array(
  15          'flags' => array(
  16              'noheader' => True,
  17              'nonavbar' => True,
  18              'currentapp' => 'home',
  19              'noapi' => True
  20      ));
  21      include ('./inc/functions.inc.php');
  22  
  23      /*
  24      Authorize the user to use setup app and load the database
  25      Does not return unless user is authorized
  26      */
  27      if(!$GLOBALS['egw_setup']->auth('Config') || @$_POST['cancel'])
  28      {
  29          Header('Location: index.php');
  30          exit;
  31      }
  32  
  33      $tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup');
  34      $setup_tpl = CreateObject('setup.Template',$tpl_root);
  35  
  36      $setup_tpl->set_file(array(
  37          'T_head' => 'head.tpl',
  38          'T_footer' => 'footer.tpl',
  39          'T_alert_msg' => 'msg_alert_msg.tpl',
  40          'T_config_pre_script' => 'config_pre_script.tpl',
  41          'T_config_post_script' => 'config_post_script.tpl'
  42      ));
  43  
  44      /* Following to ensure windows file paths are saved correctly */
  45      set_magic_quotes_runtime(0);
  46  
  47      $GLOBALS['egw_setup']->loaddb();
  48  
  49      /* Check api version, use correct table */
  50      $setup_info = $GLOBALS['egw_setup']->detection->get_db_versions();
  51  
  52      $newsettings = $_POST['newsettings'];
  53  
  54      if(@get_var('submit',Array('POST')) && @$newsettings)
  55      {
  56          /* Load hook file with functions to validate each config (one/none/all) */
  57          $GLOBALS['egw_setup']->hook('config_validate','setup');
  58  
  59          $datetime = CreateObject('phpgwapi.datetime');
  60          switch((int)$newsettings['daytime_port'])
  61          {
  62              case 13:
  63                  $newsettings['tz_offset'] = $datetime->getntpoffset();
  64                  break;
  65              case 80:
  66                  $newsettings['tz_offset'] = $datetime->gethttpoffset();
  67                  break;
  68              default:
  69                  $newsettings['tz_offset'] = $datetime->getbestguess();
  70                  break;
  71          }
  72          unset($datetime);
  73  
  74          print_debug('TZ_OFFSET',$newsettings['tz_offset']);
  75  
  76          $GLOBALS['egw_setup']->db->transaction_begin();
  77          foreach($newsettings as $setting => $value)
  78          {
  79              if($GLOBALS['egw_info']['server']['found_validation_hook'] && @function_exists($setting))
  80              {
  81                  $setting($newsettings);
  82                  if($GLOBALS['config_error'])
  83                  {
  84                      $GLOBALS['error'] .= '<b>'.$GLOBALS['config_error'] ."</b><br />\n";
  85                      $GLOBALS['config_error'] = '';
  86                      /* Bail out, stop writing config data */
  87                      break;
  88                  }
  89                  $value = $newsettings[$setting];    // it might be changed by the validation hook
  90              }
  91              /* Don't erase passwords, since we also do not print them below */
  92              if(empty($value) && !(stristr($setting,'passwd') || stristr($setting,'password') || stristr($setting,'root_pw')))
  93              {
  94                  $GLOBALS['egw_setup']->db->delete($GLOBALS['egw_setup']->config_table,array(
  95                      'config_name' => $setting,
  96                      'config_app'  => 'phpgwapi',
  97                  ),__LINE__,__FILE__);
  98                  unset($newsettings[$setting]);
  99              }
 100              elseif($value)
 101              {
 102                  $GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->config_table,array(
 103                      'config_value' => $value,
 104                  ),array(
 105                      'config_name' => $setting,
 106                      'config_app'  => 'phpgwapi',
 107                  ),__LINE__,__FILE__);
 108              }
 109          }
 110          if(!$GLOBALS['error'])
 111          {
 112              $GLOBALS['egw_setup']->db->transaction_commit();
 113  
 114              if($newsettings['auth_type'] == 'ldap')
 115              {
 116                  Header('Location: ldap.php');
 117                  exit;
 118              }
 119              else
 120              {
 121                  Header('Location: index.php');
 122                  exit;
 123              }
 124          }
 125      }
 126  
 127      $GLOBALS['egw_setup']->html->show_header(lang('Configuration'),False,'config',$GLOBALS['egw_setup']->ConfigDomain . '(' . $GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'] . ')');
 128  
 129      // if we have an validation error, use the new settings made by the user and not the stored config
 130      if($GLOBALS['error'] && is_array($newsettings))
 131      {
 132          $GLOBALS['current_config'] = $newsettings;
 133      }
 134      else
 135      {
 136          $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'*',false,__LINES__,__FILES__);
 137          while($GLOBALS['egw_setup']->db->next_record())
 138          {
 139              $GLOBALS['current_config'][$GLOBALS['egw_setup']->db->f('config_name')] = $GLOBALS['egw_setup']->db->f('config_value');
 140          }
 141      }
 142      $setup_tpl->pparse('out','T_config_pre_script');
 143  
 144      /* Now parse each of the templates we want to show here */
 145      class phpgw
 146      {
 147          var $common;
 148          var $accounts;
 149          var $applications;
 150          var $db;
 151      }
 152      $GLOBALS['egw'] = new phpgw;
 153      $GLOBALS['egw']->common =& CreateObject('phpgwapi.common');
 154      $GLOBALS['egw']->db     =& $GLOBALS['egw_setup']->db;
 155  
 156      $t = CreateObject('setup.Template',$GLOBALS['egw']->common->get_tpl_dir('setup'));
 157  
 158      $t->set_unknowns('keep');
 159      $t->set_file(array('config' => 'config.tpl'));
 160      $t->set_block('config','body','body');
 161  
 162      $vars = $t->get_undefined('body');
 163      $GLOBALS['egw_setup']->hook('config','setup');
 164  
 165      foreach($vars as $value)
 166      {
 167          $valarray = explode('_',$value);
 168          $type = $valarray[0];
 169          $new = $newval = '';
 170  
 171          while($chunk = next($valarray))
 172          {
 173              $new[] = $chunk;
 174          }
 175          $newval = implode(' ',$new);
 176  
 177          switch ($type)
 178          {
 179              case 'lang':
 180                  $t->set_var($value,lang($newval));
 181                  break;
 182              case 'value':
 183                  $newval = str_replace(' ','_',$newval);
 184                  /* Don't show passwords in the form */
 185                  if(strstr($value,'passwd') || strstr($value,'password') || strstr($value,'root_pw'))
 186                  {
 187                      $t->set_var($value,'');
 188                  }
 189                  else
 190                  {
 191                      $t->set_var($value,@$current_config[$newval]);
 192                  }
 193                  break;
 194              case 'selected':
 195                  $configs = array();
 196                  $config  = '';
 197                  $newvals = explode(' ',$newval);
 198                  $setting = end($newvals);
 199                  for($i=0;$i<(count($newvals) - 1); $i++)
 200                  {
 201                      $configs[] = $newvals[$i];
 202                  }
 203                  $config = implode('_',$configs);
 204                  /* echo $config . '=' . $current_config[$config]; */
 205                  if(@$current_config[$config] == $setting)
 206                  {
 207                      $t->set_var($value,' selected');
 208                  }
 209                  else
 210                  {
 211                      $t->set_var($value,'');
 212                  }
 213                  break;
 214              case 'hook':
 215                  $newval = str_replace(' ','_',$newval);
 216                  $t->set_var($value,$newval($current_config));
 217                  break;
 218              default:
 219                  $t->set_var($value,'');
 220                  break;
 221          }
 222      }
 223  
 224      if($GLOBALS['error'])
 225      {
 226          if($GLOBALS['error'] == 'badldapconnection')
 227          {
 228              /* Please check the number and dial again :) */
 229              $GLOBALS['egw_setup']->html->show_alert_msg('Error',
 230                  lang('There was a problem trying to connect to your LDAP server. <br />'
 231                      .'please check your LDAP server configuration') . '.');
 232          }
 233  
 234          $GLOBALS['egw_setup']->html->show_alert_msg('Error',$GLOBALS['error'].'<p>');
 235      }
 236  
 237      $t->pfp('out','body');
 238      unset($t);
 239  
 240      $setup_tpl->set_var('more_configs',lang('Please login to egroupware and run the admin application for additional site configuration') . '.');
 241  
 242      $setup_tpl->set_var('lang_submit',lang('Save'));
 243      $setup_tpl->set_var('lang_cancel',lang('Cancel'));
 244      $setup_tpl->pparse('out','T_config_post_script');
 245  
 246      $GLOBALS['egw_setup']->html->show_footer();
 247  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7