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

     File:           fac_api.asp
     Description:
     Parameters:     api_key
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/rapportselector.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="fac.inc" -->
<%
FCLTHeader.Requires({ plugins:["jQuery"] })

var api_key = getQParamInt("api_key");

var autfunction = "WEB_PRSSYS";
var authparams = user.checkAutorisation(autfunction);
var canChange = user.checkAutorisation("WEB_FACFAC", true);

canChange = true;

var sql = "SELECT * FROM fac_api a"
        + " WHERE fac_api_key ="+api_key;
var oRs = Oracle.Execute(sql);
if (oRs.Eof)
    shared.record_not_found("<!--" + api_key + "-->");

%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">

      $(function()
      {
        $('textarea').resize(function () { FcltMgr.resized(window) } );
        $('textarea').autogrow();
      });

      function api_change()
      {
        if (FcltMgr.startEdit(window))
          window.location.href = "fac_edit_api.asp?api_key=<%=api_key%>";
      }

      function api_delete()
      {
        FcltMgr.confirm(L("lcl_fac_del_txt_api"), function() {
            var data = {
                key: <%=api_key%>,
                level: "AP"
            };
            <% protectRequest.dataToken("data"); %>
            $.post("fac_delete.asp", data, FcltCallbackClose, "json");
        });
      }

    </script>
  </head>

  <body class="showmode">
<%
  SUBFRAME_START();
  var buttons = [];
  if (canChange)
  {
    buttons.push({title: L("lcl_change"), action: "api_change()", icon: "fa-fclt-edit" });
    buttons.push({title: L("lcl_delete"), action: "api_delete()", icon: "fa-trash-alt" });
  }

    IFRAMER_HEADER("Setting", buttons);
      function prettyJson(j)
      {
        try
        {
          var xx = JSON.stringify(JSON.parse(j), null, String.fromCharCode(160, 160, 160, 160));
          if (xx == "null")
              return "";
          return xx;
        }
        catch (e)
        {
          return j;
        };
      };

        BLOCK_START("apiSample", L("lcl_fac_api"), { "icon": "fa-network-wired" });
        ROFIELDTR("fld",         L("lcl_key")                  , oRs("fac_api_key").Value);
        ROFIELDTR("fld",         L("lcl_fac_api_name")         , oRs("fac_api_name").Value);
        ROFIELDTR("fld",         L("lcl_fac_api_omschrijving") , oRs("fac_api_omschrijving").value);
        ROFIELDTR("fld",         L("lcl_fac_api_filepath")     , oRs("fac_api_filepath").Value);
        ROFIELDTR("fld",         L("lcl_fac_api_loglevel")     , oRs("fac_api_loglevel").Value);
        var sql = "           SELECT 0, " + safe.qL("lcl_fac_api_errorhandling0") + " FROM DUAL"
                + " UNION ALL SELECT 1, " + safe.qL("lcl_fac_api_errorhandling1") + " FROM DUAL";
        FCLTselector("fac_api_errorhandling", sql,
            { initKey: oRs("fac_api_errorhandling").Value,
              label: L("lcl_fac_api_errorhandling"),
              readonly: true
            });

        FCLTrapportselector("fac_usrrap_key"
                           ,"sgRapport"
                           ,{ label: L("lcl_fac_api_usrrap")
                            , rapportKey: oRs("fac_usrrap_key").Value
                            , readonly: true
                            });
        ROTEXTAREATR("fldtxt",   L("lcl_fac_api_viewmapping") , prettyJson(oRs("fac_api_viewmapping_json").Value));
        ROFIELDTR("fld",         L("lcl_fac_api_stylesheet")  , oRs("fac_api_stylesheet").Value);
        ROFIELDTR("fld",         L("lcl_fac_api_stylesheet_out")  , oRs("fac_api_stylesheet_out").Value);
        ROTEXTAREATR("fldtxt",   L("lcl_fac_api_options")     , prettyJson(oRs("fac_api_options_json").Value));
        BLOCK_END();

 SUBFRAME_END();
%>
  </body>
</html>
<% ASPPAGE_END(); %>
