@ -18,10 +18,11 @@ $current_access_url_id = api_get_current_access_url_id();
// Blocks the possibility to delete a user
$delete_user_available = true;
if (isset($_configuration['deny_delete_users']) & & $_configuration['deny_delete_users']) {
$delete_user_available = false;
$delete_user_available = false;
}
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=get_user_courses';
$urlSession = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=get_user_sessions';
$htmlHeadXtra[] = '< script >
function load_course_list (div_course,my_user_id) {
$.ajax({
@ -38,6 +39,21 @@ function load_course_list (div_course,my_user_id) {
}
});
}
function load_session_list (div_session,my_user_id) {
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {
$("div#"+div_session).html("< img src = \'../inc/lib/javascript/indicator.gif\' / > "); },
type: "POST",
url: "'.$urlSession.'",
data: "user_id="+my_user_id,
success: function(datos) {
$("div#"+div_session).html(datos);
$("div#div_s_"+my_user_id).attr("class","blackboard_show");
$("div#div_s_"+my_user_id).attr("style","");
}
});
}
function active_user(element_div) {
id_image=$(element_div).attr("id");
@ -62,7 +78,7 @@ function active_user(element_div) {
if (data == 1) {
$(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/accept.png'.'");
$(ident).attr("title","'.get_lang('Lock').'");
}
}
if (data == 0) {
$(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/error.png'.'");
$(ident).attr("title","'.get_lang('Unlock').'");
@ -80,38 +96,43 @@ function clear_course_list (div_course) {
$("div#"+div_course).html(" ");
$("div#"+div_course).hide("");
}
function clear_session_list (div_session) {
$("div#"+div_session).html(" ");
$("div#"+div_session).hide("");
}
function display_advanced_search_form () {
if ($("#advanced_search_form").css("display") == "none") {
$("#advanced_search_form").css("display","block");
$("#img_plus_and_minus").html(\' '.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedSearch').'\');
} else {
$("#advanced_search_form").css("display","none");
$("#img_plus_and_minus").html(\' '.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedSearch').'\');
}
if ($("#advanced_search_form").css("display") == "none") {
$("#advanced_search_form").css("display","block");
$("#img_plus_and_minus").html(\' '.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedSearch').'\');
} else {
$("#advanced_search_form").css("display","none");
$("#img_plus_and_minus").html(\' '.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedSearch').'\');
}
}
$(document).ready(function() {
var select_val = $("#input_select_extra_data").val();
if ( document.getElementById(\'extra_data_text\')) {
if (select_val != 0) {
document.getElementById(\'extra_data_text\').style.display="block";
if (document.getElementById(\'input_extra_text\'))
if (document.getElementById(\'input_extra_text\'))
document.getElementById(\'input_extra_text\').value = "";
} else {
document.getElementById(\'extra_data_text\').style.display="none";
}
}
$(".agenda_opener").live("click", function() {
var url = this.href;
var dialog = $("#dialog");
if ($("#dialog").length == 0) {
dialog = $(\'< div id = "dialog" style = "display:hidden" > < / div > \').appendTo(\'body\');
}
}
// load remote content
dialog.load(
url,
@ -122,11 +143,11 @@ $(document).ready(function() {
);
//prevent the browser to follow the link
return false;
});
});
});
//Load user calendar
function load_calendar(user_id, month, year) {
function load_calendar(user_id, month, year) {
var url = "'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda& user_id=" +user_id + "&month="+month+"&year="+year;
$("#dialog").load(url);
}
@ -145,20 +166,20 @@ api_protect_admin_script(true);
* @author Evie Embrechts
* @author Yannick Warnier < yannick.warnier @ dokeos . com >
*/
function login_user($user_id) {
function login_user($user_id) {
$user_id = intval($user_id);
if (empty($user_id)) {
return false;
}
if ($user_id != strval(intval($user_id))) {
return false;
}
//Only superadmins can login to admin accounts
if (!api_global_admin_can_edit_admin($user_id)) {
return false;
}
}
//Load $_user to be sure we clean it before logging in
global $uidReset, $loginFailed, $_configuration, $_user;
@ -199,7 +220,7 @@ function login_user($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";
ORDER BY login.login_date DESC LIMIT 1";
$sql_result = Database::query($sql_query);
@ -311,7 +332,7 @@ function get_number_of_users() {
"AND u.official_code LIKE '%".$keyword_officialcode."%'" .
"AND u.status LIKE '".$keyword_status."'" .
$keyword_admin.$keyword_extra_value;
if ($keyword_active & & !$keyword_inactive) {
if($keyword_active & & !$keyword_inactive) {
$sql .= " AND u.active='1'";
} elseif($keyword_inactive & & !$keyword_active) {
$sql .= " AND u.active='0'";
@ -339,13 +360,14 @@ function get_number_of_users() {
*/
function get_user_data($from, $number_of_items, $column, $direction) {
global $origin;
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
$sql = "SELECT
u.user_id AS col0,
u.official_code AS col2,
".(api_is_western_name_order()
? "u.firstname AS col3,
? "u.firstname AS col3,
u.lastname AS col4,"
: "u.lastname AS col3,
u.firstname AS col4,")."
@ -395,7 +417,7 @@ function get_user_data($from, $number_of_items, $column, $direction) {
}
$keyword_extra_value = '';
if (isset($_GET['keyword_extra_data'])) {
if (!empty($_GET['keyword_extra_data']) & & !empty($_GET['keyword_extra_data_text'])) {
$keyword_extra_data_text = Database::escape_string($_GET['keyword_extra_data_text']);
@ -451,7 +473,7 @@ function get_user_data($from, $number_of_items, $column, $direction) {
$users = array ();
$t = time();
while ($user = Database::fetch_row($res)) {
while ($user = Database::fetch_row($res)) {
$image_path = UserManager::get_user_picture_path_by_id($user[0], 'web', false, true);
$user_profile = UserManager::get_picture_user($user[0], $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" ');
if (!api_is_anonymous()) {
@ -500,23 +522,28 @@ function user_filter($name, $params, $row) {
* @return string Some HTML-code with modify-buttons
*/
function modify_filter($user_id, $url_params, $row) {
global $charset, $_admins_list, $delete_user_available;
global $charset, $_admins_list, $delete_user_available;
$is_admin = in_array($user_id,$_admins_list);
$statusname = api_get_status_langvars();
$user_is_anonymous = false;
$current_user_status_label = $row['7'];
if ($current_user_status_label == $statusname[ANONYMOUS]) {
$user_is_anonymous =true;
}
$result = '';
if (!$user_is_anonymous) {
$result .= '< a href = "javascript:void(0)" onclick = "load_course_list(\'div_'.$user_id.'\','.$user_id.')" >
< img onmouseout = "clear_course_list (\'div_'.$user_id.'\')" src = "../img/course.gif " title = "'.get_lang('Courses').'" alt = "'.get_lang('Courses').'" / >
< img onmouseout = "clear_course_list (\'div_'.$user_id.'\')" src = "../img/icons/22/ course.pn g" title = "'.get_lang('Courses').'" alt = "'.get_lang('Courses').'" / >
< div class = "blackboard_hide" id = "div_'.$user_id.'" > < / div >
< / a > ';
< / a > ';
$result .= '< a href = "javascript:void(0)" onclick = "load_session_list(\'div_s_'.$user_id.'\','.$user_id.')" >
< img onmouseout = "clear_session_list (\'div_s_'.$user_id.'\')" src = "../img/icons/22/session.png" title = "'.get_lang('Sessions').'" alt = "'.get_lang('Sessions').'" / >
< div class = "blackboard_hide" id = "div_s_'.$user_id.'" > < / div >
< / a > ';
} else {
$result .= Display::return_icon('course_na.gif',get_lang('Courses')).' ';
$result .= Display::return_icon('course_na.png',get_lang('Courses')).' ';
$result .= Display::return_icon('course_na.png',get_lang('Sessions')).' ';
}
if (api_is_platform_admin()) {
@ -533,7 +560,7 @@ function modify_filter($user_id, $url_params, $row) {
if (api_global_admin_can_edit_admin($user_id)) {
$result .= '< a href = "user_list.php?action=login_as&user_id='.$user_id.'&sec_token='.$_SESSION['sec_token'].'" > '.Display::return_icon('login_as.gif', get_lang('LoginAs')).'< / a > ';
} else {
$result .= Display::return_icon('login_as_na.gif', get_lang('LoginAs')).' ';
$result .= Display::return_icon('login_as_na.gif', get_lang('LoginAs')).' ';
}
//$result .= '< a href = "user_list.php?action=login_as&user_id='.$user_id.'&sec_token='.$_SESSION['sec_token'].'" > '.Display::return_icon('login_as.gif', get_lang('LoginAs')).'< / a > ';
} else {
@ -542,27 +569,29 @@ function modify_filter($user_id, $url_params, $row) {
} else {
$result .= Display::return_icon('login_as_na.gif', get_lang('LoginAs')).' ';
}
if ($current_user_status_label != $statusname[STUDENT]) {
$result .= Display::return_icon('statistics_na.gif', get_lang('Reporting')).' ';
} else {
$result .= '< a href = "../mySpace/myStudents.php?student='.$user_id.'" > '.Display::return_icon('statistics.gif', get_lang('Reporting')).'< / a > ';
}
if (api_is_platform_admin(true)) {
if (api_is_platform_admin(true)) {
if (!$user_is_anonymous & & api_global_admin_can_edit_admin($user_id, null, true)) {
$result .= '< a href = "user_edit.php?user_id='.$user_id.'" > '.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'< / a > ';
} else {
$result .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'< / a > ';
}
}
if ($is_admin) {
$result .= Display::return_icon('admin_star.png', get_lang('IsAdministrator'),array('width'=> ICON_SIZE_SMALL, 'heigth'=> ICON_SIZE_SMALL));
} else {
$result .= Display::return_icon('admin_star_na.png', get_lang('IsNotAdministrator'));
}
// actions for assigning sessions, courses or users
if (api_is_session_admin()) {
@ -578,17 +607,17 @@ function modify_filter($user_id, $url_params, $row) {
$result .= '< a href = "dashboard_add_sessions_to_user.php?user='.$user_id.'" > '.Display::return_icon('view_more_stats.gif', get_lang('AssignSessions')).'< / a > ';
}
}
if (api_is_platform_admin()) {
if (api_is_platform_admin()) {
$result .= ' < a href = "'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&user_id='.$user_id.'" class = "agenda_opener" > '.Display::return_icon('month.png', get_lang('FreeBusyCalendar'), array(), ICON_SIZE_SMALL).'< / a > ';
if ($delete_user_available) {
if ($user_id != api_get_user_id() & & !$user_is_anonymous & & api_global_admin_can_edit_admin($user_id)) {
if ($user_id != api_get_user_id() & & !$user_is_anonymous & & api_global_admin_can_edit_admin($user_id)) {
// you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore.
$result .= ' < a href = "user_list.php?action=delete_user&user_id='.$user_id.'&'.$url_params.'&sec_token='.$_SESSION['sec_token'].'" onclick = "javascript:if(!confirm('." ' " . addslashes ( api_htmlentities ( get_lang ( " ConfirmYourChoice " ) , ENT_QUOTES , $ charset ) ) . " ' " . ' ) ) return false ; " > '.Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'< / a > ';
} else {
$result .= Display::return_icon('delete_na.png', get_lang('Delete'), array(), ICON_SIZE_SMALL);
}
}
}
}
return $result;
}
@ -621,7 +650,7 @@ function active_filter($active, $url_params, $row) {
if ($action=='edit') {
$result = Display::return_icon($image.'.png', get_lang('AccountExpired'), array(), 16);
} elseif ($row['0']< >$_user['user_id']) {
// you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore.
// you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore.
$result = Display::return_icon($image.'.png', get_lang(ucfirst($action)), array('onclick'=>'active_user(this);', 'id'=>'img_'.$row['0']), 16).'< / a > ';
}
return $result;
@ -655,7 +684,7 @@ if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) {
$message = '';
if (!empty($action)) {
$check = Security::check_token('get');
$check = Security::check_token('get');
if ($check) {
switch ($action) {
case 'add_user_to_my_url':
@ -665,7 +694,7 @@ if (!empty($action)) {
$user_info = api_get_user_info($user_id);
$message = get_lang('UserAdded').' '.$user_info['firstname'].' '.$user_info['lastname'].' ('.$user_info['username'].')';
$message = Display::return_message($message, 'confirmation');
}
}
break;
case 'login_as':
$login_as_user_id = $_GET["user_id"];
@ -689,7 +718,7 @@ if (!empty($action)) {
if (api_is_platform_admin()) {
$user_to_delete = $_GET['user_id'];
$current_user_id = api_get_user_id();
if ($delete_user_available & & api_global_admin_can_edit_admin($_GET['user_id'])) {
if ($user_to_delete != $current_user_id & & UserManager :: delete_user($_GET['user_id'])) {
$message = Display :: return_message(get_lang('UserDeleted'), 'confirmation');
@ -714,10 +743,10 @@ if (!empty($action)) {
}
}
}
if ($number_of_selected_users == $number_of_deleted_users) {
if ($number_of_selected_users == $number_of_deleted_users) {
$message = Display :: return_message(get_lang('SelectedUsersDeleted'), 'confirmation');
} else {
$message = Display :: return_message(get_lang('SomeUsersNotDeleted'), 'error');
$message = Display :: return_message(get_lang('SomeUsersNotDeleted'), 'error');
}
}
break;
@ -832,7 +861,7 @@ if (!empty($extra_data)) {
$form->addElement('html', '< / td > < / tr > ');
$form->addElement('html', '< tr > < td > ');
$form->addElement('button', 'submit', get_lang('SearchUsers'));
$form->addElement('button', 'submit',get_lang('SearchUsers'));
$form->addElement('html', '< / td > < / tr > ');
$form->addElement('html', '< / table > ');
@ -881,27 +910,27 @@ $extra_search_options = '';
//Try to search the user everywhere
if ($table->get_total_number_of_items() == 0) {
if (api_get_multiple_access_url() & & isset($_REQUEST['keyword'])) {
if (api_get_multiple_access_url() & & isset($_REQUEST['keyword'])) {
$keyword = Database::escape_string($_REQUEST['keyword']);
//$conditions = array('firstname' => $keyword, 'lastname' => $keyword, 'username' => $keyword);
$conditions = array('username' => $keyword);
$user_list = UserManager::get_user_list($conditions, array(), false, ' OR ');
$user_list = UserManager::get_user_list($conditions, array(), false, ' OR ');
if (!empty($user_list)) {
$extra_search_options = Display::page_subheader(get_lang('UsersFoundInOtherPortals'));
$table = new HTML_Table(array('class' => 'data_table'));
$column = 0;
$row = 0;
$row = 0;
$headers = array(get_lang('User'), 'URL', get_lang('Actions'));
foreach ($headers as $header) {
$table->setHeaderContents($row, $column, $header);
$column++;
}
$row++;
foreach ($user_list as $user) {
foreach ($user_list as $user) {
$column = 0;
$access_info = UrlManager::get_access_url_from_user($user['user_id']);
$access_info_to_string = '';
@ -909,18 +938,18 @@ if ($table->get_total_number_of_items() == 0) {
if (!empty($access_info)) {
foreach ($access_info as $url_info) {
if ($current_access_url_id == $url_info['access_url_id']) {
$add_user = false;
$add_user = false;
}
$access_info_to_string .= $url_info['url'].'< br / > ';
}
}
if ($add_user) {
if ($add_user) {
$row_table = array();
$row_table[] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].') ';
$row_table[] = $access_info_to_string;
$url = api_get_self().'?action=add_user_to_my_url&user_id='.$user['user_id'].'&sec_token='.$_SESSION['sec_token'];
$row_table[] = Display::url(get_lang('AddUserToMyURL'), $url, array('class' => 'btn'));
foreach ($row_table as $cell) {
$table->setCellContents($row, $column, $cell);
$table->updateCellAttributes($row, $column, 'align="center"');
@ -933,7 +962,7 @@ if ($table->get_total_number_of_items() == 0) {
$extra_search_options .= $table->toHtml();
$table_result = '';
}
}
}
}
$tpl = new Template($tool_name);
@ -941,4 +970,4 @@ $tpl = new Template($tool_name);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$tpl->assign('content', $form.$table_result.$extra_search_options);
$tpl->display_one_col_template();
$tpl->display_one_col_template();