<?php
require_once "../magic/session_config.php";
bdr_start_session();
// ob_start();
if(!isset($_SESSION["user_id"])){header("location:../logout.php");}
include_once('../op/database.php');

  $branch = $_SESSION["branch"];
  $father = $_SESSION["user_id"];
  $database = new Database();
  $db = $database->getConnection();

if(isset($_POST["car_info"])){
    $contract_id   = $_POST['contract_id'];
    $carid         = $_POST['carid'];
    $car_info      = $_POST['car_info'];
    $date_out      = $_POST['date_out'];
    $mydate = date("Y-m-d");
  
    $Number ="/^[0-9]+$/";
    $data = array(); $error = array();
  
    if(empty($contract_id)||empty($carid)){  $error["media"] = "من فضلك تأكد من رقم العقد و السيارة  "; }
    if(!empty($error)){
      $data["error"] = $error ;
    }else {
      ($date_out == $mydate )?$outback = 1: $outback = 2;
  $contt=$db->prepare(" INSERT INTO media(contract_id,carid,car_info,father,branch,outback)
                    VALUES(?,?,?,?,?,?) ");
   $contt->bindParam(1,$contract_id);
   $contt->bindParam(2,$carid);
   $contt->bindParam(3,$car_info);
   $contt->bindParam(4,$father);
   $contt->bindParam(5,$branch);
   $contt->bindParam(6,$outback);
   if($contt->execute()){
  $data["msg"]= "<div class='alert alert-success'>
                <a href='#' class='close' data-dismiss='alert' aria-label='close'style='float:left;'>&times;</a>
                <b>تم عمل طلب تصوير بنجاح .....</b>
                </div>" ;
  }
  else{ $data["msg"] = "<div class='alert alert-danger'>
                <a href='#' class='close' data-dismiss='alert' aria-label='close'style='float:left;'>&times;</a>
                <b>يوجد خطأ في تسجيل البيانات ... راجع  من فضلك</b>
                </div> " ; }
  }
  echo json_encode($data);
  }
?>