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

    File:               bez_edit_check_in.asp
    Description:        Muteerscherm voor aanmelden bezoeker
    Parameters:         urole
                        bez_key
    Context:
    Note:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="./bez.inc" -->
<!-- #include file="./bez_edit_bezoekers_save.inc" -->
<!-- #include file="./bez_flexkenmerk.inc" -->
<%
FCLTHeader.Requires({ plugins: ["suggest", "jQuery"]});

var bez_key = getQParamInt("bez_key", -1);
var urole = getQParamSafe("urole", "bo");

var fronto = urole == "fo"; // DEPRECATED
var backo  = urole == "bo";
var next_vis = 1;

var authparams = user.checkAutorisation({ fe: "WEB_BEZUSE",
                                          bo: "WEB_BEZBOF",
                                          fo: "WEB_BEZFOF"} [urole]);

var sql = "SELECT a.bez_afspraak_key"
        + "     , a.bez_afspraak_datum"
        + "     , a.bez_afspraak_eind"
        + "     , a.alg_locatie_key"
        + "     , b.bez_afspraak_naam"
        + "     , b.bez_afspraak_bedrijf"
        + "     , b.prs_contactpersoon_key"
        + "     , b.prs_perslid_key"
        + "     , b.bez_bezoekers_opmerking"
        + "     , b.bez_bezoekers_pasnr"
        + "     , b.bez_bezoekers_telefoon"
        + "     , b.bez_bezoekers_email"
        + "     , b.bez_bezoekers_kenteken"
        + "  FROM bez_afspraak a"
        + "     , bez_bezoekers b"
        + " WHERE a.bez_afspraak_key = b.bez_afspraak_key"
        + "   AND b.bez_bezoekers_key = " + bez_key;
var oRs = Oracle.Execute(sql);
if (oRs.Eof)
    shared.record_not_found("<!--" + bez_key + "-->");

var this_bez = {afspraak_key:   oRs("bez_afspraak_key").Value,
                afspraak_start: new Date(oRs("bez_afspraak_datum").Value),
                afspraak_eind:  new Date(oRs("bez_afspraak_eind").Value),
                locatie_key:    oRs("alg_locatie_key").Value,
                bezoeker_naam:  oRs("bez_afspraak_naam").Value,
                bedrijf_naam:   oRs("bez_afspraak_bedrijf").Value,
                contact_key:    oRs("prs_contactpersoon_key").Value,
                perslid_key:    oRs("prs_perslid_key").Value,
                opmerking:      oRs("bez_bezoekers_opmerking").Value,
                badgenr:        oRs("bez_bezoekers_pasnr").Value,
                telefoon:       oRs("bez_bezoekers_telefoon").Value,
                email:          oRs("bez_bezoekers_email").Value,
                kenteken:       oRs("bez_bezoekers_kenteken").Value
               };
var bez_afspraak = bez.bez_afspraak_info(this_bez.afspraak_key);
this_bez.ruimte_extern = bez_afspraak.res_ruimte_extern;
oRs.Close();

var sql = "SELECT COUNT(*) aantal"
        + "  FROM bez_kenmerk"
        + " WHERE bez_kenmerk_verwijder IS NULL"
        + "   AND BITAND(bez_kenmerk_rolcode,4) = 4";

var oRs = Oracle.Execute(sql);
var hasEditableProperties = (oRs("aantal").Value > 0);
oRs.Close();

var alleen_afhandelingskenmerken = (!user.has("WEB_BEZBOF") || ( (S("bez_show_progress_prop") & 4) > 0) );
%>

<html>
  <head>
<%  FCLTHeader.Generate() %>
    <script>

      var urole = "<%=urole%>";
      var bez_max_flex_on_line = <%=S("bez_max_flex_on_line")%>;
      async function bez_submit()
      {
        if (!await validateForm("u2", {checklength: true}))
          return false;
        $.post($("form[name=u2]")[0].action, $("[name=u2]").serialize(), FcltCallbackClose, "json");
        return true;
      }

      function bez_cancel()
      {
        FcltMgr.closeDetail(window, { cancel: true } );
      }

      $(function()
      {
          FcltMgr.resized(window);
      });

    </script>
  </head>
  <body class="fclt-modal" id="mod_bezcheckin">
  <% MODAL_START(); %>
      <form name="u2"
            action="bez_edit_bezoekers_save.asp?urole=<%=urole%>&nopark=1"
            method="post">
        <% MODAL_BLOCK_START("bezCheckin", L("lcl_vis_register_title"), {icon: "fa-user"}); %>
        <input type="hidden" id="afspr_key" name="afspr_key" value="<%=this_bez.afspraak_key%>">
        <input type="hidden" id="bez_key<%=next_vis%>" name="bez_key<%=next_vis%>" value="<%=bez_key%>">
        <input type="hidden" id="next_vis" name="next_vis" value=<%=next_vis + 1%>>

<%
            var bezreado = this_bez.ruimte_extern || this_bez.contact_key != null || this_bez.perslid_key != null;
            var company = L("lcl_vis_company") + (S("bez_sel_internpersoon") == 1 ? "/" + L("lcl_department") : "");


            RWFIELDTR("bez" + next_vis, "fld", L("lcl_vis_name"),  this_bez.bezoeker_naam, { maxlength: 30, readonly: bezreado });
            RWFIELDTR("bed" + next_vis, "fld", company,            this_bez.bedrijf_naam,  { maxlength: 60, readonly: bezreado });

            var flexfilter = [];
            if (alleen_afhandelingskenmerken)
            {
                flexfilter = ["BITAND(k.bez_kenmerk_rolcode,4) = 4"];
            }

            if (!alleen_afhandelingskenmerken && (S("vis_remark") == 1 || S("vis_remark") == 2))
            {
                RWFIELDTR("opm" + next_vis, "fld", L("lcl_vis_remark"), this_bez.opmerking, { maxlength: 50 });
            }
            if (!alleen_afhandelingskenmerken && (S("vis_bo_uses_badgenrs") == 1))
            {
                if (backo)
                    RWFIELDTR("bdg" + next_vis, "fld fldbadge", L("lcl_vis_badgenr"), this_bez.badgenr, { maxlength: 30 });
                else
                {
%>
                    <input type="hidden" id="bdg<%=next_vis%>" name="bdg<%=next_vis%>" value="<%=this_bez.badgenr%>">
<%
                }
            }
            ROFIELDTR("fld", L("lcl_bez_telefoon"), this_bez.telefoon, { suppressEmpty: true });
            ROFIELDTR("fld", L("lcl_bez_email"), this_bez.email, { suppressEmpty: true });
            ROFIELDTR("fld", L("lcl_bez_kenteken"), this_bez.kenteken, { suppressEmpty: true });

        MODAL_BLOCK_END();

        var flexparams = { urole: urole,
                            bez_key: bez_key,
                            beznum: next_vis,
                            ispopup: true,
                            filter: flexfilter
                          };
        // Mag hier alle kenmerken zien, maar alleen > 900 wijzigen.
        generateFlexKenmerkCode(flexparams);

        var buttons =  [ {title: L("lcl_submit"), icon: "fa-fclt-save", action: "bez_submit()", id: "bsubmit_bez_bezoekers", importance: 1 },
                         {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "bez_cancel()", id: "bcancel_bez_bezoekers", importance: 3 } ];
        SIMPLE_BLOCK_START();
        CreateButtons(buttons);
        SIMPLE_BLOCK_END();
    IFACE.FORM_END();
%>
      </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
