forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrouping.php
117 lines (93 loc) · 3.42 KB
/
grouping.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Create grouping OR edit grouping settings.
*
* @copyright © 2006 The Open University
* @author N.D.Freear AT open.ac.uk
* @author J.White AT open.ac.uk
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package groups
*/
require_once('../config.php');
require_once('lib.php');
require_once('grouping_form.php');
/// get url variables
$courseid = optional_param('courseid', 0, PARAM_INT);
$id = optional_param('id', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_BOOL);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
if ($id) {
if (!$grouping = $DB->get_record('groupings', array('id'=>$id))) {
print_error('invalidgroupid');
}
$grouping->description = clean_text($grouping->description);
if (empty($courseid)) {
$courseid = $grouping->courseid;
} else if ($courseid != $grouping->courseid) {
print_error('invalidcourseid');
}
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('invalidcourseid');
}
} else {
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('invalidcourseid');
}
$grouping = new object();
$grouping->courseid = $course->id;
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:managegroups', $context);
$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$course->id;
if ($id and $delete) {
if (!$confirm) {
print_header(get_string('deletegrouping', 'group'), get_string('deletegrouping', 'group'));
$optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
$optionsno = array('id'=>$courseid);
notice_yesno(get_string('deletegroupingconfirm', 'group', $grouping->name), 'grouping.php', 'groupings.php', $optionsyes, $optionsno, 'get', 'get');
print_footer();
die;
} else if (confirm_sesskey()){
if (groups_delete_grouping($id)) {
redirect($returnurl);
} else {
print_error('erroreditgrouping', 'group', $returnurl);
}
}
}
/// First create the form
$editform = new grouping_form();
$editform->set_data($grouping);
if ($editform->is_cancelled()) {
redirect($returnurl);
} elseif ($data = $editform->get_data()) {
$success = true;
if ($data->id) {
if (!groups_update_grouping($data)) {
print_error('cannotupdategroup');
}
} else {
if (!groups_create_grouping($data)) {
print_error('cannotcreategroup');
}
}
redirect($returnurl);
}
$strgroupings = get_string('groupings', 'group');
$strparticipants = get_string('participants');
if ($id) {
$strheading = get_string('editgroupingsettings', 'group');
} else {
$strheading = get_string('creategrouping', 'group');
}
$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
array('name'=>$strgroupings, 'link'=>$CFG->wwwroot.'/group/groupings.php?id='.$courseid, 'type'=>'misc'),
array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
$navigation = build_navigation($navlinks);
/// Print header
print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
print_heading($strheading);
$editform->display();
print_footer($course);
?>