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

    File:           export.asp
    Description:    Queue an export routine for execution (once)
    Parameters:
        name        Export routine
    Globals:
    Context:        Called from the portal
    Note:

*/ %>
<!--#include file="../Shared/common.inc"-->
<!--#include file="../shared/iface.inc"-->
<%
FCLTHeader.Requires({ plugins: ["jQuery"],
                      js: [] });
%>
<html>
  <head>
<%  FCLTHeader.Generate();
    var submitting = getQParamInt("submit", 0) == 1;
    var name = getQParam("name");
    var action = getFParam("action", "");
    var message = "";
    if (submitting)
    {
        protectRequest.validateToken();
        if (action == "on")
        {
            sql = "INSERT INTO imp_schedule ("
                + "    imp_schedule_name, "
                + "    prs_perslid_key"
                + ") VALUES ("
                + safe.quoted_sql(name)+ ","
                + user_key
                + ")";
            oRs = Oracle.Execute(sql);
            var message = L("lcl_export_ready").format(name);
        }
        else if (action == "off")
        {
          sql = "DELETE"
              + "  FROM imp_schedule"
              + " WHERE imp_schedule_done IS NULL"
              + "   AND imp_schedule_name = " + safe.quoted_sql(name);
            oRs = Oracle.Execute(sql);
            var message = L("lcl_export_cancelled").format(name);
        }
      %>
      <script type="text/javascript">
        FcltMgr.closeDetail( window,
                             {
                               warning: "<%=safe.jsstring(message)%>",
                               success: true
                             });
      </script>
<%
      Response.End;
    }
%>
<script type="text/javascript">
    function doSubmit(action)
    {
        $("#action").val(action);
        document.forms.u2.submit();
    }
    $(function ()
    {
        <%
          sql = "SELECT imp_schedule_key"
              + "  FROM imp_schedule"
              + " WHERE imp_schedule_done IS NULL"
              + "   AND imp_schedule_name = " + safe.quoted_sql(name);

          oRs = Oracle.Execute(sql);

          if (oRs.eof) { %>
                FcltMgr.confirm(L("lcl_export_do").format("<%=safe.jsstring(name)%>"), function() {
                    doSubmit('on');
                });
          <% } else { %>
                FcltMgr.confirm(L("lcl_export_cancel").format("<%=safe.jsstring(name)%>"), function() {
                    doSubmit('off');
                });
          <% } %>
    });
</script>

</head>
<body id="mod_export" style="width:400px">
    <form name=u2 action="export.asp?submit=1&name=<%=safe.htmlattr(name)%>" method="post">
        <input type='hidden' id='action' name='action' value='geen'>
<% IFACE.FORM_END(); %>
    </form>
</body>
<% ASPPAGE_END(); %>
