Hacked By AnonymousFox

Current Path : /home/missmand/public_html/learning/old/main/admin/
Upload File :
Current File : /home/missmand/public_html/learning/old/main/admin/user_list.php

<?php
/* For licensing terms, see /license.txt */
/**
	@author Bart Mollet
	@author Julio Montoya <gugli100@gmail.com> BeezNest 2011
*	@package chamilo.admin
*/

// name of the language file that needs to be included
$language_file = array ('registration','admin');
$cidReset = true;
require_once '../inc/global.inc.php';
require_once(api_get_path(SYS_PATH) . 'main/admin/user_list_methods.php');

global $_configuration;

$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;
}
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=get_user_courses';
        
$htmlHeadXtra[] = '<script type="text/javascript">
function load_course_list (div_course,my_user_id) {
	 $.ajax({
		contentType: "application/x-www-form-urlencoded",
		beforeSend: function(objeto) {
            $("div#"+div_course).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
		type: "POST",
		url: "'.$url.'",
		data: "user_id="+my_user_id,
		success: function(datos) {
			$("div#"+div_course).html(datos);
			$("div#div_"+my_user_id).attr("class","blackboard_show");
			$("div#div_"+my_user_id).attr("style","");
		}
	});
}

function active_user(element_div) {
	id_image=$(element_div).attr("id");
	image_clicked=$(element_div).attr("src");
	image_clicked_info = image_clicked.split("/");
	image_real_clicked = image_clicked_info[image_clicked_info.length-1];
	var status = 1;
	if (image_real_clicked == "accept.png") {
		status = 0;
	}
	user_id=id_image.split("_");
	ident="#img_"+user_id[1];
	if (confirm("'.get_lang('AreYouSureToEditTheUserStatus', '').'")) {
		 $.ajax({
			contentType: "application/x-www-form-urlencoded",
			beforeSend: function(objeto) {
				$(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'loading1.gif'.'"); }, //candy eye stuff
			type: "GET",
			url: "'.api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=active_user",
			data: "user_id="+user_id[1]+"&status="+status,
			success: function(data) {
				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').'");
				}
                if (data == -1) {
                    $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/warning.png'.'");
					$(ident).attr("title","'.get_lang('ActionNotAllowed').'");
                }
			}
		});
	}
}

function clear_course_list (div_course) {
	$("div#"+div_course).html("&nbsp;");
	$("div#"+div_course).hide("");
}

function display_advanced_search_form () {
        if ($("#advanced_search_form").css("display") == "none") {
                $("#advanced_search_form").css("display","block");
                $("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedSearch').'\');
        } else {
                $("#advanced_search_form").css("display","none");
                $("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.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\')) 
                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,
                {},
                function(responseText, textStatus, XMLHttpRequest) {
                    dialog.dialog({width:720, height:550, modal:true});
                }
            );
        //prevent the browser to follow the link
        return false;
    });    
});

//Load user calendar
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    	 	
	);    	
}
</script>';

$this_section = SECTION_PLATFORM_ADMIN;

api_protect_admin_script(true);

$action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : null;

if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) {
    $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
    $interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList'));
    $tool_name = get_lang('SearchUsers');
} else {
    $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
    $tool_name = get_lang('UserList');
}

$message = '';

if (!empty($action)) {
	$check = Security::check_token('get');    
	if ($check) {
		switch ($action) {
            case 'add_user_to_my_url':
                $user_id = $_REQUEST["user_id"];
                $result = UrlManager::add_user_to_url($user_id, $current_access_url_id);
                if ($result ) {
                    $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"];
                if (isset ($login_as_user_id)) {
                    login_user($login_as_user_id);
                }
                break;
			case 'show_message' :
                if (!empty($_GET['warn'])) {
                	// to prevent too long messages
                	if ($_GET['warn'] == 'session_message'){
                		$_GET['warn'] = $_SESSION['session_message_import_users'];
                	}
                	$message = Display::return_message(urldecode($_GET['warn']),'warning', false);
                }
                if (!empty($_GET['message'])) {
                    $message = Display :: return_message(stripslashes($_GET['message']), 'confirmation');
                }
				break;
			case 'delete_user' :
				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');
						} else {
							$message = Display :: return_message(get_lang('CannotDeleteUserBecauseOwnsCourse'), 'error');
						}
					} else {
						$message = Display :: return_message(get_lang('CannotDeleteUser'),'error');
					}
				}
				break;
            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) {						
                        $message = Display :: return_message(get_lang('SelectedUsersDeleted'), 'confirmation');
					} else {
                        $message = Display :: return_message(get_lang('SomeUsersNotDeleted'), 'error');						
					}
				}
				break;
		}
		Security::clear_token();
	}
}

// Create a search-box
$form = new FormValidator('search_simple','get', '', '', array('class' => 'form-search'),false);
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<span>{element}</span> ');
$form->addElement('text','keyword',get_lang('keyword'), 'size="25"');
$form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="btn"');
$form->addElement('static','search_advanced_link',null,'<a href="javascript://" class = "advanced_parameters" onclick="display_advanced_search_form();"><span id="img_plus_and_minus">&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedSearch').'</span></a>');

$actions  = '';
if (api_is_platform_admin()) {
	$actions .= '<span style="float:right;">'.
		 '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_add.php">'.Display::return_icon('new_user.png',get_lang('AddUsers'),'',ICON_SIZE_MEDIUM).'</a>'.
		 '</span>';
}
$actions .=$form->return_form();

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_username']	 	= Security::remove_XSS($_GET['keyword_username']);
	$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];
}

// display advaced search form
$form = new FormValidator('advanced_search','get');

$form->addElement('html','<div id="advanced_search_form" style="display:none;">');
$form->addElement('header', get_lang('AdvancedSearch'));
$form->addElement('html', '<table>');

$form->addElement('html', '<tr><td>');
$form->add_textfield('keyword_firstname',get_lang('FirstName'),false,array('style'=>'margin-left:17px'));
$form->addElement('html', '</td><td width="200px;">');
$form->add_textfield('keyword_lastname',get_lang('LastName'),false,array('style'=>'margin-left:17px'));
$form->addElement('html', '</td></tr>');

$form->addElement('html', '<tr><td>');
$form->add_textfield('keyword_username',get_lang('LoginName'),false,array('style'=>'margin-left:17px'));
$form->addElement('html', '</td>');
$form->addElement('html', '<td>');
$form->add_textfield('keyword_email',get_lang('Email'),false,array('style'=>'margin-left:17px'));
$form->addElement('html', '</td></tr>');

$form->addElement('html', '<tr><td>');
$form->add_textfield('keyword_officialcode',get_lang('OfficialCode'),false,array('style'=>'margin-left:17px'));
$form->addElement('html', '</td><td>');

$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('Profile'),$status_options, array('style'=>'margin-left:17px'));
$form->addElement('html', '</td></tr>');

$form->addElement('html', '<tr><td>');
$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'),'<br/>',false);
$form->addElement('html', '</td><td>');


/*
 * @todo fix this code
$extra_data = UserManager::get_extra_fields( 0,10,5, 'ASC', true, 1);
var_dump($extra_data);
$extra_options = array();
if (!empty($extra_data)) {
    $extra_options[0] = get_lang('All');
    // get information about extra data for adding to input select
    foreach ($extra_data as $field_variable => $field_value) {
        $extra = UserManager::get_extra_field_information_by_name($field_variable);
        $extra_options[$field_variable] = $extra['field_display_text'];
    }

    $form->addElement('select', 'keyword_extra_data', get_lang('ExtraData'), $extra_options, array('id'=>'input_select_extra_data', 'style'=>'margin-left:17px', 'onchange'=>'if(this.value!=0){document.getElementById(\'extra_data_text\').style.display=\'block\';document.getElementById(\'input_extra_text\').value = "";}else{document.getElementById(\'extra_data_text\').style.display=\'none\';}'));
    $form->addElement('html', '<div id="extra_data_text" style="display:none;">');
    $form->add_textfield('keyword_extra_data_text', '', false, array('style'=>'margin-left:17px', 'id'=>'input_extra_text'));
    $form->addElement('html', '</div>');
} else {
    $form->addElement('html', '<div id="extra_data_text" style="display:none;">');
}*/

$form->addElement('html', '</td></tr>');

$form->addElement('html', '<tr><td>');
$form->addElement('button', 'submit',get_lang('SearchUsers'));
$form->addElement('html', '</td></tr>');

$form->addElement('html', '</table>');

$defaults = array();
$defaults['keyword_active'] = 1;
$defaults['keyword_inactive'] = 1;
$form->setDefaults($defaults);
$form->addElement('html','</div>');

$form = $form->return_form();

$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, 'Role');
$table->set_header(8, get_lang('Active'), true, 'width="15px"');
$table->set_header(9, get_lang('RegistrationDate'), true, 'width="90px"');
$table->set_header(10, 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(8, 'active_filter');
$table->set_column_filter(10, 'modify_filter');

if (api_is_platform_admin())
	$table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform')));

$table_result = $table->return_table();

$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'])) {     
        $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 ');        
        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;            
            $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) {      
                $column = 0;
                $access_info = UrlManager::get_access_url_from_user($user['user_id']);
                $access_info_to_string = '';
                $add_user = true;
                if (!empty($access_info)) {
                    foreach ($access_info as $url_info) {
                        if ($current_access_url_id == $url_info['access_url_id']) {
                            $add_user = false;                            
                        }
                        $access_info_to_string .= $url_info['url'].'<br />';
                    }
                }
                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"');
                        $column++;
                    }
                    $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
                    $row++;
                }
            }
            $extra_search_options .= $table->toHtml();
            $table_result = '';
        }
    }    
}

$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();

Hacked By AnonymousFox1.0, Coded By AnonymousFox