<?php
	ob_start();
	session_start();

	

	//Included Files

	include("../class/dbConnection.php");
    include("../class/admin.php");

	

	//Declaring Variables

	$adminId;

	$name;

	$gender;

	$dateOfBirth;

	$email;

	$mobile;

	$dbName;

	

	//Retrieving Session Variable

	if(isset($_SESSION["adminId"]))

	{

		$adminId = $_SESSION["adminId"];

		//echo $adminId;

	}

	else

	{

		header('Location:index.php?message=Unauthorised%20Access%20Prohibited');

	}

	

	//Retrieving Form Fields

	$name = $_REQUEST["texName1"];

	$gender = $_REQUEST["radGender1"];

	$email = $_REQUEST["texEmail1"];

	$mobile = $_REQUEST["texMobile1"];

	//echo $name . "<br/>" . $gender . "<br/>" . $dateOfBirth . "<br/>" . $email . "<br/>" . $alternateEmail . "<br/>" . $mobile;

	

	//Creating 'dbConnection' Object

	$dbObj = new dbConnection();

	$con = $dbObj->getConnection();

	//echo $con . "<br/>";

	

	if($con)

	{

		//echo "MySQL Server Connected<br/>";

		$dbResult = $dbObj->selectDatabase();

		if($dbResult)

		{

			//Creating 'admin' Object

			$adminObj = new admin();

			$recordSet = $adminObj->getAdminDetails($adminId,$con);

			

			while($row = mysql_fetch_array($recordSet))

			{				

				$dbName = $row["name"];

			}

			//echo $dbName;

			if($dbName == "")

			{

				$insertResult = $adminObj->insertAdminDetails($adminId,$name,$gender,$email,$mobile,$con);

				if($insertResult)

				{

					header('Location:EditProfile.php?success=Updated%20Successfully');

				}

				else

				{

					header('Location:EditProfile.php?failure=Unable%20To%20InsertProfile');

				}

			}

			else

			{

				$updateResult = $adminObj->setAdminDetails($adminId,$name,$gender,$email,$mobile,$con);

				if($updateResult)

				{

					header('Location:EditProfile.php?success=Profile%20Updated%20Successfully');

				}

				else

				{

					header('Location:EditProfile.php?failure=Unable%20To%20Update');

				}

			}

		}

		else

		{

			echo mysql_errno() . " : " . mysql_error();

		}

	}

	else

	{

		echo mysql_errno() . " : " . mysql_error();

	}

	

?>