Files
Facilitor/APPL/API2/model_persons.inc
Jos Groot Lipman 095b4850e6 FSN#36665 AiAi 'INTERNAL_ERROR_PNIVEAU' is undefined
svn path=/Website/branches/v2016.1/; revision=29564
2016-05-30 10:32:37 +00:00

146 lines
7.6 KiB
PHP

<% /*
$Revision$
$Id$
File: model_persons.inc
Description: Perslid model.
Parameters:
Context:
- Notes: - We ondersteunen nog alleen opvragen van je eigen gegevens
- Standaard voegen we de gegevens van de hoofdwerkplek toe
- Ooit doen we er nog een include bij van alle werkplekken.
*/
%>
<!-- #include file="../Shared/discxalg3d.inc"-->
<!-- #include file="../api2/model_custom_fields.inc"-->
<!-- #include file="../api2/model_tracking.inc"-->
<!-- #include file="../api2/model_fac_gebruikersgroep.inc" -->
<%
function fnApiToken(oRs, field, model)
{
var hmac = protectHMAC.create(oRs("prs_perslid_oslogin").Value, { sleutel: oRs("prs_perslid_apikey").Value });
return hmac;
}
function genderLOV()
{
var s = ";" + L("lcl_prs_person_geslachtO")
+ ";0;" + L("lcl_prs_person_geslachtV")
+ ";1;" + L("lcl_prs_person_geslachtM");
return s;
}
function model_persons()
{
this.table = "prs_perslid";
this.primary = "prs_perslid_key";
this.records_name = "persons";
this.record_name = "person";
this.record_title = L("prs_perslid");
this.records_title = L("prs_perslid_m");
this.fields = {
"id" : { dbs: "prs_perslid_key", "label": "Key", typ: "key", filter: "exact"},
"name" : { dbs: "pf.prs_perslid_naam_friendly", "label": L("lcl_prs_person_name"), typ: "varchar" },
"lastname" : {
dbs: "prs_perslid_naam",
label: "Achternaam", // L("lcl_prs_person_achternaam")
typ: "varchar",
filter: "like"},
"firstname" : { dbs: "prs_perslid_voornaam", "label": L("lcl_prs_person_voornaam"), typ: "varchar", filter: "like"},
"title" : { dbs: "prs_perslid_titel", "label": L("lcl_prs_person_title"), typ: "varchar" },
"initials" : { dbs: "prs_perslid_voorletters", "label": L("lcl_prs_person_initials"), typ: "varchar" },
"prefix" : { dbs: "prs_perslid_tussenvoegsel", "label": L("lcl_prs_person_tussen"), typ: "varchar" },
"gender" : { dbs: "prs_perslid_geslacht", "label": L("lcl_prs_person_geslacht"), typ: "varchar", LOV: genderLOV() },
"language" : { dbs: "prs_perslid_lang", "label": L("lcl_lcl_taal"), typ: "varchar" },
"phone" : { dbs: "prs_perslid_telefoonnr", "label": L("lcl_prs_person_phone"), typ: "varchar" },
"mobile" : { dbs: "prs_perslid_mobiel", "label": L("lcl_prs_person_mobile"), typ: "varchar" },
"email" : { dbs: "prs_perslid_email", "label": L("lcl_prs_person_email"), typ: "varchar", filter: "exact"},
"login" : { dbs: "prs_perslid_oslogin", "label": L("lcl_prs_person_login"), typ: "varchar", filter: "like"},
"employment": { dbs: "prs_perslid_dienstverband", "label": L("lcl_prs_person_dienstverband"), typ: "float" },
"startdate" : { dbs: "prs_perslid_ingangsdatum", "label": L("lcl_prs_person_ingangsdatum"), typ: "date" },
"enddate" : { dbs: "prs_perslid_einddatum", "label": L("lcl_prs_person_einddatum"), typ: "date" },
"function" : { dbs: "prs_srtperslid_key", "label": L("lcl_prs_person_function"), typ: "key", foreign: { tbl: "prs_srtperslid", key: "prs_srtperslid_key", desc: "prs_srtperslid_omschrijving"} },
"department": { dbs: "prs_afdeling_key", "label": L("lcl_prs_organisatie"), typ: "key", foreign: "prs_afdeling"},
"company" : { dbs: "pa.prs_bedrijf_key", "label": L("lcl_prs_company"), typ: "key", foreign: "prs_bedrijf"},
"location" : { dbs: "wg.alg_locatie_key", "label": L("lcl_location"), typ: "key", foreign: "alg_locatie", filter: "exact"},
"building" : { dbs: "wg.alg_gebouw_key", "label": L("lcl_building"), typ: "key", foreign: "alg_gebouw" },
"floor" : { dbs: "wg.alg_verdieping_key", "label": L("lcl_floor"), typ: "key", foreign: "alg_verdieping" },
"room" : { dbs: "wg.alg_ruimte_key", "label": L("lcl_room"), typ: "key", foreign: "alg_ruimte" }
};
this.includes = {
"authorization": {
"model": new model_fac_gebruikersgroep(),
"joinfield": "user"
},
"custom_fields" : {
"model": new model_custom_fields(this, "PRS", { readman: true, readuse: true, pNiveau: "P" }),
"joinfield": "flexparentkey"
},
"tracking": {
"model": new model_tracking(["perslid"]),
"joinfield": "fac_tracking_refkey"
}
};
this.REST_GET = function _GET(params)
{
//var urole = "fe"; // TODO: Moet echt niet ter zake doen
//var autfunction = urole == "fe"? "WEB_ALGUSE" : "WEB_ALGMAN";
//params.authparams = user.checkAutorisation(autfunction, null, null, true); // pessimistisch
if (app_user_key > 0) // Alleen App's mogen dit opvragen. TODO: Ook echt authorisatie controleren?
{
if (user.prs_perslid_apikey() && user.oslogin())
{
this.fields["authtoken"] = { dbs: "prs_perslid_apikey", typ: "varchar", val: fnApiToken };
}
}
var query = api2.sqlfields(params, this);
query.tables.push("prs_v_perslid_fullnames_all pf");
query.wheres.push("pf.prs_perslid_key(+) = prs_perslid.prs_perslid_key");
query.tables.push("prs_v_werkplek_gegevens wg");
query.tables.push("prs_v_afdeling pa");
query.wheres.push("pa.prs_afdeling_key = prs_perslid.prs_afdeling_key");
query.tables.push("prs_v_hoofdperslidwerkplek pw");
query.wheres.push("pw.prs_perslid_key(+) = prs_perslid.prs_perslid_key");
query.wheres.push("pw.prs_werkplek_key = wg.prs_werkplek_key(+)");
if (!user.checkAutorisation("WEB_PRSSYS", true)) // PAS OP: Dit verwacht AAFM-API niet!!!
query.wheres.push("prs_perslid.prs_perslid_key = " + user_key); // Altijd fe vooralnog, TODO: Add authorization
else
query.wheres.push("prs_perslid.prs_perslid_verwijder IS NULL");
var wheres = api2.sqlfilter(params, this);
query.wheres = query.wheres.concat(wheres);
var sql = "SELECT " + query.selects.join(", ")
+ " FROM " + query.tables.join(", ")
+ " WHERE " + query.wheres.join(" AND " )
+ " ORDER BY prs_perslid.prs_perslid_naam, prs_perslid.prs_perslid_voornaam, prs_perslid_key";
if (query.orderbys.length)
sql += ", " + query.orderbys.join(", ");
var json = api2.sql2json (params, sql, this);
return json;
};
this.PUT = function (params) /* update perslid */
{
// Nog niet ondersteund
};
this.POST = function (params) /* new perslid */
{
// Nog niet ondersteund
};
this.DELETE = function (params) /* delete perslid */
{
// Nog niet ondersteund
};
}
%>