diff --git a/web/class/Database.class.php b/web/class/Database.class.php new file mode 100644 index 0000000..48eaef6 --- /dev/null +++ b/web/class/Database.class.php @@ -0,0 +1,226 @@ +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(); + } +} diff --git a/web/class/alerts.php b/web/class/alerts.php new file mode 100644 index 0000000..46e01b4 --- /dev/null +++ b/web/class/alerts.php @@ -0,0 +1,63 @@ +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; + // } +} diff --git a/web/css/styles.css b/web/css/styles.css new file mode 100644 index 0000000..0d7caf7 --- /dev/null +++ b/web/css/styles.css @@ -0,0 +1,13 @@ +html { + scroll-padding-top: 3.5rem; +} + +header { + padding-top: 9rem; + padding-bottom: 6rem; +} + +section { + padding-top: 9rem; + padding-bottom: 9rem; +} diff --git a/web/css/styles2.css b/web/css/styles2.css new file mode 100644 index 0000000..ea9a784 --- /dev/null +++ b/web/css/styles2.css @@ -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; +} diff --git a/web/index.php b/web/index.php new file mode 100644 index 0000000..491c2e0 --- /dev/null +++ b/web/index.php @@ -0,0 +1,186 @@ + + + + +
+ + + + +veuillez selectionner les filtres de recherche ou parcourez la liste ci-dessous
+ + + +N° | +Date | +Espece | +Zone | +Nombre | ++ | + |
---|---|---|---|---|---|---|
Getid(); ?> | +Getdate(); ?> | +Getespece(); ?> | +Getzone(); ?> | +Getnombre(); ?> | ++ + | ++ + | +