MDL-7861, fixing xhtml strict problems
[moodle.git] / enrol / mnet / allowed_courses.php
CommitLineData
bf1a3d20 1<?php
2
3/*
4 * Created on 12/12/2006
5 *
6 * MNET enrol allowed courses and categories form
7 */
8
9require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
10require_once $CFG->libdir . '/adminlib.php';
11include_once $CFG->dirroot . '/mnet/lib.php';
12
13require_login();
14$adminroot = admin_get_root();
15admin_externalpage_setup('ssoaccesscontrol', $adminroot);
16admin_externalpage_print_header($adminroot);
17
18$addcategory = optional_param('addcategory', 0, PARAM_BOOL);
19$removecategory = optional_param('removecategory', 0, PARAM_BOOL);
20$addcourse = optional_param('addcourse', 0, PARAM_BOOL);
21$removecourse = optional_param('removecourse', 0, PARAM_BOOL);
22
23$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
24$sesskey = sesskey();
25$formerror = array();
26
27require_capability('moodle/user:delete', $sitecontext);
28
29// process returned form data
30if ($form = data_submitted() and confirm_sesskey()) {
31
32 // add and remove categories as needed
33 if (!empty($CFG->enrol_mnet_allowed_categories)) {
34 $allowedcategories = explode(',', $CFG->enrol_mnet_allowed_categories);
35 }
36 if ($addcategory and !empty($form->addcategories)) {
37 foreach ($form->addcategories as $category) {
38 if (!$category = clean_param($category, PARAM_INT)) {
39 continue;
40 }
41 $allowedcategories[] = $category;
42 }
43 }
44 if ($removecategory and !empty($form->removecategories)) {
45 foreach ($form->removecategories as $category) {
46 if ($category = clean_param($category, PARAM_INT)) {
47 $removedcategories[] = $category;
48 }
49 }
50 $allowedcategories = array_diff($allowedcategories, $removedcategories);
51 }
52
53 // add and remove courses as needed
54 if (!empty($CFG->enrol_mnet_allowed_courses)) {
55 $allowedcourses = explode(',', $CFG->enrol_mnet_allowed_courses);
56 }
57 if ($addcourse and !empty($form->addcourses)) {
58 foreach ($form->addcourses as $course) {
59 if ($course = clean_param($course, PARAM_INT)) {
60 $allowedcourses[] = $course;
61 }
62 }
63 }
64 if ($removecourse and !empty($form->removecourses)) {
65 foreach ($form->removecourses as $course) {
66 if (!$course = clean_param($course, PARAM_INT)) {
67 continue;
68 }
69 $removedcourses[] = $course;
70 }
71 $allowedcourses = array_diff($allowedcourses, $removedcourses);
72 }
73
74 // save config
75 $cfg = empty($allowedcategories) ? '' : implode(',', $allowedcategories);
76 set_config('enrol_mnet_allowed_categories', $cfg);
77 $cfg = empty($allowedcourses) ? '' : implode(',', $allowedcourses);
78 set_config('enrol_mnet_allowed_courses', $cfg);
79
80 // redirect('allowed_courses.php', get_string('changessaved'));
81}
82
83
84
85// setup arrays for allowed categories and courses
86$categories = array();
87if ($categories = get_records('course_categories', '', '', 'name', 'id, name')) {
88 if (empty($CFG->enrol_mnet_allowed_categories)) {
89 $allowedcategories = array();
90 $potentialcategories = $categories;
91 } else {
92 $allowedcategories = array_intersect_key($categories, array_flip(explode(',', $CFG->enrol_mnet_allowed_categories)));
93 $potentialcategories = array_diff_key($categories, array_flip(explode(',', $CFG->enrol_mnet_allowed_categories)));
94 }
95}
96$courses = array();
97if ($courses = get_records('course', '', '', 'shortname', 'id, shortname')) {
98 if (empty($CFG->enrol_mnet_allowed_courses)) {
99 $allowedcourses = array();
100 $potentialcourses = $courses;
101 } else {
102 $allowedcourses = array_intersect_key($courses, array_flip(explode(',', $CFG->enrol_mnet_allowed_courses)));
103 $potentialcourses = array_diff_key($courses, array_flip(explode(',', $CFG->enrol_mnet_allowed_courses)));
104 }
105}
106
107
108
109// output the form
110print_simple_box_start('center','90%','','20');
111
112?>
113 <div class="allowedcoursesdiv">
b7dc2256 114 <form id="allowedcoursesform" method="post">
bf1a3d20 115 <input type="hidden" name="sesskey" value="<?php echo $sesskey; ?>">
116<?php
117
118// display course category selector
119if (count($categories) < 1) {
120 echo get_string('nocategoriesdefined', 'enrol_mnet', "$CFG->wwwroot/course/index.php?categoryedit=on");
121} else {
122
123?>
124 <table align="center" border="0" cellpadding="5" cellspacing="0">
125 <tr>
126 <td valign="top">
127 <?php print_string('allowedcategories', 'enrol_mnet', count($allowedcategories)); ?>
128 </td>
129 <td></td>
130 <td valign="top">
131 <?php print_string('allcategories', 'enrol_mnet', count($potentialcategories)); ?>
132 </td>
133 </tr>
134
135 <tr>
136 <td valign="top">
137 <select name="removecategories[]" size="20" id="removecategories" multiple
b7dc2256 138 onFocus="getElementById('allowedcoursesform').addcategory.disabled=true;
139 getElementById('allowedcoursesform').removecategory.disabled=false;
140 getElementById('allowedcoursesform').addcategories.selectedIndex=-1;" />
bf1a3d20 141 <?php
142 foreach ($allowedcategories as $category) {
143 echo "<option value=\"$category->id\"> $category->name </option>\n";
144 }
145 ?>
146 </select>
147 </td>
148
149 <td valign="top">
150 <br />
151 <input name="addcategory" type="submit" id="add" value="&larr;" />
152 <br />
153 <input name="removecategory" type="submit" id="remove" value="&rarr;" />
154 <br />
155 </td>
156
157 <td valign="top">
158 <select name="addcategories[]" size="20" id="addcategories" multiple
b7dc2256 159 onFocus="getElementById('allowedcoursesform').addcategory.disabled=false;
160 getElementById('allowedcoursesform').removecategory.disabled=true;
161 getElementById('allowedcoursesform').removecategories.selectedIndex=-1;">
bf1a3d20 162 <?php
163 foreach ($potentialcategories as $category) {
164 echo "<option value=\"$category->id\"> $category->name </option>\n";
165 }
166 ?>
167 </select>
168 </td>
169 </tr>
170 </table>
171<?php
172
173}
174
175// display course selector
176if (count($courses) < 1) {
177 echo get_string('nocoursesdefined', 'enrol_mnet', "TODO: $course_admin_url"); // TODO
178} else {
179
180?>
181 <table align="center" border="0" cellpadding="5" cellspacing="0">
182 <tr>
183 <td valign="top">
184 <?php print_string('allowedcourses', 'enrol_mnet', count($allowedcourses)); ?>
185 </td>
186 <td></td>
187 <td valign="top">
188 <?php print_string('allcourses', 'enrol_mnet', count($potentialcourses)); ?>
189 </td>
190 </tr>
191
192 <tr>
193 <td valign="top">
194 <select name="removecourses[]" size="20" id="removecourses" multiple
b7dc2256 195 onFocus="getElementById('allowedcoursesform').addcourse.disabled=true;
196 getElementById('allowedcoursesform').removecourse.disabled=false;
197 getElementById('allowedcoursesform').addcourses.selectedIndex=-1;" />
bf1a3d20 198 <?php
199 foreach ($allowedcourses as $course) {
200 echo "<option value=\"$course->id\"> $course->shortname </option>\n";
201 }
202 ?>
203 </select>
204 </td>
205
206 <td valign="top">
207 <br />
208 <input name="addcourse" type="submit" id="add" value="&larr;" />
209 <br />
210 <input name="removecourse" type="submit" id="remove" value="&rarr;" />
211 <br />
212 </td>
213
214 <td valign="top">
215 <select name="addcourses[]" size="20" id="addcourses" multiple
b7dc2256 216 onFocus="getElementById('allowedcoursesform').addcourse.disabled=false;
217 getElementById('allowedcoursesform').removecourse.disabled=true;
218 getElementById('allowedcoursesform').removecourses.selectedIndex=-1;">
bf1a3d20 219 <?php
220 foreach ($potentialcourses as $course) {
221 echo "<option value=\"$course->id\"> $course->shortname </option>\n";
222 }
223 ?>
224 </select>
225 </td>
226 </tr>
227 </table>
228<?php
229
230}
231
232?>
233 </form>
234 </div>
235<?php
236
237print_simple_box_end();
238admin_externalpage_print_footer($adminroot);
239
240?>