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

Commit

Permalink
Merge branch 'master' into releases
Browse files Browse the repository at this point in the history
  • Loading branch information
andrechalom committed Feb 11, 2016
2 parents d69ddc9 + 37f9979 commit 4a41c6a
Show file tree
Hide file tree
Showing 33 changed files with 422 additions and 1,355 deletions.
3 changes: 3 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ http://creativecommons.org/licenses/by/3.0/br/deed.en_US

This work uses code from:

Rserve
rserve-php - php interface to R by Cl�ment Turbelin, Simon Urbanek
jQuery
jQuery datepicker extension by Trent Richardson
jQuery latex by Andreas Grech
Bootstrap

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ Para instalar uma nova plataforma notaR, siga os passos descritos na wiki acima.
*NOTE* que a versão atual no Github é uma versão de desenvolvimento (ou seja, warnings e erros são
mostrados sem filtros ao usuário), enquanto versões na página
de [Releases] (https://github.com/lageIBUSP/notaR/releases) são adequadas para produção.

**Importante:** se você está fazendo clone a partir do Github, lembre-se de executar os seguintes comandos de dentro
do diretório clonado:
```
git submodule init
git submodule update
```


7 changes: 4 additions & 3 deletions html/aluno.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php require('head.php');
if (! $USER->admin()) {
echo "Acesso negado";
echo "<p class='alert alert-danger'>Acesso negado</p>";
exit;
}
require('menu.php');
if(! isset($_REQUEST['id'])) {
echo "<p>Erro interno!</p></div></body></html>";
echo "<p class='alert alert-danger'>Erro interno!</p></div></body></html>";
exit;
}
$aluno = new Aluno($_REQUEST['id']);
Expand All @@ -20,7 +21,7 @@
<br>Turma: <?php echo SelectTurma(false); ?>
<br><label><input type="checkbox" name="admin" value="1"
<?php if ($aluno->admin()) echo "checked"; ?>
/> Admin</label>
/><span class='glyphicon glyphicon-education' style='padding-left: 5px;'></span> Admin</label>
<br>
<button type='submit' name='submit' value='altera'>Alterar</button>

Expand Down
36 changes: 21 additions & 15 deletions html/alunos.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
require("head.php");
if (! $USER->admin()) {
echo "Acesso negado";
echo "<p class='alert alert-danger'>Acesso negado</p>";
exit;
}
require('menu.php');

###### Codigo aqui
if(isset($_POST['submit']) AND $_POST['submit']=="altera") {
Expand All @@ -14,35 +15,40 @@
if(isset($_POST['submit']) AND $_POST['submit']=="insere") {
$arr=preg_split("/\r\n|\r|\n/",$_POST['novos']);
$senha = $_POST['senha'];
if (empty($senha)) { echo "<p>Voc&ecirc; deve informar uma senha!</p>";}
if (empty($senha)) { echo "<p class='alert alert-danger'>Voc&ecirc; deve informar uma senha!</p>";}
else {
foreach ($arr as $novo) {
$aluno = new Aluno();
echo $aluno->create($novo, $TURMA, $senha)."<br>";
echo $aluno->create(trim($novo), $TURMA, $senha)."<br>";
}
}
}
?>
<h2>Cadastro de alunos</h2>
<p>Escolha a turma</p>
<form action='alunos.php' method='POST'>
<?php echo SelectTurma(); ?>
<div class='form-group'>
<label>Escolha a turma:</label><?php echo SelectTurma(); ?>
</div>

<p>Alunos cadastrados:</p>
<table><tr><td>Admin</td><td>Login</td><td>Notas</td><td>Editar</td>
<div class='form-group'>
<label>Alunos cadastrados:</label>
<table style='width:100%'><tr><th>Admin</th><th>Login</th><th>Notas</th><th>Editar</th>
<?php
foreach (ListAlunos($TURMA) as $aluno) {
echo "<tr><td>";
if ($aluno->admin()) echo "<img src='img/check.png'>"; else echo "&nbsp;";
echo "</td><td>".$aluno->getNome()."</td><td>".$aluno->numNotas()."</td><td>";
echo "<a href='aluno.php?id=".$aluno->getId()."'><img src='img/pen.png'></a></td></tr>";
echo "<tr><td align='center'>";
if ($aluno->admin()) echo "<span class='glyphicon glyphicon-education'></span>"; else echo "&nbsp;";
echo "</td><td>".$aluno->getNome()."</td><td>".$aluno->numNotas()."</td><td align='center'>";
echo "<a href='aluno.php?id=".$aluno->getId()."'><span class='glyphicon glyphicon-cog'></span></a></td></tr>";
}
?>
</table>
</table>
</div>
<p>Para cadastrar novos alunos nesta turma, preencha os logins na caixa de texto abaixo, um por linha:</p>
<textarea name="novos" rows=5 cols=70>
</textarea>
<p>Senha: <input type="text" name="senha">
<textarea name="novos" rows=5 class='form-control'> </textarea>
<div class='form-group'>
<label>Senha:</label>
<input type="text" name="senha" class='form-control'>
</div>
<br><button type='submit' name='submit' value='insere'>Inserir</button></p>

</form>
Expand Down
69 changes: 69 additions & 0 deletions html/arquivos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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 arquivos de dados</h2>
<?php
if (isset($_REQUEST['delete'])) {
$file = $_REQUEST['delete'];
if(emUso($file)) {
echo "<p class='alert alert-danger'>O arquivo parece estar em uso por um ou mais exerc&iacute;cios!</p>";
} else if(strpos($file, '/') or strpos($file, '\\')) {
echo "<p class='alert alert-danger'>Caracter inv&aacute;lido no nome do arquivo!</p>";
} else {
unlink($BASEDIR."/files/".$file);
echo "<p class='alert alert-success'>Arquivo removido</p>";
}
}
if(isset($_REQUEST['submit'])) {
if (empty($_FILES['rfile']["name"])) {
echo "<p class='alert alert-danger'>Nenhum arquivo recebido. Verifique se houve algum problema no upload.</p>";
} else {
move_uploaded_file($_FILES['rfile']['tmp_name'], $BASEDIR."/files/".basename($_FILES['rfile']['name']));
echo "<p class='alert alert-success'>Envio completo</p>";
}

}
function emUso($file) {
global $mysqli;
$file = "%$file%";
$res = $mysqli->prepare("SELECT count(*) FROM
(SELECT id_exercicio FROM exercicio WHERE precondicoes LIKE ?
UNION ALL
SELECT id_exercicio FROM teste WHERE condicao LIKE ?) AS x");
$res->bind_param('ss', $file, $file);
$res->execute();
$res->bind_result($n_uso);
$res->fetch();
return($n_uso > 0);
}
?>
<p>Arquivos cadastrados:</p>
<table><tr><th colspan=2>Nome</th><th>Em uso</th></tr>
<?php
foreach (glob($BASEDIR."/files/*") as $file) {
$file = basename($file);
echo "<tr><td><a href='?delete=".$file."'><span class='glyphicon glyphicon-remove'></span></a></td><td>".$file."</td><td align='center'>";
if(emUso($file)) echo "<span class='glyphicon glyphicon-file'></span>";
echo "</td></tr>";
}
?>
</table>
<p>&nbsp;</p>
<form name="cadastro" action="?" method="post" enctype='multipart/form-data'>
<span class="btn btn-success fileinput-button" id="fakerfile">
<i class="glyphicon glyphicon-file"></i>
<span>Submeter novo arquivo</span>
</span>
<input type="file" name="rfile" id="rfile" accept=".txt,.csv,.rdata,.rda" style="display:none;">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
<button name="submit" id="submit" type="submit" value="Submit" style="display: none;">Submeter!</button>
</form>
<p>&nbsp;</p>

</div>
</body>
</html>
45 changes: 39 additions & 6 deletions html/cadastra.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_once("head.php");
### comeca aqui
if (! $USER->admin()) {
echo "Acesso negado";
echo "<p class= 'alert alert-danger'>Acesso negado</p>";
exit;
}
if (isset($_REQUEST['exerc']))
Expand Down Expand Up @@ -33,6 +33,28 @@
$nimp++;
}

# Codigo de reordenacao de testes
$condicao = $_REQUEST['condicao'];
$peso = $_REQUEST['peso'];
$dica = $_REQUEST['dica'];
$TROCA=-2;
if (isset($_REQUEST['down']))
$TROCA = $_REQUEST['down'];
if (isset($_REQUEST['up']))
$TROCA = $_REQUEST['up'] - 1;

if($TROCA >= 0) {
$tmp = $condicao[$TROCA+1];
$condicao[$TROCA+1] = $condicao[$TROCA];
$condicao[$TROCA] = $tmp;
$tmp = $dica[$TROCA+1];
$dica[$TROCA+1] = $dica[$TROCA];
$dica[$TROCA] = $tmp;
$tmp = $peso[$TROCA+1];
$peso[$TROCA+1] = $peso[$TROCA];
$peso[$TROCA] = $tmp;
}

?>
<h2>Cadastro de exerc&iacute;cios</h2>
<?php
Expand Down Expand Up @@ -83,22 +105,33 @@
for ($i = 0; $i < $ntestes; $i ++) {
if (!empty($id)) {$T = new Teste($id, $i+1);}
echo "<tr>";
echo "<td><center>".($i+1)."</center></td>";
echo "<td>";
if($i > 0)
echo "<button class='btn btn-default' type='submit' name='up' value=$i style='width:20px; padding:0px; border:none;'>
<span class='glyphicon glyphicon-chevron-up'></span></button>";
else
echo "<button class='btn btn-default' style='width:20px; padding:0px; border:none;' disabled>&nbsp;</button>";
echo ($i+1);
if($i == $ntestes - 1)
echo "<button class='btn btn-default' style='width:20px; padding:0px; border:none;' disabled>&nbsp;</button>";
else
echo "<button class='btn btn-default' type='submit' name='down' value=$i style='width:20px; padding:0px; border:none;'>
<span class='glyphicon glyphicon-chevron-down'></span></button>";
echo"</td>";
echo "<td><input type='text' name='peso[]' value='";
if (isset($_POST['peso'][$i])) {echo $_POST['peso'][$i];}
if (isset($peso[$i])) {echo $peso[$i];}
elseif (!empty($id) AND $T->peso()) echo $T->peso();
else {echo 1;}
echo "'></td><td><input class='long' type='text' name='condicao[]' value=\"";
if (isset($_POST['condicao'][$i])) {echo htmlspecialchars($_POST['condicao'][$i]);}
if (isset($condicao[$i])) {echo htmlspecialchars($condicao[$i]);}
elseif (!empty($id)) echo htmlspecialchars($T->condicao());
echo "\"></td><td><input class='long' type='text' name='dica[]' value=\"";
if (isset($_POST['dica'][$i])) {echo htmlspecialchars($_POST['dica'][$i]);}
if (isset($dica[$i])) {echo htmlspecialchars($dica[$i]);}
elseif (!empty($id)) echo htmlspecialchars($T->dica());
echo "\"></td></tr>";
}
echo "</table>";


echo "<button type=\"submit\" name=\"submit\" value=\"submit\">OK</button>";
echo "</form>";
}
Expand Down
13 changes: 7 additions & 6 deletions html/class/aluno.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ public function __construct($id=null) {
}
public function create($nome, $turma, $senha) {
global $mysqli;
if ($nome == " ") return;
if (strlen($nome) < 4)
return "O nome $nome &eacute; muito curto. Crie usu&aacute;rios com no m&iacute;nimo 4 caracteres";
return "<p class='alert alert-warning'>O nome $nome &eacute; muito curto. Crie usu&aacute;rios com no m&iacute;nimo 4 caracteres</p>";
$res = $mysqli->prepare("INSERT INTO aluno (nome_aluno, id_turma, senha) VALUES (?, ?, SHA1(?))");
$res->bind_param('sis', $nome, $turma->getId(), $senha);
$res->execute();
if ($mysqli->error) return "Houve um erro ao inserir o aluno $nome!";
else return "Aluno $nome inserido com sucesso";
if ($mysqli->error) return "<p class='alert alert-danger'>Houve um erro ao inserir o aluno $nome!</p>";
else return "<p class='alert alert-success'>Aluno $nome inserido com sucesso</p>";
}
public function getNome() {return $this->nome;}
public function getId() { return $this->id; }
Expand All @@ -41,7 +42,7 @@ public function numNotas() {
public function altera($nome, $admin, $turma, $senha) {
global $mysqli;
if (strlen($nome) < 4)
return "O nome $nome &eacute; muito curto. Crie usu&aacute;rios com no m&iacute;nimo 4 caracteres";
return "<p class='alert alert-warning'>O nome $nome &eacute; muito curto. Crie usu&aacute;rios com no m&iacute;nimo 4 caracteres</p>";
if ($senha) {
$res = $mysqli->prepare("UPDATE aluno set nome_aluno=?, admin=?, id_turma=?, senha=SHA1(?) WHERE id_aluno=?");
$res->bind_param('siisi', $nome, $admin, $turma->getId(), $senha, $this->id);
Expand All @@ -50,8 +51,8 @@ public function altera($nome, $admin, $turma, $senha) {
$res->bind_param('siii', $nome, $admin, $turma->getId(), $this->id);
}
$res->execute();
if (! $mysqli->error) return "Altera&ccedil;&otilde;es feitas com sucesso";
else return "N&atilde;o foi poss&iacute;vel realizar as altera&ccedil;&otilde;es!";
if (! $mysqli->error) return "<p class='alert alert-success'>Altera&ccedil;&otilde;es feitas com sucesso</p>";
else return "<p class='alert alert-danger'>N&atilde;o foi poss&iacute;vel realizar as altera&ccedil;&otilde;es!</p>";
}
}

Expand Down
16 changes: 8 additions & 8 deletions html/class/exercicio.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function create($precondicoes, $html, $nome, $testes) {
VALUES (REPLACE(?, CHAR(13), ''), ?, ?)");
$res->bind_param('sss', $precondicoes, $html, $nome);
$res->execute();
if ($mysqli->error) return "Erro ao cadastrar o exerc&iacute;cio!";
if ($mysqli->error) return "<p class='alert alert-danger'>Erro ao cadastrar o exerc&iacute;cio!</p>";
$this->id = $mysqli->insert_id;
return $this->cadastraTestes($testes, "Exerc&iacute;cio criado");
return $this->cadastraTestes($testes, "<p class='alert alert-success'>Exerc&iacute;cio criado.");
}
public function cadastraTestes($testes, $msg) { // E impedimentos, por preguiça do programador
global $mysqli;
Expand All @@ -62,8 +62,8 @@ public function cadastraTestes($testes, $msg) { // E impedimentos, por preguiça
$ok = $ok AND $T->create($this->id, $j, $testes[0][$i], $testes[1][$i],$testes[2][$i]);
}
}
if (! $ok) $msg .= "<p>Falha ao cadastrar os testes!</p>";
else $msg .= " com $c testes. ";
if (! $ok) $msg .= "</p><p class='alert alert-danger'>Falha ao cadastrar os testes!</p>";
else $msg .= " com $c testes. </p>";

$res = $mysqli->prepare("DELETE FROM proibido WHERE id_exercicio=?");
$res->bind_param('i', $this->id);
Expand All @@ -76,7 +76,7 @@ public function cadastraTestes($testes, $msg) { // E impedimentos, por preguiça
$ok = $ok AND $T->create($testes[3][$i], $this->id);
}
}
if (! $ok) $msg .= "<p>Falha ao cadastrar os impedimentos!</p>";
if (! $ok) $msg .= "<p class='alert alert-danger'>Falha ao cadastrar os impedimentos!</p>";

$msg .= "Pr&oacute;ximos passos: <ul>
<li><a href='exercicio.php?exerc=$this->id'>Teste</a> se a corre&ccedil;&atilde;o funciona</li><li><a href='cadastra.php?exerc=$this->id'>Edite</a> as defini&ccedil;&otilde;es deste exerc&iacute;cio</li><li>Determine o <a href='prazos.php'>prazo</a> de entrega</li></ul>";
Expand All @@ -88,8 +88,8 @@ public function altera ($precondicoes, $html, $nome, $testes) {
precondicoes = REPLACE(?, CHAR(13), ''), html=?, nome=? WHERE id_exercicio=?");
$res->bind_param('sssi', $precondicoes, $html, $nome, $this->id);
$res->execute();
if ($mysqli->error) return "Erro ao alterar o exerc&iacute;cio!";
return $this->cadastraTestes($testes, "Exerc&iacute;cio alterado");
if ($mysqli->error) return "<p class='alert alert-danger'>Erro ao alterar o exerc&iacute;cio!</p>";
return $this->cadastraTestes($testes, "<p class='alert alert-success'>Exerc&iacute;cio alterado");
}
public function getNome() {return $this->nome;}
public function getHtml() {return $this->html;}
Expand Down Expand Up @@ -184,7 +184,7 @@ function ListExercicio($turma = null, $reverse = false) {
function SelectExercicio () {
global $EXERCICIO;
global $TURMA;
$T = "<select id='exercicio' name='exercicio'>";
$T = "<select id='exercicio' name='exercicio' class='form-control'>";
$T .= "<option value='".MIN_EX."'>---- Exerc&iacute;cios obrigat&oacute;rios ----</option>";
foreach (ListExercicio($TURMA) as $exercicio) {
$T .="<option value='".$exercicio->getId()."'";
Expand Down
Loading

0 comments on commit 4a41c6a

Please sign in to comment.