forked from guaycuru/gde
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
328 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace GDE; | ||
|
||
define('JSON', true); | ||
|
||
require_once('../common/common.inc.php'); | ||
|
||
if((isset($_POST['votar'])) && (isset($_POST['enquete']))) { | ||
$Enquete = Enquete::Load($_POST['enquete']); | ||
if($Enquete->getID() == null) | ||
Base::Error_JSON('Enquete não encontrada.'); | ||
if(($Enquete->Ja_Votou($_Usuario)) || ($Enquete->getAtiva() === false)) | ||
Base::Error_JSON('Você já votou nesta Enquete'); | ||
elseif((($Enquete->getMax_Votos() > 1) && ((!isset($_POST['votos'])) || (!is_array($_POST['votos'])))) || (($Enquete->getMax_Votos() == 1) && ((!isset($_POST['voto'])) || ($_POST['voto'] == null)))) | ||
Base::Error_JSON('Selecione pelo menos uma opção...'); | ||
elseif((isset($_POST['votos'])) && (count($_POST['votos']) > $Enquete->getMax_Votos())) | ||
Base::Error_JSON('Selecione no máximo '.$Enquete->getMax_Votos().(($Enquete->getMax_Votos() > 1)? ' opções' : ' opção').'...'); | ||
else { | ||
if($Enquete->getMax_Votos() == 1) { | ||
$Opcao = EnqueteOpcao::Load($_POST['voto']); | ||
if($Opcao->getID() == null) | ||
Base::Error_JSON('Opção não encontrada.'); | ||
if(($Opcao->getEnquete() === null) || ($Opcao->getEnquete()->getID()) != $Enquete->getID()) | ||
Base::Error_JSON('Opção inválida.'); | ||
$_Usuario->addEnquetes_Opcoes($Opcao); | ||
} else { | ||
foreach($_POST['votos'] as $id_opcao) { | ||
$Opcao = EnqueteOpcao::Load($id_opcao); | ||
if($Opcao->getID() == null) | ||
Base::Error_JSON('Opção não encontrada.'); | ||
if(($Opcao->getEnquete() === null) || ($Opcao->getEnquete()->getID()) != $Enquete->getID()) | ||
Base::Error_JSON('Opção inválida.'); | ||
$_Usuario->addEnquetes_Opcoes($Opcao); | ||
} | ||
} | ||
$_Usuario->Save_JSON(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace GDE; | ||
|
||
define('NO_CACHE', true); | ||
define('NO_HTML', true); | ||
define('NO_REDIRECT', true); | ||
|
||
require_once('../common/common.inc.php'); | ||
|
||
if(empty($_GET['id'])) | ||
exit(); | ||
|
||
$Enquete = Enquete::Load($_GET['id']); | ||
$resultado = ((isset($_GET['res'])) || ($Enquete->Ja_Votou($_Usuario)) || ($Enquete->getAtiva() === false)); | ||
?> | ||
<script type="text/javascript"> | ||
$.tablesorter.addParser({ | ||
id: 'votos', | ||
is: function(s) { return false; }, | ||
format: function(s) { | ||
var tmp = s.split(" "); | ||
return tmp[0]; | ||
}, | ||
type: 'numeric' | ||
}); | ||
var resultados = function() { | ||
$("div.enquete_content").Carregando(); | ||
$("div.enquete_content").load('<?= CONFIG_URL; ?>ajax/enquetes.php?id=<?= $Enquete->getID(); ?>&res'); | ||
return false; | ||
}; | ||
$(document).ready(function() { | ||
$("#ver_resultados").click(resultados); | ||
$("#atualizar").click(resultados); | ||
}); | ||
</script> | ||
<div class="enquete_content" style="width: 640px; height: 480px;"> | ||
<?php if(!$resultado) { ?> | ||
<form method="post" class="auto-form" action="<?= CONFIG_URL; ?>ajax/enquete.php" data-destino="<?= CONFIG_URL; ?>" data-sucesso="Voto computado com sucesso! Obrigado!"> | ||
<input type="hidden" name="enquete" value="<?= $Enquete->getID(); ?>" /> | ||
<?php } ?> | ||
<table border="1" id="table_enquete" class="tabela_bonyta" width="95%"> | ||
<thead> | ||
<tr> | ||
<td align="center" colspan="<?= ($resultado) ? 3 : 1; ?>"><strong><?= $Enquete->getPergunta(false); ?></strong></td> | ||
</tr> | ||
<?php if($resultado) { ?> | ||
<tr> | ||
<th align="center" width="75%"><strong>Opção</strong></td> | ||
<th align="center" width="15%"><strong>Votos</strong></td> | ||
<td align="center"><strong>-</strong></td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php | ||
$total_votos = $Enquete->Numero_Votos(); | ||
$total_usuarios = $Enquete->Numero_Usuarios(); | ||
foreach($Enquete->getOpcoes() as $Opcao) { | ||
$votos = $Opcao->Numero_Votos(); | ||
$porcentagem = $Opcao->Porcentagem(2); | ||
?> | ||
<tr> | ||
<td><?= $Opcao->getOpcao(false); ?></td> | ||
<td><?= $votos; ?> (<?= $porcentagem; ?>%)</td> | ||
<td><img src="<?= CONFIG_URL; ?>web/images/barra.gif" alt="" width="<?= ceil($porcentagem * 2); ?>" height="12" /></td> | ||
</tr> | ||
<?php } ?> | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<td colspan="3" align="center">Total de Votos: <?= $total_votos; ?> (<?= $total_usuarios; ?> Usuários)</td> | ||
</tr> | ||
</tfoot> | ||
<?php } else { ?> | ||
</thead> | ||
<tbody> | ||
<?php foreach($Enquete->getOpcoes() as $Opcao) { ?> | ||
<tr> | ||
<td><input type="<?= (($Enquete->getMax_Votos() > 1) ? "checkbox" : "radio"); ?>" class="opcao" name="<?= (($Enquete->getMax_Votos() > 1) ? "votos[]" : "voto"); ?>" value="<?= $Opcao->getID(); ?>" id="opcao_<?= $Opcao->getID(); ?>" /><label for="opcao_<?= $Opcao->getID(); ?>"><?= $Opcao->getOpcao(false); ?></label></td> | ||
</tr> | ||
<?php } ?> | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<td align="center"><input type="submit" name="votar" value=" " class="botao_salvar" /><br /> | ||
<a href="#" id="ver_resultados">Ver Resultados</a></td> | ||
</tr> | ||
</tfoot> | ||
<?php } ?> | ||
</table> | ||
<?php if(!$resultado) { ?> | ||
</form> | ||
<?php } else { ?> | ||
<div align="center"><a href="#" id="atualizar">Atualizar</a></div> | ||
<?php } ?> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.