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

    File:               job.asp
    Description:
    Parameters:
    Context:
    Note:

*/ %>

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

<%
FCLTHeader.Requires({ plugins: ["suggest", "jQuery"],
                      js: ["jquery-ui.js"]
                    });

var job_key = getQParamInt("job_key", -1);
var urole = getQParamSafe("urole", "bo"); //TODO?

autfunction = "WEB_MLDBOF";
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);

autfunction = "WEB_MLDFOF";
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);

autfunction = "WEB_BESFOF";
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))
{
  Response.Write(L("lcl_no_auth"));
  Response.End();
}
%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script  type="text/javascript" >
      FcltMgr.setTitle("");

      function jobClose(params)
      {
          if (params.redirect)
          {
              window.location.href = params.redirect;
              return true;
          }
          <% if (job_key ==-1) { %>
              if (params.cancel)
              {
                  FcltMgr.closeDetail(window, params );
                  return true;
              }
              if (!params.keepForm) {
              FcltMgr.setTitle("", {hot:false});
              //TODO het feitelijke aanmaken van de bijbehorende bestelling/melding of opdracht moet nog goed gemaakt worden iets voor JGL?
              alert("Actienr " + params.job_key + " is aangemaakt");
              if (params.rtable == "1")
                window.location.href = "../bes/bes_bestelling.asp?urole=fo&act_key="+params.job_key;
              if (params.rtable == "2")
                window.location.href = "../mld/mld_melding.asp?urole=fo&act_key="+params.job_key;
              if (params.rtable == "3")
                window.location.href = "../mld/mld_opdr.asp?urole=bo&mld_key="+params.mkey+"&act_key="+params.job_key;
              }
          <% } else { %>
              if (params.close)
              {
                FcltMgr.closeDetail(window, {close: true})
              }
              if (!params.keepForm && !params.deleted)
                  $("#jobFrame")[0].src = "job_show_job.asp?job_key=<%=job_key%>";
          <% } %>
      }

    </script>
  </head>

  <body>
<%
    if (job_key == -1)
    {
      var page="job_edit_job.asp"; // Maak een nieuw

      //Dan maar vragen
      var buttons = [];

      buttons.push({ title: L("lcl_bes_bestelling"),
                     action: "rtable=1;$('div#dmodal').dialog('close').remove();",
                     showText: false
                   });
      buttons.push({ title: L("lcl_complain"),
                     action: "rtable=2;$('div#dmodal').dialog('close').remove();",
                     showText: false
                   });
      buttons.push({ title: L("lcl_bes_orders"),
                     action: "rtable=3;$('div#dmodal').dialog('close').remove();",
                     showText: false
                   });

        var page="../shared/empty.html";
%>      <script type='text/javascript'>
          rtable = -1;
          function dialogClose()
          {
            if (rtable== -1)
              FcltMgr.closeDetail(window, { cancel: true } );
            else
              $("#jobFrame")[0].src = "job_edit_job.asp?job_key=<%=job_key%>&rtable="+rtable;
          }
          $(document).ready(function()
                            {
                              var params = { title: "<%=L("lcl_job_frame_algemeen")%>",
                                             modal: true,
                                             width : 180,
                                             resizable : false,
                                             close : dialogClose
                                           };
                              FcltMgr.fixActiveelementError();
                              $('div#dmodal').dialog(params).dialog('open');
                            });
        </script>
        <div id="dmodal" style="display:none">
<%        if (buttons.length)
            CreateButtons(buttons, { vertical: 1, isDialog: true} )
          else
            Response.write(L("lcl_mld_choose_na")); %>
        </div>
<%
    }
    else
    {
      var page="job_show_job.asp";
    }
    // 1. Het hoofdframe
    page += "?job_key="+job_key;
    IFRAMER("jobFrame", page, { initHeight: "450px",
                                FcltClose: "jobClose"  } );
%>
  </body>
</html>
