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

     File:        akza/rap_prs.asp (cad/rap_prs.asp)
     Description: Inhoud van het PRS-tabblad van FG
     Parameters:  floorKey (required)
                  highlight (optional list of room-keys to filter)
     Context:     -
     Note:
*/%>

<!-- #include file="../../appl/Shared/common.inc" -->
<!-- #include file="../../appl/Shared/resultset_table_v2.inc" -->

<%
var floorKey = getQParamInt("vKey", -1);
var highlight_arr = getQParamIntArray("highlight", []);
var outputmode = getQParamInt("outputmode", 0);
var showall    = getQParamInt("showall", 0) == 1;
%>

<html>
  <head>
<%  FCLTHeader.Generate({ outputmode: outputmode, root: "../../appl/" }); %>
    <script type="text/javascript">
      function onClickPerslid(row)
      {
        FcltMgr.openDetail("appl/prs/prs_perslid.asp?key=" +  row.getAttribute("ROWKEY"), "<%=''%>");
      }
    </script>
  </head>

  <body class="tabpage">
<%
    if (floorKey != -1)
    {
      // werkplekken: Personen binnen de geselecteerde ruimtes, of de werkplekken van gezochte personen
      sql = " SELECT l.alg_ruimte_aanduiding"
          + "      , COALESCE (pf.prs_perslid_naam_full, '[Vrij]') naam"
          + "      , p.prs_perslid_telefoonnr"
          + "      , p.prs_perslid_mobiel"
          + "      , p.prs_perslid_email email"
          + "      , " + S("prs_dep_string") + " afd"
          + "      , p.prs_srtperslid_omschrijving"
          + "      , p.prs_perslid_upper"
          + "      , pwp.prs_perslidwerkplek_key"
          + "      , TO_CHAR(pwp.prs_perslidwerkplek_bezetting) bezetting"
          + "      , p.prs_perslid_key"
          + "   FROM prs_v_perslid_gegevens p"
          + "      , prs_v_aanwezigafdeling d"
          + "      , prs_v_perslid_fullnames pf"
          + "      , (select * from prs_werkplek where prs_werkplek_virtueel = 0) w"
          + "      , prs_perslidwerkplek pwp"
          + "      , (SELECT alg_r.alg_ruimte_key alg_ruimte_key,"
          + "                   alg_g.alg_gebouw_code"
          + "                || '-'"
          + "                || TO_CHAR (alg_v.alg_verdieping_code)"
          + "                || '-'"
          + "                || alg_r.alg_ruimte_nr alg_ruimte_aanduiding"
          + "           FROM alg_gebouw alg_g, alg_verdieping alg_v, alg_v_aanwezigruimte alg_r"
          + "          WHERE alg_v.alg_verdieping_key = " + floorKey
          + "            AND alg_v.alg_verdieping_key = alg_r.alg_verdieping_key"
          + "            AND alg_g.alg_gebouw_key = alg_v.alg_gebouw_key) l"
          + "  WHERE w.prs_alg_ruimte_key = l.alg_ruimte_key"
          + "    AND pwp.prs_werkplek_key(+) = w.prs_werkplek_key"
          + "    AND p.prs_perslid_key(+) = pwp.prs_perslid_key"
          + "    AND d.prs_afdeling_key(+) = p.prs_afdeling_key"
          + "    AND pf.prs_perslid_key(+) = p.prs_perslid_key"
          + (highlight_arr.length
            ? " AND l.alg_ruimte_key IN (" + highlight_arr.join(",") + ")"
            : "")
          + " ORDER BY 1, 7";
    }
    else
    {
      sql = "SELECT * FROM DUAL WHERE 1 = 0";
    }

    var lastValue = null;
    function showRoomDesc(oRs)
    { // leek leuk om herhalingen te onderdrukken, maar sorteren maakt het waardeloos
      if (false && outputmode == 0 && safe.htmlattr(oRs("alg_ruimte_aanduiding").value) == lastValue)
        var result = null;
      else
        var result = safe.htmlattr(oRs("alg_ruimte_aanduiding").value);
      lastValue = result;
      return result;
    }

    function fnEmail(oRs)
    {
      if (oRs("email").value != null)
        return"<a onclick='window.event.cancelBubble = true' href='mailto:" + safe.htmlattr(oRs("email").value) + "'>" + safe.htmlattr(oRs("email").value) + "</a>";
      else
        return "";
    }

    var rst = new ResultsetTable({ sql: sql,
                                   ID : "cadprstable",
                                   keyColumn: "prs_perslid_key",
                                   title: L("lcl_search_pers"),
                                   outputmode: outputmode,
                                   showAll: showall
                                 });

    rst.addColumn(new Column({caption: L("lcl_obj_inf_room"), content: showRoomDesc}));
    rst.addColumn(new Column({caption: L("lcl_name"), content: "naam"}));
    rst.addColumn(new Column({caption: L("lcl_occupation_perc"), content: "bezetting"}));
    rst.addColumn(new Column({caption: L("lcl_phone"), content: "prs_perslid_telefoonnr"}));
    rst.addColumn(new Column({caption: L("lcl_prs_email"), content: fnEmail}));
    rst.addColumn(new Column({caption: L("lcl_prs_mobile"), content: "prs_perslid_mobiel"}));
    rst.addColumn(new Column({caption: L("lcl_prs_organisatie"), content: "afd"}));
    //AKZA wil dit niet rst.addColumn(new Column({caption: L("lcl_fg_func_names"), content: "prs_srtperslid_omschrijving"}));

    rst.addAction({ action: "onClickPerslid", caption: L("lcl_edit"), isDefault: true } );

    var cnt = rst.processResultset();
%>
  </body>
</html>
