// create groups and assign students foreach ($teams as $n4 => $t4) { $ROLE = $r; $TEAM = $n4; $s = create_group($teacher_code, $TEAM); if (is_string($s)) { err("Failed to create group \"{$TEAM}\" - {$s}"); } else { $gid = $s; //$rcodes = array("sd", "mm", "nh", "sb", ); $rnums = array(3, 4, 5, 6); for ($j = 0; $j < count($rcodes); $j++) { if (isset($t4[$rcodes[$j]])) { $l = $t4[$rcodes[$j]]; $id = create_student($teacher_code, $l[0], $l[1], $l[4], $l[5]); assignStudentToGroupAndClass($id, $gid, $rnums[$j]); } } } } } header("Location: groups.php"); } else { ?> <div style="border: solid 2px green; text-align: center; padding: 10px; background-color: #efe;"> <b>Congratulations!</b><br> No errors were detected. <p> <b> BUT WAIT! YOU'RE NOT DONE!</b> Your input looks satisfactory,but you still have to <br> confirm that you want to create the student records as <br>
function bumpStudentClass($sid, $n) { // get the student's group id $group_id = gidFromSid($sid); assert($group_id != 0); //dbg("group_id=$group_id"); // get his current (old) class $oldclass = classForStudent($sid); assert($oldclass != 0); //dbg("oldclass=$oldclass"); // compute his desired (new) class $newclass = $oldclass + $n; // wrap if necessary if ($newclass < 3) { $newclass = 6; } if ($newclass > 6) { $newclass = 3; } //dbg("newclass=$newclass"); // get id of student (if any) that already has the desired class $othersid = sidFromGidAndClass($group_id, $newclass); //dbg("othersid=$othersid"); // remove both students from group entirely if ($othersid != 0) { rmStudentFromGroup($othersid); } rmStudentFromGroup($sid); // re-add students using swapped class numbers assignStudentToGroupAndClass($sid, $group_id, $newclass); if ($othersid != 0) { assignStudentToGroupAndClass($othersid, $group_id, $oldclass); } }