Get data for user administration list.
{
global
$ilDB, $rbacreview;
$fields = array("usr_id", "login", "firstname", "lastname", "email",
"time_limit_until", "time_limit_unlimited", "time_limit_owner", "last_login", "active");
if (is_array($a_additional_fields))
{
foreach ($a_additional_fields as $f)
{
if (!in_array($f, $fields))
{
$fields[] = $f;
}
}
}
$count_query = "SELECT count(usr_id) cnt".
" FROM usr_data";
$query =
"SELECT ".implode($fields,
",").
" FROM usr_data";
$query.=
" WHERE usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
if($a_user_filter and is_array(($a_user_filter)))
{
$query .=
' AND '.$ilDB->in(
'usr_id',$a_user_filter,
false,
'integer');
}
$count_query.= " WHERE usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
$where = " AND";
if ($a_first_letter != "")
{
$add = $where." (".$ilDB->upper($ilDB->substr("usr_data.lastname", 1, 1))." = ".$ilDB->upper($ilDB->quote($a_first_letter, "text")).") ";
$count_query.= $add;
$where = " AND";
}
if ($a_string_filter != "")
{
$add = $where." (".$ilDB->like("usr_data.login", "text", "%".$a_string_filter."%")." ".
"OR ".$ilDB->like("usr_data.firstname", "text", "%".$a_string_filter."%")." ".
"OR ".$ilDB->like("usr_data.lastname", "text", "%".$a_string_filter."%")." ".
"OR ".$ilDB->like("usr_data.email", "text", "%".$a_string_filter."%").") ";
$count_query.= $add;
$where = " AND";
}
if ($a_activation_filter != "")
{
if ($a_activation_filter == "inactive")
{
$add = $where." usr_data.active = ".$ilDB->quote(0, "integer")." ";
}
else
{
$add = $where." usr_data.active = ".$ilDB->quote(1, "integer")." ";
}
$count_query.= $add;
$where = " AND";
}
if (is_object($a_last_login_filter))
{
{
$add = $where." last_login < ".
$count_query.= $add;
$where = " AND";
}
}
if ($a_limited_access_filter)
{
$add = $where." time_limit_unlimited= ".$ilDB->quote(0, "integer");
$count_query.= $add;
$where = " AND";
}
if ($a_no_courses_filter)
{
$add = $where." usr_id NOT IN (".
"SELECT DISTINCT ud.usr_id ".
"FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
"JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) ".
"WHERE od.title LIKE 'il_crs_%')";
$count_query.= $add;
$where = " AND";
}
if ($a_course_group_filter > 0)
{
$add = $where." usr_id IN (".
"SELECT DISTINCT ud.usr_id ".
"FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
"JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) ".
"WHERE od.title = ".$ilDB->quote("il_".$cgtype."_member_".$a_course_group_filter, "text").")";
$count_query.= $add;
$where = " AND";
}
if ($a_role_filter > 0)
{
$add = $where." usr_id IN (".
"SELECT DISTINCT ud.usr_id ".
"FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
"WHERE rbac_ua.rol_id = ".$ilDB->quote($a_role_filter, "integer").")";
$count_query.= $add;
$where = " AND";
}
if(!is_null($a_user_folder_filter))
{
$add = $where." ".$ilDB->in('time_limit_owner',$a_user_folder_filter,false,'integer');
$count_query.= $add;
$where = " AND";
}
if ($a_order_field != "access_until")
{
if (!in_array($a_order_field, $fields))
{
$a_order_field = "login";
}
if ($a_order_dir != "asc" && $a_order_dir != "desc")
{
$a_order_dir = "asc";
}
$query.=
" ORDER BY ".$a_order_field.
" ".strtoupper($a_order_dir);
}
else
{
if ($a_order_dir == "desc")
{
$query.=
" ORDER BY active DESC, time_limit_unlimited DESC, time_limit_until DESC";
}
else
{
$query.=
" ORDER BY active ASC, time_limit_unlimited ASC, time_limit_until ASC";
}
}
$set = $ilDB->query($count_query);
$cnt = 0;
if ($rec = $ilDB->fetchAssoc($set))
{
$cnt = $rec["cnt"];
}
$offset = (int) $a_offset;
$limit = (int) $a_limit;
$ilDB->setLimit($limit, $offset);
while($rec = $ilDB->fetchAssoc($set))
{
}
return array(
"cnt" => $cnt,
"set" =>
$result);
}