[ Index ]
 

Code source de Horde 3.1.3

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

title

Body

[fermer]

/admin/setup/ -> config.php (source)

   1  <?php
   2  /**
   3   * $Horde: horde/admin/setup/config.php,v 1.24.4.10 2006/03/30 10:15:30 selsky Exp $
   4   *
   5   * Copyright 1999-2006 Charles J. Hagenbuch <chuck@horde.org>
   6   * Copyright 1999-2006 Jon Parise <jon@horde.org>
   7   *
   8   * See the enclosed file COPYING for license information (LGPL).  If you
   9   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  10   */
  11  
  12  @define('HORDE_BASE', dirname(__FILE__) . '/../..');
  13  require_once  HORDE_BASE . '/lib/base.php';
  14  require_once 'Horde/Form.php';
  15  require_once 'Horde/Form/Action.php';
  16  require_once 'Horde/Form/Renderer.php';
  17  require_once 'Horde/Config.php';
  18  require_once 'Horde/Variables.php';
  19  
  20  if (!Auth::isAdmin()) {
  21      Horde::fatal('Forbidden.', __FILE__, __LINE__);
  22  }
  23  
  24  if (!Util::extensionExists('domxml') && !Util::extensionExists('dom')) {
  25      Horde::fatal('You need the domxml or dom PHP extension to use the configuration tool.', __FILE__, __LINE__);
  26  }
  27  
  28  $app = Util::getFormData('app');
  29  $appname = $registry->get('name', $app);
  30  $title = sprintf(_("%s Setup"), $appname);
  31  
  32  if ($app === null &&
  33      in_array($app, $registry->listApps(array('inactive', 'hidden', 'notoolbar', 'active', 'admin')))) {
  34      $notification->push(_("Invalid application."), 'horde.error');
  35      $url = Horde::applicationUrl('admin/setup/index.php', true);
  36      header('Location: ' . $url);
  37      exit;
  38  }
  39  
  40  $vars = Variables::getDefaultVariables();
  41  $form = &new ConfigForm($vars, $app);
  42  $form->setButtons(sprintf(_("Generate %s Configuration"), $appname));
  43  if (file_exists($registry->get('fileroot', $app) . '/config/conf.php.bak')) {
  44      $form->appendButtons(_("Revert Configuration"));
  45  }
  46  
  47  $php = '';
  48  if (Util::getFormData('submitbutton') == _("Revert Configuration")) {
  49      $path = $registry->get('fileroot', $app) . '/config';
  50      if (@copy($path . '/conf.php.bak', $path . '/conf.php')) {
  51          $notification->push(_("Successfully reverted configuration. Reload to see changes."), 'horde.success');
  52          @unlink($path . '/conf.php.bak');
  53      } else {
  54          $notification->push(_("Could not revert configuration."), 'horde.error');
  55      }
  56  } elseif ($form->validate($vars)) {
  57      $config = &new Horde_Config($app);
  58      $php = $config->generatePHPConfig($vars);
  59      $path = $registry->get('fileroot', $app) . '/config';
  60      if (file_exists($path . '/conf.php')) {
  61          if (@copy($path . '/conf.php', $path . '/conf.php.bak')) {
  62              $notification->push(sprintf(_("Successfully saved the backup configuration file %s."), Util::realPath($path . '/conf.php.bak')), 'horde.success');
  63          } else {
  64              $notification->push(sprintf(_("Could not save the backup configuration file %s."), Util::realPath($path . '/conf.php.bak')), 'horde.warning');
  65          }
  66      }
  67      if ($fp = @fopen($path . '/conf.php', 'w')) {
  68          /* Can write, so output to file. */
  69          fwrite($fp, String::convertCharset($php, NLS::getCharset(), 'iso-8859-1'));
  70          fclose($fp);
  71          $notification->push(sprintf(_("Successfully wrote %s"), Util::realPath($path . '/conf.php')), 'horde.success');
  72          $registry->clearCache();
  73          header('Location: ' . Horde::applicationUrl('admin/setup/index.php', true));
  74          exit;
  75      } else {
  76          /* Cannot write. */
  77          $notification->push(sprintf(_("Could not save the configuration file %s. You can either use one of the options to save the code back on %s or copy manually the code below to %s."), Util::realPath($path . '/conf.php'), Horde::link(Horde::url('index.php') . '#update', _("Setup")) . _("Setup") . '</a>', Util::realPath($path . '/conf.php')), 'horde.warning', array('content.raw'));
  78          /* Save to session. */
  79          $_SESSION['_config'][$app] = $php;
  80      }
  81  } elseif ($form->isSubmitted()) {
  82      $notification->push(_("There was an error in the configuration form. Perhaps you left out a required field."), 'horde.error');
  83  }
  84  
  85  /* Render the configuration form. */
  86  require_once 'Horde/UI/VarRenderer.php';
  87  $renderer = &new Horde_Form_Renderer();
  88  $renderer->setAttrColumnWidth('50%');
  89  $form = Util::bufferOutput(array($form, 'renderActive'), $renderer, $vars, 'config.php', 'post');
  90  
  91  
  92  /* Set up the template. */
  93  require_once 'Horde/Template.php';
  94  $template = &new Horde_Template();
  95  $template->set('php', htmlspecialchars($php), true);
  96  /* Create the link for the diff popup only if stored in session. */
  97  if (!empty($_SESSION['_config'][$app])) {
  98      Horde::addScriptFile('popup.js', 'horde', true);
  99      $url = Horde::applicationUrl('admin/setup/diff.php');
 100      $url = Util::addParameter($url, 'app', $app);
 101      $link = Horde::link('#', '', '', '', 'popup(\'' . $url . '\', 640, 480); return false;') . _("show differences") . '</a>';
 102      $template->set('diff_popup', $link);
 103  }
 104  $template->set('form', $form);
 105  $template->set('notify', Util::bufferOutput(array($notification, 'notify')));
 106  $template->setOption('gettext', true);
 107  
 108  require  HORDE_TEMPLATES . '/common-header.inc';
 109  require  HORDE_TEMPLATES . '/admin/common-header.inc';
 110  echo $template->fetch(HORDE_TEMPLATES . '/admin/setup/config.html');
 111  require  HORDE_TEMPLATES . '/common-footer.inc';


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