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

    File:               prj_edit_scenario.asp
    Description:        Muteerscherm voor verhuisscenario's
    Parameters:
      prj_key           Scenario key (REQUIRED)
      verynew           optional
    Context:
    Note:               Submit naar prj_edit_scenario_save.asp
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="prj.inc" -->

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

/***** Get webform parameters *****/
var prj_key = getQParamInt("prj_key", -1);
/***** End get webform parameters *****/

var autfunction = "WEB_PRJBOF";
var authparams = user.checkAutorisation(autfunction);

if (prj_key > 0)
{ // Bestaand verhuisscenario
  sql = "SELECT s.prj_scenario_omschrijving"
      + ", s.mld_melding_key"
      + ", prj_scenario_datum"
      + ", s.prj_scenario_status"
      + ", s.prj_scenario_raming"
      + ", s.prj_scenario_opmerking"
      + ", " + S("prs_pers_string") + " naam"
      + ", s.prj_scenario_aanmaak"
      + ", s.prs_perslid_key"
      + ", rx.alg_verdieping_key"
      + " FROM prj_scenario s"
      + ", prs_perslid p"
      + ", mld_melding m"
      + ", mld_stdmelding stdm"
      + ", prj_ruimte rx"
      + " WHERE s.prs_perslid_key = p.prs_perslid_key(+)"
      + " AND s.mld_melding_key = m.mld_melding_key(+)"
      + " AND m.mld_stdmelding_key = stdm.mld_stdmelding_key(+)"
      + " AND s.prj_scenario_key = rx.prj_scenario_key(+)"
      + " AND s.prj_scenario_key = " + prj_key;
  oRs = Oracle.Execute(sql);
  if (!oRs.eof)
  {
    prj_omschr = oRs("prj_scenario_omschrijving").value;
    mld_key = oRs("mld_melding_key").value;
    if (!mld_key) mld_key = -1;
    //prj_verhuisaanvraag = oRs("verhuisaanvraag").value;
    prj_datum = new Date(oRs("prj_scenario_datum").value);
    prj_status = oRs("prj_scenario_status").value;
    prj_raming = oRs("prj_scenario_raming").value;
    prj_opm = oRs("prj_scenario_opmerking").value;
    prj_name = oRs("naam").value;
    prj_aanmaak = oRs("prj_scenario_aanmaak").value;
    prj_perslidkey = oRs("prs_perslid_key").value;
    prj_verdieping = oRs("alg_verdieping_key").value;
    if (!prj_verdieping) prj_verdieping = -1;
  }
}
else
{ // Nieuw verhuisscenario
  prj_omschr = "";
  mld_key = -1;
  //prj_verhuisaanvraag = oRs("verhuisaanvraag").value;
  prj_datum = new Date();
  prj_status = "";
  prj_raming = 0;
  prj_opm = "";
  prj_name = user.naam();
  prj_aanmaak = new Date();
  prj_perslidkey = user_key;
  prj_verdieping = -1;
  if (!prj_verdieping) prj_verdieping = -1;
}
%>

<html>
  <head>
    <% FCLTHeader.Generate(); %>

    <script  type="text/javascript">
      $(function()
      {
        $('textarea').resize(function () { FcltMgr.resized(window) });
        $('textarea').autogrow();
      });
    </script>
  </head>

  <body class="editmode">
<%
SUBFRAME_START();
    var buttons = [ {title: L("lcl_submit"), icon: "fa-fclt-save", action: "mld_submit()"},
                    {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "mld_cancel()"}
                  ];
    IFRAMER_HEADER(L("lcl_prj_frame_algemeen"), buttons);
%>
      <form name="u2" method="post" action="prj_edit_scenario_save.asp?prj_key=<%=prj_key%>">
<%
        BLOCK_START("prjInfo", L("lcl_prj_scenario") + (prj_key > 0? " " + prj_key : ""), {icon: "fa-ruler-triangle"});
        %><input type="hidden" id="prj_key" name="prj_key" value="<%=prj_key%>">
        <input type="hidden" id="prj_perslidkey" name="prj_perslidkey" value="<%=prj_perslidkey%>"><%
        RWFIELDTR("prj_omschr", "fld", L("lcl_descr"), prj_omschr, {maxlength: 30, required: true});
        FCLTcalendar("prjdate",
                     { datum: prj_datum,
                       label : L("lcl_prj_geplande_aanvang"),
                       initEmpty: prj_key<0
                     });

        sql = "SELECT mld_melding_key"
            + ", m.mld_melding_key || '-' || "+lcl.xsqla('stdm.mld_stdmelding_omschrijving','stdm.mld_stdmelding_key')
            + " FROM mld_melding m"
            + ", mld_stdmelding stdm"
            + " WHERE stdm.mld_stdmelding_key = m.mld_stdmelding_key"
            + ((authparams.ALGreadlevel > -1)
              ? " AND mld_alg_locatie_key IN"
                + " (SELECT alg_locatie_key"
                + " FROM fac_v_my_locations"
                + " WHERE prs_perslid_key = " + user_key
                + " AND niveau = " + authparams.ALGreadlevel + ")"
              : "")
            + " AND stdm.mld_ins_discipline_key = " + S("prj_discipline_key")
            + " AND (m.mld_melding_status IN (4,7) OR mld_melding_key = " + mld_key + ")"
            + " ORDER BY 1";

        FCLTselector("mld_key",
                     sql,
                     { initKey: mld_key,
                       label: L("lcl_prj_verhuisaanvraag"),
                       trclass:"primsearch",
                       emptyOption: "",
                       initEmpty: true
                     });

        RWFIELDTR("prj_status", "fld", L("lcl_status"), prj_status, { maxlength: 30 });
        RWTEXTAREATR("prj_opm",
                     "fldtxt",
                     L("lcl_remark"),
                     prj_opm,
                     {html: "rows='3'", maxlength: 2000});
        BLOCK_END();

        BLOCK_START("prjKosten", L("lcl_prj_kosten"), {icon: "fa-euro-sign"});
%>      <!-- Geraamde kosten -->
<%      RWFIELDTR("prj_raming", "fld", L("lcl_prj_cost"), prj_raming, { maxlength: 10, datatype: "currency" });
        BLOCK_END();

IFACE.FORM_END();
%>
      </form>
<% SUBFRAME_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %> 
