<?php
###################################################################
##                           WARNING!                            ##
##                                                               ##
##        THIS SCRIPT IS COPYRIGHTED TO STOREBUILDR.COM          ##
##      DUPLICATING, SELLING OR TRANSFERRING OF THIS SCRIPT      ##
##    IS A VIOLATION OF THE COPYRIGHT AND PURCHASE AGREEMENT     ##
##          PLEASE READ THE TERMS AND CONDITIONS HERE:           ##
##      HTTP://STOREBUILDR.COM/ADMIN-TERMS-AND-CONDITIONS        ##
## ANY VIOLATION OF THESE TERMS WILL BE DEALT WITH LEGAL ACTION! ##
##                                                               ##
###################################################################
error_reporting(0);
ini_set('display_errors','off');
session_start();
//Version 1.0


//Admin Login
if($_REQUEST[do_type]=="admin_settings_read")
{
	$filename="settings/admin_settings.txt";

	if(!$handle = fopen($filename, 'r'))
	{
		echo "Cannot open file ($filename)";
		exit;
	}
	$contents = fread($handle, filesize($filename));
	fclose($handle);
	$argument_arr=explode("#_1_#",$contents);

	if($argument_arr[0]==$_REQUEST[username] && $argument_arr[1]==$_REQUEST[pass])
	{
		$_SESSION[logged_in]=true;
			$_SESSION['sec']=1;
		header("location:welcome.php");
		exit;
	}
	else
	{
		$_SESSION['sec']=0;
		header("location:index.php?flag=1");
		exit;
	}
}

//Admin Forgot Password
if($_REQUEST[do_type]=="admin_settings_forgot")
{
	$filename="settings/admin_settings.txt";

	if(!$handle = fopen($filename, 'r'))
	{
		echo "Cannot open file ($filename)";
		exit;
	}
	$contents = fread($handle, filesize($filename));
	fclose($handle);
	$admin_arr=explode("#_1_#",$contents);
	
	
	

	if($admin_arr[3]==$_REQUEST[email])
	{
		$to = "$admin_arr[2] <$admin_arr[3]>";
		$subject = "Your Username and Password";
		$from = "Store Buildr Admin <nobody@localhost>";
		$message = "Hi $admin_arr[2],\n\nHere are your requested details:\n\nYour username: $admin_arr[0]\n\nYour password: $admin_arr[1]\n\n";
		$message .= "Regards,\n\nStore Buildr Admin.";
		mail($to,$subject, $message, "From: $from");
		header("location:forgot.php?flag=1");
		exit;
	}
	else
	{
		header("location:forgot.php?flag=2");
		exit;
	}
}

//Admin Login Settings
if($_REQUEST[do_type]=="admin_settings_write" && $_SESSION['sec']=="1")
{
	$filename="settings/admin_settings.txt";

	$content  =$_REQUEST[user_name];
	$content .="#_1_#";
	$content .=$_REQUEST[password] ;
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST[f_name]);
	$content .="#_1_#";
	$content .=$_REQUEST[email] ;

	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:admin_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}else if($_REQUEST[do_type]=="admin_settings_write" && $_SESSION['sec'] == "0"){
	echo "WARNING! Hacking Attempt - All abuse is reported.";
	}


//Personal Settings
if($_REQUEST[do_type]=="personal_settings_write" && $_SESSION['sec']=="1")
{
	$filename="settings/personal_settings.txt";

	$content  =stripslashes($_REQUEST[f_name]);
	$content .="#_1_#";
	$content .=$_REQUEST[email] ;


	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:personal_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}
// Home Page Settings
if($_REQUEST[do_type]=="home_settings_write"  && $_SESSION['sec']=="1")
{
	$filename="settings/home_settings.txt";

	$content =$_REQUEST[code];
	$content .="#_1_#";
	$content .=$_REQUEST[bg_color];
	$content .="#_1_#";
	$content .=$_REQUEST[border_color];
	$content .="#_1_#";
	$content .=$_REQUEST[border_width];
	$content .="#_1_#";
	$content .=$_REQUEST[footer];
	$content .="#_1_#";
	$content .=$_REQUEST[footer_bg_color];
	$content .="#_1_#";
	$content .=$_REQUEST[content_above];
	$content .="#_1_#";
	$content .=$_REQUEST[content_below];


	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("settings/blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:home_page_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}
// Design Settings
if($_REQUEST[do_type]=="design_settings_write"  && $_SESSION['sec']=="1")
{
	$filename="settings/design_settings.txt";

	$content .=$mypic;
	$content .="#_1_#";
	$content .=$_REQUEST[display_header];
	$content .="#_1_#";
	$content .=$_REQUEST[page_width];
	$content .="#_1_#";
	$content .=$_REQUEST[bg_color];
	$content .="#_1_#";
	$content .=$_REQUEST[border_color];
	$content .="#_1_#";
	$content .=$_REQUEST[border_width];
	$content .="#_1_#";
	$content .=$_REQUEST[display_nav];
	$content .="#_1_#";
	$content .=$_REQUEST[nav_button];
	$content .="#_1_#";
	$content .=$_REQUEST[nav_button_hov];
	$content .="#_1_#";
	$content .=$_REQUEST[nav_button_font_color];
	$content .="#_1_#";
	$content .=$_REQUEST[nav_button_font_size];//10
	$content .="#_1_#";
	$content .=$_REQUEST[padding];
	$content .="#_1_#";
	$content .=$_REQUEST[nav_button_round];
	$content .="#_1_#";
	$content .=$_REQUEST[nav_background_color];
	$content .="#_1_#";
	$content .=$_REQUEST[nav_padding];
	$content .="#_1_#";
	$content .=$_REQUEST[content_padding];


	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("settings/blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:design_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}
// Sidebar Settings
if($_REQUEST[do_type]=="sidebar_settings_write"  && $_SESSION['sec']=="1")
{
	$filename="settings/sidebar_settings.txt";

	$content =$_REQUEST[sidebar];
	$content .="#_1_#";
	$content .=$_REQUEST[rightside_width];
	$content .="#_1_#";
	$content .=$_REQUEST[rightside_bg_color];
	$content .="#_1_#";
	$content .=$_REQUEST[rightside_border_color];
	$content .="#_1_#";
	$content .=$_REQUEST[rightside_border_width];
	$content .="#_1_#";
	$content .=$_REQUEST[leftside_width];
	$content .="#_1_#";
	$content .=$_REQUEST[leftside_bg_color];
	$content .="#_1_#";
	$content .=$_REQUEST[leftside_border_color];
	$content .="#_1_#";
	$content .=$_REQUEST[leftside_border_width];
	$content .="#_1_#";
	$content .=$_REQUEST[leftcontent];
	$content .="#_1_#";
	$content .=$_REQUEST[rightcontent];


	if(file_exists($filename))
	{
		//Do nothing;
	}
	else
	{
		copy("settings/blank.txt",$filename);
		chmod($filename, 0750);
	}


	if(is_writable($filename))
	{
		if(!$handle = fopen($filename, 'w'))
		{
			echo "Cannot open file ($filename)";
			exit;
		}
		if(fwrite($handle, $content) === FALSE)
		{
			echo "Cannot write to file ($filename)";
			exit;
		}
		fclose($handle);
		header("location:sidebar_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}
?>