2009-09-30 06:32:25 +00:00
|
|
|
<?php
|
2004-01-06 02:48:12 +00:00
|
|
|
|
|
|
|
/// Bulk user registration script from a comma separated file
|
|
|
|
/// Returns list of users with their user ids
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
require('../config.php');
|
2006-09-24 12:31:49 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2007-11-05 00:43:37 +00:00
|
|
|
require_once($CFG->libdir.'/csvlib.class.php');
|
|
|
|
require_once($CFG->dirroot.'/user/profile/lib.php');
|
2007-05-02 09:33:56 +00:00
|
|
|
require_once('uploaduser_form.php');
|
2007-04-30 17:08:34 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
$iid = optional_param('iid', '', PARAM_INT);
|
2007-11-02 08:41:05 +00:00
|
|
|
$previewrows = optional_param('previewrows', 10, PARAM_INT);
|
2007-11-05 00:43:37 +00:00
|
|
|
$readcount = optional_param('readcount', 0, PARAM_INT);
|
2010-02-05 07:30:53 +00:00
|
|
|
$uploadtype = optional_param('uutype', 0, PARAM_INT);
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
define('UU_ADDNEW', 0);
|
|
|
|
define('UU_ADDINC', 1);
|
|
|
|
define('UU_ADD_UPDATE', 2);
|
|
|
|
define('UU_UPDATE', 3);
|
2007-08-20 08:51:35 +00:00
|
|
|
|
2010-02-05 07:30:53 +00:00
|
|
|
$choices = array(UU_ADDNEW => get_string('uuoptype_addnew', 'admin'),
|
|
|
|
UU_ADDINC => get_string('uuoptype_addinc', 'admin'),
|
|
|
|
UU_ADD_UPDATE => get_string('uuoptype_addupdate', 'admin'),
|
|
|
|
UU_UPDATE => get_string('uuoptype_update', 'admin'));
|
|
|
|
|
2007-11-02 08:41:05 +00:00
|
|
|
@set_time_limit(3600); // 1 hour should be enough
|
|
|
|
@raise_memory_limit('256M');
|
|
|
|
if (function_exists('apache_child_terminate')) {
|
2007-11-05 00:43:37 +00:00
|
|
|
// if we are running from Apache, give httpd a hint that
|
|
|
|
// it can recycle the process after it's done. Apache's
|
2007-11-02 08:41:05 +00:00
|
|
|
// memory management is truly awful but we can help it.
|
|
|
|
@apache_child_terminate();
|
|
|
|
}
|
2004-01-06 02:48:12 +00:00
|
|
|
|
2009-07-20 08:57:18 +00:00
|
|
|
require_login();
|
2007-08-20 08:51:35 +00:00
|
|
|
admin_externalpage_setup('uploadusers');
|
2007-04-30 17:08:34 +00:00
|
|
|
require_capability('moodle/site:uploadusers', get_context_instance(CONTEXT_SYSTEM));
|
2004-01-06 02:48:12 +00:00
|
|
|
|
2007-09-10 07:02:52 +00:00
|
|
|
$textlib = textlib_get_instance();
|
2007-11-05 00:43:37 +00:00
|
|
|
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
|
|
|
|
|
|
|
$struserrenamed = get_string('userrenamed', 'admin');
|
|
|
|
$strusernotrenamedexists = get_string('usernotrenamedexists', 'error');
|
|
|
|
$strusernotrenamedmissing = get_string('usernotrenamedmissing', 'error');
|
|
|
|
$strusernotrenamedoff = get_string('usernotrenamedoff', 'error');
|
|
|
|
$strusernotrenamedadmin = get_string('usernotrenamedadmin', 'error');
|
|
|
|
|
|
|
|
$struserupdated = get_string('useraccountupdated', 'admin');
|
|
|
|
$strusernotupdated = get_string('usernotupdatederror', 'error');
|
|
|
|
$strusernotupdatednotexists = get_string('usernotupdatednotexists', 'error');
|
|
|
|
$strusernotupdatedadmin = get_string('usernotupdatedadmin', 'error');
|
|
|
|
|
|
|
|
$struseradded = get_string('newuser');
|
|
|
|
$strusernotadded = get_string('usernotaddedregistered', 'error');
|
|
|
|
$strusernotaddederror = get_string('usernotaddederror', 'error');
|
|
|
|
|
|
|
|
$struserdeleted = get_string('userdeleted', 'admin');
|
|
|
|
$strusernotdeletederror = get_string('usernotdeletederror', 'error');
|
|
|
|
$strusernotdeletedmissing = get_string('usernotdeletedmissing', 'error');
|
|
|
|
$strusernotdeletedoff = get_string('usernotdeletedoff', 'error');
|
|
|
|
$strusernotdeletedadmin = get_string('usernotdeletedadmin', 'error');
|
|
|
|
|
|
|
|
$strcannotassignrole = get_string('cannotassignrole', 'error');
|
|
|
|
$strduplicateusername = get_string('duplicateusername', 'error');
|
|
|
|
|
|
|
|
$struserauthunsupported = get_string('userauthunsupported', 'error');
|
2010-02-05 07:30:53 +00:00
|
|
|
$stremailduplicate = get_string('useremailduplicate', 'error');
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
$errorstr = get_string('error');
|
2004-01-07 06:55:35 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
$returnurl = $CFG->wwwroot.'/'.$CFG->admin.'/uploaduser.php';
|
|
|
|
$bulknurl = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
|
|
|
|
|
2010-07-13 20:58:17 +00:00
|
|
|
$today = time();
|
|
|
|
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
// array of all valid fields for validation
|
2009-06-22 01:22:37 +00:00
|
|
|
$STD_FIELDS = array('id', 'firstname', 'lastname', 'username', 'email',
|
|
|
|
'city', 'country', 'lang', 'auth', 'timezone', 'mailformat',
|
|
|
|
'maildisplay', 'maildigest', 'htmleditor', 'ajax', 'autosubscribe',
|
|
|
|
'mnethostid', 'institution', 'department', 'idnumber', 'skype',
|
|
|
|
'msn', 'aim', 'yahoo', 'icq', 'phone1', 'phone2', 'address',
|
2009-11-04 06:14:06 +00:00
|
|
|
'url', 'description', 'descriptionformat', 'oldusername', 'emailstop', 'deleted',
|
2008-04-23 02:07:11 +00:00
|
|
|
'password');
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
$PRF_FIELDS = array();
|
|
|
|
|
2008-05-30 21:36:57 +00:00
|
|
|
if ($prof_fields = $DB->get_records('user_info_field')) {
|
2007-11-05 00:43:37 +00:00
|
|
|
foreach ($prof_fields as $prof_field) {
|
|
|
|
$PRF_FIELDS[] = 'profile_field_'.$prof_field->shortname;
|
|
|
|
}
|
|
|
|
unset($prof_fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($iid)) {
|
2007-11-02 08:41:05 +00:00
|
|
|
$mform = new admin_uploaduser_form1();
|
2004-01-06 02:48:12 +00:00
|
|
|
|
2007-11-02 08:41:05 +00:00
|
|
|
if ($formdata = $mform->get_data()) {
|
2007-11-05 00:43:37 +00:00
|
|
|
$iid = csv_import_reader::get_new_iid('uploaduser');
|
|
|
|
$cir = new csv_import_reader($iid, 'uploaduser');
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
$content = $mform->get_file_content('userfile');
|
2010-02-05 07:30:53 +00:00
|
|
|
$optype = $formdata->uutype;
|
2007-11-05 00:43:37 +00:00
|
|
|
$readcount = $cir->load_csv_content($content, $formdata->encoding, $formdata->delimiter_name, 'validate_user_upload_columns');
|
|
|
|
unset($content);
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
if ($readcount === false) {
|
2008-06-15 12:02:43 +00:00
|
|
|
//TODO: need more detailed error info
|
|
|
|
print_error('csvloaderror', '', $returnurl);
|
2007-11-05 00:43:37 +00:00
|
|
|
} else if ($readcount == 0) {
|
2008-04-04 02:54:20 +00:00
|
|
|
print_error('csvemptyfile', 'error', $returnurl);
|
2007-11-01 19:37:25 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
// continue to form2
|
2007-11-02 08:41:05 +00:00
|
|
|
|
|
|
|
} else {
|
2010-03-31 08:05:53 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-09-30 06:32:25 +00:00
|
|
|
|
MDL-21695 Upload pictures and upload users - strings cleanup and fixing
Strings related to users uploading moved into admin.php component. Fixed
calling of new help strings. Fixed incorrect strings call.
The script also copies instructions from two previous commits as I
forgot that the commit must touch some string file to being parsed by
amos.
AMOS BEGIN
HLP uploadusers3.html,[uploadusers_help,core_admin]
HLP uploadusers2.html,[uploadusers_help,core_admin]
HLP uploadusers.html,[uploadusers_help,core_admin]
HLP uploadpictures.html,[uploadpictures_help,core_admin]
MOV [uploadusers,core],[uploadusers,core_admin]
MOV [uploadusers_help,core],[uploadusers_help,core_admin]
HLP cookies.html,[cookiesenabled_help,core]
HLP overrides.html,[overridepermissions_help,core_role]
HLP permissions.html,[permission_help,core_role]
AMOS END
2010-05-17 15:16:33 +00:00
|
|
|
echo $OUTPUT->heading_with_help(get_string('uploadusers', 'admin'), 'uploadusers', 'admin');
|
2009-09-30 06:32:25 +00:00
|
|
|
|
2007-11-02 08:41:05 +00:00
|
|
|
$mform->display();
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|
2007-11-02 08:41:05 +00:00
|
|
|
die;
|
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
} else {
|
|
|
|
$cir = new csv_import_reader($iid, 'uploaduser');
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
if (!$columns = $cir->get_columns()) {
|
2008-04-10 03:44:09 +00:00
|
|
|
print_error('cannotreadtmpfile', 'error', $returnurl);
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
|
|
|
$mform = new admin_uploaduser_form2(null, $columns);
|
|
|
|
// get initial date from form1
|
2010-02-05 07:30:53 +00:00
|
|
|
$mform->set_data(array('iid'=>$iid, 'previewrows'=>$previewrows, 'readcount'=>$readcount, 'uutypelabel'=>$choices[$uploadtype], 'uutype'=>$uploadtype));
|
2007-11-02 08:41:05 +00:00
|
|
|
|
|
|
|
// If a file has been uploaded, then process it
|
|
|
|
if ($formdata = $mform->is_cancelled()) {
|
2007-11-05 00:43:37 +00:00
|
|
|
$cir->cleanup(true);
|
|
|
|
redirect($returnurl);
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2008-06-09 16:53:30 +00:00
|
|
|
} else if ($formdata = $mform->get_data()) {
|
2007-11-02 08:41:05 +00:00
|
|
|
// Print the header
|
2010-03-31 08:05:53 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-08-06 08:17:12 +00:00
|
|
|
echo $OUTPUT->heading(get_string('uploadusersresult', 'admin'));
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
$optype = $formdata->uutype;
|
|
|
|
|
2007-11-05 09:36:46 +00:00
|
|
|
$createpasswords = (!empty($formdata->uupasswordnew) and $optype != UU_UPDATE);
|
|
|
|
$updatepasswords = (!empty($formdata->uupasswordold) and $optype != UU_ADDNEW and $optype != UU_ADDINC);
|
|
|
|
$allowrenames = (!empty($formdata->uuallowrenames) and $optype != UU_ADDNEW and $optype != UU_ADDINC);
|
|
|
|
$allowdeletes = (!empty($formdata->uuallowdeletes) and $optype != UU_ADDNEW and $optype != UU_ADDINC);
|
|
|
|
$updatetype = isset($formdata->uuupdatetype) ? $formdata->uuupdatetype : 0;
|
|
|
|
$bulk = $formdata->uubulk;
|
|
|
|
$noemailduplicates = $formdata->uunoemailduplicates;
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
// verification moved to two places: after upload and into form2
|
|
|
|
$usersnew = 0;
|
|
|
|
$usersupdated = 0;
|
|
|
|
$userserrors = 0;
|
|
|
|
$deletes = 0;
|
|
|
|
$deleteerrors = 0;
|
|
|
|
$renames = 0;
|
|
|
|
$renameerrors = 0;
|
|
|
|
$usersskipped = 0;
|
2009-11-25 17:05:54 +00:00
|
|
|
$weakpasswords = 0;
|
2008-09-26 09:13:24 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
// caches
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$ccache = array(); // course cache - do not fetch all courses here, we will not probably use them all anyway!
|
|
|
|
$rolecache = uu_allowed_roles_cache(); // roles lookup cache
|
|
|
|
$manualcacche = array(); // cache of used manual enrol plugins in each course
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
$allowedauths = uu_allowed_auths();
|
|
|
|
$allowedauths = array_keys($allowedauths);
|
2009-06-19 14:25:56 +00:00
|
|
|
$availableauths = get_plugin_list('auth');
|
|
|
|
$availableauths = array_keys($availableauths);
|
2007-11-05 00:43:37 +00:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
// we use only manual enrol plugin here, if it is disabled no enrol is done
|
|
|
|
if (enrol_is_enabled('manual')) {
|
|
|
|
$manual = enrol_get_plugin('manual');
|
|
|
|
} else {
|
|
|
|
$manual = NULL;
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2008-10-18 04:19:46 +00:00
|
|
|
// clear bulk selection
|
2007-11-05 00:43:37 +00:00
|
|
|
if ($bulk) {
|
2007-11-13 08:43:20 +00:00
|
|
|
$SESSION->bulk_users = array();
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
// init csv import helper
|
|
|
|
$cir->init();
|
|
|
|
$linenum = 1; //column header is first line
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
// init upload progress tracker
|
|
|
|
$upt = new uu_progress_tracker();
|
|
|
|
$upt->init(); // start table
|
2006-01-16 03:15:32 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
while ($line = $cir->next()) {
|
|
|
|
$upt->flush();
|
|
|
|
$linenum++;
|
|
|
|
|
|
|
|
$upt->track('line', $linenum);
|
|
|
|
|
2009-11-25 17:05:54 +00:00
|
|
|
$forcechangepassword = false;
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
$user = new object();
|
|
|
|
// by default, use the local mnet id (this may be changed in the file)
|
|
|
|
$user->mnethostid = $CFG->mnet_localhost_id;
|
|
|
|
// add fields to user object
|
|
|
|
foreach ($line as $key => $value) {
|
|
|
|
if ($value !== '') {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$key = $columns[$key];
|
2007-11-05 00:43:37 +00:00
|
|
|
// password is special field
|
|
|
|
if ($key == 'password') {
|
|
|
|
if ($value !== '') {
|
|
|
|
$user->password = hash_internal_user_password($value);
|
2008-09-26 09:13:24 +00:00
|
|
|
if (!empty($CFG->passwordpolicy) and !check_password_policy($value, $errmsg)) {
|
2009-11-25 17:05:54 +00:00
|
|
|
$forcechangepassword = true;
|
|
|
|
$weakpasswords++;
|
2008-09-26 09:13:24 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$user->$key = $value;
|
|
|
|
if (in_array($key, $upt->columns)) {
|
|
|
|
$upt->track($key, $value);
|
|
|
|
}
|
|
|
|
}
|
2007-08-22 06:17:11 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
// get username, first/last name now - we need them in templates!!
|
|
|
|
if ($optype == UU_UPDATE) {
|
|
|
|
// when updating only username is required
|
|
|
|
if (!isset($user->username)) {
|
|
|
|
$upt->track('status', get_string('missingfield', 'error', 'username'), 'error');
|
|
|
|
$upt->track('username', $errorstr, 'error');
|
|
|
|
$userserrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$error = false;
|
|
|
|
// when all other ops need firstname and lastname
|
|
|
|
if (!isset($user->firstname) or $user->firstname === '') {
|
|
|
|
$upt->track('status', get_string('missingfield', 'error', 'firstname'), 'error');
|
|
|
|
$upt->track('firstname', $errorstr, 'error');
|
|
|
|
$error = true;
|
|
|
|
}
|
|
|
|
if (!isset($user->lastname) or $user->lastname === '') {
|
|
|
|
$upt->track('status', get_string('missingfield', 'error', 'lastname'), 'error');
|
|
|
|
$upt->track('lastname', $errorstr, 'error');
|
|
|
|
$error = true;
|
|
|
|
}
|
|
|
|
if ($error) {
|
|
|
|
$userserrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// we require username too - we might use template for it though
|
|
|
|
if (!isset($user->username)) {
|
|
|
|
if (!isset($formdata->username) or $formdata->username === '') {
|
|
|
|
$upt->track('status', get_string('missingfield', 'error', 'username'), 'error');
|
|
|
|
$upt->track('username', $errorstr, 'error');
|
|
|
|
$userserrors++;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
$user->username = process_template($formdata->username, $user);
|
|
|
|
$upt->track('username', $user->username);
|
|
|
|
}
|
|
|
|
}
|
2007-08-22 06:17:11 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
// normalize username
|
2010-01-13 06:23:54 +00:00
|
|
|
$user->username = clean_param($user->username, PARAM_USERNAME);
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
if (empty($user->username)) {
|
|
|
|
$upt->track('status', get_string('missingfield', 'error', 'username'), 'error');
|
|
|
|
$upt->track('username', $errorstr, 'error');
|
|
|
|
$userserrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-05-30 21:36:57 +00:00
|
|
|
if ($existinguser = $DB->get_record('user', array('username'=>$user->username, 'mnethostid'=>$user->mnethostid))) {
|
2007-11-05 00:43:37 +00:00
|
|
|
$upt->track('id', $existinguser->id, 'normal', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// find out in username incrementing required
|
|
|
|
if ($existinguser and $optype == UU_ADDINC) {
|
|
|
|
$oldusername = $user->username;
|
|
|
|
$user->username = increment_username($user->username, $user->mnethostid);
|
|
|
|
$upt->track('username', '', 'normal', false); // clear previous
|
|
|
|
$upt->track('username', $oldusername.'-->'.$user->username, 'info');
|
|
|
|
$existinguser = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add default values for remaining fields
|
|
|
|
foreach ($STD_FIELDS as $field) {
|
|
|
|
if (isset($user->$field)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// all validation moved to form2
|
|
|
|
if (isset($formdata->$field)) {
|
|
|
|
// process templates
|
|
|
|
$user->$field = process_template($formdata->$field, $user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($PRF_FIELDS as $field) {
|
|
|
|
if (isset($user->$field)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isset($formdata->$field)) {
|
|
|
|
// process templates
|
|
|
|
$user->$field = process_template($formdata->$field, $user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete user
|
|
|
|
if (!empty($user->deleted)) {
|
|
|
|
if (!$allowdeletes) {
|
|
|
|
$usersskipped++;
|
|
|
|
$upt->track('status', $strusernotdeletedoff, 'warning');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($existinguser) {
|
2010-03-31 07:41:31 +00:00
|
|
|
if (is_siteadmin($existinguser->id)) {
|
2007-11-05 00:43:37 +00:00
|
|
|
$upt->track('status', $strusernotdeletedadmin, 'error');
|
|
|
|
$deleteerrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (delete_user($existinguser)) {
|
|
|
|
$upt->track('status', $struserdeleted);
|
|
|
|
$deletes++;
|
|
|
|
} else {
|
|
|
|
$upt->track('status', $strusernotdeletederror, 'error');
|
|
|
|
$deleteerrors++;
|
2006-03-17 16:19:31 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
} else {
|
|
|
|
$upt->track('status', $strusernotdeletedmissing, 'error');
|
|
|
|
$deleteerrors++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// we do not need the deleted flag anymore
|
|
|
|
unset($user->deleted);
|
|
|
|
|
|
|
|
// renaming requested?
|
|
|
|
if (!empty($user->oldusername) ) {
|
|
|
|
$oldusername = $textlib->strtolower($user->oldusername);
|
|
|
|
if (!$allowrenames) {
|
|
|
|
$usersskipped++;
|
|
|
|
$upt->track('status', $strusernotrenamedoff, 'warning');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($existinguser) {
|
|
|
|
$upt->track('status', $strusernotrenamedexists, 'error');
|
|
|
|
$renameerrors++;
|
|
|
|
continue;
|
2005-11-22 02:55:55 +00:00
|
|
|
}
|
2007-11-01 19:37:25 +00:00
|
|
|
|
2008-05-30 21:36:57 +00:00
|
|
|
if ($olduser = $DB->get_record('user', array('username'=>$oldusername, 'mnethostid'=>$user->mnethostid))) {
|
2007-11-05 00:43:37 +00:00
|
|
|
$upt->track('id', $olduser->id, 'normal', false);
|
2010-03-31 07:41:31 +00:00
|
|
|
if (is_siteadmin($olduser->id)) {
|
2007-11-05 00:43:37 +00:00
|
|
|
$upt->track('status', $strusernotrenamedadmin, 'error');
|
|
|
|
$renameerrors++;
|
2007-08-22 06:17:11 +00:00
|
|
|
continue;
|
2005-11-22 02:58:45 +00:00
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$DB->set_field('user', 'username', $user->username, array('id'=>$olduser->id));
|
|
|
|
$upt->track('username', '', 'normal', false); // clear previous
|
|
|
|
$upt->track('username', $oldusername.'-->'.$user->username, 'info');
|
|
|
|
$upt->track('status', $struserrenamed);
|
|
|
|
$renames++;
|
2007-11-05 00:43:37 +00:00
|
|
|
} else {
|
|
|
|
$upt->track('status', $strusernotrenamedmissing, 'error');
|
|
|
|
$renameerrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$existinguser = $olduser;
|
|
|
|
$existinguser->username = $user->username;
|
|
|
|
}
|
|
|
|
|
|
|
|
// can we process with update or insert?
|
|
|
|
$skip = false;
|
|
|
|
switch ($optype) {
|
|
|
|
case UU_ADDNEW:
|
|
|
|
if ($existinguser) {
|
|
|
|
$usersskipped++;
|
|
|
|
$upt->track('status', $strusernotadded, 'warning');
|
2010-02-05 07:30:53 +00:00
|
|
|
$skip = true;
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UU_ADDINC:
|
|
|
|
if ($existinguser) {
|
|
|
|
//this should not happen!
|
|
|
|
$upt->track('status', $strusernotaddederror, 'error');
|
|
|
|
$userserrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UU_ADD_UPDATE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UU_UPDATE:
|
|
|
|
if (!$existinguser) {
|
|
|
|
$usersskipped++;
|
|
|
|
$upt->track('status', $strusernotupdatednotexists, 'warning');
|
|
|
|
$skip = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($skip) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($existinguser) {
|
|
|
|
$user->id = $existinguser->id;
|
|
|
|
|
2010-03-31 07:41:31 +00:00
|
|
|
if (is_siteadmin($user->id)) {
|
2007-11-05 00:43:37 +00:00
|
|
|
$upt->track('status', $strusernotupdatedadmin, 'error');
|
|
|
|
$userserrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$updatetype) {
|
|
|
|
// no updates of existing data at all
|
|
|
|
} else {
|
|
|
|
$existinguser->timemodified = time();
|
2010-02-05 07:30:53 +00:00
|
|
|
if (empty($existinguser->timecreated)) {
|
|
|
|
if (empty($existinguser->firstaccess)) {
|
|
|
|
$existinguser->timecreated = time();
|
|
|
|
} else {
|
|
|
|
$existinguser->timecreated = $existinguser->firstaccess;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
//load existing profile data
|
|
|
|
profile_load_data($existinguser);
|
|
|
|
|
|
|
|
$allowed = array();
|
|
|
|
if ($updatetype == 1) {
|
|
|
|
$allowed = $columns;
|
|
|
|
} else if ($updatetype == 2 or $updatetype == 3) {
|
|
|
|
$allowed = array_merge($STD_FIELDS, $PRF_FIELDS);
|
|
|
|
}
|
|
|
|
foreach ($allowed as $column) {
|
|
|
|
if ($column == 'username') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($column == 'password') {
|
|
|
|
if (!$updatepasswords or $updatetype == 3) {
|
2007-08-22 06:17:11 +00:00
|
|
|
continue;
|
2007-11-05 00:43:37 +00:00
|
|
|
} else if (!empty($user->password)) {
|
|
|
|
$upt->track('password', get_string('updated'));
|
2008-09-26 09:13:24 +00:00
|
|
|
if ($forcechangepassword) {
|
|
|
|
set_user_preference('auth_forcepasswordchange', 1, $existinguser->id);
|
|
|
|
}
|
2007-08-22 06:17:11 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
|
|
|
if ((array_key_exists($column, $existinguser) and array_key_exists($column, $user)) or in_array($column, $PRF_FIELDS)) {
|
|
|
|
if ($updatetype == 3 and $existinguser->$column !== '') {
|
|
|
|
//missing == non-empty only
|
|
|
|
continue;
|
2007-08-22 06:17:11 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
if ($existinguser->$column !== $user->$column) {
|
2007-11-05 09:36:46 +00:00
|
|
|
if ($column == 'email') {
|
2008-05-30 21:36:57 +00:00
|
|
|
if ($DB->record_exists('user', array('email'=>$user->email))) {
|
2007-11-05 09:36:46 +00:00
|
|
|
if ($noemailduplicates) {
|
|
|
|
$upt->track('email', $stremailduplicate, 'error');
|
|
|
|
$upt->track('status', $strusernotupdated, 'error');
|
|
|
|
$userserrors++;
|
|
|
|
continue 2;
|
|
|
|
} else {
|
|
|
|
$upt->track('email', $stremailduplicate, 'warning');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
if ($column != 'password' and in_array($column, $upt->columns)) {
|
|
|
|
$upt->track($column, '', 'normal', false); // clear previous
|
|
|
|
$upt->track($column, $existinguser->$column.'-->'.$user->$column, 'info');
|
|
|
|
}
|
|
|
|
$existinguser->$column = $user->$column;
|
2007-08-22 06:17:11 +00:00
|
|
|
}
|
2006-03-17 16:19:31 +00:00
|
|
|
}
|
2007-08-22 06:17:11 +00:00
|
|
|
}
|
2007-11-01 19:37:25 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
// do not update record if new auth plguin does not exist!
|
|
|
|
if (!in_array($existinguser->auth, $availableauths)) {
|
|
|
|
$upt->track('auth', get_string('userautherror', 'error', $existinguser->auth), 'error');
|
|
|
|
$upt->track('status', $strusernotupdated, 'error');
|
|
|
|
$userserrors++;
|
|
|
|
continue;
|
|
|
|
} else if (!in_array($existinguser->auth, $allowedauths)) {
|
|
|
|
$upt->track('auth', $struserauthunsupported, 'warning');
|
2007-08-20 08:51:35 +00:00
|
|
|
}
|
2007-08-22 06:17:11 +00:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$DB->update_record('user', $existinguser);
|
|
|
|
$upt->track('status', $struserupdated);
|
|
|
|
$usersupdated++;
|
2007-11-05 00:43:37 +00:00
|
|
|
// save custom profile fields data from csv file
|
2008-05-30 22:11:31 +00:00
|
|
|
profile_save_data($existinguser);
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($bulk == 2 or $bulk == 3) {
|
2007-11-13 08:43:20 +00:00
|
|
|
if (!in_array($user->id, $SESSION->bulk_users)) {
|
|
|
|
$SESSION->bulk_users[] = $user->id;
|
2007-11-01 19:37:25 +00:00
|
|
|
}
|
2007-08-20 08:51:35 +00:00
|
|
|
}
|
2007-11-01 19:37:25 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
} else {
|
2007-08-22 06:17:11 +00:00
|
|
|
// save the user to the database
|
|
|
|
$user->confirmed = 1;
|
|
|
|
$user->timemodified = time();
|
2010-02-05 07:30:53 +00:00
|
|
|
$user->timecreated = time();
|
2007-08-20 08:51:35 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
if (!$createpasswords and empty($user->password)) {
|
|
|
|
$upt->track('password', get_string('missingfield', 'error', 'password'), 'error');
|
|
|
|
$upt->track('status', $strusernotaddederror, 'error');
|
|
|
|
$userserrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// do not insert record if new auth plguin does not exist!
|
|
|
|
if (isset($user->auth)) {
|
|
|
|
if (!in_array($user->auth, $availableauths)) {
|
|
|
|
$upt->track('auth', get_string('userautherror', 'error', $user->auth), 'error');
|
|
|
|
$upt->track('status', $strusernotaddederror, 'error');
|
|
|
|
$userserrors++;
|
2007-08-20 08:51:35 +00:00
|
|
|
continue;
|
2007-11-05 00:43:37 +00:00
|
|
|
} else if (!in_array($user->auth, $allowedauths)) {
|
|
|
|
$upt->track('auth', $struserauthunsupported, 'warning');
|
2007-08-20 08:51:35 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-16 03:15:32 +00:00
|
|
|
|
2008-05-30 21:36:57 +00:00
|
|
|
if ($DB->record_exists('user', array('email'=>$user->email))) {
|
2007-11-05 09:36:46 +00:00
|
|
|
if ($noemailduplicates) {
|
|
|
|
$upt->track('email', $stremailduplicate, 'error');
|
|
|
|
$upt->track('status', $strusernotaddederror, 'error');
|
|
|
|
$userserrors++;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
$upt->track('email', $stremailduplicate, 'warning');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$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 and empty($user->password)) {
|
|
|
|
// 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'));
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if ($forcechangepassword) {
|
|
|
|
set_user_preference('auth_forcepasswordchange', 1, $user->id);
|
|
|
|
}
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
// save custom profile fields data
|
|
|
|
profile_save_data($user);
|
|
|
|
|
2007-11-05 09:50:40 +00:00
|
|
|
// make sure user context exists
|
2007-12-19 17:06:47 +00:00
|
|
|
get_context_instance(CONTEXT_USER, $user->id);
|
2007-11-05 09:50:40 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
if ($bulk == 1 or $bulk == 3) {
|
2007-11-13 08:43:20 +00:00
|
|
|
if (!in_array($user->id, $SESSION->bulk_users)) {
|
|
|
|
$SESSION->bulk_users[] = $user->id;
|
2007-08-20 08:51:35 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
|
|
|
|
2008-01-21 06:09:58 +00:00
|
|
|
// find course enrolments, groups, roles/types and enrol periods
|
2007-11-05 00:43:37 +00:00
|
|
|
foreach ($columns as $column) {
|
|
|
|
if (!preg_match('/^course\d+$/', $column)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$i = substr($column, 6);
|
2006-03-17 16:19:31 +00:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if (empty($user->{'course'.$i})) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
$shortname = $user->{'course'.$i};
|
|
|
|
if (!array_key_exists($shortname, $ccache)) {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('shortname'=>$shortname), 'id, shortname')) {
|
2007-11-05 00:43:37 +00:00
|
|
|
$upt->track('enrolments', get_string('unknowncourse', 'error', $shortname), 'error');
|
2007-08-22 06:17:11 +00:00
|
|
|
continue;
|
2007-08-20 08:51:35 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
$ccache[$shortname] = $course;
|
|
|
|
$ccache[$shortname]->groups = null;
|
|
|
|
}
|
|
|
|
$courseid = $ccache[$shortname]->id;
|
|
|
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if (!isset($manualcache[$courseid])) {
|
|
|
|
if ($instances = enrol_get_instances($courseid, false)) {
|
|
|
|
$manualcache[$courseid] = reset($instances);
|
2007-08-22 06:17:11 +00:00
|
|
|
} else {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$manualcache[$courseid] = false;
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if ($manual and $manualcache[$courseid]) {
|
|
|
|
|
|
|
|
// find role
|
|
|
|
$rid = false;
|
|
|
|
if (!empty($user->{'role'.$i})) {
|
|
|
|
$addrole = $user->{'role'.$i};
|
|
|
|
if (array_key_exists($addrole, $rolecache)) {
|
|
|
|
$rid = $rolecache[$addrole]->id;
|
2007-11-05 00:43:37 +00:00
|
|
|
} else {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$upt->track('enrolments', get_string('unknownrole', 'error', $addrole), 'error');
|
|
|
|
continue;
|
2007-08-22 06:17:11 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
} else if (!empty($user->{'type'.$i})) {
|
|
|
|
// if no role, then find "old" enrolment type
|
|
|
|
$addtype = $user->{'type'.$i};
|
|
|
|
if ($addtype < 1 or $addtype > 3) {
|
|
|
|
$upt->track('enrolments', $strerror.': typeN = 1|2|3', 'error');
|
|
|
|
continue;
|
|
|
|
} else if (empty($formdata->{'uulegacy'.$addtype})) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
$rid = $formdata->{'uulegacy'.$addtype};
|
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
} else {
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
// no role specified, use the default from manual enrol plugin
|
|
|
|
$rid = $manualcache[$courseid]->roleid;
|
2007-08-22 06:17:11 +00:00
|
|
|
}
|
2008-01-21 06:09:58 +00:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
if ($rid) {
|
|
|
|
// find duration
|
|
|
|
$timeend = 0;
|
|
|
|
if (!empty($user->{'enrolperiod'.$i})) {
|
|
|
|
$duration = (int)$user->{'enrolperiod'.$i} * 86400; // convert days to seconds
|
|
|
|
if ($duration > 0) { // sanity check
|
2010-07-13 20:58:17 +00:00
|
|
|
$timeend = $today + $duration;
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-21 06:09:58 +00:00
|
|
|
|
2010-07-13 20:58:17 +00:00
|
|
|
$manual->enrol_user($manualcache[$courseid], $user->id, $rid, $today, $timeend, true);
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
|
|
|
|
$a = new object();
|
|
|
|
$a->course = $shortname;
|
|
|
|
$a->role = $rolecache[$rid]->name;
|
|
|
|
$upt->track('enrolments', get_string('enrolledincourserole', 'enrol_manual', $a));
|
2007-08-20 08:51:35 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
2006-03-17 16:19:31 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
// find group to add to
|
|
|
|
if (!empty($user->{'group'.$i})) {
|
|
|
|
// make sure user is enrolled into course before adding into groups
|
2010-03-31 07:41:31 +00:00
|
|
|
if (!is_enrolled($coursecontext, $user->id)) {
|
2007-11-05 00:43:37 +00:00
|
|
|
$upt->track('enrolments', get_string('addedtogroupnotenrolled', '', $gname), 'error');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//build group cache
|
|
|
|
if (is_null($ccache[$shortname]->groups)) {
|
|
|
|
$ccache[$shortname]->groups = array();
|
2008-05-01 22:30:28 +00:00
|
|
|
if ($groups = groups_get_all_groups($courseid)) {
|
2007-11-05 00:43:37 +00:00
|
|
|
foreach ($groups as $gid=>$group) {
|
|
|
|
$ccache[$shortname]->groups[$gid] = new object();
|
|
|
|
$ccache[$shortname]->groups[$gid]->id = $gid;
|
|
|
|
$ccache[$shortname]->groups[$gid]->name = $group->name;
|
|
|
|
if (!is_numeric($group->name)) { // only non-numeric names are supported!!!
|
|
|
|
$ccache[$shortname]->groups[$group->name] = new object();
|
|
|
|
$ccache[$shortname]->groups[$group->name]->id = $gid;
|
|
|
|
$ccache[$shortname]->groups[$group->name]->name = $group->name;
|
2007-08-22 06:17:11 +00:00
|
|
|
}
|
2005-12-06 04:53:28 +00:00
|
|
|
}
|
2005-11-22 02:58:45 +00:00
|
|
|
}
|
2006-03-17 16:19:31 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
// group exists?
|
|
|
|
$addgroup = $user->{'group'.$i};
|
|
|
|
if (!array_key_exists($addgroup, $ccache[$shortname]->groups)) {
|
2008-02-14 03:15:03 +00:00
|
|
|
// if group doesn't exist, create it
|
|
|
|
$newgroupdata = new object();
|
|
|
|
$newgroupdata->name = $addgroup;
|
|
|
|
$newgroupdata->courseid = $ccache[$shortname]->id;
|
|
|
|
if ($ccache[$shortname]->groups[$addgroup]->id = groups_create_group($newgroupdata)){
|
|
|
|
$ccache[$shortname]->groups[$addgroup]->name = $newgroupdata->name;
|
|
|
|
} else {
|
|
|
|
$upt->track('enrolments', get_string('unknowngroup', 'error', $addgroup), 'error');
|
|
|
|
continue;
|
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
|
|
|
$gid = $ccache[$shortname]->groups[$addgroup]->id;
|
|
|
|
$gname = $ccache[$shortname]->groups[$addgroup]->name;
|
|
|
|
|
2009-03-09 04:49:50 +00:00
|
|
|
try {
|
|
|
|
if (groups_add_member($gid, $user->id)) {
|
|
|
|
$upt->track('enrolments', get_string('addedtogroup', '', $gname));
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
} else {
|
|
|
|
$upt->track('enrolments', get_string('addedtogroupnot', '', $gname), 'error');
|
2009-03-09 04:49:50 +00:00
|
|
|
}
|
|
|
|
} catch (moodle_exception $e) {
|
2007-11-05 00:43:37 +00:00
|
|
|
$upt->track('enrolments', get_string('addedtogroupnot', '', $gname), 'error');
|
|
|
|
continue;
|
|
|
|
}
|
2005-12-06 04:53:28 +00:00
|
|
|
}
|
2007-08-20 08:51:35 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
$upt->flush();
|
|
|
|
$upt->close(); // close table
|
|
|
|
|
|
|
|
$cir->close();
|
|
|
|
$cir->cleanup(true);
|
|
|
|
|
2009-08-10 04:53:22 +00:00
|
|
|
echo $OUTPUT->box_start('boxwidthnarrow boxaligncenter generalbox', 'uploadresults');
|
2007-11-05 00:43:37 +00:00
|
|
|
echo '<p>';
|
|
|
|
if ($optype != UU_UPDATE) {
|
|
|
|
echo get_string('userscreated', 'admin').': '.$usersnew.'<br />';
|
|
|
|
}
|
|
|
|
if ($optype == UU_UPDATE or $optype == UU_ADD_UPDATE) {
|
|
|
|
echo get_string('usersupdated', 'admin').': '.$usersupdated.'<br />';
|
|
|
|
}
|
|
|
|
if ($allowdeletes) {
|
|
|
|
echo get_string('usersdeleted', 'admin').': '.$deletes.'<br />';
|
|
|
|
echo get_string('deleteerrors', 'admin').': '.$deleteerrors.'<br />';
|
|
|
|
}
|
|
|
|
if ($allowrenames) {
|
|
|
|
echo get_string('usersrenamed', 'admin').': '.$renames.'<br />';
|
|
|
|
echo get_string('renameerrors', 'admin').': '.$renameerrors.'<br />';
|
|
|
|
}
|
|
|
|
if ($usersskipped) {
|
|
|
|
echo get_string('usersskipped', 'admin').': '.$usersskipped.'<br />';
|
|
|
|
}
|
2009-11-25 17:05:54 +00:00
|
|
|
echo get_string('usersweakpassword', 'admin').': '.$weakpasswords.'<br />';
|
2007-11-05 00:43:37 +00:00
|
|
|
echo get_string('errors', 'admin').': '.$userserrors.'</p>';
|
2009-08-10 04:53:22 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
if ($bulk) {
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->continue_button($bulknurl);
|
2007-11-05 00:43:37 +00:00
|
|
|
} else {
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->continue_button($returnurl);
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|
2007-11-02 08:41:05 +00:00
|
|
|
die;
|
2006-03-17 16:19:31 +00:00
|
|
|
}
|
2004-01-06 02:48:12 +00:00
|
|
|
|
2007-11-02 08:41:05 +00:00
|
|
|
// Print the header
|
2010-03-31 08:05:53 +00:00
|
|
|
echo $OUTPUT->header();
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2005-12-06 04:53:28 +00:00
|
|
|
/// Print the form
|
2009-09-30 06:32:25 +00:00
|
|
|
|
MDL-21695 Upload pictures and upload users - strings cleanup and fixing
Strings related to users uploading moved into admin.php component. Fixed
calling of new help strings. Fixed incorrect strings call.
The script also copies instructions from two previous commits as I
forgot that the commit must touch some string file to being parsed by
amos.
AMOS BEGIN
HLP uploadusers3.html,[uploadusers_help,core_admin]
HLP uploadusers2.html,[uploadusers_help,core_admin]
HLP uploadusers.html,[uploadusers_help,core_admin]
HLP uploadpictures.html,[uploadpictures_help,core_admin]
MOV [uploadusers,core],[uploadusers,core_admin]
MOV [uploadusers_help,core],[uploadusers_help,core_admin]
HLP cookies.html,[cookiesenabled_help,core]
HLP overrides.html,[overridepermissions_help,core_role]
HLP permissions.html,[permission_help,core_role]
AMOS END
2010-05-17 15:16:33 +00:00
|
|
|
echo $OUTPUT->heading(get_string('uploaduserspreview', 'admin'));
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
$cir->init();
|
2010-01-13 06:23:54 +00:00
|
|
|
|
2010-02-05 07:30:53 +00:00
|
|
|
$contents = array();
|
2007-11-05 00:43:37 +00:00
|
|
|
while ($fields = $cir->next()) {
|
2010-02-05 07:30:53 +00:00
|
|
|
$errormsg = array();
|
|
|
|
$rowcols = array();
|
|
|
|
foreach($fields as $key =>$field) {
|
|
|
|
$rowcols[$columns[$key]] = $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
$usernameexist = $DB->record_exists('user', array('username'=>$rowcols['username']));
|
|
|
|
$emailexist = $DB->record_exists('user', array('email'=>$rowcols['email']));
|
|
|
|
$cleanusername = clean_param($rowcols['username'], PARAM_USERNAME);
|
|
|
|
$validusername = strcmp($rowcols['username'], $cleanusername);
|
|
|
|
$validemail = validate_email($rowcols['email']);
|
|
|
|
|
|
|
|
if ($validusername != 0 || !$validemail) {
|
|
|
|
if ($validusername != 0) {
|
|
|
|
$errormsg['username'] = get_string('invalidusernameupload');
|
|
|
|
}
|
|
|
|
if (!$validemail) {
|
|
|
|
$errormsg['email'] = get_string('invalidemail');
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
2010-01-13 06:23:54 +00:00
|
|
|
|
2010-02-05 07:30:53 +00:00
|
|
|
switch($optype) {
|
|
|
|
case UU_ADDNEW:
|
|
|
|
if ($usernameexist || $emailexist ) {
|
|
|
|
$rowcols['action'] = 'skipped';
|
|
|
|
} else {
|
|
|
|
$rowcols['action'] = 'create';
|
2010-01-13 06:23:54 +00:00
|
|
|
}
|
2010-02-05 07:30:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UU_ADDINC:
|
|
|
|
if (!$usernameexist && !$emailexist) {
|
|
|
|
$rowcols['action'] = 'create';
|
|
|
|
} else if ($usernameexist && !$emailexist) {
|
|
|
|
$rowcols['action'] = 'addcountertousername';
|
|
|
|
$rowcols['username'] = increment_username($rowcols['username'], $CFG->mnet_localhost_id);
|
|
|
|
} else {
|
|
|
|
$rowcols['action'] = 'skipped';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UU_ADD_UPDATE:
|
|
|
|
$oldusernameexist = '';
|
|
|
|
if (isset($rowcols['oldusername'])) {
|
|
|
|
$oldusernameexist = $DB->record_exists('user', array('username'=>$rowcols['oldusername']));
|
|
|
|
}
|
|
|
|
if ($usernameexist || $emailexist || $oldusernameexist ) {
|
|
|
|
$rowcols['action'] = 'update';
|
|
|
|
} else {
|
|
|
|
$rowcols['action'] = 'create';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UU_UPDATE:
|
|
|
|
$oldusernameexist = '';
|
|
|
|
if (isset($rowcols['oldusername'])) {
|
|
|
|
$oldusernameexist = $DB->record_exists('user', array('username'=>$rowcols['oldusername']));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($usernameexist || $emailexist || !empty($oldusernameexist)) {
|
|
|
|
$rowcols['action'] = 'update';
|
|
|
|
} else {
|
|
|
|
$rowcols['action'] = "skipped";
|
|
|
|
}
|
|
|
|
break;
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
|
|
|
|
2010-02-05 07:30:53 +00:00
|
|
|
if (!empty($errormsg)){
|
|
|
|
$rowcols['error'] = array();
|
|
|
|
$rowcols['error'] = $errormsg;
|
|
|
|
}
|
|
|
|
if ($rowcols['action'] != 'skipped') {
|
|
|
|
$contents[] = $rowcols;
|
2010-01-13 06:23:54 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-05 07:30:53 +00:00
|
|
|
$cir->close();
|
2010-01-13 06:23:54 +00:00
|
|
|
|
2010-02-05 07:30:53 +00:00
|
|
|
//get heading
|
|
|
|
$headings = array();
|
|
|
|
foreach ($contents as $content) {
|
|
|
|
foreach($content as $key => $value) {
|
|
|
|
if (!in_array($key, $headings)) {
|
|
|
|
$headings[] = $key;
|
|
|
|
}
|
|
|
|
}
|
2010-01-13 06:23:54 +00:00
|
|
|
}
|
2010-02-05 07:30:53 +00:00
|
|
|
|
|
|
|
$table = new html_table();
|
|
|
|
$table->id = "uupreview";
|
2010-03-20 22:15:54 +00:00
|
|
|
$table->attributes['class'] = 'generaltable';
|
2010-02-05 07:30:53 +00:00
|
|
|
$table->tablealign = 'center';
|
|
|
|
$table->summary = get_string('uploaduserspreview', 'admin');
|
|
|
|
$table->head = array();
|
|
|
|
$table->data = array();
|
|
|
|
|
|
|
|
//print heading
|
|
|
|
foreach ($headings as $heading) {
|
|
|
|
$table->head[] = s($heading);
|
2010-01-13 06:23:54 +00:00
|
|
|
}
|
|
|
|
|
2010-02-05 07:30:53 +00:00
|
|
|
$haserror = false;
|
2010-01-13 06:23:54 +00:00
|
|
|
$countcontent = 0;
|
2010-02-05 07:30:53 +00:00
|
|
|
if (in_array('error', $headings)) {
|
|
|
|
//print error
|
|
|
|
$haserror = true;
|
|
|
|
|
|
|
|
foreach ($contents as $content) {
|
|
|
|
if (array_key_exists('error', $content)) {
|
|
|
|
$rows = new html_table_row();
|
|
|
|
foreach ($content as $key => $value) {
|
|
|
|
$cells = new html_table_cell();
|
|
|
|
$errclass = '';
|
|
|
|
if (array_key_exists($key, $content['error'])) {
|
|
|
|
$errclass = 'uuerror';
|
|
|
|
}
|
|
|
|
if ($key == 'error') {
|
|
|
|
$value = join('<br />', $content['error']);
|
|
|
|
}
|
|
|
|
if ($key == 'action') {
|
|
|
|
$value = get_string($content[$key]);
|
|
|
|
}
|
|
|
|
$cells->text = $value;
|
2010-03-20 22:15:54 +00:00
|
|
|
$cells->attributes['class'] = $errclass;
|
2010-02-05 07:30:53 +00:00
|
|
|
$rows->cells[] = $cells;
|
|
|
|
}
|
|
|
|
$countcontent++;
|
|
|
|
$table->data[] = $rows;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$mform = new admin_uploaduser_form3();
|
|
|
|
$mform->set_data(array('uutype'=>$uploadtype));
|
|
|
|
} else if (empty($contents)) {
|
|
|
|
$mform = new admin_uploaduser_form3();
|
|
|
|
$mform->set_data(array('uutype'=>$uploadtype));
|
2010-01-13 06:23:54 +00:00
|
|
|
} else {
|
2010-02-05 07:30:53 +00:00
|
|
|
//print content
|
|
|
|
foreach ($contents as $content) {
|
|
|
|
$rows = new html_table_row();
|
|
|
|
if ($countcontent >= $previewrows) {
|
|
|
|
foreach ($content as $con) {
|
|
|
|
$cells = new html_table_cell();
|
|
|
|
$cells->text = '...';
|
|
|
|
}
|
|
|
|
$rows->cells[] = $cells;
|
|
|
|
$table->data[] = $rows;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
foreach ($headings as $heading) {
|
|
|
|
$cells = new html_table_cell();
|
|
|
|
if(array_key_exists($heading, $content)) {
|
|
|
|
if ($heading == 'action') {
|
|
|
|
$content[$heading] = get_string($content[$heading]);
|
|
|
|
}
|
|
|
|
$cells->text = $content[$heading];
|
|
|
|
} else {
|
|
|
|
$cells->text = '';
|
|
|
|
}
|
|
|
|
$rows->cells[] = $cells;
|
|
|
|
}
|
|
|
|
$table->data[] = $rows;
|
|
|
|
$countcontent++;
|
|
|
|
}
|
2010-01-13 06:23:54 +00:00
|
|
|
}
|
2010-03-20 22:15:54 +00:00
|
|
|
echo html_writer::table($table);
|
2010-02-05 07:30:53 +00:00
|
|
|
|
|
|
|
if ($haserror) {
|
2010-01-13 06:23:54 +00:00
|
|
|
|
2010-02-05 07:30:53 +00:00
|
|
|
echo $OUTPUT->container(get_string('useruploadtype', 'moodle', $choices[$uploadtype]), 'centerpara');
|
|
|
|
echo $OUTPUT->container(get_string('uploadinvalidpreprocessedcount', 'moodle', $countcontent), 'centerpara');
|
|
|
|
echo $OUTPUT->container(get_string('invalidusername', 'moodle'), 'centerpara');
|
|
|
|
echo $OUTPUT->container(get_string('uploadfilecontainerror', 'moodle'), 'centerpara');
|
|
|
|
} else if (empty($contents)) {
|
|
|
|
echo $OUTPUT->container(get_string('uupreprocessedcount', 'admin', $countcontent), 'centerpara');
|
|
|
|
echo $OUTPUT->container(get_string('uploadfilecontentsnovaliddata'), 'centerpara');
|
2010-01-13 06:23:54 +00:00
|
|
|
} else {
|
2010-02-05 07:30:53 +00:00
|
|
|
echo $OUTPUT->container(get_string('uupreprocessedcount', 'admin', $countcontent), 'centerpara');
|
2010-01-13 06:23:54 +00:00
|
|
|
}
|
|
|
|
|
2007-05-02 09:33:56 +00:00
|
|
|
$mform->display();
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|
2007-11-02 08:41:05 +00:00
|
|
|
die;
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
/////////////////////////////////////
|
|
|
|
/// Utility functions and classes ///
|
|
|
|
/////////////////////////////////////
|
|
|
|
|
|
|
|
class uu_progress_tracker {
|
|
|
|
var $_row;
|
|
|
|
var $columns = array('status', 'line', 'id', 'username', 'firstname', 'lastname', 'email', 'password', 'auth', 'enrolments', 'deleted');
|
|
|
|
|
|
|
|
function uu_progress_tracker() {
|
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
$ci = 0;
|
|
|
|
echo '<table id="uuresults" class="generaltable boxaligncenter" summary="'.get_string('uploadusersresult', 'admin').'">';
|
|
|
|
echo '<tr class="heading r0">';
|
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('status').'</th>';
|
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('uucsvline', 'admin').'</th>';
|
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">ID</th>';
|
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('username').'</th>';
|
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('firstname').'</th>';
|
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('lastname').'</th>';
|
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('email').'</th>';
|
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('password').'</th>';
|
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('authentication').'</th>';
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('enrolments', 'enrol').'</th>';
|
2007-11-05 00:43:37 +00:00
|
|
|
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('delete').'</th>';
|
|
|
|
echo '</tr>';
|
|
|
|
$this->_row = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function flush() {
|
|
|
|
if (empty($this->_row) or empty($this->_row['line']['normal'])) {
|
|
|
|
$this->_row = array();
|
|
|
|
foreach ($this->columns as $col) {
|
|
|
|
$this->_row[$col] = array('normal'=>'', 'info'=>'', 'warning'=>'', 'error'=>'');
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$ci = 0;
|
|
|
|
$ri = 1;
|
2010-01-13 06:23:54 +00:00
|
|
|
echo '<tr class="r'.$ri.'">';
|
|
|
|
foreach ($this->_row as $key=>$field) {
|
2007-11-05 00:43:37 +00:00
|
|
|
foreach ($field as $type=>$content) {
|
|
|
|
if ($field[$type] !== '') {
|
2010-01-13 06:23:54 +00:00
|
|
|
if ($key == 'username' && $type == 'normal') {
|
|
|
|
$field[$type] = clean_param($field[$type], PARAM_USERNAME);
|
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
$field[$type] = '<span class="uu'.$type.'">'.$field[$type].'</span>';
|
|
|
|
} else {
|
|
|
|
unset($field[$type]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '<td class="cell c'.$ci++.'">';
|
|
|
|
if (!empty($field)) {
|
|
|
|
echo implode('<br />', $field);
|
|
|
|
} else {
|
|
|
|
echo ' ';
|
|
|
|
}
|
|
|
|
echo '</td>';
|
|
|
|
}
|
|
|
|
echo '</tr>';
|
|
|
|
foreach ($this->columns as $col) {
|
|
|
|
$this->_row[$col] = array('normal'=>'', 'info'=>'', 'warning'=>'', 'error'=>'');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function track($col, $msg, $level='normal', $merge=true) {
|
|
|
|
if (empty($this->_row)) {
|
|
|
|
$this->flush(); //init arrays
|
|
|
|
}
|
|
|
|
if (!in_array($col, $this->columns)) {
|
|
|
|
debugging('Incorrect column:'.$col);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($merge) {
|
|
|
|
if ($this->_row[$col][$level] != '') {
|
|
|
|
$this->_row[$col][$level] .='<br />';
|
|
|
|
}
|
|
|
|
$this->_row[$col][$level] .= s($msg);
|
|
|
|
} else {
|
|
|
|
$this->_row[$col][$level] = s($msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
echo '</table>';
|
|
|
|
}
|
|
|
|
}
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
/**
|
|
|
|
* Validation callback function - verified the column line of csv file.
|
|
|
|
* Converts column names to lowercase too.
|
|
|
|
*/
|
|
|
|
function validate_user_upload_columns(&$columns) {
|
|
|
|
global $STD_FIELDS, $PRF_FIELDS;
|
|
|
|
|
|
|
|
if (count($columns) < 2) {
|
|
|
|
return get_string('csvfewcolumns', 'error');
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
// test columns
|
|
|
|
$processed = array();
|
|
|
|
foreach ($columns as $key=>$unused) {
|
|
|
|
$columns[$key] = strtolower($columns[$key]); // no unicode expected here, ignore case
|
|
|
|
$field = $columns[$key];
|
|
|
|
if (!in_array($field, $STD_FIELDS) && !in_array($field, $PRF_FIELDS) &&// if not a standard field and not an enrolment field, then we have an error
|
|
|
|
!preg_match('/^course\d+$/', $field) && !preg_match('/^group\d+$/', $field) &&
|
2008-01-21 06:09:58 +00:00
|
|
|
!preg_match('/^type\d+$/', $field) && !preg_match('/^role\d+$/', $field) &&
|
|
|
|
!preg_match('/^enrolperiod\d+$/', $field)) {
|
2007-11-05 00:43:37 +00:00
|
|
|
return get_string('invalidfieldname', 'error', $field);
|
|
|
|
}
|
|
|
|
if (in_array($field, $processed)) {
|
|
|
|
return get_string('csvcolumnduplicates', 'error');
|
|
|
|
}
|
|
|
|
$processed[] = $field;
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
return true;
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
/**
|
|
|
|
* Increments username - increments trailing number or adds it if not present.
|
|
|
|
* Varifies that the new username does not exist yet
|
|
|
|
* @param string $username
|
|
|
|
* @return incremented username which does not exist yet
|
|
|
|
*/
|
|
|
|
function increment_username($username, $mnethostid) {
|
2008-05-30 21:36:57 +00:00
|
|
|
global $DB;
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
if (!preg_match_all('/(.*?)([0-9]+)$/', $username, $matches)) {
|
|
|
|
$username = $username.'2';
|
|
|
|
} else {
|
|
|
|
$username = $matches[1][0].($matches[2][0]+1);
|
|
|
|
}
|
|
|
|
|
2008-05-30 21:36:57 +00:00
|
|
|
if ($DB->record_exists('user', array('username'=>$username, 'mnethostid'=>$mnethostid))) {
|
2007-11-05 00:43:37 +00:00
|
|
|
return increment_username($username, $mnethostid);
|
|
|
|
} else {
|
|
|
|
return $username;
|
|
|
|
}
|
|
|
|
}
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
/**
|
|
|
|
* Check if default field contains templates and apply them.
|
|
|
|
* @param string template - potential tempalte string
|
|
|
|
* @param object user object- we need username, firstname and lastname
|
|
|
|
* @return string field value
|
|
|
|
*/
|
|
|
|
function process_template($template, $user) {
|
|
|
|
if (strpos($template, '%') === false) {
|
|
|
|
return $template;
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
// very very ugly hack!
|
|
|
|
global $template_globals;
|
|
|
|
$template_globals = new object();
|
|
|
|
$template_globals->username = isset($user->username) ? $user->username : '';
|
|
|
|
$template_globals->firstname = isset($user->firstname) ? $user->firstname : '';
|
|
|
|
$template_globals->lastname = isset($user->lastname) ? $user->lastname : '';
|
|
|
|
|
|
|
|
$result = preg_replace_callback('/(?<!%)%([+-~])?(\d)*([flu])/', 'process_template_callback', $template);
|
|
|
|
|
|
|
|
$template_globals = null;
|
|
|
|
|
|
|
|
if (is_null($result)) {
|
|
|
|
return $template; //error during regex processing??
|
|
|
|
} else {
|
|
|
|
return $result;
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
2007-11-02 08:41:05 +00:00
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
/**
|
|
|
|
* Internal callback function.
|
|
|
|
*/
|
|
|
|
function process_template_callback($block) {
|
|
|
|
global $template_globals;
|
|
|
|
$textlib = textlib_get_instance();
|
|
|
|
$repl = $block[0];
|
|
|
|
|
|
|
|
switch ($block[3]) {
|
|
|
|
case 'u': $repl = $template_globals->username; break;
|
|
|
|
case 'f': $repl = $template_globals->firstname; break;
|
|
|
|
case 'l': $repl = $template_globals->lastname; break;
|
|
|
|
}
|
|
|
|
switch ($block[1]) {
|
|
|
|
case '+': $repl = $textlib->strtoupper($repl); break;
|
|
|
|
case '-': $repl = $textlib->strtolower($repl); break;
|
|
|
|
case '~': $repl = $textlib->strtotitle($repl); break;
|
|
|
|
}
|
|
|
|
if (!empty($block[2])) {
|
|
|
|
$repl = $textlib->substr($repl, 0 , $block[2]);
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
return $repl;
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
/**
|
|
|
|
* Returns list of auth plugins that are enabled and known to work.
|
|
|
|
*/
|
|
|
|
function uu_allowed_auths() {
|
2007-11-02 08:41:05 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
// only following plugins are guaranteed to work properly
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
// TODO: add support for more plugins in 2.0
|
2007-11-05 00:43:37 +00:00
|
|
|
$whitelist = array('manual', 'nologin', 'none', 'email');
|
|
|
|
$plugins = get_enabled_auth_plugins();
|
|
|
|
$choices = array();
|
|
|
|
foreach ($plugins as $plugin) {
|
MDL-22061 converting auths to pluginname and deprecating old method for getting auth names
AMOS START
MOV [auth_castitle,auth_cas],[pluginname,auth_cas]
MOV [auth_dbtitle,auth_db],[pluginname,auth_db]
MOV [auth_emailtitle,auth_email],[pluginname,auth_email]
MOV [auth_fctitle,auth_fc],[pluginname,auth_fc]
MOV [auth_imaptitle,auth_imap],[pluginname,auth_imap]
MOV [auth_ldaptitle,auth_ldap],[pluginname,auth_ldap]
MOV [auth_manualtitle,auth_manul],[pluginname,auth_manul]
MOV [auth_mnettitle,auth_mnet],[pluginname,auth_mnet]
MOV [auth_nntptitle,auth_nntp],[pluginname,auth_nntp]
MOV [auth_nologintitle,auth_nologin],[pluginname,auth_nologin]
MOV [auth_nonetitle,auth_none],[pluginname,auth_none]
MOV [auth_pamtitle,auth_pam],[pluginname,auth_pam]
MOV [auth_pop3title,auth_pop3],[pluginname,auth_pop3]
MOV [auth_radiustitle,auth_radius],[pluginname,auth_radius]
MOV [auth_shibbolethtitle,auth_shibboleth],[pluginname,auth_shibboleth]
MOV [auth_webservicetitle,auth_webservice],[pluginname,auth_webservice]
AMOS END
2010-04-11 21:31:36 +00:00
|
|
|
$choices[$plugin] = get_string('pluginname', "auth_{$plugin}");
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
|
|
|
|
return $choices;
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|
|
|
|
|
2007-11-05 00:43:37 +00:00
|
|
|
/**
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
* Returns list of roles that are assignable in courses
|
2007-11-05 00:43:37 +00:00
|
|
|
*/
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
function uu_allowed_roles() {
|
|
|
|
// let's cheat a bit, frontpage is guaranteed to exist and has the same list of roles ;-)
|
|
|
|
$roles = get_assignable_roles(get_context_instance(CONTEXT_COURSE, SITEID), ROLENAME_ORIGINALANDSHORT);
|
|
|
|
return array_reverse($roles, true);
|
|
|
|
}
|
2007-11-05 00:43:37 +00:00
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
function uu_allowed_roles_cache() {
|
|
|
|
$allowedroles = get_assignable_roles(get_context_instance(CONTEXT_COURSE, SITEID), ROLENAME_SHORT);
|
|
|
|
foreach ($allowedroles as $rid=>$rname) {
|
|
|
|
$rolecache[$rid] = new object();
|
|
|
|
$rolecache[$rid]->id = $rid;
|
|
|
|
$rolecache[$rid]->name = $rname;
|
|
|
|
if (!is_numeric($rname)) { // only non-numeric shortnames are supported!!!
|
|
|
|
$rolecache[$rname] = new object();
|
|
|
|
$rolecache[$rname]->id = $rid;
|
|
|
|
$rolecache[$rname]->name = $rname;
|
2007-11-05 00:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
return $rolecache;
|
2007-11-02 08:41:05 +00:00
|
|
|
}
|