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

    File:          bez_email_bezoeker.asp
    Description:   Multi select bezoekers en stuur deze een email

    Parameters:
    Context:       Vanuit bez_show_bezoekers.asp

    NOTE:
*/
%>
<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/iface.inc"-->
<!--#include file="../bez/bez.inc"-->
<!--#include file="../Shared/resultset_table_v2.inc"-->
<!--#include file="../Shared/send_mail.inc"-->
<%
FCLTHeader.Requires({ plugins: ["jQuery"],
                      js: []
                    });

%>
<html>
  <head>
<%  FCLTHeader.Generate();
    var afspraak_key = getQParamInt("afspr_key");
    var bez_key_arr = getQParamIntArray("bez_key_arr", []);

    var this_bez = bez.func_enabled_afspraak(afspraak_key);
    user.auth_required_or_abort(this_bez.canReadAny);

%>

  <script type="text/javascript">

    function bez_submit(rowArray)
    {
        var bez_key_arr = getKeyString(rowArray);
        var data = { afspr_key: <%=afspraak_key%>
                   , bez_key_arr: bez_key_arr
                   };
        protectRequest.dataToken(data);
        $.post( $("form[name=u2]")[0].action
              , data
              , FcltCallbackAndThen(bez_cancel())
              , "json"
              );
    }

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

    $(function()
    {
        // Vink gelijk alle regels aan.
        $(".master").prop("checked", true).click();
    });

  </script>

  </head>

  <body class="fclt-modal" id="mod_afspraak">
    <% MODAL_START(); %>
      <form name="u2" method="post" action="../bez/bez_email_bezoeker_save.asp?afspr_key=<%=afspraak_key%>">
<%
        MODAL_BLOCK_START("bez_blk", L("lcl_bez_mail_send_to"), { "icon": "fa-envelope" });

            var sql = "SELECT b.bez_bezoekers_key"
                    + "     , b.bez_afspraak_naam naam"
                    + "     , b.bez_afspraak_bedrijf bedrijf"
                    + "     , b.bez_bezoekers_email email"
                    + "  FROM bez_bezoekers b"
                    + " WHERE b.bez_bezoekers_email IS NOT NULL"
                    + "   AND b.bez_afspraak_key = " + afspraak_key;


            var rsParms = { keyColumn: "bez_bezoekers_key"
                          , ID: "restable"
                          , sql: sql
                          , noPrint: true
                          , outputmode: 0
                          };

            var rst = new ResultsetTable(rsParms);
            // kolommen
            rst.addColumn(new Column({caption: L("lcl_vis_name"),    content: "naam" }));
            rst.addColumn(new Column({caption: L("lcl_vis_company"), content: "bedrijf" }));
            rst.addColumn(new Column({caption: L("lcl_bez_email"),   content: "email" }));
            // acties
            rst.addAction({ action: "bez_submit", caption: L("lcl_mes_send"), single: false, multi: true, multiOnce: true});
            var count = rst.processResultset();

        MODAL_BLOCK_END();

        var buttons = [ {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "bez_cancel()" } ];

        SIMPLE_BLOCK_START();
        CreateButtons(buttons, { isModal: true });
        SIMPLE_BLOCK_END();
        IFACE.FORM_END();
%>
      </form>
<% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
