Merge branch 'w43_MDL-29964_m22_fixenrolevents' of git://github.com/skodak/moodle
[moodle.git] / group / group.php
blobe35c2289b925245cda185da0f51d9ac8171091e3
1 <?php
2 /**
3 * Create group OR edit group settings.
5 * @copyright &copy; 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
9 * @package groups
12 require_once('../config.php');
13 require_once('lib.php');
14 require_once('group_form.php');
16 /// get url variables
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.
24 if($delete) {
25 redirect('delete.php?courseid='.$courseid.'&groups='.$id);
28 if ($id) {
29 if (!$group = $DB->get_record('groups', array('id'=>$id))) {
30 print_error('invalidgroupid');
32 if (empty($courseid)) {
33 $courseid = $group->courseid;
35 } else if ($courseid != $group->courseid) {
36 print_error('invalidcourseid');
39 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
40 print_error('invalidcourseid');
43 } else {
44 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
45 print_error('invalidcourseid');
47 $group = new stdClass();
48 $group->courseid = $course->id;
51 if ($id !== 0) {
52 $PAGE->set_url('/group/group.php', array('id'=>$id));
53 } else {
54 $PAGE->set_url('/group/group.php', array('courseid'=>$courseid));
57 require_login($course);
58 $context = get_context_instance(CONTEXT_COURSE, $course->id);
59 require_capability('moodle/course:managegroups', $context);
61 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
63 if ($id and $delete) {
64 if (!$confirm) {
65 $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
66 $PAGE->set_heading($course->fullname . ': '. get_string('deleteselectedgroup', 'group'));
67 echo $OUTPUT->header();
68 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
69 $optionsno = array('id'=>$courseid);
70 $formcontinue = new single_button(new moodle_url('group.php', $optionsyes), get_string('yes'), 'get');
71 $formcancel = new single_button(new moodle_url($baseurl, $optionsno), get_string('no'), 'get');
72 echo $OUTPUT->confirm(get_string('deletegroupconfirm', 'group', $group->name), $formcontinue, $formcancel);
73 echo $OUTPUT->footer();
74 die;
76 } else if (confirm_sesskey()){
77 if (groups_delete_group($id)) {
78 redirect('index.php?id='.$course->id);
79 } else {
80 print_error('erroreditgroup', 'group', $returnurl);
85 // Prepare the description editor: We do support files for group descriptions
86 $editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>false, 'context'=>$context, 'noclean'=>true);
87 if (!empty($group->id)) {
88 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', $group->id);
89 } else {
90 $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', null);
93 /// First create the form
94 $editform = new group_form(null, array('editoroptions'=>$editoroptions));
95 $editform->set_data($group);
97 if ($editform->is_cancelled()) {
98 redirect($returnurl);
100 } elseif ($data = $editform->get_data()) {
102 if ($data->id) {
103 groups_update_group($data, $editform, $editoroptions);
104 } else {
105 $id = groups_create_group($data, $editform, $editoroptions);
106 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
109 redirect($returnurl);
112 $strgroups = get_string('groups');
113 $strparticipants = get_string('participants');
115 if ($id) {
116 $strheading = get_string('editgroupsettings', 'group');
117 } else {
118 $strheading = get_string('creategroup', 'group');
121 $PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
122 $PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$courseid)));
123 $PAGE->navbar->add($strheading);
125 /// Print header
126 $PAGE->set_title($strgroups);
127 $PAGE->set_heading($course->fullname . ': '.$strgroups);
128 echo $OUTPUT->header();
129 echo '<div id="grouppicture">';
130 if ($id) {
131 print_group_picture($group, $course->id);
133 echo '</div>';
134 $editform->display();
135 echo $OUTPUT->footer();