Admin part: can import, export and drop themes
This commit is contained in:
parent
4d1a860a01
commit
ffe0c2a7c4
8 changed files with 217 additions and 7 deletions
9
onyx/include/admin/export_theme.php
Normal file
9
onyx/include/admin/export_theme.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
header("Content-type: application/xml");
|
||||
|
||||
$template->assign("theme", new Theme($_GET["id"]));
|
||||
|
||||
return "admin/export_theme";
|
||||
75
onyx/include/admin/import_themes.php
Normal file
75
onyx/include/admin/import_themes.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
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,
|
||||
$child->getAttribute("sha1"));
|
||||
}
|
||||
|
||||
if (!$theme->add_exercice($ex))
|
||||
erreur("Unable to add '".$ex->id."' exercice.");
|
||||
}
|
||||
}
|
||||
|
||||
erreur("XML file successfully imported.", "success");
|
||||
}
|
||||
|
||||
return "admin/import_exercices";
|
||||
43
onyx/include/admin/list_themes.php
Normal file
43
onyx/include/admin/list_themes.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
function remove_themes($id)
|
||||
{
|
||||
$db = new BDD();
|
||||
$res = $db->query("SELECT id FROM exercices WHERE id_theme = ".$id);
|
||||
foreach($res as $r)
|
||||
{
|
||||
$db->query("DELETE FROM exercice_files WHERE id_exercice = ".$id);
|
||||
$db->query("DELETE FROM exercice_keys WHERE id_exercice = ".$id);
|
||||
$db->query("DELETE FROM solved WHERE id_exercice = ".$id);
|
||||
}
|
||||
|
||||
$db->query("DELETE FROM exercices WHERE id_theme = ".$id);
|
||||
$db->query("DELETE FROM themes WHERE id = ".$id);
|
||||
$db->deconnexion();
|
||||
}
|
||||
|
||||
if (!empty($_GET["delete"]))
|
||||
{
|
||||
$id_team = intval($_GET["delete"]);
|
||||
|
||||
remove_themes($id_team);
|
||||
|
||||
header("Location: /".SALT_ADMIN."/themes");
|
||||
exit;
|
||||
}
|
||||
else if (isset($_GET["drop"]))
|
||||
{
|
||||
foreach(Theme::get_themes() as $thm)
|
||||
{
|
||||
remove_themes($thm->get_id());
|
||||
}
|
||||
|
||||
header("Location: /".SALT_ADMIN."/themes");
|
||||
exit;
|
||||
}
|
||||
|
||||
$template->assign("themes", Theme::get_themes());
|
||||
|
||||
return "admin/themes";
|
||||
Reference in a new issue