Add admin pages: import_users and import_exercices

This commit is contained in:
Némunaire 2013-10-10 04:50:20 +02:00
parent 1733afb963
commit ef983a3a82
5 changed files with 180 additions and 79 deletions

View file

@ -13,88 +13,23 @@ $p = strtolower(gpc("p"));
if (empty($page) && $SESS->level > 0)
{
if ($SESS->level&1)
if ($SESS->level > 1)
{
switch($p)
{
case "adm_users":
include("admin/users.php");
break;
}
}
if ($SESS->level&2)
{
switch($p)
{
case "articles":
include("articles/articles.php");
case "exercices/import/":
case "exercices/import":
include("admin/import_exercices.php");
break;
case "articles_prod":
include("articles/production.php");
break;
}
}
if ($SESS->level&4)
{
switch($p)
{
case "palettes":
include("articles/palettes.php");
case "users":
case "users/":
include("admin/list_users.php");
break;
case "palettes_besoins":
include("articles/needs.php");
break;
case "prod_couts":
include("production/costs.php");
break;
case "stocks_besoins":
include("materials/needs.php");
break;
case "stocks_etat":
include("materials/etat.php");
break;
case "transport":
include("materials/transport.php");
break;
}
}
if ($SESS->level&16)
{
switch($p)
{
case "commandes":
include("materials/commandes.php");
break;
case "stocks_besoins":
include("materials/needs.php");
break;
case "transport":
include("materials/transport.php");
break;
}
}
if ($SESS->level&8)
{
switch($p)
{
case "prod_resume":
include("articles/needs.php");
break;
case "prod_entry":
include("production/entry.php");
case "users/import":
case "users/import/":
include("admin/import_users.php");
break;
}
}
@ -131,10 +66,6 @@ if (empty($page)) // Public pages
include("public/score.php");
break;
case "forgotpasswd":
include("public/forgotpasswd.php");
break;
case "403":
$template->assign("err", 403);
$page = "404";

View file

@ -0,0 +1,80 @@
<?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;
}
// Define thema information
$theme = new Theme();
$xpath = new DOMXpath($doc);
$elements = $xpath->query("//theme/title");
if (!is_null($elements))
{
foreach ($elements as $element)
$theme->title = $element->nodeValue;
}
// Insert thema into BDD
if (!$theme->update())
{
erreur("Unable to add a new theme.");
return;
}
$elements = $xpath->query("//theme/exercice");
if (!is_null($elements))
{
foreach ($elements as $element)
{
$ex = new Exercice();
$ex->id = $element->getAttribute("id");
$ex->level = $element->getAttribute("level");
if ($element->hasAttribute("depends"))
$ex->require = $element->getAttribute("depends");
foreach ($element->childNodes as $child)
{
if ($child->nodeName == "title")
$ex->title = $child->nodeValue;
else if ($child->nodeName == "points")
$ex->points = intval($child->nodeValue);
else if ($child->nodeName == "statement")
$ex->statement = $child->nodeValue;
else if ($child->nodeName == "key")
$ex->add_key(
$child->hasAttribute("format")?$child->getAttribute("format"):"sha512",
$child->nodeValue);
else if ($child->nodeName == "file")
$ex->add_file(
$child->getAttribute("path"),
$child->nodeValue);
}
if (!$theme->add_exercice($ex))
erreur("Unable to add '".$ex->id."' exercice.");
}
}
}
$page = "admin/import_exercices";
}
else
{
header("Location: /");
exit;
}

View 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;
}

View file

@ -0,0 +1,16 @@
{extends file="layout-nav.tpl"}
{block name=head}
<link href="/css/home.css" rel="stylesheet">
{/block}
{block name=content}
<h1>
Import d'exercices
</h1>
<form action="/exercices/import" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="inputFile">File to import:</label>
<input type="file" id="inputFile" name="inputFile">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
{/block}

View file

@ -0,0 +1,16 @@
{extends file="layout-nav.tpl"}
{block name=head}
<link href="/css/home.css" rel="stylesheet">
{/block}
{block name=content}
<h1>
Import d'utilisateurs
</h1>
<form action="/users/import" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="inputFile">File to import:</label>
<input type="file" id="inputFile" name="inputFile">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
{/block}