Location: PHPKode > scripts > Encaps Gallery > encaps-2.3.22s/core/config.class.php
<?php 
class Config
{
	function Config($filename,$htpf=array())
	{
		include($filename);
		$this->filename = $filename;
		$this->error = 0;
		$this->postget= $_POST?$_POST:$_GET;
		$this->html = array();
		$this->html['config'] = @$config;
		$this->htpf = $htpf;
	}
	
	function config_update()
	{
		if(@$this->html['config']["demo"] == "1")
			return;

		if (!is_writable($this->filename))
		{
			Misc::_show_message_color('Warning: '.$this->filename.' is not writable. Please change permissions or update file manually.','YELLOW');
			return;
		}
		//$this->html['config'] = array();
		if(isset($this->postget["db_host"]))$this->html['config']["db_host"] = trim($this->postget["db_host"]);
		if(isset($this->postget["db_user"]))$this->html['config']["db_user"] = trim($this->postget["db_user"]);
		if(isset($this->postget["db_pass"]))$this->html['config']["db_pass"] = trim($this->postget["db_pass"]);
		if(isset($this->postget["db_name"]))$this->html['config']["db_name"] = trim($this->postget["db_name"]);
		if(isset($this->postget["db_prefix"]))$this->html['config']["db_prefix"] = trim($this->postget["db_prefix"]);
		if(isset($this->postget["admin_uname"]))$this->html['config']["admin_uname"] = trim($this->postget["admin_uname"]);
		if(isset($this->postget["admin_passwd"]))$this->html['config']["admin_passwd"] = trim($this->postget["admin_passwd"]);
		if(isset($this->postget["admin_email"]))$this->html['config']["admin_email"] = trim($this->postget["admin_email"]);
		if(isset($this->postget["file_size"]))$this->html['config']["file_size"] = (int)($this->postget["file_size"]);
		if(isset($this->postget["file_thumb_size"]))$this->html['config']["file_thumb_size"] = (int)($this->postget["file_thumb_size"]);
		if(isset($this->postget["file_thumb_type"]))$this->html['config']["file_thumb_type"] = ($this->postget["file_thumb_type"]);
		$this->html['config']["shopcart_is_enabled"] = (isset($this->postget["shopcart_is_enabled"]))?"1":"";
		if(isset($this->postget["shopcart_type"]))$this->html['config']["shopcart_type"] = trim($this->postget["shopcart_type"]);
		$this->html['config']["shopcart_paypal_sandbox"] = (isset($this->postget["shopcart_paypal_sandbox"]))?"1":"";

		if(isset($this->postget["pagination"]))$this->html['config']["pagination"] = (int)($this->postget["pagination"]);
		if(isset($this->postget["url_root"]))$this->html['config']["url_root"] = trim($this->postget["url_root"]);

		$this->html['config']["watermark_is_enabled"] = (isset($this->postget["watermark_is_enabled"]))?"1":"";
		if(isset($this->postget["watermark_type"]))$this->html['config']["watermark_type"] = trim($this->postget["watermark_type"]);
		if(isset($this->postget["watermark_text"]))$this->html['config']["watermark_text"] = trim($this->postget["watermark_text"]);
		if(isset($this->postget["watermark_location"]))$this->html['config']["watermark_location"] = trim($this->postget["watermark_location"]);
		if(isset($this->postget["watermark_margin"]))$this->html['config']["watermark_margin"] = (int)($this->postget["watermark_margin"]);
		if( isset($this->htpf['watermark_image']["name"]) && $this->htpf['watermark_image']["name"] )
		{	
			$file = Misc::file_upload("../rwx/",$this->htpf['watermark_image']);
			if($file && $this->html['config']["watermark_image"] != $file)
			{
				Misc::file_unlink("../rwx/",$this->html['config']["watermark_image"]);
				$this->html['config']["watermark_image"] = $file;
			}
		}
		$fp = fopen($this->filename,"w");
		if(!$fp)
		{
			Misc::_show_message_color("Failed to write ../config.ini.php","RED");
			return;
		}
		fputs($fp,"<?php ");	
		foreach ($this->html['config'] as $key=>$value)
		{
			$line = "\n".'$config["'.$key.'"] = "'.$value.'";';
			fputs($fp,$line);	
		}
		fputs($fp,"\n?>");	
		fclose($fp);

		Misc::_show_message_color('The file '.$this->filename.' is updated',"GREEN");
	}
	
	function show_setup()
	{
		$html = $this->html;
		if(strtoupper(@$html["config"]["demo"]) == '1')
		{
			foreach($html["config"] as $key=>$value)
				$item[$key] = "demo";
//			$html["config"] = $item;
//			$html["action"] = "demo";
		}else
			$html["action"] = "config_update";		
	}

}
?>
Return current item: Encaps Gallery