<?php
$func=$_GET['id'];
if($func=='contact'){
	contact();
}elseif($func=='homereg'){
	homereg();
}elseif($func=='s31image'){
	s31image();
}elseif($func=='s32image'){
	s32image();
}elseif($func=='s33image'){
	s33image();
}elseif($func=='section3'){
	section3();
}elseif($func=='s1image'){
	s1image();
}elseif($func=='section1'){
	section1();
}elseif($func=='header'){
	header_design();
}elseif($func=='footer'){
	footer();
}elseif($func=='headerimage'){
	headerimage();
}
function headerimage(){
	require_once("config.php");
	$allowedExts = array("gif", "jpeg", "jpg", "png");
	$temp = explode(".", $_FILES["file"]["name"]);
	$extension = end($temp);
	if((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 2000000) && in_array($extension, $allowedExts)){
	$cast=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM ui_design WHERE id='1' LIMIT 1"));
	$image='../asset/images/'.$cast['header_image'];
	unlink($image);
	$newfilename = round(microtime(true)) . '.' . end($temp);
	move_uploaded_file($_FILES["file"]["tmp_name"], "../asset/images/" . $newfilename);
	mysqli_query($dbc, "UPDATE ui_design SET header_image='$newfilename' WHERE id='1'");
	}echo "<script>window.location.href='".$url."/admin/section3';</script>";
}
function footer(){
	require_once("config.php");	
	$ft_extratext=mysqli_real_escape_string($dbc, trim($_POST['ft_extratext']));
	mysqli_query($dbc,"UPDATE ui_design SET footer_extratext='$ft_extratext' WHERE id ='1'");
	echo "<script>window.location.href='".$url."/admin/uifooter';</script>";
}
function header_design(){
	require_once("config.php");	
	$header_title=mysqli_real_escape_string($dbc, trim($_POST['header_title']));	
	$header_body=mysqli_real_escape_string($dbc, trim($_POST['header_body']));		
	mysqli_query($dbc,"UPDATE ui_design SET header_title='$header_title',header_body='$header_body' WHERE id ='1'");
	echo "<script>window.location.href='".$url."/admin/section3';</script>";
}
function section1(){
  require_once("config.php");
  $s1_bg=mysqli_real_escape_string($dbc, trim($_POST['s1_bg']));    
  $s1_title=mysqli_real_escape_string($dbc, trim($_POST['s1_title']));       
  $s1_body=mysqli_real_escape_string($dbc, trim($_POST['s1_body']));       

  mysqli_query($dbc,"UPDATE ui_design SET s1_title='$s1_title',s1_body='$s1_body' WHERE id ='1'");
  echo "<script>window.location.href='".$url."/admin/section3';</script>";
}
function s1image(){
	require_once("config.php");
	$allowedExts = array("gif", "jpeg", "jpg", "png");
	$temp = explode(".", $_FILES["file"]["name"]);
	$extension = end($temp);
	if((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 2000000) && in_array($extension, $allowedExts)){
	$cast=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM ui_design WHERE id='1' LIMIT 1"));
	$image='../asset/images/'.$cast['s1_image'];
	unlink($image);
	$newfilename = round(microtime(true)) . '.' . end($temp);
	move_uploaded_file($_FILES["file"]["tmp_name"], "../asset/images/" . $newfilename);
	mysqli_query($dbc, "UPDATE ui_design SET s1_image='$newfilename' WHERE id='1'");
	}echo "<script>window.location.href='".$url."/admin/section3';</script>";
}
function s31image(){
	require_once("config.php");
	$allowedExts = array("gif", "jpeg", "jpg", "png");
	$temp = explode(".", $_FILES["file"]["name"]);
	$extension = end($temp);
	if((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 2000000) && in_array($extension, $allowedExts)){
	$cast=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM ui_design WHERE id='1' LIMIT 1"));
	$image='../asset/images/'.$cast['s3_1image'];
	unlink($image);
	$newfilename = round(microtime(true)) . '.' . end($temp);
	move_uploaded_file($_FILES["file"]["tmp_name"], "../asset/images/" . $newfilename);
	mysqli_query($dbc, "UPDATE ui_design SET s3_1image='$newfilename' WHERE id='1'");
	}echo "<script>window.location.href='".$url."/admin/section3';</script>";
}function s32image(){
	require_once("config.php");
	$allowedExts = array("gif", "jpeg", "jpg", "png");
	$temp = explode(".", $_FILES["file"]["name"]);
	$extension = end($temp);
	if((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 2000000) && in_array($extension, $allowedExts)){
	$cast=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM ui_design WHERE id='1' LIMIT 1"));
	$image='../asset/images/'.$cast['s3_2image'];
	unlink($image);
	$newfilename = round(microtime(true)) . '.' . end($temp);
	move_uploaded_file($_FILES["file"]["tmp_name"], "../asset/images/" . $newfilename);
	mysqli_query($dbc, "UPDATE ui_design SET s3_2image='$newfilename' WHERE id='1'");
	}echo "<script>window.location.href='".$url."/admin/section3';</script>";
}function s33image(){
	require_once("config.php");
	$allowedExts = array("gif", "jpeg", "jpg", "png");
	$temp = explode(".", $_FILES["file"]["name"]);
	$extension = end($temp);
	if((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 2000000) && in_array($extension, $allowedExts)){
	$cast=mysqli_fetch_array(mysqli_query($dbc, "SELECT * FROM ui_design WHERE id='1' LIMIT 1"));
	$image='../asset/images/'.$cast['s3_3image'];
	unlink($image);
	$newfilename = round(microtime(true)) . '.' . end($temp);
	move_uploaded_file($_FILES["file"]["tmp_name"], "../asset/images/" . $newfilename);
	mysqli_query($dbc, "UPDATE ui_design SET s3_3image='$newfilename' WHERE id='1'");
	}echo "<script>window.location.href='".$url."/admin/section3';</script>";
}
function section3(){
	require_once("config.php");
	$s3_title=mysqli_real_escape_string($dbc, trim($_POST['s3_title']));		
	$s3_body=mysqli_real_escape_string($dbc, trim($_POST['s3_body']));	
	$s3_bodyc=mysqli_real_escape_string($dbc, trim($_POST['s3_bodyc']));		
	$s3_1title=mysqli_real_escape_string($dbc, trim($_POST['s3_1title']));	
	$s3_1body=mysqli_real_escape_string($dbc, trim($_POST['s3_1body']));	
	$s3_2title=mysqli_real_escape_string($dbc, trim($_POST['s3_2title']));	
	$s3_2body=mysqli_real_escape_string($dbc, trim($_POST['s3_2body']));	
	$s3_3title=mysqli_real_escape_string($dbc, trim($_POST['s3_3title']));	
	$s3_3body=mysqli_real_escape_string($dbc, trim($_POST['s3_3body']));	
	mysqli_query($dbc,"UPDATE ui_design SET s3_title='$s3_title',s3_body='$s3_body',s3_bodyc='$s3_bodyc',s3_1title='$s3_1title',s3_1body='$s3_1body',s3_2title='$s3_2title',s3_2body='$s3_2body',s3_3title='$s3_3title',s3_3body='$s3_3body' WHERE id ='1'");
	echo "<script>window.location.href='".$url."/admin/section3';</script>";
}
function contact(){
	session_start();
	require_once("config.php");
	$name=mysqli_real_escape_string($dbc, trim($_POST['name']));
	$mobile=mysqli_real_escape_string($dbc, trim($_POST['phone']));
	$description=mysqli_real_escape_string($dbc, trim($_POST['comment']));
	$email=mysqli_real_escape_string($dbc, trim($_POST['email']));
	$security_code=mysqli_real_escape_string($dbc, trim($_POST['security_code']));
	$verification_code=mysqli_real_escape_string($dbc, trim($_POST['verification_code']));	
	if($security_code!=$verification_code){
		$_SESSION['contact']='security';
		redirect($url."/#contact");
	}else{
		mysqli_query($dbc,"INSERT INTO contact VALUES('0','$name','$mobile','$email','$description','$datetime')");
		$_SESSION['contact']='message';
		redirect($url."/#contact");
	}
}

function homereg(){
	session_start();
	require_once("config.php");
	$email=mysqli_real_escape_string($dbc, trim($_POST['email']));	
	$_SESSION['offshore_regmail']=$email;	
	echo "<script>window.location.href='".$url."/register';</script>";
}