Merge branch 'MDL-39489_master' of git://github.com/dmonllao/moodle
[moodle.git] / group / group.php
blobb6aa7539d64c0b1a551ba21752f0ef1e81a9aa5b
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
18 /**
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
23 * @package core_group
26 require_once('../config.php');
27 require_once('lib.php');
28 require_once('group_form.php');
30 /// get url variables
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.
38 if ($delete) {
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)));
44 if ($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');
59 } else {
60 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
61 print_error('invalidcourseid');
63 $group = new stdClass();
64 $group->courseid = $course->id;
67 if ($id !== 0) {
68 $PAGE->set_url('/group/group.php', array('id'=>$id));
69 } else {
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 $editoroptions['subdirs'] = file_area_contains_subdirs($context, 'group', 'description', $group->id);
83 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', $group->id);
84 } else {
85 $editoroptions['subdirs'] = false;
86 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', null);
89 /// First create the form
90 $editform = new group_form(null, array('editoroptions'=>$editoroptions));
91 $editform->set_data($group);
93 if ($editform->is_cancelled()) {
94 redirect($returnurl);
96 } elseif ($data = $editform->get_data()) {
97 if (!has_capability('moodle/course:changeidnumber', $context)) {
98 // Remove the idnumber if the user doesn't have permission to modify it
99 unset($data->idnumber);
102 if ($data->id) {
103 groups_update_group($data, $editform, $editoroptions);
104 } else {
105 $id = groups_create_group($data, $editform, $editoroptions);
106 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
109 redirect($returnurl);
112 $strgroups = get_string('groups');
113 $strparticipants = get_string('participants');
115 if ($id) {
116 $strheading = get_string('editgroupsettings', 'group');
117 } else {
118 $strheading = get_string('creategroup', 'group');
121 $PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
122 $PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$courseid)));
123 $PAGE->navbar->add($strheading);
125 /// Print header
126 $PAGE->set_title($strgroups);
127 $PAGE->set_heading($course->fullname . ': '.$strgroups);
128 echo $OUTPUT->header();
129 echo '<div id="grouppicture">';
130 if ($id) {
131 print_group_picture($group, $course->id);
133 echo '</div>';
134 $editform->display();
135 echo $OUTPUT->footer();