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

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

      // include db connect class
      require_once __DIR__ . '/../DBConnect.php';
               $parm=array();
	           $query="select max(CustomGroup1ID) as maxid from Account5customGroup1 ";
			   
	         try {
				$stmt = $conn->prepare($query);
				$stmt->execute();
				$users = $stmt->fetchAll();
				$CustomGroup1ID = 0;
				foreach ($users as $user) {
					$CustomGroup1ID = $user['maxid'] + 1;
				}
			}
			catch (PDOException $e) {
				echo $sql . "<br>" . $e->getMessage();
			}
	                  
			    $UpdatedDate = date("Y-m-d H:i:s");
				$sql = "INSERT INTO Account5customGroup1 (CustomGroup1ID, CustomGroupName, ClientID, ClientUserID, SysCode, NetCode, UpdatedDate ) VALUES ('$CustomGroup1ID', '$CustomGroupName', '$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["CustomGroup1ID"] = $CustomGroup1ID;
					$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);
    }
?>
