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

    File:           job_show_job.asp
    Description:    show detailed information of an object

    Parameters:     job_key

    Context:
    Note:

*/ %>
<!-- #include file="../Shared/common.inc"-->
<!-- #include file="../Shared/iface.inc"-->
<!-- #include file="../Shared/persoonselector.inc" -->

<%
var job_key = getQParamInt("job_key");

FCLTHeader.Requires({plugins:["jQuery"], js: []})

  authparams = user.checkAutorisation("WEB_MLDBOF", true);

  var MLDBOF_read  = authparams && (authparams.PRSreadlevel < 9 || authparams.ALGreadlevel < 9);
  var MLDBOF_write = authparams && (authparams.PRSwritelevel < 9 || authparams.ALGwritelevel < 9);

  authparams = user.checkAutorisation("WEB_MLDFOF", true);

  var MLDFOF_read  = authparams && (authparams.PRSreadlevel < 9 || authparams.ALGreadlevel < 9);
  var MLDFOF_write = authparams && (authparams.PRSwritelevel < 9 || authparams.ALGwritelevel < 9);

  authparams = user.checkAutorisation("WEB_BESFOF", true);

  var BESFOF_read  = authparams && (authparams.PRSreadlevel < 9 || authparams.ALGreadlevel < 9);
  var BESFOF_write = authparams && (authparams.PRSwritelevel < 9 || authparams.ALGwritelevel < 9);

if (!(MLDFOF_read || MLDFOF_write || BESFOF_read || BESFOF_write || MLDBOF_read || MLDBOF_write)) {
  shared.simpel_page(L("lcl_no_auth"));
}

var rkey      = -1;

var sql = "SELECT "
        + "       act.fac_activiteit_interval/24 interval"
        + "     , act.fac_activiteit_aantal "
        + "     , act.prs_perslid_key "
        + "     , fac_activiteit_eerste "
        + "     , fac_activiteit_einddatum "
        + "     , act.fac_activiteit_status_key "
        + "     , pf.prs_perslid_naam_full naam "
        + "     , fac_activiteit_laatste "
        + "     , fac_activiteit_omschrijving "
        + "     , fac_activiteit_xmlnode "
        + "  FROM fac_activiteit act, prs_v_perslid_fullnames_all pf "
        + " WHERE  act.prs_perslid_key = pf.prs_perslid_key "
        + "   AND  fac_activiteit_key = "+job_key;

var oRs = Oracle.Execute(sql);

      interval  = oRs("interval").value;
      aantal    = oRs("fac_activiteit_aantal").value;
      person    = oRs("prs_perslid_key").value;
      firstdate = oRs("fac_activiteit_eerste").value;
      enddate   = oRs("fac_activiteit_einddatum").value;
      status    = oRs("fac_activiteit_status_key").value;
      naam      = oRs("naam").value;
      lastdate  = oRs("fac_activiteit_laatste").value;
      act_descr = oRs("fac_activiteit_omschrijving").value;
      xmlnode   = oRs("fac_activiteit_xmlnode").value;

oRs.Close();

if (xmlnode == "bestelling")
{
  sql2 ="SELECT bes_bestelling_key "
       + "  FROM bes_bestelling "
       + " WHERE fac_activiteit_key = "+ job_key;

  oRs2 = Oracle.Execute (sql2);
  if (!oRs2.eof)
    rkey = oRs2("bes_bestelling_key").value;
  oRs2.Close();
}

if (xmlnode == "melding")
{
  sql2 = "SELECT mld_melding_key "
       + "  FROM mld_melding "
       + " WHERE fac_activiteit_key = " + job_key;

  oRs2 = Oracle.Execute (sql2);
  if (!oRs2.eof)
    rkey = oRs2("mld_melding_key").value;
  oRs2.Close();
}

if (xmlnode == "opdracht")
{
  sql2 = "SELECT mld_opdr_key "
       + "  FROM mld_opdr "
       + " WHERE fac_activiteit_key = "+ job_key;

  oRs2 = Oracle.Execute (sql2);
  if (!oRs2.eof)
    rkey = oRs2("mld_opdr_key").value;
  oRs2.Close();
}
      if (interval == 0) {
        interval = '1';
      }

      var actiontxt = "";
      // 1-malig
      if ((aantal == 1) && (firstdate != '')) {
        action = 1;
        actiontxt = L("lcl_job_action_1");
      } else
        {
        if ((aantal == '' || aantal == null) ) {
          action = 2;
          actiontxt = L("lcl_job_action_2");
        } else {
          if (aantal != '' && aantal != null) {
              // Aantal keer
              action = 3;
              actiontxt = L("lcl_job_action_3");
          }
        }
      }
%>

<html>
<head>
<%
   FCLTHeader.Generate();
%>
<script type="text/javascript">

    function job_change()
    {
      if (FcltMgr.startEdit(window))
        window.location.href = "job_edit_job.asp?job_key=<%=job_key%>";
    }
    function job_delete()
    {
        if (confirm(L("lcl_job_del_txt_job")))
        {
          var data = { key: <%=job_key%>,
                       level: "J"
                     };
          <% protectRequest.dataToken("data"); %>
          $.post("job_delete.asp",
                 data,
                 FcltCallbackClose,
                 "json");
        }
    }
    function job_bes()
    {
      FcltMgr.openDetail("appl/bes/bes_bestelling.asp?urole=bo&bes_key=<%=rkey%>", L("lcl_bes_bestelling"));
    }
    function job_complain()
    {
      FcltMgr.openDetail("appl/mld/mld_melding.asp?urole=bo&mld_key=<%=rkey%>", L("lcl_complain"));
    }
    function job_order()
    {
      FcltMgr.openDetail("appl/mld/mld_opdr.asp?urole=bo&opdr_key=<%=rkey%>", L("lcl_job_order"));
    }
</script>

</head>

<body id="showbody">
<%
var buttons = [];
var canEdit = false;
var job_attached_txt = L("lcl_undefined");

    if (xmlnode == "bestelling") {
      job_attached_txt = L("lcl_bes_bestelling");
      if (BESFOF_write)
        canEdit = true;
    }
    if (xmlnode == "melding") {
      job_attached_txt = L("lcl_complain");
      if (MLDFOF_write)
        canEdit = true;
    }
    if (xmlnode == "opdracht") {
      job_attached_txt = L("lcl_job_order");
      if (MLDBOF_write)
        canEdit = true;
    }


if (canEdit)
{
  var buttons =  [ {title: L("lcl_change"), action: "job_change()", icon: "wijzigen.png" },
                   {title: L("lcl_delete"), action: "job_delete()", icon: "delete.png" }
                 ];
}
if (rkey > 0) {
  if (xmlnode == "bestelling") {
    buttons.push( {title: L("lcl_bes_bestelling"), icon: "bes_order.png", action: "job_bes()"});
  }
  if (xmlnode == "melding") {
     buttons.push( {title: L("lcl_complain"), icon: "mld_order.png", action: "job_complain()"});
  }
  if (xmlnode == "opdracht") {
    buttons.push( {title: L("lcl_job_order"), icon: "mld_order.png", action: "job_order()"});
  }
}



IFRAMER_HEADER(L("lcl_job_frame_algemeen"), buttons);
%>
 <div id="show">
  <form name="u2">
<%
BLOCK_START("jobJob", L("lcl_job_algemeen"));
  ROFIELDTR("fldshort", L("lcl_job_nr"), job_key);
  ROFIELDTR("fld",
            L("lcl_descr"),
            act_descr,
            { suppressEmpty: true,
              translate: { fld: "fac_activiteit_omschrijving", key : job_key }}
           );
  var stat_txt = ""
  switch(status)
        {
          case 1:
            stat_txt = L("lcl_job_stat_1_inactief");
            break;
          case 2:
            stat_txt = L("lcl_job_stat_2_actief");
            break;
          case 3:
            stat_txt = L("lcl_job_stat_3_1xoverslaan");
            break;
        }

  ROFIELDTR("fld", L("lcl_job_status"), stat_txt);

            FCLTpersoonselector(
                        "Person",
                        "sgPerson",
                      { perslidKey: person,
                        label: L("lcl_requestor"),
                        fieldNameKey: "person",
                        filtercode: "M",
                        readonly: true
                      });
  ROFIELDTR("fld", L("lcl_job_action"), actiontxt, {suppressEmpty: true});
  ROFIELDTR("fld", L("lcl_job_firstdate"), toDateTimeString(firstdate));
  ROFIELDTR("fldshort", L("lcl_job_period"), interval);
  ROFIELDTR("fld", L("lcl_job_enddate"), toDateTimeString(enddate), {suppressEmpty: true});
  ROFIELDTR("fldshort", L("lcl_job_n_times"), aantal, {suppressEmpty: true});
  ROFIELDTR("fld", L("lcl_job_lastdate"), toDateTimeString(lastdate), {suppressEmpty: true});
BLOCK_END();
BLOCK_START("jobMld", L("lcl_job_att"));
if (rkey > 0 )
{
  ROFIELDTR("fld", L("lcl_job_type"), job_attached_txt);
  ROFIELDTR("fld", L("lcl_job_att_number"), rkey);
}
else
{
%>
<label><%=L("lcl_job_not_attached")%></label>
<%
}
BLOCK_END();
%>
</form>
</div>
</body>
</html>
