This is the first check-in of support for groups.

It's very early (it doesn't actually do anything yet!) but you can
define groups and get an idea of how the interface is shaping up.
I also wanted to show that I have actually done something on this! :-)

From here my plan is to add group support to the modules, one by one
(forums first), then go back and clean up some of the central interfaces,
graphics etc.

Finally, test, test, test and get 1.2 out well before the end of February.
This commit is contained in:
moodler 2003-12-30 17:18:06 +00:00
parent ee39bbe0ee
commit f374fb1006
22 changed files with 1029 additions and 57 deletions

View file

@ -22,14 +22,14 @@
if (iscreator()) {
if (isset($_GET['edit'])) {
if ($edit == "on") {
$USER->editing = true;
$USER->categoryediting = true;
} else if ($edit == "off") {
$USER->editing = false;
$USER->categoryediting = false;
}
}
$navbaritem = update_category_button($category->id);
$creatorediting = !empty($USER->editing);
$creatorediting = !empty($USER->categoryediting);
$adminediting = (isadmin() and $creatorediting);
} else {

View file

@ -1,7 +1,7 @@
<FORM METHOD="post" action="edit.php" NAME="form">
<table cellpadding=9 cellspacing=0 >
<tr valign=top>
<td><P><?php print_string("category") ?>:</td>
<td align="right"><P><?php print_string("category") ?>:</td>
<td><?php
$displaylist = array();
$parentlist = array();
@ -12,28 +12,75 @@
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("fullname") ?>:</td>
<td align="right"><P><?php print_string("fullname") ?>:</td>
<td><input type="text" name="fullname" maxlength="254" size=50 value="<?php p($form->fullname) ?>">
<?php helpbutton("coursefullname", get_string("fullname")) ?>
<?php if (isset($err["fullname"])) formerr($err["fullname"]); ?>
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("shortname") ?>:</td>
<td align="right"><P><?php print_string("shortname") ?>:</td>
<td><input type="text" name="shortname" maxlength="15" size="10" value="<?php p($form->shortname) ?>">
<?php helpbutton("courseshortname", get_string("shortname")) ?>
<?php if (isset($err["shortname"])) formerr($err["shortname"]); ?>
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("summary") ?>:</td>
<td><TEXTAREA NAME=summary COLS=50 ROWS=10 WRAP=virtual><?php p($form->summary) ?></TEXTAREA>
<?php helpbutton("text", get_string("helptext")) ?>
<?php if (isset($err["summary"])) formerr($err["summary"]); ?>
<td align="right"><P><?php print_string("summary") ?>:</td>
<td><?php
print_textarea($usehtmleditor, 10, 50, 660, 200, "summary", $form->summary);
helpbutton("text", get_string("helptext"));
if (isset($err["summary"])) formerr($err["summary"]);
?>
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("availability") ?>:</td>
<td align="right"><P><?php print_string("format") ?>:</td>
<td><?php
choose_from_menu ($form->courseformats, "format", "$form->format", "");
helpbutton("courseformats", get_string("courseformats"));
?>
</td>
</tr>
<tr valign=top>
<td align="right"><P><?php print_string("startdate") ?>:</td>
<td><?php
print_date_selector("startday", "startmonth", "startyear", $form->startdate);
helpbutton("coursestartdate", get_string("startdate"));
?></td>
</tr>
<tr valign=top>
<td align="right"><P><?php print_string("numberweeks") ?>:</td>
<td><?php
for ($i=1; $i<=52; $i++) {
$sectionmenu[$i] = "$i";
}
choose_from_menu ($sectionmenu, "numsections", "$form->numsections", "");
helpbutton("coursenumsections", get_string("numberweeks"));
?></td>
</tr>
<tr valign=top>
<td align="right"><P><?php print_string("groupmode") ?>:</td>
<td><?php
unset($choices);
$choices[NOGROUPS] = get_string("groupsnone");
$choices[SEPARATEGROUPS] = get_string("groupsseparate");
$choices[VISIBLEGROUPS] = get_string("groupsvisible");
choose_from_menu ($choices, "groupmode", $form->groupmode, "");
helpbutton("groupmode", get_string("groupmode"));
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
print_string('force');
echo ': ';
unset($choices);
$choices["0"] = get_string("no");
$choices["1"] = get_string("yes");
choose_from_menu ($choices, "groupmodeforce", $form->groupmodeforce, "");
helpbutton("groupmodeforce", get_string("groupmodeforce")); ?>
</td>
</tr>
<tr valign=top>
<td align="right"><P><?php print_string("availability") ?>:</td>
<td><?php
unset($choices);
$choices["0"] = get_string("courseavailablenot");
@ -43,14 +90,14 @@
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("enrolmentkey") ?>:</td>
<td align="right"><P><?php print_string("enrolmentkey") ?>:</td>
<td><input type="text" name="password" size=25 value="<?php p($form->password) ?>">
<?php helpbutton("enrolmentkey", get_string("enrolmentkey")) ?>
<?php if (isset($err["password"])) formerr($err["password"]); ?>
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("opentoguests") ?>:</td>
<td align="right"><P><?php print_string("opentoguests") ?>:</td>
<td><?php
unset($choices);
$choices["0"] = get_string("guestsno");
@ -61,15 +108,7 @@
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("format") ?>:</td>
<td><?php
choose_from_menu ($form->courseformats, "format", "$form->format", "");
helpbutton("courseformats", get_string("courseformats"));
?>
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("newsitemsnumber") ?>:</td>
<td align="right"><P><?php print_string("newsitemsnumber") ?>:</td>
<td><?php
$newsitem = get_string("newsitem");
$newsitems = get_string("newsitems");
@ -91,24 +130,7 @@
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("startdate") ?>:</td>
<td><?php
print_date_selector("startday", "startmonth", "startyear", $form->startdate);
helpbutton("coursestartdate", get_string("startdate"));
?></td>
</tr>
<tr valign=top>
<td><P><?php print_string("numberweeks") ?>:</td>
<td><?php
for ($i=1; $i<=52; $i++) {
$sectionmenu[$i] = "$i";
}
choose_from_menu ($sectionmenu, "numsections", "$form->numsections", "");
helpbutton("coursenumsections", get_string("numberweeks"));
?></td>
</tr>
<tr valign=top>
<td><P><?php print_string("showrecent") ?>:</td>
<td align="right"><P><?php print_string("showrecent") ?>:</td>
<td><?php
unset($choices);
$choices["0"] = get_string("no");
@ -118,7 +140,7 @@
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("showgrades") ?>:</td>
<td align="right"><P><?php print_string("showgrades") ?>:</td>
<td><?php
unset($choices);
$choices["0"] = get_string("no");
@ -128,7 +150,7 @@
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("showreports") ?>:</td>
<td align="right"><P><?php print_string("showreports") ?>:</td>
<td><?php
unset($choices);
$choices["0"] = get_string("no");
@ -138,7 +160,7 @@
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("maximumupload") ?>:</td>
<td align="right"><P><?php print_string("maximumupload") ?>:</td>
<td><?php
$choices = get_max_upload_sizes($CFG->maxbytes);
choose_from_menu ($choices, "maxbytes", $form->maxbytes, "");
@ -146,28 +168,28 @@
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("wordforteacher") ?>:</td>
<td align="right"><P><?php print_string("wordforteacher") ?>:</td>
<td><input type="text" name="teacher" maxlength="100" size=25 value="<?php p($form->teacher) ?>">
(<?php print_string("wordforteachereg") ?>)
<?php if (isset($err["teacher"])) formerr($err["teacher"]); ?>
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("wordforteachers") ?>:</td>
<td align="right"><P><?php print_string("wordforteachers") ?>:</td>
<td><input type="text" name="teachers" maxlength="100" size=25 value="<?php p($form->teachers) ?>">
(<?php print_string("wordforteacherseg") ?>)
<?php if (isset($err["teachers"])) formerr($err["teachers"]); ?>
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("wordforstudent") ?>:</td>
<td align="right"><P><?php print_string("wordforstudent") ?>:</td>
<td><input type="text" name="student" maxlength="100" size=25 value="<?php p($form->student) ?>">
(<?php print_string("wordforstudenteg") ?>)
<?php if (isset($err["student"])) formerr($err["student"]); ?>
</td>
</tr>
<tr valign=top>
<td><P><?php print_string("wordforstudents") ?>:</td>
<td align="right"><P><?php print_string("wordforstudents") ?>:</td>
<td><input type="text" name="students" maxlength="100" size=25 value="<?php p($form->students) ?>">
(<?php print_string("wordforstudentseg") ?>)
<?php if (isset($err["students"])) formerr($err["students"]); ?>

View file

@ -116,6 +116,8 @@
$form->newsitems = 5;
$form->showrecent = 1;
$form->showgrades = 1;
$form->groupmode = 0;
$form->groupmodeforce = 0;
$form->category = $category;
$form->id = "";
$form->visible = 1;
@ -147,6 +149,8 @@
$form->courseformats["$courseformat"] = get_string("format$courseformat");
}
$usehtmleditor = can_use_html_editor();
$streditcoursesettings = get_string("editcoursesettings");
$straddnewcourse = get_string("addnewcourse");
$stradministration = get_string("administration");
@ -169,6 +173,10 @@
print_footer($course);
if ($usehtmleditor) {
use_html_editor();
}
exit;
/// Functions /////////////////////////////////////////////////////////////////

View file

@ -6,6 +6,8 @@
require_once("$CFG->dirroot/mod/resource/lib.php");
$leftwidth = 210;
$strgroups = get_string("groups");
$strgroupmy = get_string("groupmy");
?>
<table width="100%" border="0" cellspacing="5" cellpadding="5">
@ -14,6 +16,16 @@
<?php
$moddata[]="<a title=\"".get_string("listofallpeople")."\" href=\"../user/index.php?id=$course->id\">".get_string("participants")."</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
if ($course->groupmode or !$course->groupmodeforce) {
if (isteacheredit($course->id) or $course->groupmode == VISIBLEGROUPS) {
$moddata[]="<a title=\"$strgroups\" href=\"groups.php?id=$course->id\">$strgroups</a>";
} else if ($currentgroup = get_current_group($course->id)) {
$moddata[]="<a title=\"$strgroupmy\" href=\"group.php?id=$course->id\">$strgroupmy</a>";
}
$modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
}
$fullname = fullname($USER, true);
$editmyprofile = "<a title=\"$fullname\" href=\"../user/edit.php?id=$USER->id&course=$course->id\">".
get_string("editmyprofile")."</A>";

View file

@ -34,6 +34,8 @@
$stractivities = get_string("activities");
$strshowalltopics = get_string("showalltopics");
$strtopic = get_string("topic");
$strgroups = get_string("groups");
$strgroupmy = get_string("groupmy");
if (isediting($course->id)) {
$strstudents = moodle_strtolower($course->students);
$strtopichide = get_string("topichide", "", $strstudents);
@ -55,6 +57,16 @@
/// Links to people
$moddata[]="<a title=\"".get_string("listofallpeople")."\" href=\"../user/index.php?id=$course->id\">".get_string("participants")."</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
if ($course->groupmode or !$course->groupmodeforce) {
if (isteacheredit($course->id) or $course->groupmode == VISIBLEGROUPS) {
$moddata[]="<a title=\"$strgroups\" href=\"groups.php?id=$course->id\">$strgroups</a>";
} else if ($currentgroup = get_current_group($course->id)) {
$moddata[]="<a title=\"$strgroupmy\" href=\"group.php?id=$course->id\">$strgroupmy</a>";
}
$modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
}
$fullname = fullname($USER, true);
$editmyprofile = "<a title=\"$fullname\" href=\"../user/edit.php?id=$USER->id&course=$course->id\">".get_string("editmyprofile")."</a>";
if ($USER->description) {

View file

@ -24,6 +24,8 @@
$stractivities = get_string("activities");
$strshowallweeks = get_string("showallweeks");
$strweek = get_string("week");
$strgroups = get_string("groups");
$strgroupmy = get_string("groupmy");
if (isediting($course->id)) {
$strstudents = moodle_strtolower($course->students);
$strweekhide = get_string("weekhide", "", $strstudents);
@ -43,6 +45,16 @@
/// Links to people
$moddata[]="<a title=\"".get_string("listofallpeople")."\" href=\"../user/index.php?id=$course->id\">".get_string("participants")."</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
if ($course->groupmode or !$course->groupmodeforce) {
if (isteacheredit($course->id) or $course->groupmode == VISIBLEGROUPS) {
$moddata[]="<a title=\"$strgroups\" href=\"groups.php?id=$course->id\">$strgroups</a>";
} else if ($currentgroup = get_current_group($course->id)) {
$moddata[]="<a title=\"$strgroupmy\" href=\"group.php?id=$course->id\">$strgroupmy</a>";
}
$modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
}
$fullname = fullname($USER, true);
$editmyprofile = "<a title=\"$fullname\" href=\"../user/edit.php?id=$USER->id&course=$course->id\">".get_string("editmyprofile")."</a>";
if ($USER->description) {

103
course/group.php Normal file
View file

@ -0,0 +1,103 @@
<?php // $Id$
/// Shows current group, and allows editing of the group
/// icon and other settings related to that group
require_once('../config.php');
require_once('lib.php');
require_variable($id); // Course id
optional_variable($group); // Optionally look at other groups
optional_variable($edit); // Turn editing on and off
if (! $course = get_record('course', 'id', $id) ) {
error("That's an invalid course id");
}
require_login($course->id);
if ($group and (isteacheredit($course->id) or $course->groupmode == VISIBLEGROUPS)) {
if (! $group = get_record("group", "id", $group)) {
error('Specified group could not be found!', "groups.php?id=$course->id");
}
} else if (! $group = get_current_group($course->id, 'full')) {
error('You are not currently in a group!', "view.php?id=$course->id");
}
if (isteacheredit($course->id) or (isteacher($course->id) and ismember($group->id) ) ) {
if (isset($edit)) {
if ($edit == "on") {
$USER->groupediting = true;
} else if ($edit == "off") {
$USER->groupediting = false;
}
}
} else {
$USER->groupediting = false;
}
/// Print the headers of the page
$strgroup = get_string('group');
$strgroups = get_string('groups');
$loggedinas = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>";
if (isteacheredit($course->id) or $course->groupmode == VISIBLEGROUPS) {
print_header("$strgroup : $group->name", "$course->fullname",
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
-> <a href=\"groups.php?id=$course->id\">$strgroups</a> -> $group->name",
"", "", true, update_group_button($course->id), $loggedinas);
} else {
print_header("$strgroup : $group->name", "$course->fullname",
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
-> $strgroup -> $group->name", "", "", true, "", $loggedinas);
}
/// Display the current group information
if ($USER->groupediting) { // Make an editing form for group information
print_heading($group->name);
echo '<div align="center">';
print_group_picture($group->id, $course->id, $group->picture, true, false, false);
echo '</div>';
print_simple_box($group->description, 'center', '50%');
} else { // Just display the information
print_heading($group->name);
echo '<div align="center">';
print_group_picture($group->id, $course->id, $group->picture, true, false, false);
echo '</div>';
print_simple_box($group->description, 'center', '50%');
}
echo '<br />';
if ($users = get_users_in_group($group->id)) {
$table->align = array('left', 'left');
$table->width = array('100', '*');
foreach ($users as $user) {
if (!$lastaccess = get_field("user_students", "timeaccess", "userid", $user->id, "course", $course->id)) {
if (!$lastaccess = get_field("user_teachers", "timeaccess", "userid", $user->id, "course", $course->id)) {
$datestring = get_string("never");
}
}
if ($lastaccess) {
$datestring = userdate($lastaccess)."&nbsp (".format_time(time() - $lastaccess).")";
}
$information = '<p><b>'.fullname($user).'</b></p>'.get_string("lastaccess").": $datestring";
$table->data[] = array(print_user_picture($user->id, $course->id, $user->picture, true, true), $information);
}
print_table($table);
} else {
print_heading(get_string('nousersyet'));
}
/// Finish off the page
print_footer($course);
?>

170
course/groups-edit.html Executable file
View file

@ -0,0 +1,170 @@
<script language="JavaScript">
<!-- Begin
<?php
foreach ($listmembers as $groupid => $listmember) {
echo "group$groupid = new Object();\n";
$useridstring = "group$groupid.userid = new Array(";
$usernamestring = "group$groupid.username = new Array(";
$max = count($listmember);
$count = 0;
foreach ($listmember as $userid => $username) {
$count++;
$useridstring .= "\"$userid\"";
$usernamestring .= "\"$username\"";
if ($count < $max) {
$useridstring .= ', ';
$usernamestring .= ', ';
}
}
$useridstring .= ");\n";
$usernamestring .= ");\n";
echo $useridstring;
echo $usernamestring;
}
?>
function updateGroup() {
document.form1.groupid.value = document.form2.groups.value;
document.form3.groupid.value = document.form2.groups.value;
}
function updateMembers(selectgroup) {
eval('group=group'+selectgroup.value);
username = group.username;
userid = group.userid;
document.form3['members[]'].length = username.length;
for (i=0;i<username.length;i++) {
document.form3['members[]'].options[i].value = userid[i];
document.form3['members[]'].options[i].text = username[i];
}
updateGroup();
}
function userWindow(selectuser) {
num = 0;
for (var i=0; i<selectuser.options.length; i++) {
if (selectuser.options[i].selected) {
num++;
user = selectuser.options[i].value;
openpopup('/user/view.php?id='+user+'&course=<?php echo $courseid ?>','userinfo'+num,'','');
}
}
return false;
}
function groupWindow(selectgroup) {
num = 0;
for (var i=0; i<selectgroup.options.length; i++) {
if (selectgroup.options[i].selected) {
num++;
group = selectgroup.options[i].value;
openpopup('/course/group.php?id=<?php echo $courseid ?>&group='+group,'groupinfo'+num,'','');
}
}
return false;
}
// end hiding script -->
</script>
<table border="0" cellspacing="2" cellpadding="10" align="center" class="generalbox">
<tr>
<td width="33%" align="center" class="generaltableheader"><?php p($strgroupnonmembers) ?></td>
<td width="33%" align="center" class="generaltableheader"><?php p($strgroups) ?></td>
<td width="33%" align="center" class="generaltableheader"><?php p($strgroupmembersselected) ?></td>
</tr>
<tr align="center" valign="top">
<td class="generalboxcontent"><p>
<form name="form1" id="form1" method="post" action="groups.php">
<input type="hidden" name="id" value="<?php p($course->id) ?>" />
<input type="hidden" name="groupid" value="<?php p($selectedgroup) ?>" />
<select name="nonmembers[]" size="15" multiple="multiple">
<?php
if (!empty($nonmembers)) {
foreach ($nonmembers as $id => $nonmembername) {
echo "<option value=\"$id\">$nonmembername</option>";
}
}
?>
</select>
</p>
<p>
<input type="submit" name="nonmembersadd" value="<?php p($strgroupaddusers) ?> -&gt;"
onclick="updateGroup()" />
</p>
<p>
<input type="submit" name="nonmembersrandom" value="<?php p($strgrouprandomassign) ?> -&gt;" />
</p>
<p>
<input type="submit" name="nonmembersinfo" value="<?php p($strgroupinfopeople) ?>"
onclick="return userWindow(document.form1['nonmembers[]']);" />
</p>
</form>
</td>
<td class="generalboxcontent"><p>
<form name="form2" id="form2" method="post" action="groups.php">
<input type="hidden" name="id" value="<?php p($course->id) ?>" />
<select name="groups" size="15" onChange="updateMembers(this)">
<?php
if (!empty($listgroups)) {
foreach ($listgroups as $id => $listgroup) {
$selected = '';
if ($id == $selectedgroup) {
$selected = 'selected="selected"';
}
echo "<option $selected value=\"$id\">$listgroup</option>";
}
}
?>
</select>
</p>
<p>
<input type="submit" name="groupsinfo" value="<?php p($strgroupinfo) ?>"
onclick="return groupWindow(document.form2.groups);"/>
</p>
<p>
<input type="submit" name="groupsremove" value="<?php p($strgroupremove) ?>" />
</p>
<p>
<input name="newgroupname" type="text" size="10" />
<input type="submit" name="groupsadd" value="<?php p($strgroupadd) ?>" />
</p>
</form>
</td>
<td class="generalboxcontent"><p>
<form name="form3" id="form3" method="post" action="groups.php">
<input type="hidden" name="id" value="<?php p($course->id) ?>" />
<input type="hidden" name="groupid" value="<?php p($selectedgroup) ?>" />
<select name="members[]" size="15" multiple="multiple">
<?php
if (!empty($members)) {
foreach ($members as $id => $membername) {
echo "<option value=\"$id\">$membername</option>";
}
}
?>
</select>
</p>
<p>
<input type="submit" name="membersinfo" value="<?php p($strgroupinfomembers) ?>"
onclick="return userWindow(document.form3['members[]']);" />
</p>
<p>
<input type="submit" name="membersremove" value="<?php p($strgroupremovemembers) ?>"
onclick="updateGroup()" />
</p>
</form>
</td>
</tr>
</table>

View file

@ -0,0 +1,19 @@
<table align="center" class="generalbox">
<tr>
<td valign="top"><?php echo $t->picture ?></td>
<td><p style="font-size: larger"><?php echo $t->name ?></p>
<p><?php echo $t->description ?></p>
<p><ul><?php
if ($t->users) {
foreach ($t->users as $user) {
echo '<li style="font-size: x-small">';
echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$t->courseid\">$user->fullname</a>";
echo '</li>';
}
}
?>
</ul></p>
</td>
</tr>
</table>
<br />

211
course/groups.php Normal file
View file

@ -0,0 +1,211 @@
<?php // $Id$
/// Shows all the groups in a course.
/// Editing teachers see a nifty interface for defining groups
require_once('../config.php');
require_once('lib.php');
require_variable($id); // Course id
optional_variable($edit); // Turn editing on and off
if (! $course = get_record('course', 'id', $id) ) {
error("That's an invalid course id");
}
require_login($course->id);
if (!isteacheredit($course->id) and $course->groupmode != VISIBLEGROUPS) {
redirect("group.php?id=$course->id"); // Not allowed to see all groups
}
if (isteacheredit($course->id)) {
if (isset($edit)) {
if ($edit == "on") {
$USER->groupsediting = true;
} else if ($edit == "off") {
$USER->groupsediting = false;
}
}
} else {
$USER->groupsediting = false;
}
/// Print the header of the page
$strgroup = get_string('group');
$strgroups = get_string('groups');
$loggedinas = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>";
print_header("$course->shortname: $strgroups", "$course->fullname",
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
-> $strgroups", "", "", true, update_groups_button($course->id), $loggedinas);
/// Get the current list of groups
$groups = get_groups($course->id);
if (!$USER->groupsediting) { /// Display an overview of all groups
if (!$groups) {
print_heading(get_string('groupsnone'));
} else {
$isteacher = isteacher($course->id);
foreach ($groups as $group) {
$t = $group;
$t->picture = print_group_picture($group->id, $course->id, $group->picture, true, true, true);
if ($t->users = get_users_in_group($group->id)) {
foreach ($t->users as $key => $user) {
$t->users[$key]->fullname = fullname($user, $isteacher);
}
}
include('groups-summary.html');
}
}
print_footer($course);
exit;
}
/// We are in editing mode. First, process any inputs there may be.
if ($data = data_submitted()) {
if (!empty($data->nonmembersadd)) { /// Add people to a group
if (!empty($data->nonmembers) and !empty($data->groupid)) {
foreach ($data->nonmembers as $userid) {
if (!user_group($courseid, $userid)) { // Just to make sure (another teacher could be editing)
$record->groupid = $data->groupid;
$record->userid = $userid;
if (!insert_record('group_members', $record)) {
notify("Error occurred while adding user $userid to group $data->groupid");
}
}
}
}
$selectedgroup = $data->groupid;
} else if (!empty($data->nonmembersrandom)) { /// Add all non members to groups
notify("Random adding of people into groups is not functional yet.");
} else if (!empty($data->nonmembersinfo)) { /// Return info about the selected users
notify("You must turn Javascript on");
} else if (!empty($data->groupsremove)) { /// Remove a group, all members become nonmembers
if (!empty($data->groups)) {
delete_records("group", "id", $data->groups);
delete_records("group_members", "groupid", $data->groups);
unset($groups[$data->groups]);
}
} else if (!empty($data->groupsinfo)) { /// Display full info for a group
notify("You must turn Javascript on");
} else if (!empty($data->groupsadd)) { /// Create a new group
if (!empty($data->newgroupname)) {
$newgroup->name = $data->newgroupname;
$newgroup->courseid = $course->id;
$newgroup->lang = current_language();
if (!insert_record("group", $newgroup)) {
notify("Could not insert the new group '$newgroup->name'");
}
$groups = get_groups($course->id);
}
} else if (!empty($data->membersremove)) { /// Remove selected people from a particular group
if (!empty($data->members) and !empty($data->groupid)) {
foreach ($data->members as $userid) {
delete_records('group_members', 'userid', $userid, "groupid", $data->groupid);
}
}
$selectedgroup = $data->groupid;
} else if (!empty($data->membersinfo)) { /// Return info about the selected users
notify("You must turn Javascript on");
}
}
$SESSION->fullnamedisplay = 'firstname lastname';
/// Calculate data ready to create the editing interface
$strgroupnonmembers = get_string('groupnonmembers');
$strgroupmembersselected = get_string('groupmembersselected');
$strgroupremovemembers = get_string('groupremovemembers');
$strgroupinfomembers = get_string('groupinfomembers');
$strgroupadd = get_string('groupadd');
$strgroupremove = get_string('groupremove');
$strgroupinfo = get_string('groupinfo');
$strgroupinfopeople = get_string('groupinfopeople');
$strgrouprandomassign = get_string('grouprandomassign');
$strgroupaddusers = get_string('groupaddusers');
$courseid = $course->id;
$listgroups = array();
$listmembers = array();
$nonmembers = array();
$groupcount = count($groups);
/// First, get everyone into the nonmembers array
if ($students = get_course_students($course->id)) {
foreach ($students as $student) {
$nonmembers[$student->id] = fullname($student, true);
}
unset($students);
}
if ($teachers = get_course_teachers($course->id)) {
foreach ($teachers as $teacher) {
$prefix = '- ';
if (isteacheredit($course->id, $user->id)) {
$prefix = '# ';
}
$nonmembers[$teacher->id] = $prefix.fullname($teacher, true);
}
unset($teachers);
}
/// Pull out all the members into little arrays
if ($groups) {
foreach ($groups as $group) {
$countusers = 0;
$listmembers[$group->id] = array();
if ($groupusers = get_users_in_group($group->id)) {
foreach ($groupusers as $groupuser) {
$listmembers[$group->id][$groupuser->id] = $nonmembers[$groupuser->id];
unset($nonmembers[$groupuser->id]);
$countusers++;
}
asort($listmembers[$group->id]);
}
$listgroups[$group->id] = $group->name." ($countusers)";
}
asort($listgroups);
}
asort($nonmembers);
if (empty($selectedgroup)) { // Choose the first group by default
if ($selectedgroup = array_shift(array_keys($listgroups))) {
$members = $listmembers[$selectedgroup];
}
} else {
$members = $listmembers[$selectedgroup];
}
/// Print out the complete form
include('groups-edit.html');
print_footer($course);
?>

View file

@ -13,14 +13,14 @@
if (isadmin()) {
if (isset($_GET['edit'])) {
if ($edit == "on") {
$USER->editing = true;
$USER->categoriesediting = true;
} else if ($edit == "off") {
$USER->editing = false;
$USER->categoriesediting = false;
}
}
}
$adminediting = (isadmin() and !empty($USER->editing));
$adminediting = (isadmin() and !empty($USER->categoriesediting));
/// Unless it's an editing admin, just print the regular listing of courses/categories

View file

@ -945,6 +945,13 @@ function get_user_info_from_db($field, $value) {
}
}
if ($groups = get_records("group_members", "userid", $user->id)) {
foreach ($groups as $group) {
$courseid = get_field("group", "courseid", "id", $group->id);
$user->groupmember[$courseid] = $group->id;
}
}
return $user;
}
@ -1418,6 +1425,69 @@ function get_users_longtimenosee($cutofftime) {
AND timeaccess < '$cutofftime' ");
}
/**
* Returns an array of group objects that the user is a member of
* in the given course. If userid isn't specified, then return a
* list of all groups in the course.
*
* @param type description
*/
function get_groups($courseid, $userid=0) {
global $CFG;
if ($userid) {
$userselect = "AND m.groupid = g.id AND m.userid = '$userid'";
}
return get_records_sql("SELECT DISTINCT g.*
FROM {$CFG->prefix}group g,
{$CFG->prefix}group_members m
WHERE g.courseid = '$courseid' $userselect ");
}
/**
* Returns an array of user objects
*
* @param type description
*/
function get_users_in_group($groupid) {
global $CFG;
return get_records_sql("SELECT DISTINCT u.*
FROM {$CFG->prefix}user u,
{$CFG->prefix}group_members m
WHERE m.groupid = '$groupid'
AND m.userid = u.id");
}
/**
* An efficient way of finding all the users who aren't in groups yet
*
* @param type description
*/
function get_users_not_in_group($courseid) {
global $CFG;
return array(); /// XXX TO BE DONE
}
/**
* Returns the user's group in a particular course
*
* @param type description
*/
function user_group($courseid, $userid) {
global $CFG;
return get_record_sql("SELECT g.*
FROM {$CFG->prefix}group g,
{$CFG->prefix}group_members m
WHERE g.courseid = '$courseid'
AND g.id = m.groupid
AND m.userid = '$userid'");
}
/// OTHER SITE AND COURSE FUNCTIONS /////////////////////////////////////////////

View file

@ -560,6 +560,39 @@ function main_upgrade($oldversion=0) {
table_column("course", "", "showreports", "integer", "4", "unsigned", "0", "", "maxbytes");
}
if ($oldversion < 2003121600) {
modify_database("", "CREATE TABLE `prefix_group` (
`id` int(10) unsigned NOT NULL auto_increment,
`courseid` int(10) unsigned NOT NULL default '0',
`name` varchar(254) NOT NULL default '',
`description` text NOT NULL,
`lang` varchar(10) NOT NULL default 'en',
`picture` int(10) unsigned NOT NULL default '0',
`timecreated` int(10) unsigned NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `courseid` (`courseid`)
) TYPE=MyISAM COMMENT='Each record is a group in a course.'; ");
modify_database("", "CREATE TABLE `prefix_group_members` (
`id` int(10) unsigned NOT NULL auto_increment,
`groupid` int(10) unsigned NOT NULL default '0',
`userid` int(10) unsigned NOT NULL default '0',
`timeadded` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `groupid` (`groupid`)
) TYPE=MyISAM COMMENT='Lists memberships of users in groups'; ");
}
if ($oldversion < 2003121800) {
table_column("course", "modinfo", "modinfo", "longtext", "", "", "");
}
if ($oldversion < 2003122600) {
table_column("course", "", "groupmode", "integer", "4", "unsigned", "0", "", "showreports");
table_column("course", "", "groupmodeforce", "integer", "4", "unsigned", "0", "", "groupmode");
}
return $result;
}

View file

@ -37,7 +37,7 @@ CREATE TABLE `prefix_course` (
`summary` text NOT NULL,
`format` varchar(10) NOT NULL default 'topics',
`showgrades` smallint(2) unsigned NOT NULL default '1',
`modinfo` text NOT NULL,
`modinfo` longtext NOT NULL,
`newsitems` smallint(5) unsigned NOT NULL default '1',
`teacher` varchar(100) NOT NULL default 'Teacher',
`teachers` varchar(100) NOT NULL default 'Teachers',
@ -51,6 +51,9 @@ CREATE TABLE `prefix_course` (
`maxbytes` int(10) unsigned NOT NULL default '0',
`showreports` int(4) unsigned NOT NULL default '0',
`visible` int(10) unsigned NOT NULL default '1',
`groupmode` int(4) unsigned NOT NULL default '0',
`groupmodeforce` int(4) unsigned NOT NULL default '0',
`showreports` int(4) unsigned NOT NULL default '0',
`timecreated` int(10) unsigned NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
@ -124,10 +127,44 @@ CREATE TABLE `prefix_course_sections` (
`summary` text NOT NULL,
`sequence` text NOT NULL default '',
`visible` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `coursesection` (course,section)
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `group`
#
CREATE TABLE `prefix_group` (
`id` int(10) unsigned NOT NULL auto_increment,
`courseid` int(10) unsigned NOT NULL default '0',
`name` varchar(254) NOT NULL default '',
`description` text NOT NULL,
`lang` varchar(10) NOT NULL default 'en',
`picture` int(10) unsigned NOT NULL default '0',
`timecreated` int(10) unsigned NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `courseid` (`courseid`)
) TYPE=MyISAM COMMENT='Each record is a group in a course.';
# --------------------------------------------------------
#
# Table structure for table `group_members`
#
CREATE TABLE `prefix_group_members` (
`id` int(10) unsigned NOT NULL auto_increment,
`groupid` int(10) unsigned NOT NULL default '0',
`userid` int(10) unsigned NOT NULL default '0',
`timeadded` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `groupid` (`groupid`)
) TYPE=MyISAM COMMENT='Lists memberships of users to groups';
# --------------------------------------------------------
#
# Table structure for table `log`
#

View file

@ -310,6 +310,36 @@ function main_upgrade($oldversion=0) {
}
if ($oldversion < 2003121600) {
execute_sql("CREATE TABLE {$CFG->prefix}group (
id SERIAL PRIMARY KEY,
courseid integer NOT NULL default '0',
name varchar(255) NOT NULL default '',
description text,
lang varchar(10) NOT NULL default '',
picture integer NOT NULL default '0',
timecreated integer NOT NULL default '0',
timemodified integer NOT NULL default '0'
)");
execute_sql("CREATE INDEX {$CFG->prefix}group_idx ON {$CFG->prefix}group (courseid) ");
execute_sql("CREATE TABLE {$CFG->prefix}group_members (
id SERIAL PRIMARY KEY,
groupid integer NOT NULL default '0',
userid integer NOT NULL default '0',
timeadded integer NOT NULL default '0'
)");
execute_sql("CREATE INDEX {$CFG->prefix}group_members_idx ON {$CFG->prefix}group_members (groupid) ");
}
if ($oldversion < 2003122600) {
table_column("course", "", "groupmode", "integer", "4", "unsigned", "0", "", "visible");
table_column("course", "", "groupmodeforce", "integer", "4", "unsigned", "0", "", "groupmode");
}
return $result;
}
?>

View file

@ -29,6 +29,8 @@ CREATE TABLE prefix_course (
maxbytes integer NOT NULL default '0',
showreports integer NOT NULL default '0',
visible integer NOT NULL default '1',
groupmode integer NOT NULL default '0',
groupmodeforce integer NOT NULL default '0',
timecreated integer NOT NULL default '0',
timemodified integer NOT NULL default '0'
);
@ -77,6 +79,28 @@ CREATE TABLE prefix_course_sections (
visible integer NOT NULL default '1'
);
CREATE TABLE prefix_group (
id SERIAL PRIMARY KEY,
courseid integer NOT NULL default '0',
name varchar(255) NOT NULL default '',
description text,
lang varchar(10) NOT NULL default '',
picture integer NOT NULL default '0',
timecreated integer NOT NULL default '0',
timemodified integer NOT NULL default '0'
);
CREATE INDEX prefix_group_idx ON prefix_group (courseid);
CREATE TABLE prefix_group_members (
id SERIAL PRIMARY KEY,
groupid integer NOT NULL default '0',
userid integer NOT NULL default '0',
timeadded integer NOT NULL default '0'
);
CREATE INDEX prefix_group_members_idx ON prefix_group_members (groupid);
CREATE TABLE prefix_log (
id SERIAL PRIMARY KEY,
time integer NOT NULL default '0',

View file

@ -34,6 +34,12 @@
// //
///////////////////////////////////////////////////////////////////////////
/// CONSTANTS /////////////////////////////////////////////////////////////
define('NOGROUPS', 0);
define('SEPARATEGROUPS', 1);
define('VISIBLEGROUPS', 2);
/// PARAMETER HANDLING ////////////////////////////////////////////////////
@ -504,7 +510,11 @@ function fullname($user, $override=false) {
/// or language. 'override' will force both names
/// to be used even if system settings specify one.
global $CFG;
global $CFG, $SESSION;
if (!empty($SESSION->fullnamedisplay)) {
$CFG->fullnamedisplay = $SESSION->fullnamedisplay;
}
if ($CFG->fullnamedisplay == 'firstname lastname') {
return "$user->firstname $user->lastname";
@ -865,6 +875,76 @@ function remove_course_contents($courseid, $showfeedback=true) {
}
/// GROUPS /////////////////////////////////////////////////////////
/**
* Returns a boolean: is the user a member of the given group?
*
* @param type description
*/
function ismember($groupid, $userid=0) {
global $USER;
if (!$userid) {
return !empty($USER->groupmember[$groupid]);
}
return record_exists("group_members", "groupid", $groupid, "userid", $userid);
}
/**
* For a given course, and possibly course module, determine
* what the current default groupmode is:
* NOGROUPS, SEPARATEGROUPS or VISIBLEGROUPS
*
* @param type description
*/
function groupmode($course, $cm=null) {
if ($cm and !$course->groupmodeforce) {
return $cm->groupmode;
}
return $course->groupmode;
}
/**
* Sets the current group in the session variable
*
* @param type description
*/
function set_current_group($courseid, $groupid) {
global $SESSION;
return $SESSION->currentgroup[$courseid] = $groupid;
}
/**
* Gets the current group for the current user as an id or an object
*
* @param type description
*/
function get_current_group($courseid, $full=false) {
global $SESSION, $USER;
if (empty($SESSION->currentgroup[$courseid])) {
if (empty($USER->groupmember[$courseid])) {
return false;
} else {
$SESSION->currentgroup[$courseid] = $USER->groupmember[$courseid];
}
}
if ($full) {
return get_record('group', 'id', $SESSION->currentgroup[$courseid]);
} else {
return $SESSION->currentgroup[$courseid];
}
}
/// CORRESPONDENCE ////////////////////////////////////////////////
function email_to_user($user, $from, $subject, $messagetext, $messagehtml="", $attachment="", $attachname="") {

View file

@ -1069,7 +1069,7 @@ function print_file_picture($path, $courseid=0, $height="", $width="", $link="")
}
function print_user_picture($userid, $courseid, $picture, $large=false, $returnstring=false, $link=true) {
global $CFG, $THEME;
global $CFG;
if ($link) {
$output = "<a href=\"$CFG->wwwroot/user/view.php?id=$userid&amp;course=$courseid\">";
@ -1106,6 +1106,44 @@ function print_user_picture($userid, $courseid, $picture, $large=false, $returns
}
}
function print_group_picture($groupid, $courseid, $picture, $large=false, $returnstring=false, $link=true) {
global $CFG;
if ($link) {
$output = "<a href=\"$CFG->wwwroot/course/group.php?id=$courseid&group=$groupid\">";
} else {
$output = "";
}
if ($large) {
$file = "f1";
$size = 100;
} else {
$file = "f2";
$size = 35;
}
if ($picture) { // Print custom group picture
if ($CFG->slasharguments) { // Use this method if possible for better caching
$output .= "<img align=\"absmiddle\" src=\"$CFG->wwwroot/user/pixgroup.php/$groupid/$file.jpg\"".
" border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
} else {
$output .= "<img align=\"absmiddle\" src=\"$CFG->wwwroot/user/pixgroup.php?file=/$groupid/$file.jpg\"".
" border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
}
} else { // Print default group pictures (use theme version if available)
$output .= "<img align=\"absmiddle\" src=\"$CFG->pixpath/g/$file.png\"".
" border=\"0\" width=\"$size\" height=\"$size\" alt=\"\" />";
}
if ($link) {
$output .= "</a>";
}
if ($returnstring) {
return $output;
} else {
echo $output;
}
}
function print_table($table) {
// Prints a nicely formatted table.
// $table is an object with several properties.
@ -1404,7 +1442,7 @@ function update_category_button($categoryid) {
global $CFG, $USER;
if (iscreator()) {
if (!empty($USER->editing)) {
if (!empty($USER->categoryediting)) {
$string = get_string("turneditingoff");
$edit = "off";
} else {
@ -1423,7 +1461,7 @@ function update_categories_button() {
global $CFG, $USER;
if (isadmin()) {
if (!empty($USER->editing)) {
if (!empty($USER->categoriesediting)) {
$string = get_string("turneditingoff");
$edit = "off";
} else {
@ -1436,6 +1474,44 @@ function update_categories_button() {
}
}
function update_group_button($courseid) {
// Prints the editing button on group page
global $CFG, $USER;
if (isteacheredit($courseid)) {
if (!empty($USER->groupediting)) {
$string = get_string("turneditingoff");
$edit = "off";
} else {
$string = get_string("turneditingon");
$edit = "on";
}
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/group.php\">".
"<input type=\"hidden\" name=\"id\" value=\"$courseid\" />".
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
"<input type=\"submit\" value=\"$string\" /></form>";
}
}
function update_groups_button($courseid) {
// Prints the editing button on groups page
global $CFG, $USER;
if (isteacheredit($courseid)) {
if (!empty($USER->groupsediting)) {
$string = get_string("turneditingoff");
$edit = "off";
} else {
$string = get_string("turneditingon");
$edit = "on";
}
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/groups.php\">".
"<input type=\"hidden\" name=\"id\" value=\"$courseid\" />".
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
"<input type=\"submit\" value=\"$string\" /></form>";
}
}
function navmenu($course, $cm=NULL, $targetwindow="self") {
// Given a course and a (current) coursemodule
@ -1801,6 +1877,10 @@ function print_paging_bar($totalcount, $page, $perpage, $baseurl) {
if ($totalcount > $perpage) {
echo "<center>";
echo "<p>".get_string("page").":";
if ($page > 0) {
$pagenum=$page-1;
echo "&nbsp;(<a href=\"{$baseurl}page=$pagenum\">".get_string("previous")."</a>)&nbsp;";
}
$lastpage = ceil($totalcount / $perpage);
if ($page > 15) {
$startpage = $page - 10;

BIN
pix/g/f1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

BIN
pix/g/f2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

49
user/pixgroup.php Normal file
View file

@ -0,0 +1,49 @@
<?php // $Id$
// This function fetches group pictures from the data directory
// Syntax: pix.php/groupid/f1.jpg or pix.php/groupid/f2.jpg
// OR: ?file=groupid/f1.jpg or ?file=groupid/f2.jpg
$nomoodlecookie = true; // Because it interferes with caching
require_once("../config.php");
$lifetime = 86400;
if (isset($file)) { // workaround for situations where / syntax doesn't work
$pathinfo = $file;
} else {
$pathinfo = get_slash_arguments("pixgroup.php");
}
if (! $args = parse_slash_arguments($pathinfo)) {
error("No valid arguments supplied");
}
$numargs = count($args);
if ($numargs == 2) {
$groupid = (integer)$args[0];
$image = $args[1];
$pathname = "$CFG->dataroot/groups/$groupid/$image";
$filetype = "image/jpeg";
} else {
$pathname = "$CFG->dirroot/pix/g/f1.png";
$filetype = "image/png";
}
$lastmodified = filemtime($pathname);
if (file_exists($pathname)) {
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
header("Cache-control: max_age = $lifetime"); // a day
header("Pragma: ");
header("Content-disposition: inline; filename=$image");
header("Content-length: ".filesize($pathname));
header("Content-type: $filetype");
readfile("$pathname");
}
exit;
?>

View file

@ -5,7 +5,7 @@
// database to determine whether upgrades should
// be performed (see lib/db/*.php)
$version = 2003121500; // The current version is a date (YYYYMMDDXX)
$version = 2003122600; // The current version is a date (YYYYMMDDXX)
$release = "1.2 development"; // User-friendly version number