<% /*
    $Revision$
    $Id$

    File:           model_mld_stdmelding.inc

    Description:

    Context:

    Notes:          Er is ook een model_issuetypes.inc
                    Deze bevat slechts een subset van de velden die hier worden gebruikt.
                    Kan model_mld_stdmelding ook gebruikt worden ipv model_issuetypes?

*/
%>
<!-- #include file="../mld/mld.inc" -->
<!-- #include file="model_mld_dienstpakket.inc" -->
<!-- #include file="model_mld_stdmelding_srtruimte.inc" -->
<%

function model_mld_stdmelding()
{
    this.records_name = "issuetypes";
    this.record_name = "issuetype",
    this.table = "mld_stdmelding";
    this.primary = "mld_stdmelding_key";
    this.soft_delete = "mld_stdmelding_verwijder";
    this.soft_expire = "mld_stdmelding_vervaldatum";
    this.autfunction = "WEB_MLDMGT";
    this.record_title = L("mld_stdmelding");
    this.records_title = L("mld_stdmelding_m");

    this.fields = {
        "id": {
            "dbs": "mld_stdmelding_key",
            "label": L("lcl_key"),
            "typ": "key",
            "required": true,
            "seq": "mld_s_mld_stdmelding_key"
        },
        "description": {
            "dbs": "mld_stdmelding_omschrijving",
            "label": L("lcl_complain"), //L("mld_stdmelding_omschrijving"),
            "typ": "varchar",
            "required": true,
            "translate": true
        },
        "disciplinetype": {
            "dbs": "ins_srtdiscipline.ins_srtdiscipline_key",
            "label": L("lcl_mld_vakgroeptype"),
            "typ": "key",
            "insertonly": true,
            "foreign" : {
                "tbl": "(SELECT ins_srtdiscipline_key"
                     + "      , ins_srtdiscipline_omschrijving srtdiscipline_oms"
                     + "   FROM ins_srtdiscipline"
                     + "  WHERE ins_srtdiscipline_module = 'MLD'"
                     + "    AND ins_srtdiscipline_verwijder IS NULL"
                     + "  ORDER BY 2 ASC"
                     + ")",
                "key": "ins_srtdiscipline_key",
                "desc": "srtdiscipline_oms"
            },
            "showtransit": true
        },
        "discipline": {
            "dbs": "mld_ins_discipline_key",
            "typ": "key",
            "label": L("lcl_mld_vakgroep"),
            "foreign": {
                "tbl": "(SELECT ins_discipline_key"
                     + "      , ins_discipline_omschrijving"
                     + "   FROM mld_v_aanwezigdiscipline"
                     + "  ORDER BY ins_discipline_omschrijving ASC"
                     + ")",
                "key": "ins_discipline_key",
                "desc": "ins_discipline_omschrijving"
            },
            "required": (mode == "edit"),
            "showtransit": true
        },
        "default_mld_ins_disc": {
            "dbs": "mld_stdmelding_default_disc",
            "typ": "key",
            "label": L("lcl_default_processing_group"),
            "foreign": "mld_discipline",
            "module" : "MLDB",
            "urlAdd": [{urlParam: "disc", field: "discipline" }],
            "emptyoption": "",
            "hidden_fld": !canUseTeams(),
            "noJustOne": true,
            "multiedit": true
        },
        "notfrontend": {
            "dbs": "mld_stdmelding_notfrontend",
            "typ": "check0",
            "label": L("lcl_mld_notfrontend"),
            "multiedit": true
        },
        "noteparticipants": {
            "dbs": "mld_stdmelding_notes",
            "label": L("lcl_mld_stdmelding_notes"),
            "typ": "key",
            "bits": [
                {
                    "name": "",
                    "label": "",
                    "typ": "check",
                    "mask": 7,
                    "radios": [
                        {
                            "name": "fe_on",
                            "label": L("lcl_caller"),
                            "mask": 1,
                            "defaultvalue": 1
                        },
                        {
                            "name": "fobo_on",
                            "label": L("lcl_mld_behandelaar"),
                            "mask": 2,
                            "defaultvalue": 1
                        },
                        {
                            "name": "uitv_on",
                            "label": L("lcl_handler"),
                            "mask": 4,
                            "defaultvalue": 0
                        }
                    ]
                }
            ],
            "defaultvalue": "3",
            "emptyoption": null,
            "multiedit": true
        },
        "costtype": {
            "dbs": "prs_kostensoort_key",
            "typ": "key",
            "label": L("lcl_charge_type"),
            "foreign": "prs_kostensoort",
            "multiedit": true
        },
        "costcentre": {
            "dbs": "prs_kostenplaats_key",
            "label": L("prs_kostenplaats"),
            "typ": "key",
            "foreign": "prs_kostenplaats",
            "foreignfiltercode": "A", // alle
            "emptyoption": "",
            "multiedit": true
        },
        "canrefer": {
            "dbs": "mld_stdmelding_kanverwijzen",
            "typ": "key",
            "label": L("lcl_mld_kanverwijzen"),
            "LOV": canrefer_LOV(),
            "multiselect": true,
            "multiadd": true,
            "defaultvalue": -1,
            "emptyoption": L("lcl_none")
        },
        "mandatorylevel": {
            "dbs": "alg_onrgoed_niveau",
            "typ": "varchar",
            "label": L("lcl_mld_onrgoed_niveau"),
            "LOV": "H;" + L("lcl_none_hide")+ ";"
                 + ";"  + L("lcl_none")     + ";"
                 + "L;" + L("lcl_location") + ";"
                 + "G;" + L("lcl_building") + ";"
                 + "V;" + L("lcl_floor")    + ";"
                 + "R;" + L("lcl_room"),
            "emptyoption": null,
            "emptyisrealvalue": true,
            "multiedit": true
        },
        "notify": {
            "dbs": "mld_stdmelding_notify",
            "typ": "check0",
            "label": L("lcl_mld_notify")
        },
        "plannable": {
            "dbs": "mld_stdmelding_planbaar",
            "typ": "number",
            "label": L("lcl_mld_planbaar"),
            "LOV": L("lcl_mld_planbaarLOV"),
            "required": true,
            "defaultvalue": 0,
            "multiedit": true
        },
        "plannablefrontend": {
            "dbs": "mld_stdmelding_planbaarfe",
            "typ": "check0",
            "label": L("lcl_mld_planbaarfe")
        },
        "_actiondate": {
            "dbs": "",
            "typ": "check0",
            "label": L("lcl_mld_actiondate"),
            "defaultvalue": 0,
            "multiedit": true
        },
        "canholdthirdparty": {
            "dbs": "mld_stdmelding_thirdparty",
            "typ": "check0",
            "label": L("lcl_mld_canholdthirdparty"),
						"multiedit": true
        },
        "subjectlist": {
            "dbs": "mld_stdmelding_subject",
            "typ": "key",
            "label": L("lcl_mld_subject"),
            "LOV": "0;" + L("lcl_mld_onzichtbaar") + ";"
                 + "1;" + L("lcl_mld_optioneel")   + ";"
                 + "2;" + L("lcl_mld_verplicht")
                 + ( ((S("ai_enabled") & 1) || mode == "api2") 
                   ? ";3;" 
                   : ";##DISABLED##;"
                   ) + L("lcl_mld_ai_generated"),
            "emptyoption": null,
            "multiedit": true
        },
        "freetext": {
            "dbs": "mld_stdmelding_freetext",
            "typ": "key",
            "label": L("lcl_mld_freetext"),
            "LOV": "0;" + L("lcl_mld_onzichtbaar") + ";"
                 + "1;" + L("lcl_mld_optioneel")   + ";"
                 + "2;" + L("lcl_mld_verplicht"),
            "emptyoption": null,
            "multiedit": true
        },
        "statusobjrequired": {
            "dbs": "ins_srtinst_verplichtstatus",
            "label": L("mld_stdmelding_obj_req_status"),
            "typ": "key",
            "LOV": buildStdmeldingObjReqStatusList(),
            "emptyoption": null
        },
        "hint": {
            "dbs": "mld_stdmelding_hint",
            "typ": "memo",
            "label": L("lcl_mld_hint"),
            "translate": true
        },
        "autoorder": {
            "dbs": "mld_stdmelding_autoorder",
            "typ": "check0",
            "label": L("lcl_mld_autoorder"),
            "multiedit": true
        },
        "autoorderamount": {
            "dbs": "mld_stdmelding_autoorderamount",
            "typ": "float",
            "iscurrency": true,
            "label": L("lcl_mld_autoorderamount"),
            "multiedit": true
        },
        "requireservice": {
            "dbs": "mld_stdmelding_vereisdienst",
            "typ": "check0",
            "label": L("lcl_mld_vereisdienst"),
            "multiedit": true
        },
        "service": {
            "dbs": "prs_dienst_key",
            "typ": "key",
            "label": L("lcl_mld_behandel_dienst"),
            "foreign": {
                "tbl": "(SELECT prs_dienst_key"
                     + "      , prs_dienst_omschrijving"
                     + "   FROM prs_dienst"
                     + "  ORDER BY UPPER(prs_dienst_omschrijving))",
                "key": "prs_dienst_key",
                "desc": "prs_dienst_omschrijving"
            },
            "emptyoption": "",
            "multiedit": true
        },
        "ordertype": {
            "dbs": "mld_typeopdr_key",
            "typ": "key",
            "label": L("lcl_mld_std_typeopdr"),
            "foreign": {
                "tbl": "(SELECT mld_typeopdr_key"
                     + "      , mld_typeopdr_omschrijving"
                     + "   FROM mld_typeopdr"
                     + "  ORDER BY UPPER(mld_typeopdr_omschrijving))",
                "key": "mld_typeopdr_key",
                "desc": "mld_typeopdr_omschrijving"
            },
            "emptyoption": "",
            "multiedit": true
        },
        "regime": {
            "dbs": "mld_stdmelding_regime",
            "typ": "key",
            "label": L("lcl_mld_regime"),
            "LOV": "1;" + L("lcl_mld_office_hours")  + ";"
                 + "2;" + L("lcl_mld_opening_hours") + ";"
                 + "3;" + L("lcl_mld_24_7"),
            "emptyoption": null,
            "multiedit": true
        },
        "fixedmalus": {
            "dbs": "mld_stdmelding_malusbasis",
            "typ": "float",
            "label": L("lcl_mld_malusbasis"),
            "multiedit": true
        },
        "periodmalus": {
            "dbs": "mld_stdmelding_malus",
            "typ": "float",
            "label": L("lcl_mld_malus"),
            "multiedit": true
        },
        "maximummalus": {
            "dbs": "mld_stdmelding_malusmax",
            "typ": "float",
            "label": L("lcl_mld_malusmax"),
            "multiedit": true
        },
        "roomtypedependant": {
            "dbs": "mld_stdmelding_afhankelijk",
            "typ": "check0",
            "label": L("lcl_mld_afh_srtruimte_object"),
            "multiedit": true
        },
        "symbolname": {
            "dbs": "mld_stdmelding_image",
            "typ": "symbol",
            "module": "MLDS",
            "label": L("lcl_mld_symbol_name")
        },
        "colors": {
            "dbs": "mld_stdmelding_color",
            "typ": "color",
            "label": L("lcl_mld_colors")
        },
        "theme": {
            "dbs": "cad_thema_key",
            "typ": "key",
            "label": L("lcl_mld_cadthema"),
            "foreign": {
                "tbl": "cad_thema",
                "key": "cad_thema_key",
                "desc": "cad_thema_omschrijving",
                "where": "BITAND(cad_thema_type, 4) <> 4"
            }
        },
        "closingtext": {
            "dbs": "mld_stdmelding_afmeldtext",
            "typ": "key",
            "label": L("lcl_mld_afmeldtext"),
            "LOV": "1;" + L("lcl_mld_optioneel") + ";"
                 + "2;" + L("lcl_mld_verplicht"),
            "emptyoption": null,
            "multiedit": true
       },
        "sequence": {
            "dbs": "mld_stdmelding_volgnr",
            "typ": "number",
            "label": L("lcl_mld_stdmelding_volgnummer")
        },
        "ownrooms": {
            "dbs": "mld_stdmelding_prseigen",
            "typ": "check0",
            "label": L("lcl_mld_prseigen"),
            "multiedit": true
        },
        "checksimilar": {
            "dbs": "mld_stdmelding_doublecheck",
            "typ": "key",
            "label": L("lcl_mld_doublecheck"),
            "LOV": "0;" + L("lcl_mld_not")         + ";"
                 + "1;" + L("lcl_mld_when_enter")  + ";"
                 + "2;" + L("lcl_mld_when_accept") + ";"
                 + "3;" + L("lcl_mld_when_enter_accept"),
            "emptyoption": null,
            "multiedit": true
        },
        "copyable": {
            "dbs": "mld_stdmelding_kopieerbaar",
            "typ": "check0",
            "label": L("lcl_mld_copyable"),
            "multiedit": true
        },
        "survey": {
            "dbs": "mld_stdmelding_kto",
            "typ": "key",
            "label": L("lcl_mld_in_KTO"),
            "LOV": "0;" + L("lcl_mld_never")  + ";"
                 + "1;" + L("lcl_mld_always") + ";"
                 + "2;" + L("lcl_mld_opt_in") + ";"
                 + "3;" + L("lcl_mld_opt_out")
        },
        "limitcatalogue": {
            "dbs": "bes_ins_discipline_key",
            "typ": "key",
            "label": L("lcl_mld_limited_bes_cat"),
            "foreign": {
                "tbl": "(SELECT d.ins_discipline_key"
                     + "      , ins_discipline_omschrijving"
                     + "   FROM ins_tab_discipline d"
                     + "  WHERE d.ins_discipline_module = 'BES'"
                     + "    AND d.ins_discipline_verwijder IS NULL"
                     + "  ORDER BY UPPER(d.ins_discipline_omschrijving))",
                 "key": "ins_discipline_key",
                 "desc": "ins_discipline_omschrijving"
            },
            "emptyoption": ""
        },
        "expires": {
            "dbs": "mld_stdmelding_vervaldatum",
            "typ": "date",
            "label": L("lcl_mld_expiration_date"),
            "multiedit": true
        },
        "ordertypemandatory": {
            "dbs": "mld_stdmelding_opdrtypevast",
            "typ": "check0",
            "label": L("lcl_mld_opdrtypevast")
        },
        "issuegroup": {
            "dbs": "mld_stdmeldinggroep_key",
            "typ": "key",
            "label": L("lcl_mld_meldinggroep"),
            "foreign": {
                "tbl": "(SELECT g.mld_stdmeldinggroep_key"
                     + ", " + lcl.xsqla("g.mld_stdmeldinggroep_naam", "g.mld_stdmeldinggroep_key")
                     + " FROM mld_stdmeldinggroep g"
                     + " ORDER BY 2)",
                "key": "mld_stdmeldinggroep_key",
                "desc": "mld_stdmeldinggroep_naam"
            },
            "emptyoption": "",
            "showtransit": true,
            "multiedit": true
        },
        "immediateready": {
            "dbs": "mld_stdmelding_directklaar",
            "typ": "number",
            "label": L("lcl_mld_directklaar"),
            "LOV": ";"  + L("lcl_mld_afhankelijk_vakgroep") + ";"
                 + "0;" + L("lcl_No")                       + ";"
                 + "1;" + L("lcl_Yes")                      + ";"
                 + "2;" + L("lcl_mld_initieel_fo"),
            "emptyoption": null,
            "multiedit": true
        },
        "conceptstatus": {
            "dbs": "mld_stdmelding_conceptstatus",
            "typ": "number",
            "label": L("lcl_mld_stdconceptstatus"),
            "LOV": "0;" + L("lcl_mld_stdconceptstatus_0")     + ";"
                 + "1;" + L("lcl_mld_stdconceptstatus_1")     + ";"
                 //+ "2;" + L("lcl_mld_stdconceptstatus_2")     + ";"  UNSUPPORTED, TE LASTIG
                 + "4;" + L("lcl_mld_stdconceptstatus_4")     + ";"
                 + "8;" + L("lcl_mld_stdconceptstatus_8")     + ";"
                 + "16;" + L("lcl_mld_stdconceptstatus_16"),
            "emptyoption": null,
            "multiedit": true
        },
        "monitorsla": {
            "dbs": "mld_stdmelding_slabewaken",
            "typ": "check0",
            "label": L("lcl_mld_slabewaken"),
            "multiedit": true
        },
        "showobject": {
            "dbs": "alg_onrgoed_obj_niveau",
            "typ": "varchar",
            "label": L("lcl_mld_obj_show_niveau"),
            "LOV": ";"  + L("lcl_mld_no_objects") + ";"
                 + "A;" + L("mgt_all")            + ";"
                 + "L;" + L("lcl_ins_controle_from").format(L("lcl_location")) + ";"
                 + "G;" + L("lcl_ins_controle_from").format(L("lcl_building")) + ";"
                 + "V;" + L("lcl_ins_controle_from").format(L("lcl_floor"))    + ";"
                 + "R;" + L("lcl_ins_controle_from").format(L("lcl_room")),
            "emptyisrealvalue": true,
            "emptyoption": null,
            "multiedit": true
        },
        "departmentobjects": {
            "dbs": "alg_org_obj_niveau",
            "typ": "number",
            "label": L("lcl_mld_dep_obj"),
            "LOV": departmentobjects_foreign(),
            "emptyoption": null,
            "multiedit": true
        },
        "personalobjects": {
            "dbs": "mld_stdmelding_prsafdobj",
            "label": L("lcl_mld_org_obj"),
            "typ": "number",
            "LOV": organisationobjects_foreign(),
            "emptyoption": null,
            "multiedit": true
        },
        "objectsallowed": {
            "dbs": "mld_stdmelding_objects_allowed",
            "typ": "number",
            "label": L("mld_stdmelding_objects_allowed"),
            "LOV": L("mld_stdmelding_objects_allowed_LOV"),
            "emptyoption": null,
            "defaultvalue": 2
        },
        "externallink": {
            "dbs": "mld_stdmelding_externurl",
            "typ": "varchar",
            "label": L("lcl_mld_externurl")
        },
        "_limitlabel": {
            "dbs": "",
            "label": "",
            "typ": "label",
            "labelvalue": L("lcl_mld_object_restrict")
        },
        "accepttime": {
            "dbs": "mld_stdmelding_t_accepttijd",
            "obj": "MLD_T_UITVOERTIJD",
            "typ": "processingtime",
            "label": L("lcl_mld_timetoaccept"),
            "multiedit": true
        },
        "criticalaccept": {
            "dbs": "mld_stdmelding_t_accept_pr1",
            "obj": "MLD_T_UITVOERTIJD",
            "typ": "processingtime",
            "label": L("lcl_mld_timetoaccept_kritisch"),
            "multiedit": true
        },
        "highpriorityaccept": {
            "dbs": "mld_stdmelding_t_accept_pr2",
            "obj": "MLD_T_UITVOERTIJD",
            "typ": "processingtime",
            "label": L("lcl_mld_timetoaccept_hoog"),
            "multiedit": true
        },
        "lowpriorityaccept": {
            "dbs": "mld_stdmelding_t_accept_pr4",
            "obj": "MLD_T_UITVOERTIJD",
            "typ": "processingtime",
            "label": L("lcl_mld_timetoaccept_laag"),
            "multiedit": true
        },
        "processingtime": {
            "dbs": "mld_stdmelding_t_uitvoertijd",
            "obj": "MLD_T_UITVOERTIJD",
            "typ": "processingtime",
            "label": L("lcl_mld_uitvoertijd_normaal"),
            "required": true,
            "multiedit": true
        },
        "criticaltime": {
            "dbs": "mld_stdmelding_t_uitvtijd_pr1",
            "obj": "MLD_T_UITVOERTIJD",
            "typ": "processingtime",
            "label": L("lcl_mld_uitvoertijd_kritisch"),
            "multiedit": true
        },
        "highprioritytime": {
            "dbs": "mld_stdmelding_t_uitvtijd_pr2",
            "obj": "MLD_T_UITVOERTIJD",
            "typ": "processingtime",
            "label": L("lcl_mld_uitvoertijd_hoog"),
            "multiedit": true
        },
        "lowprioritytime": {
            "dbs": "mld_stdmelding_t_uitvtijd_pr4",
            "obj": "MLD_T_UITVOERTIJD",
            "typ": "processingtime",
            "label": L("lcl_mld_uitvoertijd_laag"),
            "multiedit": true
        },
        "bypriomatrix": {
            "dbs": "mld_stdmelding_priomatrix",
            "typ": "check0",
            "label": L("lcl_mld_stdpriomatrix"),
            "multiedit": true
        },
        "bytag": {
            "dbs": "mld_stdmelding_taggable",
            "typ": "number",
            "label": L("lcl_mld_stdtaggable"),
            "LOV": "0;" + L("lcl_mld_stdtaggable0")  + ";"
                 + "1;" + L("lcl_mld_stdtaggable1")  + ";"
                 + "3;" + L("lcl_mld_stdtaggable3"),
            "emptyoption": null,
            "multiedit": true
        },
        "enddateempty": {
            "dbs": "mld_stdmelding_enddate_empty",
            "typ": "check0",
            "label": L("lcl_mld_enddate_empty"),
            "multiedit": true
        },
        "code": {
            "dbs": "mld_stdmelding_code",
            "typ": "varchar",
            "label": L("lcl_mld_code"),
            "readonly": !user.has("WEB_FACTAB")
        },
        "externnr": {
            "dbs": "mld_stdmelding_externnr",
            "typ": "varchar",
            "label": L("extern_nr")
        },
        "externsyncdate": {
            "dbs": "mld_stdmelding_externsyncdate",
            "typ": "datetime",
            "label": L("extern_syncdate"),
            "readonly": !(user.has("WEB_FACTAB") || user.has("WEB_FACXNR"))
        }
    };

    this.includes = {
        "disciplines": {
            "model": new model_mld_dienstpakket(),
            "joinfield": "issuetype",
            "enable_update": true,
            "multiadd": "level"
        },
        "roomfunctions": {
            "model": new model_mld_stdmelding_srtruimte(),
            "joinfield": "issuetype",
            "enable_update": true,
            "multiadd": "level"
        }
    };

    var xparams = {
        GET: {
            tables: [ "ins_tab_discipline, mld_disc_params, ins_srtdiscipline"],
            wheres: [ "ins_tab_discipline.ins_discipline_key = mld_stdmelding.mld_ins_discipline_key",
                      "mld_disc_params.mld_ins_discipline_key = mld_stdmelding.mld_ins_discipline_key",
                      "ins_tab_discipline.ins_srtdiscipline_key = ins_srtdiscipline.ins_srtdiscipline_key",
                      "ins_tab_discipline.ins_discipline_verwijder IS NULL",
                      "ins_srtdiscipline.ins_srtdiscipline_verwijder IS NULL"
                    ]
        }
    };

    this.hook_pre_edit = function(obj, fld, scf_params)
    {
        scf_params.layout.block[0].label += " " +obj.id ;
        obj.canrefer = translate_canrefer(obj.canrefer, null);
        var lobj = translate_plannable(obj.plannable, null, null);
        obj.plannable = lobj.plannable;
        obj._actiondate = lobj._actiondate;
        var srtdisc_key = -1;
        var disc_key = -1;

        obj._is_clone = getQParamInt("scf_clone", 0);
        var stdm_id = (obj._is_clone == 1 ? getQParamInt("id", -1) : obj.id);

        if (stdm_id > 0)
        {
            stdm_info = mld.mld_stdmeldinginfo(stdm_id);
            srtdisc_key = stdm_info.ins_srtdiscipline_key;
            disc_key = stdm_info.ins_discipline_key;
            // Hier hebben we echt de waarde van mld_stdmelding_directklaar nodig,
            // en niet de defaultwaarde uit mld_disc_params_directklaar.
            var sql = "SELECT mld_stdmelding_directklaar"
                    + "  FROM mld_stdmelding"
                    + " WHERE mld_stdmelding_key = " + stdm_id;
            var oRs = Oracle.Execute(sql);
            stdm_info.directklaar = oRs("mld_stdmelding_directklaar").Value;
            oRs.Close();
            fld.limitcatalogue.foreign.tbl = limitcatalogue_foreign(stdm_info);
        }

%>
  <script>
    var srtinstallatieselector_available = 1; // toon alleen actuele disciplines/groepen en objecten.
    var disciplinetype_key = <%=srtdisc_key%>;
    var discipline_key = <%=disc_key%>;
  </script>
<%
    }

    this.hook_pre_multi_edit = function (obj, fld, scf_params)
    {
%>
  <script>
    var srtinstallatieselector_available = 0;
  </script>
<%
    }

    this.hook_pre_show = function(obj, fld, scf_params)
    {
        scf_params.layout.block[0].label += " " +obj.id;
        obj.canrefer = (obj.canrefer.id != 0 ? translate_canrefer(obj.canrefer, null) : null);
        var lobj = translate_plannable(obj.plannable, null, null);
        obj.plannable = lobj.plannable;
        obj._actiondate = lobj._actiondate;
    }

    // ? deze functie als parameter aan foreign/multiselect meegeven?
    function translate_canrefer(db_value, lb_arr)
    { // Kan verwijzen naar meerdere referenties (modules).
      if (db_value)
      { // Vertalen van databasewaarde naar multiselectbox waarde.
        // mld_stdmelding_kanverwijzen is een multiselect-box. Hieraan moet een string met keys worden doorgegeven.
        // Converteer de bitjes naar string met keys.
        var kanverwijzen = { id: "", name: "" };
        if (db_value.id > -1)
        {
          for (var i = 1; i < 256; i = i * 2)
          { // Een string met keys maken.
            kanverwijzen.id   += ((db_value.id & i) == i? ((kanverwijzen.id   == ""? "" : "," ) + i) : "");
            kanverwijzen.name += ((db_value.id & i) == i? ((kanverwijzen.name == ""? "" : ", ") + mld.getrefmoduletext(i)) : "");
          }
        }
        else
        {
          kanverwijzen = { id: -1, name: L("lcl_none") };
        }
      }
      else
      { // Vertalen van multiselectbox waarde naar databasewaarde.
        var kanverwijzen = 0;
        for (var i = 0; i < lb_arr.length; i++)
        {
          if (lb_arr[i] > 0)
          {
            kanverwijzen += lb_arr[i];
          }
        }
        if (kanverwijzen > 128)
          kanverwijzen = 128; // { id: 128, name:  mld.getrefmoduletext(128) };
      }

      return kanverwijzen;
    }

    function translate_plannable(db_plannable, lb_plannable, lb_actiondate, key)
    {
      var std_key = key || -1;
      var lobj = { plannable: {}
                 , result: 0
                 };

      if (db_plannable)
      { // Voor PRE_SHOW en PRE_EDIT. Het databaseveld splitsen in 2 schermvelden.
        lobj.result         = db_plannable.id;
        lobj._actiondate    = ( ((lobj.result & 4) == 4) ? 1 : 0);
        lobj.plannable.id   = ( ((lobj.result & 4) == 4) ? lobj.result -4 : lobj.result );
        lobj.plannable.name = api2.splitLOV(L("lcl_mld_planbaarLOV"))[lobj.plannable.id];
      }
      else
      { // Voor PRE_POST en PRE_PUT. De 2 schermvelden samenvoegen tot 1 databaseveld
        if (std_key > -1)
        { // Huidige waarde van databaseveld ophalen.
          var sql = "SELECT mld_stdmelding_planbaar"
                  + "  FROM mld_stdmelding"
                  + " WHERE mld_stdmelding_key = " + std_key;
          var oRs = Oracle.Execute(sql);
          if (!oRs.eof)
          {
            lobj.result = oRs("mld_stdmelding_planbaar").Value;
          }
          oRs.Close();
          lobj._actiondate    = ( ((lobj.result & 4) == 4) ? 4 : 0);
          lobj.plannable.id   = lobj.result - lobj._actiondate;
        }

        lobj.plannable.id = (lb_plannable != null  ? lb_plannable : lobj.plannable.id);
        lobj._actiondate  = (lb_actiondate != null ? (lb_actiondate ? 4 : 0) : lobj._actiondate);
        lobj.result       = lobj.plannable.id + lobj._actiondate;
      }

      return lobj;
    }

    this.hook_pre_post = function(scf_params, obj)
    { // toevoegen
      var canrefer_arr = getFParamIntArray("canrefer", [-1]);
      obj.canrefer = translate_canrefer(null, canrefer_arr);
      var plannable = getFParamInt("plannable", 0);
      var actiondate = getFParamInt("has__actiondate", 0) == 1 && (Request.Form("_actiondate").count == 1);
      var lobj = translate_plannable(null, plannable, actiondate);
      obj.plannable = lobj.plannable;
    }
    this.hook_post_post = function(scf_params, obj, key)
    {
    }
    this.hook_pre_put = function(scf_params, obj, key)
    { // wijzigen
      if (!hasFParam("scf_multi")) // Voorkom dat multi-edit het veld canrefer leeg maakt.
      {
        var canrefer_arr = getFParamIntArray("canrefer", [-1]);
        obj.canrefer = translate_canrefer(null, canrefer_arr);
      }

      var plannable = getFParamInt("plannable", null);
      var actiondate = ( hasFParam("scf_multi") && !hasFParam("_actiondate") && !hasFParam("scf_multi__actiondate")
                       ? null
                       : (getFParamSafe("_actiondate", "") == "on" ? 1 : 0)
                       );
      var lobj = translate_plannable(null, plannable, actiondate, key);
      obj.plannable = lobj.result;
    }
    this.hook_pre_delete = function(scf_params, key)
    {
    }
    this.hook_pre_search = function(fld)
    {
    }



    this.REST_GET    = generic_REST_GET(this, xparams);
    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this);


    function departmentobjects_foreign()
    {
        var tbl = "-1;" + L("lcl_mld_all_objects") + ";"
                + "0;"  + L("lcl_ins_controle_from").format(L("lcl_company"));
        for (var i = 1; i <= S("prs_max_dep_level"); i++)
            tbl += ";" + i + ";" + L("lcl_ins_controle_from").format(L("lcl_dep_name_level" + i));
        tbl += ";8;" + L("lcl_ins_controle_from").format(L("prs_perslid"));
        return tbl;
    }

    function organisationobjects_foreign()
    {
        var tbl = "0;" + L("lcl_obj_no_deptpers") + ";"
                + "1;" + L("lcl_obj_department") + ";"
                + "2;" + L("lcl_obj_person") + ";"
                + "3;" + L("lcl_obj_department") +" + "+ L("lcl_obj_person");
        return tbl;
    }

    function limitcatalogue_foreign(stdm_info)
    {
        tbl = "(SELECT d.ins_discipline_key"
            + "      , ins_discipline_omschrijving"
            + "   FROM ins_tab_discipline d"
            + "  WHERE d.ins_discipline_module = 'BES'"
            + "    AND d.ins_discipline_verwijder IS NULL"
            + "    AND EXISTS (SELECT 1"
            + "                  FROM mld_discipline md"
            + "                     , ins_srtdiscipline isd"
            + "                 WHERE md.ins_srtdiscipline_key = isd.ins_srtdiscipline_key"
            + "                   AND isd.ins_srtdiscipline_bes = 1"
            + "                   AND md.ins_discipline_key = " + stdm_info.ins_discipline_key + ")"
            + "  ORDER BY UPPER(d.ins_discipline_omschrijving))";
        return tbl;
    }

    function canrefer_LOV()
    {
        var tbl = "128;" + mld.getrefmoduletext(128) + ";"  /* Alle meldingen */
                + "1;"   + mld.getrefmoduletext(1)   + ";"  /* [M] Eigen meldingen */
                + "2;"   + mld.getrefmoduletext(2)   + ";"  /* [O] Opdracht */
                + "4;"   + mld.getrefmoduletext(4)   + ";"  /* [R] Reservering */
                + "8;"   + mld.getrefmoduletext(8)   +  ";" /* [B] Bestelling */
             // + "16;"  + mld.getrefmoduletext(16)   + ";"  /* [X] Bestelopdracht :reserved for future use */
                + "32;"  + mld.getrefmoduletext(32)         /* [C] Contract */
             // + "64;"  + mld.getrefmoduletext(64)  + ";" /* [F] Factuur        :reserved for future use */
              /*     0: Geen verwijzingen */
        return tbl;
    }

    function canUseTeams()
    {
        var sql = "SELECT 1"
                + "  FROM DUAL"
                + " WHERE EXISTS"
                + "           (SELECT 1"
                + "              FROM mld_disc_params dp1, mld_discipline d1"
                + "             WHERE d1.ins_discipline_key = dp1.mld_ins_discipline_key"
                + "               AND d1.ins_discipline_verwijder IS NULL"
                + "               AND BITAND (dp1.mld_disc_params_srtgroep, 2) = 2)" // Is team
                + "   AND EXISTS"
                + "           (SELECT 1"
                + "              FROM mld_disc_params dp2, mld_discipline d2"
                + "             WHERE d2.ins_discipline_key = dp2.mld_ins_discipline_key"
                + "               AND d2.ins_discipline_verwijder IS NULL"
                + "               AND BITAND (dp2.mld_disc_params_srtgroep, 4) = 4)" // Has team
                + "   AND ROWNUM <= 1";
        var oRs = Oracle.Execute(sql);
        var canUseTeams = !oRs.EoF;
        oRs.Close();
        return canUseTeams;
    }
}
%>