MDL-50537 mod_chat: New WS mod_chat_get_chats_by_courses
[moodle.git] / group / group.php
blob9b966b787649d8baaebe1a785c058fc16b98413f
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 $strgroups = get_string('groups');
78 $PAGE->set_title($strgroups);
79 $PAGE->set_heading($course->fullname . ': '.$strgroups);
80 $PAGE->set_pagelayout('admin');
81 navigation_node::override_active_url(new moodle_url('/group/index.php', array('id' => $course->id)));
83 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
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);
87 if (!empty($group->id)) {
88 $editoroptions['subdirs'] = file_area_contains_subdirs($context, 'group', 'description', $group->id);
89 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', $group->id);
90 } else {
91 $editoroptions['subdirs'] = false;
92 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', null);
95 /// First create the form
96 $editform = new group_form(null, array('editoroptions'=>$editoroptions));
97 $editform->set_data($group);
99 if ($editform->is_cancelled()) {
100 redirect($returnurl);
102 } elseif ($data = $editform->get_data()) {
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);
108 if ($data->id) {
109 groups_update_group($data, $editform, $editoroptions);
110 } else {
111 $id = groups_create_group($data, $editform, $editoroptions);
112 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
115 redirect($returnurl);
118 $strgroups = get_string('groups');
119 $strparticipants = get_string('participants');
121 if ($id) {
122 $strheading = get_string('editgroupsettings', 'group');
123 } else {
124 $strheading = get_string('creategroup', 'group');
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)));
129 $PAGE->navbar->add($strheading);
131 /// Print header
132 echo $OUTPUT->header();
133 echo '<div id="grouppicture">';
134 if ($id) {
135 print_group_picture($group, $course->id);
137 echo '</div>';
138 $editform->display();
139 echo $OUTPUT->footer();