";
}
/*
--------------------------------------
DISPLAY USERS LIST
--------------------------------------
Also shows a "next page" button if there are
more than 50 users.
There's a bug in here somewhere - some users count as more than one if they are in more than one group
--> code for > 50 users should take this into account
(Roan, Feb 2004)
*/
if( CourseManager::has_virtual_courses_from_code($course_id, $user_id))
{
$real_course_code = $_course['sysCode'];
$real_course_info = Database::get_course_info($real_course_code);
$message = get_lang("RegisteredInRealCourse")." ".$real_course_info["title"]." (".$real_course_info["official_code"].")";
echo "
".$message."
";
}
/*
==============================================================================
DISPLAY LIST OF USERS
==============================================================================
*/
/**
* * Get the users to display on the current page.
*/
function get_number_of_users()
{
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
if(api_get_setting('use_session_mode')!="true"){
$sql = "SELECT COUNT(u.user_id) AS number_of_users FROM $user_table u,$course_user_table cu WHERE u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'";
}
else{
$sql = "SELECT COUNT(id_user)+1 AS number_of_users
FROM $user_table u, ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
WHERE course_code= '".$_SESSION['_course']['id']."'
AND id_session='".$_SESSION['id_session']."'";
}
if( isset ($_GET['keyword']))
{
$keyword = mysql_real_escape_string($_GET['keyword']);
$sql .= " AND (firstname LIKE '%".$keyword."%' OR lastname LIKE '%".$keyword."%' OR username LIKE '%".$keyword."%' OR official_code LIKE '%".$keyword."%')";
}
$res = api_sql_query($sql, __FILE__, __LINE__);
$result = mysql_fetch_object($res);
return $result->number_of_users;
}
/**
* Get the users to display on the current page.
*/
function get_user_data($from, $number_of_items, $column, $direction)
{
global $is_allowed_to_track;
//print_r($_SESSION);
//echo $_SESSION["id_session"];
//It's a teacher in the current course; We display all the students of the course (as if the course belong to no sessions)
if($_SESSION["is_courseAdmin"] || $_SESSION["is_platformAdmin"]){
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$columns[] = 'u.user_id';
$columns[] = 'u.official_code';
$columns[] = 'u.lastname';
$columns[] = 'u.firstname';
$columns[] = 'cu.role';
$columns[] = "''"; //placeholder for group-data
$columns[] = "IF(cu.tutor_id = 1,'".get_lang('Tutor')."','')";
$columns[] = "IF(cu.status = 1,'".get_lang('CourseManager')."','')";
$columns[] = 'u.user_id';
$sql = "SELECT ";
foreach( $columns as $index => $sqlcolumn)
{
$columns[$index] = ' '.$sqlcolumn.' AS col'.$index.' ';
}
$sql .= implode(" , ", $columns);
$sql .= "FROM $user_table u,$course_user_table cu WHERE u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'";
if( isset ($_GET['keyword']))
{
$keyword = mysql_real_escape_string($_GET['keyword']);
$sql .= " AND (firstname LIKE '%".$keyword."%' OR lastname LIKE '%".$keyword."%' OR username LIKE '%".$keyword."%' OR official_code LIKE '%".$keyword."%')";
}
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from, $number_of_items";
$res = api_sql_query($sql, __FILE__, __LINE__);
$users = array();
$user_ids = array();
while($user = mysql_fetch_row($res))
{
$users[''.$user[0]] = $user;
$user_ids[] = $user[0];
}
$sql = "
SELECT
ug.user_id,
ug.group_id group_id,
sg.name
FROM " . Database::get_course_table(TABLE_GROUP_USER) . " ug
LEFT JOIN " . Database::get_course_table(TABLE_GROUP) . " sg ON ug.group_id = sg.id
WHERE ug.user_id IN ('".implode("','", $user_ids)."')";
$res = api_sql_query($sql,__FILE__,__LINE__);
while($group = mysql_fetch_object($res))
{
$users[''.$group->user_id][5] .= $group->name.' ';
}
//Sessions
$columns=array();
$columns[] = 'u.user_id';
$columns[] = 'u.official_code';
$columns[] = 'u.lastname';
$columns[] = 'u.firstname';
$columns[] = "''";
$columns[] = "''"; //placeholder for group-data
$columns[] = "''";
$columns[] = "''";
$columns[] = 'u.user_id';
$sql = "SELECT ".implode(',',$columns)."
FROM ".Database::get_main_table(TABLE_MAIN_USER)." `u`, ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." c
WHERE `u`.`user_id`= c.`id_user`
AND c.`course_code`='".$_SESSION['_course']['id']."'
";
if( isset ($_GET['keyword']))
{
$keyword = mysql_real_escape_string($_GET['keyword']);
$sql .= " AND (firstname LIKE '%".$keyword."%' OR lastname LIKE '%".$keyword."%' OR username LIKE '%".$keyword."%' OR official_code LIKE '%".$keyword."%')";
}
$res = api_sql_query($sql, __FILE__, __LINE__);
while ($user = mysql_fetch_row($res))
{
$users[''.$user[0]] = $user;
$user_ids[] = $user[0];
}
$sql = "SELECT ug.user_id, ug.group_id group_id, sg.name
FROM ".Database::get_course_table(TABLE_GROUP_USER)." ug
LEFT JOIN ".Database::get_course_table(TABLE_GROUP)." sg
ON ug.group_id = sg.id
WHERE ug.user_id IN ('".implode("','", $user_ids)."')";
$res = api_sql_query($sql,__FILE__,__LINE__);
while($group = mysql_fetch_object($res))
{
$users[''.$group->user_id][5] .= $group->name.' ';
}
}
//Sudent or coach
else
{
//We are coach
if($_SESSION["is_courseTutor"]){
$columns = array();
if(api_is_allowed_to_edit())
{
$columns[] = 'u.user_id';
}
$columns[] = 'u.official_code';
$columns[] = 'u.lastname';
$columns[] = 'u.firstname';
$columns[] = '""';
$columns[] = "''"; //placeholder for group-data
if(api_is_allowed_to_edit())
{
$columns[] = "''";
$columns[] = "''";
}
$columns[] = 'u.user_id';
$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
$tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
$sql="SELECT ".implode(',',$columns)."
FROM $tbl_session_course_user as srcru, $tbl_user as u
WHERE srcru.course_code='".$_SESSION['_course']['id']."' AND srcru.id_user=u.user_id
";
$res = api_sql_query($sql, __FILE__, __LINE__);
while ($user = mysql_fetch_array($res))
{
$users[''.$user["user_id"]] = $user;
$user_ids[] = $user["user_id"];
}
}
else
{
$columns = array();
if(api_is_allowed_to_edit())
{
$columns[] = 'u.user_id';
}
$columns[] = 'u.official_code';
$columns[] = 'u.lastname';
$columns[] = 'u.firstname';
$columns[] = '""';
$columns[] = "''"; //placeholder for group-data
if(api_is_allowed_to_edit())
{
$columns[] = "''";
$columns[] = "''";
}
$columns[] = 'u.user_id';
$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
$tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
if(empty($_SESSION["id_session"]))
{
$sql="SELECT ";
foreach( $columns as $index => $sqlcolumn)
{
$columns[$index] = ' '.$sqlcolumn.' AS col'.$index.' ';
}
$sql .= implode(" , ", $columns);
$sql .= "FROM $tbl_course_user as cu, $tbl_user as u
WHERE cu.course_code='".$_SESSION['_course']['id']."' AND cu.user_id=u.user_id
";
}
else
{
$sql="SELECT ";
foreach( $columns as $index => $sqlcolumn)
{
$columns[$index] = ' '.$sqlcolumn.' AS col'.$index.' ';
}
$sql .= implode(" , ", $columns);
$sql .= "FROM $tbl_session_course_user as srcru, $tbl_user as u
WHERE srcru.course_code='".$_SESSION['_course']['id']."' AND srcru.id_user=u.user_id";
}
if( isset ($_GET['keyword']))
{
$keyword = mysql_real_escape_string($_GET['keyword']);
$sql .= " AND (firstname LIKE '%".$keyword."%' OR lastname LIKE '%".$keyword."%' OR username LIKE '%".$keyword."%' OR official_code LIKE '%".$keyword."%')";
}
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from, $number_of_items";
$res = api_sql_query($sql, __FILE__, __LINE__);
while ($user = mysql_fetch_array($res))
{
$users[''.$user[0]] = $user;
$user_ids[] = $user["user_id"];
}
}
}
/*if(api_get_setting('use_session_mode')!='true')
{
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
if(api_is_allowed_to_edit())
$columns[] = 'u.user_id';
$columns[] = 'u.official_code';
$columns[] = 'u.lastname';
$columns[] = 'u.firstname';
$columns[] = 'cu.role';
$columns[] = "''"; //placeholder for group-data
if(api_is_allowed_to_edit())
{
$columns[] = "IF(cu.tutor_id = 1,'".get_lang('Tutor')."','')";
$columns[] = "IF(cu.status = 1,'".get_lang('CourseManager')."','')";
}
$columns[] = 'u.user_id';
$sql = "SELECT ";
foreach( $columns as $index => $sqlcolumn)
$columns[$index] = ' '.$sqlcolumn.' AS col'.$index.' ';
$sql .= implode(" , ", $columns);
$sql .= "FROM $user_table u,$course_user_table cu WHERE u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'";
if( isset ($_GET['keyword']))
{
$keyword = mysql_real_escape_string($_GET['keyword']);
$sql .= " AND (firstname LIKE '%".$keyword."%' OR lastname LIKE '%".$keyword."%' OR username LIKE '%".$keyword."%' OR official_code LIKE '%".$keyword."%')";
}
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from, $number_of_items";
$res = api_sql_query($sql, __FILE__, __LINE__);
$users = array();
$user_ids = array();
while($user = mysql_fetch_row($res))
{
$users[''.$user[0]] = $user;
$user_ids[] = $user[0];
}
$sql = "
SELECT
ug.user_id,
ug.group_id group_id,
sg.name
FROM " . Database::get_course_table(TABLE_GROUP_USER) . " ug
LEFT JOIN " . Database::get_course_table(TABLE_GROUP) . " sg ON ug.group_id = sg.id
WHERE ug.user_id IN ('".implode("','", $user_ids)."')";
$res = api_sql_query($sql,__FILE__,__LINE__);
while($group = mysql_fetch_object($res))
$users[''.$group->user_id][5] .= $group->name.' ';
}
else {
$columns = array();
if(api_is_allowed_to_edit())
{
$columns[] = 'u.user_id';
}
$columns[] = 'u.official_code';
$columns[] = 'u.lastname';
$columns[] = 'u.firstname';
$columns[] = '"Professor"';
$columns[] = "''"; //placeholder for group-data
if(api_is_allowed_to_edit())
{
$columns[] = "'".get_lang('Tutor')."'";
$columns[] = "'".get_lang('CourseManager')."'";
}
$columns[] = 'u.user_id';
/*$sql = "SELECT ".implode(',',$columns)."
FROM ".Database::get_main_table(TABLE_MAIN_USER)." `u`, ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE)." c
WHERE `u`.`user_id`= c.`id_coach`
AND c.`course_code`='".$_SESSION['_course']['id']."'
AND c.id_session='".$_SESSION['id_session']."'";*/
/*$sql = "SELECT ".implode(',',$columns)."
FROM ".Database::get_main_table(TABLE_MAIN_USER)." `u`, ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE)." c
WHERE `u`.`user_id`= c.`id_coach`
AND c.`course_code`='".$_SESSION['_course']['id']."'
";
$res = api_sql_query($sql, __FILE__, __LINE__);
$users = array ();
while ($user = mysql_fetch_row($res))
{
$users[''.$user[0]] = $user;
$user_ids[] = $user[0];
}
$columns = array();
if(api_is_allowed_to_edit())
{
$columns[] = 'u.user_id';
}
$columns[] = 'u.official_code';
$columns[] = 'u.lastname';
$columns[] = 'u.firstname';
$columns[] = '"Professor"';
$columns[] = "''"; //placeholder for group-data
if(api_is_allowed_to_edit())
{
$columns[] = "''";
$columns[] = "''";
}
$columns[] = 'u.user_id';
/*$sql = "SELECT ".implode(',',$columns)."
FROM ".Database::get_main_table(TABLE_MAIN_USER)." `u`, ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." c
WHERE `u`.`user_id`= c.`id_user`
AND c.`course_code`='".$_SESSION['_course']['id']."'
AND c.id_session='".$_SESSION['id_session']."'";*/
/*$sql = "SELECT ".implode(',',$columns)."
FROM ".Database::get_main_table(TABLE_MAIN_USER)." `u`, ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." c
WHERE `u`.`user_id`= c.`id_user`
AND c.`course_code`='".$_SESSION['_course']['id']."'
";
$res = api_sql_query($sql, __FILE__, __LINE__);
while ($user = mysql_fetch_row($res))
{
$users[''.$user[0]] = $user;
$user_ids[] = $user[0];
}
$sql = "SELECT ug.user_id, ug.group_id group_id, sg.name
FROM ".Database::get_course_table(TABLE_GROUP_USER)." ug
LEFT JOIN ".Database::get_course_table(TABLE_GROUP)." sg
ON ug.group_id = sg.id
WHERE ug.user_id IN ('".implode("','", $user_ids)."')";
$res = api_sql_query($sql,__FILE__,__LINE__);
while($group = mysql_fetch_object($res))
{
$users[''.$group->user_id][5] .= $group->name.' ';
}
}*/
return $users;
}
/**
* Build the modify-column of the table
* @param int $user_id The user id
* @return string Some HTML-code
*/
function modify_filter($user_id)
{
global $origin,$_user,$is_allowed_to_track;
$result="