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

    File:               prs_edit_perslid_multi.asp
    Description:        Multi editten van personeelsleden
    Parameters:         key

    Context:            prs_perslid_list.asp
    Note:               De minimale multi-edit velden

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../Shared/functieselector.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/save2db.inc" -->
<!-- #include file="./prs_flexkenmerk.inc" -->
<!-- #include file="prs.inc" -->

<%
FCLTHeader.Requires({ plugins: ["suggest", "jQuery", "kenmerk"],
                      js: ["multi.js"] });

var prs_key_arr = getQParamIntArray("prs_keys");
var tobeedited = 0;
var ingesloten = [];
// Determine whether any user can be changed
for (var i = 0; i < prs_key_arr.length; i++)
{
  var prsauthparams = prs.checkAutorisation(prs_key_arr[i]);
  if (prsauthparams.writeman || prsauthparams.writeuse || prsauthparams.writeself)
  {
    ingesloten.push(prs_key_arr[i]);
    tobeedited++;
  }
}

user.auth_required_or_abort(ingesloten.length); // We klagen niet over enkele wel en enkele niet
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">
      $(function () { $("select option[value=-1]").val(""); }); // prevents removal of values from listboxes

      function prs_submit()
      {
        $.post($("form[name=u2]")[0].action,
               $("[name=u2]").serialize(),
               FcltCallbackAndThenAlways(prs_submit_callback),
               "json");
        return true; // disable button
      }

      function prs_submit_callback(json)
      {
        iface.button.enable("btn_edit_submit");
        if (json.success)
          FcltMgr.closeDetail(window, json);
      }

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

  <body class="fclt-modal" id="mod_prsmultiedit">
    <% MODAL_START(); %>
    <form name="u2" action="prs_edit_perslid_multi_save.asp?prs_keys=<%=ingesloten.join(",")%>" method="post">
<%
      MODAL_BLOCK_START("prsPerslid", L("lcl_prs_basisblok"), { icon: "fa-id-card-alt" });

      var sql = " SELECT 0, " + safe.quoted_sql(L("lcl_prs_perslid_visibility0")) + " FROM DUAL UNION ALL"
              + " SELECT 1, " + safe.quoted_sql(L("lcl_prs_perslid_visibility1")) + " FROM DUAL";
      FCLTselector("prs_visibility", sql,
               { label: L("lcl_prs_person_visibility"),
                 initKey: 0,
                 initEmpty: true,
                 readonly: !(prsauthparams.writeself || prsauthparams.writeuse)
              });

      if (prsauthparams.writesys) {
        RWCHECKBOXTR("ingids", "fldnotingids", L("lcl_prs_in_guide"));
      }

      FCLTafdelingselector("prs_afdkey",
                           "prs_afdkey",
                          { departmentKey: 0,
                            label: L("lcl_prs_organisatie"),
                            autlevel: prsauthparams.PRSreadlevel, // Was voorheen niet aanwezig
                            readonly: !prsauthparams.writeman,
                            required: false
                         });

      FCLTfunctieselector("prs_srtkey", "prs_srtkey" ,
                          {label: L("lcl_prs_person_function"),
                             srtperslidKey: 0,
                             emptyOption: "",
                             readonly: !prsauthparams.writeman,
                             required: false
                          });

      sql = "SELECT   fac_profiel_key, "
          + "         fac_profiel_omschrijving "
          + "    FROM fac_profiel "
          + "ORDER BY 2 ";
      FCLTselector("fac_prkey", sql,
                  { label: L("lcl_prs_profile"),
                    initKey: "",
                    emptyOption: "",
                    initEmpty: true,
                    readonly: !prsauthparams.writeman
                  });

      if (S("language_toggles").length > 1)
      {
          var sql = "";
          for (var i=0; i<S("language_toggles").length; i++)
          {
              sql += (i>0 ? " UNION " : "") + "SELECT "+safe.quoted_sql(S("language_toggles")[i])+","+safe.quoted_sql(S("language_toggles")[i])+" FROM DUAL";
          }
          FCLTselector("prs_lang", sql,
                     { label: L("lcl_lcl_taal"),
                       initKey: "",
                       emptyOption: "",
                       initEmpty: true
                     });
      }

      var sql = "   SELECT DISTINCT (tzname), '(UTC ' || RTRIM (TZ_OFFSET (tzname), CHR (0)) || ') ' || tzname"
              + "     FROM V$TIMEZONE_NAMES "
              + " GROUP BY tzname, TZ_OFFSET (tzname) "
              + " ORDER BY TO_NUMBER(SUBSTR (TZ_OFFSET (tzname), 1, 3) "
              + "                 || SUBSTR (TZ_OFFSET (tzname), 5, 2)) ASC,"
              + "          tzname";

      FCLTselector("prs_tz", sql,
                 { label: L("lcl_prs_person_timezone"),
                   initKey: "",
                   emptyKey: "",
                   emptyOption: "",
                   initEmpty: true
                 });

      MODAL_BLOCK_END();

      generateFlexKenmerkCode({
          niveau: "P",
          link_key: -1,
          srt_key: -1,
          prsauthparams: prsauthparams,
          reado: false,
          multi: true
        });

%>
      <script type="text/javascript">

        $(function()
          {
            init_multi();
          });
      </script>
<%
      var buttons =  [];
      buttons.push({title: L("lcl_submit"), icon: "fa-fclt-save", action:"prs_submit()", singlepress: true, id: "btn_edit_submit", importance: 1})
      buttons.push({title: L("lcl_cancel"), icon: "fa-fclt-cancel",  action:"prs_cancel()", importance: 3})
      SIMPLE_BLOCK_START();
        CreateButtons(buttons);
      SIMPLE_BLOCK_END();
      IFACE.FORM_END();
%>
    </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
