<?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'];
	//$umid=$_SESSION['umid'];
	$logistictype=$_POST['logistictype'];
	 $imid=$_POST['imid'];
	
	$lsenderdiscription=$_POST['lsenderdiscription'];
	 $lrecevirername=$_POST['lrecevirername'];
	 $logisticmid=$_POST['logisticmid'];
	$ldocumenttype=$_POST['ldocumenttype'];
	$lremarks=$_POST['lremarks'];
	$lindate=date("Y-m-d",strtotime($_POST['lindate']));
	
	
	$contactname=str_replace ("'","\'",$_POST['contactname']);
	$contactname=str_replace ('"','\"',$contactname);
	
	$cmiddlename=str_replace ("'","\'",$_POST['cmiddlename']);
	$cmiddlename=str_replace ('"','\"',$cmiddlename);
	
	$csurname=str_replace ("'","\'",$_POST['csurname']);
	$csurname=str_replace ('"','\"',$csurname);
	
		$contactnumber=str_replace ("'","\'",$_POST['contactnumber']);
	$contactnumber=str_replace ('"','\"',$contactnumber);
	$mobilecode=$_POST['mobilecode'];
	$contactnumber=$mobilecode."".$contactnumber;
	$cmobilenumber=str_replace ("'","\'",$_POST['cmobilenumber']);
	$cmobilenumber=str_replace ('"','\"',$cmobilenumber);
	$homemobilecode=$_POST['homemobilecode'];
	$cmobilenumber=$homemobilecode."".$cmobilenumber;
	$contactemail=str_replace ("'","\'",$_POST['contactemail']);
	$contactemail=str_replace ('"','\"',$contactemail);
	$caltenateemail=str_replace ("'","\'",$_POST['caltenateemail']);
	$caltenateemail=str_replace ('"','\"',$caltenateemail);
	$contactdepartmnet='Head';
	
	$cposition='Head';
	
	$cremarks=str_replace ("'","\'",$_POST['cremarks']);
	$cremarks=str_replace ('"','\"',$cremarks);
	
	$caddress1=str_replace ("'","\'",$_POST['caddress1']);
	$caddress1=str_replace ('"','\"',$caddress1);
	
	$caddress2=str_replace ("'","\'",$_POST['caddress2']);
	$caddress2=str_replace ('"','\"',$caddress2);
	
	$ccountry=str_replace ("'","\'",$_POST['ccountry']);
	$ccountry=str_replace ('"','\"',$ccountry);
	$cpostalcode=str_replace ("'","\'",$_POST['cpostalcode']);
	$cpostalcode=str_replace ('"','\"',$cpostalcode);
	
	$cmsgappname=str_replace ("'","\'",$_POST['cmsgappname']);
	$cmsgappname=str_replace ('"','\"',$cmsgappname);
	
	$ccompanyname=str_replace ("'","\'",$_POST['ccompanyname']);
	$ccompanyname=str_replace ('"','\"',$ccompanyname);
	
	$csubcategory='Direct';
	
	
	$cmsgappid=$_POST['cmsgappid'];
	
	
	$cvideoappname=str_replace ("'","\'",$_POST['cvideoappname']);
	$cvideoappname=str_replace ('"','\"',$cvideoappname);
	
	$cvideoappid=$_POST['cvideoappid'];
	
	
	
	
	$cstate=str_replace ("'","\'",$_POST['cstate']);
	$cstate=str_replace ('"','\"',$cstate);
	
	$ccity=$_POST['ccity'];
	
	
	$file="";
	 if(empty($_FILES['file']['name']) == false  )
	 {
		 
		  // Get Image Dimension
		$fileinfo = @getimagesize($_FILES['file']['tmp_name']);
		$width = $fileinfo[0];
		$height = $fileinfo[1];
	
		$simplephoto11=$_FILES['file']['name'];
		 $ext = pathinfo($simplephoto11, PATHINFO_EXTENSION);
		
		$fileexplode1 = explode(".",$simplephoto11);
		$fileend1 = end($fileexplode1);

		$file= date("YmdHis").rand(100,999).".".$fileend1;
		$path = "images";
		if($ext=='png' || $ext=='jpg' || $ext=='jpeg' || $ext=='gif' || $ext=='webp')
		{
		  move_uploaded_file( $_FILES['file']['tmp_name'], $path ."/". $file);
		  $flag=1;
		}
		else {
		  $_SESSION['msg1'] = "Only Upload Image";
			  $flag=0;
		}
		/* if ($width > "1920" || $height > "556") {
        
            $_SESSION['msg1']= "Image dimension should be within 1920X556";
			$flag=0;
        } */
	}
	
	
		   $eve2 = "INSERT INTO res_logisticin_master (logistictype,imid,lsenderdiscription,lrecevirername,logisticmid,ldocumenttype,lremarks,lindate,linaddedby,linaddedon,linupdatedby,linupdatedon,ldocument) VALUES('$logistictype','$imid','$lsenderdiscription','$lrecevirername','$logisticmid','$ldocumenttype','$lremarks','$lindate','$umid','$mdate1','$umid','$mdate1','$file')";
		
		
		if ($conn->query($eve2) === TRUE)

	{	
	
		$last_id = $conn->insert_id;
		 $eve1 = "INSERT INTO res_contact_master (contactname, contactemail,contactnumber,cmobilenumber,contactdepartmnet,cposition,cremarks,caltenateemail,caddress1,caddress2,ccountry,cstate,ccity,cpostalcode,cmiddlename,csurname,cmsgappname,cmsgappid,cvideoappname,cvideoappid,ccompanyname,csubcategory,clinktype,clinkid) VALUES('$contactname','$contactemail','$contactnumber','$cmobilenumber','$contactdepartmnet','$cposition','$cremarks','$caltenateemail','$caddress1','$caddress2','$ccountry','$cstate','$ccity','$cpostalcode','$cmiddlename','$csurname','$cmsgappname','$cmsgappid','$cvideoappname','$cvideoappid','$ccompanyname','$csubcategory','Logistic Sender','$last_id')";
		
		$re1 = mysqli_query($conn, $eve1);
			
		$_SESSION['msg'] = "Record Saved successfully";
	}else{
		$_SESSION['msg1'] = "Error";
	}
	header('Location: logisticin.php');
?>