本文整理汇总了PHP中core_user::get_support_user方法的典型用法代码示例。如果您正苦于以下问题:PHP core_user::get_support_user方法的具体用法?PHP core_user::get_support_user怎么用?PHP core_user::get_support_user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_user
的用法示例。
在下文中一共展示了core_user::get_support_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: local_sandbox_inform_admin
/**
* Helper function for sending notification mails
*
* @param string $message The message
* @param int $level Notification level
* @return
*/
function local_sandbox_inform_admin($message, $level = SANDBOX_LEVEL_NOTICE)
{
// Get recipients
$recipients = get_users_from_config(get_config('local_sandbox', 'notifyonerrors'), 'moodle/site:config');
// If there are no recipients, don't execute.
if (!is_array($recipients) || count($recipients) <= 0) {
return false;
}
// If message level is below configured notice level, don't execute
if ($level < get_config('local_sandbox', 'notifylevel')) {
return false;
}
// Get subject
if ($level > SANDBOX_LEVEL_WARNING) {
$subject = get_string('emailsubjecterror', 'local_sandbox');
} else {
if ($level > SANDBOX_LEVEL_NOTICE) {
$subject = get_string('emailsubjectwarning', 'local_sandbox');
} else {
$subject = get_string('emailsubjectnotice', 'local_sandbox');
}
}
// Send mail
foreach ($recipients as $r) {
// Email the admin directly rather than putting these through the messaging system
email_to_user($r, core_user::get_support_user(), $subject, $message);
}
}
示例2: test_get_user
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 = 'test@support.moodle.test';
$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));
}
示例3: activenotification
function activenotification($id){
global $DB, $USER, $CFG,$COURSE,$PAGE,$OUTPUT;
//Batch Name
$batchname=$DB->get_field('facetoface','name',array('id'=>$id));
//getting batch users
$batch_users=$DB->get_records_sql("select * from {local_batch_users} where f2fid=$id");
//getting session details
$session_details=$DB->get_records_sql("select * from {facetoface_sessions} where facetoface=$id");
$sessionsingle="<table border='1' style='text-align:center;'><tr><th>Serial</th><th>Startdate</th><th>Enddate</th><th>Classroom</th></tr>";
$n=1;
foreach($session_details as $session_detail){
//session dates
$startdateunix=$DB->get_field('facetoface_sessions_dates','timestart',array('sessionid'=>$session_detail->id));
$enddateuinx=$DB->get_field('facetoface_sessions_dates','timefinish',array('sessionid'=>$session_detail->id));
//converting dates
$statrtdate=date('d M Y H:i:s',$startdateunix);
$enddate=date('d M Y H:i:s',$enddateuinx);
//session room
$sessionroom=$DB->get_field('facetoface_room','name',array('id'=>$session_detail->roomid));
$sessionsingle .="<tr><td>$n</td><td>$statrtdate</td><td>$enddate</td><td>$sessionroom</td></tr>";
$n++;
}
// sending email to each users
foreach($batch_users as $batch_user){
$user_active_details=$DB->get_record_sql("select * from {user} where id=$batch_user->userid");
// Course Name
$coursename=$DB->get_field('course','fullname',array('id'=>$batch_user->courseid));
$from = core_user::get_support_user();
$subject =get_string('activenotification', 'facetoface');
$usermail=new stdClass();
$usermail->fullname=fullname($batch_user->userid);
$usermail->batchname=$batchname;
$usermail->coursename=$coursename;
$usermail->session=$sessionsingle;
$messagetext=get_string('activenotificationmsg', 'facetoface',$usermail);
$email=email_to_user($user_active_details,$from,$subject,$messagetext);
//print_object(email_to_user($user_active_details,$from,$subject,$messagetext));
}
}
示例4: test_message_get_contacts
/**
* Test message_get_contacts.
*/
public function test_message_get_contacts()
{
global $USER, $CFG;
// Set this user as the admin.
$this->setAdminUser();
$noreplyuser = core_user::get_noreply_user();
$supportuser = core_user::get_support_user();
// Create a user to add to the admin's contact list.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
// Stranger.
// Add users to the admin's contact list.
message_add_contact($user1->id);
message_add_contact($user2->id);
// Send some messages.
$this->send_fake_message($user1, $USER);
$this->send_fake_message($user2, $USER);
$this->send_fake_message($user3, $USER);
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts();
$this->assertCount(0, $onlinecontacts);
$this->assertCount(2, $offlinecontacts);
$this->assertCount(1, $strangers);
// Send message from noreply and support users.
$this->send_fake_message($noreplyuser, $USER);
$this->send_fake_message($supportuser, $USER);
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts();
$this->assertCount(0, $onlinecontacts);
$this->assertCount(2, $offlinecontacts);
$this->assertCount(3, $strangers);
// Block 1 user.
message_block_contact($user2->id);
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts();
$this->assertCount(0, $onlinecontacts);
$this->assertCount(1, $offlinecontacts);
$this->assertCount(3, $strangers);
// Noreply user being valid user.
core_user::reset_internal_users();
$CFG->noreplyuserid = $user3->id;
$noreplyuser = core_user::get_noreply_user();
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts();
$this->assertCount(0, $onlinecontacts);
$this->assertCount(1, $offlinecontacts);
$this->assertCount(2, $strangers);
}
示例5: login_lock_account
/**
* Lockout user and send notification email.
*
* @param stdClass $user
*/
function login_lock_account($user)
{
global $CFG, $SESSION;
if ($user->mnethostid != $CFG->mnet_localhost_id) {
return;
}
if (isguestuser($user)) {
return;
}
if (get_user_preferences('login_lockout_ignored', 0, $user)) {
// This user can not be locked out.
return;
}
$alreadylockedout = get_user_preferences('login_lockout', 0, $user);
set_user_preference('login_lockout', time(), $user);
if ($alreadylockedout == 0) {
$secret = random_string(15);
set_user_preference('login_lockout_secret', $secret, $user);
// Some nasty hackery to get strings and dates localised for target user.
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
if (get_string_manager()->translation_exists($user->lang, false)) {
$SESSION->lang = $user->lang;
moodle_setlocale();
}
$site = get_site();
$supportuser = core_user::get_support_user();
$data = new stdClass();
$data->firstname = $user->firstname;
$data->lastname = $user->lastname;
$data->username = $user->username;
$data->sitename = format_string($site->fullname);
$data->link = $CFG->wwwroot . '/login/unlock_account.php?u=' . $user->id . '&s=' . $secret;
$data->admin = generate_email_signoff();
$message = get_string('lockoutemailbody', 'admin', $data);
$subject = get_string('lockoutemailsubject', 'admin', format_string($site->fullname));
if ($message) {
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
email_to_user($user, $supportuser, $subject, $message);
}
if ($SESSION->lang !== $sessionlang) {
$SESSION->lang = $sessionlang;
moodle_setlocale();
}
}
}
示例6: profile_save_data
// Save custom profile fields data.
profile_save_data($usernew);
// Trigger event.
\core\event\user_updated::create_from_userid($user->id)->trigger();
// If email was changed and confirmation is required, send confirmation email now to the new address.
if ($emailchanged && $CFG->emailchangeconfirmation) {
$tempuser = $DB->get_record('user', array('id' => $user->id), '*', MUST_EXIST);
$tempuser->email = $usernew->preference_newemail;
$a = new stdClass();
$a->url = $CFG->wwwroot . '/user/emailupdate.php?key=' . $usernew->preference_newemailkey . '&id=' . $user->id;
$a->site = format_string($SITE->fullname, true, array('context' => context_course::instance(SITEID)));
$a->fullname = fullname($tempuser, true);
$emailupdatemessage = get_string('emailupdatemessage', 'auth', $a);
$emailupdatetitle = get_string('emailupdatetitle', 'auth', $a);
// Email confirmation directly rather than using messaging so they will definitely get an email.
$supportuser = core_user::get_support_user();
if (!($mailresults = email_to_user($tempuser, $supportuser, $emailupdatetitle, $emailupdatemessage))) {
die("could not send email!");
}
}
// Reload from db, we need new full name on this page if we do not redirect.
$user = $DB->get_record('user', array('id' => $user->id), '*', MUST_EXIST);
if ($USER->id == $user->id) {
// Override old $USER session variable if needed.
foreach ((array) $user as $variable => $value) {
if ($variable === 'description' or $variable === 'password') {
// These are not set for security nad perf reasons.
continue;
}
$USER->{$variable} = $value;
}
示例7: notify_login_failures
/**
* Notify admin users or admin user of any failed logins (since last notification).
*
* Note that this function must be only executed from the cron script
* It uses the cache_flags system to store temporary records, deleting them
* by name before finishing
*
* @return bool True if executed, false if not
*/
function notify_login_failures()
{
global $CFG, $DB, $OUTPUT;
if (empty($CFG->notifyloginfailures)) {
return false;
}
$recip = get_users_from_config($CFG->notifyloginfailures, 'moodle/site:config');
if (empty($CFG->lastnotifyfailure)) {
$CFG->lastnotifyfailure = 0;
}
// If it has been less than an hour, or if there are no recipients, don't execute.
if (time() - HOURSECS < $CFG->lastnotifyfailure || !is_array($recip) || count($recip) <= 0) {
return false;
}
// we need to deal with the threshold stuff first.
if (empty($CFG->notifyloginthreshold)) {
$CFG->notifyloginthreshold = 10;
// default to something sensible.
}
// Get all the IPs with more than notifyloginthreshold failures since lastnotifyfailure
// and insert them into the cache_flags temp table
$sql = "SELECT ip, COUNT(*)\n FROM {log}\n WHERE module = 'login' AND action = 'error'\n AND time > ?\n GROUP BY ip\n HAVING COUNT(*) >= ?";
$params = array($CFG->lastnotifyfailure, $CFG->notifyloginthreshold);
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $iprec) {
if (!empty($iprec->ip)) {
set_cache_flag('login_failure_by_ip', $iprec->ip, '1', 0);
}
}
$rs->close();
// Get all the INFOs with more than notifyloginthreshold failures since lastnotifyfailure
// and insert them into the cache_flags temp table
$sql = "SELECT info, count(*)\n FROM {log}\n WHERE module = 'login' AND action = 'error'\n AND time > ?\n GROUP BY info\n HAVING count(*) >= ?";
$params = array($CFG->lastnotifyfailure, $CFG->notifyloginthreshold);
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $inforec) {
if (!empty($inforec->info)) {
set_cache_flag('login_failure_by_info', $inforec->info, '1', 0);
}
}
$rs->close();
// Now, select all the login error logged records belonging to the ips and infos
// since lastnotifyfailure, that we have stored in the cache_flags table
$sql = "SELECT * FROM (\n SELECT l.*, u.firstname, u.lastname\n FROM {log} l\n JOIN {cache_flags} cf ON l.ip = cf.name\n LEFT JOIN {user} u ON l.userid = u.id\n WHERE l.module = 'login' AND l.action = 'error'\n AND l.time > ?\n AND cf.flagtype = 'login_failure_by_ip'\n UNION ALL\n SELECT l.*, u.firstname, u.lastname\n FROM {log} l\n JOIN {cache_flags} cf ON l.info = cf.name\n LEFT JOIN {user} u ON l.userid = u.id\n WHERE l.module = 'login' AND l.action = 'error'\n AND l.time > ?\n AND cf.flagtype = 'login_failure_by_info') t\n ORDER BY t.time DESC";
$params = array($CFG->lastnotifyfailure, $CFG->lastnotifyfailure);
// Init some variables
$count = 0;
$messages = '';
// Iterate over the logs recordset
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $log) {
$log->time = userdate($log->time);
$messages .= get_string('notifyloginfailuresmessage', '', $log) . "\n";
$count++;
}
$rs->close();
// If we have something useful to report.
if ($count > 0) {
$site = get_site();
$subject = get_string('notifyloginfailuressubject', '', format_string($site->fullname));
// Calculate the complete body of notification (start + messages + end)
$body = get_string('notifyloginfailuresmessagestart', '', $CFG->wwwroot) . ($CFG->lastnotifyfailure != 0 ? '(' . userdate($CFG->lastnotifyfailure) . ')' : '') . "\n\n" . $messages . "\n\n" . get_string('notifyloginfailuresmessageend', '', $CFG->wwwroot) . "\n\n";
// For each destination, send mail
mtrace('Emailing admins about ' . $count . ' failed login attempts');
foreach ($recip as $admin) {
//emailing the admins directly rather than putting these through the messaging system
email_to_user($admin, core_user::get_support_user(), $subject, $body);
}
}
// Update lastnotifyfailure with current time
set_config('lastnotifyfailure', time());
// Finally, delete all the temp records we have created in cache_flags
$DB->delete_records_select('cache_flags', "flagtype IN ('login_failure_by_ip', 'login_failure_by_info')");
return true;
}
示例8: send_password_change_info
/**
* Sends an email containinginformation on how to change your password.
*
* @param stdClass $user A {@link $USER} object
* @return bool Returns true if mail was sent OK and false if there was an error.
*/
function send_password_change_info($user)
{
global $CFG;
$site = get_site();
$supportuser = core_user::get_support_user();
$systemcontext = context_system::instance();
$data = new stdClass();
$data->firstname = $user->firstname;
$data->lastname = $user->lastname;
$data->sitename = format_string($site->fullname);
$data->admin = generate_email_signoff();
$userauth = get_auth_plugin($user->auth);
if (!is_enabled_auth($user->auth) or $user->auth == 'nologin') {
$message = get_string('emailpasswordchangeinfodisabled', '', $data);
$subject = get_string('emailpasswordchangeinfosubject', '', format_string($site->fullname));
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
return email_to_user($user, $supportuser, $subject, $message);
}
if ($userauth->can_change_password() and $userauth->change_password_url()) {
// We have some external url for password changing.
$data->link .= $userauth->change_password_url();
} else {
// No way to change password, sorry.
$data->link = '';
}
if (!empty($data->link) and has_capability('moodle/user:changeownpassword', $systemcontext, $user->id)) {
$message = get_string('emailpasswordchangeinfo', '', $data);
$subject = get_string('emailpasswordchangeinfosubject', '', format_string($site->fullname));
} else {
$message = get_string('emailpasswordchangeinfofail', '', $data);
$subject = get_string('emailpasswordchangeinfosubject', '', format_string($site->fullname));
}
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
return email_to_user($user, $supportuser, $subject, $message);
}
示例9: generate_email_supportuser
/**
* Generate a fake user for emails based on support settings
*
* @deprecated since Moodle 2.6
* @see core_user::get_support_user()
* @return stdClass user info
*/
function generate_email_supportuser()
{
debugging('generate_email_supportuser is deprecated, please use core_user::get_support_user');
return core_user::get_support_user();
}
示例10: get_sender
/**
* Gets the user company information for the provided user
*
* Parameters - $user = stdclass();
*
**/
private function get_sender($user)
{
// Get the user's company.
if ($usercompany = company::get_company_byuserid($user->id)) {
// Is there a default contact userid?
if (isset($usercompany->defaultcontactid)) {
$returnid = $usercompany->defaultcontactid;
} else {
// Use the default support email account.
$returnid = core_user::get_support_user();
}
} else {
// No company use default support user.
$returnid = core_user::get_support_user();
}
return $returnid;
}
示例11: sendConfirmMailToManagers
function sendConfirmMailToManagers($instance,$info,$applydescription){
global $DB;
global $CFG;
global $USER;
$courseid = $instance->courseid;
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'");
$show_standard_user_profile = $show_extra_user_profile = false;
if($instance->customint1 != ''){
($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false;
}else{
($apply_setting['show_standard_user_profile']->value == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false;
}
if($instance->customint2 != ''){
($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false;
}else{
($apply_setting['show_extra_user_profile']->value == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false;
}
if($apply_setting['sendmailtomanager']->value == 1){
$course = get_course($courseid);
$context = context_system::instance();
$managerType = $DB->get_record('role',array("shortname"=>"manager"));
$managers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$managerType->id));
foreach($managers as $manager){
$userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid));
$body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if($show_standard_user_profile){
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>';
$body .= '<p>'. get_string('email') .': '.$info->email.'</p>';
$body .= '<p>'. get_string('city') .': '.$info->city.'</p>';
$body .= '<p>'. get_string('country') .': '.$info->country.'</p>';
$body .= '<p>'. get_string('preferredlanguage') .': '.$info->lang.'</p>';
$body .= '<p>'. get_string('description') .': '.$info->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename') .': '.$info->middlename.'</p>';
$body .= '<p>'. get_string('alternatename') .': '.$info->alternatename.'</p>';
$body .= '<p>'. get_string('url') .': '.$info->url.'</p>';
$body .= '<p>'. get_string('icqnumber') .': '.$info->icq.'</p>';
$body .= '<p>'. get_string('skypeid') .': '.$info->skype.'</p>';
$body .= '<p>'. get_string('aimid') .': '.$info->aim.'</p>';
$body .= '<p>'. get_string('yahooid') .': '.$info->yahoo.'</p>';
$body .= '<p>'. get_string('msnid') .': '.$info->msn.'</p>';
$body .= '<p>'. get_string('idnumber') .': '.$info->idnumber.'</p>';
$body .= '<p>'. get_string('institution') .': '.$info->institution.'</p>';
$body .= '<p>'. get_string('department') .': '.$info->department.'</p>';
$body .= '<p>'. get_string('phone') .': '.$info->phone1.'</p>';
$body .= '<p>'. get_string('phone2') .': '.$info->phone2.'</p>';
$body .= '<p>'. get_string('address') .': '.$info->address.'</p>';
}
if($show_extra_user_profile){
require_once($CFG->dirroot.'/user/profile/lib.php');
$user = $DB->get_record('user',array('id'=>$USER->id));
profile_load_custom_fields($user);
foreach ($user->profile as $key => $value) {
$body .= '<p>'. $key .': '.$value.'</p>';
}
}
$body .= '<p>'. html_writer::link(new moodle_url('/enrol/apply/manage.php'), get_string('applymanage', 'enrol_apply')).'</p>';
$contact = core_user::get_support_user();
$info = $userWithManagerRole;
$info->coursename = $course->fullname;
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);
}
}
}
示例12: confirm_coupons_sent
/**
* Send confirmation email when the cron has send all the coupons
*
* @param int $ownerid
* @param int $timecreated
* @return bool
*/
public static final function confirm_coupons_sent($ownerid, $timecreated)
{
global $CFG, $DB;
require_once $CFG->libdir . '/phpmailer/moodle_phpmailer.php';
$owner = $DB->get_record('user', array('id' => $ownerid));
$supportuser = \core_user::get_support_user();
$mailcontent = get_string("confirm_coupons_sent_body", 'block_coupon', array('timecreated' => date('Y-m-d', $timecreated)));
// Send.
$phpmailer = new \moodle_phpmailer();
$phpmailer->Body = $mailcontent;
$phpmailer->AltBody = strip_tags($mailcontent);
$phpmailer->From = $supportuser->email;
$phpmailer->FromName = trim($supportuser->firstname . ' ' . $supportuser->lastname);
$phpmailer->IsHTML(true);
$phpmailer->Subject = get_string('confirm_coupons_sent_subject', 'block_coupon');
$phpmailer->AddAddress($owner->email);
return $phpmailer->Send();
}
示例13: email_welcome_message
/**
* Send welcome email to specified user.
*
* @param stdClass $instance
* @param stdClass $user user record
* @return void
*/
public function email_welcome_message($instance, $user)
{
global $CFG, $DB;
$username = isset($instance->newusername) ? $instance->newusername : null;
$password = isset($instance->newaccountpassword) ? $instance->newaccountpassword : null;
$course = $DB->get_record('course', array('id' => $instance->courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id);
$a = new stdClass();
$a->coursename = format_string($course->fullname, true, array('context' => $context));
$a->courseurl = "{$CFG->wwwroot}/course/view.php?id={$course->id}";
$a->profileurl = "{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$course->id}";
$a->forgottenpasswordurl = "{$CFG->wwwroot}/login/forgot_password.php";
$a->username = $username ? $username : '';
$a->password = $password ? $password : '';
if (trim($instance->customtext1) !== '') {
// If there is a custom welcome message use it
$message = $instance->customtext1;
$message = str_replace('{$a->coursename}', $a->coursename, $message);
$message = str_replace('{$a->courseurl}', $a->courseurl, $message);
$message = str_replace('{$a->profileurl}', $a->profileurl, $message);
$message = str_replace('{$a->forgottenpasswordurl}', $a->forgottenpasswordurl, $message);
if (strpos($message, '<') === false) {
// Plain text only.
$messagetext = $message;
$messagehtml = text_to_html($messagetext, null, false, true);
} else {
// This is most probably the tag/newline soup known as FORMAT_MOODLE
$messagetext = html_to_text($messagehtml);
$messagehtml = format_text($message, FORMAT_MOODLE, array('context' => $context, 'para' => false, 'newlines' => true, 'filter' => true));
}
} else {
// Otherwise use the default defined in the language file
$messagetext = get_string('welcometocoursetext', 'enrol_magento', $a);
$messagehtml = get_string('welcometocoursetexthtml', 'enrol_magento', $a);
}
if ($username && $password) {
$messagetext .= get_string('newcredentials', 'enrol_magento', $a);
$messagehtml .= get_string('newcredentialshtml', 'enrol_magento', $a);
} else {
$messagetext .= get_string('existinguser', 'enrol_magento', $a);
$messagehtml .= get_string('existinguserhtml', 'enrol_magento', $a);
}
$subject = get_string('welcometocourse', 'enrol_magento', format_string($course->fullname, true, array('context' => $context)));
$rusers = array();
if (!empty($CFG->coursecontact)) {
$croles = explode(',', $CFG->coursecontact);
list($sort, $sortparams) = users_order_by_sql('u');
$rusers = get_role_users($croles, $context, true, '', 'r.sortorder ASC, ' . $sort, null, '', '', '', '', $sortparams);
}
if ($rusers) {
$contact = reset($rusers);
} else {
$contact = core_user::get_support_user();
}
email_to_user($user, $contact, $subject, $messagetext, $messagehtml);
}
示例14: handle_verification_failure
/**
* Handle failure of sender verification.
*
* This will send a notification to the user identified in the Inbound Message address informing them that a message has been
* stored. The message includes a verification link and reply-to address which is handled by the
* invalid_recipient_handler.
*
* @param \Horde_Imap_Client_Ids $messageids
* @param string $recipient The message recipient
* @return bool
*/
private function handle_verification_failure(\Horde_Imap_Client_Ids $messageids, $recipient)
{
global $DB, $USER;
if (!($messageid = $this->currentmessagedata->messageid)) {
mtrace("---> Warning: Unable to determine the Message-ID of the message.");
return false;
}
// Move the message into a new mailbox.
$this->client->copy(self::MAILBOX, $this->get_confirmation_folder(), array('create' => true, 'ids' => $messageids, 'move' => true));
// Store the data from the failed message in the associated table.
$record = new \stdClass();
$record->messageid = $messageid;
$record->userid = $USER->id;
$record->address = $recipient;
$record->timecreated = time();
$record->id = $DB->insert_record('messageinbound_messagelist', $record);
// Setup the Inbound Message generator for the invalid recipient handler.
$addressmanager = new \core\message\inbound\address_manager();
$addressmanager->set_handler('\\tool_messageinbound\\message\\inbound\\invalid_recipient_handler');
$addressmanager->set_data($record->id);
$eventdata = new \stdClass();
$eventdata->component = 'tool_messageinbound';
$eventdata->name = 'invalidrecipienthandler';
$userfrom = clone $USER;
$userfrom->customheaders = array();
// Adding the In-Reply-To header ensures that it is seen as a reply.
$userfrom->customheaders[] = 'In-Reply-To: ' . $messageid;
// The message will be sent from the intended user.
$eventdata->userfrom = \core_user::get_support_user();
$eventdata->userto = $USER;
$eventdata->subject = $this->get_reply_subject($this->currentmessagedata->envelope->subject);
$eventdata->fullmessage = get_string('invalidrecipientdescription', 'tool_messageinbound', $this->currentmessagedata);
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = get_string('invalidrecipientdescriptionhtml', 'tool_messageinbound', $this->currentmessagedata);
$eventdata->smallmessage = $eventdata->fullmessage;
$eventdata->notification = 1;
$eventdata->replyto = $addressmanager->generate($USER->id);
mtrace("--> Sending a message to the user to report an verification failure.");
if (!message_send($eventdata)) {
mtrace("---> Warning: Message could not be sent.");
return false;
}
return true;
}
示例15: user_signup
function user_signup($user, $notify = false)
{
global $CFG, $DB, $SESSION;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/enrol/token/lib.php';
$lang = empty($user->lang) ? $CFG->lang : $user->lang;
$site = get_site();
$supportuser = core_user::get_support_user();
$newpassword = generate_password();
// the token the user entered (which is now validated)
$tokenValue = $user->token;
$newuser = new stdClass();
$newuser->auth = 'token';
// since technially this auth plugin is a skin
$newuser->firstname = $user->firstname;
$newuser->lastname = $user->lastname;
$newuser->password = hash_internal_user_password($newpassword, false);
$newuser->policyagreed = 1;
// might need to put this in somewhere
$newuser->username = $user->email;
$newuser->email = $user->email;
$newuser->lastip = getremoteaddr();
$newuser->timecreated = time();
$newuser->timemodified = $newuser->timecreated;
$newuser->mnethostid = $CFG->mnet_localhost_id;
$newuser = self::truncate_user_obj($newuser);
if (($newuser->id = $DB->insert_record('user', $newuser)) === false) {
notice(get_string('signupfailure', 'auth_token'), $CFG->wwwroot);
return false;
}
$user = get_complete_user_data('id', $newuser->id);
\core\event\user_created::create_from_userid($user->id)->trigger();
// just the query part of post-login redirect
$params = empty($SESSION->wantsurl) === true ? '' : parse_url($SESSION->wantsurl, PHP_URL_QUERY);
$a = new stdClass();
$a->firstname = $user->firstname;
$a->lastname = $user->lastname;
$a->username = $user->username;
$a->password = $newpassword;
$a->sitename = format_string($site->fullname);
$a->link = $CFG->wwwroot . '/auth/token/login.php?' . $params;
$a->signoff = generate_email_signoff();
$message = (string) new lang_string('signup_userregoemail', 'auth_token', $a, $lang);
$subject = format_string($site->fullname) . ': ' . (string) new lang_string('newusernewpasswordsubj', '', $a, $lang);
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
email_to_user($user, $supportuser, $subject, $message);
// log the user in immediately
if (($user = authenticate_user_login($user->username, $newpassword)) === false || complete_user_login($user) == null) {
notice(get_string('autologinfailure', 'auth_token'), $CFG->wwwroot);
return false;
}
// now, actually DO the enrolment for this course / user
$token_plugin = new enrol_token_plugin();
$courseId = 0;
$return_to_url = empty($SESSION->wantsurl) === true ? $CFG->wwwroot : $SESSION->wantsurl;
$enrolled_ok = $token_plugin->doEnrolment($tokenValue, $courseId, $return_to_url);
if ($enrolled_ok == true) {
redirect($return_to_url);
}
return $enrolled_ok == true;
}