Skip to content

Instantly share code, notes, and snippets.

@reginaldojunior
Created September 5, 2017 22:06
Show Gist options
  • Save reginaldojunior/c67a2a23ef8098b9f438bed8f591aee9 to your computer and use it in GitHub Desktop.
Save reginaldojunior/c67a2a23ef8098b9f438bed8f591aee9 to your computer and use it in GitHub Desktop.
teste.php
<?php include_once("../Connections/conexao.php"); ?>
<?php include_once("../Connections/acesso_professor.php"); ?>
<?php
//RETORNA O NOME DO ALUNO PARA MELHOR VISUALIZAÇÃO
$id = $_GET['id'];
$qrPega = mysql_query("SELECT * FROM table_aluno WHERE ID_ALUNO = '$id'");
while($ln = mysql_fetch_assoc($qrPega))
{
$nome = $ln['NOME'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/geral.css" />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<?php
//FUNÇÃO PARA COMANDO EXIBIR
//VARIAVEL $cont E UTILIZADA PARA O CONTROLE DE NOTAS CADASTRADAS NO BANCO POSSIVEL UTILIZAR ATE 10
//VERICAÇÂO PARA EXISTENCIA DA NOTA SENDO QUE A NOTA EXISTE SE ELE FOR > 0
//VARIAVEL $notafinal RECEBE A SOMA DE TODAS NOTAS VALIDAS
//VARIAVEL $notafinal2 RECEBE A MÉDIA DAS NOTAS
if($_GET['acao'] == "exibir")
{
$cont = 0;
$notafinal = '';
$qrPegaNotas = mysql_query("SELECT * FROM table_notas WHERE ID_ALUNO = '$id'");
if(mysql_num_rows($qrPegaNotas) != '0')
{
while($ln = mysql_fetch_assoc($qrPegaNotas))
{
if($ln['NOTA1'] > 0)
{
$n1Valida = $ln['NOTA1'];
$notafinal = $n1Valida;
$cont++;
}
if($ln['NOTA2'] > 0)
{
$n2Valida = $ln['NOTA2'];
$notafinal = $n1Valida+$n2Valida;
$cont++;
}
if($ln['NOTA3'] > 0)
{
$n3Valida = $ln['NOTA3'];
$notafinal = $n1Valida+$n2Valida+$n3Valida;
$cont++;
}
if($ln['NOTA4'] > 0)
{
$n4Valida = $ln['NOTA4'];
$notafinal = $n1Valida+$n2Valida+$n3Valida+$n4Valida;
$cont++;
}
if($ln['NOTA5'] > 0)
{
$n5Valida = $ln['NOTA5'];
$notafinal = $n1Valida+$n2Valida+$n3Valida+$n4Valida+$n5Valida;
$cont++;
}
if($ln['NOTA6'] > 0)
{
$n6Valida = $ln['NOTA6'];
$notafinal = $n1Valida+$n2Valida+$n3Valida+$n4Valida+$n5Valida+$n6Valida;
$cont++;
}
if($ln['NOTA7'] > 0)
{
$n7Valida = $ln['NOTA7'];
$notafinal = $n1Valida+$n2Valida+$n3Valida+$n4Valida+$n5Valida+$n6Valida+$n7Valida;
$cont++;
}
if($ln['NOTA8'] > 0)
{
$n8Valida = $ln['NOTA8'];
$notafinal = $n1Valida+$n2Valida+$n3Valida+$n4Valida+$n5Valida+$n6Valida+$n7Valida+$n8Valida;
$cont++;
}
if($ln['NOTA9'] > 0)
{
$n9Valida = $ln['NOTA9'];
$notafinal = $n1Valida+$n2Valida+$n3Valida+$n4Valida+$n5Valida+$n6Valida+$n7Valida+$n8Valida+$n9Valida;
$cont++;
}
if($ln['NOTA10'] > 0)
{
$n10Valida = $ln['NOTA10'];
$notafinal = $n1Valida+$n2Valida+$n3Valida+$n4Valida+$n5Valida+$n6Valida+$n7Valida+$n8Valida+$n9Valida+$n10Valida;
$cont++;
}
}
$notaFinal2 = $notafinal / $cont;
$AtualizarNotas = mysql_query("UPDATE table_notas SET
NOTA1 = '$n1Valida',
NOTA2 = '$n2Valida',
NOTA3 = '$n3Valida',
NOTA4 = '$n4Valida',
NOTA5 = '$n5Valida',
NOTA6 = '$n6Valida',
NOTA7 = '$n7Valida',
NOTA8 = '$n8Valida',
NOTA9 = '$n9Valida',
NOTA10 = '$n10Valida',
NOTA_FINAL = '$notaFinal2' WHERE ID_ALUNO = '$id'");
?>
<div id="conteudo">
<table>
<thead class="head">
<th>Nome Aluno</th>
<th>1ª Nota</th>
<th>2ª Nota</th>
<th>3ª Nota</th>
<th>4ª Nota</th>
<th>5ª Nota</th>
<th>6ª Nota</th>
<th>7ª Nota</th>
<th>8ª Nota</th>
<th>9ª Nota</th>
<th>10ª Nota</th>
<th>Nota Final</th>
</thead>
<tbody>
<tr class="body">
<td><?php echo $nome ?></td>
<td><?php echo $n1Valida ?></td>
<td><?php echo $n2Valida ?></td>
<td><?php echo $n3Valida ?></td>
<td><?php echo $n4Valida ?></td>
<td><?php echo $n5Valida ?></td>
<td><?php echo $n6Valida ?></td>
<td><?php echo $n7Valida ?></td>
<td><?php echo $n8Valida ?></td>
<td><?php echo $n9Valida ?></td>
<td><?php echo $n10Valida ?></td>
<td><?php echo $notaFinal2 ?></td>
</tr>
</tbody>
</table>
</div>
<?php
}
else
{
echo 'Não existe notas para o aluno '.$nome.' Cadastrado no sistema <br/>' ;
echo '<a href="notas_alunos.php">Voltar</a>';
}
}//FIM DO IF GET EXIBIR
?>
<?php
if($_GET['acao'] == "add")
{
$id_turma = $_GET['id_turma'];
$id_materia = $_GET['id_materia'];
?>
<div id="conteudo">
<table>
<thead class="head">
<th>Nome Aluno</th>
<th>1ª Nota</th>
<th>2ª Nota</th>
<th>3ª Nota</th>
<th>4ª Nota</th>
<th>5ª Nota</th>
<th>6ª Nota</th>
<th>7ª Nota</th>
<th>8ª Nota</th>
<th>9ª Nota</th>
<th>10ª Nota</th>
<th>Nota Final</th>
</thead>
<tbody>
<?php
$qrPega = mysql_query("SELECT * FROM table_notas WHERE ID_ALUNO = '$id' AND ID_MATERIA = '$id_materia'");
while($ln = mysql_fetch_assoc($qrPega))
{
$n1 = $ln['NOTA1'];
$n2 = $ln['NOTA2'];
$n3 = $ln['NOTA3'];
$n4 = $ln['NOTA4'];
$n5 = $ln['NOTA5'];
$n6 = $ln['NOTA6'];
$n7 = $ln['NOTA7'];
$n8 = $ln['NOTA8'];
$n9 = $ln['NOTA9'];
$n10 = $ln['NOTA10'];
$nFinal = $ln['NOTA_FINAL'];
}
?>
<form name="notas" method="post" action="funcao_notas.php?acao=addNotas&id=<?php echo $id ?>&id_materia=<?php echo $id_materia ?>&id_turma=<?php echo $id_turma ?>">
<tr class="body">
<td><?php echo $nome ?></td>
<td><input type="text" name="n1" maxlength="3" size="3" value="<?php echo $n1; ?>"/></td>
<td><input type="text" name="n2" maxlength="3" size="3" value="<?php echo $n2; ?>"/></td>
<td><input type="text" name="n3" maxlength="3" size="3" value="<?php echo $n3; ?>"/></td>
<td><input type="text" name="n4" maxlength="3" size="3" value="<?php echo $n4; ?>"/></td>
<td><input type="text" name="n5" maxlength="3" size="3" value="<?php echo $n5; ?>"/></td>
<td><input type="text" name="n6" maxlength="3" size="3" value="<?php echo $n6; ?>"/></td>
<td><input type="text" name="n7" maxlength="3" size="3" value="<?php echo $n7; ?>"/></td>
<td><input type="text" name="n8" maxlength="3" size="3" value="<?php echo $n8; ?>"/></td>
<td><input type="text" name="n9" maxlength="3" size="3" value="<?php echo $n9; ?>"/></td>
<td><input type="text" name="n10" maxlength="3" size="3" value="<?php echo $n10; ?>"/></td>
<td><?php echo $nFinal; ?></td>
</tr>
<tr valign="top" align="right">
<td colspan=12><input type="submit" id="botao"/></td>
</tr>
</form>
</tbody>
</table>
</div>
<a href="javascript:history.back(1)">Voltar</a>
<?php
}
?>
<?php
//AçÕES PARA ATUALIZAR E CADASTROS DE NOTA NA TABLE table_notas
//USANDO O ID_ALUNO COMO BASE DOS CADASTRO E ATUALIZAÇÃO DAs NOTAS
if($_GET['acao'] == "addNotas")
{
$id = $_GET['id'];
$id_turma = $_GET['id_turma'];
$id_materia = $_GET['id_materia'];
$n1 = $_POST['n1'];
$n2 = $_POST['n2'];
$n3 = $_POST['n3'];
$n4 = $_POST['n4'];
$n5 = $_POST['n5'];
$n6 = $_POST['n6'];
$n7 = $_POST['n7'];
$n8 = $_POST['n8'];
$n9 = $_POST['n9'];
$n10 = $_POST['n10'];
$cont = 0;
if($n1 > 0 && $n1 <= 10)
{
$nota1 = $n1;
$cont++;
}
if($n2 > 0 && $n2 <= 10)
{
$nota2 = $n2;
$cont++;
}
if($n3 > 0 && $n3 <= 10)
{
$nota3 = $n3;
$cont++;
}
if($n4 > 0 && $n4 <= 10)
{
$nota4 = $n4;
$cont++;
}
if($n5 > 0 && $n5 <= 10)
{
$nota5 = $n5;
$cont++;
}
if($n6 > 0 && $n6 <= 10)
{
$nota6 = $n6;
$cont++;
}
if($n7 > 0 && $n7 <= 10)
{
$nota7 = $n7;
$cont++;
}
if($n8 > 0 && $n8 <= 10)
{
$nota8 = $n8;
$cont++;
}
if($n9 > 0 && $n9 <= 10)
{
$nota9 = $n9;
$cont++;
}
if($n10 > 0 && $n10 <= 10)
{
$nota10 = $n10;
$cont++;
}
$notafinal = ($nota1+$nota2+$nota3+$nota4+$nota5+$nota6+$nota7+$nota8+$nota9+$nota10)/$cont;
$queryVerificar = mysql_query("SELECT * FROM table_notas WHERE ID_ALUNO = '$id' AND ID_MATERIA = '$id_materia'");
$queryVerificarNum = mysql_num_rows($queryVerificar);
if($queryVerificarNum != 0)
{
$atualizarNotas = mysql_query("UPDATE table_notas SET
NOTA1 = '$nota1',
NOTA2 = '$nota2',
NOTA3 = '$nota3',
NOTA4 = '$nota4',
NOTA5 = '$nota5',
NOTA6 = '$nota6',
NOTA7 = '$nota7',
NOTA8 = '$nota8',
NOTA9 = '$nota9',
NOTA10 = '$nota10',
NOTA_FINAL = '$notafinal' WHERE ID_ALUNO = '$id' AND ID_MATERIA = '$id_materia'");
echo "Notas Atualizadas com Sucesso ! <br/>";
echo '<a href="javascript:history.back(1)">Voltar</a>';
}
else
{
$cadadastraNotas = mysql_query("INSERT INTO table_notas
(ID_ALUNO,ID_PROFESSOR,ID_TURMA,ID_MATERIA,NOTA1,NOTA2,NOTA3,NOTA4,NOTA5,NOTA6,NOTA7,NOTA8,NOTA9,NOTA10,NOTA_FINAL)
VALUES ('$id','$userId','$id_turma','$id_materia','$nota1','$nota2','$nota3','$nota4','$nota5','$nota6','$nota7','$nota8','$nota9','$nota10','$notafinal')") or die(mysql_error());
echo "Notas cadastradas com Sucesso ! <br/>";
echo '<a href="javascript:history.back(1)">Voltar</a>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment