<?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");
	include("mylibrary.php");
	$contractaddedby=$_SESSION['umid'];
	//$umid=$_SESSION['umid'];
	$contactperson=checkvalidstring($_POST['contactperson']);
	$contactpersonid=checkvalidstring($_POST['contactpersonid']);
	$contractname=checkvalidstring($_POST['contractname']);
	$contractdescription=checkvalidstring($_POST['contractdescription']);
	$contactstartdate=date("Y-m-d", strtotime($_POST['contactstartdate']));
	$contactenddate=date("Y-m-d", strtotime($_POST['contactenddate']));
	$contractnote=checkvalidstring($_POST['contractnote']);
	$companyname=checkvalidstring($_POST['companyname']);
	
	
	//$rolemid=$_POST['rolemid'];
	//$dashboardurl=$_POST['dashboardurl'];
	//$udate1=implode('-', array_reverse(explode('-', $_POST['udate1'])));
	//$udate2=implode('-', array_reverse(explode('-', $_POST['udate2'])));
	$flag=1;
	{
		
	$contractdocument="";
	 if(empty($_FILES['contractdocument']['name']) == false  )
	 {
		 
		  // Get Image Dimension
		$fileinfo = @getimagesize($_FILES['contractdocument']['tmp_name']);
		$width = $fileinfo[0];
		$height = $fileinfo[1];
	
		$simplephoto11=$_FILES['contractdocument']['name'];
		 $ext = pathinfo($simplephoto11, PATHINFO_EXTENSION);
		
		$fileexplode1 = explode(".",$simplephoto11);
		$fileend1 = end($fileexplode1);

		$contractdocument= date("YmdHis").rand(100,999).".".$fileend1;
		$contractdocument=checkvalidstring($contractdocument);
		$path = "images";
		if($ext=='png' || $ext=='jpg' || $ext=='jpeg' || $ext=='gif' || $ext=='webp')
		{
		  move_uploaded_file( $_FILES['contractdocument']['tmp_name'], $path ."/". $contractdocument);
		  $flag=1;
		}
		else {
		  $_SESSION['msg1'] = "Only Upload Image";
			  $flag=0;
		}
		
	}
	
	}
		
		  $eve1 = "INSERT INTO res_contract_master (contactperson,contactpersonid,contractname,contractdescription,contactstartdate,contactenddate,contractnote,contractaddedon,contractaddedby,contractdocument,companyname) VALUES('$contactperson','$contactpersonid','$contractname','$contractdescription','$contactstartdate','$contactenddate','$contractnote','$mdate1','$contractaddedby','$contractdocument',$companyname)";
		
		
		$_SESSION['msg'] = "Record saved successfully";
		header('Location: contract.php');
	
?>