cvsimport fixups -- cvshead had strayed from upstream
[moodle.git] / group / grouping.php
CommitLineData
f3f7610c
ML
1<?php
2/**
3 * Create grouping OR edit grouping settings.
4 *
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
10 */
11require_once('../config.php');
12require_once('lib.php');
13require_once($CFG->libdir.'/moodlelib.php');
14
15$success = true;
16
17$courseid = required_param('courseid', PARAM_INT);
18$groupingid = optional_param('grouping', false, PARAM_INT);
19
20$groupingsettings->name = optional_param('name', PARAM_ALPHANUM);
21$groupingsettings->description= optional_param('description', PARAM_ALPHANUM);
22
23// Get the course information so we can print the header and
24// check the course id is valid
25$course = groups_get_course_info($courseid);
26if (! $course) {
27 $success = false;
28 print_error('The course ID is invalid');
29}
30
31if ($success) {
32 // Make sure that the user has permissions to manage groups.
33 require_login($courseid);
34
35 $context = get_context_instance(CONTEXT_COURSE, $courseid);
36 if (! has_capability('moodle/course:managegroups', $context)) {
37 redirect();
38 }
39
40/// If data submitted, then process and store.
41
42 if ($frm = data_submitted() and confirm_sesskey()) {
43
44 if (isset($frm->cancel)) {
45 redirect(groups_home_url($courseid, null, $groupingid, false));
46 }
47 elseif (empty($frm->name)) {
48 $err['name'] = get_string('missingname');
49 }
50 elseif (isset($frm->update)) {
51
52 if ($groupingid) {
53 $success = (bool)groups_set_grouping_settings($groupingid, $groupingsettings);
54 }
55 else {
56 $success = (bool)$groupingid = groups_create_grouping($courseid, $groupingsettings);
57 }
58 if ($success) {
59 redirect(groups_home_url($courseid, null, $groupingid, false));
60 }
61 else {
62 print_error('Error creating/updating grouping.');
63 }
64 }
65 }
66
67/// OR, prepare the form.
68
69 if ($groupingid) {
70 // Form to edit existing grouping.
71 $grouping = groups_get_grouping_settings($groupingid);
72 if (! $grouping) {
73 print_error('errorinvalidgrouping', 'group', groups_home_url($courseid));
74 }
75 $strname = s($grouping->name);
76 $strdesc = s($grouping->description);
77
78 $strbutton = get_string('save', 'group');
79 $strheading = get_string('editgroupingsettings', 'group');
80 } else {
81 // Form to create a new one.
82 $strname = get_string('defaultgroupingname', 'group');
83 $strdesc = '';
84 $strbutton = $strheading = get_string('creategrouping', 'group');
85 }
86 $strgroups = get_string('groups');
87 $strparticipants = get_string('participants');
88
89/// Print the page and form
90
91 print_header("$course->shortname: $strgroups",
92 "$course->fullname",
93 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
94 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
95 "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
96
97 $usehtmleditor = false;
98?>
99<h3 class="main"><?php echo $strheading ?></h3>
100
101<form action="grouping.php" method="post" class="mform notmform" id="groupingform">
102<input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
103<input type="hidden" name="courseid" value="<?php p($courseid); ?>" />
104<?php
105 if ($groupingid) {
106 echo '<input type="hidden" name="grouping" value="'. $groupingid .'" />';
107 }
108?>
109
110<div class="f-item">
111<p><label for="groupingname"><?php print_string('groupingname', 'group'); ?>&nbsp;</label></p>
112<p><input id="groupingname" name="name" type="text" size="40" value="<?php echo $strname; ?>" /></p>
113</div>
114
115<p><label for="edit-description"><?php print_string('groupingdescription', 'group'); ?>&nbsp;</label></p>
116<p><?php print_textarea($usehtmleditor, 5, 45, 200, 400, 'description', $strdesc); ?></p>
117
118<p class="fitem">
119 <label for="id_submit">&nbsp;</label>
120 <span class="f-element fsubmit">
121 <input type="submit" name="update" id="id_submit" value="<?php echo $strbutton; ?>" />
122 <input type="submit" name="cancel" value="<?php print_string('cancel', 'group'); ?>" />
123 </span>
124</p>
125<span class="clearer">&nbsp;</span>
126
127</form>
128<?php
129 print_footer($course);
130}
131
132?>