add page heading
[moodle.git] / group / group.php
CommitLineData
77e90955 1<?php
2/**
3 * Create group OR edit group settings.
4 *
5 * @copyright &copy; 2006 The Open University
6 * @author N.D.Freear AT open.ac.uk
2524b0f2 7 * @author J.White AT open.ac.uk
77e90955 8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 * @package groups
10 */
c4e953e6 11
77e90955 12require_once('../config.php');
77e90955 13require_once('lib.php');
c4e953e6 14require_once('group_form.php');
77e90955 15
16/// get url variables
62d63838 17$courseid = optional_param('courseid', 0, PARAM_INT);
18$id = optional_param('id', 0, PARAM_INT);
19$delete = optional_param('delete', 0, PARAM_BOOL);
20$confirm = optional_param('confirm', 0, PARAM_BOOL);
77e90955 21
f6eece19 22// This script used to support group delete, but that has been moved. In case
23// anyone still links to it, let's redirect to the new script.
24if($delete) {
25 redirect('delete.php?courseid='.$courseid.'&groups='.$id);
26}
27
80efbf98 28if ($id) {
dfdaabd6 29 if (!$group = $DB->get_record('groups', array('id'=>$id))) {
b121a4ee 30 print_error('invalidgroupid');
2524b0f2 31 }
c4e953e6 32 if (empty($courseid)) {
33 $courseid = $group->courseid;
34
35 } else if ($courseid != $group->courseid) {
b121a4ee 36 print_error('invalidcourseid');
2524b0f2 37 }
c4e953e6 38
dfdaabd6 39 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 40 print_error('invalidcourseid');
c4e953e6 41 }
42
2524b0f2 43} else {
dfdaabd6 44 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 45 print_error('invalidcourseid');
c4e953e6 46 }
2524b0f2 47 $group = new object();
c4e953e6 48 $group->courseid = $course->id;
77e90955 49}
50
af333695 51if ($id !== 0) {
a6855934 52 $PAGE->set_url('/group/group.php', array('id'=>$id));
af333695 53} else {
a6855934 54 $PAGE->set_url('/group/group.php', array('courseid'=>$courseid));
af333695 55}
56
ddff2fa8 57require_login($course);
c4e953e6 58$context = get_context_instance(CONTEXT_COURSE, $course->id);
59require_capability('moodle/course:managegroups', $context);
60
61$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
77e90955 62
c4e953e6 63if ($id and $delete) {
2524b0f2 64 if (!$confirm) {
b87573d7 65 $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
bd08a24a 66 $PAGE->set_heading($course->fullname . ': '. get_string('deleteselectedgroup', 'group'));
b87573d7 67 echo $OUTPUT->header();
2524b0f2 68 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
69 $optionsno = array('id'=>$courseid);
dc6896ef
PS
70 $formcontinue = new single_button(new moodle_url('group.php', $optionsyes), get_string('yes'), 'get');
71 $formcancel = new single_button(new moodle_url($baseurl, $optionsno), get_string('no'), 'get');
768cefa0 72 echo $OUTPUT->confirm(get_string('deletegroupconfirm', 'group', $group->name), $formcontinue, $formcancel);
653468d4 73 echo $OUTPUT->footer();
2524b0f2 74 die;
77e90955 75
2524b0f2 76 } else if (confirm_sesskey()){
77 if (groups_delete_group($id)) {
2524b0f2 78 redirect('index.php?id='.$course->id);
79 } else {
c4e953e6 80 print_error('erroreditgroup', 'group', $returnurl);
2524b0f2 81 }
e4596a4a 82 }
83}
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)) {
88 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'course_group_description', $group->id);
89} else {
90 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'course_group_description', null);
91}
92
2524b0f2 93/// First create the form
8bdc9cac 94$editform = new group_form(null, array('editoroptions'=>$editoroptions));
2524b0f2 95$editform->set_data($group);
e4596a4a 96
77e90955 97if ($editform->is_cancelled()) {
2524b0f2 98 redirect($returnurl);
99
77e90955 100} elseif ($data = $editform->get_data()) {
2524b0f2 101
2524b0f2 102 if ($data->id) {
5e2f308b 103 groups_update_group($data, $editform);
2524b0f2 104 } else {
5e2f308b 105 $id = groups_create_group($data, $editform);
778918fd 106 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
77e90955 107 }
77e90955 108
2524b0f2 109 redirect($returnurl);
110}
111
e4596a4a 112$strgroups = get_string('groups');
113$strparticipants = get_string('participants');
114
115if ($id) {
116 $strheading = get_string('editgroupsettings', 'group');
117} else {
118 $strheading = get_string('creategroup', 'group');
119}
778918fd 120
a6855934
PS
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)));
b87573d7 123$PAGE->navbar->add($strheading);
778918fd 124
125/// Print header
b87573d7 126$PAGE->set_title($strgroups);
bd08a24a 127$PAGE->set_heading($course->fullname . ': '.$strgroups);
b87573d7 128echo $OUTPUT->header();
e4596a4a 129echo '<div id="grouppicture">';
130if ($id) {
131 print_group_picture($group, $course->id);
77e90955 132}
e4596a4a 133echo '</div>';
134$editform->display();
653468d4 135echo $OUTPUT->footer();