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 $group->description
= clean_text($group->description
);
27 if (empty($courseid)) {
28 $courseid = $group->courseid
;
30 } else if ($courseid != $group->courseid
) {
31 error('Course ID was incorrect');
34 if (!$course = get_record('course', 'id', $courseid)) {
35 error('Course ID was incorrect');
39 if (!$course = get_record('course', 'id', $courseid)) {
40 error('Course ID was incorrect');
42 $group = new object();
43 $group->courseid
= $course->id
;
46 require_login($course);
47 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
48 require_capability('moodle/course:managegroups', $context);
50 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$course->id
.'&group='.$id;
52 if ($id and $delete) {
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);
57 notice_yesno(get_string('deletegroupconfirm', 'group', $group->name
), 'group.php', 'index.php', $optionsyes, $optionsno, 'get', 'get');
61 } else if (confirm_sesskey()){
62 if (groups_delete_group($id)) {
64 $eventdata = new object();
65 $eventdata->group
= $id;
66 $eventdata->course
= $courseid;
67 events_trigger('group_deleted', $eventdata);
68 redirect('index.php?id='.$course->id
);
70 print_error('erroreditgroup', 'group', $returnurl);
75 /// First create the form
76 $editform = new group_form();
77 $editform->set_data($group);
79 if ($editform->is_cancelled()) {
82 } elseif ($data = $editform->get_data()) {
85 if (!groups_update_group($data, $editform->_upload_manager
)) {
86 error('Error updating group');
89 if (!$id = groups_create_group($data, $editform->_upload_manager
)) {
90 error('Error creating group');
92 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$course->id
.'&group='.$id;
98 $strgroups = get_string('groups');
99 $strparticipants = get_string('participants');
102 $strheading = get_string('editgroupsettings', 'group');
104 $strheading = get_string('creategroup', 'group');
108 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot
.'/user/index.php?id='.$courseid, 'type'=>'misc'),
109 array('name'=>$strgroups, 'link'=>$CFG->wwwroot
.'/group/index.php?id='.$courseid, 'type'=>'misc'),
110 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
111 $navigation = build_navigation($navlinks);
114 print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
116 echo '<div id="grouppicture">';
118 print_group_picture($group, $course->id
);
121 $editform->display();
122 print_footer($course);