<?php

class Config {

	static private $config=null;
 	
 	public static function initValues(){
 	 
		self::$config = (object) array();
		self::$config->chmod_file = 0{CHMODFILE};
		self::$config->chmod_dir = 0{CHMODDIR};
				
		// server
		self::$config->server_path = "{SERVER_PATH}";
			
		// private
		self::$config->private_path = "{PRIVATE_PATH}";
		self::$config->private_system_path = self::$config->private_path."/system";
		self::$config->private_installations_path = self::$config->private_path."/applications_installations";
		self::$config->private_users_path = self::$config->private_path."/users";
		
		// private/system
	 	self::$config->private_system_logs_path = self::$config->private_system_path."/logs";
	 	self::$config->private_system_logs_index_path = self::$config->private_system_logs_path."/___index";
	 	self::$config->private_system_tmp_path = self::$config->private_system_path."/tmp";
	 	self::$config->private_system_fonts_path = self::$config->private_system_path."/fonts";
	 	self::$config->private_system_privilegies_path = self::$config->private_system_path."/privilegies";
		self::$config->private_system_sessions_path = self::$config->private_system_path."/sessions";
	 	self::$config->private_system_config_path = self::$config->private_system_path."/config";
	 	self::$config->private_system_accounts_path = self::$config->private_system_path."/accounts";
	 	self::$config->private_system_accountsGroups_path = self::$config->private_system_path."/accountsGroups";
	 	self::$config->private_system_indexes_path = self::$config->private_system_path."/indexes";
	 	
	 	// public
	 	self::$config->public_path = "{PUBLIC_PATH}";
	
		// http
		self::$config->fwindowsURL = "{HTTP_PATH}";
		self::$config->httpPublicURL = "{HTTP_PUBLIC_PATH}";
		
		// upgrades info
		self::$config->upgradesInfo = (object) array();
		self::$config->upgradesInfo->localUpgradesPath = self::$config->private_installations_path;
		self::$config->upgradesInfo->remoteUpgradesURL = "http://download.fwindows.awssoft.com/dl.php";

		
		// crypt password
		self::$config->md5_password = false;
		
		// ove pomeriti u system configuration
		self::$config->logger=true;
		self::$config->logger_index_max_filesize=1024*1024;
		//
		self::$config->file_date = "Y_m_d";
		self::$config->file_time = "H_i_s";
		self::$config->file_datetime = "Y_m_d_H_i_s";
		
		// serialize system config
		self::updateSystemConfiguration();
	
	}
	
	public static function get($varName, $onObject=null){
	 
	 	if(self::$config==null) self::initValues();
	 
		if($onObject==null && isset(self::$config->$varName)){
			return self::$config->$varName;
		}
		
		if($onObject!=null && isset(self::$config->$onObject) && isset(self::$config->$onObject->$varName)){
			return self::$config->$onObject->$varName;
		}
		
		return null;
		
	}
	
	public static function updateSystemConfiguration(){
		$sysConfigFilepath = self::$config->private_system_config_path."/system/systemConfig.txt";
		$jsonData = Util::readFile($sysConfigFilepath); 			// read
		self::$config->system =  DataSerializer::deserialize($jsonData); 	// desearilize
	}

}
?>