mirror of
https://github.com/Oxbian/SIDPS.git
synced 2025-07-06 11:55:40 +02:00
add php
This commit is contained in:
226
web/class/Database.class.php
Normal file
226
web/class/Database.class.php
Normal file
@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
class Database
|
||||
{
|
||||
private $db_name;
|
||||
private $db_user;
|
||||
private $db_pass;
|
||||
private $db_host;
|
||||
private $pdo;
|
||||
|
||||
public function __construct($db_name = "", $db_user = '', $db_pass = '', $db_host = 'localhost')
|
||||
{
|
||||
$this->db_name = $db_name;
|
||||
$this->db_user = $db_user;
|
||||
$this->db_pass = $db_pass;
|
||||
$this->db_host = $db_host;
|
||||
}
|
||||
|
||||
private function getPDO()
|
||||
{
|
||||
if ($this->pdo === null) {
|
||||
$pdo = new PDO('mysql:dbname=' . $this->db_name . ';host=localhost;charset=UTF8', $this->db_user, $this->db_pass);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
return $this->pdo;
|
||||
}
|
||||
|
||||
public function query($stmt, $class_name)
|
||||
{
|
||||
$req = $this->getPDO()->query($stmt);
|
||||
return $req->fetchAll(PDO::FETCH_CLASS, $class_name);
|
||||
}
|
||||
|
||||
|
||||
// TOCHANGE
|
||||
public function getnbAlerts()
|
||||
{
|
||||
$sql = 'SELECT COUNT(*) AS nb_alerts FROM alerts';
|
||||
|
||||
$sth = $this->getPDO()->prepare($sql);
|
||||
$sth->execute();
|
||||
$result = $sth->fetch();
|
||||
|
||||
$nbAlerts = (int) $result['nb_alerts'];
|
||||
return $nbAlerts;
|
||||
}
|
||||
|
||||
// TODO
|
||||
public function getAlerts($filters = null, $limit = 10)
|
||||
{
|
||||
$whereArgs = [];
|
||||
|
||||
if (isset($_GET["page"])) {
|
||||
$page = intval($_GET['page']);
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$decalage = ($page - 1) * $limit;
|
||||
|
||||
$sql = 'SELECT *
|
||||
FROM alerts ';
|
||||
|
||||
if ($filters != null) {
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($value != '') $whereArgs[] = $key . ' = :' . $key;
|
||||
}
|
||||
}
|
||||
if (!empty($whereArgs)) $sql .= 'WHERE ' . implode(' AND ', $whereArgs);
|
||||
|
||||
$sql .= ' LIMIT :limit OFFSET :offset';
|
||||
$sth = $this->getPDO()->prepare($sql);
|
||||
|
||||
// TODO : edit filters
|
||||
if ($filters != null) {
|
||||
if ($filters['date'] != '') $sth->bindParam('date', $filters['date']);
|
||||
if ($filters['espece'] != '') $sth->bindParam('espece', $filters['espece']);
|
||||
if ($filters['zone'] != '') $sth->bindParam('zone', $filters['zone']);
|
||||
}
|
||||
$sth->bindParam(':limit', $limit, PDO::PARAM_INT);
|
||||
$sth->bindParam(':offset', $decalage, PDO::PARAM_INT);
|
||||
$sth->execute();
|
||||
|
||||
return $sth->fetchAll(PDO::FETCH_CLASS, 'Alerts');
|
||||
}
|
||||
|
||||
public function getAlertUnique($filters = null)
|
||||
{
|
||||
$whereArgs = [];
|
||||
$sql = 'SELECT *
|
||||
FROM alerts ';
|
||||
|
||||
if ($filters != null) {
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($value != '') $whereArgs[] = $key . ' = :' . $key;
|
||||
}
|
||||
}
|
||||
if (!empty($whereArgs)) $sql .= 'WHERE ' . implode(' AND ', $whereArgs);
|
||||
|
||||
$sth = $this->getPDO()->prepare($sql);
|
||||
|
||||
if ($filters != null) {
|
||||
if ($filters['id'] != '') $sth->bindParam('id', $filters['id']);
|
||||
}
|
||||
$sth->execute();
|
||||
|
||||
return $sth->fetchAll(PDO::FETCH_CLASS, 'Alerts');
|
||||
}
|
||||
|
||||
public function getAlertsByGravite()
|
||||
{
|
||||
$sql = 'SELECT gravite
|
||||
FROM alerts
|
||||
GROUP BY gravite';
|
||||
|
||||
$sth = $this->getPDO()->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
|
||||
$sth->execute();
|
||||
return $sth->fetchAll(PDO::FETCH_CLASS, 'Alerts');
|
||||
}
|
||||
|
||||
|
||||
public function getnbbygravite($filters = null)
|
||||
{
|
||||
$i=0;
|
||||
$tmp=0;
|
||||
$maxrg=0;
|
||||
$whereArgs = [];
|
||||
if ($filters != null) {
|
||||
foreach ($filters as $key) {
|
||||
$whereArgs[] = $key;
|
||||
}
|
||||
$sql = 'SELECT gravite, COUNT(*) as nbbygravite FROM Alerts where date>='. implode(' AND ', $whereArgs).' GROUP BY gravite';
|
||||
}else {
|
||||
$sql = 'SELECT gravite, COUNT(*) as nbbygravite FROM Alerts GROUP BY gravite';
|
||||
|
||||
}
|
||||
|
||||
|
||||
$sth = $this->getPDO()->prepare($sql);
|
||||
$sth->execute();
|
||||
$result = $sth->fetchAll(PDO::FETCH_CLASS, 'Alerts');
|
||||
while($i<38)
|
||||
{
|
||||
if((int)($result[$i]->nbbyespece)>$tmp)
|
||||
{
|
||||
$tmp=(int)($result[$i]->nbbyespece);
|
||||
$maxrg=$i;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return $result[$maxrg]->espece;
|
||||
}
|
||||
|
||||
// TODO : remplacer par ce qui est demandé
|
||||
// public function getnbbyzone($filters = null)
|
||||
// {
|
||||
// $i=0;
|
||||
// $tmp=0;
|
||||
// $maxrg=0;
|
||||
// $whereArgs = [];
|
||||
// if ($filters != null) {
|
||||
// foreach ($filters as $key) {
|
||||
// $whereArgs[] = $key;
|
||||
// }
|
||||
// $sql = 'SELECT zone, COUNT(*) as nbbyzone FROM echouage where date>='. implode(' AND ', $whereArgs).' GROUP BY zone';
|
||||
// }else {
|
||||
// $sql = 'SELECT espece, COUNT(*) as nbbyespece FROM echouage GROUP BY espece';
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// $sth = $this->getPDO()->prepare($sql);
|
||||
// $sth->execute();
|
||||
// $result = $sth->fetchAll(PDO::FETCH_CLASS, 'Echouage');
|
||||
// while($i<2)
|
||||
// {
|
||||
// if((int)($result[$i]->nbbyzone)>$tmp)
|
||||
// {
|
||||
// $tmp=(int)($result[$i]->nbbyzone);
|
||||
// $maxrg=$i;
|
||||
// }
|
||||
// $i++;
|
||||
// }
|
||||
// return $result[$maxrg]->zone;
|
||||
// }
|
||||
|
||||
// public function getZonesEchouage()
|
||||
// {
|
||||
// $sql = 'SELECT zone
|
||||
// FROM echouage
|
||||
// GROUP BY zone';
|
||||
|
||||
// $sth = $this->getPDO()->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
|
||||
// $sth->execute();
|
||||
// return $sth->fetchAll(PDO::FETCH_CLASS, 'Echouage');
|
||||
// }
|
||||
|
||||
|
||||
public function editEchouage($id, $newCet)
|
||||
{
|
||||
$sql = "UPDATE echouage
|
||||
SET date=".$newCet['date'].", espece='".$newCet['espece']."', zone='".$newCet['zone']."', nombre=".$newCet['nb']
|
||||
." WHERE id=".$id;
|
||||
|
||||
$sth = $this->getPDO()->prepare($sql);
|
||||
$sth->execute();
|
||||
}
|
||||
|
||||
// TODO : ajouter commentaires
|
||||
// public function addComm($newCet)
|
||||
// {
|
||||
// $sql = "INSERT INTO echouage (date, espece, zone, nombre)
|
||||
// VALUES (".$newCet['date'].", '".$newCet['espece']."', '".$newCet['zone']."', ".$newCet['nb'].")";
|
||||
|
||||
// $sth = $this->getPDO()->prepare($sql);
|
||||
// $sth->execute();
|
||||
// }
|
||||
|
||||
public function deleteAlerts($id)
|
||||
{
|
||||
// $sql = "DELETE from echouage WHERE id=".$id;
|
||||
// $sth = $this->getPDO()->prepare($sql);
|
||||
// $sth->execute();
|
||||
}
|
||||
}
|
63
web/class/alerts.php
Normal file
63
web/class/alerts.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
class Alerts
|
||||
{
|
||||
//attributs TDO change names
|
||||
private $id;
|
||||
private $date;
|
||||
public $espece;
|
||||
public $zone;
|
||||
private $nombre;
|
||||
|
||||
//methodes TODO : changes names
|
||||
public function Getid()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
public function Getdate()
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
public function Getespece()
|
||||
{
|
||||
return $this->espece;
|
||||
}
|
||||
public function Getzone()
|
||||
{
|
||||
return $this->zone;
|
||||
}
|
||||
public function Getnombre()
|
||||
{
|
||||
return $this->nombre;
|
||||
}
|
||||
|
||||
public function Setid($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
public function Setdate($date)
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
public function Setespece($espece)
|
||||
{
|
||||
$this->espece = $espece;
|
||||
}
|
||||
public function Setzone($zone)
|
||||
{
|
||||
$this->zone = $zone;
|
||||
}
|
||||
public function Setnombre($nombre)
|
||||
{
|
||||
$this->nombre = $nombre;
|
||||
}
|
||||
|
||||
// function __construct($id, $date, $espece, $zone, $nombre)
|
||||
// {
|
||||
// $this->$id = $id;
|
||||
// $this->$date = $date;
|
||||
// $this->$espece = $espece;
|
||||
// $this->$zone = $zone;
|
||||
// $this->$nombre = $nombre;
|
||||
// }
|
||||
}
|
13
web/css/styles.css
Normal file
13
web/css/styles.css
Normal file
@ -0,0 +1,13 @@
|
||||
html {
|
||||
scroll-padding-top: 3.5rem;
|
||||
}
|
||||
|
||||
header {
|
||||
padding-top: 9rem;
|
||||
padding-bottom: 6rem;
|
||||
}
|
||||
|
||||
section {
|
||||
padding-top: 9rem;
|
||||
padding-bottom: 9rem;
|
||||
}
|
19
web/css/styles2.css
Normal file
19
web/css/styles2.css
Normal file
@ -0,0 +1,19 @@
|
||||
html {
|
||||
scroll-padding-top: 3.5rem;
|
||||
}
|
||||
|
||||
header {
|
||||
padding-top: 5rem;
|
||||
padding-bottom: 3rem;
|
||||
}
|
||||
|
||||
section {
|
||||
padding-top: 9rem;
|
||||
padding-bottom: 9rem;
|
||||
}
|
||||
|
||||
figcaption{
|
||||
font-weight: lighter;
|
||||
font-size: small;
|
||||
font-style: italic;
|
||||
}
|
186
web/index.php
Normal file
186
web/index.php
Normal file
@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 'on');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
spl_autoload_register(function ($class) {
|
||||
include 'class/' . $class . '.class.php';
|
||||
});
|
||||
|
||||
$db = new Database();
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
<title>IDPS visualization</title>
|
||||
<link rel="icon" type="image/x-icon" href="assets/favicon.ico"><!-- Core theme CSS (includes Bootstrap)-->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
||||
<link href="/css/styles.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body id="page-top">
|
||||
<!-- Navigation-->
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top" id="mainNav">
|
||||
<div class="container px-4"><a class="navbar-brand" href="#page-top">Alerts</a><button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
|
||||
<div class="collapse navbar-collapse" id="navbarResponsive">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<!-- TODO changer ? -->
|
||||
<!-- <li class="nav-item"><a class="nav-link" href="/">Accueil</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#echouage">Liste des échouages</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="add.php">Enregistrer un echouage</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="stats.php">statistiques</a></li> -->
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav><!-- Header-->
|
||||
<header class="bg-primary bg-gradient text-white">
|
||||
<div class="container px-4 text-center">
|
||||
<h1 class="fw-bolder">Alertes systemes</h1>
|
||||
<p class="lead">meilleur outil de surveillance du monde</p>
|
||||
<a class="btn btn-lg btn-light" href="#alertes">Alertes</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="bg-light" id="alertes">
|
||||
<div class="container px-4">
|
||||
<div class="row gx-4 justify-content-center">
|
||||
<div class="col-lg-8">
|
||||
<h2>Liste des échouages</h2>
|
||||
<p class="lead">veuillez selectionner les filtres de recherche ou parcourez la liste ci-dessous</p>
|
||||
|
||||
<form class="row g-3" method="POST">
|
||||
|
||||
<div class="col-auto">
|
||||
<select class="form-select" aria-label="Choisir une date" name="date">
|
||||
<option selected value="">Année</option>
|
||||
<?php for ($i = 1990; $i < 2020; $i++) : ?>
|
||||
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
|
||||
<?php endfor; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-auto">
|
||||
<select class="form-select" aria-label="Chosisir une gravité" name="gravité">
|
||||
<option selected value="">Gravité</option>
|
||||
<?php
|
||||
$especesByType = $db->getAlertsByGravite();
|
||||
foreach ($especesByType as $espece) : ?>
|
||||
<option value="<?php echo $espece->Getespece(); ?>"><?php echo $espece->Getespece(); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- <div class="col-auto">
|
||||
<select class="form-select" aria-label="Chosisir une zone" name="zone">
|
||||
<option selected value="">Zone</option>
|
||||
|
||||
<?php
|
||||
// $zonesEchouage = $db->getZonesEchouage();
|
||||
// foreach ($zonesEchouage as $zone) : ?>
|
||||
<option value="<?php //echo $zone->Getzone(); ?>"><?php// echo $zone->Getzone(); ?></option>
|
||||
<?php //endforeach; ?>
|
||||
</select>
|
||||
</div> -->
|
||||
|
||||
<div class="col-auto ms-auto me-0">
|
||||
<button type="submit" class="btn btn-primary mb-3">Filtrer</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead class="bg-primary text-white">
|
||||
<tr>
|
||||
<th scope="col" class="id">N°</th>
|
||||
<th scope="col" class="Date">Date</th>
|
||||
<th scope="col" class="label">Espece</th>
|
||||
<th scope="col" class="label">Zone</th>
|
||||
<th scope="col" class="label">Nombre</th>
|
||||
<th scope="col" class="label"></th>
|
||||
<th scope="col" class="label"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody style="border: 1px solid black;">
|
||||
|
||||
<?php
|
||||
$echouages = $db->getAlerts($_POST, 20);
|
||||
foreach ($echouages as $echouage) : ?>
|
||||
<tr style="border: 1px solid black;">
|
||||
<td class="id"><?php echo $echouage->Getid(); ?></td>
|
||||
<td class="id"><?php echo $echouage->Getdate(); ?></td>
|
||||
<td class="label"><a href="info-echouage.php/?id=<?php echo $echouage->Getid(); ?>"><?php echo $echouage->Getespece(); ?></a></td>
|
||||
<td class="label"><?php echo $echouage->Getzone(); ?></td>
|
||||
<td class="label"><?php echo $echouage->Getnombre(); ?></td>
|
||||
<td class="label"><a href="delete.php/?id=<?php echo $echouage->Getid(); ?>">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
|
||||
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
|
||||
<path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
|
||||
</svg></a>
|
||||
</td>
|
||||
<td class="label"><a href="edit.php/?id=<?php echo $echouage->Getid(); ?>">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil" viewBox="0 0 16 16">
|
||||
<path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"/>
|
||||
</svg></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination">
|
||||
|
||||
<?php
|
||||
$nb_echouage = $db->getnbAlerts();
|
||||
$nb_page = ceil($nb_echouage / 20);
|
||||
if (isset($_GET["page"])) {
|
||||
$page = intval($_GET['page']);
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
echo "<li class='page-item col-auto'><a class='page-link' href=index.php?page=1'>premiere page</a></li>";
|
||||
|
||||
if ($page > 1) {
|
||||
echo "<li class='page-item col-auto'><a class='page-link' href=index.php?page=" . strval($page - 1) . "'>" . strval($page - 1) . "</a></li>";
|
||||
}
|
||||
|
||||
echo "<li class='page-item col-auto'><a class='page-link' style=href=index.php?page=" . $page . "'>" . $page . "</a></li>";
|
||||
|
||||
if (($page) < $nb_page) {
|
||||
echo "<li class='page-item col-auto'><a class='page-link' href=index.php?page=" . strval($page + 1) . "'>" . strval($page + 1) . "</a></li>";
|
||||
}
|
||||
|
||||
echo "<li class='page-item col-auto'><a class='page-link' href=index.php?page=" . strval($nb_page) . "'>derniere page</a></li>";
|
||||
?>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
</nav>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section><!-- Contact section-->
|
||||
|
||||
|
||||
|
||||
|
||||
<footer class="py-5 bg-dark">
|
||||
<div class="container px-4">
|
||||
<p class="m-0 text-center text-white">Copyright © CIR2 2023/<a class ="text-white" href="https://www.observatoire-pelagis.cnrs.fr/">Pelagis</a></p>
|
||||
</div>
|
||||
</footer><!-- Bootstrap core JS-->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script><!-- Core theme JS-->
|
||||
<!-- <script src="js/scripts.js"></script> -->
|
||||
</body>
|
||||
|
||||
</html>
|
Reference in New Issue
Block a user