fix the display of the special chars keypad (in JCloze and JQuiz)
[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
8834b12a 20$groupingsettings->name = optional_param('name', false, PARAM_TEXT);
21$groupingsettings->description= optional_param('description', '', PARAM_TEXT);
f3f7610c 22
5bca3fed 23$delete = optional_param('delete', false, PARAM_BOOL);
24
f3f7610c
ML
25// Get the course information so we can print the header and
26// check the course id is valid
27$course = groups_get_course_info($courseid);
28if (! $course) {
29 $success = false;
b1f627d9 30 print_error('invalidcourse'); //'The course ID is invalid'
31}
32if (GROUP_NOT_IN_GROUPING == $groupingid) {
33 print_error('errornotingroupingedit', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
f3f7610c
ML
34}
35
36if ($success) {
37 // Make sure that the user has permissions to manage groups.
38 require_login($courseid);
39
40 $context = get_context_instance(CONTEXT_COURSE, $courseid);
41 if (! has_capability('moodle/course:managegroups', $context)) {
42 redirect();
43 }
44
45/// If data submitted, then process and store.
46
47 if ($frm = data_submitted() and confirm_sesskey()) {
48
49 if (isset($frm->cancel)) {
50 redirect(groups_home_url($courseid, null, $groupingid, false));
51 }
5bca3fed 52 elseif (isset($frm->confirmdelete)) {
53 if ($success = groups_delete_grouping($groupingid)) {
54 redirect(groups_home_url($courseid));
55 } else {
56 print_error('erroreditgrouping', 'group', groups_home_url($courseid));
57 }
58 }
f3f7610c
ML
59 elseif (empty($frm->name)) {
60 $err['name'] = get_string('missingname');
61 }
62 elseif (isset($frm->update)) {
63
64 if ($groupingid) {
65 $success = (bool)groups_set_grouping_settings($groupingid, $groupingsettings);
66 }
8834b12a 67 else { //OK, new group.
f3f7610c
ML
68 $success = (bool)$groupingid = groups_create_grouping($courseid, $groupingsettings);
69 }
70 if ($success) {
71 redirect(groups_home_url($courseid, null, $groupingid, false));
72 }
73 else {
5bca3fed 74 print_error('erroreditgrouping', 'group', groups_home_url($courseid));
f3f7610c
ML
75 }
76 }
77 }
78
79/// OR, prepare the form.
80
81 if ($groupingid) {
82 // Form to edit existing grouping.
83 $grouping = groups_get_grouping_settings($groupingid);
84 if (! $grouping) {
85 print_error('errorinvalidgrouping', 'group', groups_home_url($courseid));
86 }
87 $strname = s($grouping->name);
88 $strdesc = s($grouping->description);
89
90 $strbutton = get_string('save', 'group');
91 $strheading = get_string('editgroupingsettings', 'group');
92 } else {
93 // Form to create a new one.
94 $strname = get_string('defaultgroupingname', 'group');
95 $strdesc = '';
96 $strbutton = $strheading = get_string('creategrouping', 'group');
97 }
98 $strgroups = get_string('groups');
99 $strparticipants = get_string('participants');
5bca3fed 100 if ($delete) {
101 $strheading = get_string('deletegrouping', 'group');
102 }
f3f7610c
ML
103
104/// Print the page and form
105
106 print_header("$course->shortname: $strgroups",
6ba65fa0 107 $course->fullname,
f3f7610c
ML
108 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
109 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
110 "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
111
112 $usehtmleditor = false;
113?>
114<h3 class="main"><?php echo $strheading ?></h3>
115
116<form action="grouping.php" method="post" class="mform notmform" id="groupingform">
117<input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
118<input type="hidden" name="courseid" value="<?php p($courseid); ?>" />
119<?php
120 if ($groupingid) {
121 echo '<input type="hidden" name="grouping" value="'. $groupingid .'" />';
122 }
5bca3fed 123
124 if ($delete) {
125 /*echo 'Are you sure you want to delete grouping X ?';
126 choose_from_menu_yesno('confirmdelete', false, '', true);*/
127?>
128
129 <p><?php print_string('deletegroupingconfirm', 'group', $strname); ?></p>
130 <input type="hidden" name="delete" value="1" />
131 <input type="submit" name="confirmdelete" value="<?php print_string('yes'); ?>" />
132 <input type="submit" name="cancel" value="<?php print_string('no'); ?>" />
133<?php
134 } else {
f3f7610c
ML
135?>
136
137<div class="f-item">
8834b12a 138<p><label for="groupingname"><?php
139 print_string('groupingname', 'group');
140 if (isset($err['name'])) {
141 echo' ';
142 formerr($err['name']);
143 } ?>&nbsp; </label></p>
f3f7610c
ML
144<p><input id="groupingname" name="name" type="text" size="40" value="<?php echo $strname; ?>" /></p>
145</div>
146
147<p><label for="edit-description"><?php print_string('groupingdescription', 'group'); ?>&nbsp;</label></p>
148<p><?php print_textarea($usehtmleditor, 5, 45, 200, 400, 'description', $strdesc); ?></p>
149
b1f627d9 150<?php /* TODO:
151<fieldset>
152 <legend><?php print_string('editgroupingpermissions', 'group'); ?></legend>
153 <ol class="unlist para">
154 <li><label><input type="checkbox" id="perm_viewowngroup" checked="checked" /> <?php print_string('viewowngroup', 'group'); ?></label></li>
155 <li><label><input type="checkbox" id="perm_viewallgroupsmembers" checked="checked" /> <?php print_string('viewallgroupsmembers', 'group'); ?></label></li>
156 <li><label><input type="checkbox" id="perm_viewallgroupsactivities" checked="checked" /> <?php print_string('viewallgroupsactivities', 'group'); ?></label></li>
157 <li><label><input type="checkbox" id="perm_teachersgroupmark" /> <?php print_string('teachersgroupmark', 'group'); ?></label></li>
158 <li><label><input type="checkbox" id="perm_teachersgroupview" /> <?php print_string('teachersgroupview', 'group'); ?></label></li>
159 <li><label><input type="checkbox" id="perm_teachersoverride" /> <?php print_string('teachersoverride', 'group'); ?></label></li>
160 </ol>
161</fieldset>
162*/ ?>
163
f3f7610c
ML
164<p class="fitem">
165 <label for="id_submit">&nbsp;</label>
166 <span class="f-element fsubmit">
167 <input type="submit" name="update" id="id_submit" value="<?php echo $strbutton; ?>" />
168 <input type="submit" name="cancel" value="<?php print_string('cancel', 'group'); ?>" />
169 </span>
170</p>
5bca3fed 171
172<?php } //IF($delete) ?>
173
f3f7610c
ML
174<span class="clearer">&nbsp;</span>
175
176</form>
177<?php
178 print_footer($course);
179}
180
181?>