Commit 3ad3e8a0 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Added first cut at the CSV uploader, which does not actually insert users

yet (need to wait for profile stuff to do that). Also added other scripts
that will be in the UserManagement section.
parent 6c268804
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'adminnotifications');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$smarty = smarty();
$smarty->display('admin/usermanagement/adminnotifications.tpl');
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'adminusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$smarty = smarty();
$smarty->display('admin/usermanagement/adminusers.tpl');
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'staffusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$smarty = smarty();
$smarty->display('admin/usermanagement/staffusers.tpl');
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'suspendedusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$smarty = smarty();
$smarty->display('admin/usermanagement/suspendedusers.tpl');
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'uploadcsv');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
$institutions = get_records('institution');
foreach ($institutions as $name => $data) {
$options[$name] = $data->displayname;
}
$institutions = get_records_select('institution', "registerallowed = 1 AND authplugin = 'internal'");
if (count($institutions) > 1) {
$options = array();
foreach ($institutions as $institution) {
$options[$institution->name] = $institution->displayname;
}
$institutionelement = array(
'type' => 'select',
'title' => get_string('institution'),
'description' => get_string('institutiondescription'),
'options' => $options
);
}
else {
$institutionelement = array(
'type' => 'hidden',
'value' => 'mahara'
);
}
$form = array(
'name' => 'uploadcsv',
'method' => 'post',
'action' => '',
'elements' => array(
'institution' => $institutionelement,
'file' => array(
'type' => 'file',
'title' => get_string('csvfile', 'admin'),
'description' => get_string('csvfiledescription', 'admin'),
'rules' => array(
'required' => true
)
),
'submit' => array(
'type' => 'submit',
'value' => get_string('uploadcsvfile', 'admin')
)
)
);
/**
* The CSV file is parsed here so validation errors can be returned to the
* user. The data from a successful parsing is stored in the <var>$CVSDATA</var>
* array so it can be accessed by the submit function
*
* @param Form $form The form to validate
* @param array $values The values submitted
*/
function uploadcsv_validate(Form $form, $values) {
global $CSVDATA;
// Don't even start attempting to parse if there are previous errors
if ($form->has_errors()) {
return;
}
if ($values['file']['size'] == 0) {
$form->set_error('file', get_string('thisfieldisrequired', 'admin'));
return;
}
require_once('pear/File.php');
require_once('pear/File/CSV.php');
$institution = $values['institution'];
log_debug($values);
$conf = File_CSV::discoverFormat($values['file']['tmp_name']);
log_debug($conf);
$i = 0;
while ($line = @File_CSV::readQuoted($values['file']['tmp_name'], $conf)) {
log_debug($line);
$i++;
if (count($line) < 3) {
$form->set_error('file', get_string('uploadcsverrorincorrectfieldcount', 'admin', $i));
return;
}
$username = $line[0];
$email = $line[1];
$password = $line[2];
safe_require('auth', 'internal', 'lib.php', 'require_once');
if (!AuthInternal::is_username_valid($username)) {
$form->set_error('file', get_string('uploadcsverrorinvalidusername', 'admin', $i));
return;
}
if (record_exists('usr', 'username', $username)) {
$form->set_error('file', get_string('uploadcsverroruseralreadyexists', 'admin', $i));
return;
}
require_once('form/rules/email.php');
if (form_rule_email($email) !== null) {
$form->set_error('file', get_string('uploadcsverrorinvalidemail', 'admin', $i));
return;
}
// Note: only checks for valid form are done here, none of the checks
// like whether the password is too easy. The user is going to have to
// change their password on first login anyway.
if (!AuthInternal::is_password_valid($password)) {
$form->set_error('file', get_string('uploadcsverrorinvalidpassword', 'admin', $i));
return;
}
// All OK!
$CSVDATA[] = $line;
}
}
/**
* Add the users to the system. Make sure that they have to change their
* password on next login also.
*/
function uploadcsv_submit($values) {
global $SESSION, $CSVDATA;
log_info('Inserting users from the CSV file');
foreach ($CSVDATA as $record) {
log_debug('adding user ' . $record->username);
// @todo when penny has done the profile field setting stuff...
//$user = new StdClass;
//$user->username = $record[0];
//$user->password = $record[2];
//$user->institution = $values['institution'];
//$user->passwordchange = 1;
//$user->firstname = ???;
//$user->lastname = ???;
//$user->email = $record[1];
}
log_info('Inserted ' . count($CSVDATA) . ' records');
$SESSION->add_ok_msg('yo yo users added yo!');
// @todo support relative URLs here
redirect(get_config('wwwroot') . 'admin/usermanagement/uploadcsv.php');
}
$smarty = smarty();
$smarty->assign('uploadcsvform', form($form));
$smarty->display('admin/usermanagement/uploadcsv.tpl');
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment