Commit 39171a79 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add captcha config to site options; don't require captcha on contact us for logged in users

parent aa19ef19
......@@ -184,6 +184,18 @@ $siteoptionform = array(
'defaultvalue' => get_config('institutionautosuspend'),
'help' => true,
),
'captchaonregisterform' => array(
'type' => 'checkbox',
'title' => get_string('captchaonregisterform', 'admin'),
'description' => get_string('captchaonregisterformdescription', 'admin'),
'defaultvalue' => get_config('captchaonregisterform'),
),
'captchaoncontactform' => array(
'type' => 'checkbox',
'title' => get_string('captchaoncontactform', 'admin'),
'description' => get_string('captchaoncontactformdescription', 'admin'),
'defaultvalue' => get_config('captchaoncontactform'),
),
)
);
......@@ -202,10 +214,13 @@ function siteoptions_fail(Pieform $form, $field) {
}
function siteoptions_submit(Pieform $form, $values) {
$fields = array('sitename','lang','theme', 'pathtoclam',
$fields = array(
'sitename','lang','theme', 'pathtoclam',
'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
'allowpublicviews', 'allowpublicprofiles', 'createpublicgroups', 'searchplugin',
'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend');
'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend',
'captchaonregisterform', 'captchaoncontactform',
);
$oldlanguage = get_config('lang');
$oldtheme = get_config('theme');
foreach ($fields as $field) {
......
......@@ -78,8 +78,7 @@ $elements = array(
)
);
$captcharequired = get_config('captcha_on_contact_form');
if (is_null($captcharequired) || $captcharequired) {
if (get_config('captchaoncontactform') && !$USER->is_logged_in()) {
$elements['captcha'] = array(
'type' => 'captcha',
'title' => get_string('captchatitle'),
......@@ -105,8 +104,8 @@ $contactform = pieform(array(
));
function contactus_validate(Pieform $form, $values) {
$captcharequired = get_config('captcha_on_contact_form');
if ((is_null($captcharequired) || $captcharequired) && !$values['captcha']) {
global $USER;
if (get_config('captchaoncontactform') && !$USER->is_logged_in() && !$values['captcha']) {
$form->set_error('captcha', get_string('captchaincorrect'));
}
}
......
......@@ -135,6 +135,10 @@ $string['allowpublicviews'] = 'Allow public views';
$string['allowpublicviewsdescription'] = 'If set to yes, users will be able to create portfolio Views that are accessable to the public rather than only to logged in users';
$string['allowpublicprofiles'] = 'Allow public profiles';
$string['allowpublicprofilesdescription'] = 'If set to yes, users will be able to set their profile Views to be accessable to the public rather than only to logged in users';
$string['captchaonregisterform'] = 'Captcha required for registration';
$string['captchaonregisterformdescription'] = 'Require users to type letters from a captcha image when submitting the registration form';
$string['captchaoncontactform'] = 'Captcha required for contact us';
$string['captchaoncontactformdescription'] = 'Require logged-out users to type letters from a captcha image when submitting the Contact Us form';
$string['defaultaccountinactiveexpire'] = 'Default account inactivity time';
$string['defaultaccountinactiveexpiredescription'] = 'How long a user account will remain active without the user logging in';
$string['defaultaccountinactivewarn'] = 'Warning time for inactivity/expiry';
......
......@@ -1187,6 +1187,13 @@ function xmldb_core_upgrade($oldversion=0) {
drop_field($table, $field);
}
if ($oldversion < 2009082600) {
$captcha = get_config('captcha_on_contact_form');
set_config('captchaoncontactform', (int) (is_null($captcha) || $captcha));
$captcha = get_config('captcha_on_register_form');
set_config('captchaonregisterform', (int) (is_null($captcha) || $captcha));
}
return $status;
}
......
......@@ -663,6 +663,8 @@ function core_install_firstcoredata_defaults() {
set_config('createpublicgroups', 'all');
set_config('allowpublicviews', 1);
set_config('allowpublicprofiles', 1);
set_config('captchaoncontactform', 1);
set_config('captchaonregisterform', 1);
// install the applications
$app = new StdClass;
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009082400;
$config->version = 2009082600;
$config->release = '1.2.0beta2dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
......@@ -236,8 +236,7 @@ $elements['tandc'] = array(
'separator' => ' &nbsp; '
);
$captcharequired = get_config('captcha_on_register_form');
if (is_null($captcharequired) || $captcharequired) {
if (get_config('captchaonregisterform')) {
$elements['captcha'] = array(
'type' => 'captcha',
'title' => get_string('captchatitle'),
......@@ -296,8 +295,7 @@ function register_validate(Pieform $form, $values) {
}
// CAPTCHA image
$captcharequired = get_config('captcha_on_register_form');
if ((is_null($captcharequired) || $captcharequired) && !$values['captcha']) {
if (get_config('captchaonregisterform') && !$values['captcha']) {
$form->set_error('captcha', get_string('captchaincorrect'));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment