<%@ language="javascript"%>
<% /*
     $Revision$
     $Id$
*/%>
<!--#include file="../../appl/Shared/common.inc"-->
<!--#include file="../../appl/Shared/resultset_table_v2.inc" -->
<%
var sql = "";
var names = new Array();
var highlight_arr = getQParamIntArray("highlight", []);
var floorKey = getQParamInt("vKey", -1);
var outputmode = getQParamInt("outputmode", 0);
var showall    = getQParamInt("showall", 0) == 1;
%>

<html>
  <head>
<%  FCLTHeader.Generate({ outputmode: outputmode }); %>
    <script type="text/javascript">
      function gotoMelding(room_key, flr_key, bld_key, loc_key)
      {
        //url = "appl/mld/mld_melding.asp?urole=fe&mld_defaultstdmelding=253&loc_key=" + loc_key + "&bld_key=" + bld_key + "&flr_key=" + flr_key + "&room_key=" + room_key;
        url = "appl/mld/mld_melding.asp?urole=fe&mld_defaultstdmelding=253&room_key=" + room_key;
        //FcltMgr.openDetail(url, L("Extra cleaning"));
        FcltMgr.openDetail(url, "Extra cleaning");
      }
    </script>
  </head>

  <body  class="tabpage">
<%
    // akzaspecifiek
    if (floorKey != -1)
    {
      sql = " SELECT r.room_key"
          + "      , r.flr_key"
          + "      , r.bld_key"
          + "      , r.loc_key"
          + "      , r.alg_ruimte_aanduiding ruimtenr"
          + "      , r.alg_ruimte_bruto_vloeropp opp"
          + "      , COALESCE(fac.safe_to_number(nn.fac_usrdata_code),99) schoonmaakdoc"
          + "      , nn.fac_usrdata_omschr schoonmaakprog"
          + " FROM (SELECT alg_r.alg_ruimte_key room_key"
          + "            , alg_v.alg_verdieping_key flr_key"
          + "            , alg_g.alg_gebouw_key bld_key"
          + "            , alg_g.alg_locatie_key loc_key"
          + "            , alg_r.alg_ruimte_omschrijving alg_ruimte_omschrijving"
          + "            , alg_s.alg_srtruimte_omschrijving alg_srtruimte_omschrijving"
          + "            , alg_r.alg_ruimte_bruto_vloeropp alg_ruimte_bruto_vloeropp"
          + "            , alg_g.alg_gebouw_code || '-' || TO_CHAR(alg_v.alg_verdieping_code) || '-' || alg_r.alg_ruimte_nr alg_ruimte_aanduiding"
          + "         FROM alg_verdieping alg_v"
          + "            , alg_gebouw alg_g"
          + "            , alg_v_aanwezigruimte alg_r"
          + "            , alg_srtruimte alg_s"
          + "        WHERE alg_v.alg_verdieping_key = " + floorKey
          + "          AND alg_v.alg_gebouw_key = alg_g.alg_gebouw_key"
          + "          AND alg_v.alg_verdieping_key = alg_r.alg_verdieping_key"
          + "          AND alg_r.alg_srtruimte_key != 1241"   // 'Fictieve ruimte'
          + "          AND alg_r.alg_srtruimte_key = alg_s.alg_srtruimte_key(+)) r"
          + "    , (SELECT rr.alg_ruimte_key"
          + "            , ud.fac_usrdata_code"
          + "            , ud.fac_usrdata_omschr"
          + "         FROM alg_onrgoedkenmerk ok"
          + "            , (SELECT * FROM fac_usrdata WHERE fac_usrtab_key = 2301) ud"
          + "            , alg_v_aanwezigruimte rr"
          + "        WHERE ok.alg_kenmerk_key = 1020"     // 'Schoonmaakprogramma'
          + "          AND ok.alg_onrgoedkenmerk_waarde = TO_CHAR(ud.fac_usrdata_key)"
          + "          AND ok.alg_onrgoed_key = rr.alg_ruimte_key) nn"
          + " WHERE r.room_key = nn.alg_ruimte_key(+)"
          + (highlight_arr.length > 0 && highlight_arr.join(",").indexOf("-1") == -1
            ? " AND r.room_key IN (" + highlight_arr.join(",") + ")"
            : "")
          + " ORDER BY 1";
    }

    function refDoc(oRs)
    {
      if (oRs("schoonmaakdoc").value > 24)
      	return safe.html(oRs("schoonmaakprog").value);

    //var url = "http://portal.ah.intra/CouOpe/NL/AHLokFun/facser/Documents/programma%20" + oRs("schoonmaakdoc").value + "%20MSD%20AH%20,%20Labschool.xls";
    //var url = "http://portal.ah.intra/CouOpe/NL/AHLokFun/facser/Sch/Documents/Schoonmaakprogramma%27s/Programma" + oRs("schoonmaakdoc").value + ".xls";
      var url = "http://one.merck.com/pub/org/ah/CouOpe/NL/AHLokFun/facser/Sch/Documents/Schoonmaakprogramma%27s/Programma" + oRs("schoonmaakdoc").value + ".xls";
      return "<a href='" + safe.htmlattr(url) + "' target='_blank'>" + safe.html(oRs("schoonmaakprog").value) + "</a>";
    }

    function refMld(oRs)
    {
      return safe.htmlattr(oRs("schoonmaakprog").value) == null? "" :  "<a href='" + 'javascript:gotoMelding("' + oRs("room_key").value + '","' + oRs("flr_key").value + '","' + oRs("bld_key").value + '","' + oRs("loc_key").value + '")' + "'>"+oRs("room_key").value+"</a>";
    //return safe.htmlattr(oRs("schoonmaakprog").value) == null? "" :  "<a href='" + 'javascript:gotoMelding("' + safe.htmlattr(oRs("room_key").value) + '")' + "'>Extra cleaning</a>";
    }

    var rst = new ResultsetTable({ sql: sql,
                                   ID : "cadschtable",
                                   keyColumn: "room_key",
                                   title: L("lcl_cleaning_h"),
                                   outputmode: outputmode,
                                   showAll: showall
                                 });

    rst.addColumn(new Column({caption: L("lcl_obj_inf_room"), content: "ruimtenr"}));
    rst.addColumn(new Column({caption: L("lcl_opp"), content: "opp", datatype: "float"}));
    //rst.addColumn(new Column({caption: L("lcl_cleaning_h"), content: "schoonmaakprog"}));
    rst.addColumn(new Column({caption: L("lcl_cleaning_h"), content: refDoc}));
    //rst.addColumn(new Column({caption: "Request", content: refMld}));

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