VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/keeview_app/html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/keeview_app/html/data_module_cache.js
data_module.nextThread = function (callbackfunc, nextThread) {
    if (EncodingClass.type.isFunction(callbackfunc)) {
        try {
            callbackfunc();
        }
        catch (e) {
            console.log(e);
        }
    }
    Thread.setTimeout({func: nextThread});
}

data_module.getIDList = function (name) {
    if (data_module["cacheContent_" + name] !== undefined) return data_module["cacheContent_" + name].getIDList();
    return [];
}

data_module.getContent = function (name, id) {
    if (data_module["cacheContent_" + name] === undefined) return undefined;
    return data_module["cacheContent_" + name].read(id);
}

data_module.loadPartnerFunc = function (params) {
    var sort = (params.sort === true);
    var finalize, process;
    if (params.finalize === undefined) {
        finalize = function () {};
    }
    else {
        finalize = params.finalize;
    }
    if (params.process === undefined) {
        process = function () {};
    }
    else {
        process = params.process;
    }
    data_module.loadTables(
        ["partners", "partner_class_links"],
        function (sort, process, finalize) {
            return function () {
                var mark = {};
                var keys, id, i, j, t;
                var r = [];
                var host, sortFunction, processFunction, finalizeFunction;
                keys = data_module.getIDList("partners");
                for (i = 0; i < keys.length; i++) {
                    id = keys[i];
                    t = data_module.getContent("partners", id);
                    if (t.available != 1) continue;
                    delete t.uts;
                    mark[id] = {
                        data: t,
                        links: []
                    };
                    r.push(id);
                }
                keys = data_module.getIDList("partner_class_links");
                for (i = 0; i < keys.length; i++) {
                    t = data_module.getContent("partner_class_links", keys[i]);
                    id = t.partnerid;
                    if (mark[id] !== undefined) {
                        delete t.uts;
                        mark[id].links.push(t);
                    }
                }
                for (i = 0; i < r.length; i++) {
                    id = r[i];
                    mark[id].links.sort((a, b) => (a.id - b.id));
                }
                if (sort) {
                    sortFunction = function (mark) {
                        return function (a, b) {
                            var t = mark[a].data.name.localeCompare(mark[b].data.name, undefined, {numeric: true, sensitivity: 'base'});
                            if (t != 0) return t;
                            if (mark[a].data.name < mark[b].data.name) return -1;
                            if (mark[a].data.name > mark[b].data.name) return 1;
                            return a - b;
                        }
                    } (mark);
                }
                else {
                    sortFunction = (a, b) => (a - b);
                }
                r.sort(sortFunction);
                finalizeFunction = function (mark, r, finalize) {
                    return function () {
                        var partners = [], links = [];
                        var i, j, id;
                        for (i = 0; i < r.length; i++) {
                            id = r[i];
                            partners.push(mark[id].data);
                            for (j = 0; j < mark[id].links.length; j++) {
                                links.push(mark[id].links[j]);
                            }
                        }
                        try {
                            finalize({
                                partner: partners,
                                partner_class_links: links
                            });
                        }
                        catch (e) {
                            console.log("error", e);
                        }
                    }
                } (mark, r, finalize);
                host = {
                    mark: mark,
                    r: r,
                    finalizeFunction: finalizeFunction,
                    process: process
                }
                host.processFunction = function (host) {
                    return function (index) {
                        var i, j, n, id, f = false;
                        var pagelength = 500;
                        var partners = [], links = [];
                        n = index + pagelength;
                        if (n >= r.length) {
                            f = true;
                            n = r.length;
                        }
                        for (i = index; i < n; i++) {
                            id = r[i];
                            partners.push(mark[id].data);
                            for (j = 0; j < mark[id].links.length; j++) {
                                links.push(mark[id].links[j]);
                            }
                        }
                        try {
                            process({
                                finished: f,
                                partner: partners,
                                partner_class_links: links
                            });
                        }
                        catch (e) {
                            console.log("error", e);
                        }
                        if (f) {
                            setTimeout(function (host) {
                                return function () {
                                    host.finalizeFunction();
                                }
                            } (host), 10);
                            return;
                        }
                        setTimeout(function (host, index) {
                            return function () {
                                host.processFunction(index);
                            }
                        } (host, index + pagelength), 10);
                    }
                } (host);
                setTimeout(function (host, index) {
                    return function () {
                        host.processFunction(index);
                    }
                } (host, 0), 10);
            }
        } (sort, process, finalize)
    );
}

data_module.loadContactFunc = function (params) {
    var sort = (params.sort === true);
    var finalize, process;
    if (params.finalize === undefined) {
        finalize = function () {};
    }
    else {
        finalize = params.finalize;
    }
    if (params.process === undefined) {
        process = function () {};
    }
    else {
        process = params.process;
    }
    data_module.loadTables(
        ["contacts"],
        function (sort, process, finalize) {
            return function () {
                var keys, id, i, j, t;
                var r = [];
                var host, sortFunction, processFunction, finalizeFunction;
                keys = data_module.getIDList("contacts");
                for (i = 0; i < keys.length; i++) {
                    id = keys[i];
                    t = data_module.getContent("contacts", id);
                    if (t.available != 1) continue;
                    delete t.uts;
                    r.push(t);
                }
                if (sort) {
                    sortFunction = function (a, b) {
                        var t = a.name.localeCompare(b.name, undefined, {numeric: true, sensitivity: 'base'});
                        if (t != 0) return t;
                        if (a.name < b.name) return -1;
                        if (a.name > b.name) return 1;
                        return a.id - b.id;
                    }
                }
                else {
                    sortFunction = (a, b) => (a.id - b.id);
                }
                r.sort(sortFunction);
                finalizeFunction = function (r, finalize) {
                    return function () {
                        try {
                            finalize(r);
                        }
                        catch (e) {
                            console.log("error", e);
                        }
                    }
                } (r, finalize);
                host = {
                    r: r,
                    finalizeFunction: finalizeFunction,
                    process: process
                }
                host.processFunction = function (host) {
                    return function (index) {
                        var i, n, f = false;
                        var pagelength = 500;
                        n = index + pagelength;
                        if (n >= r.length) {
                            f = true;
                            n = r.length;
                        }
                        var rv = [];
                        for (i = index; i < n; i++) {
                            rv.push(r[i]);
                        }
                        try {
                            process({
                                finished: f,
                                contact: rv
                            });
                        }
                        catch (e) {
                            console.log("error", e);
                        }
                        if (f) {
                            setTimeout(function (host) {
                                return function () {
                                    host.finalizeFunction();
                                }
                            } (host), 10);
                            return;
                        }
                        setTimeout(function (host, index) {
                            return function () {
                                host.processFunction(index);
                            }
                        } (host, index + pagelength), 10);
                    }
                } (host);
                setTimeout(function (host, index) {
                    return function () {
                        host.processFunction(index);
                    }
                } (host, 0), 10);
            }
        } (sort, process, finalize)
    );
}

data_module.loadObjectFunc = function (params) {
    var idlist = [];
    var i;
    for (i = 0; i < params.objectsList.length; i++) {
        idlist.push(params.objectsList[i].id);
    }
    data_module.loadTables(
        ["objects"],
        function (idlist, func) {
            return function () {
                var content = [];
                var id, i, t;
                for (i = 0; i < idlist.length; i++) {
                    id = idlist[i];
                    if (data_module.cacheContent_objects.exists(id)) {
                        t = data_module.getContent("objects", id);
                        delete t.uts;
                        content.push({
                            id: t.id,
                            work_flowid: t.work_flowid,
                            name: t.name,
                            priority: t.priority,
                            assign_to: t.assign_to,
                            period: t.period,
                            closed: t.closed
                        });
                    }
                }
                Thread.setTimeout({
                    func: func,
                    args: [true, {objects: content}]
                });
            }
        } (idlist, params.func)
    );
}

data_module.loadAllObjects = function (callbackfunc) {
    data_module.loadTables(
        ["objects"],
        function () {
            data_module.cacheContent_objects.psearch({
                searchFunc: function(record){
                    return {
                        id: record.id,
                        name: record.name
                    };
                },
                callbackfunc: function(values){
                    callbackfunc(true, values);
                }
            });
        }
    );
}

data_module.loadObjectsList = function () {
    var host = {};
    data_module.loadAllObjects(function (host) {
        return function (success, content) {
            if (success) {
                if (host.rs !== undefined) {
                    host.rs(content);
                    return;
                }
                host.content = content;
            }
            else {
                console.log(content);
            }
        }
    } (host));
    return new Promise(function (host) {
        return function (rs, rj) {
            if (host.content !== undefined) {
                rs(host.content);
                return;
            }
            host.rs = rs;
            host.rj = rj;
        }
    } (host));
}

data_module.loadAllUsers = function (callbackfunc) {
    FormClass.api_call({
        url: "database_load.php",
        params: [
            {name: "task", value: "get_all_users"}
        ],
        func: function (callbackfunc) {
            return function (success, message) {
                var content;
                if (success) {
                    if (message.substr(0, 2) == "ok") {
                        message = EncodingClass.base64.decode(message.substr(2));
                        content = EncodingClass.number.toTable(message);
                        callbackfunc(content);
                    }
                    else {
                        console.log(message);
                    }
                }
                else {
                    console.log(message);
                }
            }
        } (callbackfunc)
    });
}

data_module.loadCommentList = function () {
    var host = {};
    host.loadUsers = function (host) {
        return function () {
            data_module.loadAllUsers(function (host) {
                return function (content) {
                    host.users = content;
                    setTimeout(function (host) {
                        return function () {
                            host.loadOrgTree();
                        }
                    } (host), 1);
                }
            } (host));
        }
    } (host);
    host.loadOrgTree = function (host) {
        return function () {
            data_module.loadOrgsTree(function (host) {
                return function (content) {
                    host.orgtree = content;
                    Thread.setTimeout({func: host.loadComments});
                }
            } (host));
        }
    } (host);
    host.loadComments = function (host) {
        return function () {
            FormClass.api_call({
                url: "database_load.php",
                params: [
                    {name: "task", value: 'load_comment_notifications_by_user'}
                ],
                func: function (success, message) {
                    if (success){
                        if (message.substr(0, 2) == 'ok') {
                            message = EncodingClass.base64.decode(message.substr(2));
                            var content = EncodingClass.number.toTable(message);
                            var i, n = content.length;
                            var notifications = [], unread = [];
                            var lastseen = -1, t;
                            for (i = 0; i < n; i++) {
                                notifications.push(content[i]);
                                if (content[i].seen == 1) {
                                    //t = content[i].readtime.getTime();
                                    //if (lastseen < t) lastseen = t;
                                }
                            }
                            for (i = 0; i < n; i++) {
                                if (content[i].seen == 0) unread.push(content[i]);
                                /*
                                if ((content[i].seen == 0) && (content[i].readtime.getTime() >= lastseen)) {
                                    unread.push(content[i]);
                                }
                                */
                            }
                            notifications.sort(function (a, b) {
                                return b.createdtime.getTime() - a.createdtime.getTime();
                            });
                            host.comment_notifications = [];
                            for (i = 0; (i < n) && (i < 15); i++) {
                                host.comment_notifications.push(notifications[i]);
                            }
                            host.number_of_unread = unread.length;

                            setTimeout(function (host) {
                                return function () {
                                    host.finalize();
                                }
                            } (host), 1);
                        }
                        else {
                            console.log(message);
                        }
                    }
                    else {
                        console.log(message);
                    }
                }
            });
        }
    } (host);
    host.finalize = function (host) {
        return function () {
            host.rs({
                users: host.users,
                orgs: host.orgtree.orgs,
                employees: host.orgtree.employees,
                peoples: host.orgtree.peoples,
                comment_notifications: host.comment_notifications,
                number_of_unread: host.number_of_unread
            });
        }
    } (host);
    return new Promise(function (host) {
        return function(rs, rj) {
            host.rs = rs;
            host.rj = rj;
            setTimeout(function (host) {
                return function () {
                    host.loadUsers();
                }
            } (host), 1);
        }
    } (host));
};

data_module.loadAllObjectByWorkFlowFunc = function (params) {
    data_module.loadTables(
        ["objects", "object_permissions"],
        function (wfid, func) {
            return function () {
                data_module.cacheContent_objects.psearch({
                    extraParams: {
                        work_flowid: wfid
                    },
                    searchFunc: function(record){
                        if (extraParams.work_flowid == record.work_flowid && record.closed == 0){
                            return {
                                id: record.id,
                                assign_to: record.assign_to,
                                closed: record.closed
                            };
                        }
                        else {
                            return null;
                        }
                    },
                    callbackfunc: function(objects){
                        var markedObj = {};
                        for (var i = 0; i < objects.length; i++){
                            markedObj[objects[i].id] = true;
                        }
                        objects.sort((a, b) => (a.id - b.id));
                        var object_permissions = [];
                        data_module.cacheContent_object_permissions.psearch({
                            extraParams: {
                                markedObj: markedObj
                            },
                            searchFunc: function(record){
                                if (extraParams.markedObj[record.objectid]){
                                    return record;
                                }
                                else {
                                    return null;
                                }
                            },
                            callbackfunc: function(object_permissions){
                                object_permissions.sort((a, b) => (a.id - b.id));
                                markedObj = null;
                                FormClass.api_call({
                                    url: "database_load.php",
                                    params: [
                                        {name: "task", value: "work_flows_load_all_subdata"},
                                        {name: "id", value: wfid}
                                    ],
                                    func: function (objects, object_permissions, func) {
                                        return function (success, message) {
                                            var content;
                                            if (message.substr(0, 2) == "ok") {
                                                content = EncodingClass.string.toVariable(message.substr(2));
                                                content.objects = objects;
                                                content.object_permissions = object_permissions;
                                                setTimeout(function (func, content) {
                                                    return function () {
                                                        func(true, content);
                                                    }
                                                } (func, content), 10);
                                            }
                                            else {
                                                setTimeout(function (func, message) {
                                                    return function () {
                                                        func(false, message);
                                                    }
                                                } (func, message), 10);
                                            }
                                        }
                                    } (objects, object_permissions, func)
                                });
                            }
                        });
                    }
                });
            }
        } (params.id, params.func)
    );
}

data_module.loadMeetingListLazySimpleData = function () {
    var host = {};
    host.finish = function (host) {
        return function () {
            var keys, i, r, n;
            if (host.rs === undefined) {
                Thread.setTimeout({
                    func: host.finish
                });
                return;
            }
            keys = data_module.getIDList("meetings");
            r = [];
            for (i = 0; i < n; i++) {
                t = data_module.getContent("meetings", keys[i]);
                if (t.uts !== undefined) {
                    delete t.uts;
                    r.push(t);
                }
            }
            host.rs(r);
        }
    } (host);
    data_module.loadTables(
        ["meetings"],
        function (host) {
            return function () {
                Thread.setTimeout({
                    func: host.finish
                });
            }
        } (host)
    );
    return new Promise(function (host) {
        return function(rs, rj) {
            host.rs = rs;
            host.rj = rj;
        }
    } (host));
}

//data_module.loader = fcache.open("keeview_" + client_code + "_hr", "dload.php");

data_module.getTables = function (tables, callbackfunc) {
    var host = {
        tables: [],
        callbackfunc: callbackfunc
    }
    var i;
    host.fetch = function (host) {
        return function (name, index) {
            var i;
            if (data_module["cacheConnector_" + name] === true) {
                data_module["cacheConnector_" + name] = false;
                data_module["cacheContent_" + name].load(function (index) {
                    return function () {
                        data_module["cacheConnector_" + name] = true;
                        host.tables[index].ready = true;
                        for (i = 0; i < host.tables.length; i++) {
                            if (!host.tables[i].ready) return;
                        }
                        Thread.setTimeout({func: host.callbackfunc});
                    }
                } (index));
            }
            else {
                Thread.setTimeout({
                    func: host.fetch2,
                    args: [name, index],
                    time: 2
                });
            }
        }
    } (host);

    host.fetch2 = function (host) {
        return function (name, index) {
            var i;
            if (data_module["cacheConnector_" + name] === true) {
                host.tables[index].ready = true;
                for (i = 0; i < host.tables.length; i++) {
                    if (!host.tables[i].ready) return;
                }
                Thread.setTimeout({func: host.callbackfunc});
                return;
            }
            Thread.setTimeout({
                func: host.fetch2,
                args: [name, index],
                time: 2
            });
        }
    } (host);

    for (i = 0; i < tables.length; i++) {
        if (data_module["cacheHost_" + tables[i]] === undefined) {
            data_module["cacheHost_" + tables[i]] = client_code;
        }
        else if (data_module["cacheHost_" + tables[i]] != client_code) {
            delete data_module["cacheConnector_" + tables[i]];
            delete data_module["cacheContent_" + tables[i]];
        }
        host.tables.push({
            name: tables[i],
            ready: false
        });
    }
    for (i = 0; i < tables.length; i++) {
        if (data_module["cacheConnector_" + tables[i]] === undefined) {
            data_module["cacheConnector_" + tables[i]] = false;
            if (data_module["loader_" + client_code] === undefined) {
                data_module["loader_" + client_code] = fcache.open("keeview_" + client_code + "_hr", "dload.php");
            }
            data_module["loader_" + client_code].load(tables[i], "block", function (host, name, index) {
                return function (retval) {
                    data_module["cacheContent_" + name] = retval;
                    data_module["cacheConnector_" + name] = true;
                    host.fetch2(name, index);
                }
            } (host, tables[i], i));
        }
        else {
            host.fetch(tables[i], i);
        }
    }
}

data_module.cacheMark = {};
data_module.lastidle = (new Date()).getTime();
data_module.initqueue = [
    "forms",
    "objects",
    "object_permissions",
    "contacts",
    "partners",
    "partner_class",
    "partner_class_links",
    "meetings",
    "orgs",
    "employees",
    "peoples",
    "configs",
    "typelists",
    "nations",
    "employee_groups",
    "employee_group_members",
    "cities",
    "meeting_links",
    "tasks",
    "task_links",
    "geopos_orgs",
    "employee_positions",
    "positions",
    "employee_managers",
    "assign_employee_shifts"
];

data_module.cacheThread = function () {
    var queue;

    while (data_module.initqueue.length > 0) {
        queue = data_module.initqueue.shift();
        if (data_module["cacheConnector_" + queue] === undefined) {
            //console.log("auto load " + queue);
            data_module.loadTables(
                [queue],
                function () {
                    Thread.setTimeout({
                        func: data_module.cacheThread,
                        time: 5000
                    });
                }
            );
            return;
        }
    }
}

data_module.mobileCacheThread = function (host) {
    return function (tloop) {
        var keys, queue, now = (new Date()).getTime();
        var i;

        //if (tloop === undefined) console.trace();
        keys = Object.keys(data_module.cacheMark);
        queue = [];
        for (i = 0; i < keys.length; i++) {
            if (data_module.cacheMark[keys[i]].length > 0) {
                queue.push(keys[i]);
            }
        }
        if (queue.length == 0) {
            if (data_module.initqueue.length > 0) {
                queue = data_module.initqueue.shift();
                if (data_module["cacheConnector_" + queue] === undefined) {
                    //console.log("auto load " + queue);
                    data_module.loadTables(
                        [queue],
                        function (oldhost, host) {
                            return function () {
                                data_module.loadingProcessing(host.finished, host.total);
                                if (host.finished == host.total) {
                                    data_module.loadingFinished();
                                    oldhost.done = true;
                                }
                            }
                        } (host, {
                            finished: host.total - data_module.initqueue.length,
                            total: host.total
                        })
                    );
                    setTimeout(function () {
                        data_module.mobileCacheThread(true);
                    }, 10);
                    return;
                }
            }
            setTimeout(function () {
                data_module.mobileCacheThread(true);
            }, 10);
            if (!host.done) {
                data_module.loadingProcessing(host.total - data_module.initqueue.length, host.total);
                if (data_module.initqueue.length == 0) {
                    data_module.loadingFinished();
                    host.done = true;
                }
            }
            return;
        }
        data_module.getTables(queue, function (queue) {
            return function () {
                var i, j, x;
                var tname;
                for (i = 0; i < queue.length; i++) {
                    tname = queue[i];
                    x = data_module.cacheMark[tname];
                    data_module.cacheMark[tname] = [];
                    for (j = 0; j < x.length; j++) {
                        try {
                            x[j]();
                        }
                        catch (e) {
                            console.log("error", e);
                        }
                    }
                }
                setTimeout(function () {
                    data_module.mobileCacheThread(true);
                }, 10);
            }
        } (queue));
    }
} ({
    total: data_module.initqueue.length,
    done: false
});

data_module.loadingProcessing = function (finished, total) {
    if (hr.isMobile && hr.waitingBar){
        hr.finishCache = finished;
        hr.totalCache = total;
        hr.menu.updateWaitingBar();
    }
    console.log("loading cache: " + finished + " / " + total);
}

data_module.loadingFinished = function () {
    if (hr.isMobile && hr.waitingBar){
        hr.finishCache = hr.totalCache;
        hr.menu.updateWaitingBar();
    }
    console.log("loading cache: done");
}

data_module.FlexDBFlags = {};

data_module.refreshFlexDB = function (tablename, callbackfunc) {
    if (!callbackfunc) callbackfunc = function(){};
    if (data_module.FlexDBFlags[tablename] === undefined) data_module.FlexDBFlags[tablename] = 1;
    else data_module.FlexDBFlags[tablename]++;
    fconnector.refresh(tablename, function(){
        data_module.FlexDBFlags[tablename]--;
        callbackfunc();
    });
}

data_module.loadTables = function (tables, callbackfunc) {
    data_module.getTables(EncodingClass.string.duplicateObject(tables), callbackfunc);
}

if (hr.isMobile) {
    if (!window.isApp) data_module.cacheThread();//data_module.mobileCacheThread();
}
else {
    data_module.cacheThread();
}

data_module.getOrgsFromCache = function(checkFunc){
    var keys = data_module.getIDList("orgs");
    var res = [];
    var t;
    for (var i = 0; i < keys.length; i++) {
        t = data_module.getContent("orgs", keys[i]);
        if ((t.obsoletedby == 0) && (t.isdelete == 0)) {
            delete t.uts;
            if (checkFunc !== undefined) {
                v = checkFunc(t);
                if (v !== null) res.push(v);
            }
            else {
                res.push(t);
            }
        }
    }
    return res;
};

data_module.getEmpsFromCache = function(checkFunc) {
    var keys = data_module.getIDList("employees");
    var res = [];
    var t;
    for (var i = 0; i < keys.length; i++) {
        t = data_module.getContent("employees", keys[i]);
        if (t.obsoletedby == 0) {
            delete t.uts;
            if (checkFunc !== undefined) {
                v = checkFunc(t);
                if (v !== null) res.push(v);
            }
            else {
                res.push(t);
            }
        }
    }
    return res;
};

data_module.getEmployeeOfMeFromCache = function(){
    var keys = data_module.getIDList("employees");
    var res = [];
    var i, t;
    for (i = 0; i < keys.length; i++) {
        t = data_module.getContent("employees", keys[i]);
        if (t.obsoletedby == 0) {
            if (t.userid == systemconfig.userid){
                res.push(t.id);
            }
        }
    }
    return res;
};

data_module.getSubOfMeFromCache = function(employeeOfMe){
    if (employeeOfMe.length == 0) return [];
    var keys = data_module.getIDList("employee_managers");
    var res = [];
    var i, t;
    for (i = 0; i < keys.length; i++) {
        t = data_module.getContent("employee_managers", keys[i]);
        if (employeeOfMe.indexOf(t.managerid) >= 0){
            res.push(t.employeeid);
        }
    }
    return res;
};

data_module.getEmployeeRelateMe = function(employeeOfMe){
    if (employeeOfMe.length == 0) return {
        directSubOfMe: [],
        directManageOfMe: [],
        indirectSubOfMe: [],
        indirectManageOfMe: []
    };
    var keys = data_module.getIDList("employee_managers");
    var res = {
        directSubOfMe: [],
        directManageOfMe: [],
        indirectSubOfMe: [],
        indirectManageOfMe: []
    };
    var t;
    for (var i = 0; i < keys.length; i++) {
        t = data_module.getContent("employee_managers", keys[i]);
        switch (t.type) {
            case "direct":
                if (employeeOfMe.indexOf(t.managerid) >= 0){
                    res.directSubOfMe.push(t.employeeid);
                }
                else if (employeeOfMe.indexOf(t.employeeid) >= 0){
                    res.directManageOfMe.push(t.managerid);
                }
                break;
            case "indirect":
                if (employeeOfMe.indexOf(t.managerid) >= 0){
                    res.indirectSubOfMe.push(t.employeeid);
                }
                else if (employeeOfMe.indexOf(t.employeeid) >= 0){
                    res.indirectManageOfMe.push(t.managerid);
                }
        }

    }
    return res;
};

data_module.getDataTablesFromCache = function(name, checkFunc) {
    var keys = data_module.getIDList(name);
    var res = [];
    var i, t, v;
    for (i = 0; i < keys.length; i++) {
        t = data_module.getContent(name, keys[i]);
        delete t.uts;
        if (checkFunc !== undefined) {
            v = checkFunc(t);
            if (v !== null) res.push(v);
        }
        else {
            res.push(t);
        }
    }
    return res;
};

/*
code mẫu:
data_module.getDataTablesFromCache("asdf", function (record) {
    if (record.userid == eid) {
        return {
            id: record.id,
            name: record.name
        };
    }
    else {
        return null;
    }
});
*/

data_module.loadConfigsByName = function(name) {
    var keys = data_module.getIDList("configs");
    var res = [];
    var i, t;
    for (i = 0; i < keys.length; i++) {
        t = data_module.getContent("configs", keys[i]);
        if (t.name == name){
            delete t.uts;
            res.push(t);
        }
    }
    return res;
};

data_module.loadConfigsByNameWorker = function(name){
    return new Promise(function(resolve, reject){
        data_module.cacheContent_configs.psearch({
            searchFunc: function(record){
                if (extraParams.name == record.name){
                    return record;
                }
                else {
                    return null;
                }
            },
            extraParams: {
                name: name
            },
            callbackfunc: function(values){
                resolve(values);
            }
        })
    });
};

data_module.getEmpsFromCacheWorker = function(allData, fieldList){
    return new Promise(function(resolve, reject){
        var res = {
            employeeOfMe: []
        };
        data_module.cacheContent_employees.psearch({
            postFunc: function(record){
                if (systemconfig.userid == record.userid && record.available == 1){
                    res.employeeOfMe.push(record.id);
                }
                return record;
            },
            searchFunc: function(record){
                if (record.obsoletedby == 0){
                    if (extraParams.allData) return record;
                    else {
                        var r = {
                            userid: record.userid,
                            available: record.available
                        };
                        for (var i = 0; i < extraParams.fieldList.length; i++){
                            r[extraParams.fieldList[i]] = record[extraParams.fieldList[i]];
                        }
                        return r;
                    }
                }
                else {
                    return null;
                }
            },
            extraParams: {
                fieldList: fieldList,
                allData: allData
            },
            callbackfunc: function(values){
                res.employees = values;
                resolve(res);
            }
        });
    });
};

data_module.getPeoplesFromCacheByEmployeesWorker = function(allData, fieldList, employees){
    return new Promise(function(resolve, reject){
        var dic = {};
        for (var i = 0; i < employees.length; i++){
            dic[employees[i].peopleid] = true;
        }
        data_module.cacheContent_peoples.psearch({
            searchFunc: function(record){
                if (extraParams.dic[record.id]){
                    if (!extraParams.allData){
                        var r = {};
                        for (var i = 0; i < extraParams.fieldList.length; i++){
                            r[extraParams.fieldList[i]] = record[extraParams.fieldList[i]];
                        }
                        return r;
                    }
                    else {
                        return record;
                    }
                }
                else {
                    return null;
                }
            },
            extraParams: {
                fieldList: fieldList,
                allData: allData,
                dic: dic
            },
            callbackfunc: function(values){
                resolve(values);
            }
        });
    });
};

data_module.loadOrgsTree = function (callbackfunc, loadAllDataPeople) {
    data_module.loadTables(
        ["orgs", "employees", "peoples"],
        function () {
            var orgs = data_module.getOrgsFromCache(function(record){
                return {
                    id: record.id,
                    parentid: record.parentid,
                    name: record.name,
                    firstid: record.firstid,
                    code: record.code,
                    firstparentid: record.firstparentid
                };
            });
            data_module.getEmpsFromCacheWorker(false, ["id", "firstid", "orgid", "peopleid", "available", "code"]).then(function(values){
                var employees = values.employees;
                var employeeOfMe = values.employeeOfMe;
                if (loadAllDataPeople){
                    data_module.getPeoplesFromCacheByEmployeesWorker(loadAllDataPeople, [], employees).then(function(peoples){
                        callbackfunc({
                            orgs: orgs,
                            employees: employees,
                            employeeOfMe: employeeOfMe,
                            peoples: peoples
                        });
                    });
                }
                else {
                    data_module.getPeoplesFromCacheByEmployeesWorker(loadAllDataPeople, ["id", "fullname"], employees).then(function(peoples){
                        callbackfunc({
                            orgs: orgs,
                            employees: employees,
                            employeeOfMe: employeeOfMe,
                            peoples: peoples
                        });
                    });
                }
            });
        }
    );
}

data_module.loadEmployeeItemsPrivView = function (host) {
    return function () {
        if (host.process === undefined) {
            host.process = function (st, resolve) {
                var host = {database: {}};
                host.employeeOfMe = st.employeeOfMe;
                delete st.employeeOfMe;
                contentModule.makeDatabaseContent(host, st);
                var pDict = {};
                host.database.peoples.items.forEach(function(elt){
                    pDict[elt.id] = elt;
                });
                host.database.employees.items.forEach(function(elt){
                    if (!pDict[elt.peopleid]){
                        console.log(elt);
                        return;
                    }
                    elt.fullname = pDict[elt.peopleid].fullname;
                });
                contentModule.makeOrgsIndex(host);
                contentModule.makeEmployeesIndex(host);
                resolve(host);
            }
        }
        return new Promise(function (host) {
            return function(resolve, reject) {
                data_module.loadOrgsTree(function (host, resolve) {
                    return function (content) {
                        host.process(content, resolve);
                    }
                } (host, resolve));
            }
        } (host));
    }
} ({});

VaKeR 2022