<?PHP
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------------+
// | <G a n e s h a> - Free Web Based Training System                           |
// +----------------------------------------------------------------------------+
// | <G a n e s h a> - Plate-forme de téléformation gratuite et en open source  |
// +----------------------------------------------------------------------------|
// | Copyright (C) 2001-2003  Anéma Formation  <http://www.anema.fr/>           |
// +----------------------------------------------------------------------------+
// |           Developer : Georges CALDEIRA <gcaldeira@anemalab.org>            |
// +----------------------------------------------------------------------------+
// |              Infos on project <http://anemalab.org/>                       |
// +----------------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify       |
// | it under the terms of the GNU General Public License as published by       |
// | the Free Software Foundation; either version 2 of the License, or          |
// | (at your option) any later version.                                        |
// |                                                                            |
// | This program is distributed in the hope that it will be useful,            |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
// | GNU General Public License for more details.                               |
// |                                                                            |
// | You should have received a copy of the GNU General Public License          |
// | along with this program; if not, write to the Free Software                |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   |
// +----------------------------------------------------------------------------+

/**
* Definition de la class pour la gestion des options
* @author	Georges Caldeira <gcaldeira@anemalab.org>
* @package	GaneshaClass
*/
/**
* Fournit une API pour gerer les options.
* @author	Georges Caldeira <gcaldeira@anemalab.org>
* @access	public
* @package	GaneshaClass
*/
class Options {

	var $m_taboptions  = array();
	
	/**
	* Charge les options. Constructeur
	* @access	public
	*/
	function Options() { 
	 global $TBL, $db ;
		$sSQL = "SELECT name,value FROM ".$TBL['options'] ;
		$db->query($sSQL)	;
		while($db->next_record()) {
			define($db->f(0),$db->f(1));
			$this->m_taboptions[] = $db->f(0) ;
		}
		$sSQL = "SELECT name,value FROM ".$TBL['options2'] ;
		$db->query($sSQL)	;
		while($db->next_record()) {
			define($db->f(0),trim($db->f(1)));
		}
	}
				
	/**
	* maj des options
	* @access	public
	*/
	function update($taboptions) { 
	 	global $TBL, $db ;
		for($i=0;$i<count($this->m_taboptions);$i++) {
			if ( in_array($this->m_taboptions[$i],$taboptions)) {
				$sSQL = "UPDATE ".$TBL['options']." SET value='1'";
			} else {
				$sSQL = "UPDATE ".$TBL['options']." SET value='0'";
			}
			$sSQL.= " WHERE name='".$this->m_taboptions[$i]."' " ;
			$db->query($sSQL)	;			
	 	}
	}

	/**
	* maj des options
	* @access	public
	*/
	function update2($taboptions) { 
	 	global $TBL, $db ;
		$sSQL = "UPDATE ".$TBL['options2']." SET value='".trim($taboptions['text1'])."' WHERE name='DIR_GRP'";
		$db->query($sSQL)	;
		$sSQL = "UPDATE ".$TBL['options2']." SET value='".trim($taboptions['text2'])."' WHERE name='GRP_CODE'";
		$db->query($sSQL)	;
		$sSQL = "UPDATE ".$TBL['options2']." SET value='".trim($taboptions['text3'])."' WHERE name='MOD_CODE'";
		$db->query($sSQL)	;
		if ( isset($taboptions['check4']) ) {
			$sSQL = "UPDATE ".$TBL['options2']." SET value='1' WHERE name='TRACE'";
		}else{
			$sSQL = "UPDATE ".$TBL['options2']." SET value='0' WHERE name='TRACE'";
		}
		$db->query($sSQL)	;
		if ( isset($taboptions['check5']) ) {
			$sSQL = "UPDATE ".$TBL['options2']." SET value='1' WHERE name='DEBUG'";
		}else{
			$sSQL = "UPDATE ".$TBL['options2']." SET value='0' WHERE name='DEBUG'";
		}
		$db->query($sSQL)	;
		if ( isset($taboptions['check6']) ) {
			$sSQL = "UPDATE ".$TBL['options2']." SET value='1' WHERE name='DEBUG_AICC'";
		}else{
			$sSQL = "UPDATE ".$TBL['options2']." SET value='0' WHERE name='DEBUG_AICC'";
		}
		$db->query($sSQL)	;
		$sSQL = "UPDATE ".$TBL['options2']." SET value='".trim($taboptions['text7'])."' ";
		$sSQL.= "WHERE name='MAX_FILE_SIZE'";
		$db->query($sSQL)	;
		$sSQL = "UPDATE ".$TBL['options2']." SET value='".trim($taboptions['text8'])."' ";
		$sSQL.= "WHERE name='MAX_CAR_MSG_WM'";
		$db->query($sSQL)	;
		$timeout = (trim($taboptions['text9']<300)?300:$taboptions['text9']);
		$sSQL = "UPDATE ".$TBL['options2']." SET value='".$timeout."' ";
		$sSQL.= "WHERE name='TIME_OUT_CNX'";
		$db->query($sSQL)	;		
	}
		
} //fin class Options

/**
* Instance de la classe Options
* @var	object	Options
*/
$ClsOptions = new Options ;

?>