2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Create group OR edit group settings.
21 * @copyright 2006 The Open University, N.D.Freear AT open.ac.uk, J.White AT open.ac.uk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../config.php');
27 require_once('lib.php');
28 require_once('group_form.php');
31 $courseid = optional_param('courseid', 0, PARAM_INT
);
32 $id = optional_param('id', 0, PARAM_INT
);
33 $delete = optional_param('delete', 0, PARAM_BOOL
);
34 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
36 // This script used to support group delete, but that has been moved. In case
37 // anyone still links to it, let's redirect to the new script.
39 debugging('Deleting a group through group/group.php is deprecated and will be removed soon. Please use group/delete.php instead');
40 redirect(new moodle_url('delete.php', array('courseid' => $courseid, 'groups' => $id)));
45 if (!$group = $DB->get_record('groups', array('id'=>$id))) {
46 print_error('invalidgroupid');
48 if (empty($courseid)) {
49 $courseid = $group->courseid
;
51 } else if ($courseid != $group->courseid
) {
52 print_error('invalidcourseid');
55 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
56 print_error('invalidcourseid');
60 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
61 print_error('invalidcourseid');
63 $group = new stdClass();
64 $group->courseid
= $course->id
;
68 $PAGE->set_url('/group/group.php', array('id'=>$id));
70 $PAGE->set_url('/group/group.php', array('courseid'=>$courseid));
73 require_login($course);
74 $context = context_course
::instance($course->id
);
75 require_capability('moodle/course:managegroups', $context);
77 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$course->id
.'&group='.$id;
79 // Prepare the description editor: We do support files for group descriptions
80 $editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES
, 'maxbytes'=>$course->maxbytes
, 'trust'=>false, 'context'=>$context, 'noclean'=>true);
81 if (!empty($group->id
)) {
82 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', $group->id
);
84 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', null);
87 /// First create the form
88 $editform = new group_form(null, array('editoroptions'=>$editoroptions));
89 $editform->set_data($group);
91 if ($editform->is_cancelled()) {
94 } elseif ($data = $editform->get_data()) {
95 if (!has_capability('moodle/course:changeidnumber', $context)) {
96 // Remove the idnumber if the user doesn't have permission to modify it
97 unset($data->idnumber
);
101 groups_update_group($data, $editform, $editoroptions);
103 $id = groups_create_group($data, $editform, $editoroptions);
104 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$course->id
.'&group='.$id;
107 redirect($returnurl);
110 $strgroups = get_string('groups');
111 $strparticipants = get_string('participants');
114 $strheading = get_string('editgroupsettings', 'group');
116 $strheading = get_string('creategroup', 'group');
119 $PAGE->navbar
->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
120 $PAGE->navbar
->add($strgroups, new moodle_url('/group/index.php', array('id'=>$courseid)));
121 $PAGE->navbar
->add($strheading);
124 $PAGE->set_title($strgroups);
125 $PAGE->set_heading($course->fullname
. ': '.$strgroups);
126 echo $OUTPUT->header();
127 echo '<div id="grouppicture">';
129 print_group_picture($group, $course->id
);
132 $editform->display();
133 echo $OUTPUT->footer();