<?php

class Load_settings {
	
	/**
	 * 
	 * Write settings constants in files
	 *
	 * @param array $settings
	 * @param array $files
	 * @return mixed 
	 */
	public function load($settings, $files) {
		
		//check if $setting is array 
		if(!is_array($settings) || count($settings) <= 0){
			return FALSE;
		}
		
		//check if $files is array
		if(!is_array($files) || count($files) <= 0){
			return FALSE;
		}
		

		$autoGeneratedText = '









						###############################################
						##                                           ##
						##            (!!)   WARNING   (!!)          ##
						##                                           ##
						##   THIS IS AN AUTOGENERATED FILE           ##
						##                                           ##
						##   DO NOT EDIT IT	                         ##
						##                                           ##
						###############################################





















		';

		$content = "<?php\n\n";
		$content .= "{$autoGeneratedText}\n\n";

		//
		foreach ($settings as $setting) {
			if($setting->type != 'separator') {
				
				if($setting->type == 'boolean') {
					if($setting->value == '1') {
						$content .= "define('". strtoupper($setting->name) ."', true);\n";
					} else {
						$content .= "define('". strtoupper($setting->name) ."', false);\n";
					}
				} else {
					$content .= "define('". strtoupper($setting->name) ."', '". $setting->value ."');\n";
				}
				
			}
		}
		
		foreach($files as $file){
			$handle = fopen($file, 'w+');
			fwrite($handle, $content);
			fclose($handle);
		}
		return TRUE;
		
		
	}
}
