Admin part: home and teams part done
This commit is contained in:
parent
568a6beef0
commit
166be860c8
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
onyx/include/admin/export_users.php
Normal file
9
onyx/include/admin/export_users.php
Normal 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";
|
5
onyx/include/admin/home.php
Normal file
5
onyx/include/admin/home.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
return "admin/home";
|
@ -2,10 +2,6 @@
|
||||
|
||||
if(!defined('ONYX')) exit;
|
||||
|
||||
if ($SESS->level > 1)
|
||||
{
|
||||
$page = "admin/import_users";
|
||||
|
||||
if (!empty($_FILES["inputFile"]['tmp_name']))
|
||||
{
|
||||
$doc = new DOMDocument();
|
||||
@ -16,41 +12,50 @@ if ($SESS->level > 1)
|
||||
}
|
||||
|
||||
$xpath = new DOMXpath($doc);
|
||||
$elements = $xpath->query("//users/user");
|
||||
$elements = $xpath->query("//teams/team");
|
||||
if (!is_null($elements))
|
||||
{
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$user->auth_level = 1;
|
||||
// Why??
|
||||
//$user->id = $element->getAttribute("id");
|
||||
$team = new Team();
|
||||
|
||||
foreach ($element->childNodes as $child)
|
||||
{
|
||||
if ($child->nodeName == "username")
|
||||
$user->username = $child->nodeValue;
|
||||
if ($child->nodeName == "name")
|
||||
$team->team_name = $child->nodeValue;
|
||||
|
||||
else if ($child->nodeName == "firstname")
|
||||
$user->firstname = $child->nodeValue;
|
||||
else if ($child->nodeName == "slogan")
|
||||
$team->slogan = $child->nodeValue;
|
||||
|
||||
else if ($child->nodeName == "lastname")
|
||||
$user->lastname = $child->nodeValue;
|
||||
else if ($child->nodeName == "member")
|
||||
{
|
||||
if (!$team->update())
|
||||
erreur("Unable to add team ".$team->team_name);
|
||||
|
||||
else if ($child->nodeName == "company")
|
||||
$user->company = $child->nodeValue;
|
||||
$user = new Member();
|
||||
$user->team = $team;
|
||||
|
||||
foreach ($child->childNodes as $child_member)
|
||||
{
|
||||
if ($child_member->nodeName == "firstname")
|
||||
$user->firstname = $child_member->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->username);
|
||||
erreur("Unable to add user ".$user->nickname);
|
||||
|
||||
$team->members[] = $user;
|
||||
}
|
||||
}
|
||||
erreur("XML file successfully imported.", "success");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
header("Location: /");
|
||||
exit;
|
||||
erreur("Fichier XML importé avec succès.", "success");
|
||||
}
|
||||
|
||||
return "admin/import_users";
|
||||
|
36
onyx/include/admin/list_users.php
Normal file
36
onyx/include/admin/list_users.php
Normal 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";
|
@ -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();
|
||||
}
|
||||
@ -208,9 +207,9 @@ class Team
|
||||
$db->deconnexion();
|
||||
|
||||
$array = array();
|
||||
foreach ($ids as $id){
|
||||
if ($ids)
|
||||
foreach ($ids as $id)
|
||||
$array[] = new Team($id['id']);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
19
onyx/tpl/bootstrap/admin/export_teams.tpl
Normal file
19
onyx/tpl/bootstrap/admin/export_teams.tpl
Normal 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>
|
7
onyx/tpl/bootstrap/admin/home.tpl
Normal file
7
onyx/tpl/bootstrap/admin/home.tpl
Normal file
@ -0,0 +1,7 @@
|
||||
{extends file="admin/layout.tpl"}
|
||||
|
||||
{block name=content}
|
||||
<h1>
|
||||
Zone d'administration
|
||||
</h1>
|
||||
{/block}
|
@ -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}
|
||||
|
48
onyx/tpl/bootstrap/admin/layout.tpl
Normal file
48
onyx/tpl/bootstrap/admin/layout.tpl
Normal 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">×</button>
|
||||
<i class="icon-warning-sign"></i> {$ERRmessage}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="container">
|
||||
{block name=content}{/block}
|
||||
</div>
|
||||
</div>
|
||||
{/block}
|
48
onyx/tpl/bootstrap/admin/users.tpl
Normal file
48
onyx/tpl/bootstrap/admin/users.tpl
Normal 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}
|
Loading…
Reference in New Issue
Block a user