Skip to content

Commit

Permalink
Getting extra fields that have the filter option "on" in the user list
Browse files Browse the repository at this point in the history
See BT#9078
  • Loading branch information
jmontoyaa committed Dec 2, 2014
1 parent 4dd8d91 commit ac3d752
Showing 1 changed file with 79 additions and 35 deletions.
114 changes: 79 additions & 35 deletions main/user/user.php
Expand Up @@ -3,7 +3,7 @@

/**
* This script displays a list of the users of the current course.
* Course admins can change user perimssions, subscribe and unsubscribe users...
* Course admins can change user permissions, subscribe and unsubscribe users...
*
* EXPERIMENTAL: support for virtual courses
* - show users registered in virtual and real courses;
Expand Down Expand Up @@ -77,6 +77,10 @@
}
}

// Getting extra fields that have the filter option "on"
$extraField = new ExtraField('user');
$extraFields = $extraField->get_all(array('field_filter' => 1));

$user_image_pdf_size = 80;

if (api_is_allowed_to_edit(null, true)) {
Expand All @@ -89,11 +93,7 @@

$data = array();
$a_users = array();

if (api_is_multiple_url_enabled()) {
$current_access_url_id = api_get_current_access_url_id();
}

$current_access_url_id = api_get_current_access_url_id();
$extra_fields = UserManager::get_extra_user_data(
api_get_user_id(),
false,
Expand Down Expand Up @@ -198,19 +198,18 @@
active
$legal
FROM $table_session_course_user as session_course_user, $table_users as user ";
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au ';
}
$sql_query .=" WHERE course_code = '$course_code' AND session_course_user.id_user = user.user_id ";
$sql_query .= ' AND id_session = '.$session_id;

if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id ";
}

//only users no coaches/teachers
$sql_query .= " AND session_course_user.status = 0 ";

$sql_query .= $sort_by_first_name ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname';

$rs = Database::query($sql_query);
Expand Down Expand Up @@ -280,12 +279,15 @@
user.official_code,
active $legal
FROM $table_course_user as course_user, $table_users as user ";
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au ';
}
$sql_query .= " WHERE course_code = '$course_code' AND course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND course_user.user_id = user.user_id ";
$sql_query .= " WHERE
course_code = '$course_code' AND
course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND
course_user.user_id = user.user_id ";

if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id ";
}

Expand Down Expand Up @@ -319,7 +321,11 @@
}
if ($_GET['type'] == 'pdf') {
$user_info = api_get_user_info($user['user_id']);
$user_image = Display::img($user_info['avatar'], null, array('width' => $user_image_pdf_size.'px'));
$user_image = Display::img(
$user_info['avatar'],
null,
array('width' => $user_image_pdf_size.'px')
);

if ($is_western_name_order) {
$user_pdf = array(
Expand Down Expand Up @@ -409,7 +415,7 @@
}
}
} else {
//if student can unsubsribe
// If student can unsubscribe
if (isset($_REQUEST['unregister']) && $_REQUEST['unregister'] == 'yes') {
if ($course_info['unsubscribe'] == 1) {
$user_id = api_get_user_id();
Expand All @@ -420,9 +426,11 @@
}
}

/* FUNCTIONS */

function display_user_search_form() {
/**
* Display search form
*/
function display_user_search_form()
{
echo '<form method="get" action="user.php">';
echo get_lang("SearchForUser") . "&nbsp;&nbsp;";
echo '<input type="text" name="keyword" value="'.Security::remove_XSS($_GET['keyword']).'"/>';
Expand Down Expand Up @@ -457,11 +465,13 @@ function display_user_search_form() {
// Tool introduction
Display::display_introduction_section(TOOL_USER, 'left');
$actions = '';
if ( api_is_allowed_to_edit(null, true)) {
if (api_is_allowed_to_edit(null, true)) {
echo '<div class="actions">';

// the action links
if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or
api_is_platform_admin()
) {
$actions .= '<a href="subscribe_user.php?'.api_get_cidreq().'">'.
Display::return_icon('user_subscribe_course.png',get_lang("SubscribeUserToCourse"),'',ICON_SIZE_MEDIUM).'</a> ';
$actions .= "<a href=\"subscribe_user.php?".api_get_cidreq()."&type=teacher\">".
Expand All @@ -472,7 +482,9 @@ function display_user_search_form() {
$actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=xls">'.
Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a> ';

if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or
api_is_platform_admin()
) {
$actions .= '<a href="user_import.php?'.api_get_cidreq().'&action=import">'.
Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'),'',ICON_SIZE_MEDIUM).'</a> ';
}
Expand All @@ -482,7 +494,9 @@ function display_user_search_form() {
$actions .= "<a href=\"../group/group.php?".api_get_cidreq()."\">".
Display::return_icon('group.png', get_lang("GroupUserManagement"),'',ICON_SIZE_MEDIUM)."</a>";

if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or
api_is_platform_admin()
) {
$actions .= ' <a class="btn" href="class.php?'.api_get_cidreq().'">'.get_lang('Classes').'</a>';
}

Expand All @@ -505,11 +519,11 @@ function display_user_search_form() {
Display::display_confirmation_message($message);
}

/* DISPLAY LIST OF USERS */
/**
* Get the users to display on the current page.
*/
function get_number_of_users() {
function get_number_of_users()
{
$counter = 0;
$sessionId = api_get_session_id();
$courseCode = api_get_course_id();
Expand Down Expand Up @@ -588,11 +602,13 @@ function searchUserKeyword($firstname, $lastname, $username, $official_code, $ke
/**
* Get the users to display on the current page.
*/
function get_user_data($from, $number_of_items, $column, $direction) {
function get_user_data($from, $number_of_items, $column, $direction)
{
global $origin;
global $course_info;
global $is_western_name_order;
global $session_id;
global $extraFields;

$a_users = array();

Expand Down Expand Up @@ -718,6 +734,17 @@ function get_user_data($from, $number_of_items, $column, $direction) {
// Active
$temp[] = $o_course_user['active'];

if (!empty($extraFields)) {
foreach ($extraFields as $extraField) {
$extraFieldValue = new ExtraFieldValue('user');
$data = $extraFieldValue->get_values_by_handler_and_field_id(
$user_id,
$extraField['id']
);
$temp[] = $data['field_value'];
}
}

// User id for actions
$temp[] = $user_id;
} else {
Expand Down Expand Up @@ -753,6 +780,7 @@ function get_user_data($from, $number_of_items, $column, $direction) {
$a_users[$user_id] = $temp;
}
}

return $a_users;
}

Expand All @@ -766,8 +794,9 @@ function get_user_data($from, $number_of_items, $column, $direction) {
* @param string $url_params
* @return string Some HTML-code with the lock/unlock button
*/
function active_filter($active, $url_params, $row) {
global $_user;
function active_filter($active, $url_params, $row)
{
$userId = api_get_user_id();
if ($active=='1') {
$action='AccountActive';
$image='accept';
Expand All @@ -779,7 +808,7 @@ function active_filter($active, $url_params, $row) {
$result = '';
/* 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.*/
if ($row[count($row)-1]<>$_user['user_id']) {
if ($row[count($row)-1] <> $userId) {
$result = '<center><img src="../img/icons/16/'.$image.'.png" border="0" style="vertical-align: middle;" alt="'.get_lang(ucfirst($action)).'" title="'.get_lang(ucfirst($action)).'"/></center>';
}
return $result;
Expand All @@ -791,26 +820,31 @@ function active_filter($active, $url_params, $row) {
* @param int $user_id The user id
* @return string Some HTML-code
*/
function modify_filter($user_id) {
function modify_filter($user_id)
{
global $origin, $_course, $is_allowed_to_track, $charset, $course_info;

$current_user_id = api_get_user_id();

$result = "";

if ($is_allowed_to_track) {
$result .= '<a href="../mySpace/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&amp;details=true&amp;course='.$_course['id'].'&amp;origin=user_course&amp;id_session='.api_get_session_id().'" title="'.get_lang('Tracking').'" ><img border="0" alt="'.get_lang('Tracking').'" src="../img/icons/22/stats.png" /></a>';
$result .= '<a href="../mySpace/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&amp;details=true&amp;course='.$_course['id'].'&amp;origin=user_course&amp;id_session='.api_get_session_id().'" title="'.get_lang('Tracking').'" >
<img border="0" alt="'.get_lang('Tracking').'" src="../img/icons/22/stats.png" />
</a>';
}

// If platform admin, show the login_as icon (this drastically shortens
// time taken by support to test things out)
if (api_is_platform_admin()) {
$result .= ' <a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('login_as.gif', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
$result .= ' <a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.$_SESSION['sec_token'].'">'.
Display::return_icon('login_as.gif', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
}

if (api_is_allowed_to_edit(null, true)) {
// edit
$result .= '<a href="userInfo.php?'.api_get_cidreq().'&origin='.$origin.'&amp;editMainUserInfo='.$user_id.'" title="'.get_lang('Edit').'" >'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
$result .= '<a href="userInfo.php?'.api_get_cidreq().'&origin='.$origin.'&amp;editMainUserInfo='.$user_id.'" title="'.get_lang('Edit').'" >'.
Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
// unregister
if ($user_id != $current_user_id || api_is_platform_admin()) {
Expand All @@ -820,7 +854,7 @@ function modify_filter($user_id) {
}
}
} else {
//Show buttons for unsubscribe
// Show buttons for unsubscribe
if ($course_info['unsubscribe'] == 1) {
if ($user_id == $current_user_id) {
$result .= '<a class="btn btn-small btn-danger" href="'.api_get_self().'?'.api_get_cidreq().'&unregister=yes&amp;user_id='.$user_id.'" title="'.get_lang('Unreg').' " onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">'.get_lang('Unreg').'</a>&nbsp;';
Expand All @@ -830,7 +864,8 @@ function modify_filter($user_id) {
return $result;
}

function hide_field() {
function hide_field()
{
return null;
}

Expand Down Expand Up @@ -892,7 +927,12 @@ function hide_field() {
} else {
$table->set_column_filter(9, 'active_filter');
}
//actions column

foreach ($extraFields as $extraField) {
$table->set_header($header_nr++, $extraField['field_display_text'], false);
}

// Actions column
$table->set_header($header_nr++, get_lang('Action'), false);
$table->set_column_filter($header_nr-1, 'modify_filter');

Expand All @@ -913,7 +953,11 @@ function hide_field() {
echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
}

if (api_get_setting('allow_user_headings') == 'true' && $is_courseAdmin && api_is_allowed_to_edit() && $origin != 'learnpath') { // only course administrators see this line
if (api_get_setting('allow_user_headings') == 'true' &&
$is_courseAdmin &&
api_is_allowed_to_edit() && $origin != 'learnpath'
) {
// only course administrators see this line
echo "<div align=\"right\">", "<form method=\"post\" action=\"userInfo.php\">", get_lang("CourseAdministratorOnly"), " : ", "<input type=\"submit\" class=\"save\" name=\"viewDefList\" value=\"".get_lang("DefineHeadings")."\" />", "</form>", "</div>\n";
}
if ($origin != 'learnpath') {
Expand Down

0 comments on commit ac3d752

Please sign in to comment.