<?php
 	session_start(); 

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





$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));

	

	

	include("connect.php");



	
	$companymid=$_POST['companymid'];
	$companyname=$_POST['companyname'];
	$cmcontactno=$_POST['cmcontactno'];
	$cmemail=$_POST['cmemail'];
	$cmaddress=$_POST['cmaddress'];
	$companymastercode=$_POST['companymastercode'];	
	$companyfaxnumber=$_POST['companyfaxnumber'];
	$companywebsite=$_POST['companywebsite'];
	$companynote=$_POST['companynote'];
	
	
	
	$tt="";
	/* 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['companyicon']['name']) == false  )
		 {
			 // Get Image Dimension
			$fileinfo = @getimagesize($_FILES['companyicon']['tmp_name']);
			$width = $fileinfo[0];
			$height = $fileinfo[1];
		
			$simplephoto11=$_FILES['companyicon']['name'];
			$ext = pathinfo($simplephoto11, PATHINFO_EXTENSION);
			$fileexplode1 = explode(".",$simplephoto11);
			$fileend1 = end($fileexplode1);

			$companyicon1= date("YmdHis").rand(100,999).".".$fileend1;
			$path = "images";
			if($ext=='png' || $ext=='jpg' || $ext=='jpeg' || $ext=='gif')
			{
			  move_uploaded_file( $_FILES['companyicon']['tmp_name'], $path ."/". $companyicon1);
			  $tt2 = ",companyicon='$companyicon1'";
			}
			else {
				$_SESSION['msg1'] = "Only Upload Image";
				header("Location: company.php");
				return;
			}
			/* if ($width > "1920" || $height > "556") {
        
				$_SESSION['msg1']= "Image dimension should be within 1920X556";
				header("Location: banner.php");
				return;
				//$flag=0;
			} */
		 }
	
	if(empty($_FILES['companylogo']['name']) == false  )
		 {
			 // Get Image Dimension
			$fileinfo = @getimagesize($_FILES['companylogo']['tmp_name']);
			$width = $fileinfo[0];
			$height = $fileinfo[1];
		
			$simplephoto11=$_FILES['companylogo']['name'];
			$ext = pathinfo($simplephoto11, PATHINFO_EXTENSION);
			$fileexplode1 = explode(".",$simplephoto11);
			$fileend1 = end($fileexplode1);

			$companylogo1= date("YmdHis").rand(100,999).".".$fileend1;
			$path = "images";
			if($ext=='png' || $ext=='jpg' || $ext=='jpeg' || $ext=='gif')
			{
			  move_uploaded_file( $_FILES['companylogo']['tmp_name'], $path ."/". $companylogo1);
			  $tt1 = ",companylogo='$companylogo1'";
			}
			else {
				$_SESSION['msg1'] = "Only Upload Image";
				header("Location: company.php");
				return;
			}
			/* if ($width > "1920" || $height > "556") {
        
				$_SESSION['msg1']= "Image dimension should be within 1920X556";
				header("Location: banner.php");
				return;
				//$flag=0;
			} */
		 }
		 if(empty($_FILES['companybanner']['name']) == false  )
		 {
			 // Get Image Dimension
			$fileinfo = @getimagesize($_FILES['companybanner']['tmp_name']);
			$width = $fileinfo[0];
			$height = $fileinfo[1];
		
			$simplephoto11=$_FILES['companybanner']['name'];
			$ext = pathinfo($simplephoto11, PATHINFO_EXTENSION);
			$fileexplode1 = explode(".",$simplephoto11);
			$fileend1 = end($fileexplode1);

			$companybanner1= date("YmdHis").rand(100,999).".".$fileend1;
			$path = "images";
			if($ext=='png' || $ext=='jpg' || $ext=='jpeg' || $ext=='gif')
			{
			  move_uploaded_file( $_FILES['companybanner']['tmp_name'], $path ."/". $companybanner1);
			  $tt3 = ",companybanner='$companybanner1'";
			}
			else {
				$_SESSION['msg1'] = "Only Upload Image";
				header("Location: company.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_company_master set companyname='$companyname',cmcontactno='$cmcontactno',cmemail='$cmemail',cmaddress='$cmaddress',companymastercode='$companymastercode',companyfaxnumber='$companyfaxnumber',companywebsite='$companywebsite',companynote='$companynote' $tt1 $tt2 $tt3 where companymid='$companymid'";

	

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

	{		

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

		header('Location: company.php');		

	} 

	else 

	{

			

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

		header('Location: company.php');

	}

?>