Customising Site Policy

Customising Site Policy

by John Mc Hale -
Number of replies: 1

Hi Moodle Developers,

I am customising the functionality of Moodle (Windows Server 2003, Apache 2.2.x, PHP 5.1.6, MySQL 5.0.x), so that when users Accept or Reject the site policy (...Administration...Configuration...Variables...Users...sitepolicy), an appropriate event is written to the moodle event log.

Not being too familiar with PHP, I have given it my best stab, and am looking for some expert input about the way I have gone about this:

I modified line 46 of /user/policy.php to read:

notice_yesno($strpolicyagree, "accept.php?agree=1&amp", "accept.php?agree=0&amp");

Next I created a new PHP script /user/accept.php:

<?php // $Id: accept.php,v 1.6 2007/02/16 09:42:53 moodler Exp $

require_once("../config.php");

$agree = required_param('agree', PARAM_INT);

define('MESSAGE_WINDOW', true); // This prevents the message window coming up

if (!isset($USER->id)) {

require_login();

}

$acceptstatus = ($agree == 1 ? 'policyaccepted' : 'policydeclined' );

if (! ($course = get_record('course', 'id', 1)) ) {

error('Invalid course id');

}

add_to_log(1, 'sitepolicy', $acceptstatus, "accept.php?agree=$agree", "$course->fullname");

$redirecturl = ($agree == 1 ? "policy.php?agree=1&amp;sesskey=$USER->sesskey" : $CFG->wwwroot . '/');

redirect($redirecturl);

exit;

?>

Then I edited /lang/en_utf8/moodle.php and included 2 new strings:

$string['policyaccepted'] = 'Policy Accepted';

$string['policydeclined'] = 'Policy Declined';

Finally, I inserted 2 additional lines of code in /course/report/log/lib.php after line 121:

'policyaccepted' => get_string('policyaccepted'),
'policydeclined' => get_string('policydeclined'),

This strategy appears to work, but i'm wondering if:

  1. I have done anything to cause memory leaks etc.
  2. There is a better way of doing this.

Thanks smile

Average of ratings: -