<?php
// array for JSON response
$response = array();


//check for required fields
if (isset($_POST['Item2GroupID']) && isset($_POST['Item1TypeID']) && isset($_POST['Item2GroupName']) && isset($_POST['ClientID']) && isset($_POST['ClientUserID']) && isset($_POST['NetCode'])
    && isset($_POST['SysCode']) ) {

		$Item2GroupID = $_POST['Item2GroupID'];
		$Item1TypeID = $_POST['Item1TypeID'];
  		$Item2GroupName = $_POST['Item2GroupName'];
  		$ClientID = $_POST['ClientID'];
  		$ClientUserID = $_POST['ClientUserID'];
  		$NetCode = $_POST['NetCode'];
  		$SysCode = $_POST['SysCode'];
		
		 // include db connect class
      require_once __DIR__ . '/../DBConnect.php';

			    $UpdatedDate = date("Y-m-d H:i:s");

          $sql = "UPDATE Item2Group SET Item1TypeID = $Item1TypeID, Item2GroupName = '$Item2GroupName', ClientUserID = '$ClientUserID', NetCode = '$NetCode', SysCode = '$SysCode', UpdatedDate = '$UpdatedDate' WHERE Item2GroupID = $Item2GroupID AND ClientID=".$ClientID;
          
		  
		  try{	
			$stmt = $conn->prepare($sql);
			$result=$stmt->execute();
	
		}
		catch(PDOException $e){
			echo $sql . "<br>" . $e->getMessage();
		}
		if ( $result=== TRUE) {
				$rows_affected= "No information available.";
				$response["success"] = 1;
				$response["roweffected"] = $rows_affected;
				$response["UpdatedDate"] = $UpdatedDate;
				$response["message"] = "Update Successfully";
				// echoing JSON response
				echo json_encode($response);
		}else{
				$response["success"] = 0;
				$response["roweffected"] = $result;      
				$response["message"] = "Not updated row ".$result;
				// echoing JSON response
				echo json_encode($response);
		}     
    }else{
      // success
      $response["success"] = 0;
      $response["message"] = "No Update";
      // echoing JSON response
      echo json_encode($response);
    }
?>
