Commit a7eec734 authored by Kylian ou Nathan's avatar Kylian ou Nathan
Browse files

Up

parent 3f116eae
......@@ -70,9 +70,9 @@ $route['capteur/edit'] = 'Capteur/edit';
$route['capteur/edit/(:any)'] = 'Capteur/edit/$1';
$route['capteur'] = 'Capteur/show';
$route['profil/nouveau'] = 'Profil/edit';
$route['profil/new'] = 'Profil/edit';
$route['profil/edit/(:any)'] = 'Profil/edit/$1';
$route['profil'] = 'Profil/show';
$route['profil'] = 'Profil/list';
$route['resume/show'] = 'Resume/show';
......
......@@ -8,7 +8,7 @@ class Profil extends CI_Controller{
$this->load->helper("url_helper");
}
public function show(){
public function list(){
//VERIFICATION QUE L'UTILISATEUR EST CONNECTE
if(!$this->session->has_userdata("email")){
......@@ -24,7 +24,7 @@ class Profil extends CI_Controller{
$data = array("profils" => $profils);
}
$this->load->view('profil/show', $data);
$this->load->view('profil/list', $data);
}
public function edit($id = "nouveau"){
......@@ -35,37 +35,82 @@ class Profil extends CI_Controller{
exit();
}
$data = array();
$data["capteurs"] = $this->CapteurModele->getCapteurs();
if($this->input->server('REQUEST_METHOD') == 'POST') {
//REQUETE HTTP POST
if($this->input->post('nom') != null and
$this->input->post('debut') != null and
$this->input->post('fin') != null and
$this->input->post('debut') != null
// A VERIFIER TOUTE LES DONNES DU POST
$this->input->post('fin') != null
){
if($this->input->post('id') != null){
$id = $this->input->post('id');
} else {
$id = "new";
}
$nom = $this->input->post('nom');
$debut = $this->input->post('debut');
$fin = $this->input->post('fin');
$capteur = array();
if($this->ProfilModele->editProfil($id, $nom, $debut, $fin, $capteur)){
redirect("/profil", "refresh");
} else {
if($this->input->post('id') != null){
$id = $this->input->post('id');
} else {
$id = "new";
}
$data["id"] = $id;
$data["new"] = false;
$data["nom"] = $this->input->post('nom');
$data["debut"] = $this->input->post('debut');
$data["fin"] = $this->input->post('fin');
$this->load->view('profil/edit', $data);
}
} else {
$msg = array("error" => "Vous n'avez pas envoyé le formulaire correctement.");
$this->load->view('auth/connexion', $msg);
if($this->input->post('id') != null){
$id = $this->input->post('id');
} else {
$id = "new";
}
$data["id"] = $id;
$data["new"] = false;
$data["nom"] = $this->input->post('nom');
$data["debut"] = $this->input->post('debut');
$data["fin"] = $this->input->post('fin');
$this->load->view('profil/edit', $data);
}
} else {
//REQUETE HTTP GET OU AUTRE
$data = array();
$data["capteurs"] = $this->CapteurModele->getCapteurs();
// CAPTEURS A RECUPERER
$d = $this->ProfilModele->getProfil($id);
if($id !== "nouveau") {
if($id !== "new") {
$d = $this->ProfilModele->getProfil($id);
if($d !== false) {
$data[""] = "y";
$data["id"] = $d->id;
$data["nom"] = $d->nom;
$data["debut"] = $d->debut;
$data["fin"] = $d->fin;
$data["new"] = false;
} else {
$data["new"] = true;
}
// AJOUTER TOUT LES ATTRIBUTS
} else {
$data["new"] = true;
......@@ -74,6 +119,20 @@ class Profil extends CI_Controller{
$this->load->view('profil/edit', $data);
}
}
public function delete($id){
//VERIFICATION QUE L'UTILISATEUR EST CONNECTE
if(!$this->session->has_userdata("email")){
redirect('/connexion', 'refresh');
exit();
}
$this->ProfilModele->delete($id);
redirect("/profil", "refresh");
}
}
?>
\ No newline at end of file
<?php
class ProfilModele extends CI_Model {
class ProfilModele extends CI_Model
{
public function __construct() {
public function __construct()
{
$this->load->database();
}
// METHODE PERMETTANT DE RECUPERER TOUT LES PROFILS
public function getProfils() {
public function getProfils()
{
$sql = "SELECT * from Profil";
$query = $this->db->query($sql);
......@@ -15,12 +18,13 @@ class ProfilModele extends CI_Model {
if ($query->num_rows() == 0) {
return false;
} else {
return $query->fetchAll(PDO::FETCH_COLUMN);
return $query->result();
}
}
// METHODE PERMETTANT DE RECUPERER UN PROFIL
public function getProfil($id) {
public function getProfil($id)
{
$sql = "SELECT * from Profil WHERE id = ?";
$query = $this->db->query($sql, array($id));
......@@ -28,10 +32,51 @@ class ProfilModele extends CI_Model {
if ($query->num_rows() == 0) {
return false;
} else {
return $query->fetchAll(PDO::FETCH_COLUMN, 0);
return $query->result()[0];
}
}
}
// METHODE PERMETTANT DE CREER OU MODIFIER UN PROFIL
public function editProfil($id, $nom, $debut, $fin, $sensor)
{
if ($id == "new") {
$data = array();
$data["nom"] = $nom;
$data["debut"] = $debut;
$data["fin"] = $fin;
$data["sensor"] = json_encode($sensor);
$this->db->insert('Profil', $data);
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
} else {
$data = array();
$data["nom"] = $nom;
$data["debut"] = $debut;
$data["fin"] = $fin;
$data["sensor"] = json_encode($sensor);
?>
\ No newline at end of file
$this->db->update('Profil', $data, array("id" => $id));
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
}
public function delete($id)
{
$this->db->delete('Profil', array("id" => $id));
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
}
......@@ -77,7 +77,7 @@
</div>
</section>
<a href="<?= base_url("/profil/show") ?>" class="first_button simple_button_link l_r blue">
<a href="<?= base_url("/profil/list") ?>" class="first_button simple_button_link l_r blue">
<div class="left">
<i class='uil uil-label-alt'></i>
<div class="title">Voir les profils</div>
......
......@@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Profil - LockHome</title>
<link rel="stylesheet" href="../static/liste_capteur.css">
<link rel="stylesheet" href="../static/commun.css">
<link rel="stylesheet" href="/static/liste_capteur.css">
<link rel="stylesheet" href="/static/commun.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://unicons.iconscout.com/release/v2.0.1/css/unicons.css">
</head>
......@@ -15,7 +15,7 @@
<body>
<header class="l_r">
<div class="left">
<a href="index.html">
<a href="<?= base_url("/profil/") ?>">
<i class='uil uil-angle-left'></i>
</a>
<div class="title">
......@@ -34,7 +34,12 @@
</div>
</header>
<main>
<form id="EditProfil" action="<?= base_url("/profil/edit") ?>">
<form id="EditProfil" action="<?= base_url("/profil/edit/" . ($new == false ? $id : "new")) ?>" method="post">
<?php if(!$new) { ?>
<input id="ID" type="hidden" name="id" value="<?= $id ?>" />
<?php } ?>
<h6 class="big">Nom</h6>
<label for="NOM" class="input l_r">
<div class="left">
......@@ -48,16 +53,14 @@
<div class="plage_horaire">
<div class="start">
<div class="text">Debut</div>
<input id="time" type="time" name="debut" value="<?php if(!$new) echo $nom; else echo "08:00"?>">
<input id="time" type="time" name="debut" value="<?php if(!$new) echo $debut; else echo "08:00"?>">
</div>
<div class="end">
<div class="text">Fin</div>
<input id="time" type="time" name="fin" value="<?php if(!$new) echo $nom; else echo "18:00"?>">
<input id="time" type="time" name="fin" value="<?php if(!$new) echo $fin; else echo "18:00"?>">
</div>
</div>
<h6 class="big">Etat des capteurs pour ce profil :</h6>
<section class="tab_layout">
......@@ -87,7 +90,7 @@
<?php if(!$new) { ?>
<a href="liste_capteur.html" class="simple_button_link l_r red bottom">
<a href="<?= base_url("/profil/delete/".$id) ?>" class="simple_button_link l_r red bottom">
<div class="left">
<i class='uil uil-trash-alt'></i>
<div class="title">Supprimer ce profil</div>
......
......@@ -23,7 +23,7 @@
</header>
<main>
<h6>Vous souhaitez créer un nouveau profil ?</h6>
<a href="<?= base_url("/nouveau") ?>" class="simple_button_link l_r blue">
<a href="<?= base_url("profil/new") ?>" class="simple_button_link l_r blue">
<div class="left">
<i class='uil uil-plus-circle'></i>
<div class="title">Créer un profil</div>
......@@ -41,9 +41,9 @@
foreach($profils as $profil) {
?>
<a href="<?= base_url("profil/".$profil["id"])?>" class="simple_button_link l_r">
<a href="<?= base_url("profil/edit/".$profil->id)?>" class="simple_button_link l_r">
<div class="left">
<div class="title"><?= $profil["nom"] ?></div>
<div class="title"><?= $profil->nom ?></div>
</div>
<div class="right">
<i class='uil uil-angle-right'></i>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment