Commit 85eda623 authored by Kylian ou Nathan's avatar Kylian ou Nathan
Browse files

Up

parent 96e5d2ed
<?php
class Capteur extends CI_Controller{
class Capteur extends CI_Controller
{
public function __construct(){
public function __construct()
{
parent::__construct();
$this->load->model("CapteurModele");
$this->load->helper("url_helper");
}
public function list(){
function list() {
//VERIFICATION QUE L'UTILISATEUR EST CONNECTE
if(!$this->session->has_userdata("email")){
if (!$this->session->has_userdata("email")) {
redirect('/connexion', 'refresh');
exit();
}
$capteurs = $this->CapteurModele->getAll();
if($capteurs == false){
$data = array("error"=> "Vous n'avez aucun capteur.");
if ($capteurs == false) {
$data = array("error" => "Vous n'avez pas ajouté de capteur pour le moment.");
} else {
$data = array("capteurs" => $capteurs);
}
......@@ -27,64 +29,37 @@ class Capteur extends CI_Controller{
$this->load->view('capteur/list', $data);
}
public function edit($id = "nouveau"){
public function edit($id = "new")
{
//VERIFICATION QUE L'UTILISATEUR EST CONNECTE
if(!$this->session->has_userdata("email")){
if (!$this->session->has_userdata("email")) {
redirect('/connexion', 'refresh');
exit();
}
$data = array();
if($this->input->server('REQUEST_METHOD') == 'POST') {
if ($this->input->server('REQUEST_METHOD') == 'POST') {
//REQUETE HTTP POST
if($this->input->post('nom') != null and
$this->input->post('id') != null and
$this->input->post('ip') != null and
$this->input->post('type') != null
){
if($this->input->post('id') != null){
$id = $this->input->post('id');
} else {
$id = "new";
}
if ($this->input->post('nom') != null and
$this->input->post('ip') != null and
$this->input->post('type') != null
) {
$nom = $this->input->post('nom');
$ip = $this->input->post('ip');
$type = $this->input->post('type');
if($this->CapteurModele->editProfil($id, $nom, $ip, $type)){
// On met a jour le capteur
$this->CapteurModele->edit($id, $nom, $ip, $type);
redirect("/capteur", "refresh");
} else {
if($this->input->post('id') != null){
$id = $this->input->post('id');
} else {
$id = "new";
}
$data["id"] = $id;
$data["nom"] = $this->input->post('nom');
$data["ip"] = $this->input->post('ip');
$data["type"] = $this->input->post('type');
$this->load->view('capteur/edit', $data);
}
redirect("/capteur", "refresh");
} else {
if($this->input->post('id') != null){
$id = $this->input->post('id');
} else {
$id = "new";
}
$data["id"] = $id;
$data["new"] = $id == "new";
$data["nom"] = $this->input->post('nom');
$data["ip"] = $this->input->post('ip');
$data["type"] = $this->input->post('type');
......@@ -95,32 +70,33 @@ class Capteur extends CI_Controller{
} else {
//REQUETE HTTP GET OU AUTRE
if($id !== "new") {
if ($id != "new") {
$d = $this->CapteurModele->get($id);
$capteur = $this->CapteurModele->get($id);
if($d !== false) {
$data["id"] = $d->id;
$data["nom"] = $d->nom;
$data["type"] = $d->type;
$data["ip"] = $d->ip;
if ($capteur !== false) {
$data["id"] = $capteur->id;
$data["nom"] = $capteur->nom;
$data["type"] = $capteur->type;
$data["ip"] = $capteur->ip;
$data["new"] = false;
} else {
$data["new"] = true;
redirect("/capteur", "refresh");
}
} else {
$data["new"] = true;
}
$this->load->view('capteur/edit', $data);
}
}
public function delete($id){
public function delete($id)
{
//VERIFICATION QUE L'UTILISATEUR EST CONNECTE
if(!$this->session->has_userdata("email")){
if (!$this->session->has_userdata("email")) {
redirect('/connexion', 'refresh');
exit();
}
......@@ -128,11 +104,7 @@ class Capteur extends CI_Controller{
$this->CapteurModele->delete($id);
redirect("/capteur", "refresh");
}
}
?>
\ No newline at end of file
......@@ -16,7 +16,7 @@ class Profil extends CI_Controller{
exit();
}
$profils = $this->ProfilModele->getProfils();
$profils = $this->ProfilModele->getAll();
if($profils == false) {
$data = array("error" => "Il n'existe pas de profil pour le moment.");
......@@ -27,7 +27,7 @@ class Profil extends CI_Controller{
$this->load->view('profil/list', $data);
}
public function edit($id = "nouveau"){
public function edit($id = "new"){
//VERIFICATION QUE L'UTILISATEUR EST CONNECTE
if(!$this->session->has_userdata("email")){
......@@ -46,48 +46,19 @@ class Profil extends CI_Controller{
$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 {
$this->ProfilModele->edit($id, $nom, $debut, $fin, $capteur);
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);
}
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["new"] = $id == "new";
$data["nom"] = $this->input->post('nom');
$data["debut"] = $this->input->post('debut');
$data["fin"] = $this->input->post('fin');
......@@ -100,16 +71,16 @@ class Profil extends CI_Controller{
if($id !== "new") {
$d = $this->ProfilModele->getProfil($id);
$profil = $this->ProfilModele->get($id);
if($d !== false) {
$data["id"] = $d->id;
$data["nom"] = $d->nom;
$data["debut"] = $d->debut;
$data["fin"] = $d->fin;
if($profil !== false) {
$data["id"] = $profil->id;
$data["nom"] = $profil->nom;
$data["debut"] = $profil->debut;
$data["fin"] = $profil->fin;
$data["new"] = false;
} else {
$data["new"] = true;
redirect("/profil", "refresh");
}
} else {
......
<?php
class CapteurModele extends CI_Model {
class CapteurModele extends CI_Model
{
public function __construct() {
public function __construct()
{
$this->load->database();
}
// METHODE PERMETTANT DE RECUPERER TOUT LES CAPTEURS
public function getAll(){
public function getAll()
{
$sql = "SELECT * from Capteur";
$query = $this->db->query($sql);
......@@ -19,7 +22,8 @@ class CapteurModele extends CI_Model {
}
}
public function get($id){
public function get($id)
{
$sql = "SELECT * from Capteur WHERE id = ?";
$query = $this->db->query($sql, array($id));
......@@ -31,6 +35,34 @@ class CapteurModele extends CI_Model {
}
}
public function edit($id, $nom, $ip, $type)
{
$data = array();
$data["nom"] = $nom;
$data["ip"] = $ip;
$data["type"] = $type;
if ($id == "new") {
$this->db->insert('Capteur', $data);
} else {
$this->db->update('Capteur', $data, array("id" => $id));
}
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
public function delete($id)
{
$this->db->delete('Capteur', array("id" => $id));
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
}
?>
\ No newline at end of file
......@@ -9,7 +9,7 @@ class ProfilModele extends CI_Model
}
// METHODE PERMETTANT DE RECUPERER TOUT LES PROFILS
public function getProfils()
public function getAll()
{
$sql = "SELECT * from Profil";
......@@ -23,7 +23,7 @@ class ProfilModele extends CI_Model
}
// METHODE PERMETTANT DE RECUPERER UN PROFIL
public function getProfil($id)
public function get($id)
{
$sql = "SELECT * from Profil WHERE id = ?";
......@@ -37,35 +37,24 @@ class ProfilModele extends CI_Model
}
// METHODE PERMETTANT DE CREER OU MODIFIER UN PROFIL
public function editProfil($id, $nom, $debut, $fin, $sensor)
public function edit($id, $nom, $debut, $fin, $sensor)
{
if ($id == "new") {
$data = array();
$data["nom"] = $nom;
$data["debut"] = $debut;
$data["fin"] = $fin;
$data["sensor"] = json_encode($sensor);
$data = array();
$data["nom"] = $nom;
$data["debut"] = $debut;
$data["fin"] = $fin;
$data["sensor"] = json_encode($sensor);
if ($id == "new") {
$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);
$this->db->update('Profil', $data, array("id" => $id));
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
......
......@@ -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>Capteur - LockHome</title>
<link rel="stylesheet" href="<?= base_url() ?>/static/liste_capteur.css">
<link rel="stylesheet" href="<?= base_url() ?>/static/commun.css">
<link rel="stylesheet" href="<?=base_url()?>/static/liste_capteur.css">
<link rel="stylesheet" href="<?=base_url()?>/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,23 +15,25 @@
<body>
<header class="l_r">
<div class="left">
<a href="<?= base_url("/capteur") ?>">
<a href="<?=base_url("/capteur")?>">
<i class='uil uil-angle-left'></i>
</a>
<div class="title">Capteur : Porte d'entrée</div>
<div class="title"><?= ($new ? "Ajouter un capteur" : ("Capteur : " . $nom) )?></div>
</div>
<div class="right">
<a href="index.html" class="blue">
<button type="submit" form="EditCapteur" class="blue">
<i class='uil uil-check'></i>
</a>
</button>
</div>
</header>
<main>
<form id="EditCapteur" action="<?= base_url("/capteur/edit/" . ($new ? "new" : $id))?>" method="post">
<h6 class="big">Nom</h6>
<label for="NOM" class="input l_r">
<div class="left">
<i class='uil uil-processor'></i>
<input id="NOM" type="text" value="Porte d'entrée" />
<input name="nom" required type="text" value="<?=isset($nom) ? $nom : ""?>" placeholder="Nom du capteur" />
</div>
</label>
......@@ -39,24 +41,26 @@
<label for="IP" class="input l_r">
<div class="left">
<i class='uil uil-wifi'></i>
<input id="IP" type="text" value="192.168.0.23" />
<input name="ip" required pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$" type="text" value="<?=isset($ip) ? $ip : ""?>" placeholder="192.168.4..." />
</div>
</label>
<h6 class="big">Type du capteur</h6>
<select id="TYPE_DU_CAPTEUR">
<option selected disabled value="ouverture">Veuillez choisir le type du capteur</option>
<option value="ouverture">Capteur d'ouverture</option>
<option value="vibration">Capteur de vibration</option>
<option value="infrarouge">Capteur infrarouge</option>
<select id="TYPE_DU_CAPTEUR" required name="type">
<option <?= $new ? "selected" : "" ?> disabled value="ouverture">Veuillez choisir le type du capteur</option>
<option <?= isset($type) && $type == "ouverture" ? "selected" : "" ?> value="ouverture">Capteur d'ouverture</option>
<option <?= isset($type) && $type == "vibration" ? "selected" : "" ?> value="vibration">Capteur de vibration</option>
<option <?= isset($type) && $type == "infrarouge" ? "selected" : "" ?> value="infrarouge">Capteur infrarouge</option>
</select>
<a href="<?= base_url("/capteur/edit") ?>" class="simple_button_link l_r red bottom">
<div class="left">
<i class='uil uil-trash-alt'></i>
<div class="title">Supprimer ce capteur</div>
</div>
</a>
<?php if (!$new) {?>
<a href="<?=base_url("/capteur/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 capteur</div>
</div>
</a>
<?php }?>
</main>
</body>
......
......@@ -18,33 +18,23 @@
<a href="<?= base_url("/profil/") ?>">
<i class='uil uil-angle-left'></i>
</a>
<div class="title">
<?php if($new == true) { ?>
Créer un profil
<?php } else { ?>
Profil : <?= $nom ?>
<?php } ?>
</div>
<div class="title"><?= $new ? "Créer un profil" : "Profil :".$nom ?></div>
</div>
<div class="right">
<button type="submit" form="EditProfil" href="<?= base_url("/profil/edit") ?>" class="blue">
<button type="submit" form="EditProfil" class="blue">
<i class='uil uil-check'></i>
</button>
</div>
</header>
<main>
<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 } ?>
<form id="EditProfil" action="<?= base_url("/profil/edit/" . (!$new ? $id : "new")) ?>" method="post">
<h6 class="big">Nom</h6>
<label for="NOM" class="input l_r">
<div class="left">
<i class='uil uil-label-alt'></i>
<input id="NOM" type="text" name="nom" value="<?php if(!$new) echo $nom; ?>" placeholder="Vacance..." />
<input id="NOM" required type="text" name="nom" value="<?= !$new ? $nom : "" ?>" placeholder="Vacance..." />
</div>
</label>
......@@ -53,11 +43,11 @@
<div class="plage_horaire">
<div class="start">
<div class="text">Debut</div>
<input id="time" type="time" name="debut" value="<?php if(!$new) echo $debut; else echo "08:00"?>">
<input id="time" required type="time" name="debut" value="<?= !$new ? $debut : "08:00"?>">
</div>
<div class="end">
<div class="text">Fin</div>
<input id="time" type="time" name="fin" value="<?php if(!$new) echo $fin; else echo "18:00"?>">
<input id="time" required type="time" name="fin" value="<?= !$new ? $fin : "18:00"?>">
</div>
</div>
......
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