Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
Gerenciando impedimentos
Browse files Browse the repository at this point in the history
  • Loading branch information
andrechalom committed Feb 11, 2016
1 parent dedcd8d commit 9c49a43
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 10 deletions.
43 changes: 36 additions & 7 deletions html/class/proibido.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
}

?>
1 change: 1 addition & 0 deletions html/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Administrar:<br><ul><li><a href='turmas.php'>Turmas</a></li>
<li><a href='alunos.php'>Alunos</a></li><li><a href='prazos.php'>Prazos</a></li>
<li><a href='arquivos.php'>Arquivos</a></li>
<li><a href='proibidos.php'>Impedimentos</a></li>
</ul>
<br>Relat&oacute;rios:<ul><li><a href='notas.php'>Notas</a></li>
<li><a href='complecao.php'>Realiza&ccedil;&atilde;o</a></li>
Expand Down
58 changes: 58 additions & 0 deletions html/proibidos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php require('head.php');
if (! $USER->admin()) {
echo "<p class='alert alert-danger'>Acesso negado</p>";
exit;
}
require('menu.php');
?>
<h2>Administra&ccedil;&atilde;o de impedimentos</h2>
<?php
if (isset($_REQUEST['delete'])) {
$pr = new Proibidos($_REQUEST['delete']);
if ($pr->remove())
echo "<p class='alert alert-success'>Impedimento removido</p>";
else
echo "<p class='alert alert-danger'>Erro ao remover impedimento!</p>";
}
if(isset($_REQUEST['submit'])) {
$pr = new Proibidos();
if ($pr->create($_REQUEST['nome']))
echo "<p class='alert alert-success'>Impedimento criado</p>";
else
echo "<p class='alert alert-danger'>Erro ao criar impedimento!</p>";
}
?>
<p>Impedimentos globais cadastrados:</p>
<p>(Para detalhes de como impedimentos funcionam, veja <a href="https://github.com/lageIBUSP/notaR/wiki/Gerenciando-arquivos-e-proibi%C3%A7%C3%B5es">aqui</a>).
<table><tr><th colspan=2>Palavra</th></tr>
<?php
foreach (ListProibidos(true) as $pr) {
echo "<tr><td>";
if (!$pr->getHard())
echo "<a href='?delete=".$pr->getId()."'><span class='glyphicon glyphicon-remove'></span></a>";
echo "</td><td>".$pr->getPalavra()."</td></tr>";
}
?>
</table>

<p>Exerc&iacute;cios com impedimentos locais:</p>
<table><tr><th colspan=2>Palavra</th><th>Exerc&iacute;cio</th></tr>
<?php
foreach (ListProibidos(false) as $pr) {
echo "<tr><td>";
$EX = new Exercicio($pr->getExercicio());
echo "<a href='cadastra.php?exerc=".$pr->getExercicio()."'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "</td><td>".$pr->getPalavra()."</td><td>".$EX->getNome()."</td></tr>";
}
?>
</table>

<form name="cadastro" action="?" method="post">
<p>&nbsp;</p>
<p>Criar novo impedimento global: <input type="text" name="nome" style="width: 300px;"></p>
<p><button type="submit" name="submit" value="submit">ok</button></p>
</form>

</div>
</body>
</html>
4 changes: 2 additions & 2 deletions rserve
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ local NO_COLOUR="\033[0m"

N=`ps -ef | grep Rserve | wc -l`
if [ "$N" -lt 2 ]; then
echo "Rserve is ${RED}down${NO_COLOUR}.";
echo -e "Rserve is ${RED}down${NO_COLOUR}.";
else
echo "Rserve is ${GREEN}up${NO_COLOUR}.";
echo -e "Rserve is ${GREEN}up${NO_COLOUR}.";
fi
}

Expand Down
2 changes: 1 addition & 1 deletion tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CREATE TABLE proibido (
id_proibido int(10) PRIMARY KEY AUTO_INCREMENT,
palavra VARCHAR(200),
id_exercicio INT(10),
hard BIT(1),
hard BIT(1) DEFAULT 0,
INDEX (id_exercicio),
FOREIGN KEY (id_exercicio) REFERENCES exercicio (id_exercicio)
) ENGINE=INNODB;
Expand Down

0 comments on commit 9c49a43

Please sign in to comment.