weekly release 3.10.1+
[moodle.git] / group / group.php
CommitLineData
77e90955 1<?php
4d8e2417
AG
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.
13//
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/>.
16
17
77e90955 18/**
19 * Create group OR edit group settings.
20 *
4d8e2417
AG
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
77e90955 24 */
c4e953e6 25
77e90955 26require_once('../config.php');
77e90955 27require_once('lib.php');
c4e953e6 28require_once('group_form.php');
77e90955 29
30/// get url variables
62d63838 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);
77e90955 35
f6eece19 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.
cab03a03
ARN
38if ($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)));
f6eece19 41}
42
cab03a03 43
80efbf98 44if ($id) {
dfdaabd6 45 if (!$group = $DB->get_record('groups', array('id'=>$id))) {
b121a4ee 46 print_error('invalidgroupid');
2524b0f2 47 }
c4e953e6 48 if (empty($courseid)) {
49 $courseid = $group->courseid;
50
51 } else if ($courseid != $group->courseid) {
b121a4ee 52 print_error('invalidcourseid');
2524b0f2 53 }
c4e953e6 54
dfdaabd6 55 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 56 print_error('invalidcourseid');
c4e953e6 57 }
58
2524b0f2 59} else {
dfdaabd6 60 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 61 print_error('invalidcourseid');
c4e953e6 62 }
ace9051c 63 $group = new stdClass();
c4e953e6 64 $group->courseid = $course->id;
77e90955 65}
66
af333695 67if ($id !== 0) {
a6855934 68 $PAGE->set_url('/group/group.php', array('id'=>$id));
af333695 69} else {
a6855934 70 $PAGE->set_url('/group/group.php', array('courseid'=>$courseid));
af333695 71}
72
ddff2fa8 73require_login($course);
bf0f06b1 74$context = context_course::instance($course->id);
c4e953e6 75require_capability('moodle/course:managegroups', $context);
76
f196f42c
FM
77$strgroups = get_string('groups');
78$PAGE->set_title($strgroups);
79$PAGE->set_heading($course->fullname . ': '.$strgroups);
566889aa 80$PAGE->set_pagelayout('admin');
f196f42c
FM
81navigation_node::override_active_url(new moodle_url('/group/index.php', array('id' => $course->id)));
82
e88dd876 83$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
77e90955 84
8bdc9cac
SH
85// Prepare the description editor: We do support files for group descriptions
86$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>false, 'context'=>$context, 'noclean'=>true);
87if (!empty($group->id)) {
5e95223e 88 $editoroptions['subdirs'] = file_area_contains_subdirs($context, 'group', 'description', $group->id);
64f93798 89 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', $group->id);
8bdc9cac 90} else {
5e95223e 91 $editoroptions['subdirs'] = false;
64f93798 92 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', null);
8bdc9cac
SH
93}
94
2524b0f2 95/// First create the form
8bdc9cac 96$editform = new group_form(null, array('editoroptions'=>$editoroptions));
2524b0f2 97$editform->set_data($group);
e4596a4a 98
77e90955 99if ($editform->is_cancelled()) {
2524b0f2 100 redirect($returnurl);
101
77e90955 102} elseif ($data = $editform->get_data()) {
74b714df
ARN
103 if (!has_capability('moodle/course:changeidnumber', $context)) {
104 // Remove the idnumber if the user doesn't have permission to modify it
105 unset($data->idnumber);
106 }
2524b0f2 107
2524b0f2 108 if ($data->id) {
e88dd876 109 groups_update_group($data, $editform, $editoroptions);
2524b0f2 110 } else {
e88dd876
PS
111 $id = groups_create_group($data, $editform, $editoroptions);
112 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
77e90955 113 }
77e90955 114
2524b0f2 115 redirect($returnurl);
116}
117
e4596a4a 118$strgroups = get_string('groups');
119$strparticipants = get_string('participants');
120
121if ($id) {
122 $strheading = get_string('editgroupsettings', 'group');
123} else {
124 $strheading = get_string('creategroup', 'group');
125}
778918fd 126
a6855934
PS
127$PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
128$PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$courseid)));
b87573d7 129$PAGE->navbar->add($strheading);
778918fd 130
131/// Print header
b87573d7 132echo $OUTPUT->header();
e4596a4a 133echo '<div id="grouppicture">';
134if ($id) {
135 print_group_picture($group, $course->id);
77e90955 136}
e4596a4a 137echo '</div>';
138$editform->display();
653468d4 139echo $OUTPUT->footer();