<?php

session_start(); 
	$brmid = $_SESSION['linkarisebranchid'];
	$cmpmid = $_SESSION['linkarisecmpmid'];
	$umid = $_SESSION['linkariseumid'];

	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	
	include("connect.php");
	include("removespecial.php");
	
	date_default_timezone_set("Asia/Kolkata");
	$mdate1= date('Y-m-d H:i:s');
	$mdate2= date('d-m-Y');
	
	$par1 = $_SESSION['linkariseumobile'];
	$ipaddress = "";

	if (getenv('HTTP_CLIENT_IP'))
		$ipaddress = getenv('HTTP_CLIENT_IP');
	else if(getenv('HTTP_X_FORWARDED_FOR'))
		$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
	else if(getenv('HTTP_X_FORWARDED'))
		$ipaddress = getenv('HTTP_X_FORWARDED');
	else if(getenv('HTTP_FORWARDED_FOR'))
		$ipaddress = getenv('HTTP_FORWARDED_FOR');
	else if(getenv('HTTP_FORWARDED'))
		$ipaddress = getenv('HTTP_FORWARDED');
	else if(getenv('REMOTE_ADDR'))
		$ipaddress = getenv('REMOTE_ADDR');
	else
		$ipaddress = 'UNKNOWN';
	
	$userserver=$_SERVER['HTTP_USER_AGENT'];
	$eve1 = "insert into res_user_log (lid,mobile,lastupdatedtime,pagename,taskname,ipaddress,useragentdetail) values(NULL,'$par1','$mdate1','Item','Edit Item','$ipaddress','$userserver')";
	$re1 = mysqli_query($conn, $eve1);

	$itemid=$_POST['itemid'];
	$itemcode=$_POST['itemcode'];
	$itemcategory=removespecialchar($_POST['itemcategory']);
	$itemname=removespecialchar($_POST['itemname']);
	$itemdescription=removespecialchar($_POST['itemdescription']);
	$itemhsncode=$_POST['itemhsncode'];
	$itemtaxper=$_POST['itemtaxper'];
	$iunitmasterstock=$_POST['iunitmasterstock'];
		$itemunit=$_POST['itemunit'];
		$itemminstock=$_POST['itemminstock'];
	$itemsalesrate=$_POST['itemsalesrate'];
	$itempurchaserate=$_POST['itempurchaserate'];
	
	 $eve = "update res_item_master set itemcode='$itemcode', itemcategory='$itemcategory', itemname='$itemname', itemdescription='$itemdescription', itemhsncode='$itemhsncode', itemtaxper=$itemtaxper,itemunit='$itemunit',itemminstock='$itemminstock',itemsalesrate='$itemsalesrate',itempurchaserate='$itempurchaserate' where itemid=$itemid";
	
	
	if ($conn->query($eve) === TRUE)
	{
			
		$_SESSION['msg'] = "Record has been updated successfully";	
	}
	else
	{
		$_SESSION['msg1'] = "Error";
	}
	header('Location: item.php');
?>