<% /*
     $Revision$
     $Id$

     File:    fac/header.asp
     Context: iframe vanuit appl/fac/Facilitor.asp

*/
%>
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/productsearch.inc" -->
<%
FCLTHeader.Requires({ plugins: [], js: [] });

// Kijk in welke omgeving we volgens de database zitten,
// en toon dat prominent als dat niet de productie is.
var sql = "SELECT COALESCE(fac_version_otap, 'P') otap, "
        + "       fac.getdbversion() dbversion,"
        + "       fac_version_cust, "
        + "       fac_version_schema "
        + "  FROM fac_version";
var oRs = Oracle.Execute(sql);
// Dit kan onduidelijke problemen geven met putorders en genexport. Controleer daar hier op.
if (!oRs("fac_version_cust").Value)
    abort_with_warning("fac_version_cust is niet gezet in de database. Doe dat eerst.");

var otap = oRs("otap").value;
if (otap == "P") otap = "";
var dbversion = oRs("dbversion").value;
var schemaversion = oRs("fac_version_schema").Value;
var facilitorversion = FCLTVersion + "@" + dbversion;
oRs.Close();

function todayString() {
    var d=new Date()

    return calendar_names.days[d.getDay()] + "&nbsp;" + d.getDate() + "&nbsp;"
            + calendar_names.months[d.getMonth()] + "&nbsp;" + d.getFullYear();
}

function generateHeader()
{
%>
<script type="text/javascript">
    function setGlobalUser (prs_key, prs_naam) {
        FcltMgr.setCaller({prs_key: prs_key, prs_naam: prs_naam});
    }
</script>

<div id="headerblok" style='height:100%'>
<%
    if (Session("org_user_key") > 0)
    {
        var other_key = parseInt(Session("org_user_key"), 10);
        var other = new Perslid(other_key);
        Response.Write("<div id='userimperson'>" + L("lcl_impersonate_active").format(other.naam() + "</div>"));
    }
    else
        Response.Write("<div id='headerprefix'>" + otap+" "+L("lcl_facilitor_header_prefix") + "</div>");
%>
 <div id="headerdate" title="<%=L("lcl_facilitor_appl")+' '+facilitorversion%>"><%=todayString()%></div>

<%
  if (user_key != -1) {
    if (parseInt(schemaversion,10) < parseInt(FCLTMinDatabaseSchema,10))
    {
        if (user.checkAutorisation("WEB_FACTAB", true))
            Response.Write("<div id='badschema' title='"+Oracle.RealConnection.Properties("User Name")+'@'+Oracle.RealConnection.Properties("Data source")+"'>BAD SCHEMA. Need DB"+FCLTMinDatabaseSchema+" have DB"+schemaversion+"</div>");
        // else: gewone users niet direct lastigvallen.
        //       tijdens een (nieuw ingrijpende) hot-upgrade staan we het gewoon eventjes toe.
    }
    %><div id="headersuggest"><%
      // Suggest om een persoon te vinden. Gebruikt de scope van de telefoongids
      var authparams = user.checkAutorisation("WEB_PHSRCH", true);
      if (authparams && authparams.PRSreadlevel < 9) {
          FCLTpersoonselector("sName_key", "sgPerson", { perslidKey: -1,
                moreinfo: true,
                no_table: true,
                filtercode: "PHB",
                whenEmpty: L("lcl_select_persoon_generic"),
                onChange: "setGlobalUser",
                autlevel: authparams.PRSreadlevel
              });
      } else {
        // spacer
        %><div class="hsspacer">&nbsp;</div><%
      }
%>
</div>
 <div id="headersearch">
<%
   FCLTproductsearch ();
%>
</div>
<% generateHeaderFunctions();
}
   %></div>
   <%
}
function generateHeaderFunctions (params)
{
    %>
  <script type="text/javascript">
    function openHelp()
    {
        if (FcltMgr._pageManager.name == "tabbedManager")
            var src = FcltMgr._pageManager._activeTab().src;
        else
            src = window.location.href;

        var url = 'appl/fac/help.asp?url='+escape(src);
        if (<%=S("help_window")?"false":"true"%>)
            FcltMgr.openDetail(url,'<%=L("lcl_help")%>');
        else
            var newWindow = window.open('../../'+url);
    }

    function myInfo()
    {
        FcltMgr.openDetail('appl/fac/fac_user_info.asp?');
    }

    function toMobile()
    {
          parent.location.href="../../default.asp?pda=1";
    }

    function logOffCallback(json, textStatus)
    {
        parent.location.href="<%=S("logoff_return_url")%>";
    };

    function logOff()
    {
      var data = {};
      <% protectRequest.dataToken("data"); %>
      $.post("../shared/LogOff.asp",
             data,
             FcltCallbackAndThen(logOffCallback),
             "json");
    }

    function changeLanguage(lang)
    {
      var data = {};
      <% protectRequest.dataToken("data"); %>
      $.post("./set_language.asp?lang="+lang,
             data,
             FcltCallbackRefresh,
             "json");
    }
  </script>
  <div id="headerfunctions"><%
    if (user_key != -1) {
        %><div id="loggedinuser"><%=L("lcl_loggedin_as") + '<span onclick="myInfo()">'+ safe.html(user.naam())+'</span>' + (user.alg_locatie_key({withcurrent:true})>-1 ? L("lcl_mobile_currentpos")+(new Locatie(user.alg_locatie_key({withcurrent:true})).locatie_string()) : "") %></div><%
    }
    if (S("language_toggles").length > 1)
    {
    %><div id="langtoggle"><%
       for (lang in S("language_toggles"))
       {
         var desc = lcl.languages[lang];
         var code = S("language_toggles")[lang];
       %><img style="cursor:pointer; height:12px" onClick="changeLanguage('<%=code%>');" title="<%=desc%>" src=../pictures/<%=code%>.png>&nbsp;
    <%  } %>
      </div><%
    }
    if (params && params.touch && S("mobile_enabled") == 1)  // we voorkomen nu nog dat je via desktop naar Mobile gaat; touch-only
    {
        %><div id="touch2mobile" onclick="toMobile()"><% = L("lcl_mobile_mobilemode") %></div> |<%
    }
    if (S("helppage_url") != "") {
        %><div id="headerhelp" onclick="openHelp()"><% = L("lcl_help") %></div> |<%
    }
    %><div id="headerlogout" onclick="logOff()"><% = L("lcl_logoff") %></div></div><%
  }
%>