<?php
	class SystemParametersModel {
		public static function getVar( $key ) {
			$query = sprintf( "select system_parameter_value from system_parameters where system_parameter_name='%s'" , FNTH_db_addslashes( $key ) );
			return FNTH_db_get_field( $query , "system_parameter_value" );
		}
		
		public static function getVarType( $key ) {
			$query = sprintf( "select system_parameter_type from system_parameters where system_parameter_name='%s'" , FNTH_db_addslashes( $key ) );
			return FNTH_db_get_field( $query , "system_parameter_type" );
		}

		public static function setVar( $key , $value ) {
			$val = self::getVar( $key );
			$d = array();
			$d["system_parameter_value"]=sprintf( "'%s'" , FNTH_db_addslashes( $value ) );
			$q = ($val!==false) ?
				FNTH_db_generate_update_query( "system_parameters" , $d , sprintf( "system_parameter_name='%s'" , FNTH_db_addslashes( $key ) ) ) :
				FNTH_db_generate_insert_query( "system_parameters" , $d );
			FNTH_db_free_result( FNTH_db_query( $q ) );
		}

		public static function getVarDescription( $key ) {
			if (!is_array( $key ))
				return FNTH_db_get_field(
					sprintf( "select system_parameter_description from system_parameters where system_parameter_name='%s'" , FNTH_db_addslashes( $key ) ) , "system_parameter_description" );

			$temp = FNTH_db_get_associative(
				sprintf( "select 
					system_parameter_name,
					system_parameter_description
				from system_parameters where system_parameter_name in ('%s')",
					implode( "','" , array_map( "FNTH_db_addslashes" , $key ) ) ),
					"system_parameter_name",
					"system_parameter_description" );
			$retval = array();
			foreach ($key as $k) $retval[$k]=$temp[$k];
			return $retval;
		}

		public function getVarNames() {
			$query = sprintf( "select system_parameter_name from system_parameters" );
			return FNTH_db_get_column( $query , "system_parameter_name" );
		}

		public function getAllVars() {
			$query = sprintf( "select system_parameter_name,system_parameter_value from system_parameters" );
			return FNTH_db_get_associative( $query , "system_parameter_name" , "system_parameter_value" );

		}
	}
?>
