Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-rowe committed Jul 22, 2013
1 parent 412aab4 commit 0424453
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 4 deletions.
4 changes: 0 additions & 4 deletions README.md

This file was deleted.

33 changes: 33 additions & 0 deletions lang/en/local_configlogemailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* This plugin sends an email to a specified user after
* it has detected a config setting was changed when
* running cron. The to and from email addresses can
* be changed in the settings page.
*
* @package local
* @subpackage configlogemailer
* @copyright 2013 Alex Rowe - Study Group
* @author Alex Rowe [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['pluginname'] = 'Config Log Emailer';
$string['subject'] = 'There have been Moodle Site config changes';
$string['messagetext'] = 'Changes made on: {$a}
Date | Name | Plugin | Setting | New Value | Old Value
';
$string['to_email_title'] = 'Send to email';
$string['to_email_description'] = 'Who do you want to send the email to';
$string['to_email_default'] = '{$a}';
$string['from_email_title'] = 'Send from email';
$string['from_email_description'] = 'Who do you want to send the email from';
$string['from_email_default'] = '{$a}';
$string['from_firstname_title'] = 'Send from firstname';
$string['from_firstname_description'] = 'What is the first name of the sender';
$string['from_firstname_default'] = '{$a}';
$string['from_lastname_title'] = 'Send from lastname';
$string['from_lastname_description'] = 'What is the last name of the sender';
$string['from_lastname_default'] = '{$a}';
61 changes: 61 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* This plugin sends an email to a specified user after
* it has detected a config setting was changed when
* running cron. The to and from email addresses can
* be changed in the settings page.
*
* @package local
* @subpackage configlogemailer
* @copyright 2013 Alex Rowe - Study Group
* @author Alex Rowe [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

function local_configlogemailer_cron() {
global $CFG, $DB;

// Create the from and to users
$from = get_admin();
$to = get_admin();
// Overwrite the email address with the local plugin settings
$to->email = get_config('local_configlogemailer','to_email');
// Check when the last cron was run, if it was the first time, then make it the current time
$lastcron = get_config('local_configlogemailer','lastcron');
if (empty($lastcron)) {
$lastcron = time();
}

$from->email = get_config('local_configlogemailer','from_email');
$from->firstname = get_config('local_configlogemailer','from_firstname');
$from->lastname = get_config('local_configlogemailer','from_lastname');

$subject = get_string('subject', 'local_configlogemailer');
$messagetext = get_string('messagetext', 'local_configlogemailer',$CFG->wwwroot)

$sql = "SELECT u.firstname, u.lastname, cl.timemodified, cl.plugin, cl.name, cl.value, cl.oldvalue
FROM {config_log} cl
JOIN {user} u ON u.id = cl.userid
WHERE cl.timemodified >= $lastcron
ORDER BY cl.timemodified DESC";
$rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
foreach ($rs as $log) {
$messagetext .= date('Y-m-d H:i:s', $log->timemodified) . ' | ';
$messagetext .= $log->firstname . ' ' . $log->lastname . ' | ';
if (is_null($log->plugin)) {
$plugin = 'core';
} else {
$plugin = $log->plugin;
}
$messagetext .= $plugin . ' | ';
$messagetext .= $log->name . ' | ';
$messagetext .= $log->value . ' | ';
$messagetext .= $log->oldvalue . '
';
}
$rs->close();
email_to_user($to, $from, $subject, $messagetext);
}
}
Binary file added pix/icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
moodle-local_configlogemailer

Moodle local plugin to email config log updates

This plugin sends an email to a specified user after
it has detected a config setting was changed when
running cron. The to and from email addresses can
be changed in the settings page.

@package local
@subpackage configlogemailer
@copyright 2013 Alex Rowe - Study Group
@author Alex Rowe [email protected]
@license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Install into /local/

Version 1.0 (2013072200)

Required Moodle 2.4
38 changes: 38 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
defined('MOODLE_INTERNAL') || die;

if ($hassiteconfig) {

$from = get_admin();

$settings = new admin_settingpage('local_configlogemailer', 'Config Log Emailer');
$ADMIN->add('localplugins', $settings);

$name = 'local_configlogemailer/to_email';
$title = get_string('to_email_title','local_configlogemailer');
$description = get_string('to_email_description','local_configlogemailer');
$default = get_string('to_email_default','local_configlogemailer');
$setting = new admin_setting_configtext($name, $title, $description, $default);
$settings->add($setting);

$name = 'local_configlogemailer/from_email';
$title = get_string('from_email_title','local_configlogemailer');
$description = get_string('from_email_description','local_configlogemailer');
$default = get_string('from_email_default','local_configlogemailer',$from->email);
$setting = new admin_setting_configtext($name, $title, $description, $default);
$settings->add($setting);

$name = 'local_configlogemailer/from_firstname';
$title = get_string('from_firstname_title','local_configlogemailer');
$description = get_string('from_firstname_description','local_configlogemailer');
$default = get_string('from_firstname_default','local_configlogemailer',$from->firstname);
$setting = new admin_setting_configtext($name, $title, $description, $default);
$settings->add($setting);

$name = 'local_configlogemailer/from_lastname';
$title = get_string('from_lastname_title','local_configlogemailer');
$description = get_string('from_lastname_description','local_configlogemailer');
$default = get_string('from_lastname_default','local_configlogemailer',$from->lastname);
$setting = new admin_setting_configtext($name, $title, $description, $default);
$settings->add($setting);
}
17 changes: 17 additions & 0 deletions version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* This plugin sends an email to a specified user after
* it has detected a config setting was changed when
* running cron. The to and from email addresses can
* be changed in the settings page.
*
* @package local
* @subpackage configlogemailer
* @copyright 2013 Alex Rowe - Study Group
* @author Alex Rowe [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$plugin->version = 2013072200; // The (date) version of this plugin
$plugin->requires = 2012120300; // Requires this Moodle version

0 comments on commit 0424453

Please sign in to comment.