--- /dev/null
+
+<form name="studentform" id="studentform" method="post" action="importstudents.php">
+<input type="hidden" name="previoussearch" value="<?php echo $previoussearch ?>">
+<input type="hidden" name="id" value="<?php echo $id?>">
+ <table align="center" border="0" cellpadding="5" cellspacing="0">
+ <tr>
+ <td valign="top">
+ <?php echo count($alreadycourses) . " ". $stralreadycourses ?>
+ </td>
+ <td></td>
+ <td valign="top">
+ <?php echo $numcourses . " " . $strpotentialcourses ?>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top">
+ <select name="removeselect[]" size="20" id="removeselect" multiple
+ onFocus="document.studentform.add.disabled=true;
+ document.studentform.remove.disabled=false;
+ document.studentform.addselect.selectedIndex=-1;">
+ <?php
+ foreach ($alreadycourses as $course) {
+ echo "<option value=\"$course->id\">".course_format_name($course,60)."</option>\n";
+ }
+ ?>
+ </select></td>
+ <td valign="top">
+ <br />
+ <input name="add" type="submit" id="add" value="←" />
+ <br />
+ <input name="remove" type="submit" id="remove" value="→" />
+ <br />
+ </td>
+ <td valign="top">
+ <select name="addselect[]" size="20" id="addselect" multiple
+ onFocus="document.studentform.add.disabled=false;
+ document.studentform.remove.disabled=true;
+ document.studentform.removeselect.selectedIndex=-1;">
+ <?php
+
+ if (!empty($searchcourses)) {
+ echo "<optgroup label=\"$strsearchresults (" . count($searchcourses) . ")\">\n";
+ foreach ($searchcourses as $course) {
+ echo "<option value=\"$course->id\">".course_format_name($course,60)."</option>\n";
+ }
+ echo "</optgroup>\n";
+ }
+ if (!empty($courses)) {
+ if ($numcourses > MAX_COURSES_PER_PAGE) {
+ echo '<optgroup label="'.get_string('toomanytoshow').'"><option></option></optgroup>'."\n"
+ .'<optgroup label="'.get_string('trysearching').'"><option></option></optgroup>'."\n";
+ }
+ else {
+ foreach ($courses as $course) {
+ echo "<option value=\"$course->id\">".course_format_name($course,60)."</option>\n";
+ }
+ }
+ }
+ ?>
+ </select>
+ <br />
+ <input type="text" name="searchtext" size="30" value="<?php echo $searchtext ?>"
+ onFocus ="document.studentform.add.disabled=true;
+ document.studentform.remove.disabled=true;
+ document.studentform.removeselect.selectedIndex=-1;
+ document.studentform.addselect.selectedIndex=-1;"
+ onkeydown = "var keyCode = event.which ? event.which : event.keyCode;
+ if (keyCode == 13) {
+ document.studentform.previoussearch.value=1;
+ document.studentform.submit();
+ } " />
+ <input name="search" id="search" type="submit" value="<?php p($strsearch) ?>" />
+ <?php
+ if (!empty($searchcourses)) {
+ echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
+ }
+ ?>
+ </td>
+ </tr>
+ </table>
+</form>
+
+
--- /dev/null
+<?php
+// script to assign students to a meta course by selecting which courses the meta course comprises.
+// this is basically a hack of student.php that uses courses instead.
+
+
+ require_once("../config.php");
+ require_once("lib.php");
+
+ define("MAX_COURSES_PER_PAGE", 1000);
+
+ require_variable($id); // course id
+ optional_variable($add, "");
+ optional_variable($remove, "");
+ optional_variable($search, ""); // search string
+
+ if (! $site = get_site()) {
+ redirect("$CFG->wwwroot/$CFG->admin/index.php");
+ }
+
+ if (! $course = get_record("course", "id", $id)) {
+ error("Course ID was incorrect (can't find it)");
+ }
+
+ require_login($course->id);
+
+ if (!$course->meta_course) {
+ redirect("$CFG->wwwroot/course/student.php?id=$course->id");
+ }
+
+ if (!isadmin()) {
+ error("You must be an admin");
+ }
+
+
+ $strassigncourses = get_string('metaassigncourses');
+ $stralreadycourses = get_string('metaalreadycourses');
+ $strnoalreadycourses = get_string('metanoalreadycourses');
+ $strpotentialcourses = get_string('metapotentialcourses');
+ $strnopotentialcourses = get_string('metanopotentialcourses');
+ $straddcourses = get_string('metaaddcourse');
+ $strremovecourse = get_string('metaremovecourse');
+ $strsearch = get_string("search");
+ $strsearchresults = get_string("searchresults");
+ $strcourses = get_string("courses");
+ $strshowall = get_string("showall");
+
+ print_header("$course->shortname: $strassigncourses",
+ "$site->fullname",
+ "<a href=\"view.php?id=$course->id\">$course->shortname</a> -> $strassigncourses",
+ "studentform.searchtext");
+
+/// Don't allow restricted teachers to even see this page (because it contains
+/// a lot of email addresses and access to all student on the server
+
+ check_for_restricted_user($USER->username, "$CFG->wwwroot/course/view.php?id=$course->id");
+
+/// Print a help notice about the need to use this page
+
+ if (!$frm = data_submitted()) {
+ $note = get_string("importmetacoursenote");
+ print_simple_box($note, "center", "50%");
+
+/// A form was submitted so process the input
+
+ } else {
+ if (!empty($frm->add) and !empty($frm->addselect)) {
+ $timestart = $timeend = 0;
+ foreach ($frm->addselect as $addcourse) {
+ if (!add_to_metacourse($course->id,$addcourse)) {
+ error("Could not add the selected course to this meta course!");
+ }
+ }
+ } else if (!empty($frm->remove) and !empty($frm->removeselect)) {
+ foreach ($frm->removeselect as $removecourse) {
+ if (! remove_from_metacourse($course->id,$removecourse)) {
+ error("Could not remove the selected course to this meta course!");
+ }
+ }
+ } else if (!empty($frm->showall)) {
+ unset($frm->searchtext);
+ $frm->previoussearch = 0;
+ }
+ }
+
+ $previoussearch = (!empty($frm->search) or ($frm->previoussearch == 1)) ;
+
+ /// Get all existing students and teachers for this course.
+ if(! $alreadycourses = get_courses_in_metacourse($course->id)) {
+ $alreadycourses = array();
+ }
+
+ $numcourses = 0;
+
+
+/// Get search results excluding any users already in this course
+ if (!empty($frm->searchtext) and $previoussearch) {
+ $searchcourses = get_courses_search(explode(" ",$frm->searchtext),'fullname ASC',0,99999,$numcourses);
+ foreach ($searchcourses as $tmp) {
+ if (array_key_exists($tmp->id,$alreadycourses)) {
+ unset($searchcourses[$tmp->id]);
+ }
+ }
+ $numcourses = count($searchcourses);
+ }
+
+/// If no search results then get potential students for this course excluding users already in course
+ if (empty($searchcourses)) {
+
+ $numcourses = get_courses_notin_metacourse($course->id,true);
+
+ $courses = array();
+
+ if ($numcourses <= MAX_COURSES_PER_PAGE) {
+ $courses = get_courses_notin_metacourse($course->id);
+ }
+ }
+
+
+ $searchtext = (isset($frm->searchtext)) ? $frm->searchtext : "";
+ $previoussearch = ($previoussearch) ? '1' : '0';
+
+ print_simple_box_start("center", "", "$THEME->cellheading");
+
+ include('importstudents.html');
+
+ print_simple_box_end();
+
+ print_footer();
+
+
+
+
+
+?>
\ No newline at end of file