Ejemplo n.º 1
0
 public function __construct($testId, $password)
 {
     $this->user = UserSession::getInstance()->getUser();
     $this->testId = $testId;
     $this->password = $password;
     $tprbBS = new TestProblemsBS(null);
     $qbuilder = new QueryBuilder('testproblems');
     $qbuilder->addEqual("tpb_tst_id", $testId);
     $qbuilder->addOrder("tpb_questionNumber", QueryBuilder::$ASC);
     $this->problems = $tprbBS->findNotDeleted($qbuilder);
     $testBS = new TestBS(null);
     $qbuilder = new QueryBuilder('test');
     $qbuilder->addEqual("tst_id", $testId);
     $qbuilder->addEqual("tst_password", $password);
     $tests = $testBS->findNotDeleted($qbuilder);
     if (count($tests) < 1) {
         die("<h3>ACESSO NEGADO</h3>");
     }
     $this->test = $tests[0];
     $ttrialBS = new TestTrialBS(null);
     $ttrialBS->createUserTrials($this->problems);
     $qbuilder = new QueryBuilder('testtrial');
     $qbuilder->addEqual("ttl_tst_id", $testId);
     $qbuilder->addEqual("ttl_usr_id", $this->user->get('usr_id'));
     $trials = $ttrialBS->findNotDeleted($qbuilder);
     $this->trials = array();
     if (count($trials) > 0) {
         foreach ($trials as $t => $trial) {
             $this->trials[$trial->get('ttl_prb_id')] = $trial;
         }
     }
     // Gravando log
     if ($this->test->get("tst_enableLogging") != 0) {
         $testBS->logAction($this->user->get('usr_id'), $this->testId, "Usuário abriu a prova.");
     }
 }
<?php

if (!isset($_POST['_action'])) {
    header("Location: ../");
    die;
}
include "./TestProblemsBS.php";
include "./UserSession.php";
$tproblemsBS = new TestProblemsBS($_POST);
if ($_POST['_action'] == 'save') {
    $status = $tproblemsBS->save();
    if ($status) {
        header("Location: ../testProblems.php?tpb_tst_id=" . $_POST['tpb_tst_id']);
    } else {
        die("Um erro inesperado ocorreu.");
    }
} else {
    if ($_POST['_action'] == 'update') {
        $status = $tproblemsBS->update();
        if ($status) {
            header("Location: ../testProblems.php?tpb_tst_id=" . $_POST['tpb_tst_id']);
        } else {
            die("Um erro inesperado ocorreu.");
        }
    } else {
        if ($_POST['_action'] == 'delete') {
            $status = $tproblemsBS->delete();
            if ($status) {
                header("Location: ../testProblems.php?tpb_tst_id=" . $_POST['tpb_tst_id']);
            } else {
                die("Um erro inesperado ocorreu.");
Ejemplo n.º 3
0
include "controller/UserSession.php";
$session = UserSession::getInstance();
if ($session->getAccessLevel() < 3) {
    die("Forbidden.");
} else {
    if (!isset($_GET['tpb_tst_id'])) {
        die("Forbidden.");
    }
}
$testSelected = $_GET['tpb_tst_id'];
include "./controller/TestProblemsBS.php";
include "./controller/TestTrialBS.php";
header("Conten-Type: text/csv");
header('Content-Disposition:  attachment; filename="notas.csv";');
$bs = new TestProblemsBS(null);
if (!isset($testSelected) || $testSelected == "") {
    die("Nenhuma prova selecionada.");
} else {
    $qbuilder = new QueryBuilder('testproblems');
    $qbuilder->addEqual('tpb_tst_id', $testSelected);
    $qbuilder->addOrder('tpb_questionNumber', QueryBuilder::$ASC);
    $qbuilder->addOrder('prb_title', QueryBuilder::$ASC, "problem");
    $tproblems = $bs->findNotDeleted($qbuilder);
}
$nProblems = count($tproblems);
if ($nProblems <= 0) {
    die("Nenhum problema nesta prova.");
} else {
    $test = $tproblems[0]->getForeignModel('tpb_tst_id');
    $problemWeights = array();
Ejemplo n.º 4
0
 public function save()
 {
     if (UserSession::getInstance()->isLogged() !== true) {
         die("<h1>Forbidden resource for you.</h1>");
     }
     $model = new TestTrial();
     $model->setFields($this->params);
     $model->set('ttl_usr_id', UserSession::getInstance()->getUser()->get('usr_id'));
     $existent = $this->retrieve($model);
     $tproblemBS = new TestProblemsBS(null);
     $qbuilder = new QueryBuilder("testproblems");
     $qbuilder->addEqual("tpb_prb_id", $existent->get("ttl_prb_id"));
     $qbuilder->addEqual("tpb_tst_id", $existent->get("ttl_tst_id"));
     $tprobs = $tproblemBS->findNotDeleted($qbuilder);
     if (count($tprobs) < 1) {
         die("Invalid request.");
     }
     $tprob = $tprobs[0];
     $today = new DateTime('now');
     $model->set('ttl_lastTrial', $today->format(Model::$SQL_DATE_FORMAT));
     $model->set('ttl_remoteAddr', $_SERVER['REMOTE_ADDR']);
     $output = array();
     $status = 0;
     $text = exec("algoddecrypter " . $model->get('ttl_code'), $output, $status);
     //echo $text;
     $countTrial = true;
     $nTrials = $existent->get("ttl_trials");
     $attenuation = $existent->getForeignModel("ttl_tst_id")->get("tst_scoreAttenuationPerTrial");
     //echo "Att: ".$attenuation;
     //die("<br />Trials: ".$nTrials);
     if ($status != 0) {
         $countTrial = false;
         $model->set("ttl_score", "0");
         $model->set("ttl_hostname", "N/A");
         $model->set("ttl_reason", "<i>Código do corretor submetido foi inválido.</i>");
     } else {
         $mat = "";
         $host = "";
         $question = "";
         $nota = "";
         sscanf($output[0], "%s\t%s\t%d\t%d", $mat, $host, $question, $nota);
         if ($mat == UserSession::getInstance()->getUser()->get('usr_matricula')) {
             if ($question == $tprob->get("tpb_questionNumber")) {
                 $notaAttenuated = $nota * pow($attenuation, $nTrials);
                 //die("Nota: ".$notaAttenuated);
                 $model->set("ttl_score", $notaAttenuated);
                 $model->set("ttl_hostname", $host);
                 $model->set("ttl_reason", "Avaliado pelo corretor.");
             } else {
                 $countTrial = false;
                 $model->set("ttl_score", "0");
                 $model->set("ttl_hostname", $host);
                 $model->set("ttl_reason", "<i>O número da questão no código do corretor não corresponde à esta questão.</i>");
             }
         } else {
             $countTrial = false;
             $model->set("ttl_score", "0");
             $model->set("ttl_hostname", $host);
             $model->set("ttl_reason", "<i>A matrícula passada ao corretor não corresponde à matrícula de seu usuário.</i>");
         }
     }
     $model->set("ttl_sourcefile", mysql_real_escape_string($model->get("ttl_sourcefile")));
     $test = $existent->getForeignModel("ttl_tst_id");
     if ($test->get("tst_enableLogging") != 0) {
         $testBS = new TestBS(null);
         $testBS->logAction(UserSession::getInstance()->getUser()->get('usr_id'), $test->get('tst_id'), "Sumetida tentativa: " . $model->get('ttl_reason') . "\n" . $model->get('ttl_sourcefile'), $model->get('ttl_hostname'), $tprob->get("tpb_questionNumber"), $model->get('ttl_score'));
     }
     @($dao = new DAO(TestTrial));
     if ($countTrial === true) {
         $model->set("ttl_trials", $existent->get("ttl_trials") + 1);
     } else {
         $model->set("ttl_trials", $existent->get("ttl_trials"));
     }
     $status = $dao->update($model);
     if ($status !== true) {
         die("Um erro ocorreu ao tentar cadastrar o usuário, favor contatar um professor:<br />" . $status);
     }
     return true;
 }
Ejemplo n.º 5
0
        public function render($testSelected = null)
        {
            $bs = new TestProblemsBS(null);
            if (!isset($testSelected) || $testSelected == "") {
                echo "<i>Nenhuma prova selecionada.</i>";
                return;
            } else {
                $qbuilder = new QueryBuilder('testproblems');
                $qbuilder->addEqual('tpb_tst_id', $testSelected);
                $qbuilder->addOrder('tpb_questionNumber', QueryBuilder::$ASC);
                $qbuilder->addOrder('prb_title', QueryBuilder::$ASC, "problem");
                $tproblems = $bs->findNotDeleted($qbuilder);
            }
            $nProblems = count($tproblems);
            if ($nProblems <= 0) {
                ?>
					<br/><i>Nenhum problema anexado à esta prova ainda.</i><br />
				<?php 
            } else {
                $test = $tproblems[0]->getForeignModel('tpb_tst_id');
                $problemWeights = array();
                $maxGradeSum = 0.0;
                foreach ($tproblems as $tp => $tproblem) {
                    if (!isset($problemWeights[$tproblem->get('tpb_prb_id')])) {
                        $problemWeights[$tproblem->get('tpb_prb_id')] = 0;
                    }
                    $problemWeights[$tproblem->get('tpb_prb_id')] += $tproblem->get('tpb_weight');
                    $maxGradeSum += 100.0 * $tproblem->get('tpb_weight');
                }
                $qbuilder = new QueryBuilder('testtrial');
                $qbuilder->addEqual('ttl_tst_id', $testSelected);
                $qbuilder->addOrder('usr_name', QueryBuilder::$ASC, "user");
                $qbuilder->addOrder('usr_matricula', QueryBuilder::$ASC, "user");
                $qbuilder->addOrder('ttl_usr_id', QueryBuilder::$ASC);
                $bs = new TestTrialBS(null);
                $ttrials = $bs->findNotDeleted($qbuilder);
                $userGrades = array();
                $lastId = -1;
                $lastPos = -1;
                $averageScore = 0.0;
                foreach ($ttrials as $tt => $ttrial) {
                    if ($lastId != $ttrial->get('ttl_usr_id')) {
                        $lastId = $ttrial->get('ttl_usr_id');
                        $lastPos++;
                    }
                    if (!isset($userGrades[$lastPos])) {
                        $userGrades[$lastPos] = array();
                        $userGrades[$lastPos]['matricula'] = $ttrial->getForeignModel("ttl_usr_id")->get("usr_matricula");
                        $userGrades[$lastPos]['name'] = $ttrial->getForeignModel("ttl_usr_id")->get("usr_name");
                        $userGrades[$lastPos]['totalScore'] = 0.0;
                        $userGrades[$lastPos]['totalSubmitted'] = 0;
                    }
                    if (strlen($ttrial->get("ttl_sourcefile")) > 50) {
                        $userGrades[$lastPos]['totalSubmitted']++;
                    }
                    $userGrades[$lastPos]['totalScore'] += $ttrial->get('ttl_score') * $problemWeights[$ttrial->get('ttl_prb_id')];
                    $averageScore += $ttrial->get('ttl_score') * $problemWeights[$ttrial->get('ttl_prb_id')];
                }
                $nAlunos = count($userGrades);
                if ($nAlunos > 0) {
                    $averageScore /= $nAlunos;
                }
                ?>
					<br />
					<h3><?php 
                echo $test->get('tst_title');
                ?>
</h3>
					<b>Número de Questões:</b> <?php 
                echo $nProblems;
                ?>
<br />
					<b>Acumulado Máximo:</b> <?php 
                echo $maxGradeSum;
                ?>
<br />
					<b>Média do Acumulado:</b> <?php 
                echo $averageScore;
                ?>
<br />
					<b>Média da Nota Final:</b> <?php 
                echo 100 * $averageScore / $maxGradeSum;
                ?>
<br />
					<b>Número de Alunos:</b> <?php 
                echo $nAlunos;
                ?>
<br />
					<table class="dataView">
					<tr>
						<th>Matrícula</th>
						<th>Nome do Aluno</th>
						<th>Nota Acumulada</th>
						<th>Nota Final</th>
						<th>Questões Entregues</th>
						<th>Nota pela Entrega</th>
					</tr>
					<?php 
                foreach ($userGrades as $ug => $userGrade) {
                    ?>
						<tr class="color<?php 
                    echo $ug % 2;
                    ?>
">
							<td><?php 
                    echo $userGrade['matricula'];
                    ?>
</td>
							<td><?php 
                    echo $userGrade['name'];
                    ?>
</td>
							<td><?php 
                    echo $userGrade['totalScore'];
                    ?>
</td>
							<td><?php 
                    echo 100 * $userGrade['totalScore'] / $maxGradeSum;
                    ?>
%</td>
							<td><?php 
                    echo $userGrade["totalSubmitted"];
                    ?>
</td>
							<td><?php 
                    echo 100.0 * $userGrade["totalSubmitted"] / $nProblems;
                    ?>
%</td>
						</tr>
					<?php 
                }
                ?>
				</table>
				<?php 
            }
        }
Ejemplo n.º 6
0
        public function renderNotDeleted($testSelected = null)
        {
            $bs = new TestProblemsBS(null);
            if (!isset($testSelected) || $testSelected == "") {
                $tproblems = $bs->findNotDeleted(null);
            } else {
                $qbuilder = new QueryBuilder('testproblems');
                $qbuilder->addEqual('tpb_tst_id', $testSelected);
                $qbuilder->addOrder('tpb_questionNumber', QueryBuilder::$ASC);
                $qbuilder->addOrder('prb_title', QueryBuilder::$ASC, "problem");
                $tproblems = $bs->findNotDeleted($qbuilder);
            }
            if (count($tproblems) <= 0) {
                ?>
					<br/><i>Nenhum problema anexado à esta prova ainda.</i><br />
				<?php 
            } else {
                ?>
					<script type="text/javascript">
					function deleteTestProblem(testId, probId) {
						if (confirm("Deseja realmente desanexar este problema?")) {
							$("#tproblems-action-form input[name='_action']").val("delete");
							$("#tproblems-action-form input[name='tpb_tst_id']").val(testId);
							$("#tproblems-action-form input[name='tpb_prb_id']").val(probId);
							$("#tproblems-action-form").submit();
						}
					}
					</script>
					<form method="POST" action="./controller/TestProblemsController.php" style="display:none;"
					id="tproblems-action-form">
						<input type="hidden" name="_action" />
						<input type="hidden" name="tpb_tst_id" />
						<input type="hidden" name="tpb_prb_id" />
					</form>
					<table class="dataView">
					<tr>
						<th>Prova</th>
						<th>Nº da Questão</th>
						<th>Problema</th>
						<th>Nível de Dificuldade</th>
						<th>Peso</th>
						<th style="min-width: 60px;width: 60px;max-width: 60px;">Ações</th>
					</tr>
					<?php 
                foreach ($tproblems as $tp => $tproblem) {
                    ?>
						<tr class="color<?php 
                    echo $tp % 2;
                    ?>
">
							<td><?php 
                    echo $tproblem->getForeignModel('tpb_tst_id')->get('tst_title');
                    ?>
</td>
							<td><?php 
                    echo $tproblem->get('tpb_questionNumber');
                    ?>
</td>
							<td><?php 
                    echo $tproblem->getForeignModel('tpb_prb_id')->get('prb_title');
                    ?>
</td>
							<td><?php 
                    echo $tproblem->getForeignModel('tpb_prb_id')->get('prb_difficultyLevel');
                    ?>
</td>
							<td><?php 
                    echo $tproblem->get('tpb_weight');
                    ?>
</td>
							<td class="actions">
								<span class="ui-state-default ui-corner-all" title="Editar Anexo de Questão"
								onClick="location.assign('./testProblemsEdit.php?tpb_tst_id=<?php 
                    echo $tproblem->get("tpb_tst_id");
                    ?>
&tpb_prb_id=<?php 
                    echo $tproblem->get('tpb_prb_id');
                    ?>
');">
									<span class="ui-icon ui-icon-pencil"></span>
								</span>
								<span class="ui-state-default ui-corner-all" title="Desanexar Problema"
								onClick="deleteTestProblem(<?php 
                    echo $tproblem->get('tpb_tst_id');
                    ?>
, <?php 
                    echo $tproblem->get('tpb_prb_id');
                    ?>
)">
									<span class="ui-icon ui-icon-trash"></span>
								</span>
							</td>
						</tr>
					<?php 
                }
                ?>
				</table>
				<?php 
            }
        }