3 * Create group OR edit group settings.
5 * @copyright © 2006 The Open University
6 * @author N.D.Freear AT open.ac.uk
7 * @author J.White AT open.ac.uk
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 require_once('../config.php');
13 require_once('lib.php');
14 require_once('group_form.php');
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
);
23 if (!$group = get_record('groups', 'id', $id)) {
24 error('Group ID was incorrect');
26 if (empty($courseid)) {
27 $courseid = $group->courseid
;
29 } else if ($courseid != $group->courseid
) {
30 error('Course ID was incorrect');
33 if (!$course = get_record('course', 'id', $courseid)) {
34 error('Course ID was incorrect');
38 if (!$course = get_record('course', 'id', $courseid)) {
39 error('Course ID was incorrect');
41 $group = new object();
42 $group->courseid
= $course->id
;
45 require_login($course);
46 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
47 require_capability('moodle/course:managegroups', $context);
49 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$course->id
.'&group='.$id;
51 if ($id and $delete) {
53 print_header(get_string('deleteselectedgroup', 'group'), get_string('deleteselectedgroup', 'group'));
54 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
55 $optionsno = array('id'=>$courseid);
56 notice_yesno(get_string('deletegroupconfirm', 'group', $group->name
), 'group.php', 'index.php', $optionsyes, $optionsno, 'get', 'get');
60 } else if (confirm_sesskey()){
61 if (groups_delete_group($id)) {
63 $eventdata = new object();
64 $eventdata->group
= $id;
65 $eventdata->course
= $courseid;
66 events_trigger('group_deleted', $eventdata);
67 redirect('index.php?id='.$course->id
);
69 print_error('erroreditgroup', 'group', $returnurl);
74 /// First create the form
75 $editform = new group_form();
76 $editform->set_data($group);
78 if ($editform->is_cancelled()) {
81 } elseif ($data = $editform->get_data()) {
84 if (!groups_update_group($data, $editform->_upload_manager
)) {
85 error('Error updating group');
88 if (!$id = groups_create_group($data, $editform->_upload_manager
)) {
89 error('Error updating group');
91 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$course->id
.'&group='.$id;
97 $strgroups = get_string('groups');
98 $strparticipants = get_string('participants');
101 $strheading = get_string('editgroupsettings', 'group');
103 $strheading = get_string('creategroup', 'group');
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);
113 print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
115 echo '<div id="grouppicture">';
117 print_group_picture($group, $course->id
);
120 $editform->display();
121 print_footer($course);