xhtml validation fixes for MDL-8425
[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;
b1f627d9 28 print_error('invalidcourse'); //'The course ID is invalid'
29}
30if (GROUP_NOT_IN_GROUPING == $groupingid) {
31 print_error('errornotingroupingedit', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
f3f7610c
ML
32}
33
34if ($success) {
35 // Make sure that the user has permissions to manage groups.
36 require_login($courseid);
37
38 $context = get_context_instance(CONTEXT_COURSE, $courseid);
39 if (! has_capability('moodle/course:managegroups', $context)) {
40 redirect();
41 }
42
43/// If data submitted, then process and store.
44
45 if ($frm = data_submitted() and confirm_sesskey()) {
46
47 if (isset($frm->cancel)) {
48 redirect(groups_home_url($courseid, null, $groupingid, false));
49 }
50 elseif (empty($frm->name)) {
51 $err['name'] = get_string('missingname');
52 }
53 elseif (isset($frm->update)) {
54
55 if ($groupingid) {
56 $success = (bool)groups_set_grouping_settings($groupingid, $groupingsettings);
57 }
58 else {
59 $success = (bool)$groupingid = groups_create_grouping($courseid, $groupingsettings);
60 }
61 if ($success) {
62 redirect(groups_home_url($courseid, null, $groupingid, false));
63 }
64 else {
b1f627d9 65 print_error('erroreditgroup', 'group', groups_home_url($courseid));
f3f7610c
ML
66 }
67 }
68 }
69
70/// OR, prepare the form.
71
72 if ($groupingid) {
73 // Form to edit existing grouping.
74 $grouping = groups_get_grouping_settings($groupingid);
75 if (! $grouping) {
76 print_error('errorinvalidgrouping', 'group', groups_home_url($courseid));
77 }
78 $strname = s($grouping->name);
79 $strdesc = s($grouping->description);
80
81 $strbutton = get_string('save', 'group');
82 $strheading = get_string('editgroupingsettings', 'group');
83 } else {
84 // Form to create a new one.
85 $strname = get_string('defaultgroupingname', 'group');
86 $strdesc = '';
87 $strbutton = $strheading = get_string('creategrouping', 'group');
88 }
89 $strgroups = get_string('groups');
90 $strparticipants = get_string('participants');
91
92/// Print the page and form
93
94 print_header("$course->shortname: $strgroups",
95 "$course->fullname",
96 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
97 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
98 "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
99
100 $usehtmleditor = false;
101?>
102<h3 class="main"><?php echo $strheading ?></h3>
103
104<form action="grouping.php" method="post" class="mform notmform" id="groupingform">
105<input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
106<input type="hidden" name="courseid" value="<?php p($courseid); ?>" />
107<?php
108 if ($groupingid) {
109 echo '<input type="hidden" name="grouping" value="'. $groupingid .'" />';
110 }
111?>
112
113<div class="f-item">
114<p><label for="groupingname"><?php print_string('groupingname', 'group'); ?>&nbsp;</label></p>
115<p><input id="groupingname" name="name" type="text" size="40" value="<?php echo $strname; ?>" /></p>
116</div>
117
118<p><label for="edit-description"><?php print_string('groupingdescription', 'group'); ?>&nbsp;</label></p>
119<p><?php print_textarea($usehtmleditor, 5, 45, 200, 400, 'description', $strdesc); ?></p>
120
b1f627d9 121<?php /* TODO:
122<fieldset>
123 <legend><?php print_string('editgroupingpermissions', 'group'); ?></legend>
124 <ol class="unlist para">
125 <li><label><input type="checkbox" id="perm_viewowngroup" checked="checked" /> <?php print_string('viewowngroup', 'group'); ?></label></li>
126 <li><label><input type="checkbox" id="perm_viewallgroupsmembers" checked="checked" /> <?php print_string('viewallgroupsmembers', 'group'); ?></label></li>
127 <li><label><input type="checkbox" id="perm_viewallgroupsactivities" checked="checked" /> <?php print_string('viewallgroupsactivities', 'group'); ?></label></li>
128 <li><label><input type="checkbox" id="perm_teachersgroupmark" /> <?php print_string('teachersgroupmark', 'group'); ?></label></li>
129 <li><label><input type="checkbox" id="perm_teachersgroupview" /> <?php print_string('teachersgroupview', 'group'); ?></label></li>
130 <li><label><input type="checkbox" id="perm_teachersoverride" /> <?php print_string('teachersoverride', 'group'); ?></label></li>
131 </ol>
132</fieldset>
133*/ ?>
134
f3f7610c
ML
135<p class="fitem">
136 <label for="id_submit">&nbsp;</label>
137 <span class="f-element fsubmit">
138 <input type="submit" name="update" id="id_submit" value="<?php echo $strbutton; ?>" />
139 <input type="submit" name="cancel" value="<?php print_string('cancel', 'group'); ?>" />
140 </span>
141</p>
142<span class="clearer">&nbsp;</span>
143
144</form>
145<?php
146 print_footer($course);
147}
148
149?>