<?php
 	session_start(); 

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}



$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	
	include("connect.php");
include("mylibrary.php");
	$usermid = $_SESSION['umid'];
date_default_timezone_set("Asia/Kolkata");
	$mdate1= date('Y-m-d H:i:s');
	
	
	//$visatype=$_POST['visatype'];
	 $collegeapplicationmid=$_POST['collegeapplicationmid'];
	$camcondition=checkvalidstring($_POST['camcondition']);
	$camprocessdetail=checkvalidstring($_POST['camprocessdetail']);
	$camdocumentname=checkvalidstring($_POST['camdocumentname']);
	$collegemid=$_POST['collegemid'];
	$camstartdate=date("Y-m-d",strtotime($_POST['camstartdate']));
	$camdeadline=date("Y-m-d",strtotime($_POST['camdeadline']));
	
	$camdocumnet = "";
	if(empty($_FILES['camdocumnet']['name']) == false  )
	{
		$camdocumnet1 =checkvalidstring($_FILES['camdocumnet']['name']);
		$camdocumnet = date("YmdHis").$camdocumnet1;
		$path = "docs/";
		move_uploaded_file( $_FILES['camdocumnet']['tmp_name'], $path ."/". $camdocumnet );
	
	}
	
	 $eve1 = "INSERT INTO res_collegeappmanagement_detail (collegeapplicationmid,camcondition,camprocessdetail,camdocumentname,collegemid,camstartdate,camdeadline,camdocumnet) VALUES('$collegeapplicationmid','$camcondition','$camprocessdetail','$camdocumentname','$collegemid','$camstartdate','$camdeadline','$camdocumnet')";
	
	if ($conn->query($eve1) === TRUE)

	{	
	$last_id = $conn->insert_id;
	$delete_checkbox_array = $_POST['cdstep'];
		$n=0;
			foreach ($delete_checkbox_array as $one_by_one_sid) 
			{
				$cdstep = checkvalidstring($one_by_one_sid);
				if($cdstep != '')
				{
					
					$cdsdocument1 = "";
	if(empty($_FILES['cdsdocument1']['name'][$n]) == false  )
	{
		$cdsdocument1 = date("YmdHis").$_FILES['cdsdocument1']['name'][$n];
		$path = "docs/";
		move_uploaded_file( $_FILES['cdsdocument1']['tmp_name'][$n], $path ."/". $cdsdocument1 );
	
	}
				$n = $n + 1;
				 $eve2="insert into res_collegedefferalsteps_detail (collegemid,camdid,cdstep,cdsaddedby,cdsaddedon,cdsdocument1) values('$collegemid',$last_id,'$cdstep','$usermid','$mdate1','$cdsdocument1')";
				
					$re2 = mysqli_query($conn, $eve2);
				}
			}
	}else{
		
	}
			
	$_SESSION['msg'] = "Record saved successfully";
	header('Location: collegedetail.php?id='.$collegemid);
			
	
?>