You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

504 lines
17 KiB

<?php
session_start();
require_once("conn/db.php");
require_once('utils/helper.php');
if (!isset($_SESSION['nim'])) {
header('location:login.php');
}
//SET TIMEZONE
date_default_timezone_set('Asia/Makassar');
$date = date("Y-m-d H:i");
//CEK PANITIA ISTIMEWA
$nim = $_SESSION['nim'];
$query = odbc_exec($koneksi, "SELECT TOP 1 * FROM tb_panitia WHERE nim_panitia = '$nim' AND role='1'");
$panitia = dbGet($query);
if ($date <= date("Y-m-d H:i", strtotime("2018-10-15 06:00")) || !isset($panitia[0])) {
header('location:tampilanSION.php');
}
// Ambil profil calon
$queryCandidates = "SELECT
id_calon,
nama_calon,
photo,
id_status
FROM
tb_calon
ORDER BY photo";
$execCandidates = odbc_exec($koneksi, $queryCandidates);
$candidates = dbGet($execCandidates);
$pluckedCandidateId = colPluck($candidates, 'id_calon');
// Ambil semua suara yang didapatkan
$stringifyCandidateId = implode("','", $pluckedCandidateId);
$queryVotes = "SELECT
b.id_calon,
COUNT(a.id_pemilu) AS count
FROM
(SELECT
MIN(a.id_pemilu) AS id_pemilu,
b.id_status,
MIN(a.create_at) as create_at
FROM
tb_pemilu a
JOIN
tb_calon b ON a.id_calon = b.id_calon
WHERE
a.id_status IN ('S9af54pY', 'KTU3vVnd')
GROUP BY
a.id_status,
nim_mhs,
b.id_status) a
JOIN tb_pemilu b
ON b.id_pemilu = a.id_pemilu
WHERE
b.id_calon IN ('$stringifyCandidateId')
GROUP BY
b.id_calon
ORDER BY
b.id_calon";
$execVotes = odbc_exec($koneksi, $queryVotes);
$votes = dbGet($execVotes);
$keyedVotes = colKeyBy($votes, 'id_calon');
// Pasang hasil vote ke setiap calon
foreach ($candidates as &$candidate) {
if (!empty($keyedVotes[$candidate['id_calon']])) {
$candidate['votes'] = $keyedVotes[$candidate['id_calon']];
} else {
$candidate['votes'] = [
'id_calon' => $candidate['id_calon'],
'count' => 0
];
}
}
// Ambil sema
$semaTotalVotes = 0;
$sema = array_filter($candidates, function ($item) {
return $item['id_status'] === 'KTU3vVnd';
});
array_reduce($sema, function ($prev, $cur) use (&$semaTotalVotes) {
$prevVotes = (int) $prev['votes']['count'];
$curVotes = (int) $cur['votes']['count'];
$semaTotalVotes += $prevVotes + $curVotes;
});
// Ambil balma
$balmaTotalVotes = 0;
$balma = array_filter($candidates, function ($item) {
return $item['id_status'] === 'S9af54pY';
});
array_reduce($balma, function ($prev, $cur) use (&$balmaTotalVotes) {
$prevVotes = (int) $prev['votes']['count'];
$curVotes = (int) $cur['votes']['count'];
$balmaTotalVotes += $prevVotes + $curVotes;
});
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="theme-color" content="#2160ac">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hasil Polling Pemilu Raya <?= date('Y') ?></title>
<link href="public/css/bootstrap.css" rel="stylesheet">
<link href="public/fonts/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link href="public/css/normalize.css" rel="stylesheet">
<link href="public/css/style.css" rel="stylesheet">
<style>
.btn-count.btn-free:active, .btn-count.btn-free.active {
color: #333 !important;
background-color: #fff !important;
}
.btn-count.btn-free:active .candidate-name, .btn-count.btn-free.active .candidate-name {
color: #333 !important;
}
</style>
</head>
<body>
<header>
<div>
<img class="img-responsive shd one" src="public/images/banner.png">
</div>
<div class="clearfix"></div>
</header>
<main>
<div class="text-center lists-striped" data-toggle="buttons"> <!--data-toggle="buttons"-->
<h1 class="ttl" style="font-size:50px; margin-bottom:10px;">HASIL POLLING PEMILU RAYA <?= date('Y') ?><br></h1>
<br>
<p class="ttl" style="font-size:14px; margin-bottom:50px;">Update Terakhir: <span id="last_update"><?= date("d M Y H:i:s"); ?> WITA<span></p>
<h1 class="ttl">Ketua & Wakil Ketua Senat Mahasiswa</h1>
<div class="lines"></div>
<br>
<div class="container">
<div class="row">
<?php
// Looping sema
$no = 1;
foreach ($sema as $key => $item) {
if ($semaTotalVotes > 0) {
$percentage = number_format(($item['votes']['count'] / $semaTotalVotes) * 100, 2, ",", ".");
} else {
$percentage = 0;
}
?>
<div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
<?php include('./components/card.php'); ?>
</div>
<?php
}
?>
</div>
</div>
<div class="clearfix" style="margin-top:10px;"></div>
<!-- <div class="stripe-reverse"></div> -->
</div>
<!--end for senat-->
<div class="clearfix"></div>
<div class="shadow"></div>
<!--for balma-->
<div class="text-center lists" data-toggle="buttons" style="margin-bottom : 40px">
<h1 class="ttl">Ketua Badan Legislatif Mahasiswa</h1>
<div class="lines"></div>
<br>
<div class="container">
<div class="row">
<?php
// Looping balma
$no = 1;
foreach ($balma as $key => $item) {
if ($balmaTotalVotes > 0) {
$percentage = number_format(($item['votes']['count'] / $balmaTotalVotes) * 100, 2, ",", ".");
} else {
$percentage = 0;
}
?>
<div class="col-lg-push-2 col-lg-4 col-md-6 col-sm-6 col-xs-12">
<?php include('./components/card.php'); ?>
</div>
<?php
}
?>
</div>
</div>
<div class="clearfix" style="margin-top: 15px;"></div>
<!-- <div class="stripe-reverse"></div> -->
</div>
<!--end for balma-->
<div class="container">
<center>
<h1 class="ttl">Grafik Pemilihan Sema & Balma</h1>
<div class="lines-divider"></div>
</center>
<div style="margin-bottom : 40px">
<div class="row">
<div class="sema-chart col-md-6">
<center>
<h3 class="chart-title">
Ketua dan Wakil Sema
</h3>
</center>
<div class="title-divider"></div>
<div class="chart-container" style="max-height : 100px;overflow : hidden;">
<canvas id="sema-legend"></canvas>
</div>
<div class="chart-container">
<canvas id="sema-chart" onbeforeprint="beforePrintHandler()"></canvas>
</div>
</div>
<div class="balma-chart col-md-6">
<center>
<h3 class="chart-title">
Ketua Balma
</h3>
</center>
<div class="title-divider"></div>
<div class="chart-container balma-legend" style="overflow : hidden;">
<canvas id="balma-legend"></canvas>
</div>
<div class="chart-container">
<canvas id="balma-chart"></canvas>
</div>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="text-center">
<a href="http://sion.stikom-bali.ac.id" class="btn btn-lg btn-success submit">Lanjut Ke SION <span class="glyphicon glyphicon-chevron-right" ></span></a>
</div>
</main>
<footer>
<div class="clearfix"></div>
<div class="text-center">
<img class="img-responsive one" src="public/images/banner2.png">
<div class="lists-footer">
<p style="margin:0 5px;">Copyright &copy; <?= date('Y') ?> IT Support Pemira</p>
</div>
</div>
</footer>
<script src="public/js/jquery-3.3.1.min.js"></script>
<script src="public/js/bootstrap.min.js"></script>
<script src="public/js/chart.js"></script>
<script src="public/js/chart-label.js"></script>
<script>
function beforePrintHandler () {
for (var id in Chart.instances) {
Chart.instances[id].resize()
}
}
var $ctxSema = document.getElementById("sema-chart").getContext('2d');
var $semaChart = new Chart($ctxSema,{
type: 'pie',
data: {
datasets: [{
data: [
<?php
foreach($sema as $key => $value) {
echo $value['votes']['count'].",";
}
?>
],
backgroundColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
]
}],
labels: [
<?php
foreach($sema as $key => $value) {
echo "'".$value['nama_calon']."',";
}
?>
],
},
options: {
plugins : {
labels : {
render : function (args) {
return ((args.value / <?=$semaTotalVotes?>) * 100).toFixed(2) + " %" ;
},
precision : 0,
fontColor : "#FFF",
fontSize : 15,
fontStyle : 'bold'
}
},
responsive : true,
legend: {
display: false
},
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
let dataset = data.datasets[tooltipItem.datasetIndex];
let currentValue = dataset.data[tooltipItem.index];
return " " + currentValue + ' Suara';
},
title: function(tooltipItem, data) {
return data.labels[tooltipItem[0].index];
}
}
}
}
});
var $ctxSemaLegend = document.getElementById("sema-legend").getContext('2d');
var $semaLegend = new Chart($ctxSemaLegend,{
type: 'pie',
data: {
datasets: [{
data: [
<?php
foreach($sema as $key => $value) {
echo $value['votes']['count'].",";
}
?>
],
backgroundColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
}],
labels: [
<?php
foreach($sema as $key => $value) {
echo "'".$value['nama_calon']."',";
}
?>
],
},
options: {
cutoutPercentage : 100,
plugins : {
labels : {
fontColor : "#FFF",
}
},
}
});
var $ctxBalmaLegend = document.getElementById("balma-legend").getContext('2d');
var $balmaLegend = new Chart($ctxBalmaLegend,{
type: 'pie',
data: {
datasets: [{
data: [
<?php
foreach($balma as $key => $value) {
echo $value['votes']['count'].",";
}
?>
],
backgroundColor: [
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)',
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
]
}],
labels: [
<?php
foreach($balma as $key => $value) {
echo "'".$value['nama_calon']."',";
}
?>
],
},
options: {
cutoutPercentage : 100,
plugins : {
labels : {
fontColor : "#FFF",
}
},
}
});
var $ctxBalma = document.getElementById("balma-chart").getContext('2d');
var $balmaChart = new Chart($ctxBalma,{
type: 'pie',
data: {
datasets: [{
data: [
<?php
foreach($balma as $key => $value) {
echo $value['votes']['count'].",";
}
?>
],
backgroundColor: [
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)',
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
]
}],
labels: [
<?php
foreach($balma as $key => $value) {
echo "'".$value['nama_calon']."',";
}
?>
],
},
options: {
plugins : {
labels : {
render : function (args) {
return ((args.value / <?=$balmaTotalVotes?>) * 100).toFixed(2) + " %" ;
},
precision : 0,
fontColor : "#FFF",
fontSize : 16,
fontStyle : 'bold',
showActualPercentages: true,
showZero: true,
}
},
legend: {
display: false
},
responsive : true,
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
let dataset = data.datasets[tooltipItem.datasetIndex];
let currentValue = dataset.data[tooltipItem.index];
return " " + currentValue + ' Suara';
},
title: function(tooltipItem, data) {
return data.labels[tooltipItem[0].index];
}
}
}
}
});
</script>
</body>
</html>