<?php
include_once '../classes/relatorio.php';

class Pontuacoes extends Relatorio {
    
    public function __construct() {
        parent::checarPermissao(array('administrador', 'editarequipes', 'elaboradorquestoes'));
        parent::__construct();
    }
    
    public function filtro() {
        echo "<fieldset><legend>Filtro</legend>";
        echo "<table align='center'>";
        $prova_id = (isset($_REQUEST[prova_id]))? $_REQUEST[prova_id] : $_SESSION[prova_id];
        echo "<tr style='display:block'><td>";
        echo "Prova: ";parent::selectProva($prova_id, true, null, "1=1");
        echo "</td></tr>";
        echo "<tr style='display:block'><td>";
        echo "Fase: ";parent::montaSelect('fase', array('1', '2', '3', '4', '5', '6'), $_REQUEST[fase], true);
        echo "</td></tr>";
        echo "</table>";
        echo "</fieldset>";
    }

    public function conteudo(){
        $bd = new BD();
        
        $sql = "SELECT questao.numero AS questao, alternativa.letra, count(alternativa_id) AS pontuacao "
                . "FROM imediaco_geo.resposta "
                . "INNER JOIN imediaco_geo.questao ON (resposta.questao_id = questao.id) "
                . "INNER JOIN imediaco_geo.alternativa ON (resposta.alternativa_id = alternativa.id) "
                . "INNER JOIN imediaco_geo.provafase ON (questao.provafase_id = provafase.id) "
                . "WHERE provafase.prova_id = $_REQUEST[prova_id] AND provafase.fase = '$_REQUEST[fase]' "
                . "GROUP BY alternativa_id "
                . "ORDER BY questao, letra";
        $bd->executarSQL($sql);
        
        echo "<table class='tabelaDados'>";
        echo "<tr>";
        echo "<th>Questão Nº</th>";
        echo "<th>Alternativa</th>";
        echo "<th>Pontuação</th>";
        
        echo "</tr>";
        $i = 0;
        while($obj = $bd->getObjeto()){
            echo "<tr>";
            echo "<td>$obj->questao</td>";
            echo "<td>$obj->letra</td>";
            echo "<td>$obj->pontuacao</td>";
            
            echo "</tr>";
            $i++;
        }
        echo "</table>";
    }
}

$pagina = new Pontuacoes();
$pagina->montar();
