Admin part: home and teams part done

This commit is contained in:
Némunaire 2013-11-08 19:15:17 +01:00
commit 166be860c8
11 changed files with 249 additions and 54 deletions

View file

@ -0,0 +1,9 @@
<?php
if(!defined('ONYX')) exit;
header("Content-type: application/xml");
$template->assign("teams", Team::get_teams());
return "admin/export_teams";

View file

@ -0,0 +1,5 @@
<?php
if(!defined('ONYX')) exit;
return "admin/home";

View file

@ -2,55 +2,60 @@
if(!defined('ONYX')) exit;
if ($SESS->level > 1)
if (!empty($_FILES["inputFile"]['tmp_name']))
{
$page = "admin/import_users";
if (!empty($_FILES["inputFile"]['tmp_name']))
$doc = new DOMDocument();
if (@!$doc->load($_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;
}
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))
$xpath = new DOMXpath($doc);
$elements = $xpath->query("//teams/team");
if (!is_null($elements))
{
foreach ($elements as $element)
{
foreach ($elements as $element)
$team = new Team();
foreach ($element->childNodes as $child)
{
$user = new User();
if ($child->nodeName == "name")
$team->team_name = $child->nodeValue;
$user->auth_level = 1;
// Why??
//$user->id = $element->getAttribute("id");
else if ($child->nodeName == "slogan")
$team->slogan = $child->nodeValue;
foreach ($element->childNodes as $child)
else if ($child->nodeName == "member")
{
if ($child->nodeName == "username")
$user->username = $child->nodeValue;
if (!$team->update())
erreur("Unable to add team ".$team->team_name);
else if ($child->nodeName == "firstname")
$user->firstname = $child->nodeValue;
$user = new Member();
$user->team = $team;
else if ($child->nodeName == "lastname")
$user->lastname = $child->nodeValue;
foreach ($child->childNodes as $child_member)
{
if ($child_member->nodeName == "firstname")
$user->firstname = $child_member->nodeValue;
else if ($child->nodeName == "company")
$user->company = $child->nodeValue;
else if ($child_member->nodeName == "lastname")
$user->lastname = $child_member->nodeValue;
else if ($child_member->nodeName == "company")
$user->company = $child_member->nodeValue;
}
if (!$user->update())
erreur("Unable to add user ".$user->nickname);
$team->members[] = $user;
}
if (!$user->update())
erreur("Unable to add user ".$user->username);
}
}
erreur("XML file successfully imported.", "success");
}
erreur("Fichier XML importé avec succès.", "success");
}
else
{
header("Location: /");
exit;
}
return "admin/import_users";

View file

@ -0,0 +1,36 @@
<?php
if(!defined('ONYX')) exit;
function remove_team($id)
{
$db = new BDD();
$db->query("DELETE FROM team_members WHERE id_team = ".$id);
$db->query("DELETE FROM solved WHERE id_team = ".$id);
$db->query("DELETE FROM teams WHERE id = ".$id);
$db->deconnexion();
}
if (!empty($_GET["delete"]))
{
$id_team = intval($_GET["delete"]);
remove_team($id_team);
header("Location: /".SALT_ADMIN."/teams");
exit;
}
else if (isset($_GET["drop"]))
{
foreach(Team::get_teams() as $team)
{
remove_team($team->get_id());
}
header("Location: /".SALT_ADMIN."/teams");
exit;
}
$template->assign("teams", Team::get_teams());
return "admin/users";

View file

@ -49,7 +49,6 @@ class Team
$key_hash = $this->key_hash;
$auth_level = intval($this->auth_level);
$slogan = $this->slogan;
$company = $this->company;
$team_name = $this->team_name;
$db = new BDD();
@ -60,14 +59,14 @@ class Team
if (empty($this->id))
{
$db->query("INSERT INTO teams
VALUES (NULL, '".$key_hash."', ".$auth_level.", '".$slogan."')");
VALUES (NULL, '".$team_name."', '".$key_hash."', ".$auth_level.", '".$slogan."')");
$this->id = $db->insert_id();
$aff = ($this->id > 0);
}
else
{
$db->query("UPDATE teams
SET team_name = '".$team_name."', auth_level = ".$auth_level.", key_hash = '".$key_hash."', company = '".$slogan."'
SET team_name = '".$team_name."', auth_level = ".$auth_level.", key_hash = '".$key_hash."', slogan = '".$slogan."'
WHERE id = ".intval($this->id));
$aff = $db->affected();
}
@ -173,7 +172,7 @@ class Team
{
if ($id_theme != -1)
{
$db = new BDD();
$db = new BDD();
$ids = $db->query("SELECT id_theme, id_exercice
FROM `solved`
LEFT OUTER JOIN exercices ON `solved`.id_exercice = `exercices`.id
@ -208,9 +207,9 @@ class Team
$db->deconnexion();
$array = array();
foreach ($ids as $id){
$array[] = new Team($id['id']);
}
if ($ids)
foreach ($ids as $id)
$array[] = new Team($id['id']);
return $array;
}