4 * Created on 12/12/2006
6 * MNET enrol allowed courses and categories form
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
);
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
)) {
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
)) {
68 $removedcourses[] = $course;
70 $allowedcourses = array_diff($allowedcourses, $removedcourses);
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;
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;
97 $potentialcategories[] = $category;
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;
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;
115 $potentialcourses[] = $course;
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; ?>" />
132 // display course category selector
133 if (count($categories) < 1) {
134 echo get_string('nocategoriesdefined', 'enrol_mnet', "$CFG->wwwroot/course/index.php?categoryedit=on");
138 <table align
="center" border
="0" cellpadding
="5" cellspacing
="0">
141 <?php
print_string('allowedcategories', 'enrol_mnet', count($allowedcategories)); ?
>
145 <?php
print_string('allcategories', 'enrol_mnet', count($potentialcategories)); ?
>
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;" >
156 foreach ($allowedcategories as $category) {
157 echo "<option value=\"$category->id\"> " . format_string($category->name
) . " </option>\n";
165 <input name
="addcategory" type
="submit" id
="add" value
="←" />
167 <input name
="removecategory" type
="submit" id
="remove" value
="→" />
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;">
177 foreach ($potentialcategories as $category) {
178 echo "<option value=\"$category->id\"> " . format_string($category->name
) . " </option>\n";
189 // display course selector
190 if (count($courses) < 1) {
191 echo get_string('nocoursesdefined', 'enrol_mnet', "TODO: $course_admin_url"); // TODO
195 <table align
="center" border
="0" cellpadding
="5" cellspacing
="0">
198 <?php
print_string('allowedcourses', 'enrol_mnet', count($allowedcourses)); ?
>
202 <?php
print_string('allcourses', 'enrol_mnet', count($potentialcourses)); ?
>
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;">
213 foreach ($allowedcourses as $course) {
214 echo "<option value=\"$course->id\"> " . format_string($course->shortname
) . " </option>\n";
222 <input name
="addcourse" type
="submit" id
="add" value
="←" />
224 <input name
="removecourse" type
="submit" id
="remove" value
="→" />
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;">
234 foreach ($potentialcourses as $course) {
235 echo "<option value=\"$course->id\"> " . format_string($course->shortname
) . " </option>\n";
251 print_simple_box_end();
252 admin_externalpage_print_footer();