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

     File:               fac_prsfaq.asp
     Description:        Laat aan een FAQ meerdere bedrijven of afdelingen
     Parameters:         faq_key: fac_faq_key waaraan deze gekoppeld moeten worden
     Context:
     Note:

k
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/bedrijfselector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../fac/fac.inc" -->

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

var faq_key = getQParamInt("faq_key");
var submitting = getQParamInt("submit", 0) == 1;

var this_faq = fac.func_enabled_faq(faq_key); // Wat heb ik zoal aan rechten op deze specifieke kennisbankitem.

user.auth_required_or_abort(this_faq.canChange);

var bedr_key = -1;
var afd_key = -1;
%>
  <html>
    <head>
<%    FCLTHeader.Generate(); %>
      <script>
        function onChangeBedrijf(bdr_key) {
          if (bdr_key > 0) {
            sgDepartment.setValue($("#sgCompany").val(), $("#sgCompany_show").val(), true, true);
          } else {
            sgDepartment.setValue(-1, "");
          }
        }
        function onChangeAfdeling(afd_key) {
          var bdr_key = $("#bdr_key").val();
          if (!(bdr_key > 0) && afd_key > 0) {
            $.getJSON("./get_fac_info_ajax.asp",
                      { req_info: "get_company",
                        afd_key: afd_key
                      },
                      data => {
                        sgCompany.setValue(data.bedrijf_key, data.bedrijf_naam);
                      });
          }
        }
      </script>
    </head>

    <body class="fclt-modal" id="mod_prsfaq">
      <% MODAL_START(); %>
        <form name="u2" method="post" action="fac_prsfaq_save.asp?faq_key=<%=faq_key%>">
        <% MODAL_BLOCK_START(); %>
          <input type="hidden" id="nrRows" name="nrRows" value="0">
          <input type="hidden" id="plaats" name="plaats" value="">
          <input type="hidden" id="scope" name="scope" value="">
<%
          FCLTbedrijfselector("bedrijf",
                              "sgCompany",
                            { label: L("lcl_company"),
                              onChange: "onChangeBedrijf",
                              filtercode: "I"
                            });

          FCLTafdelingselector("afdeling",
                               "sgDepartment",
                             { label: L("lcl_department"),
                               onChange: "onChangeAfdeling",
                               filtercode: "I",
                               urlAdd: [{ urlParam: "bedrijf_key", field: "bedrijf" }]
                             });
%>
          <tr>
            <td></td>
            <td>
              <div id="addprsfaqbuttons">
<%
              var buttons =  [ {title: L("lcl_add"), icon: "fa-plus", action: "fac_add()", id: "btn_faq_add_prs", importance: 1  }];
              CreateButtons(buttons, { showIcons: true });
%>
              </div>
            </td>
          </tr>
          <tr>
            <td class="label" colspan="2">
              <label for="prsfaqtable" style="white-space: nowrap"><%=L("lcl_faq_voor_prs")%></label>
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <table id="prsfaqtable" class="rstable">
                <thead>
                  <tr>
                    <th style='width:15px'></th>
                    <th><%=L("lcl_company")%></th>
                    <th><%=L("lcl_department")%></th>
                  </tr>
                </thead>
                <tbody>

<%
        var sql = "SELECT f.prs_prsfaq_key"
                + "     , f.prs_bedrijf_key bedrijf_key"
                + "     , b.prs_bedrijf_naam bedrijf"
                + "     , COALESCE(f.prs_afdeling_key, -1) afdeling_key"
                + "     , d.prs_afdeling_naam afdeling"
                + "  FROM prs_prsfaq f"
                + "     , prs_bedrijf b"
                + "     , prs_afdeling d"
                + " WHERE f.prs_bedrijf_key = b.prs_bedrijf_key"
                + "   AND f.prs_afdeling_key = d.prs_afdeling_key(+)"
                + "   AND f.fac_faq_key = " + faq_key;

                oRs = Oracle.Execute(sql);
                while (!oRs.eof)
                {
%>
                  <script type="text/javascript">
                    CreateRow(<%=oRs("bedrijf_key").value%>
                            , '<%=safe.jsstring(oRs("bedrijf").value)%>'
                            , <%=oRs("afdeling_key").value%>
                            , '<%=safe.jsstring(oRs("afdeling").value)%>'
                             );
                  </script>
<%
                  oRs.MoveNext();
                }
%>
                </tbody>
              </table>
            </td>
          </tr>
<%
          MODAL_BLOCK_END();
          var buttons1 =  [{title: L("lcl_submit"), icon: "fa-fclt-save", action: "fac_submit()", importance: 1 }];
          SIMPLE_BLOCK_START();
            CreateButtons(buttons1);
          SIMPLE_BLOCK_END();
          IFACE.FORM_END();
%>
        </form>
        <% MODAL_END(); %>
    </body>
  </html>
<%

%><% ASPPAGE_END(); %>
