Permalink
Browse files

Bulk assignment to groups

  • Loading branch information...
1 parent cc14c8b commit 499d1a4020b901ceda198477bfb780397c8e287e fiedorow committed Feb 24, 2004
Showing with 61 additions and 14 deletions.
  1. +51 −6 admin/uploaduser.php
  2. +2 −1 lang/en/error.php
  3. +5 −5 lang/en/help/uploadusers.html
  4. +3 −2 lang/en/moodle.php
View
@@ -80,7 +80,12 @@
"course2" => 1,
"course3" => 1,
"course4" => 1,
- "course5" => 1);
+ "course5" => 1,
+ "group1" => 1,
+ "group2" => 1,
+ "group3" => 1,
+ "group4" => 1,
+ "group5" =>1);
// --- get header (field names) ---
$header = split("\,", fgets($fp,1024));
@@ -142,6 +147,11 @@
$addcourse[2] = $user->course3;
$addcourse[3] = $user->course4;
$addcourse[4] = $user->course5;
+ $addgroup[0] = $user->group1;
+ $addgroup[1] = $user->group2;
+ $addgroup[2] = $user->group3;
+ $addgroup[3] = $user->group4;
+ $addgroup[4] = $user->group5;
$courses = get_courses("all");
for ($i=0; $i<5; $i++) {
$courseid[$i]=0;
@@ -153,11 +163,6 @@
}
}
}
- for ($i=0; $i<5; $i++) {
- if ($addcourse[$i] && !$courseid[$i]) {
- notify(get_string('unknowncourse', 'error', $addcourse[$i]));
- }
- }
if (! $user->id = insert_record("user", $user)) {
if (!$user = get_record("user", "username", "changeme")) { // half finished user from another time
//Record not added - probably because user is already registered
@@ -174,6 +179,25 @@
$numusers++;
}
for ($i=0; $i<5; $i++) {
+ if ($addcourse[$i] && !$courseid[$i]) {
+ notify(get_string('unknowncourse', 'error', $addcourse[$i]));
+ }
+ }
+ for ($i=0; $i<5; $i++) {
+ $groupid[$i] = 0;
+ if ($addgroup[$i]) {
+ if (!$courseid[$i]) {
+ notify(get_string('coursegroupunknown','error',$addgroup[$i]));
+ } else {
+ if ($group = get_record("groups","courseid",$courseid[$i],"name",$addgroup[$i])) {
+ $groupid[$i] = $group->id;
+ } else {
+ notify(get_string('groupunknown','error',$addgroup[$i]));
+ }
+ }
+ }
+ }
+ for ($i=0; $i<5; $i++) {
if ($courseid[$i]) {
if (enrol_student($user->id, $courseid[$i])) {
notify('-->'. get_string('enrolledincourse', '', $addcourse[$i]));
@@ -182,6 +206,27 @@
}
}
}
+ for ($i=0; $i<5; $i++) {
+ if ($courseid[$i] && $groupid[$i]) {
+ if (record_exists("user_students","userid",$user->id,"course",$courseid[$i])) {
+ if (record_exists("groups_members","groupid",$groupid[$i],"userid",$user->id)) {
+ notify('-->' . get_string('addedtogroup','',$addgroup[$i]));
+ } else {
+ $group_member->groupid = $groupid[$i];
+ $group_member->userid = $user->id;
+ $group_member->timeadded = time();
+ if (insert_record("groups_members",$group_member)) {
+ notify('-->' . get_string('addedtogroup','',$addgroup[$i]));
+ } else {
+ notify('-->' . get_string('addedtogroupnot','',$addgroup[$i]));
+ }
+ }
+ } else {
+ notify('-->' . get_string('addedtogroupnotenrolled','',$addgroup[$i]));
+ }
+ }
+ }
+
unset ($user);
}
}
View
@@ -1,9 +1,10 @@
<?PHP // $Id$
// error.php - created with Moodle 1.2 development (2003122600)
-
+$string['coursegroupunknown'] = 'Course corresponding to group $a not specified';
$string['erroronline'] = 'Error on line $a';
$string['fieldrequired'] = '\"$a\" is a required field';
+$string['groupunknown'] = 'Group $a not associated to specified course';
$string['invalidfieldname'] = '\"$a\" is not a valid field name';
$string['missingfield'] = 'Field \"$a\" is missing';
$string['modulerequirementsnotmet'] = 'Module \"$a->modulename\" ($a->moduleversion) could not be installed. It requires a newer version of Moodle (currently you are using $a->currentmoodle, you need $a->requiremoodle).';
@@ -14,8 +14,8 @@
</p>
<p><strong>Default fieldnames:</strong> these are optional - if they are not included then the values are taken from the primary admin</p>
<p><font color="#990000" face="Courier New, Courier, mono">institution, department, city, country, lang, timezone</font> </p>
- <p><strong>Optional fieldnames: </strong>all of these are completely optional. The course names are the &quot;shortnames&quot; of the courses - if present then the user will be enrolled as students in those courses</p>
- <p> <font color="#990000" face="Courier New, Courier, mono">idnumber, icq, phone1, phone2, address, url, description, mailformat, maildisplay, htmleditor, autosubscribe, course1, course2, course3, course4, course5</font></p>
+ <p><strong>Optional fieldnames: </strong>all of these are completely optional. The course names are the &quot;shortnames&quot; of the courses - if present then the user will be enrolled as students in those courses. Group names must be associated to the corresponding courses, i.e. group1 to course1, etc.</p>
+ <p> <font color="#990000" face="Courier New, Courier, mono">idnumber, icq, phone1, phone2, address, url, description, mailformat, maildisplay, htmleditor, autosubscribe, course1, course2, course3, course4, course5, group1, group2, group3, group4, group5</font></p>
</blockquote>
</li>
<li>Commas within the data should be encoded as &amp;#44 - the script will automatically decode these back to commas. </li>
@@ -27,7 +27,7 @@
<p>Here is an example of a valid import file:</p>
-<p><font size="-1" face="Courier New, Courier, mono">username, password, firstname, lastname, email, lang, idnumber, maildisplay, course1<br>
-jonest, verysecret, Tom, Jones, jonest@someplace.edu, en, 3663737, 1, Intro101<br>
-reznort, somesecret, Trent, Reznor, reznort@someplace.edu, en_us, 6736733, 0, Advanced202</font></p>
+<p><font size="-1" face="Courier New, Courier, mono">username, password, firstname, lastname, email, lang, idnumber, maildisplay, course1, group1<br>
+jonest, verysecret, Tom, Jones, jonest@someplace.edu, en, 3663737, 1, Intro101, Section 1<br>
+reznort, somesecret, Trent, Reznor, reznort@someplace.edu, en_us, 6736733, 0, Advanced202, Section 3</font></p>
View
@@ -15,6 +15,9 @@
$string['addadmin'] = 'Add admin';
$string['addcreator'] = 'Add course creator';
$string['added'] = 'Added $a';
+$string['addedtogroup'] = 'Added to group $a';
+$string['addedtogroupnot'] = 'Not added to group $a';
+$string['addedtogroupnotenrolled'] = 'Not added to group $a, because not enrolled in course';
$string['addinganew'] = 'Adding a new $a';
$string['addinganewto'] = 'Adding a new $a->what to $a->to';
$string['addingdatatoexisting'] = 'Adding data to existing';
@@ -88,8 +91,6 @@
$string['backupfinished'] = 'Backup completed successfully';
$string['backupincludemoduleshelp'] = 'Choose whether you want to include course modules, with or without user data, in automated backups';
$string['backupkeephelp'] = 'How many recent backups for each course do you want to keep? (older ones will be deleted automatically)';
-$string['backuplogdetailed'] = 'Backup detailed log';
-$string['backuploglaststatus'] = 'Backup last status log';
$string['backuplogshelp'] = 'If enabled, then course logs will be included in automated backups';
$string['backupnameformat'] = '%%Y%%m%%d-%%H%%M';
$string['backuporiginalname'] = 'Backup Name';

0 comments on commit 499d1a4

Please sign in to comment.