<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "id") 
    $ab_id = $paramValue;  
  else if ($paramName == "currid") 
    $ba_id = $paramValue;  
  else if ($paramName == "affiliation_id") 
    $affiliation_id = $paramValue;  
  else if ($paramName == "material_id") 
    $material_id = $paramValue;  
  else if ($paramName == "form_id") 
    $form_id = $paramValue;  
  else if ($paramName == "completeness_id") 
    $completeness_id = $paramValue;  
  else if ($paramName == "diagnostics") 
    $diagnostics = $paramValue;  
  else if ($paramName == "collectcount") 
    $collectcount = $paramValue;  
  else if ($paramName == "samplerationale")  
    $samplerationale = $paramValue;  
  else if ($paramName == "note") 
    $note = $paramValue;  
}

$dal = new DAL();

if ($ab_id == 0) {

  $ab_id = hexdec(uniqid());

  $sql = "INSERT INTO artifactbatch " .
         "(id, bag_id, affiliation_id, material_id, form_id, completeness_id " .
         "diagnostics, collectcount, docucount, samplerationale, note) " .
         "VALUES ($ab_id, $ba_id, $affiliation_id, $material_id, $form_id, $completeness_id " .
         "$diagnostics, $collectcount, $docucount, $samplerationale, $note) "; 
  $result = $dal->query($sql);
}

else { 
 
  $sql = "UPDATE artifactbatch SET " .
         "id=$ab_id, affiliation_id=$affiliation_id, material_id=$material_id " .
         "form_id=$form_id, completeness_id=$completeness_id, ".
         "diagnostics=$diagnostics, collectcount=$collectcount, docucount=$docucount, " "samplerationale=$samplerationale, note=$note " .
         "WHERE id = $ab_id " ;
  $result = $dal->query($sql);
}
    
echo json_encode($result);

?>

