<?php 
session_start();
include("dbConfig.php");

$def_id = $_POST["def_id"];
$company_id = $_POST["company_id"];
$company_idd = $_POST["company_idd"];
$lang = $_POST["lang"];
$definition = $_POST["definition"];
date_default_timezone_set("Asia/Riyadh");
$created_date = date("Y-m-d");
$creatime = date("H:i:s");


$sql = "INSERT INTO def_tb(id,def_name,type,company_id,createdDate,creatime)
VALUES ('$def_id','$definition','hr','$company_id','$created_date','$creatime')";

$rows1 = $_POST['hidden'];
$count = 0;              
foreach ($rows1 as $key => $value) {
  
        $account_number = $_POST["account_number$value"];
        $request = $_POST["request$value"];
        $operate = $_POST["operate$value"];

        $query = "INSERT INTO sub_def_tb(account_number,request,operator,def_id) VALUES('$account_number','$request','$operate','$def_id')" ;
        $run = $conn->query($query) or die("Error in saving image".$conn->error);
        $count++;
      
  }
  
if ($conn->query($sql) === TRUE && $count>0) {
  $_SESSION['message'] = "تمت الإضـــافه بنجاح";
    header('location:hr_Add_Difinition_Report.php?'.$lang.'&company_id='.$company_idd);
  } else {
    echo "Error: " . $sql . "<br>" . $conn->error;
  }
?>