';
}
return $result;
}
/**
* Lock or unlock a user
* @author Patrick Cool
, Ghent University
* @param int $status, do we want to lock the user ($status=lock) or unlock it ($status=unlock)
* @param int $user_id The user id
* @return language variable
*/
function lock_unlock_user($status,$user_id)
{
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
if ($status=='lock')
{
$status_db='0';
$return_message=get_lang('UserLocked');
}
if ($status=='unlock')
{
$status_db='1';
$return_message=get_lang('UserUnlocked');
}
if(($status_db=='1' OR $status_db=='0') AND is_numeric($user_id))
{
$sql="UPDATE $user_table SET active='".Database::escape_string($status_db)."' WHERE user_id='".Database::escape_string($user_id)."'";
$result = Database::query($sql);
}
if ($result)
{
return $return_message;
}
}
/**
* Instead of displaying the integer of the status, we give a translation for the status
*
* @param integer $status
* @return string translation
*
* @version march 2008
* @author Patrick Cool , Ghent University, Belgium
*/
function status_filter($status)
{
$statusname = api_get_status_langvars();
return $statusname[$status];
}
/**
==============================================================================
INIT SECTION
==============================================================================
*/
$action = $_GET["action"];
$login_as_user_id = $_GET["user_id"];
// Login as ...
if ($_GET['action'] == "login_as" && isset ($login_as_user_id))
{
login_user($login_as_user_id);
}
if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
{
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList'));
$tool_name = get_lang('SearchAUser');
Display :: display_header($tool_name);
//api_display_tool_title($tool_name);
$form = new FormValidator('advanced_search','get');
$form->addElement('header', '', $tool_name);
$form->add_textfield('keyword_firstname',get_lang('FirstName'),false);
$form->add_textfield('keyword_lastname',get_lang('LastName'),false);
$form->add_textfield('keyword_username',get_lang('LoginName'),false);
$form->add_textfield('keyword_email',get_lang('Email'),false);
$form->add_textfield('keyword_officialcode',get_lang('OfficialCode'),false);
$status_options = array();
$status_options['%'] = get_lang('All');
$status_options[STUDENT] = get_lang('Student');
$status_options[COURSEMANAGER] = get_lang('Teacher');
$status_options[DRH] = get_lang('Drh');
$status_options[SESSIONADMIN] = get_lang('Administrator');//
$form->addElement('select','keyword_status',get_lang('Status'),$status_options);
$active_group = array();
$active_group[] = $form->createElement('checkbox','keyword_active','',get_lang('Active'));
$active_group[] = $form->createElement('checkbox','keyword_inactive','',get_lang('Inactive'));
$form->addGroup($active_group,'',get_lang('ActiveAccount'),'
',false);
$form->addElement('style_submit_button', 'submit',get_lang('SearchUsers'),'class="search"');
$defaults['keyword_active'] = 1;
$defaults['keyword_inactive'] = 1;
$form->setDefaults($defaults);
$form->display();
}
else
{
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$tool_name = get_lang('UserList');
Display :: display_header($tool_name, "");
//api_display_tool_title($tool_name);
if (isset ($_GET['action'])) {
$check = Security::check_token('get');
if($check) {
switch ($_GET['action']) {
case 'show_message' :
if (!empty($_GET['warn'])) {
// to prevent too long messages
if ($_GET['warn'] == 'session_message'){
$_GET['warn'] = $_SESSION['session_message_import_users'];
}
Display::display_warning_message(urldecode($_GET['warn']),false);
}
if (!empty($_GET['message'])) {
Display :: display_confirmation_message(stripslashes($_GET['message']));
}
break;
case 'delete_user' :
if (api_is_platform_admin()) {
if ($user_id != $_user['user_id'] && UserManager :: delete_user($_GET['user_id'])) {
Display :: display_confirmation_message(get_lang('UserDeleted'));
} else {
Display :: display_error_message(get_lang('CannotDeleteUserBecauseOwnsCourse'));
}
}
break;
case 'lock' :
$message=lock_unlock_user('lock',$_GET['user_id']);
Display :: display_normal_message($message);
break;
case 'unlock';
$message=lock_unlock_user('unlock',$_GET['user_id']);
Display :: display_normal_message($message);
break;
}
Security::clear_token();
}
}
if (isset ($_POST['action']))
{
$check = Security::check_token('get');
if($check)
{
switch ($_POST['action'])
{
case 'delete' :
if (api_is_platform_admin()) {
$number_of_selected_users = count($_POST['id']);
$number_of_deleted_users = 0;
if (is_array($_POST['id'])) {
foreach ($_POST['id'] as $index => $user_id)
{
if($user_id != $_user['user_id'])
{
if(UserManager :: delete_user($user_id))
{
$number_of_deleted_users++;
}
}
}
}
if($number_of_selected_users == $number_of_deleted_users)
{
Display :: display_confirmation_message(get_lang('SelectedUsersDeleted'));
}
else
{
Display :: display_error_message(get_lang('SomeUsersNotDeleted'));
}
}
break;
}
Security::clear_token();
}
}
// Create a search-box
$form = new FormValidator('search_simple','get','','',null,false);
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('{element} ');
$form->addElement('text','keyword',get_lang('keyword'));
$form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="search"');
$form->addElement('static','search_advanced_link',null,''.get_lang('AdvancedSearch').'');
echo '';
if (isset ($_GET['keyword'])) {
$parameters = array ('keyword' => Security::remove_XSS($_GET['keyword']));
} elseif (isset ($_GET['keyword_firstname'])) {
$parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']);
$parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']);
$parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']);
$parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']);
$parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']);
$parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']);
$parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']);
}
// Create a sortable table with user-data
$parameters['sec_token'] = Security::get_token();
// get the list of all admins to mark them in the users list
$admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
$sql_admin = "SELECT user_id FROM $admin_table";
$res_admin = Database::query($sql_admin);
$_admins_list = array();
while ($row_admin = Database::fetch_row($res_admin)) {
$_admins_list[] = $row_admin[0];
}
$image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
$user_profile = UserManager::get_picture_user($user_id, $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" ');
if (!api_is_anonymous()) {
$photo = '
';
} else {
$photo = '
';
}
$table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2);
$table->set_additional_parameters($parameters);
$table->set_header(0, '', false, 'width="18px"');
$table->set_header(1, get_lang('Photo'), false);
$table->set_header(2, get_lang('OfficialCode'));
if (api_is_western_name_order()) {
$table->set_header(3, get_lang('FirstName'));
$table->set_header(4, get_lang('LastName'));
} else {
$table->set_header(3, get_lang('LastName'));
$table->set_header(4, get_lang('FirstName'));
}
$table->set_header(5, get_lang('LoginName'));
$table->set_header(6, get_lang('Email'));
$table->set_header(7, get_lang('Status'));
$table->set_header(8, get_lang('Active'),true, 'width="15px"');
$table->set_header(9, get_lang('Action'), false,'width="220px"');
$table->set_column_filter(3, 'user_filter');
$table->set_column_filter(4, 'user_filter');
$table->set_column_filter(6, 'email_filter');
$table->set_column_filter(7, 'status_filter');
$table->set_column_filter(8, 'active_filter');
$table->set_column_filter(9, 'modify_filter');
if (api_is_platform_admin())
$table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform')));
$table->display();
}
/*
==============================================================================
FOOTER
==============================================================================
*/
Display :: display_footer();
?>