<?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");
	$contractmid=$_POST['contractmid'];
	$contractupdatedby=$_SESSION['umid'];
	$contactperson=checkvalidstring($_POST['contactperson']);
	$contactpersonid=$_POST['contactpersonid'];
	$contractname=checkvalidstring($_POST['contractname']);
	$Contractdescription=$_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'])));
	
	$tt1="";
	/* if(empty($_FILES['attechment']['name']) == false  )
	{
		$attechment = date("YmdHis").$_FILES['attechment']['name'];
		$path = "docs/";
		move_uploaded_file( $_FILES['attechment']['tmp_name'], $path ."/". $attechment );
	
		$tt = ",attechment='$attechment' ";
	} */
	
	 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);

			$companyicon1= date("YmdHis").rand(100,999).".".$fileend1;
			$companyicon1=checkvalidstring($companyicon1);
			$path = "images";
			if($ext=='png' || $ext=='jpg' || $ext=='jpeg' || $ext=='gif')
			{
			  move_uploaded_file( $_FILES['contractdocument']['tmp_name'], $path ."/". $companyicon1);
			  $tt1 = ",contractdocument='$companyicon1'";
			}
			else {
				$_SESSION['msg1'] = "Only Upload Image";
				header("Location: contract.php.php");
				return;
			}
			/* if ($width > "1920" || $height > "556") {
        
				$_SESSION['msg1']= "Image dimension should be within 1920X556";
				header("Location: banner.php");
				return;
				//$flag=0;
			} */
		 }
	
	$eve = "update res_contract_master set contactperson='$contactperson',contactpersonid='$contactpersonid',contractname='$contractname',Contractdescription='$Contractdescription',contactstartdate='$contactstartdate',contactenddate='$contactenddate',contractnote='$contractnote',contractupdatedby='$contractupdatedby',contractupdatedon='$mdate1',companyname='$companyname' $tt1  where contractmid ='$contractmid'";



	if ($conn->query($eve) === TRUE)

	{		

		$_SESSION['msg'] = "Contract Record Updated succesfully";

		header('Location: contract.php');		

	} 

	else 

	{

			

		$_SESSION['msg'] = "Error";

		header('Location: contract.php');

	}

?>