<?php

/*  Alternate WebKit
(C) 2011 by Alternate Tools
-----------------------------------------------------

File:         class_configuration.php
Description:  Class cConfiguration definition,
              handling of the multipurpose web
              parameters

*/

include "class_storagefile.php";

if (!defined("CLASS_CONFIGURATION"))
{
    define ("CLASS_CONFIGURATION", "DEFINED");

    class cConfiguration extends cStorageFile
    {
        var $m_ConfigurationFile;
        var $m_DataArray;

        function cConfig()  // PHP 4
        {
            $this->InitConfig();
        }
        function __construct()
        {
            $this->InitConfig();
        }

        function InitConfig()
        {
            $this->m_ConfigurationFile = "";
            unset($this->m_DataArray);
            $this->m_DataArray = array();
            $this->InitStorageFile();
        }

        // Getter and setter
        function SetConfigurationFile($configFile)
        {
            $this->m_ConfigurationFile = $configFile;
        }
        
        function SetParameter($parameter, $value)
        {
            $this->m_DataArray[$parameter] = $value;
        }
        
        function GetParameter($parameter, $defaultValue = "")
        {
            if (isset($this->m_DataArray[$parameter]) == true)
                return $this->m_DataArray[$parameter];

            return $defaultValue;
        }

        function DeleteParameter($parameter)
        {
            if (isset($this->m_DataArray[$parameter]) == true)
                unset($this->m_DataArray[$parameter]);
        }

        // Main methods
        function LoadConfigFile()
        {
            //echo  $this->m_ConfigurationFile;

            if (file_exists($this->m_ConfigurationFile) == false)
                return false;

            if ($this->LoadStorageFromFile($this->m_ConfigurationFile) == false)
                return false;

            $this->m_DataArray = $this->m_strgData;
            return true;
        }
        
        function SaveConfigFile()
        {
            $newRow = "\r\n";
            // echo $this->m_ConfigurationFile;

            if ($this->m_ConfigurationFile == "")
                return false;

            $this->SetType("configuration_file");

            foreach ($this->m_DataArray as $key => $value)
            {
                $this->AddData($key, $value);
            }

            return $this->SaveStorageToFile($this->m_ConfigurationFile);
        }

    }
}