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
);
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.
25 redirect('delete.php?courseid='.$courseid.'&groups='.$id);
29 if (!$group = get_record('groups', 'id', $id)) {
30 error('Group ID was incorrect');
32 $group->description
= clean_text($group->description
);
33 if (empty($courseid)) {
34 $courseid = $group->courseid
;
36 } else if ($courseid != $group->courseid
) {
37 error('Course ID was incorrect');
40 if (!$course = get_record('course', 'id', $courseid)) {
41 error('Course ID was incorrect');
45 if (!$course = get_record('course', 'id', $courseid)) {
46 error('Course ID was incorrect');
48 $group = new object();
49 $group->courseid
= $course->id
;
52 require_login($course);
53 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
54 require_capability('moodle/course:managegroups', $context);
56 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$course->id
.'&group='.$id;
58 if ($id and $delete) {
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);
63 notice_yesno(get_string('deletegroupconfirm', 'group', $group->name
), 'group.php', 'index.php', $optionsyes, $optionsno, 'get', 'get');
67 } else if (confirm_sesskey()){
68 if (groups_delete_group($id)) {
69 redirect('index.php?id='.$course->id
);
71 print_error('erroreditgroup', 'group', $returnurl);
76 /// First create the form
77 $editform = new group_form();
78 $editform->set_data($group);
80 if ($editform->is_cancelled()) {
83 } elseif ($data = $editform->get_data()) {
86 if (!groups_update_group($data, $editform->_upload_manager
)) {
87 error('Error updating group');
90 if (!$id = groups_create_group($data, $editform->_upload_manager
)) {
91 error('Error creating group');
93 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$course->id
.'&group='.$id;
99 $strgroups = get_string('groups');
100 $strparticipants = get_string('participants');
103 $strheading = get_string('editgroupsettings', 'group');
105 $strheading = get_string('creategroup', 'group');
109 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot
.'/user/index.php?id='.$courseid, 'type'=>'misc'),
110 array('name'=>$strgroups, 'link'=>$CFG->wwwroot
.'/group/index.php?id='.$courseid, 'type'=>'misc'),
111 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
112 $navigation = build_navigation($navlinks);
115 print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
117 echo '<div id="grouppicture">';
119 print_group_picture($group, $course->id
);
122 $editform->display();
123 print_footer($course);