MDL-24570 multiple sitepolicy fixes + adding new separate guest user policy

AMOS BEGIN
 MOV [configsitepolicy,core_admin],[sitepolicy_help,core_admin]
AMOS END
This commit is contained in:
Petr Skoda 2010-10-09 18:13:33 +00:00
parent 67bd584ee0
commit b593d49d59
5 changed files with 47 additions and 29 deletions

View File

@ -51,7 +51,9 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
'lastname firstname' => get_string('lastname').' + '.get_string('firstname'),
'firstname' => get_string('firstname'))));
$temp->add(new admin_setting_configcheckbox('extendedusernamechars', get_string('extendedusernamechars', 'admin'), get_string('configextendedusernamechars', 'admin'), 0));
$temp->add(new admin_setting_configtext('sitepolicy', get_string('sitepolicy', 'admin'), get_string('configsitepolicy', 'admin'), '', PARAM_RAW));
$temp->add(new admin_setting_configtext('sitepolicy', get_string('sitepolicy', 'admin'), get_string('sitepolicy_help', 'admin'), '', PARAM_RAW));
$temp->add(new admin_setting_configtext('sitepolicyguest', get_string('sitepolicyguest', 'admin'), get_string('sitepolicyguest_help', 'admin'), (isset($CFG->sitepolicy) ? $CFG->sitepolicy : ''), PARAM_RAW));
$temp->add(new admin_setting_configcheckbox('extendedusernamechars', get_string('extendedusernamechars', 'admin'), get_string('configextendedusernamechars', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('usetags', get_string('usetags','admin'),get_string('configusetags', 'admin'),'1'));
$temp->add(new admin_setting_configcheckbox('keeptagnamecase', get_string('keeptagnamecase','admin'),get_string('configkeeptagnamecase', 'admin'),'1'));

View File

@ -322,7 +322,6 @@ $string['configsitedefaultlicensehelp'] = 'The default licence for publishing co
$string['configsitemailcharset'] = 'All the emails generated by your site will be sent in the charset specified here. Anyway, every individual user will be able to adjust it if the next setting is enabled.';
$string['configsitemaxcategorydepth'] = 'Maximum Category Depth';
$string['configsitemaxcategorydepthhelp'] = 'This specifies the maximum depth of child categories shown';
$string['configsitepolicy'] = 'If you have a site policy that all users must see and agree to before using this site, then specify the URL to it here, otherwise leave this field blank. The URL can point to anywhere - one convenient place would be a file in the site files. eg http://yoursite/file.php/1/policy.html';
$string['configslasharguments'] = 'Files (images, uploads etc) are provided via a script using \'slash arguments\'. This method allows files to be more easily cached in web browsers, proxy servers etc. Unfortunately, some PHP servers don\'t allow this method, so if you have trouble viewing uploaded files or images (eg user pictures), disable this setting.';
$string['configsmartpix'] = 'With this on, icons are served through a PHP script that searches the current theme, then all parent themes, then the Moodle /pix folder. This reduces the need to duplicate image files within themes, but has a slight performance cost.';
$string['configsmtphosts'] = 'Give the full name of one or more local SMTP servers that Moodle should use to send mail (eg \'mail.a.com\' or \'mail.a.com;mail.b.com\'). To specify a non-default port (i.e other than port 25), you can use the [server]:[port] syntax (eg \'mail.a.com:587\'. If you leave it blank, Moodle will use the PHP default method of sending mail.';
@ -888,6 +887,9 @@ $string['sitemaintenancewarning'] = 'Your site is currently in maintenance mode
$string['sitemaintenancewarning2'] = 'Your site is currently in maintenance mode (only admins can log in). To return this site to normal operation, <a href="{$a}">disable maintenance mode</a>.';
$string['sitepolicies'] = 'Site policies';
$string['sitepolicy'] = 'Site policy URL';
$string['sitepolicy_help'] = 'If you have a site policy that all registered users must see and agree to before using this site, then specify the URL to it here, otherwise leave this field blank. This setting can contain any public URL.';
$string['sitepolicyguest'] = 'Site policy URL for guests';
$string['sitepolicyguest_help'] = 'If you have a site policy that all guests must see and agree to before using this site, then specify the URL to it here, otherwise leave this field blank. This setting can contain any public URL. Note: access of not-logged-in users may be prevented with forcelogin setting.';
$string['sitesectionhelp'] = 'If selected, a topic section will be displayed on the site\'s front page.';
$string['slasharguments'] = 'Use slash arguments';
$string['smartpix'] = 'Smart pix search';

View File

@ -2360,12 +2360,18 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $
return;
}
// Check that the user has agreed to a site policy if there is one
if (!empty($CFG->sitepolicy)) {
if ($preventredirect) {
throw new require_login_exception('Policy not agreed');
}
if (!$USER->policyagreed) {
// Check that the user has agreed to a site policy if there is one - do not test in case of admins
if (!$USER->policyagreed and !is_siteadmin()) {
if (!empty($CFG->sitepolicy) and !isguestuser()) {
if ($preventredirect) {
throw new require_login_exception('Policy not agreed');
}
$SESSION->wantsurl = $FULLME;
redirect($CFG->wwwroot .'/user/policy.php');
} else if (!empty($CFG->sitepolicyguest) and isguestuser()) {
if ($preventredirect) {
throw new require_login_exception('Policy not agreed');
}
$SESSION->wantsurl = $FULLME;
redirect($CFG->wwwroot .'/user/policy.php');
}

View File

@ -25,35 +25,42 @@
require_once('../config.php');
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->libdir.'/resourcelib.php');
$agree = optional_param('agree', 0, PARAM_BOOL);
$url = new moodle_url('/user/policy.php');
if ($agree !== 0) {
$url->param('agree', $agree);
}
$PAGE->set_url($url);
$PAGE->set_url('/user/policy.php');
define('MESSAGE_WINDOW', true); // This prevents the message window coming up
define('MESSAGE_WINDOW', true); // This prevents the message window coming up - TODO: this is a hack! (skodak)
if (!isloggedin()) {
require_login();
}
if (isguestuser()) {
$sitepolicy = $CFG->sitepolicyguest;
} else {
$sitepolicy = $CFG->sitepolicy;
}
if (!empty($SESSION->wantsurl)) {
$return = $SESSION->wantsurl;
} else {
$return = $CFG->wwwroot.'/';
}
if (empty($sitepolicy)) {
// nothing to agree to, sorry, hopefully we will not get to infinite loop
redirect($return);
}
if ($agree and confirm_sesskey()) { // User has agreed
if (!isguestuser()) { // Don't remember guests
$DB->set_field('user', 'policyagreed', 1, array('id'=>$USER->id));
}
$USER->policyagreed = 1;
if (!empty($SESSION->wantsurl)) {
$wantsurl = $SESSION->wantsurl;
unset($SESSION->wantsurl);
redirect($wantsurl);
} else {
redirect($CFG->wwwroot.'/');
}
exit;
unset($SESSION->wantsurl);
redirect($return);
}
$strpolicyagree = get_string('policyagree');
@ -68,17 +75,18 @@ $PAGE->navbar->add($strpolicyagreement);
echo $OUTPUT->header();
echo $OUTPUT->heading($strpolicyagreement);
$mimetype = mimeinfo('type', $CFG->sitepolicy);
$mimetype = mimeinfo('type', $sitepolicy);
if ($mimetype == 'document/unknown') {
//fallback for missing index.php, index.html
$mimetype = 'text/html';
}
echo '<div class="noticebox">';
echo '<object id="policyframe" data="'.$CFG->sitepolicy.'" type="'.$mimetype.'">';
// we can not use our popups here, because the url may be arbitrary, see MDL-9823
echo '<a href="'.$CFG->sitepolicy.'" onclick="this.target=\'_blank\'">'.$strpolicyagreementclick.'</a>';
echo '</object></div>';
$clicktoopen = '<a href="'.$sitepolicy.'" onclick="this.target=\'_blank\'">'.$strpolicyagreementclick.'</a>';
echo '<div class="noticebox">';
echo resourcelib_embed_general($sitepolicy, $strpolicyagreement, $clicktoopen, $mimetype);
echo '</div>';
$formcontinue = new single_button(new moodle_url('policy.php', array('agree'=>1)), get_string('yes'));
$formcancel = new single_button(new moodle_url($CFG->wwwroot.'/login/logout.php', array('agree'=>0)), get_string('no'));

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2010100600; // YYYYMMDD = date of the last version bump
$version = 2010100900; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 RC1 (Build: 20101009)'; // Human-friendly version name