[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/include/ -> class.setup.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */
   3  // +----------------------------------------------------------------------+
   4  // | Eventum - Issue Tracking System                                      |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB                  |
   7  // |                                                                      |
   8  // | This program is free software; you can redistribute it and/or modify |
   9  // | it under the terms of the GNU General Public License as published by |
  10  // | the Free Software Foundation; either version 2 of the License, or    |
  11  // | (at your option) any later version.                                  |
  12  // |                                                                      |
  13  // | This program is distributed in the hope that it will be useful,      |
  14  // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  15  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  16  // | GNU General Public License for more details.                         |
  17  // |                                                                      |
  18  // | You should have received a copy of the GNU General Public License    |
  19  // | along with this program; if not, write to:                           |
  20  // |                                                                      |
  21  // | Free Software Foundation, Inc.                                       |
  22  // | 59 Temple Place - Suite 330                                          |
  23  // | Boston, MA 02111-1307, USA.                                          |
  24  // +----------------------------------------------------------------------+
  25  // | Authors: João Prado Maia <jpm@mysql.com>                             |
  26  // +----------------------------------------------------------------------+
  27  //
  28  //
  29  
  30  /**
  31   * Class to handle the business logic related to setting and updating
  32   * the setup information of the system.
  33   *
  34   * @version 1.0
  35   * @author João Prado Maia <jpm@mysql.com>
  36   */
  37  
  38  class Setup
  39  {
  40      /**
  41       * Method used to load the setup options for the application.
  42       *
  43       * @access  public
  44       * @param   boolean $force If the data should be forced to be loaded again.
  45       * @return  array The system-wide preferences
  46       */
  47      function load($force = false)
  48      {
  49          static $setup;
  50          if ((empty($setup)) || ($force == true)) {
  51              require(APP_SETUP_FILE);
  52              $setup = unserialize(base64_decode($eventum_setup_string));
  53          }
  54          return $setup;
  55      }
  56  
  57  
  58      /**
  59       * Method used to save the setup options for the application.
  60       *
  61       * @access  public
  62       * @param   array $options The system-wide preferences
  63       * @return  integer 1 if the update worked, -1 or -2 otherwise
  64       */
  65      function save($options)
  66      {
  67          // this is needed to check if the file can be created or not
  68          if (!file_exists(APP_SETUP_FILE)) {
  69              if (!@is_writable(APP_CONFIG_PATH)) {
  70                  clearstatcache();
  71                  return -1;
  72              }
  73          } else {
  74              if (!@is_writable(APP_SETUP_FILE)) {
  75                  clearstatcache();
  76                  return -2;
  77              }
  78          }
  79          $fp = @fopen(APP_SETUP_FILE, "w");
  80          if (!$fp) {
  81              return -2;
  82          }
  83          @flock($fp, LOCK_EX);
  84          @fwrite($fp, "<?php\n\$eventum_setup_string='" . base64_encode(serialize($options)) . "';\n?>");
  85          @flock($fp, LOCK_UN);
  86          @fclose($fp);
  87          return 1;
  88      }
  89  }
  90  
  91  // benchmarking the included file (aka setup time)
  92  if (APP_BENCHMARK) {
  93      $GLOBALS['bench']->setMarker('Included Setup Class');
  94  }


Generated: Wed Dec 19 21:21:33 2007 Cross-referenced by PHPXref 0.7