Admin part: home and teams part done

This commit is contained in:
Némunaire 2013-11-08 19:15:17 +01:00
parent 568a6beef0
commit 166be860c8
11 changed files with 250 additions and 55 deletions

View File

@ -21,26 +21,48 @@ $p = $out[0];
// Admin part
if ($n && $p[0] == SALT_ADMIN)
{
if (isset($p[1]))
$template->assign("menu_where", $p[1]);
else
$template->assign("menu_where", "");
if (isset($p[2]))
$template->assign("submenu_where", $p[2]);
else
$template->assign("submenu_where", "");
$template->assign("themes", Theme::get_themes());
if ($n <= 1)
$page = require("admin/home.php");
else
{
switch($p[1])
if (isset($p[2]))
$cmpstr = $p[1]."/".$p[2];
else
$cmpstr = $p[1];
switch($cmpstr)
{
case "exercices/import/":
case "exercices/import":
$page = require("admin/import_exercices.php");
break;
case "users":
case "users/":
// Users
case "teams":
case "teams/":
$page = require("admin/list_users.php");
break;
case "users/import":
case "users/import/":
case "teams/import":
case "teams/import/":
$page = require("admin/import_users.php");
break;
case "teams/export":
case "teams/export/":
$page = require("admin/export_users.php");
break;
}
}
}

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

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<teams>
{foreach from=$teams item=t}
<team>
<name>{$t->team_name}</name>
{if $t->slogan}<slogan>{$t->slogan}</slogan>{/if}
{if $t->get_members()}
{foreach from=$t->get_members() item=m}
<member>
<lastname>{$m->lastname}</lastname>
<firstname>{$m->firstname}</firstname>
{if $m->nickname}<nickname>{$m->nickname}</nickname>{/if}
{if $m->company}<company>{$m->company}</company>{/if}
</member>
{/foreach}
{/if}
</team>
{/foreach}
</teams>

View File

@ -0,0 +1,7 @@
{extends file="admin/layout.tpl"}
{block name=content}
<h1>
Zone d'administration
</h1>
{/block}

View File

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

View File

@ -0,0 +1,48 @@
{extends file="layout.tpl"}
{block name=body}
<nav class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/{$SALT_ADMIN}/">FIC</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li{if $menu_where == "teams"} class="active"{/if}><a href="/{$SALT_ADMIN}/teams">Équipes</a></li>
<li{if $menu_where == "themes"} class="active"{/if}><a href="/{$SALT_ADMIN}/themes">Thèmes</a></li>
{foreach from=$themes item=t}
<li class="dropdown{if $menu_where == $t->get_name()} active{/if}">
<a href="/{$SALT_ADMIN}/{$t->get_id()}-{$t->get_name()}" class="dropdown-toggle" data-toggle="dropdown">{$t->get_name()} <b class="caret"></b></a>
<ul class="dropdown-menu">
{foreach from=$t->get_exercicesOrdered() item=e}
<li><a href="/{$SALT_ADMIN}/{$t->get_id()}-{$t->get_name()}/{$e->get_id()}">{$e->get_name()}</a></li>
{/foreach}
</ul>
</li>
{/foreach}
</ul>
<p class="navbar-right navbar-text">01:23:42</p>
</div><!-- /.navbar-collapse -->
</nav>
<div class="container" style="margin-top: 50px">
{if $ERRmessage}
<div class="alert alert-{$ERRcolor}">
<button class="close" data-dismiss="alert">&times;</button>
<i class="icon-warning-sign"></i> {$ERRmessage}
</div>
{/if}
<div class="container">
{block name=content}{/block}
</div>
</div>
{/block}

View File

@ -0,0 +1,48 @@
{extends file="admin/layout.tpl"}
{block name=content}
<table class="table">
<thead>
<tr>
<th>id</th>
<th>Nom</th>
<th>Slogan</th>
<th>Membres</th>
<th>Points</th>
<th>Place</th>
</tr>
</thead>
{if $teams}
<tbody>
{foreach from=$teams item=t}
<tr>
<td>
{$t->id}<br>
<a href="?delete={$t->id}"><span class="glyphicon glyphicon-trash"></span></a>
</td>
<td>{$t->team_name}</td>
<td>{$t->slogan}</td>
<td><ul>
{foreach from=$t->get_members() item=m}
<li><span style="font-variant: small-caps">{$m->lastname}</span> <em>{$m->nickname}</em> {$m->firstname}</li>
{/foreach}
</ul></td>
<td>{$t->get_pts()}</td>
<td>{$t->get_rank()}</td>
</tr>
{/foreach}
</tbody>
{/if}
<tfoot>
<tr>
<td colspan="6">
<a class="btn btn-success" href="/{$SALT_ADMIN}/teams/import" role="button"><span class="glyphicon glyphicon-cloud-upload"></span> Importer</a>
{if $teams}
<a class="btn btn-primary" href="/{$SALT_ADMIN}/teams/export" role="button"><span class="glyphicon glyphicon-floppy-save"></span> Exporter</a>
<a class="btn btn-danger" href="/{$SALT_ADMIN}/teams/?drop" onclick="return confirm('Êtes-vous sûr de vouloir vider la table des équipes ?')" role="button"><span class="glyphicon glyphicon-floppy-trash"></span> Vider</a>
{/if}
</td>
</tr>
</tfoot>
</table>
{/block}