From: moodler Date: Tue, 3 Aug 2004 12:50:18 +0000 (+0000) Subject: First pass at an improved interface for manual student enrolments X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5363911f84cc54f3e041639a69ecb5102c5d133b;p=moodle.git First pass at an improved interface for manual student enrolments --- diff --git a/course/student.html b/course/student.html new file mode 100644 index 0000000000..a4aee5480a --- /dev/null +++ b/course/student.html @@ -0,0 +1,72 @@ + +
+ + + + + + + + + + + + +
+ + + +
+ +
+ +
+ +
+
+ +
+ + + '."\n"; + } + ?> +
+
+ + diff --git a/course/student.php b/course/student.php index 1d2616216f..f383dc8cba 100644 --- a/course/student.php +++ b/course/student.php @@ -33,19 +33,10 @@ $strremovestudent = get_string("removestudent"); $strsearch = get_string("search"); $strsearchresults = get_string("searchresults"); - $strsearchagain = get_string("searchagain"); - $strtoomanytoshow = get_string("toomanytoshow"); $strstudents = get_string("students"); - $strunenrolallstudents = get_string("unenrolallstudents"); - $strunenrolallstudentssure = get_string("unenrolallstudentssure"); + $strshowall = get_string("showall"); - if ($search) { - $searchstring = $strsearchagain; - } else { - $searchstring = $strsearch; - } - if ($course->students != $strstudents) { $parastudents = " ($course->students)"; } else { @@ -61,125 +52,87 @@ check_for_restricted_user($USER->username, "$CFG->wwwroot/course/view.php?id=$course->id"); -/// Add a student if one is specified - - if (!empty($add)) { - if ($course->enrolperiod) { - $timestart = time(); - $timeend = $timestart + $course->enrolperiod; - } else { - $timestart = $timeend = 0; - } - if (! enrol_student($add, $course->id, $timestart, $timeend)) { - error("Could not add that student to this course!"); - } - } - -/// Remove a student if one is specified. - - if (!empty($remove)) { - if (! unenrol_student($remove, $course->id)) { - error("Could not remove that student from this course!"); - } - } - -/// Remove all students from specified course - - if (!empty($removeall)) { - $students = get_course_students($course->id, "u.lastname ASC, u.firstname ASC"); - foreach ($students as $student) { - if (! unenrol_student($student->id, $course->id)) { - $fullname = fullname($student, true); - notify("Could not remove $fullname from this course!"); - } - } - } - /// Print a help notice about the need to use this page - if (empty($add) and empty($remove) and empty($search)) { - $note = get_string("assignstudentsnote"); + if (!$frm = data_submitted()) { + $note = get_string("assignstudentsnote"); + if ($course->password) { - $note .= "

".get_string("assignstudentspass", "", "id\">$course->password"); + $note .= "

".get_string("assignstudentspass", "", + "id\">$course->password"); } print_simple_box($note, "center", "50%"); - } - -/// Get all existing students for this course. - $students = get_course_students($course->id, "u.lastname ASC, u.firstname ASC"); -/// Print the lists of existing and potential students - - echo ""; - echo ""; - echo ""; - echo "
$strexistingstudents$parastudents $strpotentialstudents
"; - -/// First, show existing students for this course - - if (empty($students)) { - echo "

$strnoexistingstudents"; - $studentlist = ""; +/// A form was submitted so process the input } else { - $studentarray = array(); - foreach ($students as $student) { - $studentarray[] = $student->id; - $fullname = fullname($student, true); - echo "

$fullname, $student->email    id&remove=$student->id\" title=\"$strremovestudent\">

"; + if (!empty($frm->add) and !empty($frm->addselect)) { + if ($course->enrolperiod) { + $timestart = time(); + $timeend = $timestart + $course->enrolperiod; + } else { + $timestart = $timeend = 0; + } + foreach ($frm->addselect as $addstudent) { + if (! enrol_student($addstudent, $course->id, $timestart, $timeend)) { + error("Could not add student with id $addstudent to this course!"); + } + } + } else if (!empty($frm->remove) and !empty($frm->removeselect)) { + foreach ($frm->removeselect as $removestudent) { + if (! unenrol_student($removestudent, $course->id)) { + error("Could not remove student with id $removestudent from this course!"); + } + } + } else if (!empty($frm->showall)) { + unset($frm->searchtext); } - $studentlist = implode(",",$studentarray); - unset($studentarray); - // button to unenrol all students from course - - echo "

 

\n"; - echo "

\n"; - echo "\n"; - echo "

\n"; } - echo "
 "; - -/// Print list of potential students - - $usercount = get_users(false, $search, true, $studentlist, "lastname ASC, firstname ASC"); - - if ($usercount == 0) { - echo "

$strnopotentialstudents

"; - - } else if ($usercount > MAX_USERS_PER_PAGE) { - echo "

$strtoomanytoshow ($usercount)

"; - } else { +/// Get all existing students for this course. + if (!$students = get_course_students($course->id, "u.firstname ASC, u.lastname ASC", "", 0, 99999, + '', '', NULL, '', 'u.id,u.firstname,u.lastname,u.email')) { + $students = array(); + } + + $studentarray = array(); + foreach ($students as $student) { + $studentarray[] = $student->id; + } + $studentlist = implode(',', $studentarray); - if ($search) { - echo "

($strsearchresults : $search)

"; - } - if (!$users = get_users(true, $search, true, $studentlist)) { - error("Could not get users!"); +/// Get search results excluding any users already in this course + if (!empty($frm->searchtext)) { + if ($searchusers = get_users(true, $frm->searchtext, true, $studentlist, 'firstname ASC, lastname ASC', + '', '', 0, 99999, 'id, firstname, lastname, email')) { + foreach ($searchusers as $student) { + $studentarray[] = $student->id; + } + $studentlist = implode(',', $studentarray); } + } - foreach ($users as $user) { - $fullname = fullname($user, true); - echo "

id&add=$user->id\"". - "title=\"$straddstudent\">  $fullname, $user->email"; + unset($studentarray); + +/// Get potential students for this course excluding users already in course or +/// users in the search results + if (empty($searchusers)) { + if (!$users = get_users(true, '', true, $studentlist, 'firstname ASC, lastname ASC', '', '', + 0, 99999, 'id, firstname, lastname, email') ) { + $users = array(); } } - if ($search or $usercount > MAX_USERS_PER_PAGE) { - echo "

"; - echo "id\">"; - echo ""; - echo ""; - echo "
"; - } + $searchtext = (isset($frm->searchtext)) ? $frm->searchtext : ""; + + print_simple_box_start("center", "", "$THEME->cellheading"); + + include('student.html'); - echo "
"; + print_simple_box_end(); print_footer();