-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
61 lines (55 loc) · 2.23 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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);
}
}