<?php
	ob_start(); 
	session_start();	

	//Included Files

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

	//Retrieving Form Fields
	$cur_date =  date('Y-m-d');
	if(isset($_REQUEST["admin_id"]))
	{
		$admin_id = $_REQUEST["admin_id"];
	}
	if(isset($_REQUEST["date"]))
	{
		$date = date_create($_REQUEST["date"]);
		echo $date = date_format($date,"Y-m-d H:i:s");
	}
	
	//Creating 'dbConnection' Object

	$dbObject = new dbConnection();

	$con = $dbObject->getConnection();

	//echo $con;

	if($con)
	{
		//MySQL Connection Established

		$dbResult = $dbObject->selectDatabase();

		if($dbResult)
		{
			//Creating 'doctor' Object

			$adminObj = new admin();
				
			if($_FILES["file"]["type"] != "")  
			{

				$temporary1 = explode(".", $_FILES["file"]["name"]); 				

				$file_extension1 = end($temporary1); 					

				$sourcePath1 = $_FILES['file']['tmp_name'];   // Storing source path of the file in a variable

				$uImage1 = "../uploadfile/STOCK POSITION AS ON ".$date.".".$file_extension1;  // Target path where file is to be stored
				//  Moving Uploaded file
				move_uploaded_file($sourcePath1,$uImage1);
				
			}

			$insertResult = $adminObj->insertFileDetails($admin_id,$uImage1,$date,$con);
			if($insertResult)
			{
				header('Location:add_file.php?success=File%20has%20been%20Inserted%20Successfully');
			}
			else
			{
				header('Location:home.php?failure=Unable%20To%20Insert');
			} 		

		}
		else
		{
			echo mysql_errno() . "<br/>" . mysql_error();
		}		 

	}
	else
	{
		echo mysql_errno() . "<br/>" . mysql_error();
	}

?>