<% /*
     $Revision$
     $Id$
*/ %>

<!-- #include file="fac_menu.inc" -->

<%

var the_menu_arr = null;

wgt = {

        // Geeft de informatie van alle widgets van een widgetpagina terug op basis van een widget-pagina-key
        get_widgets_onpage:
            function(wgt_page_key)
            {
                var sql = "  SELECT DISTINCT w.fac_widget_key, "
                        + "         wop.fac_widget_onpage_key, "
                        + "         wop.fac_widget_onpage_order, "
                        + "         fac_widget_id, "
                        + lcl.xsqla('fac_widget_title', 'w.fac_widget_key') + ","
                        + "         fac_widget_onpage_height, "
                        + "         COALESCE(fac_widget_onpage_width, 100) fac_widget_onpage_width, "
                        + "         fac_widget_type, "
                        + "         fac_widget_typerefkey, "
                        + "         fac_widget_url, "
                        + "         fac_widget_content, "
                        + "         fac_widget_refreshtime, "
                        + "         fac_functie_key, "
                        + "         fac_widget_volgnr "
                        + "    FROM fac_widget w"
                        + "       , fac_widget_onpage wop  "
                        + "   WHERE wop.fac_widget_page_key = " + wgt_page_key
                        + "     AND w.fac_widget_key = wop.fac_widget_key "
                        + "     AND (   w.fac_functie_key IS NULL "
                        + "          OR w.fac_functie_key IN (SELECT fac_functie_key "
                        + "                                   FROM fac_v_webgebruiker "
                        + "                                  WHERE prs_perslid_key = " + user_key + ")) "
                        + (S("fac_usrrap_mode") == 0 ? " AND fac_widget_type = 'FAC'" : "")
                        + "ORDER BY wop.fac_widget_onpage_order";
                var oRs = Oracle.Execute(sql);

                var widgets = [];
                var widget;
                while (!oRs.EoF)
                {
                    widget = {
                        "id":               (oRs("fac_widget_id").Value || "wgt_") + shared.random(12, "base32"),
                        "uid":              oRs("fac_widget_onpage_key").Value,
                        "wgt_key":          oRs("fac_widget_key").Value,
                        "height":           oRs("fac_widget_onpage_height").Value,
                        "width":            Math.round(Math.min(100, oRs("fac_widget_onpage_width").Value) / (100/12)),
                        "title":            oRs("fac_widget_title").Value,
                        "type":             oRs("fac_widget_type").Value,
                        "typerefkey":       oRs("fac_widget_typerefkey").Value,
                        "url":              oRs("fac_widget_url").Value,
                        "content":          oRs("fac_widget_content").Value,
                        "refreshtime":      oRs("fac_widget_refreshtime").Value || -1
                    }

                    widgets.push(widget);
                    oRs.MoveNext();
                }

                oRs.Close();

                return widgets;
            },

        // Een clone neemt ook de pagina-indeling over, dat doen we hier
        clone_widgets_onpage:
            function (from_page_key, to_page_key)
            {
                result = {};
                var sql = " INSERT INTO fac_widget_onpage (fac_widget_page_key,"
                        + "                                fac_widget_key,"
                        + "                                fac_widget_onpage_order,"
                        + "                                fac_widget_onpage_height,"
                        + "                                fac_widget_onpage_width)"
                        + "     SELECT " + to_page_key
                        + "          , fac_widget_key"
                        + "          , fac_widget_onpage_order"
                        + "          , fac_widget_onpage_height"
                        + "          , fac_widget_onpage_width"
                        + "       FROM fac_widget_onpage"
                        + "      WHERE fac_widget_page_key = " + from_page_key;
                var err = Oracle.Execute(sql, true);
                result.success = !err.friendlyMsg;
                result.warning = err.friendlyMsg;
                return result;
            },

        exists_widget_page:
            function (wgt_page_key)
            {
                var sql = " SELECT ''"
                        + "   FROM fac_widget_page"
                        + "  WHERE fac_widget_page_key = " + wgt_page_key;
                var oRs = Oracle.Execute(sql);
                var result = !oRs.EoF;
                oRs.Close();
                return result;
            },

        // Geeft de widget informatie terug op basis van een widget-key
        get_widget:
            function (wgt_key)
            {
                var sql = "  SELECT fac_widget_key, "
                        + "         fac_widget_id, "
                        + lcl.xsqla('fac_widget_title', 'fac_widget_key') + ","
                        + "         fac_widget_type, "
                        + "         fac_widget_typerefkey, "
                        + "         fac_widget_url, "
                        + "         fac_widget_content, "
                        + "         fac_widget_refreshtime, "
                        + "         fac_functie_key, "
                        + "         fac_widget_volgnr "
                        + "    FROM fac_widget"
                        + "   WHERE (   fac_functie_key IS NULL "
                        + "          OR fac_functie_key IN (SELECT fac_functie_key "
                        + "                                   FROM fac_v_webgebruiker "
                        + "                                  WHERE prs_perslid_key = " + user_key + ")) "
                        + "     AND fac_widget_key = " + wgt_key;

                var oRs = Oracle.Execute(sql);
                var widget = {
                    "id":               (oRs("fac_widget_id").Value || ""), /* TODO unique*/
                    "wgt_key":          oRs("fac_widget_key").Value,
                    "height":           0, /* To be determined onpage */
                    "width":            0, /* To be determined onpage */
                    "title":            oRs("fac_widget_title").Value,
                    "type":             oRs("fac_widget_type").Value,
                    "typerefkey":       oRs("fac_widget_typerefkey").Value,
                    "url":              oRs("fac_widget_url").Value,
                    "content":          oRs("fac_widget_content").Value,
                    "refreshtime":      oRs("fac_widget_refreshtime").Value || -1
                }

                oRs.Close();

                return widget;
            },

        renderWidget:
            function (widget, mode)
            {
                // Hier komt de type-afhankelijke specifieke rendering van de verschillende content
                mode = mode || "show";

                widget.qs = "";
                // QueryString in orde boxen, asWidget toevoegen, originele QS behouden (minus 1=1/mode/wgt_page_key), widget_height bij rap, en custom parameters qs0 - qs9
                if (inArray(widget.type, ["FAC", "URL", "NWS", "RAP", "FLR", "FAQ"]))
                {
                    widget.qs = (inArray(widget.type, ["FAC", "URL"]) && widget.url.indexOf("?") === -1) ? "?" : "&"; // Types NWS, RAP, FLR & FAQ hebben sowieso al een ? in de url
                    widget.qs += "asWidget=1&title_locked=1";
                    if (widget.type == "FAC" && typeof widget.height === "number")
                        widget.qs += "&widget_height=" + widget.height;
                    var qs = String(Request.ServerVariables("QUERY_STRING"));
                    qs = qs.replace(/mode=(?:.*&|.*$)/, "");
                    qs = qs.replace(/1=1(?:&|$)/, "");
                    qs = qs.replace(/wgt_page_key=(?:\d*&|\d*$)/, "");
                    if (qs != "")
                        widget.qs += "&" + qs;
                    if (inArray(widget.type, ["NWS", "RAP"]) && widget.url) // Deze types kunnen zowel een ref_key als een queryString-parameter krijgen
                    {
                        if (sharedTrim(widget.url).indexOf("&") !== 0)
                            widget.url = "&" + widget.url;
                    }
                    if (widget.qs != "" && widget.url && widget.url.indexOf("#") > 0)
                    {
                        var temp = widget.url.split("#")[0];
                        widget.url = temp[0];
                        widget.qs += "#" + temp[1];
                    }
                }
                var custom_qs = [];
                var autorefresh = widget.refreshtime > 0 && widget.refreshtime < 60; // refreshtime < 60 ververst de widget alleen als je het tabje (her)activeert (FCLT#23925)
                if (widget.url || widget.qs)
                {
                    for (var i = 0; i < 10; i++)
                    {
                        custom_qs[i] = getQParamSafe("qs" + i, "");
                        if (custom_qs[i] === "")
                            continue;
                        var regex = new RegExp('\\{'+i+'\\}', 'gi');
                        if (widget.url)
                            widget.url = widget.url.replace(regex, custom_qs[i]);
                        if (widget.qs)
                            widget.qs = widget.qs.replace(regex, custom_qs[i]);
                    }
                }
%>
                <div class="<%=(mode == "edit" ? 'widget-col-wrapper ' : '')%>item-width-<%=widget.width%>"
                    data-widget-type="<%=widget.type%>"
                    <%=(mode == "edit" ? ' data-key="' + widget.wgt_key + '"' + '"' + ' data-width="' + widget.width + '"' : '')%>
                    <%=(widget.height ? ' data-height="' + widget.height + '"' : '')%>
                    <%=(mode == "edit" && widget.uid ? ' data-uid="' + widget.uid + '"' : '')%>>

                    <%=(mode == "edit" ? "<div class=\"widget-col-bg\">" + I("fa-repeat", { fastyle: "far" }) + "</div>" : "")%>
                    <%=(mode == "edit" ? "<div class=\"widget-col\">" : "")%>
                    <%=(widget.title ? '<div' + (widget.url && widget.url.indexOf("fac_nieuws.asp") > -1 ? ' id="mywelcomeinfo"' : '') + ' class="widget-title">' + safe.html(widget.title) + '</div>' : '')%>
<%
                    switch (widget.type)
                    {
                        case "FAC": // Interne/Facilitor url
%>
                            <div class="widget-type-fac">
                                <iframe src="../fac/<%=safe.htmlattr(widget.url)%><%=safe.htmlattr(widget.qs)%>" id="frame_<%=safe.htmlattr(widget.id)%>" name="frame_<%=safe.htmlattr(widget.id)%>"
                                        <%=autorefresh ? "data-autorefresh " : ""%>
                                        <%=(widget.height ? 'style="max-height: ' + widget.height + 'px"' : '')%>
                                        marginwidth="0" marginheight="0" frameborder="0"
                                        onload="FcltMgr.iframeLoaded(this);<%=(mode == "edit" ? ' checkRowClearance(this);' : '')%>">
                                </iframe>
                            </div>
<%
                            break;
                        case "URL": // Externe url
%>
                            <div class="widget-type-url">
                                <iframe src="<%=widget.url%><%=safe.htmlattr(widget.qs)%>" id="frame_<%=safe.htmlattr(widget.id)%>" name="frame_<%=safe.htmlattr(widget.id)%>"
                                        <%=autorefresh ? "data-autorefresh " : ""%>
                                        <%=(widget.height ? 'height="' + widget.height + 'px"' : '')%>
                                        marginwidth="0" marginheight="0" frameborder="0"
                                        <%=(mode == "edit" ? ' onload="checkRowClearance(this);"' : '')%>>
                                </iframe>
                            </div>
<%
                            break;
                        case "MK": // Menukop (incl. sub-items)
%>
                            <div class="widget-type-mk">
<%
                            if (the_menu_arr === null)
                                the_menu_arr = fillMenuArray();

                            var menu_arr = JSON.parse(JSON.stringify(the_menu_arr)); // Deep copy van primitives

                            var a = menu_arr.length;
                            while (a--) // Loop van achter naar voren, per Tabblad
                            {
                                var tabblad = menu_arr[a];
                                var tabblad_has_match = false;
                                if (!tabblad || !tabblad.Koppen)
                                    continue;
                                var b = tabblad.Koppen.length;
                                while (b--) // Per kop
                                {
                                    var kop = tabblad.Koppen[b];
                                    if (kop.menu_key == widget.typerefkey)
                                    {
                                        generatePortalmenu([kop], true);
                                        tabblad_has_match = true;
                                        continue;
                                    }
                                }
                                if (!tabblad_has_match)
                                {
                                    menu_arr.splice(a, 1);
                                }
                            }

%>                          </div>
<%
                            break;
                        case "MI":  // submenuitem
%>
                            <div class="widget-type-mi">
<%
                            if (the_menu_arr === null)
                                the_menu_arr = fillMenuArray();

                            var menu_arr = JSON.parse(JSON.stringify(the_menu_arr)); // Deep copy van primitives

                            var a = menu_arr.length;
                            while (a--) // Loop van achter naar voren, per Tabblad
                            {
                                var tabblad = menu_arr[a];
                                var tabblad_has_match = false;
                                if (!tabblad || !tabblad.Koppen)
                                    continue;
                                var b = tabblad.Koppen.length;
                                while (b--) // Per kop
                                {
                                    var kop = tabblad.Koppen[b];

                                    var c = kop.Items.length;
                                    var kop_has_match = false;
                                    while (c--) // Per menu-item
                                    {
                                        var item = kop.Items[c];
                                        if (item.menu_key != widget.typerefkey)
                                        {
                                            menu_arr[a].Koppen[b].Items.splice(c, 1);
                                        }
                                        else
                                        {
                                            kop_has_match = true;
                                            tabblad_has_match = true;
                                        }
                                    }
                                    if (!kop_has_match)
                                    {
                                        menu_arr[a].Koppen.splice(b, 1);
                                    }
                                    else
                                    {
                                        generatePortalmenuitem(kop, true);
                                    }
                                }

                                if (!tabblad_has_match)
                                {
                                    menu_arr.splice(a, 1);
                                }
                            }

%>                          </div>
<%
                            break;
                        case "NWS": // Nieuwspagina
%>
                            <div class="widget-type-nws">
                                <iframe src="../fac/fac_nieuws.asp?<%=(widget.typerefkey > 0 ? "nieuwsgroep_key=" + widget.typerefkey : "1=1")%><%=safe.htmlattr(widget.url)%><%=safe.htmlattr(widget.qs)%>" id="frame_<%=safe.htmlattr(widget.id)%>" name="frame_<%=safe.htmlattr(widget.id)%>"
                                        <%=autorefresh ? "data-autorefresh " : ""%>
                                        <%=(widget.height ? 'style="max-height: ' + widget.height + 'px"' : '')%>
                                        marginwidth="0" marginheight="0" frameborder="0"
                                        onload="FcltMgr.iframeLoaded(this);<%=(mode == "edit" ? ' checkRowClearance(this);' : '')%>">
                                </iframe>
                            </div>
<%
                            break;
                        case "RAP": // Rapport
%>
                            <div class="widget-type-rap">
                                <iframe src="../fac/fac_report.asp?mode=list&usrrap_key=<%=widget.typerefkey%><%=safe.htmlattr(widget.url)%><%=safe.htmlattr(widget.qs)%>" id="frame_<%=safe.htmlattr(widget.id)%>" name="frame_<%=safe.htmlattr(widget.id)%>"
                                        <%=autorefresh ? "data-autorefresh " : ""%>
                                        <%=(widget.height ? 'style="max-height: ' + widget.height + 'px"' : '')%>
                                        marginwidth="0" marginheight="0" frameborder="0"
                                        onload="FcltMgr.iframeLoaded(this);<%=(mode == "edit" ? ' checkRowClearance(this);' : '')%>">
                                </iframe>
                            </div>
<%
                            break;
                        case "FLR": // Graphics plattegrond (Floorplan)
%>
                            <div class="widget-type-flr">
                                <img thesrc="../cad/mySlnk2IMG.asp?<%=safe.htmlattr(widget.url)%><%=safe.htmlattr(widget.qs)%>" id="img_<%=safe.htmlattr(widget.id)%>"
                                     onload="javascript: { <%=(mode == "edit" ? ' checkRowClearance(this);' : '')%> }">
                            </div>
<%
                            break;
                        case "RAW": // HTML, geen sandbox attribuut, type HTML is gewoon onveilig en moet voorzichtig gebruikt worden
                            if (S("fac_html_strictness") == 1) {
                                break;
                            }
%>
                            <div class="widget-type-raw">
                                <iframe srcdoc="<%=safe.htmlattr(widget.content)%>" src="about:blank" id="frame_<%=safe.htmlattr(widget.id)%>" name="frame_<%=safe.htmlattr(widget.id)%>"
                                        <%=autorefresh ? "data-autorefresh " : ""%>
                                        <%=(widget.height ? 'height="' + widget.height + '" style="max-height: ' + widget.height + 'px"' : '')%>
                                        marginwidth="0" marginheight="0" frameborder="0"
                                        onload="javascript: { resize_raw(this);
                                                             <%=(mode == "edit" ? ' checkRowClearance(this);' : '')%> }">
                                </iframe>
                            </div>
<%
                            break;
                        case "IMG": // Plaatje (Image)
%>
                            <div class="widget-type-img">
                                <img src="<%=safe.htmlattr(widget.url)%>"<%=(widget.height ? ' style="max-height: ' + widget.height + 'px"' : '')%> id="img_<%=safe.htmlattr(widget.id)%>"
                                     <%=(mode == "edit" ? ' onload="checkRowClearance(this);"' : '')%>>
                            </div>
<%
                            break;
                        case "FAQ": // Kennisbankitem (key) TODO: leuk geformatteerde vraag/antwoord
%>
                            <div class="widget-type-faq">
                                <iframe src="../fac/fac_show_faq.asp?faq_key=<%=widget.typerefkey%><%=safe.htmlattr(widget.qs)%>" id="frame_<%=safe.htmlattr(widget.id)%>" name="frame_<%=safe.htmlattr(widget.id)%>"
                                        <%=autorefresh ? "data-autorefresh " : ""%>
                                        <%=(widget.height ? 'style="max-height: ' + widget.height + 'px"' : '')%>
                                        marginwidth="0" marginheight="0" frameborder="0"
                                        onload="FcltMgr.iframeLoaded(this);<%=(mode == "edit" ? ' checkRowClearance(this);' : '')%>">
                                </iframe>
                            </div>
<%
                            break;
                    }
                    if (widget.refreshtime != -1 && widget.refreshtime >= 60)
                    {   %>
                            <script>
                                setReloadTimer("<%=safe.jsstring(widget.id)%>", "<%=safe.jsstring(widget.type)%>", <%=widget.refreshtime%>);
                            </script>
<%                  }   %>
                    <%=(mode == "edit" ? '</div>' : '')%>
                    <%=(mode == "edit" ? wgt.widget_icons(widget.wgt_key) : '')%>
                </div>
<%          },

        saveWidgetPage:
            function(wgt_page_key, widgets)
            {
                if (wgt_page_key > 0)
                {
                    // Deze MAX(key) opzoeken zodat we de oude widgets kunnen verwijderen nadat(!) de nieuwe zijn toegevoegd
                    var sql = "SELECT COALESCE(MAX(fac_widget_onpage_key), -1)"
                            + "  FROM fac_widget_onpage"
                            + " WHERE fac_widget_page_key = " + wgt_page_key;
                    var oRs = Oracle.Execute(sql);
                    var max_onpage_key = oRs(0).Value;
                    oRs.Close();

                    if (widgets.length)
                    {
                        // Nieuwe widgets toevoegen
                        sql = "INSERT ALL";
                        var widget;
                        for (i in widgets)
                        {
                            widget = widgets[i];
                            sql += " INTO fac_widget_onpage (fac_widget_page_key, fac_widget_key, fac_widget_onpage_order, fac_widget_onpage_height, fac_widget_onpage_width)"
                                + "                 VALUES (" + wgt_page_key + ", " + widget.key + ", " + widget.order + ", " + widget.height + ", " + widget.width + ")";
                        }
                        sql += " SELECT 1 FROM DUAL" // <- nodig voor een multi-row INSERT
                        Oracle.Execute(sql);
                    }

                    // Nu pas de oude widgets weghalen
                    wgt.emptyWidgetPage(wgt_page_key, max_onpage_key);
                }
            },

        emptyWidgetPage:
            function (wgt_page_key, up_to_key)
            {
                var sql = "DELETE FROM fac_widget_onpage"
                        + " WHERE fac_widget_page_key = " + wgt_page_key;
                if (up_to_key)
                    sql += " AND fac_widget_onpage_key <= " + up_to_key
                Oracle.Execute(sql);
            },

        newWidgetPage:
            function()
            {
                // First time initialisation & creation of your personal page
                sql = "SELECT fac_s_fac_widget_page_key.nextval"
                    + "  FROM DUAL";
                oRs = Oracle.Execute(sql);
                var new_key = oRs(0).value;
                oRs.Close();

                sql = "INSERT INTO fac_widget_page"
                    + "         (fac_widget_page_key, prs_perslid_key)"
                    + "  VALUES (" + new_key + ", " + user_key + ")";
                oRs = Oracle.Execute(sql);

                __Log('Personal widgetpage created');
                return new_key;
            },

        _getReadWrite:
            function _getReadWrite(authparam)
            {
                return {
                    "canRead":  !!(authparam && authparam.PRSreadlevel < 9 && authparam.ALGreadlevel < 9),
                    "canWrite": !!(authparam && authparam.PRSwritelevel < 9 && authparam.ALGwritelevel < 9)
                }
            },

        func_enabled_wgt:
            function func_enabled_wgt(pkey)
            {
                // Bij sommige widget-types kan in de widgets zelf ook nog autorisatie van toepassing zijn, bijv. bij rapportages
                var result = { "canRead": true, "canWrite": false };

                var xfunc = user.func_enabled2("WGT", { isOptional: true });
                var authparamsPRSSYS = user.checkAutorisation("WEB_PRSSYS", true);
                var prssys = wgt._getReadWrite(authparamsPRSSYS);

                result.writeman = S("fac_usrrap_mode") == 1 && xfunc.canWrite("WEB_WGTMAN");
                result.canWrite = result.writeman || prssys.canWrite;

                if (pkey > -1) // Voor nieuwe widgets houdt het hier wel op met proberen
                {
                    var sql = "SELECT fac_widget_type, fac_functie_key"
                            + "  FROM fac_widget"
                            + " WHERE fac_widget_key = " + pkey;
                    var oRs = Oracle.Execute(sql);
                    var wgt_type        = oRs("fac_widget_type").Value;
                    var fac_functie_key = oRs("fac_functie_key").Value || -1;
                    oRs.Close();

                    if (fac_functie_key > -1)
                    {
                        var authParams = user.checkAutorisation(fac_functie_key, true);
                        var extraF = wgt._getReadWrite(authParams);

                        result.canRead  = result.canRead && extraF.canRead;
                        result.canWrite = result.canWrite && extraF.canWrite; // Momenteel is canWrite hier altijd false
                    }
                }

                return result;
            },

        func_enabled_wgt_page:
            function func_enabled_wgt_page(wgt_page_key)
            {
                var result = {};
                var xfunc = user.func_enabled2("WGT", { isOptional: true });
                var authparamsPRSSYS = user.checkAutorisation("WEB_PRSSYS", true);
                var prssys = wgt._getReadWrite(authparamsPRSSYS);

                result.readuse  = S("fac_usrrap_mode") == 1 && xfunc.canRead("WEB_WGTUSE");
                result.writeuse = S("fac_usrrap_mode") == 1 && xfunc.canWrite("WEB_WGTUSE");
                result.readman  = S("fac_usrrap_mode") == 1 && xfunc.canRead("WEB_WGTMAN");
                result.writeman = S("fac_usrrap_mode") == 1 && xfunc.canWrite("WEB_WGTMAN");
                result.readsys  = prssys.canRead;
                result.writesys = prssys.canWrite;
                result.readAny  = result.readuse || result.readman || prssys.readsys;
                result.writeAny = result.writeuse || result.writeman || prssys.canWrite;
                result.title    = "";

                if (wgt_page_key > -1) // Bestaande widget-pagina
                {
                    var sql = "SELECT prs_perslid_key"
                            + "     , fac_groep_key"
                            + "     , fac_widget_page_name"
                            + "  FROM fac_widget_page"
                            + " WHERE fac_widget_page_key = " + wgt_page_key;
                    var oRs = Oracle.Execute(sql);
                    if (oRs.EoF) // Omdat de key uit een setting gehaald wordt die vroeger een 0 of 1 was, kan het per ongeluk fout gaan, daarom hieronder een aanwijzing
                        _AiAi("INTERNAL_ERROR: Widgetpagina met key {0} bestaat niet".format(wgt_page_key));
                    var prs_key         = oRs("prs_perslid_key").Value || -1;
                    var fac_groep_key   = oRs("fac_groep_key").Value || -1;
                    result.title        = oRs("fac_widget_page_name").Value || "";
                    oRs.Close();

                    // Als ik geen beheerder ben moet ik ook de 'Extra autorisatie' hebben
                    if (fac_groep_key > -1 && !user.has("WEB_FACTAB") && !user.has("WEB_FACFAC") && !result.readsys && !result.readman) {
                        sql = "SELECT 'dummy'"
                            + "  FROM fac_gebruikersgroep"
                            + " WHERE prs_perslid_key = " + user_key
                            + "   AND fac_groep_key = " + fac_groep_key;
                        oRs = Oracle.Execute(sql);
                        user.auth_required_or_abort(!oRs.EoF);
                        oRs.Close();
                    }

                    result.public   = prs_key == -1;
                    result.canRead  = result.public ||                              // Iedereen mag openbare pagina's zien
                                        (prs_key == user_key && result.readAny) ||  // readAny mag zijn eigen pagina zien
                                        result.readsys;                             // PRSSYS mag ook andermans pagina zien
                    result.canWrite = (prs_key == user_key && result.writeAny) ||   // writeAny mag zijn eigen pagina aanpassen
                                        (result.public && result.writeman) ||       // WGTMAN mag publieke pagina's aanpassen
                                        prssys.canWrite;                            // PRSSYS mag ook andermans pagina aanpassen

                    if (result.canWrite) {
                        sql = "SELECT fac_widget_key"
                            + "  FROM fac_widget_onpage"
                            + " WHERE fac_widget_page_key = " + wgt_page_key;
                        oRs = Oracle.Execute(sql);
                        while (!oRs.EoF && result.canWrite) {
                            result.canWrite = wgt.func_enabled_wgt(oRs("fac_widget_key").Value).canRead; // Je mag je pagina her-indelen als je alle widgets op de pagina mag zien
                            oRs.MoveNext();
                        }
                        oRs.Close();
                    }
                }
                else // Nieuwe widget-pagina
                {
                    result.public   = false;
                    result.canRead  = result.readAny;
                    result.canWrite = result.writeAny;
                }

                return result;
            },

        tooltip_row:
            function()
            {
                Response.Write('<div class="widget-container editable">');
                wgt.tooltip_col();
                wgt.empty_col();
                Response.Write('</div>');
            },

        tooltip_col:
            function()
            {
                Response.Write('<div class="widget-col-wrapper item-width-12 widget-new-wrapper">'
                             + '  <div class="widget-col big-tooltip">'
                             +      L("fac_widget_add_new")
                             +      I("fa-hand-point-up fa-xl", { fastyle: "fal" })
                             + '  </div>'
                             + '</div>');
            },

        empty_col:
            function()
            {
                Response.Write('<div class="filler-col-wrapper"></div>'
                             + '<div class="empty-col-wrapper item-width-0">'
                             + '  <div class="empty-col">'
                             +      I("fa-plus-circle fa-4x", { fastyle: "fal" })
                             + '     <div class="widget-tooltip">' + L("fac_widget_add_here") + '</div>'
                             + '  </div>'
                             + '</div>');
            },

        widget_icons:
            function(wgt_key) {
                var wgt_info = wgt.func_enabled_wgt(wgt_key);
                Response.Write('<div class="icons-wrapper">'
                             + (wgt_info.canWrite
                                ? '  <div class="edit-widget widget-icon">'
                                +      I("fa-fclt-edit fa-lg", { fastyle: "far" })
                                + '  </div>'
                                : '')
                             + '  <div class="delete-widget widget-icon">'
                             +      I("fa-trash-alt fa-lg", { fastyle: "far" })
                             + '  </div>'
                             + '  <div class="widget-size">'
                             + '    <span class="widget-size-value"></span>'
                             +      I("fa-arrows-v", { fastyle: "fal" })
                             + '  </div>'
                             + '</div>');
            }
}

%>