]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10383 - some more refactoring/cleanup, enablegroupings experimental admin setting...
authorskodak <skodak>
Thu, 16 Aug 2007 21:14:03 +0000 (21:14 +0000)
committerskodak <skodak>
Thu, 16 Aug 2007 21:14:03 +0000 (21:14 +0000)
14 files changed:
admin/settings/misc.php
admin/uploaduser.php
enrol/imsenterprise/enrol.php
enrol/manual/enrol.php
group/group.php
group/grouping.php
group/groupings.php
group/index.php
group/lib.php
group/tabs.php [new file with mode: 0644]
lang/en_utf8/admin.php
lang/en_utf8/group.php
lib/deprecatedlib.php
lib/grouplib.php

index 7065f0bad70cefc29034b0ed0e88f514ce586c42..9e030be0240256767b2f3711a2f141d2fe95e86e 100644 (file)
@@ -7,6 +7,8 @@ $temp = new admin_settingpage('experimental', get_string('experimental', 'admin'
 $temp->add(new admin_setting_configcheckbox('enableglobalsearch', get_string('enableglobalsearch', 'admin'), get_string('configenableglobalsearch', 'admin'), 0));
 $temp->add(new admin_setting_configcheckbox('smartpix', get_string('smartpix', 'admin'), get_string('configsmartpix', 'admin'), 0));
 $temp->add(new admin_setting_configcheckbox('enablehtmlpurifier', get_string('enablehtmlpurifier', 'admin'), get_string('configenablehtmlpurifier', 'admin'), 0));
+$temp->add(new admin_setting_configcheckbox('enablegroupings', get_string('enablegroupings', 'admin'), get_string('configenablegroupings', 'admin'), 0));
+
 $ADMIN->add('misc', $temp);
 
 // XMLDB editor
index 8a2c91af3e7684eeee067ab222df865f516724dc..4f357a84d22b5adc6f1e527dc522463dbbc28904 100755 (executable)
@@ -5,6 +5,7 @@
 
 require_once('../config.php');
 require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->dirroot.'/group/lib.php');
 require_once('uploaduser_form.php');
 
 admin_externalpage_setup('uploadusers');
index 96c7fac5a43cc5ee0b297aa9464702ae2653b736..8c70e5cbe34e8acf44047d978a1af3c9850d5c0f 100644 (file)
@@ -5,6 +5,7 @@
 * @package enrol_imsenterprise
 */
 require_once("$CFG->libdir/blocklib.php");
+require_once($CFG->dirroot.'/group/lib.php');
 
 // The following flags are set in the configuration
 // $CFG->enrol_imsfilelocation:        where is the file we are looking for?
index 347e7e610ef6b1526e687de440c33797302d7eff..bc6a2a7168520bf255cbed98b1d8cab185f00d58 100644 (file)
@@ -22,6 +22,7 @@
 //                                                                       //
 ///////////////////////////////////////////////////////////////////////////
 
+require_once($CFG->dirroot.'/group/lib.php');
 
 /**
 * enrolment_plugin_manual is the default enrolment plugin
index 4a8a93a2fd856697096243c6bb828baef6c432cc..b39757879e18874174893f483674e455128781d4 100644 (file)
@@ -85,9 +85,10 @@ if ($editform->is_cancelled()) {
             error('Error updating group');
         }
     } else {
-        if (!groups_create_group($data, $editform->_upload_manager)) {
+        if (!$id = groups_create_group($data, $editform->_upload_manager)) {
             error('Error updating group');
         }
+        $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
     }
 
     redirect($returnurl);
@@ -101,14 +102,15 @@ if ($id) {
 } else {
     $strheading = get_string('creategroup', 'group');
 }
-print_header("$course->shortname: ". $strheading,
-             $course->fullname,
-             "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
-             "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
-             "-> <a href=\"$CFG->wwwroot/group/index.php?id=$courseid\">$strgroups</a>".
-             "-> $strheading", '', '', true, '', user_login_string($course, $USER));
-
-print_heading($strheading);
+
+
+$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
+                  array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'),
+                  array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
+$navigation = build_navigation($navlinks);
+
+/// Print header
+print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
 
 echo '<div id="grouppicture">';
 if ($id) {
index eb55a24455a31d26c565cb022858925ec5e4eaa9..dc5ad1b482381fab50bc1f6bbccbdf01082402b6 100644 (file)
@@ -99,7 +99,6 @@ if ($editform->is_cancelled()) {
 
 }
 
-$strgroups        = get_string('groups');
 $strgroupings     = get_string('groupings', 'group');
 $strparticipants = get_string('participants');
 
@@ -109,12 +108,15 @@ if ($id) {
     $strheading = get_string('creategrouping', 'group');
 }
 
-print_header("$course->shortname: ". $strheading,
-             $course->fullname,
-             "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
-             "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
-             "-> <a href=\"$returnurl\">$strgroupings</a>".
-             "-> $strheading", '', '', true, '', user_login_string($course, $USER));
+$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
+                  array('name'=>$strgroupings, 'link'=>$CFG->wwwroot.'/group/groupings.php?id='.$courseid, 'type'=>'misc'),
+                  array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
+$navigation = build_navigation($navlinks);
+
+/// Print header
+print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
+
+
 print_heading($strheading);
 $editform->display();
 print_footer($course);
index 7844e7c923b290224f08f9a531422a03c6da9558..0abbc8ef52eb2ff8fe5df8226e8da01a38cbcade 100644 (file)
@@ -24,16 +24,19 @@ $strgroups       = get_string('groups');
 $strgroupings    = get_string('groupings', 'group');
 $struses         = get_string('activities');
 $strparticipants = get_string('participants');
-$strmanagegrping = get_String('addgroupstogrouping', 'group');
+$strmanagegrping = get_String('showgroupsingrouping', 'group');
 
 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
-                  array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'),
                   array('name'=>$strgroupings, 'link'=>'', 'type'=>'misc'));
 $navigation = build_navigation($navlinks);
 
 /// Print header
 print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
 
+// Add tabs
+$currenttab = 'groupings';
+require('tabs.php');
+
 print_heading($strgroupings);
 
 $data = array();
@@ -58,7 +61,7 @@ if ($groupings = get_records('groupings', 'courseid', $course->id)) {
         $buttons .= "<a title=\"$strdelete\" href=\"grouping.php?id=$grouping->id&amp;delete=1\"><img".
                     " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
         $buttons .= "<a title=\"$strmanagegrping\" href=\"assign.php?id=$grouping->id\"><img".
-                    " src=\"$CFG->pixpath/i/group.gif\" class=\"iconsmall\" alt=\"$strmanagegrping\" /></a> ";
+                    " src=\"$CFG->pixpath/i/group.gif\" class=\"icon\" alt=\"$strmanagegrping\" /></a> ";
 
         $line[3] = $buttons;
         $data[] = $line;
index a12281f1e5ca88978148ab0cb3030b57292c4afc..bee224799fdec8b65a57ba9db31ac0291cded442 100644 (file)
@@ -33,188 +33,195 @@ if (!$course = get_record('course', 'id',$courseid)) {
     print_error('invalidcourse'); //'The course ID is invalid'
 }
 
-    // Make sure that the user has permissions to manage groups.
-    require_login($course);
+// Make sure that the user has permissions to manage groups.
+require_login($course);
 
-    $context = get_context_instance(CONTEXT_COURSE, $courseid);
-    if (! has_capability('moodle/course:managegroups', $context)) {
-        redirect(); //"group.php?id=$course->id");   // Not allowed to see all groups
-    }
+$context = get_context_instance(CONTEXT_COURSE, $courseid);
+if (! has_capability('moodle/course:managegroups', $context)) {
+    redirect(); //"group.php?id=$course->id");   // Not allowed to see all groups
+}
 
-    switch ($action) {
-        case false: //OK, display form.
-            break;
-
-        case 'ajax_getmembersingroup':
-            $members = array();
-            if ($members = groups_get_members($groupid)) {
-                $member_names = array();
-                foreach($members as $member) {
-                    $user = new object();
-                    $user->id   = $member->id;
-                    $user->name = fullname($member, true);
-                    $member_names[] = $user;
-                }
-                $json = new Services_JSON();
-                echo $json->encode($member_names);
+switch ($action) {
+    case false: //OK, display form.
+        break;
+
+    case 'ajax_getmembersingroup':
+        $members = array();
+        if ($members = groups_get_members($groupid)) {
+            $member_names = array();
+            foreach($members as $member) {
+                $user = new object();
+                $user->id   = $member->id;
+                $user->name = fullname($member, true);
+                $member_names[] = $user;
             }
-            die;  // Client side JavaScript takes it from here.
+            $json = new Services_JSON();
+            echo $json->encode($member_names);
+        }
+        die;  // Client side JavaScript takes it from here.
 
-        case 'deletegroup':
-            redirect('group.php?delete=1&amp;courseid='.$courseid.'&amp;id='.$groupid);
-            break;
+    case 'deletegroup':
+        redirect('group.php?delete=1&amp;courseid='.$courseid.'&amp;id='.$groupid);
+        break;
 
-        case 'showcreateorphangroupform':
-            redirect('group.php?courseid='.$courseid);
-            break;
+    case 'showcreateorphangroupform':
+        redirect('group.php?courseid='.$courseid);
+        break;
 
-        case 'showgroupsettingsform':
-            redirect('group.php?courseid='.$courseid.'&amp;id='.$groupid);
-            break;
+    case 'showgroupsettingsform':
+        redirect('group.php?courseid='.$courseid.'&amp;id='.$groupid);
+        break;
 
-        case 'updategroups': //Currently reloading.
-            break;
+    case 'updategroups': //Currently reloading.
+        break;
 
-        case 'removemembers':
-            break;
+    case 'removemembers':
+        break;
 
-        case 'showaddmembersform':
-            redirect('members.php?group='.$groupid);
-            break;
+    case 'showaddmembersform':
+        redirect('members.php?group='.$groupid);
+        break;
 
-        case 'updatemembers': //Currently reloading.
-            break;
+    case 'updatemembers': //Currently reloading.
+        break;
 
-        default: //ERROR.
-            if (debugging()) {
-                error('Error, unknown button/action. Probably a user-interface bug!', $returnurl);
-            break;
-        }
+    default: //ERROR.
+        if (debugging()) {
+            error('Error, unknown button/action. Probably a user-interface bug!', $returnurl);
+        break;
     }
+}
 
-    // Print the page and form
-    $strgroups = get_string('groups');
-    $strparticipants = get_string('participants');
-
-    print_header("$course->shortname: $strgroups",
-                 $course->fullname,
-                 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
-                 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
-                 "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
+// Print the page and form
+$strgroups = get_string('groups');
+$strparticipants = get_string('participants');
 
-    $disabled = 'disabled="disabled"';
+$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
+                  array('name'=>$strgroups, 'link'=>'', 'type'=>'misc'));
+$navigation = build_navigation($navlinks);
 
-    $showeditgroupsettingsform_disabled = $disabled;
-    $deletegroup_disabled = $disabled;
-    $showcreategroupform_disabled = $disabled;
-
-    if (!empty($groupid)) {
-        $showaddmembersform_disabled = '';
-        $showeditgroupsettingsform_disabled = '';
-        $deletegroup_disabled = '';
-    } else {
-        $deletegroup_disabled = $disabled;
-        $showeditgroupsettingsform_disabled = $disabled;
-        $showaddmembersform_disabled = $disabled;
-    }
-
-    print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3);
-    echo '<form id="groupeditform" action="index.php" method="post">'."\n";
-    echo '<div>'."\n";
-    echo '<input type="hidden" name="id" value="' . $courseid . '" />'."\n";
-
-    echo '<table cellpadding="6" class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">'."\n";
-    echo '<tr>'."\n";
+/// Print header
+print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
 
+if (!empty($CFG->enablegroupings)) {
+    // Add tabs
+    $currenttab = 'groups';
+    require('tabs.php');
+}
 
-    echo "<td>\n";
-    // NO GROUPINGS YET!
-    echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping">&nbsp;</span></label></p>'."\n";
+$disabled = 'disabled="disabled"';
 
-    echo '<select name="group" id="groups" size="15" class="select" onchange="membersCombo.refreshMembers(this.options[this.selectedIndex].value);"'."\n";
-    echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
+$showeditgroupsettingsform_disabled = $disabled;
+$deletegroup_disabled = $disabled;
+$showcreategroupform_disabled = $disabled;
 
-    $groups = groups_get_all_groups($courseid);
+if (!empty($groupid)) {
+    $showaddmembersform_disabled = '';
+    $showeditgroupsettingsform_disabled = '';
+    $deletegroup_disabled = '';
+} else {
+    $deletegroup_disabled = $disabled;
+    $showeditgroupsettingsform_disabled = $disabled;
+    $showaddmembersform_disabled = $disabled;
+}
 
-    $sel_groupid = 0;
+print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3);
+echo '<form id="groupeditform" action="index.php" method="post">'."\n";
+echo '<div>'."\n";
+echo '<input type="hidden" name="id" value="' . $courseid . '" />'."\n";
 
-    if ($groups) {
-        // Print out the HTML
-        foreach ($groups as $group) {
-            $select = '';
-            if ($groupid == $group->id) {
-                $select = ' selected="selected"';
-                $sel_groupid = $group->id;
-            }
-            $usercount = (int)count_records('groups_members', 'groupid', $group->id);
-            $groupname = format_string($group->name).' ('.$usercount.')';
+echo '<table cellpadding="6" class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">'."\n";
+echo '<tr>'."\n";
 
-            echo "<option value=\"{$group->id}\"$select title=\"$groupname\">$groupname</option>\n";
-        }
-    } else {
-        // Print an empty option to avoid the XHTML error of having an empty select element
-        echo '<option>&nbsp;</option>';
-    }
 
-    echo '</select>'."\n";
-    echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="'
-            . get_string('showmembersforgroup', 'group') . '" /></p>'."\n";
-    echo '<p><input type="submit" '. $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="'
-            . get_string('editgroupsettings', 'group') . '" /></p>'."\n";
-    echo '<p><input type="submit" '. $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="'
-            . get_string('deleteselectedgroup', 'group') . '" /></p>'."\n";
+echo "<td>\n";
+// NO GROUPINGS YET!
+echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping">&nbsp;</span></label></p>'."\n";
 
-    echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="'
-            . get_string('creategroup', 'group') . '" /></p>'."\n";
+echo '<select name="group" id="groups" size="15" class="select" onchange="membersCombo.refreshMembers(this.options[this.selectedIndex].value);"'."\n";
+echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
 
-    echo '</td>'."\n";
-    echo '<td>'."\n";
-    echo '<p><label for="members"><span id="memberslabel">'.get_string('membersofselectedgroup', 'group').' </span><span id="thegroup">&nbsp;</span></label></p>'."\n";
-    //NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick.
-    echo '<select name="user" id="members" size="15" class="select"'."\n";
-    echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
+$groups = groups_get_all_groups($courseid);
 
-    $member_names = array();
+$sel_groupid = 0;
 
-    if ($sel_groupid) {
-        if ($members = groups_get_members($groupid)) {
-            foreach($members as $member) {
-                $member_names[$member->id] = fullname($member, true);
-            }
+if ($groups) {
+    // Print out the HTML
+    foreach ($groups as $group) {
+        $select = '';
+        if ($groupid == $group->id) {
+            $select = ' selected="selected"';
+            $sel_groupid = $group->id;
         }
+        $usercount = (int)count_records('groups_members', 'groupid', $group->id);
+        $groupname = format_string($group->name).' ('.$usercount.')';
+
+        echo "<option value=\"{$group->id}\"$select title=\"$groupname\">$groupname</option>\n";
     }
+} else {
+    // Print an empty option to avoid the XHTML error of having an empty select element
+    echo '<option>&nbsp;</option>';
+}
 
-    if ($member_names) {
-        // Put the groupings into a hash and sort them
-        foreach ($member_names as $userid=>$username) {
-            echo "<option value=\"{$userid}\" title=\"{$username}\">{$username}</option>\n";
+echo '</select>'."\n";
+echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="'
+        . get_string('showmembersforgroup', 'group') . '" /></p>'."\n";
+echo '<p><input type="submit" '. $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="'
+        . get_string('editgroupsettings', 'group') . '" /></p>'."\n";
+echo '<p><input type="submit" '. $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="'
+        . get_string('deleteselectedgroup', 'group') . '" /></p>'."\n";
+
+echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="'
+        . get_string('creategroup', 'group') . '" /></p>'."\n";
+
+echo '</td>'."\n";
+echo '<td>'."\n";
+echo '<p><label for="members"><span id="memberslabel">'.get_string('membersofselectedgroup', 'group').' </span><span id="thegroup">&nbsp;</span></label></p>'."\n";
+//NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick.
+echo '<select name="user" id="members" size="15" class="select"'."\n";
+echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
+
+$member_names = array();
+
+if ($sel_groupid) {
+    if ($members = groups_get_members($groupid)) {
+        foreach($members as $member) {
+            $member_names[$member->id] = fullname($member, true);
         }
+    }
+}
 
-    } else {
-        // Print an empty option to avoid the XHTML error of having an empty select element
-        echo '<option>&nbsp;</option>';
+if ($member_names) {
+    // Put the groupings into a hash and sort them
+    foreach ($member_names as $userid=>$username) {
+        echo "<option value=\"{$userid}\" title=\"{$username}\">{$username}</option>\n";
     }
 
-    echo '</select>'."\n";
+} else {
+    // Print an empty option to avoid the XHTML error of having an empty select element
+    echo '<option>&nbsp;</option>';
+}
+
+echo '</select>'."\n";
 
-    echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" '
-            . 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n";
-    echo '</td>'."\n";
-    echo '</tr>'."\n";
-    echo '</table>'."\n";
+echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" '
+        . 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n";
+echo '</td>'."\n";
+echo '</tr>'."\n";
+echo '</table>'."\n";
 
-    //<input type="hidden" name="rand" value="om" />
-    echo '</div>'."\n";
-    echo '</form>'."\n";
+//<input type="hidden" name="rand" value="om" />
+echo '</div>'."\n";
+echo '</form>'."\n";
 
-    echo '<script type="text/javascript">'."\n";
-    echo '//<![CDATA['."\n";
-    echo 'var groupsCombo = new UpdatableGroupsCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
-    echo 'var membersCombo = new UpdatableMembersCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
-    echo '//]]>'."\n";
-    echo '</script>'."\n";
+echo '<script type="text/javascript">'."\n";
+echo '//<![CDATA['."\n";
+echo 'var groupsCombo = new UpdatableGroupsCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
+echo 'var membersCombo = new UpdatableMembersCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n";
+echo '//]]>'."\n";
+echo '</script>'."\n";
 
-    print_footer($course);
+print_footer($course);
 
 /**
  * Returns the first button action with the given prefix, taken from
index eb0234472d6abea60f362a850c660b112dee3e95..c0d571aa8ec305128baea07de8f09df2a7f73ef8 100644 (file)
  * require_once $CFG->dirroot.'/group/lib.php' must be used
  */
 
+/**
+ * Adds a specified user to a group
+ * @param int $userid   The user id
+ * @param int $groupid  The group id
+ * @return boolean True if user added successfully or the user is already a 
+ * member of the group, false otherwise. 
+ */
+function groups_add_member($groupid, $userid) {
+    if (!groups_group_exists($groupid)) {
+        return false;
+    }
+
+    if (groups_is_member($groupid, $userid)) {
+        return true;
+    }
+
+    $member = new object();
+    $member->groupid   = $groupid;
+    $member->userid    = $userid;
+    $member->timeadded = time();
+
+    if (!insert_record('groups_members', $member)) {
+        return false;
+    }
+
+    //update group info
+    set_field('groups', 'timemodified', $member->timeadded, 'id', $groupid);
+
+    // MDL-9983
+    $eventdata = new object();
+    $eventdata->groupid = $groupid;
+    $eventdata->userid = $userid;
+    events_trigger('group_user_added', $eventdata);      
+
+    return true;
+}
+
+/**
+ * Deletes the link between the specified user and group.
+ * @param int $groupid The group to delete the user from
+ * @param int $userid The user to delete
+ * @return boolean True if deletion was successful, false otherwise
+ */
+function groups_remove_member($groupid, $userid) {
+    if (!groups_group_exists($groupid)) {
+        return false;
+    }
+
+    if (!groups_is_member($groupid, $userid)) {
+        return true;
+    }
+
+    if (!delete_records('groups_members', 'groupid', $groupid, 'userid', $userid)) {
+        return false;
+    }    
+    //update group info
+    set_field('groups', 'timemodified', time(), 'id', $groupid);
+
+    return true;
+}
+
 /**
  * Add a new group
  * @param object $data group properties (with magic quotes);
diff --git a/group/tabs.php b/group/tabs.php
new file mode 100644 (file)
index 0000000..5953184
--- /dev/null
@@ -0,0 +1,15 @@
+<?php  // $Id$
+    $row = $tabs = array();
+    $row[] = new tabobject('groups',
+                           $CFG->wwwroot.'/group/index.php?id='.$courseid,
+                           get_string('groups'));
+
+    $row[] = new tabobject('groupings',
+                           $CFG->wwwroot.'/group/groupings.php?id='.$courseid,
+                           get_string('groupings', 'group'));
+
+    $tabs[] = $row;
+    echo '<div class="groupdisplay">';
+    print_tabs($tabs, $currenttab);
+    echo '</div>';
+?>
index db85bb2338dd73da5c22906fb51566569dc648af..47b71cc41beefc687795e11dac458d872bc9def1 100644 (file)
@@ -87,6 +87,7 @@ $string['configeditordictionary'] = 'This value will be used if aspell doesn\'t
 $string['configenableajax'] = 'This setting allows you to control the use of AJAX (advanced client/server interfaces using Javascript) across the whole site.  With this setting enabled users can still make a choice in their profile, otherwise AJAX is disabled for everybody.';
 $string['configenablecourserequests'] = 'This will allow any user to request a course be created.';
 $string['configenableglobalsearch'] = 'This setting enables global text searching in resources and activities, it is not compatible with PHP 4.';
+$string['configenablegroupings'] = 'This setting enables groupings of groups. (Not yet fully implemented)';
 $string['configenablehtmlpurifier'] = 'Use HTML Purifier instead of KSES for cleaning of untrusted text. HTML Purifier is actively developed and is believed to be more secure, but it is more resource intensive. Expect minor visual differences in the resulting html code. Please note that embed and object tags can not be enabled, MathML tags and old lang tags are not supported. ';
 $string['configenablerssfeeds'] = 'This switch will enable RSS feeds from across the site.  To actually see any change you will need to enable RSS feeds in the individual modules too - go to the Modules settings under Admin Configuration.';
 $string['configenablerssfeedsdisabled'] = 'It is not available because RSS feeds are disabled in all the Site. To enable them, go to the Variables settings under Admin Configuration.';
@@ -277,6 +278,7 @@ $string['editstrings'] = 'Edit words or phrases';
 $string['enableajax'] = 'Enable AJAX';
 $string['enablecourserequests'] = 'Enable course requests';
 $string['enableglobalsearch'] = 'Enable global search';
+$string['enablegroupings'] = 'Enable groupings';
 $string['enablehtmlpurifier'] = 'Enable HTML Purifier';
 $string['enablerecordcache'] = 'Enable Record Cache';
 $string['enablerssfeeds'] = 'Enable RSS feeds';
index 6396f4eae52fbbe8fbf2f58cd52defa1b50504ec..1d41b387b8ab5799698aa2dc7b65e2512561c950 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Language strings for new Moodle Groups (cvs:/group/) 
+ * Language strings for Moodle Groups (cvs:/group/) 
  *
  * @copyright &copy; 2006 The Open University
  * @author J.White AT open.ac.uk
@@ -13,16 +13,11 @@ $string['groupmemberdesc'] = 'Standard role for a member of a group.';
 $string['notingrouping'] = '[Not in a grouping]';
 $string['anygrouping'] = '[Any grouping]';
 
-$string['errornotingrouping'] = 'Sorry, you can\'t create a group in $a';
-$string['errornotingroupingedit'] = 'Sorry, you can\'t edit grouping $a';
-$string['errorinvalidgrouping'] = 'Error, invalid grouping $a';
 $string['errorinvalidgroup'] = 'Error, invalid group $a';
 $string['erroreditgrouping'] = 'Error creating/updating grouping $a';
 $string['erroreditgroup'] = 'Error creating/updating group $a';
 $string['erroraddremoveuser'] = 'Error adding/removing user $a to group';
 
-$string['upgradeconfirm'] = 'Sorry, groups tables created in Moodle 1.8 DEV have to be deleted for this upgrade. Do you want to continue?';
-
 $string['groupings'] = 'Groupings';
 $string['grouping'] = 'Grouping';
 $string['groups'] = 'Groups';
@@ -81,16 +76,11 @@ $string['newpicture'] = 'New picture';
 $string['defaultgroupdescription'] = 'Default group description';
 
 $string['displaygrouping'] = 'Display grouping';
-$string['showusersalreadyingroup'] = 'Show users already in a group in the grouping';
 
-$string['save'] = 'Save';
-$string['cancel'] = 'Cancel';
-$string['return'] = 'Return';
 $string['backtogroups'] = 'Back to groups';
 $string['backtogroupings'] = 'Back to groupings';
 $string['existingmembers'] = 'Existing members: $a'; 
 $string['potentialmembers'] = 'Potential members: $a';
-$string['groupfor'] = 'for group';
 $string['groupinfo'] = 'Info about selected group';
 $string['groupinfomembers'] = 'Info about selected members';
 $string['groupinfopeople'] = 'Info about selected people';
@@ -98,16 +88,8 @@ $string['groupmembers'] = 'Group members';
 $string['groupmemberssee'] = 'See group members';
 $string['groupmembersselected'] = 'Members of selected group';
 
-
 $string['javascriptrequired'] = 'This page requires Javascript to be enabled.';
 
-$string['viewowngroup'] = 'Students may view the members of any groups to which they belong';
-$string['viewallgroupsmembers'] = 'Students may view the members of all groups';
-$string['viewallgroupsactivities'] = 'Students may view but not contribute to activities for all groups';
-$string['teachersgroupmark'] = 'Teachers may not mark activities for groups to which they do not belong';
-$string['teachersgroupview'] = 'Teachers may not view activities for groups to which they do not belong';
-$string['teachersoverride'] = 'Teachers not in any group may view and mark activities for all groups (overrides the above)';
-
 $string['groupmode'] = 'Group mode';
 $string['groupmodeforce'] = 'Force group mode';
 $string['groupmy'] = 'My group';
index e2f34d1351b7a8e67bdaf59e2dc3baed87283839..a37025bb0873c710172f0d71960c7e7442aaf336 100644 (file)
@@ -1170,6 +1170,9 @@ function mygroupid($courseid) {
  * @return bool
  */
 function add_user_to_group($groupid, $userid) {
+    global $CFG;
+    require_once($CFG->dirroot.'/group/lib.php');
+
     return groups_add_member($groupid, $userid);
 }
 
index dc6fdc6f9e3fff5bd6814e8ca4053817f2c27aaa..8c7de05963cd23cc7b36f3519e5020f28b38209e 100644 (file)
@@ -1,68 +1,6 @@
 <?php  //$Id$
 
 
-/**
- * Adds a specified user to a group
- * @param int $userid   The user id
- * @param int $groupid  The group id
- * @return boolean True if user added successfully or the user is already a 
- * member of the group, false otherwise. 
- */
-function groups_add_member($groupid, $userid) {
-    if (!groups_group_exists($groupid)) {
-        return false;
-    }
-
-    if (groups_is_member($groupid, $userid)) {
-        return true;
-    }
-
-    $member = new object();
-    $member->groupid   = $groupid;
-    $member->userid    = $userid;
-    $member->timeadded = time();
-
-    if (!insert_record('groups_members', $member)) {
-        return false;
-    }
-
-    //update group info
-    set_field('groups', 'timemodified', $member->timeadded, 'id', $groupid);
-
-    // MDL-9983
-    $eventdata = new object();
-    $eventdata -> groupid = $groupid;
-    $eventdata -> userid = $userid;
-    events_trigger('group_user_added', $eventdata);      
-
-    return true;
-}
-
-/**
- * Deletes the link between the specified user and group.
- * @param int $groupid The group to delete the user from
- * @param int $userid The user to delete
- * @return boolean True if deletion was successful, false otherwise
- */
-function groups_remove_member($groupid, $userid) {
-    if (!groups_group_exists($groupid)) {
-        return false;
-    }
-
-    if (!groups_is_member($groupid, $userid)) {
-        return true;
-    }
-
-    if (!delete_records('groups_members', 'groupid', $groupid, 'userid', $userid)) {
-        return false;
-    }    
-    //update group info
-    set_field('groups', 'timemodified', time(), 'id', $groupid);
-
-    return true;
-}
-
-
 /**
  * Determines if a group with a given groupid exists. 
  * @param int $groupid The groupid to check for