<%@language = "javascript" %>
<%  Server.ScriptTimeout=6000; %>
<% /*
     $Revision$
     $Id$

    File:               inlezen_form.asp
    Description:        Laat een willekeurig bestand inlezen
    Parameters:
        imp_key         Importfunctie key
    Context:            Vanuit imp_list
    Note:               Na inlezen sluiten we onzelf

*/
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="imp.inc" -->

<%
FCLTHeader.Requires({ plugins:["jQuery"] });

var import_app_key = getQParamInt("import_app_key"); // Importfunctiekey

// Heb ik rechten om in te lezen
var this_imp = imp.func_enabled_import_app(import_app_key);
user.auth_required_or_abort(this_imp.canWrite);

var sql = "SELECT i.fac_import_app_charset "
        + "  FROM fac_import_app i"
        + " WHERE i.fac_import_app_key = " + import_app_key;
var oRs = Oracle.Execute(sql);
var charset = oRs("fac_import_app_charset").value;
oRs.Close();

%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script>
      async function doSubmit()
      {
        // Standaard checks op verplichte velden, datum formaat, numeriek en float formaat, currency formaat.
        if (!await validateForm("u2"))
          return false

        document.getElementById("inlezen").innerHTML = L("lcl_imp_please_wait");
        document.importForm.submit();
        // JGL: Omzetten naar een $.post kun je wel vergeten, die kent geen multipart/form-data
      }

      function displayFilename(fileInput)
      {
          var fileString = "";
          var files = fileInput.files;
          if (files)
          {
              for (var i = 0; i < files.length; i++) {
                if (i != 0) fileString += "<br>";
                fileString += files[i].name
              }
          }
          else if (fileInput.value)     // IE
              fileString = fileInput.value;

          document.getElementById("inlezen").innerHTML = fileString;
          FcltMgr.resized();
      }

    </script>
  </head>

  <body class="fclt-modal" id="mod_impinlezen">
    <% MODAL_START(); %>
    <form name="importForm" id="importForm" method="POST" enctype="multipart/form-data"
          target="hidFrame" action="imp_inlezen.asp?import_app_key=<%=import_app_key%>" onsubmit="" onreset="">
<%    MODAL_BLOCK_START("fileupload", L("lcl_imp_lezen") + " " + L("lcl_imp_file").toLowerCase(), { "icon": "fa-file-lines" });%>
      <tr>
        <td>
          <label><%=L("fac_import_app_charset")%>: <%=charset || 'windows-1252'%></label>
        </td>
      </tr>
      <tr>
        <td>
           <label for="imp_file" class="uploadbutton"><%=I("fa-upload")%><%=L("lcl_imp_file_name")%></label>
        </td>
      </tr>
      <tr>
        <td>
          <input type="file" name="imp_file" id="imp_file" class="required" style="width:100%" onchange="displayFilename(this)">
        </td>
      </tr>
      <tr>
        <td id="inlezen">
          &nbsp;
        </td>
      </tr>
<%    MODAL_BLOCK_END();
      var buttons = [];
      buttons.push({id: "doupload", title: L("lcl_imp_lezen"), action: "doSubmit()" , icon: "fa-fclt-save"});
      SIMPLE_BLOCK_START();
      CreateButtons(buttons);
      SIMPLE_BLOCK_END();
IFACE.FORM_END();
%>
    </form>
    <iframe height=0 width=100% name="hidFrame" id="hidFrame" src="../shared/empty.asp">
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
