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

     File:         prs_edit_contactpersoon_save.asp
     Description:  SUBMIT-form
*/ %>
<%
var JSON_Result = true;
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../shared/save2db.inc" -->
<!-- #include file="../Shared/kenmerk_common.inc"-->
<!--  #include file="../Shared/json2.js" -->

<%
var autfunction = 'WEB_RELUSE';
var authparams = user.checkAutorisation(autfunction);
user.auth_required_or_abort(authparams && authparams.ALGwritelevel < 9);

  var cps_key = getQParamInt( "cps_key", -1 );

  var isNew = (cps_key<0);

  var fields =  [ { dbs: "prs_bedrijf_key",                 typ: "key",      frm: "prs_bdrkey" },
                  { dbs: "prs_contactpersoon_aanhef",       typ: "varchar",  frm: "prs_aanh" },
                  { dbs: "prs_contactpersoon_voorletters",  typ: "varchar",  frm: "prs_voorl" },
                  { dbs: "prs_contactpersoon_naam",         typ: "varchar",  frm: "prs_naam" },
                  { dbs: "prs_contactpersoon_voornaam",     typ: "varchar",  frm: "prs_vrnaam" },
                  { dbs: "prs_contactpersoon_tussenv",      typ: "varchar",  frm: "prs_tsnvgs" },
                  { dbs: "prs_contactpersoon_functie",      typ: "varchar",  frm: "prs_func" },
                  { dbs: "prs_contactpersoon_titel",        typ: "varchar",  frm: "prs_titel" },
                  { dbs: "prs_contactpersoon_telefoon_1",   typ: "varchar",  frm: "prs_tel1" },
                  { dbs: "prs_contactpersoon_telefoon_2",   typ: "varchar",  frm: "prs_tel2" },
                  { dbs: "prs_contactpersoon_fax",          typ: "varchar",  frm: "prs_fax" },
                  { dbs: "prs_contactpersoon_email",        typ: "varchar",  frm: "prs_email" },
                  { dbs: "prs_contactpersoon_opmerking",    typ: "varchar",  frm: "prs_opm" },
                  { dbs: "prs_perslid_key",                 typ: "key",      frm: "prs_prskey" },
                  { dbs: "prs_contactpersoon_uurloon",      typ: "float",    frm: "prs_loon" }];

var warning = "";
if (cps_key > 0)
  {
    sql = buildUpdate("prs_contactpersoon", fields)
        + "     prs_contactpersoon_key = " + cps_key;

    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
else
  {
    fields.push({  dbs: "prs_contactpersoon_key",         typ: "key",      seq: "prs_s_prs_contactpersoon_key" });
    var regIns = buildInsert("prs_contactpersoon", fields);
    var cps_key = regIns.sequences["prs_contactpersoon_key"];
    sql = regIns.sql;
    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
    if (!warning)
    {
       currentKenmerkenSQL = "SELECT kl.prs_kenmerk_key " +
                                "  , kl.prs_kenmerklink_waarde" +
                                "  FROM PRS_KENMERKLINK kl, PRS_KENMERK k " +
                                " WHERE  k.PRS_KENMERK_KEY = kl.PRS_KENMERK_KEY " +
                                "   AND PRS_KENMERKLINK_VERWIJDER IS NULL " +
                                "   AND PRS_LINK_KEY = " + cps_key;

       saveFlexKenmerken(cps_key, { kenmerkTable: "PRS_KENMERKLINK",
                                    kenmerkParentKey : "PRS_LINK_KEY",
                                    kenmerkWaarde: "prs_kenmerklink_waarde",
                                    kenmerkKey: "PRS_KENMERK_KEY",
                                    currentKenmerkenSQL: currentKenmerkenSQL,
                                    requestQF: Request.Form,
                                    moduleName: "PRS_KENMERKLINK_NIVEAU",
                                    moduleVal: "C",
                                    isNew: isNew,
                                    flexPath: "PRS/C"
                              });

    }

var result = {success: true,
              cps_key: cps_key,
              warning: warning,
              keepForm: (warning?true:false),
              refresh: true
             };
Response.Write(JSON.stringify(result));
%>
