add page heading
[moodle.git] / group / grouping.php
CommitLineData
f3f7610c
ML
1<?php
2/**
3 * Create grouping OR edit grouping settings.
4 *
5 * @copyright &copy; 2006 The Open University
6 * @author N.D.Freear AT open.ac.uk
ddff2fa8 7 * @author J.White AT open.ac.uk
f3f7610c
ML
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 * @package groups
10 */
11require_once('../config.php');
12require_once('lib.php');
ddff2fa8 13require_once('grouping_form.php');
f3f7610c 14
ddff2fa8 15/// get url variables
62d63838 16$courseid = optional_param('courseid', 0, PARAM_INT);
17$id = optional_param('id', 0, PARAM_INT);
18$delete = optional_param('delete', 0, PARAM_BOOL);
19$confirm = optional_param('confirm', 0, PARAM_BOOL);
f3f7610c 20
a6855934 21$url = new moodle_url('/group/grouping.php');
ddff2fa8 22if ($id) {
bbe0bd98 23 $url->param('id', $id);
dfdaabd6 24 if (!$grouping = $DB->get_record('groupings', array('id'=>$id))) {
b121a4ee 25 print_error('invalidgroupid');
ddff2fa8 26 }
3980c306 27 $grouping->description = clean_text($grouping->description);
ddff2fa8 28 if (empty($courseid)) {
62d63838 29 $courseid = $grouping->courseid;
62d63838 30 } else if ($courseid != $grouping->courseid) {
b121a4ee 31 print_error('invalidcourseid');
bbe0bd98 32 } else {
33 $url->param('courseid', $courseid);
ddff2fa8 34 }
08103c93 35
dfdaabd6 36 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 37 print_error('invalidcourseid');
ddff2fa8 38 }
03221650 39
ddff2fa8 40} else {
bbe0bd98 41 $url->param('courseid', $courseid);
dfdaabd6 42 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 43 print_error('invalidcourseid');
ddff2fa8 44 }
45 $grouping = new object();
46 $grouping->courseid = $course->id;
c7b0485f 47}
f3f7610c 48
bbe0bd98 49$PAGE->set_url($url);
50
ddff2fa8 51require_login($course);
52$context = get_context_instance(CONTEXT_COURSE, $course->id);
53require_capability('moodle/course:managegroups', $context);
f3f7610c 54
62d63838 55$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$course->id;
ddff2fa8 56
57
58if ($id and $delete) {
59 if (!$confirm) {
b87573d7 60 $PAGE->set_title(get_string('deletegrouping', 'group'));
bd08a24a 61 $PAGE->set_heading($course->fullname. ': '. get_string('deletegrouping', 'group'));
b87573d7 62 echo $OUTPUT->header();
ddff2fa8 63 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
64 $optionsno = array('id'=>$courseid);
dc6896ef
PS
65 $formcontinue = new single_button(new moodle_url('grouping.php', $optionsyes), get_string('yes'), 'get');
66 $formcancel = new single_button(new moodle_url('groupings.php', $optionsno), get_string('no'), 'get');
768cefa0 67 echo $OUTPUT->confirm(get_string('deletegroupingconfirm', 'group', $grouping->name), $formcontinue, $formcancel);
653468d4 68 echo $OUTPUT->footer();
ddff2fa8 69 die;
70
71 } else if (confirm_sesskey()){
72 if (groups_delete_grouping($id)) {
62d63838 73 redirect($returnurl);
ddff2fa8 74 } else {
75 print_error('erroreditgrouping', 'group', $returnurl);
76 }
e4596a4a 77 }
78}
79
8bdc9cac
SH
80// Prepare the description editor: We do support files for grouping descriptions
81$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>true, 'context'=>$context, 'noclean'=>true);
82if (!empty($grouping->id)) {
83 $grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'course_grouping_description', $grouping->id);
84} else {
85 $grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'course_grouping_description', null);
86}
87
ddff2fa8 88/// First create the form
8bdc9cac 89$editform = new grouping_form(null, compact('editoroptions'));
ddff2fa8 90$editform->set_data($grouping);
91
c7b0485f 92if ($editform->is_cancelled()) {
ddff2fa8 93 redirect($returnurl);
94
c7b0485f 95} elseif ($data = $editform->get_data()) {
96 $success = true;
ddff2fa8 97
98 if ($data->id) {
8bdc9cac 99 groups_update_grouping($data, $editoroptions);
c7b0485f 100 } else {
8bdc9cac 101 groups_create_grouping($data, $editoroptions);
5bca3fed 102 }
ddff2fa8 103
104 redirect($returnurl);
105
f3f7610c 106}
ddff2fa8 107
5e2f308b 108$strgroupings = get_string('groupings', 'group');
ddff2fa8 109$strparticipants = get_string('participants');
110
111if ($id) {
112 $strheading = get_string('editgroupingsettings', 'group');
113} else {
114 $strheading = get_string('creategrouping', 'group');
115}
116
a6855934
PS
117$PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
118$PAGE->navbar->add($strgroupings, new moodle_url('/group/groupings.php', array('id'=>$courseid)));
b87573d7 119$PAGE->navbar->add($strheading);
778918fd 120
121/// Print header
b87573d7 122$PAGE->set_title($strgroupings);
bd08a24a 123$PAGE->set_heading($course->fullname. ': '.$strgroupings);
b87573d7 124echo $OUTPUT->header();
9cb990ec 125echo $OUTPUT->heading($strheading);
ddff2fa8 126$editform->display();
653468d4 127echo $OUTPUT->footer();