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

    File:               shared/queuemail_schedule.asp
    Description:        Laat een bepaalde URL (die hopelijk een rapportage oplevert) inplannen
    Parameters:
    Context:
    Note:

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../API2/api2.inc" -->
<%
protectQS.verify(); // tamper check
FCLTHeader.Requires({plugins:[],
                     js: ["jquery.timepicker-table.js"],
                     css: ["timePicker-table.css"]});

var usrrap_key = getQParamInt("usrrap_key", -1);
var subject = getQParam("subject", "");

%>
  <html>
    <head>
<%
      FCLTHeader.Generate();
%>
      <script type='text/javascript'>
        $(function()
        {
            $("textarea").resize(function () { FcltMgr.resized(window) } );
            $("textarea").autogrow();
            $("#emails").focus();
            $("[name=fac_sched]").change(function () {
                    $("#show_nextrun").closest("tr").toggle($(this).val() != "0");
                    $("#interval").closest("tr").toggleClass('hidden', $(this).val() == "0");
                    FcltMgr.resized();
                 });
        });

        async function queueSubmit()
        {
            // Standaard checks op verplichte velden, datum formaat, numeriek en float formaat, currency formaat.
            if (!await validateForm("u2"))
                return false;

            var params = FcltMgr.dialogArguments()||{};
            if (params.geturl)
            {
                $("#geturl").val(params.geturl);
            }

            var xurl = "queuemail_schedule_save.asp";
            $.post(xurl,
                   $("[name=u2]").serialize(),
                   FcltCallbackClose,
                   "json");
        }

        function queueCancel()
        {
          FcltMgr.closeDetail(window, { cancel: true } );
        }
      </script>
    </head>

    <body class="fclt-modal" id="mod_queuemail">
<%    MODAL_START(); %>
        <form name="u2" id="u2" method="post">
            <input type="hidden" name="geturl" id="geturl" value="">
            <input type="hidden" name="fac_usrrap_key" id="fac_usrrap_key" value="<%=usrrap_key%>">
<%
          MODAL_BLOCK_START("emailInput", subject, { icon: "fa-envelope" });

            FCLTpersoonselector("sName_key",
                                "sgPerson",
                                { perslidKey: user_key,
                                  readonly: !user.has("WEB_UDRMAN"), // Gewone gebruikers mogen alleen naar zichzelf
                                  label: L("prs_perslid_key_receiver"),
                                  filtercode: "MAIL" // dit maakt dat _Facilitor vaak rood wordt bij gebrek aan e-mail
                                });
          RWFIELDTR("subject",  "fld", L("lcl_noti_sendsubject"), subject, { maxlength: 60});

        var sql = "       SELECT 1, " + safe.qL('lcl_schedule_format_standard') + ", 0 volgorde FROM DUAL"
                + " UNION SELECT 8, " + safe.qL('lcl_schedule_format_excel')    + ", 1 FROM DUAL"
                + " UNION SELECT 4, " + safe.qL('lcl_schedule_format_csv')      + ", 2 FROM DUAL"
                + " ORDER BY 3"
        FCLTselector("q_outputmode",
                     sql,
                     { label: L("lcl_schedule_format"),
                       initKey: 1
                     });

if (user.has("WEB_UDRMAN"))
{
%>
            <tr>
            <td class="label"><label for="fac_sched"><%=L("lcl_schedule_plan")%></label></td>
                <td>
                  <label for="fac_sched">
                    <input type="radio" name="fac_sched" id="fac_sched" value="0" checked="1"><%=L("lcl_schedule_once")%>
                  </label>
                  <br />
                  <label for="fac_sched_p">
                    <input type="radio" name="fac_sched" id="fac_sched_p" value="1"><%=L("lcl_schedule_planned")%>
                  </label>
               </td>
            </tr>
<%
        var dt = new Date();
        dt.setDate(dt.getDate() + 1);
        dt.setHours(8, 0, 0, 0); // Morgenvroeg 8 uur als default
        FCLTcalendar( "nextrun",
                      { label     : L("fac_notificatie_job_nextrun"),
                        datum     : dt,
                        maxPast   : 0,
                        timeField : true,
                        timeStep  : 60,
                        startTime : 0,
                        endTime   : 23,
                        required  : true,
                        trhidden  : true
                      });

        var sql = api2.splitLOV2sql(L("fac_notificatie_job_intervalLOV"));
        FCLTselector("interval",
                    sql,
                    { label: L("fac_notificatie_job_interval2"),
                      initKey: 168,
                      trclass: 'hidden'
                    });

}
MODAL_BLOCK_END();
          SIMPLE_BLOCK_START();
            var buttons =  [ { title: L("lcl_noti_send"), id: "btn_send", icon: "fa-paper-plane", action: "queueSubmit()", singlepress: true, importance: 1 },
                            { title: L("lcl_cancel"), id: "btn_cancel", icon: "fa-fclt-cancel", action: "queueCancel()", importance: 3 }];
            CreateButtons(buttons, { isModal: true, showIcons: true });
          SIMPLE_BLOCK_END();

IFACE.FORM_END();
%>
        </form>
<%    MODAL_END(); %>
    </body>
  </html>
<% ASPPAGE_END(); %>
