<?php 
require_once("header.php");
require_once("session_check.php");

//CODE FOR UPDATE SETTINGS
if(isset($_POST['save']))
{
	$sql_update = "UPDATE `pr_administrator` SET `admin_username` = '".addslashes($_POST['admin_username'])."',`contact_address` = '".addslashes($_POST['contact_address'])."',`contact_email` = '".$_POST['contact_email']."',`contact_no1` = '".$_POST['contact_no1']."',`contact_no2` = '".$_POST['contact_no2']."',`youtube_link` = '".addslashes($_POST['youtube_link'])."',`linkedin_link` = '".$_POST['linkedin_link']."',`twitter_link` = '".addslashes($_POST['twitter_link'])."',`instagram_link` = '".addslashes($_POST['instagram_link'])."' WHERE `admin_id` = '1'";
	$exe_update = mysqli_query($connection,$sql_update);
	
	$_SESSION['save_succ_msg'] = 'Site settings updated successfully.';
	header("location: site_settings.php");
	exit;
}

//FETCH DATA FROM DATABASE
$fetch_record = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `pr_administrator` WHERE `admin_id` = '1'"));
$admin_username = stripslashes($fetch_record['admin_username']);

$contact_address = stripslashes($fetch_record['contact_address']);
$contact_email = stripslashes($fetch_record['contact_email']);
$contact_no1 = stripslashes($fetch_record['contact_no1']);
$contact_no2 = stripslashes($fetch_record['contact_no2']);

$facebook_link = stripslashes($fetch_record['facebook_link']);
$twitter_link = stripslashes($fetch_record['twitter_link']);
$instagram_link = stripslashes($fetch_record['instagram_link']);
$linkedin_link = stripslashes($fetch_record['linkedin_link']);
$youtube_link = stripslashes($fetch_record['youtube_link']);
?>

<?php require_once("left_panel.php");?>
<div class="content">
	<div class="workplace">
		<?php if(isset($_SESSION['save_succ_msg'])) { ?>
		<div class="alert alert-success">                
		<b><?php echo $_SESSION['save_succ_msg'];?></b>
		</div> 
		<?php
		unset($_SESSION['save_succ_msg']);
		}
		?>
		<div class="row-fluid">
			<div class="span12">
				<form action="" method="post" enctype="multipart/form-data" onsubmit="return frm_validation();">
				<div class="head clearfix">
					<div class="isw-documents"></div>
					<h1>Site Settings</h1>
				</div>
				<div class="block-fluid">
					<div class="row-form clearfix">
						<div class="span3">Admin Username <font color="#FF0000">*</font></div>
						<div class="span9"><input type="text" name="admin_username" id="admin_username" value="<?php echo $admin_username;?>" /></div>
					</div> 
					<div class="row-form clearfix">
						<div class="span3">Contact Address <font color="#FF0000">*</font></div>
						<div class="span9"><textarea name="contact_address" id="contact_address"><?php echo $contact_address;?></textarea></div>
					</div>
					<div class="row-form clearfix">
						<div class="span3">Contact Email <font color="#FF0000">*</font></div>
						<div class="span9"><input type="text" name="contact_email" id="contact_email" value="<?php echo $contact_email;?>" /></div>
					</div>
					<div class="row-form clearfix">
						<div class="span3">Contact No. 1 <font color="#FF0000">*</font></div>
						<div class="span9"><input type="text" name="contact_no1" id="contact_no1" value="<?php echo $contact_no1;?>" /></div>
					</div>
					<div class="row-form clearfix">
						<div class="span3">Contact No. 2</div>
						<div class="span9"><input type="text" name="contact_no2" id="contact_no2" value="<?php echo $contact_no2;?>" /></div>
					</div>
					
				</div>
				<div>&nbsp;</div>
				<div class="head clearfix">
					<div class="isw-documents"></div>
					<h1>Social Media Settings</h1>
				</div>
				<div class="block-fluid">
					<div class="row-form clearfix">
						<div class="span3">Facebook Link</div>
						<div class="span9"><input type="text" name="facebook_link" id="facebook_link" value="<?php echo $facebook_link;?>" /></div>
					</div>
					<div class="row-form clearfix">
						<div class="span3">Twitter Link</div>
						<div class="span9"><input type="text" name="twitter_link" id="twitter_link" value="<?php echo $twitter_link;?>" /></div>
					</div>
					<div class="row-form clearfix">
						<div class="span3">Linkedin Link</div>
						<div class="span9"><input type="text" name="linkedin_link" id="linkedin_link" value="<?php echo $linkedin_link;?>" /></div>
					</div>
					<div class="row-form clearfix">
						<div class="span3">Instagram Link</div>
						<div class="span9"><input type="text" name="instagram_link" id="instagram_link" value="<?php echo $instagram_link;?>" /></div>
					</div>
					<div class="row-form clearfix">
						<div class="span3">Youtube Link</div>
						<div class="span9"><input type="text" name="youtube_link" id="youtube_link" value="<?php echo $youtube_link;?>" /></div>
					</div>
					<div class="row-form clearfix">
						<div class="span3">&nbsp;</div>
						<div class="span9"><button class="btn" type="submit" name="save">Save</button></div>
					</div>
				</div>
				</form>
			</div>
		</div>
	</div>
</div>   

<?php require_once("footer.php"); ?>