### Eclipse Workspace Patch 1.0 #P moodle Index: admin/user/actions/removefromcourses/version.php =================================================================== RCS file: admin/user/actions/removefromcourses/version.php diff -N admin/user/actions/removefromcourses/version.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/removefromcourses/version.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +version = 2008101800; +$plugin->requires = 2008101800; + +?> Index: admin/user/actions/removefromcourses/lang/en_utf8/bulkuseractions_removefromcourses.php =================================================================== RCS file: admin/user/actions/removefromcourses/lang/en_utf8/bulkuseractions_removefromcourses.php diff -N admin/user/actions/removefromcourses/lang/en_utf8/bulkuseractions_removefromcourses.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/removefromcourses/lang/en_utf8/bulkuseractions_removefromcourses.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,12 @@ +'; +$string['confirmpart2'] = 'from courses:'; +$string['removeall'] = 'Remove all from selection'; + +?> Index: admin/user/actions/removefromcourses/lang/ru_utf8/bulkuseractions_removefromcourses.php =================================================================== RCS file: admin/user/actions/removefromcourses/lang/ru_utf8/bulkuseractions_removefromcourses.php diff -N admin/user/actions/removefromcourses/lang/ru_utf8/bulkuseractions_removefromcourses.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/removefromcourses/lang/ru_utf8/bulkuseractions_removefromcourses.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,12 @@ +'; +$string['confirmpart2'] = 'с курсов:'; +$string['removeall'] = 'Удалить все из выбранных'; + +?> Index: admin/user/actions/removefromcourses/index.php =================================================================== RCS file: admin/user/actions/removefromcourses/index.php diff -N admin/user/actions/removefromcourses/index.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/removefromcourses/index.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,244 @@ +libdir.'/adminlib.php'); + +$allcourses = optional_param('allcourses', '', PARAM_CLEAN); +$selcourses = optional_param('selcourses', '', PARAM_CLEAN); +$accept = optional_param('accept', 0, PARAM_BOOL); +$confirm = optional_param('confirm', 0, PARAM_BOOL); +$cancel = optional_param('cancel', 0, PARAM_BOOL); +$searchtext = optional_param('searchtext', '', PARAM_RAW); +$showall = optional_param('showall', 0, PARAM_BOOL); +$listadd = optional_param('add', 0, PARAM_BOOL); +$listremove = optional_param('remove', 0, PARAM_BOOL); +$removeall = optional_param('removeall', 0, PARAM_BOOL); + +admin_externalpage_setup('userbulk'); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; + +if ($showall) { + $searchtext = ''; +} + +$strsearch = get_string('search'); +$langdir = $CFG->dirroot.'/admin/user/actions/removefromcourses/lang/'; +$pluginname = 'bulkuseractions_removefromcourses'; + +if (empty($SESSION->bulk_users) || $cancel) { + redirect($return); +} + +if (!isset($SESSION->bulk_courses) || $removeall) + $SESSION->bulk_courses = array(); + +// course selection add/remove actions +if ($listadd && !empty($allcourses)) { + foreach ($allcourses as $course) { + if (!in_array( $course, $SESSION->bulk_courses )) { + $SESSION->bulk_courses[] = $course; + } + } +} + +if ($listremove && !empty($selcourses)) { + foreach ($selcourses as $course) { + unset($SESSION->bulk_courses[ array_search($course, $SESSION->bulk_courses) ]); + } +} + +// show the confirmation message +if( $accept ) { + if( empty( $SESSION->bulk_courses ) ) + redirect( $return ); + + // generate user name list + $in = implode(',', $SESSION->bulk_users); + $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); + $usernames = implode('', $userlist); + + // generate course name list + $courselist = array(); + $courses = get_courses(0, 'c.sortorder ASC', 'c.id, c.fullname'); + foreach ($courses as $course) { + if (in_array( $course->id, $SESSION->bulk_courses )) { + $courselist[] = $course->fullname; + } + } + + // generate the message + $confmsg = get_string('confirmpart1', $pluginname, NULL, $langdir).$usernames; + $confmsg .= get_string('confirmpart2', $pluginname, NULL, $langdir); + $confmsg .= implode('', $courselist) . '?'; + $optionsyes = array(); + $optionsyes['confirm'] = true; + + // print the message + admin_externalpage_print_header(); + print_heading(get_string('confirmation', 'admin')); + notice_yesno($confmsg, 'index.php', $return, $optionsyes, NULL, 'post', 'get'); + admin_externalpage_print_footer(); + die; +} + +// action confirmed, perform it +if ($confirm) { + if (empty( $SESSION->bulk_courses)) { + redirect($return); + } + + foreach ($SESSION->bulk_courses as $course) { + $context = get_context_instance(CONTEXT_COURSE, $course); + $in = implode(',', $SESSION->bulk_users); + // for each user, unenrol them from the course + if ($rs = get_recordset_select('user', "id IN ($in)")) { + while ($user = rs_fetch_next_record($rs)) + role_unassign(0, $user->id, 0, $context->id); + } + rs_close($rs); + } + + // we're done, exit now + admin_externalpage_print_header(); + redirect($return, get_string('changessaved')); +} + +/** +* This function generates the list of courses for control +* using the specified string filter and/or course id's filter +* +* @param string $strfilter The course name filter +* @param array $arrayfilter Course ID's filter, NULL by default, which means not to use id filter +* @return string +*/ +function gen_course_list( $strfilter = '', $arrayfilter = NULL ) +{ + $courselist = array(); + $catcnt = 0; + // get the list of course categories + $categories = get_categories(); + foreach ($categories as $cat) { + // for each category, add the to the string array first + $courselist[$catcnt] = ''; + // get the course list in that category + $courses = get_courses($cat->id, 'c.sortorder ASC', 'c.fullname, c.id'); + $coursecnt = 0; + + // for each course, check the specified filter + foreach ($courses as $course) { + if (( !empty($strfilter) && strripos($course->fullname, $strfilter) === false ) || ( $arrayfilter !== NULL && in_array($course->id, $arrayfilter) === false )) { + continue; + } + // if we pass the filter, add the option to the current string + $courselist[$catcnt] .= ''.$course->fullname.''; + $coursecnt++; + } + + // if no courses pass the filter in that category, delete the current string + if ($coursecnt == 0) { + unset($courselist[$catcnt]); + } else { + $courselist[$catcnt] .= ''; + $catcnt++; + } + } + + // return the html code with categorized courses + return implode(' ', $courselist); +} + +// generate full and selected course lists +$availablecourses = array(); +foreach ($SESSION->bulk_users as $user) { + $usercourses = get_my_courses($user); + foreach($usercourses as $key=>$junk) { + if(!in_array($key, $availablecourses)) { + $availablecourses[] = $key; + } + } +} +$coursenames = gen_course_list($searchtext, array_diff($availablecourses, $SESSION->bulk_courses)); +$selcoursenames = gen_course_list('', array_intersect($availablecourses, $SESSION->bulk_courses)); + +// print the general page +admin_externalpage_print_header(); + +?> + + + + + + + + + + + + + + + + + + + + + '."\n"; + } + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: admin/user/actions/enroltocourses/version.php =================================================================== RCS file: admin/user/actions/enroltocourses/version.php diff -N admin/user/actions/enroltocourses/version.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/enroltocourses/version.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +version = 2008101800; +$plugin->requires = 2008101800; + +?> Index: admin/user/actions/enroltocourses/lang/ru_utf8/bulkuseractions_enroltocourses.php =================================================================== RCS file: admin/user/actions/enroltocourses/lang/ru_utf8/bulkuseractions_enroltocourses.php diff -N admin/user/actions/enroltocourses/lang/ru_utf8/bulkuseractions_enroltocourses.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/enroltocourses/lang/ru_utf8/bulkuseractions_enroltocourses.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,18 @@ +'; +$string['default'] = 'По умолчанию'; +$string['accept'] = 'Принять'; +$string['autogroup'] = 'Автоматическидобавлять в группу'; +$string['nogroup'] = 'Не добавлять'; +$string['confirmpart1'] = 'Вы уверены, что хотите записать пользователей:'; +$string['confirmpart2'] = 'на курсы:'; +$string['confirmpart3'] = 'и добавить их в соответствующие группы '; +$string['confirmpart4'] = 'с ролью '; +$string['removeall'] = 'Удалить все из выбранных'; + +?> Index: admin/user/actions/enroltocourses/index.php =================================================================== RCS file: admin/user/actions/enroltocourses/index.php diff -N admin/user/actions/enroltocourses/index.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/enroltocourses/index.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,321 @@ +libdir.'/adminlib.php'); + +$allcourses = optional_param('allcourses', '', PARAM_CLEAN); +$selcourses = optional_param('selcourses', '', PARAM_CLEAN); +$accept = optional_param('accept', 0, PARAM_BOOL); +$confirm = optional_param('confirm', 0, PARAM_BOOL); +$cancel = optional_param('cancel', 0, PARAM_BOOL); +$searchtext = optional_param('searchtext', '', PARAM_RAW); +$groupname = optional_param('groupname', '', PARAM_RAW); +$roleassign = optional_param('roleassign', '', PARAM_RAW); +$showall = optional_param('showall', 0, PARAM_BOOL); +$listadd = optional_param('add', 0, PARAM_BOOL); +$listremove = optional_param('remove', 0, PARAM_BOOL); +$removeall = optional_param('removeall', 0, PARAM_BOOL); +$hidden = optional_param('hidden', 0, PARAM_BOOL); + +admin_externalpage_setup('userbulk'); + +$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php'; + +if ($showall) { + $searchtext = ''; +} + +$strsearch = get_string('search'); +$langdir = $CFG->dirroot.'/admin/user/actions/enroltocourses/lang/'; +$pluginname = 'bulkuseractions_enroltocourses'; + +if (empty($SESSION->bulk_users) || $cancel) { + redirect($return); +} + +if (!isset($SESSION->bulk_courses) || $removeall) { + $SESSION->bulk_courses = array(); +} + +// course selection add/remove actions +if ($listadd && !empty($allcourses)) { + foreach ($allcourses as $course) { + if (!in_array( $course, $SESSION->bulk_courses )) { + $SESSION->bulk_courses[] = $course; + } + } +} + +if ($listremove && !empty($selcourses)) { + foreach ($selcourses as $course) { + unset($SESSION->bulk_courses[ array_search($course, $SESSION->bulk_courses) ]); + } +} + +// show the confirmation message +if ($accept) { + if (empty( $SESSION->bulk_courses )) { + redirect( $return ); + } + + // generate user name list + $in = implode(',', $SESSION->bulk_users); + $userlist = get_records_select_menu('user', "id IN ($in)", 'fullname', 'id,'.sql_fullname().' AS fullname'); + $usernames = implode('', $userlist); + + // generate course name list + $courselist = array(); + $courses = get_courses(0, 'c.sortorder ASC', 'c.id, c.fullname'); + foreach ($courses as $course) { + if (in_array( $course->id, $SESSION->bulk_courses )) { + $courselist[] = $course->fullname; + } + } + + // generate the message + $confmsg = get_string('confirmpart1', $pluginname, NULL, $langdir).$usernames; + $confmsg .= get_string('confirmpart2', $pluginname, NULL, $langdir); + $confmsg .= implode('', $courselist); + $groupname = stripslashes($groupname); + if (!empty($groupname)) { + $confmsg .= get_string('confirmpart3', $pluginname, NULL, $langdir).s($groupname, false); + } + + // get system roles info and add the selected role to the message + $context = get_context_instance(CONTEXT_SYSTEM); + $roles = array(0 => get_string( 'default', $pluginname, NULL, $langdir )) + get_assignable_roles($context); + $confmsg .= get_string( 'confirmpart4', $pluginname, NULL, $langdir ).$roles[$roleassign]; + if ($hidden) { + $confmsg .= ' ('.get_string( 'hiddenassign' ).')'; + } + $confmsg .= '?'; + + $optionsyes['confirm'] = true; + $optionsyes['groupname'] = $groupname; + $optionsyes['roleassign'] = $roleassign; + $optionsyes['hidden'] = $hidden; + + // print the message + admin_externalpage_print_header(); + print_heading(get_string('confirmation', 'admin')); + notice_yesno( $confmsg, 'index.php', $return, $optionsyes, NULL, 'post', 'get'); + admin_externalpage_print_footer(); + die; +} + +// action confirmed, perform it +if( $confirm ) { + if(empty($SESSION->bulk_courses)) { + redirect($return); + } + + // for each course, get the default role if needed and check the selected group + foreach ($SESSION->bulk_courses as $course) { + $context = get_context_instance(CONTEXT_COURSE, $course); + $in = implode(',', $SESSION->bulk_users); + $groupid = false; + if ($roleassign == 0) { + $roleassign = get_default_course_role( $context )->id; + } + if (!empty($groupname)) { + $groupid = groups_get_group_by_name($course, stripslashes($groupname)); + } + // for each user, enrol them to the course with the selected role, + // and add to the selected group if available + if ($rs = get_recordset_select('user', "id IN ($in)")) { + while ($user = rs_fetch_next_record($rs)) { + role_assign($roleassign, $user->id, 0, $context->id, 0, 0, $hidden); + if ($groupid !== false) { + groups_add_member($groupid, $user->id); + } + } + } + rs_close($rs); + } + // we're done, exit now + admin_externalpage_print_header(); + redirect($return, get_string('changessaved')); +} + +/** +* This function generates the list of courses for control +* using the specified string filter and/or course id's filter +* +* @param string $strfilter The course name filter +* @param array $arrayfilter Course ID's filter, NULL by default, which means not to use id filter +* @return string +*/ +function gen_course_list( $strfilter = '', $arrayfilter = NULL, $filtinvert = false ) +{ + $courselist = array(); + $catcnt = 0; + // get the list of course categories + $categories = get_categories(); + foreach ($categories as $cat) { + // for each category, add the to the string array first + $courselist[$catcnt] = ''; + // get the course list in that category + $courses = get_courses($cat->id, 'c.sortorder ASC', 'c.fullname, c.id'); + $coursecnt = 0; + + // for each course, check the specified filter + foreach ($courses as $course) { + if (( !empty($strfilter) && strripos($course->fullname, $strfilter) === false ) || ( $arrayfilter !== NULL && in_array($course->id, $arrayfilter) === $filtinvert )) { + continue; + } + // if we pass the filter, add the option to the current string + $courselist[$catcnt] .= ''.$course->fullname.''; + $coursecnt++; + } + + // if no courses pass the filter in that category, delete the current string + if ($coursecnt == 0) { + unset($courselist[$catcnt]); + } else { + $courselist[$catcnt] .= ''; + $catcnt++; + } + } + + // return the html code with categorized courses + return implode(' ', $courselist); +} + +// generate full and selected course lists +$coursenames = gen_course_list($searchtext, $SESSION->bulk_courses, true); +$selcoursenames = gen_course_list('', $SESSION->bulk_courses); + +// generate the list of groups names from the selected courses. +// groups with the same name appear only once +$groupnames = array(); +foreach ($SESSION->bulk_courses as $course) { + $cgroups = groups_get_all_groups($course); + foreach ($cgroups as $cgroup) { + if (!in_array($cgroup->name, $groupnames)) { + $groupnames[] = $cgroup->name; + } + } +} + +sort($groupnames); + +// generate html code for the group select control +foreach ($groupnames as $key => $name) { + $groupnames[$key] = ''.s($name, true).''; +} + +$groupnames = ''.get_string('nogroup', $pluginname, NULL, $langdir).' '.implode(' ', $groupnames); + +// get the system roles list and generate html code for role select control +$context = get_context_instance(CONTEXT_SYSTEM); +$roles = array(0 => get_string('default', $pluginname, NULL, $langdir)) + get_assignable_roles($context); +$rolenames = ''; +foreach ($roles as $key => $name) { + $rolenames .= ' '; +} + +// print the general page +admin_externalpage_print_header(); + +?> + + + + + + + + + + + + + + + + + + + + + '."\n"; + } + ?> + + + + + + + + + + + + + /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: admin/user/actions/enroltocourses/lang/en_utf8/bulkuseractions_enroltocourses.php =================================================================== RCS file: admin/user/actions/enroltocourses/lang/en_utf8/bulkuseractions_enroltocourses.php diff -N admin/user/actions/enroltocourses/lang/en_utf8/bulkuseractions_enroltocourses.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ admin/user/actions/enroltocourses/lang/en_utf8/bulkuseractions_enroltocourses.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,18 @@ +'; +$string['default'] = 'Course default'; +$string['accept'] = 'Accept'; +$string['autogroup'] = 'Automaticallyadd to group'; +$string['nogroup'] = 'Do not add'; +$string['confirmpart1'] = 'Are you sure you want to enrol users:'; +$string['confirmpart2'] = 'on courses:'; +$string['confirmpart3'] = 'and add them in corresponding groups '; +$string['confirmpart4'] = 'with role of '; +$string['removeall'] = 'Remove all from selection'; + +?>
+ +
+ + + +
+