public function execute()
 {
     global $USER;
     // Check to make sure external communications hasn't been disabled
     $extcom = !!get_config('mod_hvp', 'external_communication');
     $extcomnotify = !!get_config('mod_hvp', 'external_communication_notify');
     if ($extcom || !$extcomnotify) {
         $core = \mod_hvp\framework::instance();
         $core->fetchLibrariesMetadata(!$extcom);
         set_config('external_communication_notify', $extcom ? false : time(), 'mod_hvp');
         // Notify admin if there are updates available!
         $update_available = \get_config('mod_hvp', 'update_available');
         $current_update = \get_config('mod_hvp', 'current_update');
         $admin_notified = \get_config('mod_hvp', 'admin_notified');
         if ($admin_notified !== $update_available && $update_available !== false && $current_update !== false && $current_update < $update_available) {
             // New update is available
             // Send message
             $updatesurl = new \moodle_url('/mod/hvp/library_list.php');
             $message = new \stdClass();
             $message->component = 'mod_hvp';
             $message->name = 'updates';
             $message->userfrom = $USER;
             $message->userto = get_admin();
             $message->subject = get_string('updatesavailabletitle', 'mod_hvp');
             $message->fullmessage = get_string('updatesavailablemsgpt1', 'mod_hvp') . ' ' . get_string('updatesavailablemsgpt2', 'mod_hvp') . "\n\n" . get_string('updatesavailablemsgpt3', 'mod_hvp', date('Y-m-d', $update_available)) . "\n" . get_string('updatesavailablemsgpt4', 'mod_hvp', date('Y-m-d', $current_update)) . "\n\n" . $updatesurl;
             $message->fullmessageformat = FORMAT_PLAIN;
             $message->fullmessagehtml = '<p>' . get_string('updatesavailablemsgpt1', 'mod_hvp') . '<br/>' . get_string('updatesavailablemsgpt2', 'mod_hvp') . '</p>' . '<p>' . get_string('updatesavailablemsgpt3', 'mod_hvp', '<b>' . date('Y-m-d', $update_available) . '</b>') . '<br/>' . get_string('updatesavailablemsgpt4', 'mod_hvp', '<b>' . date('Y-m-d', $current_update) . '</b>') . '</p>' . '<a href="' . $updatesurl . '" target="_blank">' . $updatesurl . '</a>';
             $message->smallmessage = '';
             $message->notification = 1;
             message_send($message);
             // Keep track of which version we've notfied about
             \set_config('admin_notified', $update_available, 'mod_hvp');
         }
     }
 }
예제 #2
0
/**
 *
 * Sends message to administrator listing all updated
 * duplicate custom fields
 * @param array $data
 */
function facetoface_send_admin_upgrade_msg($data)
{
    global $SITE;
    // No data - no need to send email.
    if (empty($data)) {
        return;
    }
    $table = new html_table();
    $table->head = array('Custom field ID', 'Custom field original shortname', 'Custom field new shortname');
    $table->data = $data;
    $table->align = array('center', 'center', 'center');
    $title = "{$SITE->fullname}: Face to Face upgrade info";
    $note = 'During the last site upgrade the face-to-face module has been modified. It now
requires session custom fields to have unique shortnames. Since some of your
custom fields had duplicate shortnames, they have been renamed to remove
duplicates (see table below). This could impact on your email messages if you
reference those custom fields in the message templates.';
    $message = html_writer::start_tag('html');
    $message .= html_writer::start_tag('head') . html_writer::tag('title', $title) . html_writer::end_tag('head');
    $message .= html_writer::start_tag('body');
    $message .= html_writer::tag('p', $note) . html_writer::table($table, true);
    $message .= html_writer::end_tag('body');
    $message .= html_writer::end_tag('html');
    $admin = get_admin();
    email_to_user($admin, $admin, $title, '', $message);
}
예제 #3
0
/**
 * EditPDF upgrade code
 * @param int $oldversion
 * @return bool
 */
function xmldb_assignfeedback_editpdf_upgrade($oldversion)
{
    global $CFG;
    if ($oldversion < 2013110800) {
        // Check that no stamps where uploaded.
        $fs = get_file_storage();
        $stamps = $fs->get_area_files(context_system::instance()->id, 'assignfeedback_editpdf', 'stamps', 0, "filename", false);
        // Add default stamps.
        if (empty($stamps)) {
            // List of default stamps.
            $defaultstamps = array('smile.png', 'sad.png', 'tick.png', 'cross.png');
            // Stamp file object.
            $filerecord = new stdClass();
            $filerecord->component = 'assignfeedback_editpdf';
            $filerecord->contextid = context_system::instance()->id;
            $filerecord->userid = get_admin()->id;
            $filerecord->filearea = 'stamps';
            $filerecord->filepath = '/';
            $filerecord->itemid = 0;
            // Add all default stamps.
            foreach ($defaultstamps as $stamp) {
                $filerecord->filename = $stamp;
                $fs->create_file_from_pathname($filerecord, $CFG->dirroot . '/mod/assign/feedback/editpdf/pix/' . $filerecord->filename);
            }
        }
        upgrade_plugin_savepoint(true, 2013110800, 'assignfeedback', 'editpdf');
    }
    // Moodle v2.6.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
예제 #4
0
function notify_user($user, $subject, $a)
{
    if (!$user) {
        return false;
    }
    $body = get_string('virusfoundlater', 'moodle', $a);
    email_to_user($user, get_admin(), $subject, $body);
}
예제 #5
0
function is_valid_admin_login($username, $password)
{
    $token = get_admin($username);
    if ($token['password'] == $password) {
        return TRUE;
    } else {
        return FALSE;
    }
}
 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . "/mod/turnitintooltwo/lib.php";
     require_once $CFG->dirroot . "/mod/turnitintooltwo/turnitintooltwo_view.class.php";
     $data = (array) $this->get_custom_data();
     // Make sure we are still wanted.
     $submission = $DB->get_record('turnitintooltwo_submissions', array('id' => $data['submissionid']));
     if (!$submission) {
         return true;
     }
     cli_writeln("Processing Turnitintooltwo submission: " . $data['submissionid']);
     $user = $DB->get_record('user', array('id' => $data['userid']));
     \core\session\manager::set_user($user);
     $turnitintooltwo = $DB->get_record('turnitintooltwo', array('id' => $data['tiiid']));
     list($course, $cm) = get_course_and_cm_from_instance($turnitintooltwo, 'turnitintooltwo');
     try {
         $turnitintooltwoassignment = new \turnitintooltwo_assignment($turnitintooltwo->id, $turnitintooltwo);
         $turnitintooltwosubmission = new \turnitintooltwo_submission($data['submissionid'], "moodle", $turnitintooltwoassignment);
         $parts = $turnitintooltwoassignment->get_parts();
         $tiisubmission = $turnitintooltwosubmission->do_tii_submission($cm, $turnitintooltwoassignment);
         // Update submission.
         $DB->update_record('turnitintooltwo_submissions', array('id' => $data['submissionid'], 'submission_modified' => $data['subtime']));
     } catch (\Exception $e) {
         $tiisubmission = array('success' => false, 'message' => $e->getMessage());
         cli_writeln($e->getMessage());
     }
     $digitalreceipt = $tiisubmission;
     $digitalreceipt['is_manual'] = 0;
     $digitalreceipt = json_encode($digitalreceipt);
     $this->update_sub_status($data['submissionid'], $tiisubmission['success'], $digitalreceipt);
     if ($tiisubmission['success'] === true) {
         $lockedassignment = new \stdClass();
         $lockedassignment->id = $turnitintooltwoassignment->turnitintooltwo->id;
         $lockedassignment->submitted = 1;
         $DB->update_record('turnitintooltwo', $lockedassignment);
         $lockedpart = new \stdClass();
         $lockedpart->id = $data['submissionpart'];
         $lockedpart->submitted = 1;
         // Disable anonymous marking if post date has passed.
         if ($parts[$data['submissionpart']]->dtpost <= time()) {
             $lockedpart->unanon = 1;
         }
         $DB->update_record('turnitintooltwo_parts', $lockedpart);
         cli_writeln("Finished processing successful submission: " . $data['submissionid']);
     } else {
         turnitintooltwo_add_to_log($course->id, "errored submission", 'view.php?id=' . $cm->id, "Failed to submit '" . $turnitintooltwosubmission->submission_title . "'", $cm->id, $user->id, array('submissionid' => $data['submissionid']));
         cli_writeln("Finished processing unsuccessful submission: " . $data['submissionid']);
     }
     \core\session\manager::set_user(get_admin());
     return $tiisubmission['success'];
 }
예제 #7
0
/**
 * This function returns the icon (from theme) with the link to rss/file.php
 *
 * @global object
 * @global object
 */
function rss_get_link($courseid, $userid, $modulename, $id, $tooltiptext = '')
{
    global $OUTPUT;
    static $rsspath = '';
    //In site course, if no logged (userid), use admin->id. Bug 2048.
    if ($courseid == SITEID and empty($userid)) {
        $admin = get_admin();
        $userid = $admin->id;
    }
    $rsspath = rss_get_url($courseid, $userid, $modulename, $id);
    $rsspix = $OUTPUT->old_icon_url('i/rss');
    return '<a href="' . $rsspath . '"><img src="' . $rsspix . '" title="' . strip_tags($tooltiptext) . '" alt="' . get_string('rss') . '" /></a>';
}
 /**
  *
  */
 public static function notification_definition($mform, $dataformid, $prefix = null)
 {
     global $DB;
     $paramtext = !empty($CFG->formatstringstriptags) ? PARAM_TEXT : PARAM_CLEAN;
     $mform->addElement('header', 'messagehdr', get_string('message', 'message'));
     $mform->setExpanded('messagehdr');
     // Message type.
     $options = array(0 => get_string('notification', 'dataform'), 1 => get_string('conversation', 'dataform'));
     $mform->addElement('select', $prefix . 'messagetype', get_string('type', 'dataform'), $options);
     // Subject.
     $mform->addElement('text', $prefix . 'subject', get_string('subject', 'dataform'));
     $mform->setType($prefix . 'subject', $paramtext);
     // Content.
     $mform->addElement('textarea', $prefix . 'contenttext', get_string('content'));
     $mform->setType($prefix . 'contenttext', $paramtext);
     // Content from view.
     $options = array('' => get_string('choosedots'));
     if ($items = \mod_dataform_view_manager::instance($dataformid)->views_menu) {
         $items = array_combine($items, $items);
         $options = array_merge($options, $items);
     }
     $label = get_string('contentview', 'mod_dataform');
     $mform->addElement('select', $prefix . 'contentview', $label, $options);
     // Format.
     $options = array(FORMAT_PLAIN => get_string('formatplain'), FORMAT_HTML => get_string('formathtml'));
     $mform->addElement('select', $prefix . 'messageformat', get_string('format'), $options);
     // Sender: Entry author, manager.
     $mform->addElement('header', 'senderhdr', get_string('sender', 'mod_dataform'));
     $mform->setExpanded('senderhdr');
     $admin = get_admin();
     $options = array(\core_user::NOREPLY_USER => get_string('noreply', 'dataform'), \core_user::SUPPORT_USER => get_string('supportcontact', 'admin'), $admin->id => get_string('admin'), 'author' => get_string('author', 'dataform'), 'event' => get_string('event', 'dataform'));
     $mform->addElement('select', $prefix . 'sender', get_string('from'), $options);
     // Recipient.
     $mform->addElement('header', 'recipientshdr', get_string('recipient', 'mod_dataform'));
     $mform->setExpanded('recipientshdr');
     // Admin.
     $mform->addElement('advcheckbox', $prefix . 'recipient[admin]', get_string('admin'));
     // Support.
     $mform->addElement('advcheckbox', $prefix . 'recipient[support]', get_string('supportcontact', 'admin'));
     // Entry author.
     $mform->addElement('advcheckbox', $prefix . 'recipient[author]', get_string('author', 'dataform'));
     // Role (mod/dataform:notification permission in context).
     $mform->addElement('advcheckbox', $prefix . 'recipient[role]', get_string('role'));
     // Username (comma delimited).
     $mform->addElement('text', $prefix . 'recipient[username]', get_string('username'));
     $mform->setType($prefix . 'recipient[username]', $paramtext);
     // Email (comma delimited).
     $mform->addElement('text', $prefix . 'recipient[email]', get_string('email'));
     $mform->setType($prefix . 'recipient[email]', $paramtext);
 }
예제 #9
0
/**
 * Theme_mimoodle install function.
 *
 * @return void
 */
function xmldb_theme_evolved_install()
{
    global $CFG;
    // Set the default background.
    $fs = get_file_storage();
    $filerecord = new stdClass();
    $filerecord->component = 'theme_evolved';
    $filerecord->contextid = context_system::instance()->id;
    $filerecord->userid = get_admin()->id;
    $filerecord->filearea = 'backgroundimage';
    $filerecord->filepath = '/';
    $filerecord->itemid = 0;
    $filerecord->filename = 'background.png';
    $fs->create_file_from_pathname($filerecord, $CFG->dirroot . '/theme/evolved/pix/background.png');
}
function local_enrolmentreminder_send_messages($events)
{
    global $DB;
    global $CFG;
    require_once $CFG->libdir . '/completionlib.php';
    $eventdata = new stdClass();
    $eventdata->component = 'local_enrolmentreminder';
    // plugin name
    $eventdata->name = 'enrolmentending';
    // message interface name
    $eventdata->userfrom = get_admin();
    $dateformat = '%b %e';
    if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
        $dateformat = '%b %#d';
    }
    foreach ($events as $event) {
        $course = $DB->get_record('course', array('id' => $event->courseid));
        $user = $DB->get_record('user', array('id' => $event->userid));
        if (empty($completioninfo[$event->courseid])) {
            $completioninfo[$event->courseid] = new completion_info($course);
        }
        if ($completioninfo[$event->courseid]->is_course_complete($event->userid)) {
            mtrace("user {$event->userid} has completed course {$event->courseid}");
            continue;
        }
        // use timeend for enrolments, timestart for events.
        $ending = userdate($event->timeend, $dateformat);
        $eventdata->fullmessage = local_enrolmentreminder_get_message_plaintext($course, $user, $ending, $event->reminderid);
        if (empty($eventdata->fullmessage)) {
            mtrace("eventdata->fullmessage is empty");
        }
        if (!empty($eventdata->fullmessage)) {
            $eventdata->subject = $course->shortname . ' ending ' . $ending;
            $eventdata->smallmessage = $course->fullname . ' ending ' . $ending;
            $eventdata->fullmessagehtml = '';
            $eventdata->fullmessageformat = FORMAT_PLAIN;
            $eventdata->notification = 1;
            $eventdata->userto = $user;
            // $eventdata->userto = get_admin();
            $mailresult = message_send($eventdata);
            mtrace("sent message with result {$mailresult}: " . print_r($eventdata, true));
            $params = array('context' => context_course::instance($event->courseid), 'objectid' => $course->id, 'relateduserid' => $event->userid);
            $msg_event = \local_enrolmentreminder\event\message_sent::create($params);
            $msg_event->trigger();
        }
    }
}
예제 #11
0
function notify_user($user, $subject, $a)
{
    if (!$user) {
        return false;
    }
    $body = get_string('virusfoundlater', 'moodle', $a);
    $eventdata = new stdClass();
    $eventdata->modulename = 'moodle';
    $eventdata->userfrom = get_admin();
    $eventdata->userto = $user;
    $eventdata->subject = $subject;
    $eventdata->fullmessage = $body;
    $eventdata->fullmessageformat = FORMAT_PLAIN;
    $eventdata->fullmessagehtml = '';
    $eventdata->smallmessage = '';
    message_send($eventdata);
}
/**
 * This plugin sends users a welcome message after logging in
 * and notify a moderator a new user has been added
 * it has a settings page that allow you to configure the messages
 * send.
 *
 * @package    local
 * @subpackage welcome
 * @copyright  2014 Bas Brands, basbrands.nl, bas@sonsbeekmedia.nl
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function send_welcome($user)
{
    global $CFG, $SITE;
    $moderator = get_admin();
    $sender = get_admin();
    if (!empty($user->email)) {
        $config = get_config('local_welcome');
        if (!empty($config->auth_plugins)) {
            $auths = explode(',', $config->auth_plugins);
            if (!in_array($user->auth, $auths)) {
                return '';
            }
        } else {
            return '';
        }
        $moderator->email = $config->moderator_email;
        $sender->email = $config->sender_email;
        $sender->firstname = $config->sender_firstname;
        $sender->lastname = $config->sender_lastname;
        $message_user_enabled = $config->message_user_enabled;
        $message_user = $config->message_user;
        $message_user_subject = $config->message_user_subject;
        $message_moderator_enabled = $config->message_moderator_enabled;
        $message_moderator = $config->message_moderator;
        $message_moderator_subject = $config->message_moderator_subject;
        if (!empty($user->country)) {
            $user->country = get_string($user->country, 'countries');
        } else {
            $user->country = '';
        }
        $sitelink = html_writer::link(new moodle_url('/'), $SITE->fullname);
        $resetpasswordlink = html_writer::link(new moodle_url('/login/forgot_password.php'), get_string('resetpass', 'local_welcome'));
        $fields = array('[[fullname]]', '[[username]]', '[[firstname]]', '[[lastname]]', '[[email]]', '[[city]]', '[[country]]', '[[sitelink]]', '[[sitename]]', '[[resetpasswordlink]]');
        $values = array(fullname($user), $user->username, $user->firstname, $user->lastname, $user->email, $user->city, $user->country, $sitelink, $SITE->fullname, $resetpasswordlink);
        $message_user = str_replace($fields, $values, $message_user);
        $message_user_subject = str_replace($fields, $values, $message_user_subject);
        $message_moderator = str_replace($fields, $values, $message_moderator);
        $message_moderator_subject = str_replace($fields, $values, $message_moderator_subject);
        if (!empty($message_user) && !empty($sender->email) && $message_user_enabled) {
            email_to_user($user, $sender, $message_user_subject, html_to_text($message_user), $message_user);
        }
        if (!empty($message_moderator) && !empty($sender->email) && $message_moderator_enabled) {
            email_to_user($moderator, $sender, $message_moderator_subject, html_to_text($message_moderator), $message_moderator);
        }
    }
}
예제 #13
0
 public function execute()
 {
     global $CFG;
     require_once "{$CFG->libdir}/datalib.php";
     $user = get_admin();
     if (!$user) {
         cli_error("Unable to find admin user in DB.");
     }
     $auth = empty($user->auth) ? 'manual' : $user->auth;
     if ($auth == 'nologin' or !is_enabled_auth($auth)) {
         cli_error(sprintf("User authentication is either 'nologin' or disabled. Check Moodle authentication method for '%s'", $user->username));
     }
     $authplugin = get_auth_plugin($auth);
     $authplugin->sync_roles($user);
     login_attempt_valid($user);
     complete_user_login($user);
     printf("%s:%s\n", session_name(), session_id());
 }
 /**
  * Send non-submitters message to students.
  *
  * @param string $message
  * @return void
  */
 public function send_message($userid, $subject, $message)
 {
     $eventdata = new stdClass();
     $eventdata->component = 'mod_turnitintooltwo';
     //your component name
     $eventdata->name = 'nonsubmitters';
     //this is the message name from messages.php
     $eventdata->userfrom = get_admin();
     $eventdata->userto = $userid;
     $eventdata->subject = $subject;
     $eventdata->fullmessage = $message;
     $eventdata->fullmessageformat = FORMAT_HTML;
     $eventdata->fullmessagehtml = $message;
     $eventdata->smallmessage = '';
     $eventdata->notification = 1;
     //this is only set to 0 for personal messages between users
     message_send($eventdata);
 }
예제 #15
0
/**
 * Emails admins about a clam outcome
 *
 * @param string $notice The body of the email to be sent.
 */
function clam_message_admins($notice)
{
    $site = get_site();
    $subject = get_string('clamemailsubject', 'moodle', format_string($site->fullname));
    $admins = get_admins();
    foreach ($admins as $admin) {
        $eventdata = new stdClass();
        $eventdata->component = 'moodle';
        $eventdata->name = 'errors';
        $eventdata->userfrom = get_admin();
        $eventdata->userto = $admin;
        $eventdata->subject = $subject;
        $eventdata->fullmessage = $notice;
        $eventdata->fullmessageformat = FORMAT_PLAIN;
        $eventdata->fullmessagehtml = '';
        $eventdata->smallmessage = '';
        message_send($eventdata);
    }
}
예제 #16
0
/**
 * Theme_more upgrade function.
 *
 * @param  int $oldversion The version we upgrade from.
 * @return bool
 */
function xmldb_theme_more_upgrade($oldversion)
{
    global $CFG;
    if ($oldversion < 2014032400) {
        // Set the default background. If an image is already there then ignore.
        $fs = get_file_storage();
        $bg = $fs->get_area_files(context_system::instance()->id, 'theme_more', 'backgroundimage', 0);
        // Add default background image.
        if (empty($bg)) {
            $filerecord = new stdClass();
            $filerecord->component = 'theme_more';
            $filerecord->contextid = context_system::instance()->id;
            $filerecord->userid = get_admin()->id;
            $filerecord->filearea = 'backgroundimage';
            $filerecord->filepath = '/';
            $filerecord->itemid = 0;
            $filerecord->filename = 'background.jpg';
            $fs->create_file_from_pathname($filerecord, $CFG->dirroot . '/theme/more/pix/background.jpg');
        }
        upgrade_plugin_savepoint(true, 2014032400, 'theme', 'more');
    }
    if ($oldversion < 2014032401) {
        // Set the default settings as they might already be set.
        set_config('textcolor', '#333366', 'theme_more');
        set_config('linkcolor', '#FF6500', 'theme_more');
        set_config('backgroundrepeat', 'repeat', 'theme_more');
        set_config('contentbackground', '#FFFFFF', 'theme_more');
        set_config('secondarybackground', '#FFFFFF', 'theme_more');
        set_config('invert', 1, 'theme_more');
        set_config('backgroundimage', '/background.jpg', 'theme_more');
        upgrade_plugin_savepoint(true, 2014032401, 'theme', 'more');
    }
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.0.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
예제 #17
0
/**
 * EditPDF install code
 */
function xmldb_setaskfeedback_editpdf_install()
{
    global $CFG;
    // List of default stamps.
    $defaultstamps = array('smile.png', 'sad.png', 'tick.png', 'cross.png');
    // Stamp file object.
    $filerecord = new stdClass();
    $filerecord->component = 'setaskfeedback_editpdf';
    $filerecord->contextid = context_system::instance()->id;
    $filerecord->userid = get_admin()->id;
    $filerecord->filearea = 'stamps';
    $filerecord->filepath = '/';
    $filerecord->itemid = 0;
    $fs = get_file_storage();
    // Load all default stamps.
    foreach ($defaultstamps as $stamp) {
        $filerecord->filename = $stamp;
        $fs->create_file_from_pathname($filerecord, $CFG->dirroot . '/mod/setask/feedback/editpdf/pix/' . $filerecord->filename);
    }
}
    protected function process_facetoface_session($data) {
        global $DB, $USER;

        $data = (object)$data;
        $oldid = $data->id;

        $data->facetoface = $this->get_new_parentid('facetoface');

        $data->timecreated = $this->apply_date_offset($data->timecreated);
        $data->timemodified = $this->apply_date_offset($data->timemodified);
        $data->usermodified = isset($USER->id) ? $USER->id : get_admin()->id;

        $rooms = $DB->get_records('facetoface_room', array('name' => $data->room_name,
            'building' => $data->room_building, 'address' => $data->room_address, 'custom' => 0), '', 'id');
        $rooms_found = count($rooms);
        if (!$rooms_found || $data->room_custom) {
            if (!$data->room_custom) {
                debugging("Room [{$data->room_name}, {$data->room_building}, {$data->room_address}] ".
                    "in face to face session does not exist - creating as custom room");
            }
            $customroom = new stdClass();
            $customroom->name = $data->room_name;
            $customroom->building = $data->room_building;
            $customroom->address = $data->room_address;
            $customroom->capacity = $data->capacity;
            $customroom->custom = 1;
            $customroom->timecreated = $data->timecreated;
            $customroom->timemodified = $data->timemodified;
            $data->roomid = $DB->insert_record('facetoface_room', $customroom);
        } else {
            if ($rooms_found > 1) {
                debugging("Room [{$data->room_name}, {$data->room_building}, {$data->room_address}] matches more ".
                    "than one predefined room and we can't identify which - arbitrarily selecting one of them");
            }
            $data->roomid = reset($rooms)->id;
        }

        // insert the entry record
        $newitemid = $DB->insert_record('facetoface_sessions', $data);
        $this->set_mapping('facetoface_session', $oldid, $newitemid, true); // childs and files by itemname
    }
예제 #19
0
 public function test_get_user()
 {
     global $CFG;
     $this->resetAfterTest(true);
     // Create user and try fetach it with api.
     $user = $this->getDataGenerator()->create_user();
     $this->assertEquals($user, core_user::get_user($user->id, '*', MUST_EXIST));
     // Test noreply user.
     $CFG->noreplyuserid = null;
     $noreplyuser = core_user::get_noreply_user();
     $this->assertEquals(1, $noreplyuser->emailstop);
     $this->assertFalse(core_user::is_real_user($noreplyuser->id));
     $this->assertEquals($CFG->noreplyaddress, $noreplyuser->email);
     $this->assertEquals(get_string('noreplyname'), $noreplyuser->firstname);
     // Set user as noreply user and make sure noreply propery is set.
     core_user::reset_internal_users();
     $CFG->noreplyuserid = $user->id;
     $noreplyuser = core_user::get_noreply_user();
     $this->assertEquals(1, $noreplyuser->emailstop);
     $this->assertTrue(core_user::is_real_user($noreplyuser->id));
     // Test support user.
     core_user::reset_internal_users();
     $CFG->supportemail = null;
     $CFG->noreplyuserid = null;
     $supportuser = core_user::get_support_user();
     $adminuser = get_admin();
     $this->assertEquals($adminuser, $supportuser);
     $this->assertTrue(core_user::is_real_user($supportuser->id));
     // When supportemail is set.
     core_user::reset_internal_users();
     $CFG->supportemail = '*****@*****.**';
     $supportuser = core_user::get_support_user();
     $this->assertEquals(core_user::SUPPORT_USER, $supportuser->id);
     $this->assertFalse(core_user::is_real_user($supportuser->id));
     // Set user as support user and make sure noreply propery is set.
     core_user::reset_internal_users();
     $CFG->supportuserid = $user->id;
     $supportuser = core_user::get_support_user();
     $this->assertEquals($user, $supportuser);
     $this->assertTrue(core_user::is_real_user($supportuser->id));
 }
예제 #20
0
/**
 * Send a message to the admin in regard with the APIv1 migration.
 *
 * @return void
 */
function repository_alfresco_admin_security_key_notice()
{
    $admins = get_admins();
    if (empty($admins)) {
        return;
    }
    foreach ($admins as $admin) {
        $message = new stdClass();
        $message->component = 'moodle';
        $message->name = 'notices';
        $message->userfrom = get_admin();
        $message->userto = $admin;
        $message->smallmessage = get_string('security_key_notice_message_small', 'repository_alfresco');
        $message->subject = get_string('security_key_notice_message_subject', 'repository_alfresco');
        $message->fullmessage = get_string('security_key_notice_message_content', 'repository_alfresco');
        $message->fullmessagehtml = get_string('security_key_notice_message_content', 'repository_alfresco');
        $message->fullmessageformat = FORMAT_PLAIN;
        $message->notification = 1;
        message_send($message);
    }
}
예제 #21
0
파일: util.php 프로젝트: janeklb/moodle
 /**
  * Alerts site admin of potential problems.
  *
  * @param string   $subject email subject
  * @param stdClass $data    PayPal IPN data
  */
 public static function message_paypal_error_to_admin($subject, $data)
 {
     $admin = get_admin();
     $site = get_site();
     $message = "{$site->fullname}:  Transaction failed.\n\n{$subject}\n\n";
     foreach ($data as $key => $value) {
         $message .= "{$key} => {$value}\n";
     }
     $eventdata = new \stdClass();
     $eventdata->modulename = 'moodle';
     $eventdata->component = 'enrol_paypal';
     $eventdata->name = 'paypal_enrolment';
     $eventdata->userfrom = $admin;
     $eventdata->userto = $admin;
     $eventdata->subject = "PAYPAL ERROR: " . $subject;
     $eventdata->fullmessage = $message;
     $eventdata->fullmessageformat = FORMAT_PLAIN;
     $eventdata->fullmessagehtml = '';
     $eventdata->smallmessage = '';
     message_send($eventdata);
 }
예제 #22
0
function xmldb_local_hub_install()
{
    global $DB;
    //create a new scale called featured, at this moment moment we have no alternative than adding it to the DB
    //core TODO: better way to create a scale or adding a scale MDL-21631, MDL-16474
    $scale = new stdClass();
    $scale->courseid = 0;
    $admin = get_admin();
    $scale->userid = empty($admin) ? 2 : $admin->id;
    //if the script is run before an admin has ever been created, assign userid = 2 (usual admin default)
    $scale->name = 'coursefeatured';
    $scale->scale = get_string('featured', 'local_hub');
    $scale->description = get_string('featureddesc', 'local_hub');
    $scale->descriptionformat = 1;
    $scale->timemodified = time();
    $scale->id = $DB->insert_record('scale', $scale);
    //save the scale id into the config table
    set_config('courseratingscaleid', $scale->id, 'local_hub');
    // Set the extendedusernamechars option to true
    set_config('extendedusernamechars', 1);
}
예제 #23
0
 public function find_users($search)
 {
     global $DB, $CFG;
     list($wherecondition, $params) = $this->search_sql($search, '');
     $fields = 'SELECT ' . $this->required_fields_sql('');
     if ($wherecondition) {
         $wherecondition = "{$wherecondition} AND id IN ({$CFG->siteadmins})";
     } else {
         $wherecondition = "id IN ({$CFG->siteadmins})";
     }
     $sql = " FROM {user}\n                WHERE {$wherecondition}";
     list($sort, $sortparams) = users_order_by_sql('', $search, $this->accesscontext);
     $params = array_merge($params, $sortparams);
     $order = ' ORDER BY ' . $sort;
     $availableusers = $DB->get_records_sql($fields . $sql . $order, $params);
     if (empty($availableusers)) {
         return array();
     }
     $mainadmin = array();
     $mainadminuser = get_admin();
     if ($mainadminuser && isset($availableusers[$mainadminuser->id])) {
         $mainadmin = array($mainadminuser->id => $availableusers[$mainadminuser->id]);
         unset($availableusers[$mainadminuser->id]);
     }
     $result = array();
     if ($mainadmin) {
         $result[get_string('mainadmin', 'core_role')] = $mainadmin;
     }
     if ($availableusers) {
         if ($search) {
             $groupname = get_string('extusersmatching', 'core_role', $search);
         } else {
             $groupname = get_string('extusers', 'core_role');
         }
         $result[$groupname] = $availableusers;
     }
     return $result;
 }
예제 #24
0
/**
 * Inform admins about setup required for picasa change.
 */
function portfolio_picasa_admin_upgrade_notification()
{
    $admins = get_admins();
    if (empty($admins)) {
        return;
    }
    $a = new stdClass();
    $a->docsurl = get_docs_url('Google_OAuth_2.0_setup');
    foreach ($admins as $admin) {
        $message = new stdClass();
        $message->component = 'moodle';
        $message->name = 'notices';
        $message->userfrom = get_admin();
        $message->userto = $admin;
        $message->smallmessage = get_string('oauth2upgrade_message_small', 'portfolio_picasa');
        $message->subject = get_string('oauth2upgrade_message_subject', 'portfolio_picasa');
        $message->fullmessage = get_string('oauth2upgrade_message_content', 'portfolio_picasa', $a);
        $message->fullmessagehtml = get_string('oauth2upgrade_message_content', 'portfolio_picasa', $a);
        $message->fullmessageformat = FORMAT_PLAIN;
        $message->notification = 1;
        message_send($message);
    }
}
예제 #25
0
/**
 * Send a message to the admin in regard with the APIv1 migration.
 *
 * @return void
 */
function repository_boxnet_admin_upgrade_notification()
{
    $admins = get_admins();
    if (empty($admins)) {
        return;
    }
    $a = new stdClass();
    $a->docsurl = get_docs_url('Box.net_APIv1_migration');
    foreach ($admins as $admin) {
        $message = new stdClass();
        $message->component = 'moodle';
        $message->name = 'notices';
        $message->userfrom = get_admin();
        $message->userto = $admin;
        $message->smallmessage = get_string('apiv1migration_message_small', 'repository_boxnet');
        $message->subject = get_string('apiv1migration_message_subject', 'repository_boxnet');
        $message->fullmessage = get_string('apiv1migration_message_content', 'repository_boxnet', $a);
        $message->fullmessagehtml = get_string('apiv1migration_message_content', 'repository_boxnet', $a);
        $message->fullmessageformat = FORMAT_PLAIN;
        $message->notification = 1;
        message_send($message);
    }
}
예제 #26
0
/**
 * Sends confirmation email to the student taking the course
 *
 * @param stdClass $a associative array of replaceable fields for the templates
 *
 * @return bool|string result of email_to_user()
 */
function quiz_send_confirmation($a)
{
    global $USER;
    // recipient is self
    $a->useridnumber = $USER->idnumber;
    $a->username = fullname($USER);
    $a->userusername = $USER->username;
    // fetch the subject and body from strings
    $subject = get_string('emailconfirmsubject', 'quiz', $a);
    $body = get_string('emailconfirmbody', 'quiz', $a);
    // send email and analyse result
    return email_to_user($USER, get_admin(), $subject, $body);
}
예제 #27
0
<?php

require '../config.php';
require_once $CFG->libdir . '/eventslib.php';
if ($form = data_submitted()) {
    // form submitted, do not check referer (original page unknown)!
    /// Only deal with real users
    if (!isloggedin()) {
        redirect($CFG->wwwroot);
    }
    /// Work out who to send the message to
    if (!($admin = get_admin())) {
        print_error('cannotfindadmin', 'debug');
    }
    $supportuser = new stdClass();
    $supportuser->email = $CFG->supportemail ? $CFG->supportemail : $admin->email;
    $supportuser->firstname = $CFG->supportname ? $CFG->supportname : $admin->firstname;
    $supportuser->lastname = $CFG->supportname ? '' : $admin->lastname;
    //emailstop could be hard coded "false" to ensure error reports are sent
    //but then admin's would have to alter their messaging preferences to temporarily stop them
    $supportuser->emailstop = $admin->emailstop;
    $supportuser->maildisplay = true;
    /// Send the message and redirect
    $eventdata = new stdClass();
    $eventdata->modulename = 'moodle';
    $eventdata->userfrom = $USER;
    $eventdata->userto = $supportuser;
    $eventdata->subject = 'Error: ' . $form->referer . ' -> ' . $form->requested;
    $eventdata->fullmessage = $form->text;
    $eventdata->fullmessageformat = FORMAT_PLAIN;
    $eventdata->fullmessagehtml = '';
예제 #28
0
 /**
 * Notify users about enrolments that are going to expire soon!
 * This function is run by admin/cron.php
 * @return void
 */
 function cron()
 {
     global $CFG, $USER, $SITE;
     if (!isset($CFG->lastexpirynotify)) {
         set_config('lastexpirynotify', 0);
     }
     // notify once a day only - TODO: add some tz handling here, maybe use timestamps
     if ($CFG->lastexpirynotify == date('Ymd')) {
         return;
     }
     if ($rs = get_recordset_select('course', 'enrolperiod > 0 AND expirynotify > 0 AND expirythreshold > 0')) {
         $cronuser = clone $USER;
         $admin = get_admin();
         while ($course = rs_fetch_next_record($rs)) {
             $a = new object();
             $a->coursename = $course->shortname . '/' . $course->fullname;
             // must be processed by format_string later
             $a->threshold = $course->expirythreshold / 86400;
             $a->extendurl = $CFG->wwwroot . '/user/index.php?id=' . $course->id;
             $a->current = array();
             $a->past = array();
             $expiry = time() + $course->expirythreshold;
             $cname = $course->fullname;
             /// Get all the manual role assignments for this course that have expired.
             if (!($context = get_context_instance(CONTEXT_COURSE, $course->id))) {
                 continue;
             }
             if ($oldenrolments = get_records_sql("\n                      SELECT u.*, ra.timeend\n                        FROM {$CFG->prefix}user u\n                             JOIN {$CFG->prefix}role_assignments ra ON (ra.userid = u.id)\n                        WHERE ra.contextid = {$context->id}\n                              AND ra.timeend > 0 AND ra.timeend <= {$expiry}\n                              AND ra.enrol = 'manual'")) {
                 // inform user who can assign roles or admin
                 if ($teachers = get_users_by_capability($context, 'moodle/role:assign', '', '', '', '', '', '', false)) {
                     $teachers = sort_by_roleassignment_authority($teachers, $context);
                     $teacher = reset($teachers);
                 } else {
                     $teachers = array($admin);
                     $teacher = $admin;
                 }
                 $a->teacherstr = fullname($teacher, true);
                 foreach ($oldenrolments as $user) {
                     /// Email all users about to expire
                     $a->studentstr = fullname($user, true);
                     if ($user->timeend < $expiry - 86400) {
                         $a->past[] = fullname($user) . " <{$user->email}>";
                     } else {
                         $a->current[] = fullname($user) . " <{$user->email}>";
                         if ($course->notifystudents) {
                             // Send this guy notice
                             // setup global $COURSE properly - needed for languages
                             $USER = $user;
                             course_setup($course);
                             $a->coursename = format_string($cname);
                             $a->course = $a->coursename;
                             $strexpirynotifystudentsemail = get_string('expirynotifystudentsemail', '', $a);
                             $strexpirynotify = get_string('expirynotify');
                             email_to_user($user, $teacher, format_string($SITE->fullname) . ' ' . $strexpirynotify, $strexpirynotifystudentsemail);
                         }
                     }
                 }
                 $a->current = implode("\n", $a->current);
                 $a->past = implode("\n", $a->past);
                 if ($a->current || $a->past) {
                     foreach ($teachers as $teacher) {
                         // setup global $COURSE properly - needed for languages
                         $USER = $teacher;
                         course_setup($course);
                         $a->coursename = format_string($cname);
                         $strexpirynotifyemail = get_string('expirynotifyemail', '', $a);
                         $strexpirynotify = get_string('expirynotify');
                         email_to_user($teacher, $admin, $a->coursename . ' ' . $strexpirynotify, $strexpirynotifyemail);
                     }
                 }
             }
         }
         $USER = $cronuser;
         course_setup($SITE);
         // More environment
     }
     set_config('lastexpirynotify', date('Ymd'));
 }
 /**
  * Runs the automated backups if required
  *
  * @global moodle_database $DB
  */
 public static function run_automated_backup($rundirective = self::RUN_ON_SCHEDULE)
 {
     global $CFG, $DB;
     $status = true;
     $emailpending = false;
     $now = time();
     $config = get_config('backup');
     mtrace("Checking automated backup status", '...');
     $state = backup_cron_automated_helper::get_automated_backup_state($rundirective);
     if ($state === backup_cron_automated_helper::STATE_DISABLED) {
         mtrace('INACTIVE');
         return $state;
     } else {
         if ($state === backup_cron_automated_helper::STATE_RUNNING) {
             mtrace('RUNNING');
             if ($rundirective == self::RUN_IMMEDIATELY) {
                 mtrace('Automated backups are already running. If this script is being run by cron this constitues an error. You will need to increase the time between executions within cron.');
             } else {
                 mtrace("automated backup are already running. Execution delayed");
             }
             return $state;
         } else {
             mtrace('OK');
         }
     }
     backup_cron_automated_helper::set_state_running();
     mtrace("Getting admin info");
     $admin = get_admin();
     if (!$admin) {
         mtrace("Error: No admin account was found");
         $state = false;
     }
     if ($status) {
         mtrace("Checking courses");
         mtrace("Skipping deleted courses", '...');
         mtrace(sprintf("%d courses", backup_cron_automated_helper::remove_deleted_courses_from_schedule()));
     }
     if ($status) {
         mtrace('Running required automated backups...');
         cron_trace_time_and_memory();
         // This could take a while!
         core_php_time_limit::raise();
         raise_memory_limit(MEMORY_EXTRA);
         $nextstarttime = backup_cron_automated_helper::calculate_next_automated_backup($admin->timezone, $now);
         $showtime = "undefined";
         if ($nextstarttime > 0) {
             $showtime = date('r', $nextstarttime);
         }
         $rs = $DB->get_recordset('course');
         foreach ($rs as $course) {
             $backupcourse = $DB->get_record('backup_courses', array('courseid' => $course->id));
             if (!$backupcourse) {
                 $backupcourse = new stdClass();
                 $backupcourse->courseid = $course->id;
                 $backupcourse->laststatus = self::BACKUP_STATUS_NOTYETRUN;
                 $DB->insert_record('backup_courses', $backupcourse);
                 $backupcourse = $DB->get_record('backup_courses', array('courseid' => $course->id));
             }
             // The last backup is considered as successful when OK or SKIPPED.
             $lastbackupwassuccessful = ($backupcourse->laststatus == self::BACKUP_STATUS_SKIPPED || $backupcourse->laststatus == self::BACKUP_STATUS_OK) && ($backupcourse->laststarttime > 0 && $backupcourse->lastendtime > 0);
             // Assume that we are not skipping anything.
             $skipped = false;
             $skippedmessage = '';
             // Check if we are going to be running the backup now.
             $shouldrunnow = $backupcourse->nextstarttime > 0 && $backupcourse->nextstarttime < $now || $rundirective == self::RUN_IMMEDIATELY;
             // If config backup_auto_skip_hidden is set to true, skip courses that are not visible.
             if ($shouldrunnow && $config->backup_auto_skip_hidden) {
                 $skipped = $config->backup_auto_skip_hidden && !$course->visible;
                 $skippedmessage = 'Not visible';
             }
             // If config backup_auto_skip_modif_days is set to true, skip courses
             // that have not been modified since the number of days defined.
             if ($shouldrunnow && !$skipped && $lastbackupwassuccessful && $config->backup_auto_skip_modif_days) {
                 $timenotmodifsincedays = $now - $config->backup_auto_skip_modif_days * DAYSECS;
                 // Check log if there were any modifications to the course content.
                 $logexists = self::is_course_modified($course->id, $timenotmodifsincedays);
                 $skipped = $course->timemodified <= $timenotmodifsincedays && !$logexists;
                 $skippedmessage = 'Not modified in the past ' . $config->backup_auto_skip_modif_days . ' days';
             }
             // If config backup_auto_skip_modif_prev is set to true, skip courses
             // that have not been modified since previous backup.
             if ($shouldrunnow && !$skipped && $lastbackupwassuccessful && $config->backup_auto_skip_modif_prev) {
                 // Check log if there were any modifications to the course content.
                 $logexists = self::is_course_modified($course->id, $backupcourse->laststarttime);
                 $skipped = $course->timemodified <= $backupcourse->laststarttime && !$logexists;
                 $skippedmessage = 'Not modified since previous backup';
             }
             // Check if the course is not scheduled to run right now.
             if (!$shouldrunnow) {
                 $backupcourse->nextstarttime = $nextstarttime;
                 $DB->update_record('backup_courses', $backupcourse);
                 mtrace('Skipping ' . $course->fullname . ' (Not scheduled for backup until ' . $showtime . ')');
             } else {
                 if ($skipped) {
                     // Must have been skipped for a reason.
                     $backupcourse->laststatus = self::BACKUP_STATUS_SKIPPED;
                     $backupcourse->nextstarttime = $nextstarttime;
                     $DB->update_record('backup_courses', $backupcourse);
                     mtrace('Skipping ' . $course->fullname . ' (' . $skippedmessage . ')');
                     mtrace('Backup of \'' . $course->fullname . '\' is scheduled on ' . $showtime);
                 } else {
                     // Backup every non-skipped courses.
                     mtrace('Backing up ' . $course->fullname . '...');
                     // We have to send an email because we have included at least one backup.
                     $emailpending = true;
                     // Only make the backup if laststatus isn't 2-UNFINISHED (uncontrolled error).
                     if ($backupcourse->laststatus != self::BACKUP_STATUS_UNFINISHED) {
                         // Set laststarttime.
                         $starttime = time();
                         $backupcourse->laststarttime = time();
                         $backupcourse->laststatus = self::BACKUP_STATUS_UNFINISHED;
                         $DB->update_record('backup_courses', $backupcourse);
                         $backupcourse->laststatus = backup_cron_automated_helper::launch_automated_backup($course, $backupcourse->laststarttime, $admin->id);
                         $backupcourse->lastendtime = time();
                         $backupcourse->nextstarttime = $nextstarttime;
                         $DB->update_record('backup_courses', $backupcourse);
                         if ($backupcourse->laststatus === self::BACKUP_STATUS_OK) {
                             // Clean up any excess course backups now that we have
                             // taken a successful backup.
                             $removedcount = backup_cron_automated_helper::remove_excess_backups($course);
                         }
                     }
                     mtrace("complete - next execution: {$showtime}");
                 }
             }
         }
         $rs->close();
     }
     //Send email to admin if necessary
     if ($emailpending) {
         mtrace("Sending email to admin");
         $message = "";
         $count = backup_cron_automated_helper::get_backup_status_array();
         $haserrors = $count[self::BACKUP_STATUS_ERROR] != 0 || $count[self::BACKUP_STATUS_UNFINISHED] != 0;
         // Build the message text.
         // Summary.
         $message .= get_string('summary') . "\n";
         $message .= "==================================================\n";
         $message .= '  ' . get_string('courses') . '; ' . array_sum($count) . "\n";
         $message .= '  ' . get_string('ok') . '; ' . $count[self::BACKUP_STATUS_OK] . "\n";
         $message .= '  ' . get_string('skipped') . '; ' . $count[self::BACKUP_STATUS_SKIPPED] . "\n";
         $message .= '  ' . get_string('error') . '; ' . $count[self::BACKUP_STATUS_ERROR] . "\n";
         $message .= '  ' . get_string('unfinished') . '; ' . $count[self::BACKUP_STATUS_UNFINISHED] . "\n";
         $message .= '  ' . get_string('warning') . '; ' . $count[self::BACKUP_STATUS_WARNING] . "\n";
         $message .= '  ' . get_string('backupnotyetrun') . '; ' . $count[self::BACKUP_STATUS_NOTYETRUN] . "\n\n";
         //Reference
         if ($haserrors) {
             $message .= "  " . get_string('backupfailed') . "\n\n";
             $dest_url = "{$CFG->wwwroot}/report/backups/index.php";
             $message .= "  " . get_string('backuptakealook', '', $dest_url) . "\n\n";
             //Set message priority
             $admin->priority = 1;
             //Reset unfinished to error
             $DB->set_field('backup_courses', 'laststatus', '0', array('laststatus' => '2'));
         } else {
             $message .= "  " . get_string('backupfinished') . "\n";
         }
         //Build the message subject
         $site = get_site();
         $prefix = format_string($site->shortname, true, array('context' => context_course::instance(SITEID))) . ": ";
         if ($haserrors) {
             $prefix .= "[" . strtoupper(get_string('error')) . "] ";
         }
         $subject = $prefix . get_string('automatedbackupstatus', 'backup');
         //Send the message
         $eventdata = new stdClass();
         $eventdata->modulename = 'moodle';
         $eventdata->userfrom = $admin;
         $eventdata->userto = $admin;
         $eventdata->subject = $subject;
         $eventdata->fullmessage = $message;
         $eventdata->fullmessageformat = FORMAT_PLAIN;
         $eventdata->fullmessagehtml = '';
         $eventdata->smallmessage = '';
         $eventdata->component = 'moodle';
         $eventdata->name = 'backup';
         message_send($eventdata);
     }
     //Everything is finished stop backup_auto_running
     backup_cron_automated_helper::set_state_running(false);
     mtrace('Automated backups complete.');
     return $status;
 }
예제 #30
-1
/**
 * This plugin sends users a welcome message after logging in
 * and notify a moderator a new user has been added
 * it has a settings page that allow you to configure the messages
 * send.
 *
 * @package    local
 * @subpackage welcome
 * @copyright  2015 Bas Brands, basbrands.nl, bas@sonsbeekmedia.nl
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function send_welcome($user)
{
    global $CFG, $SITE;
    require_once $CFG->dirroot . '/local/welcome/locallib.php';
    $sender = get_admin();
    if (!empty($user->email)) {
        $config = get_config('local_welcome');
        $moderator = clone $sender;
        if (!empty($config->auth_plugins)) {
            $auths = explode(',', $config->auth_plugins);
            if (!in_array($user->auth, $auths)) {
                return '';
            }
        } else {
            return '';
        }
        $moderator->email = $config->moderator_email;
        $sender->email = $config->sender_email;
        $sender->firstname = $config->sender_firstname;
        $sender->lastname = $config->sender_lastname;
        $message_user_enabled = $config->message_user_enabled;
        $message_user = $config->message_user;
        $message_user_subject = $config->message_user_subject;
        $message_moderator_enabled = $config->message_moderator_enabled;
        $message_moderator = $config->message_moderator;
        $message_moderator_subject = $config->message_moderator_subject;
        $welcome = new local_welcome();
        $message_user = $welcome->replace_values($user, $message_user);
        $message_user_subject = $welcome->replace_values($user, $message_user_subject);
        $message_moderator = $welcome->replace_values($user, $message_moderator);
        $message_moderator_subject = $welcome->replace_values($user, $message_moderator_subject);
        if (!empty($message_user) && !empty($sender->email) && $message_user_enabled) {
            email_to_user($user, $sender, $message_user_subject, html_to_text($message_user), $message_user);
        }
        if (!empty($message_moderator) && !empty($sender->email) && $message_moderator_enabled) {
            email_to_user($moderator, $sender, $message_moderator_subject, html_to_text($message_moderator), $message_moderator);
        }
    }
}