<%@language = "javascript" %>
<% /*
     $Revision$
     $Id$


     File:         prs_edit_inzetbaar_save.asp
     Description:  SUBMIT-form
     Parameters:

     Context:
     Note:
*/
var JSON_Result = true;
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/json2.js" -->
<!-- #include file="../shared/save2db.inc" -->

<%
var prs_inzetbaar_key = getFParamInt("prs_inzetbaar_key");
var prs_perslid_key = getFParamInt("prs_key");
var isNew = prs_inzetbaar_key < 0;

var autfunction = "WEB_PRSMAN";
var authparams = user.checkAutorisation(autfunction);
user.auth_required_or_abort(authparams.PRSwritelevel < 9 && authparams.ALGwritelevel < 9);

var inzetbaar_van = getFParamDate("inzetbaar_van");
var hours = inzetbaar_van.getHours()
var minutes = inzetbaar_van.getMinutes();
inzetbaar_van = (hours * 60) + minutes;

var inzetbaar_tot = getFParamDate("inzetbaar_tot");
hours = inzetbaar_tot.getHours()
minutes = inzetbaar_tot.getMinutes();
inzetbaar_tot = (hours * 60) + minutes;


var fields = [{ dbs: "prs_perslid_key",           typ: "key",    val: prs_perslid_key },
              { dbs: "prs_perslid_inzetbaar_van", typ: "float",  val: inzetbaar_van },
              { dbs: "prs_perslid_inzetbaar_tot", typ: "float",  val: inzetbaar_tot },
              { dbs: "prs_perslid_inzetbaar_dag", typ: "number", frm: "prsinzetbaardag" }];


result = {success: true, isnew: isNew};
if (prs_inzetbaar_key > 0)
{
  sql = buildUpdate("prs_perslid_inzetbaar", fields)
      + "     prs_perslid_inzetbaar_key = " + prs_inzetbaar_key;

  var err= Oracle.Execute(sql, true);
  if (err.friendlyMsg)
     result.message = err.friendlyMsg;
}
else
{
  fields.push({dbs: "prs_perslid_inzetbaar_key", typ: "key", seq: "prs_s_prs_perslid_inzet_key"});
  var regIns = buildInsert("prs_perslid_inzetbaar", fields);
  prs_inzetbaar_key = regIns.sequences["prs_perslid_inzetbaar_key"];

  sql = regIns.sql;
  var err = Oracle.Execute(sql, true);
  if (err.friendlyMsg)
      result.message = err.friendlyMsg
}

Response.Write(JSON.stringify(result));
%>
