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

    File:           fac_locale_edit_std.asp
    Status:
    Description:    Bewerkscherm voor overrulen van één standaard lcl

    Parameters:     lcl_label

    Context:        Vanuit fac_locale_list_std
    Note:           Modal popupje
                    Altijd voor alle talen tegelijk

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

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

var autfunction = "WEB_LCLSYS";
var authparams = user.checkAutorisation(autfunction);

var submitting = getQParamInt("submit", 0) == 1;
var lcl_label = getQParam("lcl_label");
var module = getQParam("module");
var transitParam = buildTransitParam(["lcl_label", "module"]);

maxlen = 2000; // fac_locale_xsl_cust
%>

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

    if (submitting) {
        protectRequest.validateToken();
        for (l in S("language_toggles"))
        {
            var tekst = getFParam("lcl_cust_" + S("language_toggles")[l], "");
            var sql = "UPDATE fac_locale_xsl"
                    + "   SET fac_locale_xsl_cust = " + safe.quoted_sql(tekst, maxlen)
                    + " WHERE fac_locale_xsl_lang = " + safe.quoted_sql(S("language_toggles")[l])
                    + "   AND fac_locale_xsl_label = " + safe.quoted_sql(lcl_label);
            Oracle.Execute(sql);
        }

%>
      <script type="text/javascript">
        FcltMgr.closeDetail( window, { success: true });
      </script>
<%
      Response.End;
    }
%>

  </head>
  <body class="fclt-modal" id="localebody">
    <% MODAL_START(); %>
      <form id="lclform" name="lclform" action="fac_locale_edit_std.asp?submit=1<%=transitParam%>%>" method="post">
<%
function langlabel(code)
{
    return '<img style="height:12px" alt="' + lcl.languages[code] + '" src=../pictures/' + code + '.png>&nbsp;' + lcl.languages[code];
}

        MODAL_BLOCK_START("lcl_locale_std", L("lcl_lcl_xsl_label") + ": " + lcl_label, {icon: "fa-hashtag"});

        //kolomkeydata
        var talen_arr = [];
        var nn=0;
        for (l in S("language_toggles"))
        {
            talen_arr.push("SELECT " + safe.quoted_sql(S("language_toggles")[l]) + " fac_locale_lang, "+(nn++)+"volgorde FROM DUAL");
        }

        var talen = talen_arr.join(" UNION ");
        var sql = "SELECT tl.fac_locale_lang"
                + "     , l.fac_locale_xsl_tekst"
                + "     , l.fac_locale_xsl_isvalid"
                + "     , l.fac_locale_xsl_cust"
                + "  FROM fac_locale_xsl l, ("+talen+") tl"
                + " WHERE l.fac_locale_xsl_label = " + safe.quoted_sql(lcl_label)
                + "   AND l.fac_locale_xsl_module = " + safe.quoted_sql(module)
                + "   AND l.fac_locale_xsl_lang = tl.fac_locale_lang"
                + " ORDER BY volgorde";
        var oRs = Oracle.Execute(sql);

        while (!oRs.eof)
        {
            var tekst = oRs("fac_locale_xsl_tekst").Value
            if (oRs("fac_locale_xsl_isvalid").Value == 0)
                tekst = "<<{0}>>".format(L("lcl_lcl_undefined"));

            var fldname = "lcl_cust_"+oRs("fac_locale_lang").Value;
            ROFIELDTR("", langlabel(oRs("fac_locale_lang").Value), tekst, { maxlength: maxlen });
            RWFIELDTR(fldname, "fld", "", oRs("fac_locale_xsl_cust").Value, { maxlength: maxlen });

            oRs.MoveNext();
        }

        sql = "SELECT COUNT(DISTINCT fac_locale_xref_filepath)"
              + "  FROM fac_locale_xsl l,"
              + "       fac_locale_xref x"
              + " WHERE x.fac_locale_xsl_key = l.fac_locale_xsl_key"
              + "   AND l.fac_locale_xsl_label = " + safe.quoted_sql(lcl_label);
        var oRs = Oracle.Execute(sql);
        var n_records = oRs(0).Value;
        oRs.Close();

/*
        var res = FCLTselector("mldstatusmulti",
                      sql,
                      { label: L("lcl_lcl_infiles"),
                        trclass:"hidden",
                        multi: true,
                        size: 10
                      });
*/
        %><tr><td colspan="2"><%=L("lcl_lcl_n_file") + ": " + n_records%></td></tr><%
        MODAL_BLOCK_END();

        var buttons =  [ {title: L("lcl_submit"), icon: "fa-fclt-save", action: "document.forms.lclform.submit()", importance: 1 },
                         {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "FcltMgr.closeDetail(window, { cancel: true } )", importance: 3 }];
        SIMPLE_BLOCK_START();
          CreateButtons(buttons);
        SIMPLE_BLOCK_END();
IFACE.FORM_END();
%>
      </form>
      <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
