group MDL-19798 Updated print_header and build_navigation to OUTPUT and PAGE equivalents
[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
ddff2fa8 21if ($id) {
dfdaabd6 22 if (!$grouping = $DB->get_record('groupings', array('id'=>$id))) {
b121a4ee 23 print_error('invalidgroupid');
ddff2fa8 24 }
3980c306 25 $grouping->description = clean_text($grouping->description);
ddff2fa8 26 if (empty($courseid)) {
62d63838 27 $courseid = $grouping->courseid;
5bca3fed 28
62d63838 29 } else if ($courseid != $grouping->courseid) {
b121a4ee 30 print_error('invalidcourseid');
ddff2fa8 31 }
08103c93 32
dfdaabd6 33 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 34 print_error('invalidcourseid');
ddff2fa8 35 }
f3f7610c 36
ddff2fa8 37} else {
dfdaabd6 38 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 39 print_error('invalidcourseid');
ddff2fa8 40 }
41 $grouping = new object();
42 $grouping->courseid = $course->id;
c7b0485f 43}
f3f7610c 44
ddff2fa8 45require_login($course);
46$context = get_context_instance(CONTEXT_COURSE, $course->id);
47require_capability('moodle/course:managegroups', $context);
f3f7610c 48
62d63838 49$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$course->id;
ddff2fa8 50
51
52if ($id and $delete) {
53 if (!$confirm) {
b87573d7 54 $PAGE->set_title(get_string('deletegrouping', 'group'));
55 $PAGE->set_heading(get_string('deletegrouping', 'group'));
56 echo $OUTPUT->header();
ddff2fa8 57 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
58 $optionsno = array('id'=>$courseid);
768cefa0 59 $formcontinue = html_form::make_button('grouping.php', $optionsyes, get_string('yes'), 'get');
60 $formcancel = html_form::make_button('groupings.php', $optionsno, get_string('no'), 'get');
61 echo $OUTPUT->confirm(get_string('deletegroupingconfirm', 'group', $grouping->name), $formcontinue, $formcancel);
653468d4 62 echo $OUTPUT->footer();
ddff2fa8 63 die;
64
65 } else if (confirm_sesskey()){
66 if (groups_delete_grouping($id)) {
62d63838 67 redirect($returnurl);
ddff2fa8 68 } else {
69 print_error('erroreditgrouping', 'group', $returnurl);
70 }
e4596a4a 71 }
72}
73
ddff2fa8 74/// First create the form
75$editform = new grouping_form();
76$editform->set_data($grouping);
77
c7b0485f 78if ($editform->is_cancelled()) {
ddff2fa8 79 redirect($returnurl);
80
c7b0485f 81} elseif ($data = $editform->get_data()) {
82 $success = true;
ddff2fa8 83
84 if ($data->id) {
5e2f308b 85 groups_update_grouping($data);
c7b0485f 86
c7b0485f 87 } else {
5e2f308b 88 groups_create_grouping($data);
5bca3fed 89 }
ddff2fa8 90
91 redirect($returnurl);
92
f3f7610c 93}
ddff2fa8 94
5e2f308b 95$strgroupings = get_string('groupings', 'group');
ddff2fa8 96$strparticipants = get_string('participants');
97
98if ($id) {
99 $strheading = get_string('editgroupingsettings', 'group');
100} else {
101 $strheading = get_string('creategrouping', 'group');
102}
103
b87573d7 104$PAGE->navbar->add($strparticipants, new moodle_url($CFG->wwwroot.'/user/index.php', array('id'=>$courseid)));
105$PAGE->navbar->add($strgroups, new moodle_url($CFG->wwwroot.'/group/groupings.php', array('id'=>$courseid)));
106$PAGE->navbar->add($strheading);
778918fd 107
108/// Print header
b87573d7 109$PAGE->set_title($strgroupings);
110$PAGE->set_heading(': '.$strgroupings);
111echo $OUTPUT->header();
9cb990ec 112echo $OUTPUT->heading($strheading);
ddff2fa8 113$editform->display();
653468d4 114echo $OUTPUT->footer();
ddff2fa8 115
f3f7610c 116?>