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

     File:    fac/fac_widgetspage.asp
              Container om widgets in een pagina te tonen
     Context:
*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="fac.inc" -->
<%
FCLTHeader.Requires({ plugins: ["jQuery"], js: ["jQuery-ui.js"]
                    });


var wdg_groep = getQParam("wgrp");

function createWidget(p_divid, p_title, p_height, p_width, p_url, p_refreshtime){
%><div class="widget" id="<%=p_divid%>" style="width:<%=p_width%>%;height:<%=p_height%>px;float:left">
       <div class="widgettitle"><%=p_title%></div>
       <iframe src="<%=p_url%>" id="<%=p_divid%>frame" name="<%=p_divid%>frame" refresher="<%=p_refreshtime%>"
           height="100%" width="100%" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"
           <%=(!p_height?'onload="FcltMgr.iframeLoaded(this)"':"")%>
           >
      </iframe>
   </div>
   <%if (p_refreshtime != -1 && p_refreshtime >= 60){
   %><script type='text/javascript'>
         setReloadTimer("<%=p_divid%>frame", "<%=safe.jsstring(p_url)%>", <%=p_refreshtime%>);
     </script><%
   }
}

   FCLTHeader.Generate();
%>
   <script type='text/javascript'>
        // FSN#22791 refresh als we in een inactief tab zitten is overbodig
        //           en (jqPlot) geeft errors
        var pendingReload = [];
        function fcltontabshow()
        {
            var t;
            for (t in pendingReload)
                pendingReload[t]();

            $("iframe").each(function ()
                {
                    if (this.getAttribute("refresher") > 0 && this.getAttribute("refresher") < 60)
                    {
                        this.src = this.src ;
                    }
                });
        }

         function doReload(pObject, pUrl, pTime) {
            if (FcltMgr.inInvisbleTab())
                pendingReload.push(function () { doReload(pObject, pUrl, pTime); });
            else
            {
                document.getElementById(pObject).src=pUrl;
                setReloadTimer(pObject, pUrl, pTime);
            }
         };

         function setReloadTimer(pObject, pUrl, pTime) {
            setTimeout('doReload("'+pObject+'", "'+pUrl+'", '+pTime+');', pTime*1000);
         }
   </script>

<% if (user_key != -1) {

    var sql =   "SELECT COALESCE(fac_widget_id, 'widget_' || to_char(fac_widget_key)) fac_widget_id,"
              + lcl.xsqla('fac_widget_title', 'fac_widget_key') + ","
              + "       fac_widget_url,"
              + "       fac_widget_height fac_widget_height,"
              + "       fac_widget_width fac_widget_width,"
              + "       fac_widget_refreshtime"
              + "  FROM fac_widget"
              + " WHERE fac_widget_groep = " + safe.quoted_sql(wdg_groep)
              + "   AND (fac_functie_key IS NULL"
              + "     OR fac_functie_key IN"
              + "             (SELECT fac_functie_key FROM fac_v_webgebruiker"
              + "               WHERE prs_perslid_key = " + user_key + "))"
              + " ORDER BY fac_widget_volgnr";
    oRs = Oracle.Execute(sql);
    while (!oRs.Eof)
    {
        l_divid = oRs("fac_widget_id").Value;
        l_url = oRs("fac_widget_url").Value;
        l_title = fac.localstring(oRs("fac_widget_title").value||"");
        l_height = oRs("fac_widget_height").Value;
        l_width = oRs("fac_widget_width").Value||100;
        l_refreshtime = oRs("fac_widget_refreshtime").Value||-1;

        l_url += (l_url.indexOf("?")>0?"&":"?")+"widget_height=" + l_height;
        createWidget(l_divid, l_title, l_height, l_width, l_url, l_refreshtime);

        oRs.MoveNext();
    }

}
%>


