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

    File:        pda/cnt_list.asp
    Description: Toont de actuele contractenlijst voor op de pda.
                 Dat zijn contracten met scopen, contracten zonder scope en de aan mij toegekende (beheerder of contact) contracten.
                 Nu met volledige autorisatie/scope.

    Parameters:  -
    Context:     -

    Note:        -
*/
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/discx3d.inc" -->
<!-- #include file="../Shared/getkenmerksql.inc" -->
<!-- #include file="../cnt/cnt.inc" -->
<!-- #include file="./resultset_table.inc" -->
<!-- #include file="./mobile.inc" -->
<!-- #include file="./iface.inc" -->

<%
var grp_sel = getQParamUTF8("grp_sel", "");
var qrc = getQParamInt("qrc", 0) != 0;
var subject = L("lcl_mobile_contracten");
var mantel_key = getQParamInt("mantel_key", -1);

var loc_key = getQParamInt("loc_key", -1);
var geb_key = getQParamInt("geb_key", -1);
var ver_key = getQParamInt("ver_key", -1);
var rui_key = getQParamInt("rui_key", -1);
var cntnum = getQParam("cntnum", ""); // Contractnummer (zoekveld, unsafe)

var cntFFut = getQParamSafe("cntFFut", "off") == "on"; // Fase toekomstig binnen status actief
var cntFAct = getQParamSafe("cntFAct", "off") == "on"; // Fase actueel binnen status actief
var cntFRap = getQParamSafe("cntFRap", "off") == "on"; // Fase rappel binnen status actief
var cntFOpz = getQParamSafe("cntFOpz", "off") == "on"; // Fase in opzegtermijn binnen status actief
var cntFVerl = getQParamSafe("cntFVerl", "off") == "on"; // Fase verlopen binnen status actief

var cntAct = 1; // standard checked
if (!cntFFut && !cntFAct && !cntFRap && !cntFOpz)
{
  cntFFut = true; // standard checked
  cntFAct = true; // standard checked
  cntFRap = true; // standard checked
  cntFOpz = true; // standard checked
}

var transitParam = buildTransitParam(["mantel_key", "loc_key", "geb_key", "ver_key", "rui_key", "cntAct", "cntFFut", "cntFAct", "cntFRap", "cntFOpz", "cntFVerl", "cntnum", "grp_sel"]);

var urole  = getQParamSafe("urole", "bo");
var autfunction = (urole == "fe" ? "WEB_CNTUSE" : "WEB_CNTMAN");

%>
<html>
  <head>
<%  FCLTMHeader.Generate({}); %>
  </head>

  <body>
<%
    function fncolLink(oRs)
    {
      var url = "";
      if (grp_sel == "" && cntnum == "")
        url = "../pda/cnt_list.asp?grp_sel=" + safe.urlUTF8(oRs("ins_discipline_omschrijving").Value) + transitParam;
      else
        url = "../pda/contract.asp?cnt_key=" + oRs("cnt_contract_key").Value;
      return url;
    };

    function fnHeader (oRs)
    {
      return oRs("cnt_contract_nummer_intern").value + (oRs("cnt_contract_versie").value == null? "" : "." + oRs("cnt_contract_versie").value);
    }

    function fnBedrag (oRs)
    {
      return oRs("cnt_contract_kosten").value? S("currency_pref") + safe.curr(oRs("cnt_contract_kosten").value) : "";
    }

    function fncolSubHeader(oRs)
    {
      return  "<div class='listbodykop'>" + toDateString(oRs("begindatum").value, true) + " " + L("lcl_tot") + " " + toDateString(oRs("einddatum").value, true) +"</div>"
              + (oRs("cnt_contract_omschrijving").Value? "<div class='listbodytext'>" +safe.html(shorttxt(oRs("cnt_contract_omschrijving").Value, S("rs_mobile_maxchar")))+"</div>":"");
    };

    function fnEinddatum (oRs)
    {
      return toDateString(oRs("einddatum").value, false);
    }

    var params = {urole: urole,
                  grp_sel: grp_sel,
                  cntAct:  cntAct,   // Alleen actieve contracten tonen.
                  cntFFutu: cntFFut,  // Toekomstige contracten tonen.
                  cntFAct: cntFAct,  // Actuele contracten tonen.
                  cntFRap: cntFRap,  // Contracten in rappel tonen.
                  cntFOpz: cntFOpz,  // Contracten in opzegtermijn tonen.
                  cntFVerl: cntFVerl,  // Contracten in opzegtermijn tonen.
                  cntnum: cntnum,      // Contractnummer (zoekveld, unsafe)
                  mobile: 1         // Mobile lijst.
                 };
    if (mantel_key > 0)
         params.mantel_key = mantel_key;
    if (loc_key > 0)
         params.loc_key_arr = [loc_key];
    if (geb_key > 0)
         params.bld_key_arr = [geb_key];
    if (ver_key > 0)
         params.flr_key_arr = [ver_key];
    if (rui_key > 0)
         params.room_key_arr = [rui_key];

    var bewaarParams = params;
    params = params.cntnum != "" ? {urole: urole, grp_sel: "", cntnum: getQParam("cntnum", ""), mobile: 1} : params;
    var sql = cnt.getfromwherelist_sql(autfunction, params);
    params = bewaarParams;

    PAGE_START();
    HEADER({title: subject, back:!qrc});
%>
  <script>
    function cnt_filter()
    {
        document.forms.cnt_filter_list.submit();
    }

    function cnt_home()
    {
        window.location.href = rooturl + "/appl/pda/Facilitor.asp";
    }
  </script>

<%  FILTER_PANEL_START(); %>

        <form name="u2" id="cnt_filter_list" action="<%=rooturl%>/appl/pda/cnt_list.asp" method="get">
            <input type="hidden" name="urole" id="urole" value="<%=urole%>">
            <input type="hidden" name="cntAct" id="cntAct" value="<%=params.cntAct%>">
<%
        CONTROLGROUP_START();
          CHB_FIELD("cntFFut", L("lcl_cnt_future"), params.cntFFutu);
          CHB_FIELD("cntFAct", L("lcl_cnt_topical"), params.cntFAct);
          CHB_FIELD("cntFRap", L("lcl_cnt_warn"), params.cntFRap);
          CHB_FIELD("cntFOpz", L("lcl_cnt_cancel"), params.cntFOpz);
          CHB_FIELD("cntFVerl", L("lcl_cnt_past"), params.cntFVerl);
        CONTROLGROUP_END();

        CONTROLGROUP_START();
          RWFIELD("cntnum", L("lcl_cnt_intern_nr"), cntnum);
        CONTROLGROUP_END();

        CONTROLGROUP_START();
            BUTTON(L("lcl_mobile_panel_filter"), { id: "search_submit", click: "cnt_filter()", icon: "fa-fclt-refresh" });
        CONTROLGROUP_END();
%>
        </form>
<%  FILTER_PANEL_END();

    HEADER({
        title: subject,
        back: false,
        filterPanel: true
    });
    CONTENT_START();

    var rst = new ResultsetTable({sql: sql,
                                   keyColumn: "cnt_contract_key",
                                   detailColumn: "uitvoerder",
                                   headerColumn: fnHeader,
                                   asideColumn: fnBedrag,
                                   subheaderColumn: fncolSubHeader,
                                   groupColumn: "ins_discipline_omschrijving",
                                   groupSelect: cntnum == "" ? grp_sel : null,
                                   linkColumn: fncolLink,
                                   ID: "cnttable",
                                   showAll: true
                                  });

    var cnt = rst.processResultset();

    CONTENT_END();
    FOOTER();
    PAGE_END();
PDA_PAGE_END(); %>
	</body>
</html>
<% ASPPAGE_END(); %>
