commit a4e79a3913b6ca0dc2456f67a3be9c5754d1fac3
Author: Daniel Neis Araujo <danielneis@gmail.com>
Date:   Thu Aug 9 15:23:46 2012 -0300

    MDL-34816 : Self enrol may be conditioned by a plugin callback

diff --git a/enrol/self/edit.php b/enrol/self/edit.php
index 4affcb7..ce37e59 100644
--- a/enrol/self/edit.php
+++ b/enrol/self/edit.php
@@ -70,6 +70,7 @@ if ($mform->is_cancelled()) {
         $instance->status         = $data->status;
         $instance->name           = $data->name;
         $instance->password       = $data->password;
+        $instance->customchar1    = $data->customchar1;
         $instance->customint1     = $data->customint1;
         $instance->customint2     = $data->customint2;
         $instance->customint3     = $data->customint3;
diff --git a/enrol/self/edit_form.php b/enrol/self/edit_form.php
index 5919d69..612884e 100644
--- a/enrol/self/edit_form.php
+++ b/enrol/self/edit_form.php
@@ -104,6 +104,9 @@ class enrol_self_edit_form extends moodleform {
         $mform->setDefault('customint4', $plugin->get_config('sendcoursewelcomemessage'));
         $mform->addHelpButton('customint4', 'sendcoursewelcomemessage', 'enrol_self');
 
+        $mform->addElement('text', 'customchar1', get_string('conditionplugin', 'enrol_self'));
+        $mform->addHelpButton('customchar1', 'conditionplugin', 'enrol_self');
+
         $mform->addElement('textarea', 'customtext1', get_string('customwelcomemessage', 'enrol_self'), array('cols'=>'60', 'rows'=>'8'));
 
         $mform->addElement('hidden', 'id');
@@ -176,4 +179,4 @@ class enrol_self_edit_form extends moodleform {
         }
         return $roles;
     }
-}
\ No newline at end of file
+}
diff --git a/enrol/self/lang/en/enrol_self.php b/enrol/self/lang/en/enrol_self.php
index af2c54c..92dff03 100644
--- a/enrol/self/lang/en/enrol_self.php
+++ b/enrol/self/lang/en/enrol_self.php
@@ -24,6 +24,8 @@
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
+$string['conditionplugin'] = 'Condition plugin';
+$string['conditionplugin_help'] = 'Path to plugin that implements a conditional enrol callback. eg.: local/progress_tracking. Leave blank if dont want a callback to be called.';
 $string['customwelcomemessage'] = 'Custom welcome message';
 $string['defaultrole'] = 'Default role assignment';
 $string['defaultrole_desc'] = 'Select role which should be assigned to users during self enrolment';
diff --git a/enrol/self/lib.php b/enrol/self/lib.php
index 32c9d48..08bbb92 100644
--- a/enrol/self/lib.php
+++ b/enrol/self/lib.php
@@ -188,6 +188,19 @@ class enrol_self_plugin extends enrol_plugin {
             //TODO: inform that enrolment is not possible any more
             return null;
         }
+        if (!empty($instance->customchar1)) {
+            $plugin = $instance->customchar1;
+            $plugin_lib = "{$CFG->dirroot}/{$plugin}/lib.php";
+            if (file_exists($plugin_lib)) {
+                require_once($plugin_lib);
+                $f = basename($plugin).'_user_can_enrol';
+                if (function_exists($f)) {
+                    if (!call_user_func($f, $instance)) {
+                        return null;
+                    }
+                }
+            }
+        }
 
         require_once("$CFG->dirroot/enrol/self/locallib.php");
         require_once("$CFG->dirroot/group/lib.php");
