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

     File:         fac_edit_menu_save.asp
     Description:  SUBMIT-form
*/ %>

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

<% FCLTHeader.Requires({ plugins:["jQuery"] }) %>
<%
var menu_key = getQParamInt("menu_key", -1);
var menuitem_key = getQParamInt("menuitem_key", -1);
var disckey = getFParamInt("disckey", -1);
var srtdisckey = getFParamInt("srtdisckey", -1);

var fields =  [ { dbs: "fac_menu_altlabel", typ: "varchar",  frm: "altlabel" },
                { dbs: "fac_menu_altgroep", typ: "key",  frm: "altgroep" },
                { dbs: "fac_menu_image", typ: "varchar",  frm: "image" },
                { dbs: "fac_menu_info", typ: "varchar",  frm: "menuinfo" },
                { dbs: "fac_menu_volgnr", typ: "number",  frm: "volgnr" },
                { dbs: "fac_menu_alturl", typ: "varchar",  frm: "alturl" },
                { dbs: "fac_functie_key", typ: "key",  frm: "altfunctie" },
                { dbs: "fac_menu_portal", typ: "check",  frm: "portal" },
                { dbs: "fac_menu_level", typ: "check",  frm: "level" }
              ];

if (menu_key == -1)
{
  if (menuitem_key != -1)
    fields.push({ dbs: "fac_menuitems_key", typ: "key", val: menuitem_key }); // via url
  else
    fields.push({ dbs: "fac_menuitems_key", typ: "key", frm: "fac_mikey" });
}

if (disckey > -1)
  fields.push({ dbs: "ins_discipline_key", typ: "key", val: disckey });
else
  fields.push({ dbs: "ins_discipline_key", typ: "key", val: -1 });
if (srtdisckey > -1)
  fields.push({ dbs: "ins_srtdiscipline_key", typ: "key", val: srtdisckey });
else
  fields.push({ dbs: "ins_srtdiscipline_key", typ: "key", val: -1 });


var warning = "";
if (menu_key > 0)
{
  sql = buildUpdate("fac_menu", fields)
      + "     fac_menu_key = " + menu_key;

  var err = Oracle.Execute(sql, true);
  if (err.friendlyMsg)
      warning = err.friendlyMsg;
}
else
{
  fields.push({  dbs: "fac_menu_key",         typ: "key",      seq: "fac_s_fac_menu_key" });
  var regIns = buildInsert("fac_menu", fields);
  var menu_key = regIns.sequences["fac_menu_key"];
  var menuitem_key = getFParamInt("fac_mikey", -1);
  sql = regIns.sql;
  var err = Oracle.Execute(sql, true);
  if (err.friendlyMsg)
      warning = err.friendlyMsg;
}

%>
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(document).ready(function () {
            FcltMgr.closeDetail(window, { menu_key: <%=menu_key%>,
                                          menuitem_key: <%=menuitem_key%>,
                                          warning: "<%=safe.jsstring(warning)%>",
                                          keepForm: <%=warning?"true":"false"%>
                                         }); } );
    </script>
  </head>
  <body>
  </body>
</html>
