MDL-15498 Minor display bug with completion progress report
[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
80efbf98 22if ($id) {
dfdaabd6 23 if (!$group = $DB->get_record('groups', array('id'=>$id))) {
b121a4ee 24 print_error('invalidgroupid');
2524b0f2 25 }
3980c306 26 $group->description = clean_text($group->description);
c4e953e6 27 if (empty($courseid)) {
28 $courseid = $group->courseid;
29
30 } else if ($courseid != $group->courseid) {
b121a4ee 31 print_error('invalidcourseid');
2524b0f2 32 }
c4e953e6 33
dfdaabd6 34 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 35 print_error('invalidcourseid');
c4e953e6 36 }
37
2524b0f2 38} else {
dfdaabd6 39 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
b121a4ee 40 print_error('invalidcourseid');
c4e953e6 41 }
2524b0f2 42 $group = new object();
c4e953e6 43 $group->courseid = $course->id;
77e90955 44}
45
ddff2fa8 46require_login($course);
c4e953e6 47$context = get_context_instance(CONTEXT_COURSE, $course->id);
48require_capability('moodle/course:managegroups', $context);
49
50$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
77e90955 51
c4e953e6 52if ($id and $delete) {
2524b0f2 53 if (!$confirm) {
54 print_header(get_string('deleteselectedgroup', 'group'), get_string('deleteselectedgroup', 'group'));
55 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
56 $optionsno = array('id'=>$courseid);
c4e953e6 57 notice_yesno(get_string('deletegroupconfirm', 'group', $group->name), 'group.php', 'index.php', $optionsyes, $optionsno, 'get', 'get');
2524b0f2 58 print_footer();
59 die;
77e90955 60
2524b0f2 61 } else if (confirm_sesskey()){
62 if (groups_delete_group($id)) {
2524b0f2 63 redirect('index.php?id='.$course->id);
64 } else {
c4e953e6 65 print_error('erroreditgroup', 'group', $returnurl);
2524b0f2 66 }
e4596a4a 67 }
68}
69
2524b0f2 70/// First create the form
ddff2fa8 71$editform = new group_form();
2524b0f2 72$editform->set_data($group);
e4596a4a 73
77e90955 74if ($editform->is_cancelled()) {
2524b0f2 75 redirect($returnurl);
76
77e90955 77} elseif ($data = $editform->get_data()) {
2524b0f2 78
2524b0f2 79 if ($data->id) {
172dd12c 80 if (!groups_update_group($data, $editform)) {
b121a4ee 81 print_error('cannotupdategroup');
77e90955 82 }
2524b0f2 83 } else {
172dd12c 84 if (!$id = groups_create_group($data, $editform)) {
b121a4ee 85 print_error('cannotcreategroup');
e5138261 86 }
778918fd 87 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
77e90955 88 }
77e90955 89
2524b0f2 90 redirect($returnurl);
91}
92
e4596a4a 93$strgroups = get_string('groups');
94$strparticipants = get_string('participants');
95
96if ($id) {
97 $strheading = get_string('editgroupsettings', 'group');
98} else {
99 $strheading = get_string('creategroup', 'group');
100}
778918fd 101
102
103$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
104 array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'),
105 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
106$navigation = build_navigation($navlinks);
107
108/// Print header
109print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
e4596a4a 110
e4596a4a 111echo '<div id="grouppicture">';
112if ($id) {
113 print_group_picture($group, $course->id);
77e90955 114}
e4596a4a 115echo '</div>';
116$editform->display();
117print_footer($course);
77e90955 118?>