#------------------------------------------------------------------------------
# /var/install/include/syslib - script interface for system files
#
# Creation:    2009-09-21 dv
# Last update: $Id: syslib-2 40459 2016-02-06 15:55:07Z dv

# Copyright (c) 2009-@@YEAR@@ the eisfair team, team(at)eisfair(dot)org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#------------------------------------------------------------------------------

SYS_API_USERSTOLIST=10
SYS_API_GROUPSTOLIST=20
SYS_API_GROUPMEMBERSELECTION=30
SYS_API_SETGROUPMEMBERS=40

USERS_SHOW_ALL=0
USERS_HIDE_SYSTEM=1
USERS_HIDE_REAL=2
USERS_HIDE_MACHINES=4
USERS_HIDE_NOBODY=8
USERS_HIDE_ROOT=16

GROUPS_SHOW_ALL=0
GROUPS_HIDE_SYSTEM=1
GROUPS_HIDE_REAL=2
GROUPS_HIDE_NOGROUP=3

sys_module_offs="99000"


#------------------------------------------------------------------------------
# Load system module
# Expects: <nothing>
# Returns: <nothing> but success or failure
#------------------------------------------------------------------------------
sys_initmodule()
{
    cui_load_addon "/usr/lib/cui-addons/libsys-addon.so.2.0.3"
    if [ "$p2" != 0 ]
    then
        sys_module_offs="$p2"
        return 0
    else
        return 1
    fi
}


#------------------------------------------------------------------------------
# Transfer user database to list view
# Expects: $1  <-- Handle         : listview window handle
#          $2  <-- Flags          : flags for user query
#          $3  <-- String         : text for user name matching
# Returns: nothing
#------------------------------------------------------------------------------
sys_users_tolist()
{
    cui_send "C" "$[${sys_module_offs} + ${SYS_API_USERSTOLIST}]" "$@"
    cui_wait_ack
    return $?
}


#------------------------------------------------------------------------------
# Transfer group database to list view
# Expects: $1  <-- Handle         : listview window handle
#          $2  <-- Flags          : flags for group query
#          $3  <-- String         : text for group name matching
# Returns: nothing
#------------------------------------------------------------------------------
sys_groups_tolist()
{
    cui_send "C" "$[${sys_module_offs} + ${SYS_API_GROUPSTOLIST}]" "$@"
    cui_wait_ack
    return $?
}


#------------------------------------------------------------------------------
# Transfer group database to list view
# Expects: $1  <-- Handle         : listbox window handle for unselected users
#          $2  <-- Handle         : listbox window handle for selected users
#          $3  <-- String         : group name
# Returns: nothing
#------------------------------------------------------------------------------
sys_group_member_selection()
{
    cui_send "C" "$[${sys_module_offs} + ${SYS_API_GROUPMEMBERSELECTION}]" "$@"
    cui_wait_ack
    return $?
}


#------------------------------------------------------------------------------
# Set a new member list to a given group
# Expects: $1  <-- String         : group to set member list for
#          $2  <-- String         : member list separated by comma
# Returns: nothing
#------------------------------------------------------------------------------
sys_set_group_members()
{
    cui_send "C" "$[${sys_module_offs} + ${SYS_API_SETGROUPMEMBERS}]" "$@"
    cui_wait_ack
    return $?
}

#----------------------------------------------------------------------------
# End
#----------------------------------------------------------------------------
