I'm using Moodle 1.8 as an administrator for a small society.
I would prefer to use the manual enrolment to enroll users/students. I expected that an email notification would be sent to each user's address with the username I chose for him/her and the password.
Is this feature simply not posssible or have I misconfigured anything?
Thanks in advance
As far as I know, if you create the accounts manually, then no email is sent to the users. So the administrator should take care of sending the emails.
Saludos. Iñaki.
And is there a way to send the emails in one shot? May be, posting a message from the Course forum?
I need to tell the students which username I chose for them, while the password is a temporary password (they have to change it at their first login), the same password for all.
Posting a message from the Course forum would only be an option if your courses are open to guests. Otherwise the users won't see the message.
You could also modify .../user/editadvanced.php (in 1.8 and above) and use the email_to_user() function to send the emails automatically, as part of the user creation process.
Saludos. Iñaki.
I'm trying to modify the file you said, but I'm not so good in PHP.
I've changed these lines (from about 73):
if ($usernew->id == -1) {
//TODO check out if it makes sense to create account with this auth plugin and what to do with the password
unset($usernew->id);
$usernew->mnethostid = $CFG->mnet_localhost_id; // always local user
$usernew->confirmed = 1;
$usernew->password = hash_internal_user_password($usernew->newpassword);
if (!$usernew->id = insert_record('user', $usernew)) {
error('Error creating user record');
}
email_to_user();
}
I'm not sure at all if this is the right place to insert the function... For now, I still can't receive emails...
Thanks for helping.
This is what I've done to get the email sent. Just add marked lines:
if ($usernew->id == -1) {
//TODO check out if it makes sense to create account with this auth plugin and what to do with the password
unset($usernew->id);
$usernew->mnethostid = $CFG->mnet_localhost_id; // always local user
$usernew->confirmed = 1;
$clearpassword = $usernew->newpassword; # <=== Add this line
$usernew->password = hash_internal_user_password($usernew->newpassword);
if (!$usernew->id = insert_record('user', $usernew)) {
error('Error creating user record');
}
// Add lines from here ====>
$site = get_site();
$a = new object();
$a->firstname = $usernew->firstname;
$a->sitename = format_string($site->fullname);
$a->username = $usernew->username;
$a->newpassword = $clearpassword;
$a->link = $CFG->wwwroot .'/login/';
$a->signoff = fullname($mainadmin, true).' ('. $mainadmin->email .')';
$message = get_string('newusernewpasswordtext', '', $a);
$subject = format_string($site->fullname) .': '. get_string('newusernewpasswordsubj');
email_to_user($usernew, $mainadmin, $subject, $message);
// Add lines to here <=====
} else {
This code re-uses the message for the password-reset feature, so it warns the user s/he'll need to change the password on the first logon. If this is not desired, you'll need to create a new language string (instead of using 'newuserpasswordtext') with the required text, in .../lang/en_utf8/moodle.php.
Saludos. Iñaki.
We want the users to change the temporary password, so your code is exactly what we need.
In my opinion this sould be a feature integrated in Moodle by default, at least when you choose to force the user to change the password at her/his first login.
Saluti.
Antonio
Hi Inaki,
I recently integrated this code in Moodle2 and it works perfectly fine for the Manual enrollments. Thank you for the same!
I also have manual enrollments through csv uploads. However for csv uploads these emails are not being triggered. Could you tell me where I should possibly make the change for csv uploads of users?
Thanks
Saru
Re: Manual enrolment: does it send any notification?
Saru,
When you CSV make sure that the student is enroled in there course using the CSV.
If for some reason you can't put them straight into a course, auto enrol in something like student lounge.
Ensure the Welcome message is turned On. The Welcome email will be sent automatically.
Re: Manual enrolment: does it send any notification?
can you say where to turn on the welcome message. I can't find it.
Re: Manual enrolment: does it send any notification?
Hi
In Users/ Authentication/Manage Authentication
You can change here the message
Re: Manual enrolment: does it send any notification?
Hi
There is part called Instruction in common settings of Manage authentication. Is that what you are saying about or some thing else?
Re: Manual enrolment: does it send any notification?
Hi Saru,
First things first: I think it's a VERY BAD IDEA to send user passwords over email, as anyone can read them. Even if they are temporary passwords, it is still a very bad idea..
Now, if you are still determined to send them and deal with the potential security consequences of it, you need to edit admin/uploaduser.php and find the following piece of code (around line 617 in Moodle 2.0.x) and add the marked lines of code:
if (!$isinternalauth) {
$user->password = 'not cached';
$upt->track('password', 'not cached');
} else {
$clearpassword = $usernew->newpassword; # <====== Add this line
$user->password = hash_internal_user_password($user->password);
}
$user->id = $DB->insert_record('user', $user);
$info = ': ' . $user->username .' (ID = ' . $user->id . ')';
$upt->track('status', $struseradded);
$upt->track('id', $user->id, 'normal', false);
$usersnew++;
if ($createpasswords && $isinternalauth) {
if (empty($user->password) || $forcechangepassword) {
// passwords will be created and sent out on cron
set_user_preference('create_password', 1, $user->id);
set_user_preference('auth_forcepasswordchange', 1, $user->id);
$upt->track('password', get_string('new'));
} else {
set_user_preference('auth_forcepasswordchange', 1, $user->id);
}
}
// Add lines from here ====>
else {
$site = get_site();
$mainadmin = get_admin();
$a = new object();
$a->firstname = $user->firstname;
$a->sitename = format_string($site->fullname);
$a->username = $user->username;
$a->newpassword = $clearpassword;
$a->link = $CFG->wwwroot .'/login/';
$a->signoff = fullname($mainadmin, true).' ('. $mainadmin->email .')';
$message = get_string('newusernewpasswordtext', '', $a);
$subject = format_string($site->fullname) .': '. get_string('newusernewpasswordsubj');
email_to_user($usernew, $mainadmin, $subject, $message);
}
// Add lines to here <=====
That should do the trick.
Saludos. Iñaki.
Re: Manual enrolment: does it send any notification?
Just curious Iñaki
If not e-mail, then what? Phone call? Letter?
-Derek
Re: Manual enrolment: does it send any notification?
If possible, I always let the user choose the password beforehand (using some sort of auto-registration process) over a secure channel (HTTPS, etc.) or physical presence (we are a Uni and have to deal with a lot of registration paperwork that has to be done still face to face). And then the user is created in Moodle (or the external authentication service that Moodle will use).
If not possible, you can generate an auth token for the user (based on some information you have from the user that she provided you with and some salting information) and send the user a URL with the token. When the user clicks on the token URL, you ask her for the information you used to create the token. If both values are ok, then you let the user set the password. Of course, the URL for these interaction should use HTTPS.
This needs a small custom development, but should not be that difficult.
Saludos.
Iñaki.
Re: Manual enrolment: does it send any notification?
Hi
The above code is not triggerring the email.It is only adding the user but not sending the email. I made the password field blank and also assigned a course to them in the csv file but still no email is send. The password is created and saved in database but no email. Can you please help me out? I am attaching the csv file that i am trying to upload. please check wether the format is correct or not.
Thanks in advance
Re: Manual enrolment: does it send any notification?
Hello, I tryed to apply this code to moodle 1.9.9 and it does not work, the autenciation for users is by mail, any suggestions?
thanks
Re: Manual enrolment: does it send any notification?
Hey Iñaki,
Thanks for these code snippets - the second one (further down the page for manual user entry works a treat).
However, this portion (in /admin/uploaduser.php) differes significantly from the new version of the file.
However, my establishment, would very much like this capability. Would you be able to update this to work with the latest version? It'd be much appreciated Oh-Guru!
Re: Manual enrolment: does it send any notification?
You guys should vote for this tracker request: http://tracker.moodle.org/browse/MDL-19390
"Perhaps this could be an option under bulk user actions "Email login information" and/or a checkbox on the create/edit user page" - Derek
Re: Manual enrolment: does it send any notification?
Does this work for strictly manual enrollments or do I HAVE to do a bulk upload? I usually only create participants manually. Some instructions on how you did this in 2.0.x would be great if you could share. Thanks!
Re: Manual enrolment: does it send any notification?
It depends on which piece of code you add
The first piece of code (from 2007) is for manual account creation (not to be confused with enrolments, which are a completely different thing in Moodle). The second piece of code is for bulk uploads.
If you don't need bulk uploads, the first piece of code is still valid, thought the standard code has changed a little bit. Here's it updated for 2.x. Just add the marked lines below:
if ($usernew->id == -1) {
//TODO check out if it makes sense to create account with this auth plugin and what to do with the password
unset($usernew->id);
$usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, null, 'user', 'profile', null);
$usernew->mnethostid = $CFG->mnet_localhost_id; // always local user
$usernew->confirmed = 1;
$usernew->timecreated = time();
$clearpassword = $usernew->newpassword; # <=== Add this line
$usernew->password = hash_internal_user_password($usernew->newpassword);
$usernew->id = $DB->insert_record('user', $usernew);
$usercreated = true;
// Add lines from here ====>
$site = get_site();
$a = new object();
$a->firstname = $usernew->firstname;
$a->sitename = format_string($site->fullname);
$a->username = $usernew->username;
$a->newpassword = $clearpassword;
$a->link = $CFG->wwwroot .'/login/';
$a->signoff = fullname($mainadmin, true).' ('. $mainadmin->email .')';
$message = get_string('newusernewpasswordtext', '', $a);
$subject = format_string($site->fullname) .': '. get_string('newusernewpasswordsubj');
email_to_user($usernew, $mainadmin, $subject, $message);
// Add lines to here <=====
} else {
Saludos. Iñaki.
Re: Manual enrolment: does it send any notification?
Thank you SO much for your help. I will try this. Can you please tell me which file to add this code to and where? Thanks!
Re: Manual enrolment: does it send any notification?
I hate to double post, but I still am not sure where to place this piece of code (which file)? Can you please advise? Your help is greatly appreciated!!
Re: Manual enrolment: does it send any notification?
sorry about that! I receive so much email from the forums that your previous post was buried by new mail so fast that I didn't notice it
You need to edit .../user/editadvanced.php
Saludos.
Iñaki.
Re: Manual enrolment: does it send any notification?
Hi there Iñaki, your previous post have been very helpfull to me.
I know that it has been a while from this post now...
But what we need now is to send email notifications when I enroll a user just to let him know that he has to take the course, it's like an invitation to take the course.
I have linked LDAP syncronization with the cron job and all is working as it should, but we need this extra funcionallity...
is this possible?
after we enroll a user to a course moodle send a mail to th euser with something like...
You have been invited to the Secuity Concientitation
to take the course click HERE
Regards!
That's it, this could help us a lot !
Thank you very much for your help!
Re: Manual enrolment: does it send any notification?
Hi, this code works grat, but I have a problem, the send mail from tag appear "unknown" and I would like to change the "from" tag mail so it say from: sitename...
Where do I change that? thanks I apreciate your help
Re: Manual enrolment: does it send any notification?
make sure you set 'Support username' and 'Support email' under Site Administration >> Server >> Email (in Moodle 1.9 and Moodle 2.0) or Site Administration >> Server >> Support Contact (in Moodle 2.1).
Saludos.
Iñaki.
Re: Manual enrolment: does it send any notification?
Hi Iñaki
Is there an update for the uploaduser hack for Moodle 2.6? We've migrated from 1.9 and found that one of the key functionalities from our old site, which may have been a hack, is now missing; when bulk uploading from Upload Users, the only emails generated are when a student doesn't exist. We need emails for both when they exist and when they don't, as Upload Users is our method of both adding and enrolling participants (students) in one hit.
The flatfile method doesn't work for us as this only works for participants that are already in the system, and we don't know who is already in there and who isn't. We have new participants coming and going all the time.
Any help would be greatly appreciated, we've been searching for a solution for this for weeks, and there's confusing contradictory information all over the place
Lee
Re: Manual enrolment: does it send any notification?
G'day Lee,
Did you ever have any joy with this one?
Cheers,
-Matt.