From 9c49a4384971b9265e776df24b6960db8040f3a4 Mon Sep 17 00:00:00 2001 From: Andre Chalom Date: Thu, 11 Feb 2016 18:04:57 -0200 Subject: [PATCH] Gerenciando impedimentos --- html/class/proibido.php | 43 +++++++++++++++++++++++++----- html/menu.php | 1 + html/proibidos.php | 58 +++++++++++++++++++++++++++++++++++++++++ rserve | 4 +-- tables.sql | 2 +- 5 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 html/proibidos.php diff --git a/html/class/proibido.php b/html/class/proibido.php index 90ecbfc..3b542ef 100644 --- a/html/class/proibido.php +++ b/html/class/proibido.php @@ -2,28 +2,45 @@ require_once("config.php"); class Proibidos { - private $id, $palavra; + private $id, $palavra, $exercicio, $hard; public function __construct($id=null) { global $mysqli; if ($id) { - $res = $mysqli->prepare("SELECT palavra FROM proibido WHERE id_proibido = ?"); + $res = $mysqli->prepare("SELECT palavra, id_exercicio, hard FROM proibido WHERE id_proibido = ?"); $res->bind_param('i', $id); $res->execute(); - $res->bind_result($this->palavra); + $res->bind_result($this->palavra, $this->exercicio, $this->hard); $res->fetch(); $this->id= $id; } } public function getPalavra() {return $this->palavra;} + public function getHard() {return $this->hard;} + public function getExercicio() {return $this->exercicio;} public function getId() {return $this->id;} - public function create($palavra, $id) { + public function create($palavra, $exercicio = null) { global $mysqli; - $res = $mysqli->prepare("INSERT INTO proibido (id_exercicio, palavra) VALUES (?, ?)"); - $res->bind_param('is', $id, $palavra); + if ($exercicio) { + $res = $mysqli->prepare("INSERT INTO proibido (id_exercicio, palavra) VALUES (?, ?)"); + $res->bind_param('is', $exercicio, $palavra); + } else { + $res = $mysqli->prepare("INSERT INTO proibido (palavra) VALUES (?)"); + $res->bind_param('s', $palavra); + } $res->execute(); - if (! $mysqli->error) return false; + if ($mysqli->error) return false; return true; } + public function remove() { + global $mysqli; + if ($this->hard == 1 or !empty($this->exercicio)) + return false; + $res = $mysqli->prepare("DELETE FROM proibido WHERE id_proibido = ?"); + $res->bind_param('i', $this->id); + $res->execute(); + if ($mysqli->error) return false; + return true; + } public function pass($string, $id_ex) { global $mysqli; $res = $mysqli->prepare("SELECT palavra FROM proibido WHERE id_exercicio =? OR id_exercicio IS NULL"); @@ -38,4 +55,16 @@ public function pass($string, $id_ex) { } } +function ListProibidos($ex = false) { + global $mysqli; + if ($ex) + $res = $mysqli->query("SELECT id_proibido FROM proibido WHERE id_exercicio IS NULL ORDER BY id_proibido ASC"); + else + $res = $mysqli->query("SELECT id_proibido FROM proibido WHERE id_exercicio IS NOT NULL ORDER BY id_proibido ASC"); + $a = array(); + while ($row = $res->fetch_assoc()) + array_push($a, new Proibidos($row['id_proibido'])); + return $a; +} + ?> diff --git a/html/menu.php b/html/menu.php index 5170650..1a21e0f 100644 --- a/html/menu.php +++ b/html/menu.php @@ -3,6 +3,7 @@ Administrar:

Relatórios: