2013-10-10 02:50:20 +00:00
|
|
|
<?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"),
|
2013-10-10 03:11:47 +00:00
|
|
|
$child->nodeValue,
|
|
|
|
$child->getAttribute("sha1"));
|
2013-10-10 02:50:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$theme->add_exercice($ex))
|
|
|
|
erreur("Unable to add '".$ex->id."' exercice.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$page = "admin/import_exercices";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
header("Location: /");
|
|
|
|
exit;
|
|
|
|
}
|