1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* This plugin sends users a welcome message after logging in
|
|
|
19 |
* and notify a moderator a new user has been added
|
|
|
20 |
* it has a settings page that allow you to configure the messages
|
|
|
21 |
* send.
|
|
|
22 |
*
|
|
|
23 |
* @package local
|
|
|
24 |
* @subpackage welcome
|
|
|
25 |
* @copyright 2017 Bas Brands, basbrands.nl, bas@sonsbeekmedia.nl
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
*/
|
|
|
28 |
|
|
|
29 |
namespace local_welcome;
|
|
|
30 |
|
|
|
31 |
defined('MOODLE_INTERNAL') || die();
|
|
|
32 |
|
|
|
33 |
class observer {
|
|
|
34 |
|
|
|
35 |
public static function send_welcome(\core\event\user_created $event) {
|
|
|
36 |
global $CFG, $SITE;
|
|
|
37 |
|
|
|
38 |
$eventdata = $event->get_data();
|
|
|
39 |
|
|
|
40 |
$user = \core_user::get_user($eventdata['objectid']);
|
|
|
41 |
|
|
|
42 |
$sender = get_admin();
|
|
|
43 |
|
|
|
44 |
// Sender can be false when unit tests are running.
|
|
|
45 |
if ($sender === false) {
|
|
|
46 |
return;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
if (!empty($user->email)) {
|
|
|
50 |
|
|
|
51 |
$config = get_config('local_welcome');
|
|
|
52 |
|
|
|
53 |
$moderator = clone($sender);
|
|
|
54 |
|
|
|
55 |
if (!empty($config->auth_plugins)) {
|
|
|
56 |
$auths = explode(',', $config->auth_plugins);
|
|
|
57 |
if (!in_array($user->auth, $auths)) {
|
|
|
58 |
return '';
|
|
|
59 |
}
|
|
|
60 |
} else {
|
|
|
61 |
return '';
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
$moderator->email = $config->moderator_email;
|
|
|
65 |
|
|
|
66 |
$sender->email = $config->sender_email;
|
|
|
67 |
$sender->firstname = $config->sender_firstname;
|
|
|
68 |
$sender->lastname = $config->sender_lastname;
|
|
|
69 |
|
|
|
70 |
$messageuserenabled = $config->message_user_enabled;
|
|
|
71 |
$messageuser = $config->message_user;
|
|
|
72 |
$messageusersubject = $config->message_user_subject;
|
|
|
73 |
|
|
|
74 |
$messagemoderatorenabled = $config->message_moderator_enabled;
|
|
|
75 |
$messagemoderator = $config->message_moderator;
|
|
|
76 |
$messagemoderatorsubject = $config->message_moderator_subject;
|
|
|
77 |
|
|
|
78 |
$welcome = new \local_welcome\message();
|
|
|
79 |
|
|
|
80 |
$messageuser = $welcome->replace_values($user, $messageuser);
|
|
|
81 |
$messageusersubject = $welcome->replace_values($user, $messageusersubject);
|
|
|
82 |
$messagemoderator = $welcome->replace_values($user, $messagemoderator);
|
|
|
83 |
$messagemoderatorsubject = $welcome->replace_values($user, $messagemoderatorsubject);
|
|
|
84 |
|
|
|
85 |
if (!empty($messageuser) && !empty($sender->email) && $messageuserenabled) {
|
|
|
86 |
email_to_user($user, $sender, $messageusersubject, html_to_text($messageuser), $messageuser);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
if (!empty($messagemoderator) && !empty($sender->email) && $messagemoderatorenabled) {
|
|
|
90 |
email_to_user($moderator, $sender, $messagemoderatorsubject,
|
|
|
91 |
html_to_text($messagemoderator), $messagemoderator);
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
}
|