Permalink
Browse files

mnet: new enrolment plugin

  • Loading branch information...
1 parent af9c522 commit bf1a3d20102eaadedfe478122eb23f38ee7af7bd martinlanghoff committed Jan 4, 2007
@@ -0,0 +1,240 @@
+<?php
+
+/*
+ * Created on 12/12/2006
+ *
+ * MNET enrol allowed courses and categories form
+ */
+
+require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
+require_once $CFG->libdir . '/adminlib.php';
+include_once $CFG->dirroot . '/mnet/lib.php';
+
+require_login();
+$adminroot = admin_get_root();
+admin_externalpage_setup('ssoaccesscontrol', $adminroot);
+admin_externalpage_print_header($adminroot);
+
+$addcategory = optional_param('addcategory', 0, PARAM_BOOL);
+$removecategory = optional_param('removecategory', 0, PARAM_BOOL);
+$addcourse = optional_param('addcourse', 0, PARAM_BOOL);
+$removecourse = optional_param('removecourse', 0, PARAM_BOOL);
+
+$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+$sesskey = sesskey();
+$formerror = array();
+
+require_capability('moodle/user:delete', $sitecontext);
+
+// process returned form data
+if ($form = data_submitted() and confirm_sesskey()) {
+
+ // add and remove categories as needed
+ if (!empty($CFG->enrol_mnet_allowed_categories)) {
+ $allowedcategories = explode(',', $CFG->enrol_mnet_allowed_categories);
+ }
+ if ($addcategory and !empty($form->addcategories)) {
+ foreach ($form->addcategories as $category) {
+ if (!$category = clean_param($category, PARAM_INT)) {
+ continue;
+ }
+ $allowedcategories[] = $category;
+ }
+ }
+ if ($removecategory and !empty($form->removecategories)) {
+ foreach ($form->removecategories as $category) {
+ if ($category = clean_param($category, PARAM_INT)) {
+ $removedcategories[] = $category;
+ }
+ }
+ $allowedcategories = array_diff($allowedcategories, $removedcategories);
+ }
+
+ // add and remove courses as needed
+ if (!empty($CFG->enrol_mnet_allowed_courses)) {
+ $allowedcourses = explode(',', $CFG->enrol_mnet_allowed_courses);
+ }
+ if ($addcourse and !empty($form->addcourses)) {
+ foreach ($form->addcourses as $course) {
+ if ($course = clean_param($course, PARAM_INT)) {
+ $allowedcourses[] = $course;
+ }
+ }
+ }
+ if ($removecourse and !empty($form->removecourses)) {
+ foreach ($form->removecourses as $course) {
+ if (!$course = clean_param($course, PARAM_INT)) {
+ continue;
+ }
+ $removedcourses[] = $course;
+ }
+ $allowedcourses = array_diff($allowedcourses, $removedcourses);
+ }
+
+ // save config
+ $cfg = empty($allowedcategories) ? '' : implode(',', $allowedcategories);
+ set_config('enrol_mnet_allowed_categories', $cfg);
+ $cfg = empty($allowedcourses) ? '' : implode(',', $allowedcourses);
+ set_config('enrol_mnet_allowed_courses', $cfg);
+
+ // redirect('allowed_courses.php', get_string('changessaved'));
+}
+
+
+
+// setup arrays for allowed categories and courses
+$categories = array();
+if ($categories = get_records('course_categories', '', '', 'name', 'id, name')) {
+ if (empty($CFG->enrol_mnet_allowed_categories)) {
+ $allowedcategories = array();
+ $potentialcategories = $categories;
+ } else {
+ $allowedcategories = array_intersect_key($categories, array_flip(explode(',', $CFG->enrol_mnet_allowed_categories)));
+ $potentialcategories = array_diff_key($categories, array_flip(explode(',', $CFG->enrol_mnet_allowed_categories)));
+ }
+}
+$courses = array();
+if ($courses = get_records('course', '', '', 'shortname', 'id, shortname')) {
+ if (empty($CFG->enrol_mnet_allowed_courses)) {
+ $allowedcourses = array();
+ $potentialcourses = $courses;
+ } else {
+ $allowedcourses = array_intersect_key($courses, array_flip(explode(',', $CFG->enrol_mnet_allowed_courses)));
+ $potentialcourses = array_diff_key($courses, array_flip(explode(',', $CFG->enrol_mnet_allowed_courses)));
+ }
+}
+
+
+
+// output the form
+print_simple_box_start('center','90%','','20');
+
+?>
+ <div class="allowedcoursesdiv">
+ <form name="allowedcoursesform" method="post">
+ <input type="hidden" name="sesskey" value="<?php echo $sesskey; ?>">
+<?php
+
+// display course category selector
+if (count($categories) < 1) {
+ echo get_string('nocategoriesdefined', 'enrol_mnet', "$CFG->wwwroot/course/index.php?categoryedit=on");
+} else {
+
+?>
+ <table align="center" border="0" cellpadding="5" cellspacing="0">
+ <tr>
+ <td valign="top">
+ <?php print_string('allowedcategories', 'enrol_mnet', count($allowedcategories)); ?>
+ </td>
+ <td></td>
+ <td valign="top">
+ <?php print_string('allcategories', 'enrol_mnet', count($potentialcategories)); ?>
+ </td>
+ </tr>
+
+ <tr>
+ <td valign="top">
+ <select name="removecategories[]" size="20" id="removecategories" multiple
+ onFocus="document.allowedcoursesform.addcategory.disabled=true;
+ document.allowedcoursesform.removecategory.disabled=false;
+ document.allowedcoursesform.addcategories.selectedIndex=-1;" />
+ <?php
+ foreach ($allowedcategories as $category) {
+ echo "<option value=\"$category->id\"> $category->name </option>\n";
+ }
+ ?>
+ </select>
+ </td>
+
+ <td valign="top">
+ <br />
+ <input name="addcategory" type="submit" id="add" value="&larr;" />
+ <br />
+ <input name="removecategory" type="submit" id="remove" value="&rarr;" />
+ <br />
+ </td>
+
+ <td valign="top">
+ <select name="addcategories[]" size="20" id="addcategories" multiple
+ onFocus="document.allowedcoursesform.addcategory.disabled=false;
+ document.allowedcoursesform.removecategory.disabled=true;
+ document.allowedcoursesform.removecategories.selectedIndex=-1;">
+ <?php
+ foreach ($potentialcategories as $category) {
+ echo "<option value=\"$category->id\"> $category->name </option>\n";
+ }
+ ?>
+ </select>
+ </td>
+ </tr>
+ </table>
+<?php
+
+}
+
+// display course selector
+if (count($courses) < 1) {
+ echo get_string('nocoursesdefined', 'enrol_mnet', "TODO: $course_admin_url"); // TODO
+} else {
+
+?>
+ <table align="center" border="0" cellpadding="5" cellspacing="0">
+ <tr>
+ <td valign="top">
+ <?php print_string('allowedcourses', 'enrol_mnet', count($allowedcourses)); ?>
+ </td>
+ <td></td>
+ <td valign="top">
+ <?php print_string('allcourses', 'enrol_mnet', count($potentialcourses)); ?>
+ </td>
+ </tr>
+
+ <tr>
+ <td valign="top">
+ <select name="removecourses[]" size="20" id="removecourses" multiple
+ onFocus="document.allowedcoursesform.addcourse.disabled=true;
+ document.allowedcoursesform.removecourse.disabled=false;
+ document.allowedcoursesform.addcourses.selectedIndex=-1;" />
+ <?php
+ foreach ($allowedcourses as $course) {
+ echo "<option value=\"$course->id\"> $course->shortname </option>\n";
+ }
+ ?>
+ </select>
+ </td>
+
+ <td valign="top">
+ <br />
+ <input name="addcourse" type="submit" id="add" value="&larr;" />
+ <br />
+ <input name="removecourse" type="submit" id="remove" value="&rarr;" />
+ <br />
+ </td>
+
+ <td valign="top">
+ <select name="addcourses[]" size="20" id="addcourses" multiple
+ onFocus="document.allowedcoursesform.addcourse.disabled=false;
+ document.allowedcoursesform.removecourse.disabled=true;
+ document.allowedcoursesform.removecourses.selectedIndex=-1;">
+ <?php
+ foreach ($potentialcourses as $course) {
+ echo "<option value=\"$course->id\"> $course->shortname </option>\n";
+ }
+ ?>
+ </select>
+ </td>
+ </tr>
+ </table>
+<?php
+
+}
+
+?>
+ </form>
+ </div>
+<?php
+
+print_simple_box_end();
+admin_externalpage_print_footer($adminroot);
+
+?>
@@ -0,0 +1,36 @@
+<table cellspacing="0" cellpadding="5" border="0" align="center">
+
+<tr valign="top">
+ <th align="center" colspan="3">Remote Servers:</td>
+</tr>
+<tr valign="top">
+ <td align="left" colspan="3">
+ <a href="<?php echo $CFG->wwwroot .'/enrol/mnet/remote_hosts.php?sesskey=' . sesskey(); ?>" >Manage Moodle Network Enrolments.</a><br>
+ Servers configured: <?php echo count(array_keys($mnethosts)); ?>
+
+ </td>
+</tr>
+
+<tr valign="top">
+ <th align="center" colspan="3">Local courses for external users:</td>
+</tr>
+
+<tr valign="top">
+ <td align="right">allow_allcourses:</td>
+ <td>
+ <?php print choose_from_menu_yesno('enrol_mnet_allow_allcourses', $frm->enrol_mnet_allow_allcourses); ?>
+ </td>
+ <td>
+ <?php print_string("allow_allcourses", "enrol_mnet") ?>
+ </td>
+</tr>
+
+<tr>
+ <td align="right">allowed_courses:</td>
+ <td>
+ <a href="<?php echo "$CFG->wwwroot/enrol/mnet/allowed_courses.php" ?>"><?php print_string('allowedcourseslinktext', 'enrol_mnet') ?></a>
+ </td>
+</tr>
+
+
+</table>
Oops, something went wrong.

0 comments on commit bf1a3d2

Please sign in to comment.