<?php
###################################################################
##                           WARNING!                            ##
##                                                               ##
##         THIS SCRIPT IS COPYRIGHTED TO EASYBUILDR.COM          ##
##      DUPLICATING, SELLING OR TRANSFERRING OF THIS SCRIPT      ##
##    IS A VIOLATION OF THE COPYRIGHT AND PURCHASE AGREEMENT     ##
##          PLEASE READ THE TERMS AND CONDITIONS HERE:           ##
##            https://easybuildr.com/members/terms/              ##
## ANY VIOLATION OF THESE TERMS WILL BE DEALT WITH LEGAL ACTION! ##
###################################################################

error_reporting(E_ERROR);
ini_set('display_errors',1);
session_save_path('./sessions');
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'])
	{
		global $reauth;
		$reauth = 1;
		$_SESSION['logged_in']=true;
		$_SESSION['sec']=1;
		require_once  "./includes/init.php";
		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 = "Website 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\nWebsite 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.";
	}

// Download Page Settings
if($_REQUEST['do_type']=="download_settings_write"  && $_SESSION['sec']=="1")
{
	$filename="settings/download_settings.txt";

	$content =$_REQUEST['download'];
	$content  =stripslashes($_REQUEST['download']);
	$content .="#_1_#";
	$content .=$_REQUEST['d-location'] ;
	$content .="#_1_#";
	$content .=$_REQUEST['display_ads'] ;
	$content .="#_1_#";
	$content .=$_REQUEST['cbid'] ;


	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:download_page_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

// Affiliate Page Settings
if($_REQUEST['do_type']=="jv_settings_write"  && $_SESSION['sec']=="1")
{
	$filename="settings/jv_settings.txt";

	$content =$_REQUEST['jv'];
	$content  =stripslashes($_REQUEST['jv']);
	$content .="#_1_#";
	$content .=$_REQUEST['jv-location'] ;


	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:jv_page_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

//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";
	}
}
// Sales Page Settings

if($_REQUEST['do_type']=="sales_settings_write"  && $_SESSION['sec']=="1")
{

	$filename="settings/sales_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("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:sales_page_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

//Optin Settings
if($_REQUEST['do_type']=="optin_settings_write" && $_SESSION['sec']=="1")
{
	$filename="settings/optin_settings.txt";

	$content  =stripslashes($_REQUEST['text']);
	$content .="#_1_#";
	$content .=$_REQUEST['meta_web'];
	$content .="#_1_#";
	$content .=$_REQUEST['unit'];
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['redirect']);
	$content .="#_1_#";
	$content .=$_REQUEST['to_display_form'];
	$content .="#_1_#";
	$content .=stripslashes($_REQUEST['form']);
	$content .="#_1_#";
	$content .=$_REQUEST['to_display_alternate'];
	$content .="#_1_#";
	$content .=$_REQUEST['grlist'];
	$content .="#_1_#";
	$content .=$_REQUEST['grref'];
	$content .="#_1_#";
	$content .=$_REQUEST['autoresponder'];
	$content .="#_1_#";
	$content .=$_REQUEST['name-place'];
	$content .="#_1_#";
	$content .=$_REQUEST['email-place'];
	$content .="#_1_#";
	$content .=$_REQUEST['button-text'];
	$content .="#_1_#";
	$content .= preg_replace("/[^a-z0-9]/", "", trim( strtolower( strip_tags( $_REQUEST['o-location'] ) ) ) );
	$content .="#_1_#";
	$content .=$_REQUEST['optimage'];
	$content .="#_1_#";
	$content .=$_REQUEST['formtop'];
	$content .="#_1_#";
	$content .=$_REQUEST['formbot'];

	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:optin_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

// Privacy Terms Settings

if($_REQUEST['do_type']=="privacy_terms_settings_write"  && $_SESSION['sec']=="1")
{

	$filename="settings/privacy_terms_settings.txt";

	$content =$_REQUEST['privacy'];
	$content .="#_1_#";
	$content .=$_REQUEST['terms'];
	$content .="#_1_#";
	$content .=$_REQUEST['display_privacy_terms'];


	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:privacy_terms_settings.php?flag=1");
		exit;
	} else
	{
		echo "The file $filename is not writable";
	}
}

//SEO Website Settings

  if($_REQUEST[do_type]=="seo_settings_write")
    {
		$filename="settings/seo_settings.txt";
		
        $content .=stripslashes($_REQUEST[website_page_title]) ;
		$content .="#_1_#";
		$content .=stripslashes($_REQUEST[website_description]) ;
		$content .="#_1_#";
        $content .=stripslashes($_REQUEST[website_keywords]) ;
		$content .="#_1_#";
        $content .=stripslashes($_REQUEST[track]) ;

		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:seo_settings.php?flag=1");
			exit;				
		  } else
		  {
			echo "The file $filename is not writable";
		  }
	}
	
?>