<?php
 	session_start(); 

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


date_default_timezone_set("Asia/Kolkata");
	$mdate1= date('Y-m-d H:i:s');
	$mdate2= date('Y-m-d');
	
	$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	
	include("connect.php");
	$umid=$_SESSION['umid'];

	
	//$tmdocument=$_POST['tmdocument'];
	
	
	$countrymid = $_POST['countrymid'];
	$visatmid = $_POST['visatmid'];
	$subservicemid = $_POST['subservicemid'];
	
	$tmdocument="";
	
	
	
		 $eve1 = "INSERT INTO res_immigration_master (countrymid,visatmid,subservicemid,imgaddedby,imgaddedon,imgupdatedby,imgupdatedon) VALUES('$countrymid','$visatmid','$subservicemid')";
		
			
			if($conn->query($eve1) === TRUE)
	{
			$last_id = $conn->insert_id;
		$total1 = count($_FILES['imgdocument']['name']);
		for( $i=0 ; $i < $total1 ; $i++ ) 
		{
			$imgdocumentname = $_POST['imgdocumentname'][$i];
			$imgname1 = $_FILES['imgdocument']['name'][$i];
			$fileexplode = explode(".",$imgname1);
			$fileend11 = end($fileexplode);
			$imgrnd=rand(100,999);
			$imgdocument = date("YmdHis").$imgrnd.".".$fileend11;
			$path = "docs";
			//	$filename111 = $filename11[1];
			
				move_uploaded_file( $_FILES['imgdocument']['tmp_name'][$i], $path ."/". $imgdocument );
				$eve2 = "INSERT INTO res_immigrationdocs_detail (imgmid,imgdocument,imgdocumentname) VALUES($last_id,'$imgdocument','$imgdocumentname')";
				$re2 = mysqli_query($conn, $eve2);
				
				$_SESSION['msg'] = "Record has been added successfully";
			
		} 
	}else{
		$_SESSION['msg1'] = "Error";
	}
		
		
		
	header('Location: immigration.php');
	
	
			
	
			
	
?>