mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-9627 - moving uploaduser to formslib
This commit is contained in:
parent
7c8a963f7b
commit
0a5dffccd7
@ -4,15 +4,11 @@
|
||||
/// Returns list of users with their user ids
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/uploadlib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once('uploaduser_form.php');
|
||||
|
||||
admin_externalpage_setup('uploadusers');
|
||||
|
||||
$createpassword = optional_param('createpassword', 0, PARAM_BOOL);
|
||||
$updateaccounts = optional_param('updateaccounts', 0, PARAM_BOOL);
|
||||
$allowrenames = optional_param('allowrenames', 0, PARAM_BOOL);
|
||||
|
||||
require_capability('moodle/site:uploadusers', get_context_instance(CONTEXT_SYSTEM));
|
||||
|
||||
if (! $site = get_site()) {
|
||||
@ -23,12 +19,8 @@ if (!$adminuser = get_admin()) {
|
||||
error("Could not find site admin");
|
||||
}
|
||||
|
||||
$strfile = get_string('file');
|
||||
$struser = get_string('user');
|
||||
$strusersnew = get_string('usersnew');
|
||||
$strusersupdated = get_string('usersupdated');
|
||||
$struploadusers = get_string('uploadusers');
|
||||
$straddnewuser = get_string('importuser');
|
||||
|
||||
$csv_encode = '/\&\#44/';
|
||||
if (isset($CFG->CSV_DELIMITER)) {
|
||||
@ -47,15 +39,18 @@ if (isset($CFG->CSV_DELIMITER)) {
|
||||
|
||||
admin_externalpage_print_header();
|
||||
|
||||
$mform = new admin_uploaduser_form();
|
||||
|
||||
/// If a file has been uploaded, then process it
|
||||
|
||||
if ( $formdata = $mform->get_data() ) {
|
||||
|
||||
$um = new upload_manager('userfile',false,false,null,false,0);
|
||||
|
||||
if ($um->preprocess_files() && confirm_sesskey()) {
|
||||
$filename = $um->files['userfile']['tmp_name'];
|
||||
$createpassword = $formdata->createpassword;
|
||||
$updateaccounts = $formdata->updateaccounts;
|
||||
$allowrenames = $formdata->allowrenames;
|
||||
|
||||
$filename = $mform->get_userfile_name();
|
||||
|
||||
// Large files are likely to take their time and memory. Let PHP know
|
||||
// that we'll take longer, and that the process should be recycled soon
|
||||
// to free up memory.
|
||||
@ -274,12 +269,12 @@ if ($um->preprocess_files() && confirm_sesskey()) {
|
||||
$usersnew++;
|
||||
if (empty($user->password) && $createpassword) {
|
||||
// passwords will be created and sent out on cron
|
||||
insert_record('user_preferences', array( userid => $user->id,
|
||||
name => 'create_password',
|
||||
value => 1));
|
||||
insert_record('user_preferences', array( userid => $user->id,
|
||||
name => 'auth_forcepasswordchange',
|
||||
value => 1));
|
||||
insert_record('user_preferences', array( 'userid' => $user->id,
|
||||
'name' => 'create_password',
|
||||
'value' => 1));
|
||||
insert_record('user_preferences', array( 'userid' => $user->id,
|
||||
'name' => 'auth_forcepasswordchange',
|
||||
'value' => 1));
|
||||
}
|
||||
} else {
|
||||
// Record not added -- possibly some other error
|
||||
@ -369,36 +364,9 @@ if ($um->preprocess_files() && confirm_sesskey()) {
|
||||
}
|
||||
|
||||
/// Print the form
|
||||
print_heading_with_help($struploadusers, 'uploadusers');
|
||||
print_heading_with_help(get_string('uploadusers'), 'uploadusers');
|
||||
|
||||
$noyesoptions = array( get_string('no'), get_string('yes') );
|
||||
|
||||
$maxuploadsize = get_max_upload_file_size();
|
||||
echo '<div style="text-align:center">';
|
||||
echo '<form method="post" enctype="multipart/form-data" action="uploaduser.php"><div>'.
|
||||
$strfile.' <input type="hidden" name="MAX_FILE_SIZE" value="'.$maxuploadsize.'" />'.
|
||||
'<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />'.
|
||||
'<input type="file" name="userfile" size="30" />';
|
||||
print_heading(get_string('settings'));
|
||||
echo '<table style="margin-left:auto;margin-right:auto">';
|
||||
echo '<tr><td>' . get_string('passwordhandling', 'auth') . '</td><td>';
|
||||
$passwordopts = array( 0 => get_string('infilefield', 'auth'),
|
||||
1 => get_string('createpasswordifneeded', 'auth'),
|
||||
);
|
||||
choose_from_menu($passwordopts, 'createpassword', $createpassword);
|
||||
echo '</td></tr>';
|
||||
|
||||
echo '<tr><td>' . get_string('updateaccounts', 'admin') . '</td><td>';
|
||||
choose_from_menu($noyesoptions, 'updateaccounts', $updateaccounts);
|
||||
echo '</td></tr>';
|
||||
|
||||
echo '<tr><td>' . get_string('allowrenames', 'admin') . '</td><td>';
|
||||
choose_from_menu($noyesoptions, 'allowrenames', $allowrenames);
|
||||
echo '</td></tr>';
|
||||
echo '</table><br />';
|
||||
echo '<input type="submit" value="'.$struploadusers.'" />';
|
||||
echo '</div></form><br />';
|
||||
echo '</div>';
|
||||
$mform->display();
|
||||
|
||||
admin_externalpage_print_footer();
|
||||
|
||||
@ -419,4 +387,3 @@ function my_file_get_contents($filename, $use_include_path = 0) {
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
34
admin/uploaduser_form.php
Normal file
34
admin/uploaduser_form.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
require_once $CFG->libdir.'/formslib.php';
|
||||
|
||||
class admin_uploaduser_form extends moodleform {
|
||||
function definition (){
|
||||
$mform =& $this->_form;
|
||||
|
||||
$mform->addElement('file', 'userfile', get_string('file'));
|
||||
$mform->addRule('userfile', null, 'required');
|
||||
|
||||
$mform->addElement('header', 'settingsheader', get_string('settings'));
|
||||
|
||||
$passwordopts = array( 0 => get_string('infilefield', 'auth'),
|
||||
1 => get_string('createpasswordifneeded', 'auth'),
|
||||
);
|
||||
|
||||
$mform->addElement('select', 'createpassword', get_string('passwordhandling', 'auth'), $passwordopts);
|
||||
|
||||
$mform->addElement('selectyesno', 'updateaccounts', get_string('updateaccounts', 'admin'));
|
||||
$mform->addElement('selectyesno', 'allowrenames', get_string('allowrenames', 'admin'));
|
||||
|
||||
$this->add_action_buttons(false, get_string('uploadusers'));
|
||||
}
|
||||
|
||||
function get_userfile_name(){
|
||||
if ($this->is_submitted() and $this->is_validated()) {
|
||||
// return the temporary filename to process
|
||||
return $this->_upload_manager->files['userfile']['tmp_name'];
|
||||
}else{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user