<?php
include('../../../dbconnection/dbconnection.php');

if(isset($_POST["btn_action"])){
	if($_POST["btn_action"]==="Add-Details"){
		$title=$_POST["title"];
		$mission=$_POST["mission"];
		$vision=$_POST["vision"];
		$about=$_POST["about"];
		$sql=$connect->prepare("SELECT * FROM school_details");
	  $sql->execute();
	 $count=COUNT($sql->fetchAll());
		if($count===0){
			
			$query = "
				INSERT INTO school_details (name, mission, vision, about) 
				VALUES (:title, :mission, :vision,:about)
				";
			}else{
			
			$query = "
				UPDATE school_details 
				SET name=:title, 
					mission=:mission, 
					vision=:vision,
					about=:about
				";
		
		}
			$statement=$connect->prepare($query);
			$statement->execute(
			array(
				":title"		=>	$title, 
				":mission" 		=>	$mission,
				":vision"		=>	$vision, 
				":about"		=>	$about
			));
			$result = $statement->fetchAll();
				if(isset($result))
				{
					echo 'Details Updated';
				}
		
	}	
	
	if($_POST["btn_action"]==="Add-Contacts"){
		$tel=$_POST["tel"];
		$whatsapp=$_POST["whatsapp"];
		$email=$_POST["email"];
		$fb=$_POST["fb"];
		$ig=$_POST["ig"];
		$twitter=$_POST["twitter"];
		$ln=$_POST["ln"];
		$youtube=$_POST["youtube"];
		$sql=$connect->prepare("SELECT * FROM school_details");
	  $sql->execute();
	 $count=COUNT($sql->fetchAll());
		if($count===0){
			
			$query = "
				INSERT INTO school_details ( email,tel, whatsapp, fb,ig,twitter,ln,youtube,) 
				VALUES (:email,:tel, :whatsapp, :fb,:ig,:twitter,:ln,:youtube)
				";
			}else{
			
			$query = "
				UPDATE school_details 
				SET email=:email, 
					tel=:tel,
					whatsapp=:whatsapp,
					fb=:fb,
					ig=:ig,
					twitter=:twitter,
					ln=:ln,
					youtube=:youtube
				";
		
		}
			$statement=$connect->prepare($query);
			$statement->execute(
			array(
			
				":email"		=>	$email,
				":tel"			=>	$tel, 
				":whatsapp" 	=>	$whatsapp, 
				":fb"			=>	$fb,
				":ig"			=>	$ig,
				":twitter"		=>	$twitter,
				":ln"			=>	$ln,
				":youtube"		=>	$youtube
			));
			$result = $statement->fetchAll();
				if(isset($result))
				{
					echo 'Contacts Updated';
				}
		
	}

}

?>