<% /*
     $Revision$
     $Id$

    File:               srtdeelFilter.inc
    Description:        functies voor srtdeel suggest velden
    Globals:
    Context:
    Note:
*/ %>


<%

function getFiltClauseSrtdeel(pfiltcode, params)
{
  var lfiltClause = {from: "", where: ""};
  var orgmodule = params.module || "INS"; // geldige waarden: INS, BES, SLE
  var module = (orgmodule == "SLE" ? "INS" : orgmodule);

  if (orgmodule != "INS" && orgmodule != "BES" && orgmodule != "SLE")
    shared.internal_error(L("lcl_obj_bad_value") + " module={0}.".format(orgmodule));

  if (params.module != "")
  {
    lfiltClause.from = ", " + module + "_discipline id";
    lfiltClause.where = " AND sg.ins_discipline_key = id.ins_discipline_key"
                      + " AND id.ins_discipline_module = " + safe.quoted_sql(module)
                      + (orgmodule == "INS" || orgmodule == "SLE"
                        ? " AND sg.ins_srtgroep_key "
                          + (orgmodule == "INS" ? "NOT" : "")
                          + " IN (" + S("sle_ins_srt_groep_key") + ", " + S("cil_ins_srt_groep_key") + ")"
                        : ""
                        );
  }

  if (params.disc_key && params.disc_key > 0)
    lfiltClause.where += " AND sg.ins_discipline_key = " + params.disc_key;

  if (params.srtgroep_key && params.srtgroep_key > 0)
    lfiltClause.where += " AND sg." + module + "_srtgroep_key = " + params.srtgroep_key;

  if (params.srtdeel_key && params.srtdeel_key > 0)
    lfiltClause.where += " AND sd." + module + "_srtdeel_key = " + params.srtdeel_key;

  if (pfiltcode == "LEND")
    lfiltClause.where += " AND sd.ins_srtdeel_uitleenbaar = 1";

  if (pfiltcode != "VERW")
    lfiltClause.where += " AND sd." + module + "_srtdeel_verwijder IS NULL";

  if (params.autfunction != "")
  {
    var authparams = user.checkAutorisation(params.autfunction);
    if (authparams.fac_functie_discipline == 1)
    { // INSBOF autorisatie is wel discipline afhankelijk, INSMGT en SLEXXX autorisatie niet.
      lfiltClause.where += " AND sg.ins_discipline_key IN ("
                   + "    SELECT g.ins_discipline_key"
                   + "      FROM fac_v_webgebruiker g"
                   + "     WHERE g.prs_perslid_key = " + user_key
                   + "       AND g.fac_functie_key = " + authparams.autfunctionkey
                   + ")";
    }
  }
  return lfiltClause;
}

function getExtraInfSrtdeel(pextracode, pmodule)
{
  var lExtraInf = ", sg." + pmodule + "_srtgroep_key extra";
  if (pmodule == "INS")
  {
    if (pextracode && pextracode != "")
    {
      switch(pextracode)
      {
        case 'B': lExtraInf = ", sd.ins_srtdeel_binding extra";
                  break;
      }
    }
  }
  return lExtraInf;
}
%>
