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

     File:               mld_vrije_dagen_copy.asp
     Description:        Kopieer van de aangegeven kalender_id de vrije dagen naar een andere kalender_id
     Parameters:         kalender_id
                         jaar

     Context:
     Note:

  */
%>

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

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

user.checkAutorisation("WEB_PRSSYS");

%>
<html>
  <head>
<%  FCLTHeader.Generate();
    var submitting = getQParamInt("submit", 0) == 1;
    if (submitting)
    {
      var calOrg_id = getFParamSafe("cal_org", "");
      var calJaar = getFParamInt("cal_yr", -1);
      var calNew_id = getFParamSafe("cal_new", "");
      protectRequest.validateToken();

      var sql = "SELECT mld_vrije_dagen_datum"
              + "  FROM mld_vrije_dagen"
              + " WHERE mld_vrije_dagen_id = " + safe.quoted_sql(calOrg_id)
              + "   AND EXTRACT(YEAR FROM mld_vrije_dagen_datum) = " + calJaar;
      var oRs = Oracle.Execute(sql);
      while (!oRs.eof)
      {
        var vrijedag = new Date(oRs("mld_vrije_dagen_datum").Value);
        var sql_copy = "INSERT INTO mld_vrije_dagen"
                     + "( mld_vrije_dagen_id, mld_vrije_dagen_datum)"
                     + "VALUES"
                     + "(" + safe.quoted_sql(calNew_id)
                     + "," + vrijedag.toSQL()
                     + ")";
        Oracle.Execute(sql_copy);
        oRs.MoveNext();
      }
      oRs.Close();

%>    <script type="text/javascript">
        FcltMgr.closeDetail(window, { refresh: true } );
      </script>
<%    Response.End;
    }
%>
    <script type="text/javascript">
      async function mld_submit()
      {
          document.activeElement.blur(); // trigger laatste onChanges
          if (!await validateForm("copyform"))
              return false;
          if ($("#cal_org").val() == $("#cal_new").val() )
          {
            alert(L("mld_vrije_dagen_same_id"));
            return false;
          }
          document.forms.copyform.submit();
      }
      function mld_cancel()
      {
          FcltMgr.closeDetail(window);
      }
      function changeCalOrg()
      {
        var sel_id = $("#cal_org").find(":selected").val();
        var dis_id = $("#cal_sel").find(":disabled").val();

        $("#cal_sel option[value='" + dis_id + "']").attr("disabled", false);
        $("#cal_sel option[value='" + sel_id + "']").attr("disabled", true);
      }
      function changeCalSel()
      {
        var sel_id = $("#cal_sel").find(":selected").val();
        $("#cal_new").val( (sel_id == -1 ? "" : sel_id) );
      }
    </script>
  </head>

  <body class="fclt-modal" id="mod_vrijedagencopy">
    <% MODAL_START(); %>
    <form id="copyform" name="copyform" action="mld_vrije_dagen_copy.asp?submit=1" method="post">
<%
      var sql_k = "SELECT DISTINCT"
                + "       mld_vrije_dagen_id"
                + "     , mld_vrije_dagen_id"
                + "  FROM mld_vrije_dagen"
                + " ORDER BY 2";
      var sql_j = " SELECT DISTINCT"
                + "        EXTRACT(YEAR FROM mld_vrije_dagen_datum)"
                + "      , EXTRACT(YEAR FROM mld_vrije_dagen_datum)"
                + "   FROM mld_vrije_dagen"
                + "  ORDER BY 2";

      MODAL_BLOCK_START("van_kalender", L("mld_vrije_dagen_sel_id"), { icon: "fa-file-arrow-up" });
        FCLTselector( "cal_org"
                    , sql_k
                    , { label: L("lcl_calendar")
                      , required: true
                      , emptyOption: L("mld_vrije_dagen_sel_id")
                      , onChange: "changeCalOrg()"
                      }
                    );
        FCLTselector( "cal_yr"
                    , sql_j
                    , { label: L("lcl_mld_year")
                      , required: true
                      , emptyOption: L("mld_vrije_dagen_sel_jr")
                      }
                    );
      MODAL_BLOCK_END();

      MODAL_BLOCK_START("naar_kalender", L("mld_vrije_dagen_copy_to"), { icon: "fa-file-arrow-down"});
        FCLTselector( "cal_sel"
                    , sql_k
                    , { emptyOption: L("mld_vrije_dagen_sel_id")
                      , label: "&nbsp;"
                      , onChange: "changeCalSel()"
                      }
                    );
        RWFIELDTR("cal_new", "fld required", L("lcl_calendar"), "", {datatype: "text", placeholder: L("mld_vrije_dagen_new_id")});
      MODAL_BLOCK_END();

      SIMPLE_BLOCK_START();
        CreateButtons( [ {title: L("lcl_submit"), icon: "fa-fclt-save", action: "mld_submit()", singlepress: true, id: "btn_copy_submit", importance: 1}
                       , {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "mld_cancel()", importance: 3}
                       ]
                     );
      SIMPLE_BLOCK_END();
      IFACE.FORM_END();
%>
    </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
