"MDL-15251, see tracker"
[moodle-linuxchix.git] / group / grouping.php
blobd1bde1beb2e414ea4ebd49097fdee59cbfbe9f38
1 <?php
2 /**
3 * Create grouping OR edit grouping 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
11 require_once('../config.php');
12 require_once('lib.php');
13 require_once('grouping_form.php');
15 /// get url variables
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 if ($id) {
22 if (!$grouping = get_record('groupings', 'id', $id)) {
23 error('Group ID was incorrect');
25 $grouping->description = clean_text($grouping->description);
26 if (empty($courseid)) {
27 $courseid = $grouping->courseid;
29 } else if ($courseid != $grouping->courseid) {
30 error('Course ID was incorrect');
33 if (!$course = get_record('course', 'id', $courseid)) {
34 error('Course ID was incorrect');
37 } else {
38 if (!$course = get_record('course', 'id', $courseid)) {
39 error('Course ID was incorrect');
41 $grouping = new object();
42 $grouping->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/groupings.php?id='.$course->id;
52 if ($id and $delete) {
53 if (!$confirm) {
54 print_header(get_string('deletegrouping', 'group'), get_string('deletegrouping', 'group'));
55 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
56 $optionsno = array('id'=>$courseid);
57 notice_yesno(get_string('deletegroupingconfirm', 'group', $grouping->name), 'grouping.php', 'groupings.php', $optionsyes, $optionsno, 'get', 'get');
58 print_footer();
59 die;
61 } else if (confirm_sesskey()){
62 if (groups_delete_grouping($id)) {
63 // MDL-9983
64 $eventdata = new object();
65 $eventdata->group = $id;
66 $eventdata->course = $courseid;
67 events_trigger('grouping_deleted', $eventdata);
68 redirect($returnurl);
69 } else {
70 print_error('erroreditgrouping', 'group', $returnurl);
75 /// First create the form
76 $editform = new grouping_form();
77 $editform->set_data($grouping);
79 if ($editform->is_cancelled()) {
80 redirect($returnurl);
82 } elseif ($data = $editform->get_data()) {
83 $success = true;
85 if ($data->id) {
86 if (!groups_update_grouping($data)) {
87 error('Error updating grouping');
90 } else {
91 if (!groups_create_grouping($data)) {
92 error('Error creating grouping');
96 redirect($returnurl);
100 $strgroupings = get_string('groupings', 'group');
101 $strparticipants = get_string('participants');
103 if ($id) {
104 $strheading = get_string('editgroupingsettings', 'group');
105 } else {
106 $strheading = get_string('creategrouping', 'group');
109 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
110 array('name'=>$strgroupings, 'link'=>$CFG->wwwroot.'/group/groupings.php?id='.$courseid, 'type'=>'misc'),
111 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
112 $navigation = build_navigation($navlinks);
114 /// Print header
115 print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
118 print_heading($strheading);
119 $editform->display();
120 print_footer($course);