registerFunction('courses_of_user');
//$xajax->registerFunction('empty_courses_of_user');
$xajax->processRequests();
function courses_of_user($arg)
{
// do some stuff based on $arg like query data from a database and
// put it into a variable like $newContent
//$newContent = 'werkt het? en met een beetje meer text, wordt dat goed opgelost? ';
$personal_course_list = UserManager::get_personal_session_course_list($arg);
$newContent = '';
if(count($personal_course_list)>0)
{
foreach ($personal_course_list as $key=>$course)
{
$newContent .= $course['i'].'
';
}
}
else
{
$newContent .= '- '.get_lang('None').' -
';
}
// Instantiate the xajaxResponse object
$objResponse = new xajaxResponse();
// add a command to the response to assign the innerHTML attribute of
// the element with id="SomeElementId" to whatever the new content is
$objResponse->addAssign("user".$arg,"innerHTML", $newContent);
$objResponse->addReplace("coursesofuser".$arg,"alt", $newContent);
$objResponse->addReplace("coursesofuser".$arg,"title", $newContent);
//return the xajaxResponse object
return $objResponse;
}
function empty_courses_of_user($arg)
{
// do some stuff based on $arg like query data from a database and
// put it into a variable like $newContent
$newContent = '';
// Instantiate the xajaxResponse object
$objResponse = new xajaxResponse();
// add a command to the response to assign the innerHTML attribute of
// the element with id="SomeElementId" to whatever the new content is
$objResponse->addAssign("user".$arg,"innerHTML", $newContent);
//return the xajaxResponse object
return $objResponse;
}
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
$htmlHeadXtra[] = ' ';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
/**
* Make sure this function is protected
* because it does NOT check password!
*
* This function defines globals.
* @author Roan Embrechts
*/
function login_user($user_id)
{
//init ---------------------------------------------------------------------
global $uidReset, $loginFailed, $_configuration;
$main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
$main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
$track_e_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
//logic --------------------------------------------------------------------
//unset($_user['user_id']); // uid not in session ? prevent any hacking
if (!isset ($user_id))
{
$uidReset = true;
return;
}
$sql_query = "SELECT * FROM $main_user_table WHERE user_id='$user_id'";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
$result = Database :: fetch_array($sql_result);
$firstname = $result["firstname"];
$lastname = $result["lastname"];
$user_id = $result["user_id"];
$message = "Attempting to login as ".$firstname." ".$lastname." (id ".$user_id.")";
$loginFailed = false;
$uidReset = false;
if ($user_id) // a uid is given (log in succeeded)
{
if ($_configuration['tracking_enabled'])
{
$sql_query = "SELECT user.*, a.user_id is_admin,
UNIX_TIMESTAMP(login.login_date) login_date
FROM $main_user_table
LEFT JOIN $main_admin_table a
ON user.user_id = a.user_id
LEFT JOIN $track_e_login_table login
ON user.user_id = login.login_user_id
WHERE user.user_id = '".$user_id."'
ORDER BY login.login_date DESC LIMIT 1";
}
else
{
$sql_query = "SELECT user.*, a.user_id is_admin
FROM $main_user_table
LEFT JOIN $main_admin_table a
ON user.user_id = a.user_id
WHERE user.user_id = '".$user_id."'";
}
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
if (Database::num_rows($sql_result) > 0)
{
// Extracting the user data
$user_data = Database::fetch_array($sql_result);
//Delog the current user
LoginDelete($_SESSION["_user"]["user_id"], $_configuration['statistics_database']);
// Cleaning session variables
unset($_SESSION['_user']);
unset($_SESSION['is_platformAdmin']);
unset($_SESSION['is_allowedCreateCourse']);
unset($_SESSION['_uid']);
$_user['firstName'] = $user_data['firstname'];
$_user['lastName'] = $user_data['lastname'];
$_user['mail'] = $user_data['email'];
$_user['lastLogin'] = $user_data['login_date'];
$_user['official_code'] = $user_data['official_code'];
$_user['picture_uri'] = $user_data['picture_uri'];
$_user['user_id'] = $user_data['user_id'];
$is_platformAdmin = (bool) (!is_null($user_data['is_admin']));
$is_allowedCreateCourse = (bool) ($user_data['status'] == 1);
// Filling session variables with new data
$_SESSION['_uid'] = $user_id;
$_SESSION['_user'] = $_user;
$_SESSION['is_platformAdmin'] = $is_platformAdmin;
$_SESSION['is_allowedCreateCourse'] = $is_allowedCreateCourse;
$_SESSION['login_as'] = true; // will be usefull later to know if the user is actually an admin or not (example reporting)s
$target_url = api_get_path(WEB_PATH)."user_portal.php";
$message .= "
Login successful. Go to $target_url";
Display :: display_header(get_lang('UserList'));
Display :: display_normal_message($message,false);
Display :: display_footer();
exit;
}
else
{
exit ("
WARNING UNDEFINED UID !! ");
}
}
}
/**
* Get the total number of users on the platform
* @see SortableTable#get_total_number_of_items()
*/
function get_number_of_users()
{
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u";
if (isset ($_GET['keyword']))
{
$keyword = Database::escape_string($_GET['keyword']);
$sql .= " WHERE u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.email LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%'";
}
elseif (isset ($_GET['keyword_firstname']))
{
$admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
$keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
$keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
$keyword_email = Database::escape_string($_GET['keyword_email']);
$keyword_username = Database::escape_string($_GET['keyword_username']);
$keyword_status = Database::escape_string($_GET['keyword_status']);
$query_admin_table = '';
$keyword_admin = '';
if($keyword_status == 10)
{
$keyword_status = '%';
$query_admin_table = " , $admin_table a ";
$keyword_admin = ' AND a.user_id = u.user_id ';
}
$keyword_active = isset($_GET['keyword_active']);
$keyword_inactive = isset($_GET['keyword_inactive']);
$sql .= $query_admin_table .
" WHERE u.firstname LIKE '%".$keyword_firstname."%' " .
"AND u.lastname LIKE '%".$keyword_lastname."%' " .
"AND u.username LIKE '%".$keyword_username."%' " .
"AND u.email LIKE '%".$keyword_email."%' " .
//"AND u.official_code LIKE '%".$keyword_officialcode."%' " .
"AND u.status LIKE '".$keyword_status."'" .
$keyword_admin;
if($keyword_active && !$keyword_inactive)
{
$sql .= " AND u.active='1'";
}
elseif($keyword_inactive && !$keyword_active)
{
$sql .= " AND u.active='0'";
}
}
$res = api_sql_query($sql, __FILE__, __LINE__);
$obj = Database::fetch_object($res);
return $obj->total_number_of_items;
}
/**
* Get the users to display on the current page.
* @see SortableTable#get_table_data($from)
*/
function get_user_data($from, $number_of_items, $column, $direction)
{
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$sql = "SELECT
u.user_id AS col0,
u.official_code AS col1,
u.lastname AS col2,
u.firstname AS col3,
u.username AS col4,
u.email AS col5,
u.status AS col6,
u.active AS col7,
u.user_id AS col8
FROM
$user_table u";
if (isset ($_GET['keyword']))
{
$keyword = Database::escape_string($_GET['keyword']);
$sql .= " WHERE u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.username LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%'";
}
elseif (isset ($_GET['keyword_firstname']))
{
$admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
$keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
$keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
$keyword_email = Database::escape_string($_GET['keyword_email']);
$keyword_username = Database::escape_string($_GET['keyword_username']);
$keyword_status = Database::escape_string($_GET['keyword_status']);
$query_admin_table = '';
$keyword_admin = '';
if($keyword_status == 10)
{
$keyword_status = '%';
$query_admin_table = " , $admin_table a ";
$keyword_admin = ' AND a.user_id = u.user_id ';
}
$keyword_active = isset($_GET['keyword_active']);
$keyword_inactive = isset($_GET['keyword_inactive']);
$sql .= $query_admin_table." WHERE u.firstname LIKE '%".$keyword_firstname."%' " .
"AND u.lastname LIKE '%".$keyword_lastname."%' " .
"AND u.username LIKE '%".$keyword_username."%' " .
"AND u.email LIKE '%".$keyword_email."%' " .
//"AND u.official_code LIKE '%".$keyword_officialcode."%' " .
"AND u.status LIKE '".$keyword_status."'" .
$keyword_admin;
if($keyword_active && !$keyword_inactive)
{
$sql .= " AND u.active='1'";
}
elseif($keyword_inactive && !$keyword_active)
{
$sql .= " AND u.active='0'";
}
}
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from,$number_of_items";
$res = api_sql_query($sql, __FILE__, __LINE__);
$users = array ();
while ($user = Database::fetch_row($res))
{
$users[] = $user;
}
return $users;
}
/**
* Returns a mailto-link
* @param string $email An email-address
* @return string HTML-code with a mailto-link
*/
function email_filter($email)
{
return Display :: encrypted_mailto_link($email, $email);
}
/**
* Build the modify-column of the table
* @param int $user_id The user id
* @param string $url_params
* @return string Some HTML-code with modify-buttons
*/
function modify_filter($user_id,$url_params,$row)
{
global $charset;
$result .= '
';
$result .= ' ';
$result .= ' ';
$statusname = api_get_status_langvars();
if ($row['6'] != $statusname[STUDENT])
{
$result .= '