diff --git a/group/edit.php b/group/edit.php
index 83d0a97fd81..b2569bb1508 100755
--- a/group/edit.php
+++ b/group/edit.php
@@ -16,33 +16,37 @@ require_once('lib.php');
require_once('edit_form.php');
/// get url variables
-$id = required_param('id', PARAM_INT);
-$groupingid = optional_param('grouping', false, PARAM_INT);
-$newgrouping= optional_param('newgrouping', false, PARAM_INT);
-$groupid = optional_param('group', false, PARAM_INT);
+$id = optional_param('id', false, PARAM_INT);
+$groupingid = optional_param('grouping', false, PARAM_INT);
+$newgrouping = optional_param('newgrouping', false, PARAM_INT);
+$courseid = required_param('courseid', PARAM_INT);
+if ($groupingid === false) {
+ $groupingid = -1;
+}
$delete = optional_param('delete', false, PARAM_BOOL);
/// Course must be valid
-if (!$course = get_record('course', 'id', $id)) {
+if (!$course = get_record('course', 'id', $courseid)) {
error('Course ID was incorrect');
}
/// Delete action should not be called without a group id
-if ($delete && !$groupid) {
+if ($delete && !$id) {
error(get_string('errorinvalidgroup'));
}
/// basic access control checks
-if ($groupid) {
- if (!$group = get_record('groups', 'id', $groupid)) {
+if ($id) {
+ if (!$group = get_record('groups', 'id', $id)) {
error('Group ID was incorrect');
}
- require_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE), $course->id);
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ require_capability('moodle/course:managegroups', $context);
}
/// First create the form
-$editform = new group_edit_form('group.php', compact('group'));
+$editform = new group_edit_form('edit.php', compact('group', 'groupingid', 'newgrouping', 'group', 'courseid'));
/// Override defaults if group is set
if (!empty($group)) {
@@ -50,218 +54,71 @@ if (!empty($group)) {
}
if ($editform->is_cancelled()) {
- redirect(groups_home_url($courseid, $groupid, $groupingid, false));
+ redirect(groups_home_url($courseid, $id, $groupingid, false));
} elseif ($data = $editform->get_data()) {
$success = true;
-
+
// preprocess data
if ($delete) {
- if ($success = groups_delete_group($groupid)) {
+ if ($success = groups_delete_group($id)) {
redirect(groups_home_url($course->id, null, $groupingid, false));
} else {
print_error('erroreditgroup', 'group', groups_home_url($course->id));
}
} elseif (empty($group)) { // New group
- if (!$group = groups_create_group($course->id)) {
+ if (!$id = groups_create_group($course->id, $data)) {
print_error('erroreditgroup');
} else {
- $success = (bool)$groupid = groups_create_group($course->id);
+ $success = (bool)$id;
+ $data->id = $id;
+ if ($groupingid) {
+ $success = $success && groups_add_group_to_grouping($id, $groupingid);
+ }
}
} elseif ($groupingid != $newgrouping) { // Moving group to new grouping
- if ($groupingid != GROUP_NOT_IN_GROUPING) {
- $success = $success && groups_remove_group_from_grouping($groupid, $groupingid);
- }
+ $success = $success && groups_remove_group_from_grouping($id, $groupingid);
+ $success = $success && groups_add_group_to_grouping($id, $newgrouping);
} else { // Updating group
if (!groups_update_group($data, $course->id)) {
print_error('groupnotupdated');
}
}
-
// Handle file upload
if ($success) {
- $um = new upload_manager('imagefile',false,false,$course=null,false,$modbytes=0,$silent=false,$allownull=true);
- if ($um->preprocess_files()) {
- require_once("$CFG->libdir/gdlib.php");
-
- if (save_profile_image($groupid, $um, 'groups')) {
- $groupsettings->picture = 1;
- }
- } else {
- $success = false;
- }
+ require_once("$CFG->libdir/gdlib.php");
+ if (save_profile_image($id, $editform->_upload_manager, 'groups')) {
+ $data->picture = 1;
+ $success = $success && groups_update_group($data, $course->id);
+ }
}
- $success = $success && groups_set_group_settings($groupid, $groupsettings);
if ($success) {
- redirect(groups_home_url($course->id, $groupid, $groupingid, false));
+ redirect(groups_home_url($course->id, $id, $groupingid, false));
} else {
print_error('erroreditgroup', 'group', groups_home_url($course->id));
}
} else { // Prepare and output form
$strgroups = get_string('groups');
+ $strparticipants = get_string('participants');
- if ($groupid) {
+ if ($id) {
$strheading = get_string('editgroupsettings', 'group');
} else {
$strheading = get_string('creategroup', 'group');
}
-
print_header("$course->shortname: ". $strheading,
$course->fullname,
"wwwroot/course/view.php?id=$courseid\">$course->shortname ".
"-> wwwroot/user/index.php?id=$courseid\">$strparticipants ".
"-> $strgroups", '', '', true, '', user_login_string($course, $USER));
+
+ print_heading($strheading);
+ echo '
';
+ if ($id) {
+ print_group_picture($group, $course->id);
+ }
+ echo '
';
$editform->display();
print_footer($course);
}
-
-/// OR, prepare the form.
-
-if ($groupid) {
- // Form to edit existing group.
- $group = groups_get_group_settings($groupid);
- if (! $group) {
- print_error('errorinvalidgroup', 'group', groups_home_url($courseid));
- }
- $strname = s($group->name);
- $strdesc = s($group->description);
-
- $strbutton = get_string('save', 'group');
- $strheading = get_string('editgroupsettings', 'group');
-} else {
- // Form to create a new one.
- $strname = get_string('defaultgroupname', 'group');
- $strdesc = '';
- $strbutton = $strheading = get_string('creategroup', 'group');
-}
-$strgroups = get_string('groups');
-$strparticipants = get_string('participants');
-if ($delete) {
- $strheading = get_string('deleteselectedgroup', 'group');
-} //else { $strheader = get_string('groupinfoedit'); }
-
-$maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes);
-if (!empty($CFG->gdversion) and $maxbytes) {
- $printuploadpicture = true;
-} else {
- $printuploadpicture = false;
-}
-
-/// Print the page and form
-
-print_header("$course->shortname: ". $strheading,
- $course->fullname,
- "wwwroot/course/view.php?id=$courseid\">$course->shortname ".
- "-> wwwroot/user/index.php?id=$courseid\">$strparticipants ".
- "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
-
-$usehtmleditor = false;
-
-echo '' . $strheading . '
'."\n";
-
-echo ''."\n";
-
-print_footer($course);
-
?>
diff --git a/group/edit_form.php b/group/edit_form.php
index c9bbe7c7948..b9af51f43f6 100644
--- a/group/edit_form.php
+++ b/group/edit_form.php
@@ -2,6 +2,7 @@
require_once($CFG->dirroot.'/lib/formslib.php');
+/// get url variables
class group_edit_form extends moodleform {
// Define the form
@@ -9,22 +10,31 @@ class group_edit_form extends moodleform {
global $USER, $CFG, $COURSE;
$strrequired = get_string('required');
+ $buttonstr = get_string('creategroup', 'group');
+
+ if (isset($this->_customdata['group'])) {
+ $group = $this->_customdata['group'];
+ } else {
+ $group = false;
+ }
- $group = $this->_customdata['group'];
$groupingid = $this->_customdata['groupingid'];
$newgrouping = $this->_customdata['newgrouping'];
+ $courseid = $this->_customdata['courseid'];
+
+ $id = $group->id;
$mform =& $this->_form;
-
- $mform->addElement('text','name', get_string('name'),'maxlength="254" size="50"');
- $mform->setDefault('name', get_string('defaultgroupname'));
+
+ $mform->addElement('text','name', get_string('groupname', 'group'),'maxlength="254" size="50"');
+ $mform->setDefault('name', get_string('defaultgroupname', 'group'));
$mform->addRule('name', get_string('missingname'), 'required', null, 'client');
$mform->setType('name', PARAM_MULTILANG);
- $mform->addElement('htmleditor', 'description', get_string('description'), array('rows'=> '5', 'cols'=>'45'));
+ $mform->addElement('htmleditor', 'description', get_string('groupdescription', 'group'), array('rows'=> '5', 'cols'=>'45'));
$mform->setType('description', PARAM_RAW);
- $mform->addElement('text', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="40"', get_string('enrolmentkey'));
+ $mform->addElement('text', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey'));
$mform->setHelpButton('enrolmentkey', array('groupenrolmentkey', get_string('enrolmentkey', 'group')), true);
$mform->setType('enrolmentkey', PARAM_RAW);
@@ -32,92 +42,46 @@ class group_edit_form extends moodleform {
$mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
$maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
- if (!empty($CFG->gdversion) and $maxbytes and !empty($CFG->disableuserimages)) {
- $mform->addElement('file', 'imagefile', get_string('newpicture', 'group'));
- $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')), true);
+
+ if (!empty($CFG->gdversion) and $maxbytes) {
+ $this->set_upload_manager(new upload_manager('imagefile', false, false, null, false, 0, true, true, false));
+ $mform->addElement('file', 'imagefile', get_string('newpicture', 'group'));
+ $mform->setHelpButton('imagefile', array ('picture', get_string('helppicture')), true);
}
- /// Add some extra hidden fields
+
if ($group) {
- $mform->addElement('hidden', 'group', $group->id);
+ $buttonstr = get_string('save', 'group');
+ $mform->addElement('hidden','id', null);
+ $mform->setType('id', PARAM_INT);
+
+ // Options to move group to another grouping
+ $groupingids = groups_get_groupings($courseid);
+
+ // Add pseudo-grouping "Not in a grouping"
+ $groupingids[] = GROUP_NOT_IN_GROUPING;
+ if ($groupingids) {
+ // Put the groupings into a hash and sort them
+ foreach($groupingids as $id) {
+ $listgroupings[$id] = groups_get_grouping_displayname($id, $courseid);
+ }
+ natcasesort($listgroupings);
+ $mform->addElement('select', 'newgrouping', get_string('addgroupstogrouping', 'group'), $listgroupings);
+ $mform->setDefault('newgrouping', $groupingid);
+ }
}
- if ($groupingid) {
- $mform->addElement('hidden', 'groupingid', s($groupingid));
- } else {
-
+ if($groupingid) {
+ $mform->addElement('hidden', 'grouping', $groupingid);
+ $mform->setType('grouping', PARAM_INT);
}
- $mform->addElement('hidden', 'group');
- $mform->addElement('hidden', 'course', $COURSE->id);
-
- $this->set_upload_manager(new upload_manager('imagefile', false, false, null, false, 0, true, true, false));
-
- $this->add_action_buttons(false, get_string('updatemyprofile'));
+ $this->add_action_buttons(true, $buttonstr);
+ $mform->addElement('hidden', 'courseid', $courseid);
}
function definition_after_data() {
global $USER, $CFG;
-
- $mform =& $this->_form;
- $userid = $mform->getElementValue('id');
-
- if ($user = get_record('user', 'id', $userid)) {
-
- // print picture
- if (!empty($CFG->gdversion)) {
- $image_el = $mform->getElement('currentpicture');
- if ($user and $user->picture) {
- $image_el->setValue(print_user_picture($user->id, SITEID, $user->picture, 64,true,false,'',true));
- } else {
- $image_el->setValue(get_string('none'));
- }
- }
-
- /// disable fields that are locked by auth plugins
- $fields = get_user_fieldnames();
- $freezefields = array();
- $authplugin = get_auth_plugin($user->auth);
- foreach ($fields as $field) {
- if (!$mform->elementExists($field)) {
- continue;
- }
- $configvariable = 'field_lock_' . $field;
- if (isset($authplugin->config->{$configvariable})) {
- if ($authplugin->config->{$configvariable} === 'locked') {
- $freezefields[] = $field;
- } else if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->$field != '') {
- $freezefields[] = $field;
- }
- }
- }
- $mform->hardFreeze($freezefields);
- }
- }
-
- function validation ($usernew) {
- global $CFG;
-
- $usernew = (object)$usernew;
- $user = get_record('user', 'id', $usernew->id);
- $err = array();
-
- // validate email
- if (!validate_email($usernew->email)) {
- $err['email'] = get_string('invalidemail');
- } else if (($usernew->email !== $user->email) and record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
- $err['email'] = get_string('emailexists');
- }
-
- if ($usernew->email === $user->email and over_bounce_threshold($user)) {
- $err['email'] = get_string('toomanybounces');
- }
-
- if (count($err) == 0){
- return true;
- } else {
- return $err;
- }
}
function get_um() {
diff --git a/group/group.php b/group/group.php
deleted file mode 100644
index fdab5a6d8ca..00000000000
--- a/group/group.php
+++ /dev/null
@@ -1,268 +0,0 @@
-libdir.'/moodlelib.php');
-require_once($CFG->libdir.'/uploadlib.php');
-
-$success = true;
-$err = array();
-
-$courseid = required_param('courseid', PARAM_INT);
-$groupingid = optional_param('grouping', false, PARAM_INT);
-$newgrouping= optional_param('newgrouping', false, PARAM_INT);
-$groupid = optional_param('group', false, PARAM_INT);
-
-$groupsettings->name = optional_param('name', false, PARAM_TEXT);
-$groupsettings->description= optional_param('description', '', PARAM_TEXT);
-$groupsettings->enrolmentkey= optional_param('enrolmentkey', '', PARAM_TEXT);
-$groupsettings->hidepicture= optional_param('hidepicture', true, PARAM_BOOL);
-
-$delete = optional_param('delete', false, PARAM_BOOL);
-
-// Get the course information so we can print the header and
-// check the course id is valid
-$course = groups_get_course_info($courseid);
-if (! $course) {
- $success = false;
- print_error('invalidcourse'); //'The course ID is invalid'
-}
-if ($delete && !$groupid) {
- $success = false;
- print_error('errorinvalidgroup', 'group', groups_home_url($courseid));
-}
-
-if ($success) {
- // Make sure that the user has permissions to manage groups.
- require_login($courseid);
-
- $context = get_context_instance(CONTEXT_COURSE, $courseid);
- if (! has_capability('moodle/course:managegroups', $context)) {
- redirect();
- }
-
-/// If data submitted, then process and store.
-
- if ($frm = data_submitted() and confirm_sesskey()) {
-
- if (isset($frm->cancel)) {
- redirect(groups_home_url($courseid, $groupid, $groupingid, false));
- }
- elseif (isset($frm->confirmdelete)) {
- if ($success = groups_delete_group($groupid)) {
- redirect(groups_home_url($courseid, null, $groupingid, false));
- } else {
- print_error('erroreditgroup', 'group', groups_home_url($courseid));
- }
- }
- elseif (empty($frm->name)) {
- $err['name'] = get_string('missingname');
- }
- elseif (isset($frm->update)) {
- if (! $groupid) { //OK, new group.
- // Allow groups to be created outside of groupings
- /*
- if (GROUP_NOT_IN_GROUPING == $groupingid) {
- print_error('errornotingrouping', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
- }
- */
- $success = (bool)$groupid = groups_create_group($courseid); //$groupsettings);
-
- }
- elseif ($groupingid != $newgrouping) { //OK, move group.
- // Allow groups to be created outside of groupings
- /*
- if (GROUP_NOT_IN_GROUPING == $newgrouping) {
- print_error('errornotingrouping', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
- }
- */
- if ($groupingid != GROUP_NOT_IN_GROUPING) {
- $success = $success && groups_remove_group_from_grouping($groupid, $groupingid);
- }
-
- $success = $success && groups_add_group_to_grouping($groupid, $newgrouping);
- }
- if ($success) {
- //require_once($CFG->dirroot.'/lib/uploadlib.php');
-
- $um = new upload_manager('imagefile',false,false,$course=null,false,$modbytes=0,$silent=false,$allownull=true);
- if ($um->preprocess_files()) {
- require_once("$CFG->libdir/gdlib.php");
-
- if (save_profile_image($groupid, $um, 'groups')) {
- $groupsettings->picture = 1;
- }
- } else {
- $success = false;
- }
- }
- $success = $success && groups_set_group_settings($groupid, $groupsettings);
-
- if ($success) {
- redirect(groups_home_url($courseid, $groupid, $groupingid, false));
- }
- else {
- print_error('erroreditgroup', 'group', groups_home_url($courseid));
- }
- }
- }
-
-/// OR, prepare the form.
-
- if ($groupid) {
- // Form to edit existing group.
- $group = groups_get_group_settings($groupid);
- if (! $group) {
- print_error('errorinvalidgroup', 'group', groups_home_url($courseid));
- }
- $strname = s($group->name);
- $strdesc = s($group->description);
-
- $strbutton = get_string('save', 'group');
- $strheading = get_string('editgroupsettings', 'group');
- } else {
- // Form to create a new one.
- $strname = get_string('defaultgroupname', 'group');
- $strdesc = '';
- $strbutton = $strheading = get_string('creategroup', 'group');
- }
- $strgroups = get_string('groups');
- $strparticipants = get_string('participants');
- if ($delete) {
- $strheading = get_string('deleteselectedgroup', 'group');
- } //else { $strheader = get_string('groupinfoedit'); }
-
- $maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes);
- if (!empty($CFG->gdversion) and $maxbytes) {
- $printuploadpicture = true;
- } else {
- $printuploadpicture = false;
- }
-
-/// Print the page and form
-
- print_header("$course->shortname: ". $strheading,
- $course->fullname,
- "wwwroot/course/view.php?id=$courseid\">$course->shortname ".
- "-> wwwroot/user/index.php?id=$courseid\">$strparticipants ".
- "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
-
- $usehtmleditor = false;
-
- echo '' . $strheading . '
'."\n";
-
- echo ''."\n";
-
- print_footer($course);
-}
-
-?>
diff --git a/group/lib/basicgrouplib.php b/group/lib/basicgrouplib.php
index 0face0399e4..b6b121d1b14 100644
--- a/group/lib/basicgrouplib.php
+++ b/group/lib/basicgrouplib.php
@@ -424,7 +424,6 @@ function groups_remove_all_members($groupid) {
*/
function groups_update_group($data, $courseid) {
global $USER, $CFG;
-
$oldgroup = get_record('groups', 'id', $data->id); // should not fail, already tested above
// Update with the new data
diff --git a/group/lib/groupinglib.php b/group/lib/groupinglib.php
index 80649ec0dc3..77a321c2a36 100644
--- a/group/lib/groupinglib.php
+++ b/group/lib/groupinglib.php
@@ -397,10 +397,11 @@ function groups_create_grouping($courseid, $groupingsettings = false) {
*/
function groups_add_group_to_grouping($groupid, $groupingid) {
if (GROUP_NOT_IN_GROUPING == $groupingid) {
- return false;
+ return true;
}
$belongstogrouping = groups_belongs_to_grouping($groupid, $groupingid);
- if (!groups_grouping_exists($groupingid)) {
+
+ if (!groups_grouping_exists($groupingid)) {
$groupadded = false;
} elseif (!$belongstogrouping) {
$groupadded = groups_db_add_group_to_grouping($groupid, $groupingid);
@@ -491,4 +492,4 @@ function groups_delete_all_groupings($courseid) {
return $success;
}
-?>
\ No newline at end of file
+?>
diff --git a/group/lib/utillib.php b/group/lib/utillib.php
index acd412f1f97..fa296d20214 100644
--- a/group/lib/utillib.php
+++ b/group/lib/utillib.php
@@ -39,6 +39,11 @@ function groups_count_group_members($groupid) {
function groups_count_groups_in_grouping($groupingid, $courseid) {
if (GROUP_NOT_IN_GROUPING == $groupingid) {
$groupids = groups_get_groups_not_in_any_grouping($courseid);
+
+ if ($groupids === false) {
+ return false;
+ }
+
return count($groupids);
} elseif (GROUP_ANY_GROUPING == $groupingid) {
return count_records('groups_courses_groups', 'courseid', $courseid);
@@ -309,9 +314,9 @@ function groups_get_course($groupid) {
function groups_group_edit_url($courseid, $groupid, $groupingid=false, $html=true, $param=false) {
global $CFG;
$html ? $sep = '&' : $sep = '&';
- $url = $CFG->wwwroot.'/group/group.php?courseid='.$courseid;
+ $url = $CFG->wwwroot.'/group/edit.php?courseid='.$courseid;
if ($groupid) {
- $url .= $sep.'group='.$groupid;
+ $url .= $sep.'id='.$groupid;
}
if ($groupingid) {
$url .= $sep.'grouping='.$groupingid;
@@ -415,4 +420,4 @@ function groups_param_action($prefix = 'act_') {
return $action;
}
-?>
\ No newline at end of file
+?>
diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css
index 499adc8b3d4..e2ad949e25d 100644
--- a/theme/standard/styles_layout.css
+++ b/theme/standard/styles_layout.css
@@ -116,6 +116,10 @@ img.grouppicture {
border: 0;
}
+#grouppicture {
+ text-align: center;
+}
+
.notifyproblem {
text-align: center;
padding: 10px;