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");
$ut_join = "";
if (is_array($a_additional_fields))
{
foreach ($a_additional_fields as $f)
{
if (!in_array($f, $fields))
{
if($f == "online_time")
{
$fields[] = "ut_online.online_time";
$ut_join = " LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id";
}
else
{
$fields[] = $f;
}
}
}
}
$count_query = "SELECT count(usr_id) cnt".
" FROM usr_data";
$sql_fields = array();
foreach($fields as $idx => $field)
{
if(!stristr($field, "."))
{
$sql_fields[] = "usr_data.".$field;
}
else
{
$sql_fields[] = $field;
}
}
$query =
"SELECT ".implode($sql_fields,
",").
" FROM usr_data".
$ut_join;
$query.=
" WHERE usr_data.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
if($a_user_filter and is_array(($a_user_filter)))
{
$query .=
' AND '.$ilDB->in(
'usr_data.usr_id',$a_user_filter,
false,
'integer');
}
$count_query.= " WHERE usr_data.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." usr_data.last_login < ".
$count_query.= $add;
$where = " AND";
}
}
if ($a_limited_access_filter)
{
$add = $where." usr_data.time_limit_unlimited= ".$ilDB->quote(0, "integer");
$count_query.= $add;
$where = " AND";
}
if ($a_no_courses_filter)
{
$add = $where." usr_data.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_data.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_data.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('usr_data.time_limit_owner',$a_user_folder_filter,false,'integer');
$count_query.= $add;
$where = " AND";
}
switch($a_order_field)
{
case "access_until":
if ($a_order_dir == "desc")
{
$query.=
" ORDER BY usr_data.active DESC, usr_data.time_limit_unlimited DESC, usr_data.time_limit_until DESC";
}
else
{
$query.=
" ORDER BY usr_data.active ASC, usr_data.time_limit_unlimited ASC, usr_data.time_limit_until ASC";
}
break;
case "online_time":
if ($a_order_dir == "desc")
{
$query.=
" ORDER BY ut_online.online_time DESC";
}
else
{
$query.=
" ORDER BY ut_online.online_time ASC";
}
break;
default:
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 usr_data.".$a_order_field.
" ".strtoupper($a_order_dir);
break;
}
$set = $ilDB->query($count_query);
$cnt = 0;
if ($rec = $ilDB->fetchAssoc($set))
{
$cnt = $rec["cnt"];
}
$offset = (int) $a_offset;
$limit = (int) $a_limit;
if($offset >= $cnt)
{
$offset = 0;
}
$ilDB->setLimit($limit, $offset);
while($rec = $ilDB->fetchAssoc($set))
{
}
return array(
"cnt" => $cnt,
"set" =>
$result);
}