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 "./TestBS.php"; include "./UserSession.php"; $testBS = new TestBS($_POST); if ($_POST['_action'] == 'save') { $status = $testBS->save(); if ($status) { header("Location: ../tests.php"); } else { die("Um erro inesperado ocorreu."); } } else { if ($_POST['_action'] == 'delete') { $status = $testBS->delete(); if ($status) { header("Location: ../tests.php"); } else { die("Um erro inesperado ocorreu."); } } else { die("<b>Action especificada é inválida.</b>"); } } die;
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; }
public function renderNotDeleted($disciplineSelected = null) { $bs = new TestBS(null); if (!isset($disciplineSelected) || $disciplineSelected == "") { $tests = $bs->findNotDeleted(null); } else { $qbuilder = new QueryBuilder('test'); $qbuilder->addEqual('tst_dsc_id', $disciplineSelected); $qbuilder->addOrder('tst_openUntil', QueryBuilder::$DESC); $qbuilder->addOrder('tst_visibleUntil', QueryBuilder::$DESC); $qbuilder->addOrder('tst_createdAt', QueryBuilder::$DESC); $qbuilder->addOrder('tst_title', QueryBuilder::$ASC); $qbuilder->addOrder('tst_openSince', QueryBuilder::$DESC); $qbuilder->addOrder('tst_visibleSince', QueryBuilder::$DESC); $tests = $bs->findNotDeleted($qbuilder); } if (count($tests) <= 0) { ?> <br/><i>Nenhuma prova cadastrada ainda.</i><br /> <?php } else { ?> <script type="text/javascript"> function deleteTest(id) { if (confirm("Deseja realmente excluir esta prova?")) { $("#test-action-form input[name='_action']").val("delete"); $("#test-action-form input[name='tst_id']").val(id); $("#test-action-form").submit(); } } </script> <form method="POST" action="./controller/TestController.php" style="display:none;" id="test-action-form"> <input type="hidden" name="_action" /> <input type="hidden" name="tst_id" /> </form> <table class="dataView"> <tr> <th>Disciplina</th> <th>Título</th> <th>Visível de</th> <th>Visível até</th> <th>Aberta de</th> <th>Aberta até</th> <th>Nº de Questões</th> <th style="min-width:140px;width:140px;max-width:140px;">Ações</th> </tr> <?php foreach ($tests as $t => $test) { ?> <tr class="color<?php echo $t % 2; ?> "> <td><?php echo $test->getForeignModel('tst_dsc_id')->get('dsc_code'); ?> </td> <td><?php echo $test->get('tst_title'); ?> </td> <td><?php echo Model::parseSQLToInputDate($test->get('tst_visibleSince')); ?> </td> <td><?php echo Model::parseSQLToInputDate($test->get('tst_visibleUntil')); ?> </td> <td><?php echo Model::parseSQLToInputDate($test->get('tst_openSince')); ?> </td> <td><?php echo Model::parseSQLToInputDate($test->get('tst_openUntil')); ?> </td> <?php $questions = $test->getMetaField("tst_numberOfQuestions"); if (!isset($questions) || $questions < 1) { ?> <td style="background:#ff8888;"><?php } else { ?> <td><?php } echo $questions; ?> </td> <td class="actions"> <span class="ui-state-default ui-corner-all" title="Editar Prova" onClick="location.assign('./testEdit.php?tst_id=<?php echo $test->get("tst_id"); ?> ');"> <span class="ui-icon ui-icon-pencil"></span> </span> <span class="ui-state-default ui-corner-all" title="Configurar Problemas/Questões da Prova" onClick="location.assign('./testProblems.php?tpb_tst_id=<?php echo $test->get("tst_id"); ?> ');"> <span class="ui-icon ui-icon-gear"></span> </span> <span class="ui-state-default ui-corner-all" title="Baixar ProblemBundleInit.hpp para o módulo AlGod Corretor (C++)." onClick="location.assign('./problemBundleInit.php?tpb_tst_id=<?php echo $test->get("tst_id"); ?> ');"> <span class="ui-icon ui-icon-arrowthickstop-1-s"></span> </span> <span class="ui-state-default ui-corner-all" title="Visualizar logs da Prova." onClick="location.assign('./testLogs.php?tsl_tst_id=<?php echo $test->get("tst_id"); ?> ');"> <span class="ui-icon ui-icon-note"></span> </span> <span class="ui-state-default ui-corner-all" title="Gerar relatório de notas." onClick="location.assign('./testReport.php?tpb_tst_id=<?php echo $test->get("tst_id"); ?> ');"> <span class="ui-icon ui-icon-document"></span> </span> <span class="ui-state-default ui-corner-all" title="Excluir Prova" onClick="deleteTest(<?php echo $test->get('tst_id'); ?> )"> <span class="ui-icon ui-icon-trash"></span> </span> </td> </tr> <?php } ?> </table> <?php } }
public function renderNotDeleted() { $bs = new TestBS(null); $qbuilder = new QueryBuilder('test'); $today = new DateTime('now'); $qbuilder->addLessEqual("tst_visibleSince", $today->format(Model::$SQL_DATE_FORMAT)); $qbuilder->addGreaterEqual("tst_visibleUntil", $today->format(Model::$SQL_DATE_FORMAT)); $qbuilder->addOrder('tst_openSince', QueryBuilder::$DESC); $qbuilder->addOrder('tst_visibleSince', QueryBuilder::$DESC); $qbuilder->addOrder('tst_title', QueryBuilder::$ASC); $qbuilder->addOrder('tst_createdAt', QueryBuilder::$DESC); $tests = $bs->findNotDeleted($qbuilder); if (count($tests) <= 0) { ?> <br/><i>Nenhuma prova aberta no momento.</i><br /> <?php } else { foreach ($tests as $t => $test) { ?> <div class="data-view-box"> <h3><?php echo $test->getForeignModel('tst_dsc_id')->get('dsc_code'); ?> - <?php echo $test->get('tst_title'); ?> </h3> <p><b>INFORMAÇÕES:</b><br /> <b>Visível de:</b> <?php echo Model::parseSQLToInputDate($test->get('tst_visibleSince')); ?> <br /> <b>Visível até:</b> <?php echo Model::parseSQLToInputDate($test->get('tst_visibleUntil')); ?> <br /> <b>Aberta de:</b> <?php echo Model::parseSQLToInputDate($test->get('tst_openSince')); ?> <br /> <b>Aberta até:</b> <?php echo Model::parseSQLToInputDate($test->get('tst_openUntil')); ?> <br /> <b>Descrição:</b><br /> <?php echo $test->get('tst_description'); ?> </p> <form method="POST" class="centering" action="encodePassword.php"> <table class="formTable"> <tr> <td>Senha de Acesso:</td> <td><input type="password" name="tst_password" size=40 /></td> </tr> </table> <input type="hidden" value="<?php echo $test->get("tst_id"); ?> " name="tst_id" /> <input type="submit" value="Abrir Prova" /> </form> </div><br /> <?php } } }
<?php $__REQUIRE_ACCESS_LEVEL__ = 3; $__REDIRECT_TO__ = './'; include "static/header.php"; ?> <h1>Editar Prova</h1> <div class="centering"> <?php include "controller/TestBS.php"; include "view/TestEdit.php"; $bs = new TestBS($_GET); $model = $bs->retrieve(); if (isset($model)) { $widget = new TestEdit($model); $widget->render(); } else { echo "<br /><i>Esta prova não existe.</i><br />"; } ?> <br /> <button onClick="location.assign('./tests.php');">Voltar às Provas</button> </div> <?php include "static/footer.php";