'index.php', "name" => get_lang('PlatformAdmin'));
$htmlHeadXtra[] = '
';
// displaying the header
Display :: display_header($tool_name);
$link_add_group = ''.Display::return_icon('multiple.gif',get_lang('RegistrationByUsersGroups')).get_lang('RegistrationByUsersGroups').' ';
echo '
'.$link_add_group.'
';
// displaying the tool title
// api_display_tool_title($tool_name);
$form = new FormValidator('subscribe_user2course');
$form->addElement('header', '', $tool_name);
$form->display();
/* MAIN CODE */
//checking for extra field with filter on
$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]);
}
}
}
/* React on POSTed request */
if (!empty($_POST['form_sent'])) {
$form_sent = $_POST['form_sent'];
$users = (isset($_POST['UserList']) && is_array($_POST['UserList']) ? $_POST['UserList'] : array());
$courses = (isset($_POST['CourseList']) && is_array($_POST['CourseList']) ? $_POST['CourseList'] : array());
$first_letter_user = $_POST['firstLetterUser'];
$first_letter_course = $_POST['firstLetterCourse'];
foreach ($users as $key => $value) {
$users[$key] = intval($value);
}
if ($form_sent == 1) {
if ( count($users) == 0 || count($courses) == 0) {
Display :: display_error_message(get_lang('AtLeastOneUserAndOneCourse'));
} else {
foreach ($courses as $course_code) {
foreach ($users as $user_id) {
CourseManager::subscribe_user($user_id,$course_code);
}
}
Display :: display_confirmation_message(get_lang('UsersAreSubscibedToCourse'));
}
}
}
/* Display GUI */
if(empty($first_letter_user)) {
$sql = "SELECT count(*) as nb_users FROM $tbl_user";
$result = Database::query($sql);
$num_row = Database::fetch_array($result);
if($num_row['nb_users']>1000)
{//if there are too much users to gracefully handle with the HTML select list,
// assign a default filter on users names
$first_letter_user = 'A';
}
unset($result);
}
//Filter by Extra Fields
$use_extra_fields = false;
if (is_array($extra_field_list)) {
if (is_array($new_field_list) && count($new_field_list)>0 ) {
$result_list=array();
foreach ($new_field_list as $new_field) {
$varname = 'field_'.$new_field['variable'];
if (UserManager::is_extra_field_available($new_field['variable'])) {
if (isset($_POST[$varname]) && $_POST[$varname]!='0') {
$use_extra_fields = true;
$extra_field_result[]= UserManager::get_extra_user_data_by_value($new_field['variable'], $_POST[$varname]);
}
}
}
}
}
$where_filter ='';
if ($use_extra_fields) {
$final_result = array();
if (count($extra_field_result)>1) {
for($i=0;$i0) {
$where_filter = " AND u.user_id IN ('".implode("','",$final_result)."') ";
} else {
//no results
$where_filter = " AND u.user_id = -1";
}
} else {
if (is_array($final_result) && count($final_result)>0) {
$where_filter = " AND user_id IN ('".implode("','",$final_result)."') ";
} else {
//no results
$where_filter = " AND user_id = -1";
}
}
}
$target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
$sql = "SELECT user_id,lastname,firstname,username
FROM $tbl_user
WHERE user_id<>2 AND ".$target_name." LIKE '".$first_letter_user."%' $where_filter
ORDER BY ". (count($users) > 0 ? "(user_id IN(".implode(',', $users).")) DESC," : "")." ".$target_name;
global $_configuration;
if ($_configuration['multiple_access_urls']) {
$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){
$sql = "SELECT u.user_id,lastname,firstname,username FROM ".$tbl_user ." u
INNER JOIN $tbl_user_rel_access_url user_rel_url
ON (user_rel_url.user_id = u.user_id)
WHERE u.user_id<>2 AND access_url_id = $access_url_id AND (".$target_name." LIKE '".$first_letter_user."%' ) $where_filter
ORDER BY ". (count($users) > 0 ? "(u.user_id IN(".implode(',', $users).")) DESC," : "")." ".$target_name;
}
}
$result = Database::query($sql);
$db_users = Database::store_result($result);
unset($result);
$sql = "SELECT code,visual_code,title FROM $tbl_course WHERE visual_code LIKE '".$first_letter_course."%' ORDER BY ". (count($courses) > 0 ? "(code IN('".implode("','", $courses)."')) DESC," : "")." visual_code";
if (api_is_multiple_url_enabled()) {
$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1){
$sql = "SELECT code, visual_code, title
FROM $tbl_course as course
INNER JOIN $tbl_course_rel_access_url course_rel_url
ON (course_rel_url.c_id = course.id)
WHERE access_url_id = $access_url_id AND (visual_code LIKE '".$first_letter_course."%' )
ORDER BY ". (count($courses) > 0 ? "(code IN('".implode("','", $courses)."')) DESC," : "")." visual_code";
}
}
$result = Database::query($sql);
$db_courses = Database::store_result($result);
unset($result);
if (api_is_multiple_url_enabled()) {
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1){
$sqlNbCours = " SELECT course_rel_user.course_code, course.title
FROM $tbl_course_user as course_rel_user
INNER JOIN $tbl_course as course
ON course.code = course_rel_user.course_code
INNER JOIN $tbl_course_rel_access_url course_rel_url
ON (course_rel_url.c_id = course.id)
WHERE access_url_id = $access_url_id AND
course_rel_user.user_id='".$_user['user_id']."' AND
course_rel_user.status='1'
ORDER BY course.title";
}
}
?>