print_error('erroreditgroup'); } else { $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 $success = $success && groups_remove_group_from_grouping($id, $groupingid); $success = $success && groups_add_group_to_grouping($id, $newgrouping); } else { // Updating group $group = groups_get_group($data->id); if (groups_group_name_exists($courseid, $data->name) && $group->name != $data->name) { $error = get_string('groupnameexists', 'group', $data->name); $success = false; } elseif (!groups_update_group($data, $course->id)) { print_error('groupnotupdated'); } } // Handle file upload if ($success) { 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); } } if ($success) {
$newgroup->courseid = $mycourse->id; } else { $newgroup->courseid = $id; } } //if courseid is set if (isset($newgroup->courseid)) { $newgroup->timecreated = time(); $linenum++; $groupname = $newgroup->name; $newgrpcoursecontext = get_context_instance(CONTEXT_COURSE, $newgroup->courseid); ///Users cannot upload groups in courses they cannot update. if (!has_capability('moodle/course:managegroups', $newgrpcoursecontext)) { notify(get_string('nopermissionforcreation', 'group', $newgroup->name)); } else { if ($group = groups_group_name_exists($newgroup->courseid, $groupname) || !($newgroup->id = groups_create_group($newgroup->courseid, $newgroup))) { //Record not added - probably because group is already registered //In this case, output groupname from previous registration if ($group) { notify("{$newgroup->name} :" . get_string('groupexistforcourse', 'error', $groupname)); } else { notify(get_string('groupnotaddederror', 'error', $groupname)); } } else { notify(get_string('groupaddedsuccesfully', 'group', $newgroup->name)); } } } //close courseid validity check unset($newgroup); }