<?php
ob_start();
session_start();
require_once("../conn/conn.php");
//include('../utility/chksession.php');
date_default_timezone_set("Asia/Bangkok");


$id_posub=$_POST['id_posub'];
$job_pdid=$_POST['job_pdid'];
$id_dep = $_SESSION['id_dep'];
$job_round=$_POST['job_round'];
$job_step=$_POST['job_step'];

//echo $id_posub;
 //echo $id_dep;

if($job_pdid == "" ){
    ?>
        <script language="JavaScript" type="text/javascript">
			<!--
			alert("กรุณากรอกข้อมูลให้ครบถ้วน !!! ");
			location.href='../admin/add_jobid.php';
			//-->
		</script>
    <?php 
}else{
    
    
    $strSQL1 = "SELECT * FROM pd_ver where id_posub='$id_posub' and id_dep='$id_dep'";
	$objQuery1 = mysqli_query($con,$strSQL1); 
	$objResult1 = mysqli_fetch_array($objQuery1);
    echo $objResult1['job_round'];
									   
	 if($objResult1['job_round']==''){
	     
	     echo "ไม่มี";
	     
	      $sql = "INSERT INTO `pd_jobver` (`ver_id`, `id_posub`, `id_dep`, `job_round`,`job_pdid`,`job_step`) VALUES ('NULL', '$id_posub', '$id_dep','$job_round','$job_pdid','$job_step')";
	$query = mysqli_query($con,$sql);
	
	$sql1 = "INSERT INTO `pd_ver` (`ver_id`, `job_round`, `id_posub`, `id_dep`) VALUES ('NULL', '$job_round', '$id_posub','$id_dep')";
	$query1 = mysqli_query($con,$sql1);
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../user/user_job.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con);
	     
	 }else{
	     
	     $sql = "INSERT INTO `pd_jobver` (`ver_id`, `id_posub`, `id_dep`, `job_round`,`job_pdid`,`job_step`) VALUES ('NULL', '$id_posub', '$id_dep','$job_round','$job_pdid','$job_step')";
	$query = mysqli_query($con,$sql);
	
	$sql1 = "UPDATE `pd_ver` SET `job_round` = '$job_round' WHERE id_posub='$id_posub' and id_dep='$id_dep'";
	
	
	$query1 = mysqli_query($con,$sql1);
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../user/user_job.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con); 
	     
	     
	 }
	 
	 
	 
    
    exit;
   
}




?>