From fb8634e50c6972e248826a175e351aa110f8a878 Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 26 Jul 2008 16:50:33 +0000 Subject: [PATCH] MDL-15846 add option to prevent course welcome emails + support for searching in enrolment page --- admin/enrol.php | 42 +++++++++++++++++++++++++++++-- admin/settings/courses.php | 2 +- lang/en_utf8/admin.php | 2 ++ lib/adminlib.php | 51 ++++++++++++++++++++++++++++++++++++++ lib/moodlelib.php | 4 +++ 5 files changed, 98 insertions(+), 3 deletions(-) diff --git a/admin/enrol.php b/admin/enrol.php index 14b75d6b10..707e183b65 100644 --- a/admin/enrol.php +++ b/admin/enrol.php @@ -5,18 +5,23 @@ require_once('../config.php'); require_once($CFG->libdir.'/adminlib.php'); - $enrol = optional_param('enrol', $CFG->enrol, PARAM_SAFEDIR); + $enrol = optional_param('enrol', $CFG->enrol, PARAM_SAFEDIR); + $savesettings = optional_param('savesettings', 0, PARAM_BOOL); + $CFG->pagepath = 'enrol'; admin_externalpage_setup('enrolment'); + if (!isset($CFG->sendcoursewelcomemessage)) { + set_config('sendcoursewelcomemessage', 1); + } require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class /// Save settings - if ($frm = data_submitted()) { + if ($frm = data_submitted() and !$savesettings) { if (!confirm_sesskey()) { print_error('confirmsesskeybad', 'error'); } @@ -34,6 +39,12 @@ set_config('enrol_plugins_enabled', implode(',', $frm->enable)); set_config('enrol', $frm->default); redirect("enrol.php", get_string("changessaved"), 1); + + } else if ($frm = data_submitted() and $savesettings) { + if (!confirm_sesskey()) { + print_error('confirmsesskeybad', 'error'); + } + set_config('sendcoursewelcomemessage', required_param('sendcoursewelcomemessage', PARAM_BOOL)); } /// Print the form @@ -101,6 +112,33 @@ echo ""; echo ""; + echo '
'; + + $yesnooptions = array(0=>get_string('no'), 1=>get_string('yes')); + + echo '
frametarget.' id="adminsettings" method="post" action="enrol.php">'; + echo '
'; + print_heading(get_string('commonsettings', 'admin')); + echo ''; + echo ''; + echo '
'; + echo '
'; + + echo '
'; + echo '
'; + choose_from_menu($yesnooptions, 'sendcoursewelcomemessage', $CFG->sendcoursewelcomemessage, ''); + echo '
'.get_string('defaultsettinginfo', 'admin', get_string('yes')).'
'; + echo '
' . get_string('configsendcoursewelcomemessage', 'admin') . '
'; + echo '
'; + + echo '
'; + + echo '
'; + echo '
'; + echo '
'; + admin_externalpage_print_footer(); ?> diff --git a/admin/settings/courses.php b/admin/settings/courses.php index 42f804bd30..60f10c5ccc 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -9,7 +9,7 @@ if ($hassiteconfig $ADMIN->add('courses', new admin_externalpage('coursemgmt', get_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/index.php?categoryedit=on','moodle/category:update')); - $ADMIN->add('courses', new admin_externalpage('enrolment', get_string('enrolments'), $CFG->wwwroot . '/'.$CFG->admin.'/enrol.php')); + $ADMIN->add('courses', new admin_enrolment_page()); // "courserequests" settingpage $temp = new admin_settingpage('courserequest', get_string('courserequest')); diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 4d794c81cd..5c9595fc63 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -215,6 +215,7 @@ $string['configsectionsecurity'] = 'Security'; $string['configsectionstats'] = 'Statistics'; $string['configsectionuser'] = 'User'; $string['configsecureforms'] = 'Moodle can use an additional level of security when accepting data from web forms. If this is enabled, then the browser\'s HTTP_REFERER variable is checked against the current form address. In a very few cases this can cause problems if the user is using a firewall (eg Zonealarm) configured to strip HTTP_REFERER from their web traffic. Symptoms are getting \'stuck\' on a form. If your users are having problems with the login page (for example) you might want to disable this setting, although it might leave your site more open to brute-force password attacks. If in doubt, leave this set to \'Yes\'.'; +$string['configsendcoursewelcomemessage'] = 'If enabled users receive welcome message after they are enrolled into course.'; $string['configsessioncookie'] = 'This setting customises the name of the cookie used for Moodle sessions. This is optional, and only useful to avoid cookies being confused when there is more than one copy of Moodle running within the same web site.'; $string['configsessioncookiepath'] = 'If you need to change where browsers send the Moodle cookies, you can change this setting to specify a subdirectory of your web site. Otherwise the default \'/\' should be fine.'; $string['configsessiontimeout'] = 'If people logged in to this site are idle for a long time (without loading pages) then they are automatically logged out (their session is ended). This variable specifies how long this time should be.'; @@ -643,6 +644,7 @@ $string['searchinsettings'] = 'Search in settings'; $string['sectionerror'] = 'Section Error!'; $string['secureforms'] = 'Use additional form security'; $string['security'] = 'Security'; +$string['sendcoursewelcomemessage'] = 'Send course welcome message'; $string['server'] = 'Server'; $string['serverchecks'] = 'Server Checks'; $string['serverlimit'] = 'Server Limit'; diff --git a/lib/adminlib.php b/lib/adminlib.php index e5b5f49c34..91643f8559 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3725,6 +3725,57 @@ class admin_page_managemods extends admin_externalpage { } } +/** + * Enrolment manage page + */ +class admin_enrolment_page extends admin_externalpage { + public function admin_enrolment_page() { + global $CFG; + parent::admin_externalpage('enrolment', get_string('enrolments'), $CFG->wwwroot . '/'.$CFG->admin.'/enrol.php'); + } + + function search($query) { + if ($result = parent::search($query)) { + return $result; + } + + $found = false; + + if ($modules = get_list_of_plugins('enrol')) { + $textlib = textlib_get_instance(); + foreach ($modules as $plugin) { + if (strpos($plugin, $query) !== false) { + $found = true; + break; + } + $strmodulename = get_string('enrolname', "enrol_$plugin"); + if (strpos($textlib->strtolower($strmodulename), $query) !== false) { + $found = true; + break; + } + } + } + //ugly harcoded hacks + if (strpos('sendcoursewelcomemessage', $query) !== false) { + $found = true; + } else if (strpos($textlib->strtolower(get_string('sendcoursewelcomemessage', 'admin')), $query) !== false) { + $found = true; + } else if (strpos($textlib->strtolower(get_string('configsendcoursewelcomemessage', 'admin')), $query) !== false) { + $found = true; + } else if (strpos($textlib->strtolower(get_string('configenrolmentplugins', 'admin')), $query) !== false) { + $found = true; + } + if ($found) { + $result = new object(); + $result->page = $this; + $result->settings = array(); + return array($this->name => $result); + } else { + return array(); + } + } +} + /** * Blocks manage page */ diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 24630a52be..e7edc4fc06 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4390,6 +4390,10 @@ function email_is_not_allowed($email) { function email_welcome_message_to_user($course, $user=NULL) { global $CFG, $USER; + if (isset($CFG->sendcoursewelcomemessage) and !$CFG->sendcoursewelcomemessage) { + return; + } + if (empty($user)) { if (!isloggedin()) { return false; -- 2.39.5