group MDL-19798 Updated print_header and build_navigation to OUTPUT and PAGE equivalents
[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 }
3980c306 32 $group->description = clean_text($group->description);
c4e953e6 33 if (empty($courseid)) {
34 $courseid = $group->courseid;
35
36 } else if ($courseid != $group->courseid) {
b121a4ee 37 print_error('invalidcourseid');
2524b0f2 38 }
c4e953e6 39
dfdaabd6 40 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 41 print_error('invalidcourseid');
c4e953e6 42 }
43
2524b0f2 44} else {
dfdaabd6 45 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 46 print_error('invalidcourseid');
c4e953e6 47 }
2524b0f2 48 $group = new object();
c4e953e6 49 $group->courseid = $course->id;
77e90955 50}
51
ddff2fa8 52require_login($course);
c4e953e6 53$context = get_context_instance(CONTEXT_COURSE, $course->id);
54require_capability('moodle/course:managegroups', $context);
55
56$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
77e90955 57
c4e953e6 58if ($id and $delete) {
2524b0f2 59 if (!$confirm) {
b87573d7 60 $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
61 $PAGE->set_heading(get_string('deleteselectedgroup', 'group'));
62 echo $OUTPUT->header();
2524b0f2 63 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
64 $optionsno = array('id'=>$courseid);
768cefa0 65 $formcontinue = html_form::make_button('group.php', $optionsyes, get_string('yes'), 'get');
66 $formcancel = html_form::make_button($baseurl, $optionsno, get_string('no'), 'get');
67 echo $OUTPUT->confirm(get_string('deletegroupconfirm', 'group', $group->name), $formcontinue, $formcancel);
653468d4 68 echo $OUTPUT->footer();
2524b0f2 69 die;
77e90955 70
2524b0f2 71 } else if (confirm_sesskey()){
72 if (groups_delete_group($id)) {
2524b0f2 73 redirect('index.php?id='.$course->id);
74 } else {
c4e953e6 75 print_error('erroreditgroup', 'group', $returnurl);
2524b0f2 76 }
e4596a4a 77 }
78}
79
2524b0f2 80/// First create the form
ddff2fa8 81$editform = new group_form();
2524b0f2 82$editform->set_data($group);
e4596a4a 83
77e90955 84if ($editform->is_cancelled()) {
2524b0f2 85 redirect($returnurl);
86
77e90955 87} elseif ($data = $editform->get_data()) {
2524b0f2 88
2524b0f2 89 if ($data->id) {
5e2f308b 90 groups_update_group($data, $editform);
2524b0f2 91 } else {
5e2f308b 92 $id = groups_create_group($data, $editform);
778918fd 93 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
77e90955 94 }
77e90955 95
2524b0f2 96 redirect($returnurl);
97}
98
e4596a4a 99$strgroups = get_string('groups');
100$strparticipants = get_string('participants');
101
102if ($id) {
103 $strheading = get_string('editgroupsettings', 'group');
104} else {
105 $strheading = get_string('creategroup', 'group');
106}
778918fd 107
b87573d7 108$PAGE->navbar->add($strparticipants, new moodle_url($CFG->wwwroot.'/user/index.php', array('id'=>$courseid)));
109$PAGE->navbar->add($strgroups, new moodle_url($CFG->wwwroot.'/group/index.php', array('id'=>$courseid)));
110$PAGE->navbar->add($strheading);
778918fd 111
112/// Print header
b87573d7 113$PAGE->set_title($strgroups);
114$PAGE->set_heading(': '.$strgroups);
115echo $OUTPUT->header();
e4596a4a 116echo '<div id="grouppicture">';
117if ($id) {
118 print_group_picture($group, $course->id);
77e90955 119}
e4596a4a 120echo '</div>';
121$editform->display();
653468d4 122echo $OUTPUT->footer();
77e90955 123?>