Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / group / grouping.php
blob04324eb882adb412935ff896fa17e486e199ffa7
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($CFG->libdir.'/moodlelib.php');
14 require_once('grouping_edit_form.php');
16 $courseid = required_param('courseid', PARAM_INT);
17 $id = optional_param('id', false, PARAM_INT);
19 $delete = optional_param('delete', false, PARAM_BOOL);
21 if (empty($CFG->enablegroupings)) {
22 // NO GROUPIGS YET!
23 error('No groupings yet');
26 // Get the course information so we can print the header and
27 // check the course id is valid
28 $course = groups_get_course_info($courseid);
29 if (! $course) {
30 $success = false;
31 print_error('invalidcourse'); //'The course ID is invalid'
33 if (GROUP_NOT_IN_GROUPING == $id) {
34 print_error('errornotingroupingedit', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
37 /// basic access control checks
38 if ($id) {
39 if (!$grouping = get_record('groups_groupings', 'id', $id)) {
40 error('Grouping ID was incorrect');
42 $context = get_context_instance(CONTEXT_COURSE, $course->id);
43 require_capability('moodle/course:managegroups', $context);
46 /// First create the form
47 $editform = new grouping_edit_form('grouping.php', compact('grouping', 'courseid'));
49 /// Override defaults if group is set
50 if (!empty($grouping)) {
51 $editform->set_data($grouping);
54 // preprocess data
55 if ($delete) {
56 if (groups_delete_grouping($id)) {
57 redirect(groups_home_url($course->id));
58 } else {
59 print_error('erroreditgrouping', 'group', groups_home_url($course->id));
63 if ($editform->is_cancelled()) {
64 redirect(groups_home_url($courseid, false, $id, false));
65 } elseif ($data = $editform->get_data()) {
66 $success = true;
68 if (empty($grouping)) { // New grouping
69 if (!$id = groups_create_grouping($course->id, $data)) {
70 print_error('erroreditgrouping');
71 } else {
72 $success = (bool)$id;
73 $data->id = $id;
75 } else { // Updating grouping
76 if (!groups_update_grouping($data, $course->id)) {
77 print_error('groupingnotupdated');
81 if ($success) {
82 redirect(groups_home_url($courseid, false, $id, false));
83 } else {
84 print_error('erroreditgrouping', 'group', groups_home_url($courseid));
87 } else { // Prepare and output form
88 $strgroups = get_string('groups');
89 $strparticipants = get_string('participants');
91 if ($id) {
92 $strheading = get_string('editgroupingsettings', 'group');
93 } else {
94 $strheading = get_string('creategrouping', 'group');
96 print_header("$course->shortname: ". $strheading,
97 $course->fullname,
98 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
99 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
100 '-> <a href="' .format_string(groups_home_url($courseid, false, $id, false)) . "\">$strgroups</a>".
101 "-> $strheading", '', '', true, '', user_login_string($course, $USER));
102 print_heading($strheading);
103 $editform->display();
104 print_footer($course);