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

     File:               bes_levopm.asp
     Status:             50%
     Description:        Opens a supplier specific page(URL) in a modal window to support
                         off the record communication between requester, backoffice and supplier
                         e.g. with a Damo-like platform
     Parameters:
         bes_key         bes_bestelling_key.
     Context:            Called from sel_items_tab.js (from bes details screen)
     Note:               This function is only provided if bes_disc_params.bes_disc_params_levopm_url is not null
                         Parameters that can be given to the url are
                         *           all fixed parameters like logboekdb and user (a key for the anonymous
                                     user on that platform) should be defined in
                                     bes_disc_params.bes_disc_params_levopm_url for a discipline (catalog/supplier).
                         email       email address of the user OR
                         client_code the 'name' of bes_key, i.e. prefix + bes_key

*/ %>

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

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

var bes_key = getFParamInt("bes_key", -1);
var disc_key = -1;
var levopm = "";
var email = "";

//var autfunction = "WEB_BESBOF";
// De functie checkAutorisation(autfunction) geeft een Response.End indien er geen autorisatie voor autfunction wordt gevonden
//var authparams = user.checkAutorisation(autfunction);

// Welke discipline? Kunnen er in uitzonderingsgevallen meer als één zijn. Neem dan de nieuwste voor de veiligheid.
var sql = "SELECT MAX (isg.ins_discipline_key)"
        + "  FROM bes_bestelling b"
        + "     , bes_bestelling_item bi"
        + "     , bes_srtdeel isd"
        + "     , bes_srtgroep isg"
        + " WHERE b.bes_bestelling_key = bi.bes_bestelling_key"
        + "   AND bi.bes_srtdeel_key = isd.bes_srtdeel_key"
        + "   AND isd.bes_srtgroep_key = isg.bes_srtgroep_key"
        + "   AND b.bes_bestelling_key = " + bes_key;
oRs = Oracle.Execute(sql);
if (!oRs.eof)
{
  disc_key = oRs(0).value;
}

// Welke url is gerelateerd aan deze discipline?
sql = "SELECT bdp.bes_disc_params_levopm_url"
    + "  FROM bes_disc_params bdp"
    + " WHERE bdp.bes_ins_discipline_key = " + disc_key;
oRs = Oracle.Execute(sql);
if (!oRs.eof)
{
  levopm_url = "" + oRs(0).value;
}
oRs.close();

if (levopm_url != "")
{
  // Wat is het email adres van de aanvrager?
  sql = "SELECT p.prs_perslid_email"
      + "  FROM bes_bestelling b, prs_perslid p"
      + " WHERE p.prs_perslid_key = b.prs_perslid_key"
      + "   AND bes_bestelling_key = " + bes_key;
  oRs = Oracle.Execute(sql);
  if (!oRs.eof) {
      email = "" + oRs(0).value;
  }
  // Als het email adres van de aanvrager onbekend is, gebruik die van de user.
  if (email == "")
  {
    sql = "SELECT p.prs_perslid_email"
        + "  FROM prs_perslid p "
        + " WHERE p.prs_perslid_key = " + user_key;
    oRs = Oracle.Execute(sql);
    if (!oRs.eof)
    {
      email = "" + oRs(0).value;
    }
  }
  oRs.close();
}
levopm_url = levopm_url + "&email=" + email;
levopm_url = levopm_url + "&client_code=" + S("bes_bestelling_prefix") + bes_key;
%>

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

    <script language=JavaScript>
      levopm_url = "<%=levopm_url%>";

      function loaded()
      {
        // Open een nieuwe tab met de levopm_url
        FcltMgr.openDetail(levopm_url, L("lcl_communicatie"));
      }
    </script>
  </head>

  <body id="info" topmargin='0' onLoad="loaded()">
  </body>
</html>
