Add admin pages: import_users and import_exercices
This commit is contained in:
parent
1733afb963
commit
ef983a3a82
5 changed files with 180 additions and 79 deletions
58
onyx/include/admin/import_users.php
Normal file
58
onyx/include/admin/import_users.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
if ($SESS->level > 1)
|
||||
{
|
||||
if (!empty($_FILES["inputFile"]['tmp_name']))
|
||||
{
|
||||
$doc = new DOMDocument();
|
||||
if (!$doc->load($_FILES["inputFile"]['tmp_name']))
|
||||
{
|
||||
erreur("Unable to parse given file. A XML file was expected.");
|
||||
return;
|
||||
}
|
||||
|
||||
$xpath = new DOMXpath($doc);
|
||||
$elements = $xpath->query("//users/user");
|
||||
if (!is_null($elements))
|
||||
{
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$user->auth_level = 1;
|
||||
// Why??
|
||||
//$user->id = $element->getAttribute("id");
|
||||
|
||||
foreach ($element->childNodes as $child)
|
||||
{
|
||||
if ($child->nodeName == "username")
|
||||
$user->username = $child->nodeValue;
|
||||
|
||||
else if ($child->nodeName == "firstname")
|
||||
$user->firstname = $child->nodeValue;
|
||||
|
||||
else if ($child->nodeName == "lastname")
|
||||
$user->lastname = $child->nodeValue;
|
||||
|
||||
else if ($child->nodeName == "company")
|
||||
$user->company = $child->nodeValue;
|
||||
}
|
||||
|
||||
if (!$user->update())
|
||||
erreur("Unable to add user ".$user->username);
|
||||
}
|
||||
}
|
||||
|
||||
// Define thema information
|
||||
$theme = new Theme();
|
||||
}
|
||||
|
||||
$page = "admin/import_users";
|
||||
}
|
||||
else
|
||||
{
|
||||
header("Location: /");
|
||||
exit;
|
||||
}
|
Reference in a new issue