<%@ 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="fac.inc" -->
<!-- #include file="../Shared/json2.js" -->
<%
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" >

      jQuery(document).ready(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()
      {
        if (confirm(L("lcl_fac_del_txt_api")))
        {
           var data = { key: <%=api_key%>
                      , level: "AP"
                      };
           <% protectRequest.dataToken("data"); %>
           $.post("fac_delete.asp"
                 , data
                 , FcltCallbackClose
                 , "json"
                 );
        }
      }

    </script>
  </head>

  <body id="editbody">
<%
  var buttons = [];
  if (canChange)
  {
    buttons.push({title: L("lcl_change"), action: "api_change()", icon: "wijzigen.png" });
    buttons.push({title: L("lcl_delete"), action: "api_delete()", icon: "delete.png" });
  }

    IFRAMER_HEADER("Setting", buttons);
%>
    <div id="edit">
      <form name=u2>
<%
function prettyJson(j)
{
  try
  {
    var xx = JSON.stringify(eval("("+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"));
        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);
        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_import_app")      , oRs("fac_import_app_key").Value);
        ROTEXTAREATR("fldtxt",   L("lcl_fac_api_options")     , prettyJson(oRs("fac_api_options_json").Value));
        BLOCK_END();
if (0) // We weten niet welke user te gebruiken?
{
        BLOCK_START("apiSample", L("lcl_fac_api")+" "+L("lcl_fac_api_sample"));
          var proto = (Request.ServerVariables("SERVER_PORT") == "443")? "https" : "http";
          var sitenoroot = proto + "://" + Request.ServerVariables("SERVER_NAME");
          var site = sitenoroot + rooturl;
          var deep = site + "/?API="+oRs("fac_api_name").Value+"&APIKEY="+oRs("fac_api_apikey").Value;
          ROFIELDTR("fldtxt",L("lcl_fac_api_sample"), deep);
          var deep = site + "/?fac_id="+customerId+"&API="+oRs("fac_api_name").Value+"&APIKEY="+oRs("fac_api_apikey").Value;
          ROFIELDTR("fldtxt",L("lcl_fac_api_of"), deep);
        BLOCK_END();
}
%>
      </form>
    </div>
  </body>
</html>
