Skip to content

Commit

Permalink
Simple interface to manually add students to a course.
Browse files Browse the repository at this point in the history
  • Loading branch information
moodler committed Aug 17, 2003
1 parent 6843d30 commit 7d569d2
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 1 deletion.
3 changes: 3 additions & 0 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,9 @@ function print_course_admin_links($course, $width=180) {
$admindata[]="<a href=\"teacher.php?id=$course->id\">$course->teachers...</a>";
$adminicon[]="<img src=\"$pixpath/i/settings.gif\" height=16 width=16 alt=\"\">";

$admindata[]="<a href=\"student.php?id=$course->id\">$course->students...</a>";
$adminicon[]="<img src=\"$pixpath/i/settings.gif\" height=16 width=16 alt=\"\">";

$admindata[]="<a href=\"$CFG->wwwroot/backup/backup.php?id=$course->id\">".get_string("backup")."...</a>";
$adminicon[]="<img src=\"$pixpath/i/backup.gif\" height=16 width=16 alt=\"\">";

Expand Down
141 changes: 141 additions & 0 deletions course/student.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?PHP // $Id$
// Script to assign students to courses

require_once("../config.php");

define("MAX_USERS_PER_PAGE", 30);

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 (!isteacheredit($course->id)) {
error("You must be able to edit this course to assign students");
}

$strassignstudents = get_string("assignstudents");
$strexistingstudents = get_string("existingstudents");
$strnoexistingstudents = get_string("noexistingstudents");
$strpotentialstudents = get_string("potentialstudents");
$strnopotentialstudents = get_string("nopotentialstudents");
$straddstudent = get_string("addstudent");
$strremovestudent = get_string("removestudent");
$strsearch = get_string("search");
$strsearchresults = get_string("searchresults");
$strsearchagain = get_string("searchagain");
$strtoomanytoshow = get_string("toomanytoshow");

if ($search) {
$searchstring = $strsearchagain;
} else {
$searchstring = $strsearch;
}

print_header("$course->shortname: $strassignstudents",
"$site->fullname",
"<a href=\"view.php?id=$course->id\">$course->shortname</a> -> $strassignstudents", "");

/// Add a student if one is specified

if (!empty($add)) {
if (! enrol_student($add, $course->id)) {
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 add that student to this course!");
}
}

/// Print a help notice about the need to use this page

if (empty($add) and empty($remove)) {
$note = get_string("assignstudentsnote");
if ($course->password) {
$note .= "<p>".get_string("assignstudentspass", "", $course->password);
}
print_simple_box($note, "center", "50%");
}

/// Get all existing students for this course.
$students = get_course_students($course->id);

/// Print the lists of existing and potential students

echo "<table cellpadding=2 cellspacing=10 align=center>";
echo "<tr><th width=50%>$strexistingstudents</th><th width=50%>$strpotentialstudents</th></tr>";
echo "<tr><td width=50% nowrap valign=top>";

/// First, show existing students for this course

if (empty($students)) {
echo "<p align=center>$strnoexistingstudents</a>";
$studentlist = "";

} else {
$studentarray = array();
foreach ($students as $student) {
$studentarray[] = $student->id;
echo "<p align=right>$student->firstname $student->lastname, $student->email &nbsp;&nbsp; <a href=\"student.php?id=$course->id&remove=$student->id\" title=\"$strremovestudent\"><img src=\"../pix/t/right.gif\" border=0></a></p>";
}
$studentlist = implode(",",$studentarray);
unset($studentarray);
}

echo "<td width=50% nowrap valign=top>";

/// Print list of potential students

$usercount = get_users(false, $search, true, $studentlist);

if ($usercount == 0) {
echo "<p align=center>$strnopotentialstudents</p>";

} else if ($usercount > MAX_USERS_PER_PAGE) {
echo "<p align=center>$strtoomanytoshow</p>";

} else {

if ($search) {
echo "<p align=center>($strsearchresults : $search)</p>";
}

if (!$users = get_users(true, $search, true, $studentlist)) {
error("Could not get users!");
}

foreach ($users as $user) {
echo "<p align=left><a href=\"{$_SERVER['PHP_SELF']}?id=$course->id&add=$user->id\"".
"title=\"$straddstudent\"><img src=\"../pix/t/left.gif\"".
"border=0></a>&nbsp;&nbsp;$user->firstname $user->lastname, $user->email";
}
}

if ($search or $usercount > MAX_USERS_PER_PAGE) {
echo "<form action={$_SERVER['PHP_SELF']} method=post>";
echo "<input type=hidden name=id value=\"$course->id\">";
echo "<input type=text name=search size=20>";
echo "<input type=submit value=\"$searchstring\">";
echo "</form>";
}

echo "</tr></table>";

print_footer();

?>
9 changes: 8 additions & 1 deletion lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

$string['thislanguage'] = "English"; // Name of this language in the native language eg Français
$string['thischarset'] = "iso-8859-1"; // The best charset to use for this language

$string['action'] = "Action";
$string['activities'] = "Activities";
$string['activity'] = "Activity";
Expand All @@ -23,6 +22,7 @@
$string['address'] = "Address";
$string['addadmin'] = "Add admin";
$string['addcreator'] = "Add course creator";
$string['addstudent'] = "Add student";
$string['addteacher'] = "Add teacher";
$string['admin'] = "Admin";
$string['adminhelpaddnewuser'] = "To manually create a new user account";
Expand Down Expand Up @@ -61,6 +61,8 @@
$string['assignadmins'] = "Assign admins";
$string['assigncreators'] = "Assign creators";
$string['assignstudents'] = "Assign students";
$string['assignstudentsnote'] = "Note: it may not be necessary to use this page, since it is possible for students to enrol themselves in this course.";
$string['assignstudentspass'] = "All you may need to do is notify your students of the enrolment key for this course, which is currently set to: '\$a'";
$string['assignteachers'] = "Assign teachers";
$string['authentication'] = "Authentication";
$string['autosubscribe'] = "Forum auto-subscribe";
Expand Down Expand Up @@ -289,6 +291,7 @@
$string['existingcourseadding'] = "Existing course, adding data to it";
$string['existingcoursedeleting'] = "Existing course, deleting it first";
$string['existingcreators'] = "Existing course creators";
$string['existingstudents'] = "Existing students";
$string['existingteachers'] = "Existing teachers";
$string['feedback'] = "Feedback";
$string['filemissing'] = "\$a is missing";
Expand Down Expand Up @@ -530,6 +533,7 @@
$string['nocoursesyet'] = "No courses in this category";
$string['noexistingadmins'] = "No existing admins, this is a serious error and you should never have seen this message.";
$string['noexistingcreators'] = "No existing creators";
$string['noexistingstudents'] = "No existing students";
$string['noexistingteachers'] = "No existing teachers";
$string['nofilesselected'] = "No files have been selected to restore";
$string['nofilesyet'] = "No files have been uploaded to your course yet";
Expand All @@ -540,6 +544,7 @@
$string['none'] = "None";
$string['nopotentialadmins'] = "No potential admins";
$string['nopotentialcreators'] = "No potential course creators";
$string['nopotentialstudents'] = "No potential students";
$string['nopotentialteachers'] = "No potential teachers";
$string['normal'] = "Normal";
$string['nostudentsyet'] = "No students enrolled in this course yet";
Expand Down Expand Up @@ -586,6 +591,7 @@
$string['popupwindow'] = "Open file in new window";
$string['potentialadmins'] = "Potential admins";
$string['potentialcreators'] = "Potential course creators";
$string['potentialstudents'] = "Potential students";
$string['potentialteachers'] = "Potential teachers";
$string['preferredlanguage'] = "Preferred language";
$string['preview'] = "Preview";
Expand Down Expand Up @@ -614,6 +620,7 @@
$string['registrationyes'] = "Yes, please notify me about important issues";
$string['removeadmin'] = "Remove admin";
$string['removecreator'] = "Remove course creator";
$string['removestudent'] = "Remove student";
$string['removeteacher'] = "Remove teacher";
$string['rename'] = "Rename";
$string['renamefileto'] = "Rename <b>\$a</b> to";
Expand Down

0 comments on commit 7d569d2

Please sign in to comment.