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 // Admin part
if ($n && $p[0] == SALT_ADMIN) 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) if ($n <= 1)
$page = require("admin/home.php"); $page = require("admin/home.php");
else 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/":
case "exercices/import": case "exercices/import":
$page = require("admin/import_exercices.php"); $page = require("admin/import_exercices.php");
break; break;
case "users": // Users
case "users/": case "teams":
case "teams/":
$page = require("admin/list_users.php"); $page = require("admin/list_users.php");
break; break;
case "users/import": case "teams/import":
case "users/import/": case "teams/import/":
$page = require("admin/import_users.php"); $page = require("admin/import_users.php");
break; 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(!defined('ONYX')) exit;
if ($SESS->level > 1) if (!empty($_FILES["inputFile"]['tmp_name']))
{ {
$page = "admin/import_users"; $doc = new DOMDocument();
if (@!$doc->load($_FILES["inputFile"]['tmp_name']))
if (!empty($_FILES["inputFile"]['tmp_name']))
{ {
$doc = new DOMDocument(); erreur("Unable to parse given file. A XML file was expected.");
if (@!$doc->load($_FILES["inputFile"]['tmp_name'])) return;
{ }
erreur("Unable to parse given file. A XML file was expected.");
return;
}
$xpath = new DOMXpath($doc); $xpath = new DOMXpath($doc);
$elements = $xpath->query("//users/user"); $elements = $xpath->query("//teams/team");
if (!is_null($elements)) 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; else if ($child->nodeName == "slogan")
// Why?? $team->slogan = $child->nodeValue;
//$user->id = $element->getAttribute("id");
foreach ($element->childNodes as $child) else if ($child->nodeName == "member")
{ {
if ($child->nodeName == "username") if (!$team->update())
$user->username = $child->nodeValue; erreur("Unable to add team ".$team->team_name);
else if ($child->nodeName == "firstname") $user = new Member();
$user->firstname = $child->nodeValue; $user->team = $team;
else if ($child->nodeName == "lastname") foreach ($child->childNodes as $child_member)
$user->lastname = $child->nodeValue; {
if ($child_member->nodeName == "firstname")
$user->firstname = $child_member->nodeValue;
else if ($child->nodeName == "company") else if ($child_member->nodeName == "lastname")
$user->company = $child->nodeValue; $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
{ return "admin/import_users";
header("Location: /");
exit;
}

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; $key_hash = $this->key_hash;
$auth_level = intval($this->auth_level); $auth_level = intval($this->auth_level);
$slogan = $this->slogan; $slogan = $this->slogan;
$company = $this->company;
$team_name = $this->team_name; $team_name = $this->team_name;
$db = new BDD(); $db = new BDD();
@ -60,14 +59,14 @@ class Team
if (empty($this->id)) if (empty($this->id))
{ {
$db->query("INSERT INTO teams $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(); $this->id = $db->insert_id();
$aff = ($this->id > 0); $aff = ($this->id > 0);
} }
else else
{ {
$db->query("UPDATE teams $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)); WHERE id = ".intval($this->id));
$aff = $db->affected(); $aff = $db->affected();
} }
@ -208,9 +207,9 @@ class Team
$db->deconnexion(); $db->deconnexion();
$array = array(); $array = array();
foreach ($ids as $id){ if ($ids)
$array[] = new Team($id['id']); foreach ($ids as $id)
} $array[] = new Team($id['id']);
return $array; 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"} {extends file="admin/layout.tpl"}
{block name=head}
<link href="/css/common.css" rel="stylesheet">
{/block}
{block name=content} {block name=content}
<h1> <h1>
Import d'utilisateurs Import d'utilisateurs
</h1> </h1>
<form action="/users/import" method="post" enctype="multipart/form-data"> <form action="?" method="post" enctype="multipart/form-data">
<div class="form-group"> <div class="form-group">
<label for="inputFile">File to import:</label> <label for="inputFile">Fichier à importer :</label>
<input type="file" id="inputFile" name="inputFile"> <input type="file" id="inputFile" name="inputFile">
</div> </div>
<button type="submit" class="btn btn-default">Submit</button> <button type="submit" class="btn btn-primary">Importer</button>
</form> </form>
{/block} {/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}