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

//check for required fields
if ( isset($_POST['ClientID']) ) {
		
		$CustomGroup2ID = $_POST['CustomGroup2ID'];
		$CustomGroup1ID = $_POST['CustomGroup1ID'];
		$AcNameID = $_POST['AcNameID'];
		$ClientID = $_POST['ClientID'];
  		$ClientUserID = $_POST['ClientUserID'];
  		$SysCode = $_POST['SysCode'];
		$NetCode = $_POST['NetCode'];
		$UpdatedDate = $_POST['UpdatedDate'];
		

      // include db connect class
      require_once __DIR__ . '/../DBConnect.php';
               $parm=array();
	           $query="select max(CustomGroup2ID) as maxid from Account5customGroup2 ";
			   
				try {
					$stmt = $conn->prepare($query);
					$stmt->execute();
					$users = $stmt->fetchAll();
					$CustomGroup2ID = 0;
					foreach ($users as $user) {
						$CustomGroup2ID = $user['maxid'] + 1;
					}
				}
				catch (PDOException $e) {
					echo $sql . "<br>" . $e->getMessage();
				}
	                  
			    $UpdatedDate = date("Y-m-d H:i:s");
          $sql = "INSERT INTO Account5customGroup2 (CustomGroup2ID, CustomGroup1ID, AcNameID, ClientID, ClientUserID, SysCode, NetCode, UpdatedDate ) VALUES('$CustomGroup2ID', '$CustomGroup1ID', '$AcNameID', '$ClientID', '$ClientUserID', '$SysCode', '$NetCode', '$UpdatedDate');";
      		
      		try {
			   $result= $conn->exec($sql);		   
					if( $result === false ) {
					/////////////not inserted
						$response["success"] = 0;  
						$response["message"] = "User Not Register";
					echo json_encode($response);
					}else{
						/////////////inserted
					$response["success"] = 1;
					$response["CustomGroup2ID"] = $CustomGroup2ID;
					$response["UpdatedDate"] = $UpdatedDate;
					$response["message"] = "User Register";
					echo json_encode($response);
					}
				}
			catch (PDOException $e) {
				echo $sql . "<br>" . $e->getMessage();
			}
		 
        }else{
      // success
      $response["success"] = 0;
      $response["message"] = "Send All Required Fields ";
      // echoing JSON response
      echo json_encode($response);
    }
?>
