<?php 
ob_start();
session_start();
require_once("../conn/conn.php");
//echo $_SESSION['sess_name_user'];
@include('../utility/chksession.php');
date_default_timezone_set("Asia/Bangkok");

$pj_hid = $_POST['pj_hid'];
$pj_hname = $_POST['pj_hname'];
$pj_hsaleorder = $_POST['pj_hsaleorder'];
$pj_hpo = $_POST['pj_hpo'];
$pjg_id = $_POST['pjg_id'];

echo $pj_hid;
echo $pj_hname;
echo $pj_hsaleorder;
echo $pj_hpo;
echo $pjg_id;

    $sql = "INSERT INTO `pj_haedproject` (`pj_hid`, `pj_hname`, `pj_hsaleorder`, `pj_hpo`, `pjg_id`, `pj_hstatus`, `pj_hcreatetime`) 
    VALUES ('$pj_hid', '$pj_hname', '$pj_hsaleorder', '$pj_hpo', '$pjg_id', 'P', NOW());";
    $query = mysqli_query($con,$sql);
        if($query){
        echo "ok";
        
        $strSQL = "SELECT * FROM pj_grouptitle,pj_title 
        where pj_grouptitle.pjt_id=pj_title.pjt_id 
        and pj_grouptitle.pjg_id='$pjg_id'";
        $objQuery = mysqli_query($con,$strSQL);
        while($objResult = mysqli_fetch_array($objQuery)){
        echo $objResult['pjt_id'].$objResult['pjt_name'];?></br><?
    
        $sql = "INSERT INTO `pj_subproject` (`pj_subid`, `pj_hid`, `pjt_id`, `pj_plandate`, `pj_startdate`, `pj_enddate`, `pj_namerecord`, `pj_daterecode`) 
        VALUES ('', '$pj_hid', '$objResult[pjt_id]', '0000-00-00', '0000-00-00', '0000-00-00','', '')";
    	$query = mysqli_query($con,$sql);
            if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../admin/data.php';
                    //-->
                </script>
            <?php
            }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

            }
        }
        
        
    }else{
        
        
        echo "not";
    }



?>