diff --git a/main/user/add_users_to_session.php b/main/user/add_users_to_session.php index b052d291a6..da2eadb84f 100755 --- a/main/user/add_users_to_session.php +++ b/main/user/add_users_to_session.php @@ -1,8 +1,9 @@ registerFunction('search_users'); // setting the section (for the tabs) $this_section = SECTION_PLATFORM_ADMIN; - $id_session = intval($_GET['id_session']); SessionManager::protect_teacher_session_edit($id_session); // setting breadcrumbs if (api_is_platform_admin()) { - $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); - $interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList')); - $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id_session, "name" => get_lang('SessionOverview')); + $interbreadcrumb[] = array( + 'url' => 'index.php', + 'name' => get_lang('PlatformAdmin') + ); + $interbreadcrumb[] = array( + 'url' => 'session_list.php', + 'name' => get_lang('SessionList') + ); + $interbreadcrumb[] = array( + 'url' => "resume_session.php?id_session=".$id_session, + "name" => get_lang('SessionOverview') + ); } $allowTutors = api_get_setting('allow_tutors_to_assign_students_to_session'); $extra_field_list = []; @@ -49,62 +58,59 @@ if ($allowTutors == 'true') { $extra_field_list = UserManager::get_extra_fields(); $new_field_list = array(); if (is_array($extra_field_list)) { - foreach ($extra_field_list as $extra_field) { - //if is enabled to filter and is a "" field type + if ($extra_field[8] == 1 && $extra_field[2] == 4) { $new_field_list[] = array( 'name' => $extra_field[3], 'variable' => $extra_field[1], 'data' => $extra_field[9], ); - } - } + } + } } function search_users($needle, $type) { - global $id_session; - + global $id_session; $tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); + $xajax_response = new xajaxResponse(); + $return = ''; - $xajax_response = new xajaxResponse(); - $return = ''; - - if (!empty($needle) && !empty($type)) { - + if (!empty($needle) && !empty($type)) { //normal behaviour if ($type == 'any_session' && $needle == 'false') { $type = 'multiple'; $needle = ''; } - // xajax send utf8 datas... datas in db can be non-utf8 datas - $charset = api_get_system_encoding(); - $needle = Database::escape_string($needle); - $needle = api_convert_encoding($needle, $charset, 'utf-8'); + // xajax send utf8 datas... datas in db can be non-utf8 datas + $charset = api_get_system_encoding(); + $needle = Database::escape_string($needle); + $needle = api_convert_encoding($needle, $charset, 'utf-8'); - $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; - $cond_user_id = ''; + $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; + $cond_user_id = ''; //Only for single & multiple if (in_array($type, array('single', 'multiple'))) { - if (!empty($id_session)) { - $id_session = intval($id_session); - // check id_user from session_rel_user table - $sql = 'SELECT user_id FROM '.$tbl_session_rel_user.' - WHERE session_id ="'.$id_session.'" AND relation_type<>'.SESSION_RELATION_TYPE_RRHH.' '; - $res = Database::query($sql); - $user_ids = array(); - if (Database::num_rows($res) > 0) { - while ($row = Database::fetch_row($res)) { - $user_ids[] = (int) $row[0]; - } - } - if (count($user_ids) > 0) { - $cond_user_id = ' AND user.user_id NOT IN('.implode(",", $user_ids).')'; - } - } + if (!empty($id_session)) { + $id_session = intval($id_session); + // check id_user from session_rel_user table + $sql = 'SELECT user_id FROM '.$tbl_session_rel_user.' + WHERE session_id ="'.$id_session.'" AND relation_type<>'.SESSION_RELATION_TYPE_RRHH.' '; + $res = Database::query($sql); + $user_ids = array(); + if (Database::num_rows($res) > 0) { + while ($row = Database::fetch_row($res)) { + $user_ids[] = (int) $row[0]; + } + } + if (count($user_ids) > 0) { + $cond_user_id = ' AND user.user_id NOT IN('.implode(",", $user_ids).')'; + } + } } switch ($type) { @@ -136,11 +142,11 @@ if ($allowTutors == 'true') { user.status <> 6 '.$cond_user_id. $order_clause; break; - } - if (api_is_multiple_url_enabled()) { - $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1) { + } + if (api_is_multiple_url_enabled()) { + $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1) { switch ($type) { case 'single': $sql = 'SELECT user.user_id, username, lastname, firstname @@ -164,7 +170,7 @@ if ($allowTutors == 'true') { '.(api_sort_by_first_name() ? 'firstname' : 'lastname').' LIKE "'.$needle.'%" AND user.status<>'.DRH.' AND user.status<>6 '.$cond_user_id. $order_clause; break; - case 'any_session' : + case 'any_session': $sql = 'SELECT DISTINCT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user LEFT OUTER JOIN '.$tbl_session_rel_user.' s @@ -178,65 +184,64 @@ if ($allowTutors == 'true') { user.status<>6 '.$cond_user_id. $order_clause; break; - } - } - } + } + } + } - $rs = Database::query($sql); + $rs = Database::query($sql); $i = 0; - if ($type == 'single') { - while ($user = Database::fetch_array($rs)) { - $i++; - if ($i <= 10) { - $person_name = api_get_person_name($user['firstname'], $user['lastname']); - $return .= ''.$person_name.' ('.$user['username'].')
'; - } else { - $return .= '...
'; - } - } - - $xajax_response -> addAssign('ajax_list_users_single', 'innerHTML', api_utf8_encode($return)); - } else { - $return .= ''; - $xajax_response -> addAssign('ajax_list_users_multiple', 'innerHTML', api_utf8_encode($return)); - } - } - - return $xajax_response; + if ($type == 'single') { + while ($user = Database::fetch_array($rs)) { + $i++; + if ($i <= 10) { + $person_name = api_get_person_name($user['firstname'], $user['lastname']); + $return .= ''.$person_name.' ('.$user['username'].')
'; + } else { + $return .= '...
'; + } + } + + $xajax_response -> addAssign('ajax_list_users_single', 'innerHTML', api_utf8_encode($return)); + } else { + $return .= ''; + $xajax_response -> addAssign('ajax_list_users_multiple', 'innerHTML', api_utf8_encode($return)); + } + } + + return $xajax_response; } - $xajax -> processRequests(); + $xajax->processRequests(); $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/'); $htmlHeadXtra[] = ' '. Display::return_icon('back.png', get_lang("Classes"), array(), ICON_SIZE_MEDIUM).''; - $form = new FormValidator('groups', 'post', api_get_self(), '', '', FormValidator::LAYOUT_INLINE); + $form = new FormValidator( + 'groups', + 'post', + api_get_self(), + '', + [], + FormValidator::LAYOUT_INLINE + ); $options = [ -1 => get_lang('All'), 1 => get_lang('SocialGroups'), 0 => get_lang('Classes') ]; - $form->addSelect('group_filter', get_lang('Groups'), $options, ['id' => 'group_filter']); + $form->addSelect( + 'group_filter', + get_lang('Groups'), + $options, + ['id' => 'group_filter'] + ); $form->setDefaults(['group_filter' => $groupFilter]); $actionsRight = $form->returnForm(); } @@ -89,7 +102,6 @@ if (api_is_allowed_to_edit()) { } //jqgrid will use this URL to do the selects - $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type.'&group_filter='.$groupFilter; //The order is important you need to check the the $column variable in the model.ajax.php file @@ -146,7 +158,16 @@ Display :: display_header($tool_name, "User"); $(function() { display() function - echo Display::grid_js('usergroups', $url, $columns, $columnModel, $extraParams, array(), '', true); + echo Display::grid_js( + 'usergroups', + $url, + $columns, + $columnModel, + $extraParams, + array(), + '', + true + ); ?> });