<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "currid") 
    $sl_id = $paramValue;  
  else if ($paramName == "id") 
    $ba_id = $paramValue;  
  else if ($paramName == "refno") 
    $refno = $paramValue;  
  else if ($paramName == "descr") 
    $descr = $paramValue;  
}

$dal = new DAL();

if ($sl_id == 0) {

  $ba_id = hexdec(uniqid());

  $sql = "INSERT INTO bag " .
         "(id, refno, descr) " .
         "VALUES ($ba_id, $refno, $descr) "; 
  $result = $dal->query($sql);
}

else { 
 
  $sql = "UPDATE bag SET " .
         "refno=$refno, descr=$descr " .
         "WHERE ba_id = $ba_id " ;
  $result = $dal->query($sql);
}
    
echo json_encode($result);

?>

