MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / enrol / mnet / allowed_courses.php
blobabd797c54131946a45429a9b002f283cbc5f9d4b
1 <?php
3 /*
4 * Created on 12/12/2006
6 * MNET enrol allowed courses and categories form
7 */
9 require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
10 require_once $CFG->libdir . '/adminlib.php';
11 include_once $CFG->dirroot . '/mnet/lib.php';
14 admin_externalpage_setup('ssoaccesscontrol');
15 admin_externalpage_print_header();
17 $addcategory = optional_param('addcategory', 0, PARAM_BOOL);
18 $removecategory = optional_param('removecategory', 0, PARAM_BOOL);
19 $addcourse = optional_param('addcourse', 0, PARAM_BOOL);
20 $removecourse = optional_param('removecourse', 0, PARAM_BOOL);
22 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
23 $sesskey = sesskey();
24 $formerror = array();
26 require_capability('moodle/user:delete', $sitecontext);
28 // process returned form data
29 if ($form = data_submitted() and confirm_sesskey()) {
31 // add and remove categories as needed
32 if (!empty($CFG->enrol_mnet_allowed_categories)) {
33 $allowedcategories = explode(',', $CFG->enrol_mnet_allowed_categories);
35 if ($addcategory and !empty($form->addcategories)) {
36 foreach ($form->addcategories as $category) {
37 if (!$category = clean_param($category, PARAM_INT)) {
38 continue;
40 $allowedcategories[] = $category;
43 if ($removecategory and !empty($form->removecategories)) {
44 foreach ($form->removecategories as $category) {
45 if ($category = clean_param($category, PARAM_INT)) {
46 $removedcategories[] = $category;
49 $allowedcategories = array_diff($allowedcategories, $removedcategories);
52 // add and remove courses as needed
53 if (!empty($CFG->enrol_mnet_allowed_courses)) {
54 $allowedcourses = explode(',', $CFG->enrol_mnet_allowed_courses);
56 if ($addcourse and !empty($form->addcourses)) {
57 foreach ($form->addcourses as $course) {
58 if ($course = clean_param($course, PARAM_INT)) {
59 $allowedcourses[] = $course;
63 if ($removecourse and !empty($form->removecourses)) {
64 foreach ($form->removecourses as $course) {
65 if (!$course = clean_param($course, PARAM_INT)) {
66 continue;
68 $removedcourses[] = $course;
70 $allowedcourses = array_diff($allowedcourses, $removedcourses);
73 // save config
74 $cfg = empty($allowedcategories) ? '' : implode(',', $allowedcategories);
75 set_config('enrol_mnet_allowed_categories', $cfg);
76 $cfg = empty($allowedcourses) ? '' : implode(',', $allowedcourses);
77 set_config('enrol_mnet_allowed_courses', $cfg);
79 // redirect('allowed_courses.php', get_string('changessaved'));
84 // setup arrays for allowed categories and courses
85 $categories = array();
86 if ($categories = get_records('course_categories', '', '', 'name', 'id, name')) {
87 $allowedcategories = array();
88 if (empty($CFG->enrol_mnet_allowed_categories)) {
89 $potentialcategories = $categories;
90 } else {
91 $potentialcategories = array();
92 $explode_categories = explode(',', $CFG->enrol_mnet_allowed_categories);
93 foreach($categories as $category) {
94 if (in_array($category->id, $explode_categories)) {
95 $allowedcategories[] = $category;
96 } else {
97 $potentialcategories[] = $category;
102 $courses = array();
103 if ($courses = get_records('course', '', '', 'shortname', 'id, shortname')) {
104 unset($courses[SITEID]); // never list or offer the siteid
105 $allowedcourses = array();
106 if (empty($CFG->enrol_mnet_allowed_courses)) {
107 $potentialcourses = $courses;
108 } else {
109 $potentialcourses = array();
110 $explode_courses = explode(',', $CFG->enrol_mnet_allowed_courses);
111 foreach($courses as $course) {
112 if (in_array($course->id, $explode_courses)) {
113 $allowedcourses[] = $course;
114 } else {
115 $potentialcourses[] = $course;
123 // output the form
124 print_simple_box_start('center','90%','','20');
127 <div class="allowedcoursesdiv">
128 <form id="allowedcoursesform" method="post">
129 <input type="hidden" name="sesskey" value="<?php echo $sesskey; ?>" />
130 <?php
132 // display course category selector
133 if (count($categories) < 1) {
134 echo get_string('nocategoriesdefined', 'enrol_mnet', "$CFG->wwwroot/course/index.php?categoryedit=on");
135 } else {
138 <table align="center" border="0" cellpadding="5" cellspacing="0">
139 <tr>
140 <td valign="top">
141 <?php print_string('allowedcategories', 'enrol_mnet', count($allowedcategories)); ?>
142 </td>
143 <td></td>
144 <td valign="top">
145 <?php print_string('allcategories', 'enrol_mnet', count($potentialcategories)); ?>
146 </td>
147 </tr>
149 <tr>
150 <td valign="top">
151 <select name="removecategories[]" size="20" id="removecategories" multiple="multiple"
152 onfocus="getElementById('allowedcoursesform').addcategory.disabled=true;
153 getElementById('allowedcoursesform').removecategory.disabled=false;
154 getElementById('allowedcoursesform').addcategories.selectedIndex=-1;" >
155 <?php
156 foreach ($allowedcategories as $category) {
157 echo "<option value=\"$category->id\"> " . format_string($category->name) . " </option>\n";
160 </select>
161 </td>
163 <td valign="top">
164 <br />
165 <input name="addcategory" type="submit" id="add" value="&larr;" />
166 <br />
167 <input name="removecategory" type="submit" id="remove" value="&rarr;" />
168 <br />
169 </td>
171 <td valign="top">
172 <select name="addcategories[]" size="20" id="addcategories" multiple="multiple"
173 onFocus="getElementById('allowedcoursesform').addcategory.disabled=false;
174 getElementById('allowedcoursesform').removecategory.disabled=true;
175 getElementById('allowedcoursesform').removecategories.selectedIndex=-1;">
176 <?php
177 foreach ($potentialcategories as $category) {
178 echo "<option value=\"$category->id\"> " . format_string($category->name) . " </option>\n";
181 </select>
182 </td>
183 </tr>
184 </table>
185 <?php
189 // display course selector
190 if (count($courses) < 1) {
191 echo get_string('nocoursesdefined', 'enrol_mnet', "TODO: $course_admin_url"); // TODO
192 } else {
195 <table align="center" border="0" cellpadding="5" cellspacing="0">
196 <tr>
197 <td valign="top">
198 <?php print_string('allowedcourses', 'enrol_mnet', count($allowedcourses)); ?>
199 </td>
200 <td></td>
201 <td valign="top">
202 <?php print_string('allcourses', 'enrol_mnet', count($potentialcourses)); ?>
203 </td>
204 </tr>
206 <tr>
207 <td valign="top">
208 <select name="removecourses[]" size="20" id="removecourses" multiple="multiple"
209 onFocus="getElementById('allowedcoursesform').addcourse.disabled=true;
210 getElementById('allowedcoursesform').removecourse.disabled=false;
211 getElementById('allowedcoursesform').addcourses.selectedIndex=-1;">
212 <?php
213 foreach ($allowedcourses as $course) {
214 echo "<option value=\"$course->id\"> " . format_string($course->shortname) . " </option>\n";
217 </select>
218 </td>
220 <td valign="top">
221 <br />
222 <input name="addcourse" type="submit" id="add" value="&larr;" />
223 <br />
224 <input name="removecourse" type="submit" id="remove" value="&rarr;" />
225 <br />
226 </td>
228 <td valign="top">
229 <select name="addcourses[]" size="20" id="addcourses" multiple="multiple"
230 onFocus="getElementById('allowedcoursesform').addcourse.disabled=false;
231 getElementById('allowedcoursesform').removecourse.disabled=true;
232 getElementById('allowedcoursesform').removecourses.selectedIndex=-1;">
233 <?php
234 foreach ($potentialcourses as $course) {
235 echo "<option value=\"$course->id\"> " . format_string($course->shortname) . " </option>\n";
238 </select>
239 </td>
240 </tr>
241 </table>
242 <?php
247 </form>
248 </div>
249 <?php
251 print_simple_box_end();
252 admin_externalpage_print_footer();