lesson MDL-19812 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) {
60 print_header(get_string('deleteselectedgroup', 'group'), get_string('deleteselectedgroup', 'group'));
61 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
62 $optionsno = array('id'=>$courseid);
768cefa0 63 $formcontinue = html_form::make_button('group.php', $optionsyes, get_string('yes'), 'get');
64 $formcancel = html_form::make_button($baseurl, $optionsno, get_string('no'), 'get');
65 echo $OUTPUT->confirm(get_string('deletegroupconfirm', 'group', $group->name), $formcontinue, $formcancel);
653468d4 66 echo $OUTPUT->footer();
2524b0f2 67 die;
77e90955 68
2524b0f2 69 } else if (confirm_sesskey()){
70 if (groups_delete_group($id)) {
2524b0f2 71 redirect('index.php?id='.$course->id);
72 } else {
c4e953e6 73 print_error('erroreditgroup', 'group', $returnurl);
2524b0f2 74 }
e4596a4a 75 }
76}
77
2524b0f2 78/// First create the form
ddff2fa8 79$editform = new group_form();
2524b0f2 80$editform->set_data($group);
e4596a4a 81
77e90955 82if ($editform->is_cancelled()) {
2524b0f2 83 redirect($returnurl);
84
77e90955 85} elseif ($data = $editform->get_data()) {
2524b0f2 86
2524b0f2 87 if ($data->id) {
5e2f308b 88 groups_update_group($data, $editform);
2524b0f2 89 } else {
5e2f308b 90 $id = groups_create_group($data, $editform);
778918fd 91 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
77e90955 92 }
77e90955 93
2524b0f2 94 redirect($returnurl);
95}
96
e4596a4a 97$strgroups = get_string('groups');
98$strparticipants = get_string('participants');
99
100if ($id) {
101 $strheading = get_string('editgroupsettings', 'group');
102} else {
103 $strheading = get_string('creategroup', 'group');
104}
778918fd 105
106
107$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
108 array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'),
109 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
110$navigation = build_navigation($navlinks);
111
112/// Print header
113print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
e4596a4a 114
e4596a4a 115echo '<div id="grouppicture">';
116if ($id) {
117 print_group_picture($group, $course->id);
77e90955 118}
e4596a4a 119echo '</div>';
120$editform->display();
653468d4 121echo $OUTPUT->footer();
77e90955 122?>