<?php 
    require_once('../Connections/conn_ama.php'); 
    include("../../../../../../functions/functions.php");    
	
    $curr_time = date("Y-m-d H:i:s");

    if (!isset($_SESSION)) {
    session_start();
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add-new-sub-department-detail")) {

        $insertSQL = sprintf("INSERT INTO deptsubdetails(deptID, subdeptname,deptfunctions) VALUES (%s, %s, %s)",
                        GetSQLValueString(trim($_POST['deptID']), "int"),
                        GetSQLValueString(trim($_POST['subdeptname']), "text"),
                        GetSQLValueString(trim($_POST['deptfunctions']), "text"));

        $Result1 = mysqli_query($conn_ama, $insertSQL) or die(mysqli_error($conn_ama));
            $supdeptID = mysqli_insert_id($conn_ama);
        
        if($Result1){
                $insertSQL1 = sprintf("INSERT INTO deptcontact(subdeptdetailsID,`location`, digitaladdress, `address`, phone, email) VALUES (%s, %s, %s, %s, %s, %s)",
                                GetSQLValueString(trim($supdeptID), "int"),
                                GetSQLValueString(trim($_POST['location']), "text"),
                                GetSQLValueString(trim($_POST['digitaladdress']), "text"),
                                GetSQLValueString(trim($_POST['address']), "text"),
                                GetSQLValueString(trim($_POST['phone']), "text"),
                                GetSQLValueString(trim($_POST['email']), "text"));

                $Result2 = mysqli_query($conn_ama, $insertSQL1) or die(mysqli_error($conn_ama));   
                if($Result2){
                   echo "datasent"; 
                }
                else{
                    echo "notset";
                }
        }
    }
?>