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

    File:           fac_locale_dialect.asp
    Status:
    Description:    Bewerkscherm voor locale en dialecten
                    bewerk alle lcl's van een bepaalde dialect/ taal combinatie
    Parameters:     dialect_key
                    dialect_id
                    lang
    Context:        Vanuit Facmgt (specifieke kolom) en vanuit fac_locale_list
    Note:           Er bestaat geen show-variant. Zou te weinig meerwaarde hebben

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

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

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

var submitting = getQParamInt("submit", 0) == 1;
var lang = getQParam("lang", "NL"); // TODO: popup als niet meegegeven
var dialect_key = getQParamInt("dialect_key");
var dialect_id = getQParam("dialect_id");

switch (dialect_id)
{
    case "MLD_SRTDISCIPLINE_KEY":
        sql = "SELECT "+lcl.xsql('ins_srtdiscipline_omschrijving','ins_srtdiscipline_key')+" descr"
            + "  FROM ins_srtdiscipline"
            + " WHERE ins_srtdiscipline_key = " + dialect_key;
        term_label = L("lcl_mld_vakgroeptype");
        break;
    case "MLD_TYPEOPDR_KEY":
        sql = "SELECT "+lcl.xsql('mld_typeopdr_omschrijving', 'mld_typeopdr_key')+" descr"
            + "  FROM mld_typeopdr"
            + " WHERE mld_typeopdr_key = " + dialect_key;
        term_label = L("lcl_mld_typeopdr");
        break;
    case "RES_SRTACTIVITEIT_KEY":
        sql = "SELECT "+lcl.xsql('res_srtactiviteit_omschrijving','res_srtactiviteit_key')+" descr"
            + "  FROM res_srtactiviteit"
            + " WHERE res_srtactiviteit_key = " + dialect_key;
        term_label = L("lcl_srtactivity");
        break;
    default: INTERNAL_ERROR;
}
var oRs = Oracle.Execute(sql);
var term_omschrijving = oRs("descr").Value;
%>

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

    if (submitting) {
        protectRequest.validateToken();
        // de aanwezige teksten
        var sql = "SELECT fli.fac_localeitems_key,"
                + "       fli.fac_localeitems_lcl,"
                + "       fl.fac_locale_dialect_key,"
                + "       fl.fac_locale_tekst"
                + "  FROM fac_localeitems fli, fac_locale fl"
                + " WHERE fli.fac_localeitems_key = fl.fac_localeitems_key(+)"
                + "   AND fl.fac_locale_lang(+) = " + safe.quoted_sql(lang)
                + "   AND fl.fac_locale_dialect_key(+) = " + dialect_key
                + "   AND fli.fac_localeitems_dialect_id = " + safe.quoted_sql(dialect_id)
                + " ORDER BY fac_locale_tekst";

        var oRs = Oracle.Execute(sql);
        while (!oRs.Eof)
        {
            var tekst = getFParam("lcl_tekst_"+oRs("fac_localeitems_key").Value, "");
            if (tekst == "")
            {
                var sql = "DELETE FROM fac_locale fl"
                        + " WHERE fac_locale_lang = " + safe.quoted_sql(lang)
                        + "   AND fl.fac_locale_dialect_key(+) = " + dialect_key
                        + "   AND fl.fac_localeitems_key = " + oRs("fac_localeitems_key").Value;
            }
            else
            {
                if (oRs("fac_locale_dialect_key").Value == null) // nog niet aanwezig
                {
                    var sql = "INSERT INTO FAC_LOCALE (fac_locale_lang, fac_locale_dialect_key, fac_localeitems_key, fac_locale_tekst)"
                            + " VALUES(" + safe.quoted_sql(lang) + ", "+dialect_key+", "+oRs("fac_localeitems_key").Value + "," + safe.quoted_sql(tekst) + ")";
                }
                else
                {
                    var sql = "UPDATE fac_locale SET fac_locale_tekst = " +safe.quoted_sql(tekst)
                            + " WHERE fac_locale_lang = " + safe.quoted_sql(lang)
                            + "   AND fac_locale_dialect_key = "+dialect_key
                            + "   AND fac_localeitems_key = " + oRs("fac_localeitems_key").Value;
                }
            }
            Oracle.Execute(sql);
            oRs.MoveNext();
        }

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

    <script  type="text/javascript" >
      FcltMgr.setTitle(L("lcl_lcl_terminologie"), {hot:false});
    </script>

    <style>
      tr.odd { background-color: #fafafa; }
    </style>
  </head>
  <body id="localebody">
<%
    var buttons =  [ {title: L("lcl_submit"), icon: "opslaan.png", action: "document.forms.lclform.submit()" },
                     {title: L("lcl_cancel"), icon: "undo.png", action: "FcltMgr.closeDetail(window, { cancel: true } )" }];
    IFRAMER_HEADER(L("lcl_lcl_terminologie") + " " + safe.jsstring(term_label) + " " + safe.jsstring(term_omschrijving), buttons);
%>
    <div id="edit">
      <form id="lclform" name="lclform" action="fac_locale_dialect.asp?submit=1&dialect_key=<%=dialect_key%>&dialect_id=<%=dialect_id%>&lang=<%=lang%>" method="post">
<%
        BLOCK_START("lcldialect", lang);

        var sql = "SELECT fli.fac_localeitems_key,"
                + "       fli.fac_localeitems_lcl,"
                + "       fl.fac_locale_dialect_key,"
                + "       fl.fac_locale_tekst"
                + "  FROM fac_localeitems fli, fac_locale fl"
                + " WHERE fli.fac_localeitems_key = fl.fac_localeitems_key(+)"
                + "   AND fl.fac_locale_lang(+) = " + safe.quoted_sql(lang)
                + "   AND fl.fac_locale_dialect_key(+) = " + dialect_key
                + "   AND fli.fac_localeitems_dialect_id = " + safe.quoted_sql(dialect_id)
                + " ORDER BY fac_locale_tekst, fac_localeitems_lcl";
        var oRs = Oracle.Execute(sql);
        var nn = 0;
        while (!oRs.eof)
        {
            var lbl = L(oRs("fac_localeitems_lcl").Value); // originele tekst
            if (lbl != safe.html(lbl))
                lbl += "<br> <span style='color:#999;'>"+safe.html(lbl)+"</span>";
            nn++;

            //if (Session("logging") & 4)
            {
                lbl = "</label>" + " <span style='color:#999;'>"+oRs("fac_localeitems_lcl").Value + "</span></td><td class='label'><label>" + lbl;
                //lbl = "</label>" + " <td class='label' title='"+oRs("fac_localeitems_lcl").Value + "'><label>" + lbl;
            }

            RWFIELDTR("lcl_tekst_"+oRs("fac_localeitems_key").Value, "fldlcldialect", lbl,
                                         oRs("fac_locale_tekst").Value, {maxlength: 100, trclass: (nn%2?"odd":"even") });
            oRs.MoveNext();
        }
        BLOCK_END();
IFACE.FORM_END();
%>
      </form>
    </div> <!-- edit -->
  </body>
</html>
