3 * Create grouping OR edit grouping 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
11 require_once('../config.php');
12 require_once('lib.php');
13 require_once('grouping_form.php');
16 $courseid = optional_param('courseid', 0, PARAM_INT
);
17 $id = optional_param('id', 0, PARAM_INT
);
18 $delete = optional_param('delete', 0, PARAM_BOOL
);
19 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
21 $url = new moodle_url('/group/grouping.php');
23 $url->param('id', $id);
24 if (!$grouping = $DB->get_record('groupings', array('id'=>$id))) {
25 print_error('invalidgroupid');
27 $grouping->description
= clean_text($grouping->description
);
28 if (empty($courseid)) {
29 $courseid = $grouping->courseid
;
30 } else if ($courseid != $grouping->courseid
) {
31 print_error('invalidcourseid');
33 $url->param('courseid', $courseid);
36 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
37 print_error('invalidcourseid');
41 $url->param('courseid', $courseid);
42 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
43 print_error('invalidcourseid');
45 $grouping = new stdClass();
46 $grouping->courseid
= $course->id
;
51 require_login($course);
52 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
53 require_capability('moodle/course:managegroups', $context);
55 $returnurl = $CFG->wwwroot
.'/group/groupings.php?id='.$course->id
;
58 if ($id and $delete) {
60 $PAGE->set_title(get_string('deletegrouping', 'group'));
61 $PAGE->set_heading($course->fullname
. ': '. get_string('deletegrouping', 'group'));
62 echo $OUTPUT->header();
63 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
64 $optionsno = array('id'=>$courseid);
65 $formcontinue = new single_button(new moodle_url('grouping.php', $optionsyes), get_string('yes'), 'get');
66 $formcancel = new single_button(new moodle_url('groupings.php', $optionsno), get_string('no'), 'get');
67 echo $OUTPUT->confirm(get_string('deletegroupingconfirm', 'group', $grouping->name
), $formcontinue, $formcancel);
68 echo $OUTPUT->footer();
71 } else if (confirm_sesskey()){
72 if (groups_delete_grouping($id)) {
75 print_error('erroreditgrouping', 'group', $returnurl);
80 // Prepare the description editor: We do support files for grouping descriptions
81 $editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES
, 'maxbytes'=>$course->maxbytes
, 'trust'=>true, 'context'=>$context, 'noclean'=>true);
82 if (!empty($grouping->id
)) {
83 $grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'grouping', 'description', $grouping->id
);
85 $grouping = file_prepare_standard_editor($grouping, 'description', $editoroptions, $context, 'grouping', 'description', null);
88 /// First create the form
89 $editform = new grouping_form(null, compact('editoroptions'));
90 $editform->set_data($grouping);
92 if ($editform->is_cancelled()) {
95 } elseif ($data = $editform->get_data()) {
99 groups_update_grouping($data, $editoroptions);
101 groups_create_grouping($data, $editoroptions);
104 redirect($returnurl);
108 $strgroupings = get_string('groupings', 'group');
109 $strparticipants = get_string('participants');
112 $strheading = get_string('editgroupingsettings', 'group');
114 $strheading = get_string('creategrouping', 'group');
117 $PAGE->navbar
->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
118 $PAGE->navbar
->add($strgroupings, new moodle_url('/group/groupings.php', array('id'=>$courseid)));
119 $PAGE->navbar
->add($strheading);
122 $PAGE->set_title($strgroupings);
123 $PAGE->set_heading($course->fullname
. ': '.$strgroupings);
124 echo $OUTPUT->header();
125 echo $OUTPUT->heading($strheading);
126 $editform->display();
127 echo $OUTPUT->footer();