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.

651 lines
23 KiB

  1. <?php
  2. session_start();
  3. require_once("conn/db.php");
  4. require_once('utils/helper.php');
  5. if (!isset($_SESSION['nim'])) {
  6. header('location:login.php');
  7. }
  8. date_default_timezone_set('Asia/Makassar');
  9. $date = date("Y-m-d H:i");
  10. if ($date <= date("Y-m-d H:i", strtotime("2016-12-05 23:59"))) {
  11. header('location:tampilanSION.php');
  12. }
  13. //CEK PANITIA / TIDAK :
  14. $nim = $_SESSION['nim'];
  15. $query = odbc_exec($koneksi, "SELECT TOP 1 * FROM tb_panitia WHERE nim_panitia = '$nim' AND role='1'");
  16. $panitia = dbGet($query);
  17. if (!isset($panitia[0])) {
  18. header('location:tampilanSION.php');
  19. }
  20. // Ambil profil calon
  21. $queryCandidates = "SELECT
  22. id_calon,
  23. nama_calon,
  24. photo,
  25. id_status
  26. FROM
  27. tb_calon
  28. ORDER BY photo";
  29. $execCandidates = odbc_exec($koneksi, $queryCandidates);
  30. $candidates = dbGet($execCandidates);
  31. $pluckedCandidateId = colPluck($candidates, 'id_calon');
  32. // Ambil semua suara yang didapatkan
  33. $stringifyCandidateId = implode("','", $pluckedCandidateId);
  34. $queryVotes = "SELECT
  35. b.id_calon,
  36. COUNT(a.id_pemilu) AS count
  37. FROM
  38. (SELECT
  39. MIN(a.id_pemilu) AS id_pemilu,
  40. b.id_status,
  41. MIN(a.create_at) as create_at
  42. FROM
  43. tb_pemilu a
  44. JOIN
  45. tb_calon b ON a.id_calon = b.id_calon
  46. WHERE
  47. a.id_status IN ('S9af54pY', 'KTU3vVnd')
  48. GROUP BY
  49. a.id_status,
  50. nim_mhs,
  51. b.id_status) a
  52. JOIN tb_pemilu b
  53. ON b.id_pemilu = a.id_pemilu
  54. WHERE
  55. b.id_calon IN ('$stringifyCandidateId')
  56. GROUP BY
  57. b.id_calon
  58. ORDER BY
  59. b.id_calon";
  60. $execVotes = odbc_exec($koneksi, $queryVotes);
  61. $votes = dbGet($execVotes);
  62. $keyedVotes = colKeyBy($votes, 'id_calon');
  63. $queryAllVotes = "SELECT
  64. id_calon,
  65. COUNT(id_pemilu) AS allCount
  66. FROM
  67. tb_pemilu
  68. WHERE
  69. id_calon IN ('$stringifyCandidateId')
  70. GROUP BY
  71. id_calon
  72. ORDER BY
  73. id_calon";
  74. $execAllVotes = odbc_exec($koneksi, $queryAllVotes);
  75. $allVote = dbGet($execAllVotes);
  76. $keyedAllVotes = colKeyBy($allVote, 'id_calon');
  77. // Pasang hasil vote ke setiap calon
  78. foreach ($candidates as &$candidate) {
  79. if (!empty($keyedVotes[$candidate['id_calon']])) {
  80. $candidate['votes'] = $keyedVotes[$candidate['id_calon']];
  81. } else {
  82. $candidate['votes'] = [
  83. 'id_calon' => $candidate['id_calon'],
  84. 'count' => 0
  85. ];
  86. }
  87. if (!empty($keyedAllVotes[$candidate['id_calon']]['allCount'])) {
  88. $candidate['votes']['allCount'] = $keyedAllVotes[$candidate['id_calon']]['allCount'];
  89. } else {
  90. $candidate['votes']['allCount'] = 0;
  91. }
  92. }
  93. // Ambil sema
  94. $semaTotalVotes = 0;
  95. $sema = array_filter($candidates, function ($item) {
  96. return $item['id_status'] === 'KTU3vVnd';
  97. });
  98. array_reduce($sema, function ($prev, $cur) use (&$semaTotalVotes) {
  99. $prevVotes = (int) $prev['votes']['count'];
  100. $curVotes = (int) $cur['votes']['count'];
  101. $semaTotalVotes += $prevVotes + $curVotes;
  102. });
  103. // Ambil balma
  104. $balmaTotalVotes = 0;
  105. $balma = array_filter($candidates, function ($item) {
  106. return $item['id_status'] === 'S9af54pY';
  107. });
  108. array_reduce($balma, function ($prev, $cur) use (&$balmaTotalVotes) {
  109. $prevVotes = (int) $prev['votes']['count'];
  110. $curVotes = (int) $cur['votes']['count'];
  111. $balmaTotalVotes += $prevVotes + $curVotes;
  112. });
  113. ?>
  114. <!doctype html>
  115. <html>
  116. <head>
  117. <meta charset="utf-8">
  118. <meta name="theme-color" content="#2160ac">
  119. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  120. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  121. <title>Hasil Sementara Polling Pemilu Raya <?= date('Y') ?></title>
  122. <link href="public/css/bootstrap.css" rel="stylesheet">
  123. <link href="public/fonts/font-awesome/css/font-awesome.min.css" rel="stylesheet">
  124. <link href="public/css/normalize.css" rel="stylesheet">
  125. <link href="public/css/style.css" rel="stylesheet">
  126. <style>
  127. .btn-count.btn-free:active, .btn-count.btn-free.active {
  128. color: #333 !important;
  129. background-color: #fff !important;
  130. }
  131. .btn-count.btn-free:active .candidate-name, .btn-count.btn-free.active .candidate-name {
  132. color: #333 !important;
  133. }
  134. </style>
  135. </head>
  136. <body>
  137. <header>
  138. <div>
  139. <img class="img-responsive shd one" src="public/images/banner.png">
  140. </div>
  141. <div class="clearfix"></div>
  142. </header>
  143. <main>
  144. <div class="text-center lists-striped" data-toggle="buttons"> <!--data-toggle="buttons"-->
  145. <h1 class="ttl" style="font-size:50px; margin-bottom:10px;">HASIL SEMENTARA POLLING PEMILU RAYA <?= date('Y') ?><br></h1>
  146. <br>
  147. <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>
  148. <h1 class="ttl">Ketua & Wakil Ketua Senat Mahasiswa</h1>
  149. <div class="lines"></div>
  150. <br>
  151. <div class="container">
  152. <div class="row">
  153. <?php
  154. // Looping sema
  155. $no = 1;
  156. foreach ($sema as $key => $item) {
  157. if ($semaTotalVotes > 0) {
  158. $percentage = number_format(($item['votes']['count'] / $semaTotalVotes) * 100, 2, ",", ".");
  159. } else {
  160. $percentage = 0;
  161. }
  162. ?>
  163. <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
  164. <?php include('./components/card.php'); ?>
  165. </div>
  166. <?php
  167. }
  168. ?>
  169. </div>
  170. </div>
  171. <div class="clearfix" style="margin-top:10px;"></div>
  172. <!-- <div class="stripe-reverse"></div> -->
  173. </div>
  174. <!--end for senat-->
  175. <div class="clearfix"></div>
  176. <div class="shadow"></div>
  177. <!--for balma-->
  178. <div class="text-center lists" data-toggle="buttons" style="margin-bottom : 40px">
  179. <h1 class="ttl">Ketua Badan Legislatif Mahasiswa</h1>
  180. <div class="lines"></div>
  181. <br>
  182. <div class="container">
  183. <div class="row">
  184. <?php
  185. // Looping sema
  186. $no = 1;
  187. foreach ($balma as $key => $item) {
  188. if ($balmaTotalVotes > 0) {
  189. $percentage = number_format(($item['votes']['count'] / $balmaTotalVotes) * 100, 2, ",", ".");
  190. } else {
  191. $percentage = 0;
  192. }
  193. ?>
  194. <div class="col-lg-push-2 col-lg-4 col-md-6 col-sm-6 col-xs-12">
  195. <?php include('./components/card.php'); ?>
  196. </div>
  197. <?php
  198. }
  199. ?>
  200. </div>
  201. </div>
  202. <div class="clearfix" style="margin-top: 15px;"></div>
  203. <!-- <div class="stripe-reverse"></div> -->
  204. </div>
  205. <!--end for balma-->
  206. <div class="container">
  207. <center>
  208. <h1 class="ttl">Grafik Pemilihan Sema & Balma</h1>
  209. <div class="lines-divider"></div>
  210. </center>
  211. <div style="margin-bottom : 40px">
  212. <div class="row">
  213. <div class="sema-chart col-md-6">
  214. <center>
  215. <h3 class="chart-title">
  216. Ketua dan Wakil Sema
  217. </h3>
  218. </center>
  219. <div class="title-divider"></div>
  220. <div class="chart-container" style="max-height : 100px;overflow : hidden;">
  221. <canvas id="sema-legend"></canvas>
  222. </div>
  223. <div class="chart-container">
  224. <canvas id="sema-chart" onbeforeprint="beforePrintHandler()"></canvas>
  225. </div>
  226. </div>
  227. <div class="balma-chart col-md-6">
  228. <center>
  229. <h3 class="chart-title">
  230. Ketua Balma
  231. </h3>
  232. </center>
  233. <div class="title-divider"></div>
  234. <div class="chart-container balma-legend" style="overflow : hidden;">
  235. <canvas id="balma-legend"></canvas>
  236. </div>
  237. <div class="chart-container">
  238. <canvas id="balma-chart"></canvas>
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. <!--tabel jumlah suara-->
  245. <div style="margin-bottom : 40px">
  246. <div class="container">
  247. <center style="margin-bottom : 32px">
  248. <h1 class="ttl">Tabel Jumlah Suara</h1>
  249. <div class="lines-divider"></div>
  250. </center>
  251. <div class="table-responsive">
  252. <table class="table table-bordered">
  253. <thead>
  254. <tr>
  255. <th>Calon</th>
  256. <th>Tipe</th>
  257. <th>Persentase</th>
  258. <th>Suara Sah</th>
  259. <th>Suara Tidak Sah</th>
  260. <th>Total Suara</th>
  261. </tr>
  262. </thead>
  263. <tbody>
  264. <?php
  265. $i = 0;
  266. $legal_vote = 0;
  267. $ilegal_vote = 0;
  268. $count = 0;
  269. foreach ($candidates as &$candidate) {
  270. $status = $candidate["id_status"];
  271. if ($status == "KTU3vVnd") {
  272. $type = "SEMA";
  273. } elseif ($status == "S9af54pY") {
  274. $type = "BALMA";
  275. } else {
  276. $type = "Unknown";
  277. }
  278. ?>
  279. <tr>
  280. <td>
  281. <?= $candidate["nama_calon"] ?>
  282. </td>
  283. <td>
  284. <?= $type ?>
  285. </td>
  286. <td align="right">
  287. <?php
  288. if ($type === "SEMA") {
  289. $number_of_votes = $semaTotalVotes;
  290. $count_candidates = count($sema);
  291. } else if ($type === "BALMA") {
  292. $number_of_votes = $balmaTotalVotes;
  293. $count_candidates = count($balma);;
  294. }
  295. if ($number_of_votes > 0) {
  296. $percentage = number_format(($candidate["votes"]["count"] / $number_of_votes) * 100, 2, ",", ".");
  297. } else {
  298. $percentage = 0;
  299. }
  300. ?>
  301. <?= $percentage ?>%
  302. </td>
  303. <td align="right">
  304. <?php
  305. echo $candidate["votes"]["count"];
  306. $legal_vote += $candidate["votes"]["count"];
  307. ?>
  308. </td>
  309. <td align="right">
  310. <?php
  311. $data = $candidate['votes']['allCount'] - $candidate["votes"]["count"];
  312. echo $data;
  313. $ilegal_vote += $data;
  314. ?>
  315. </td>
  316. <td align="right">
  317. <?php
  318. echo $candidate['votes']['allCount'];
  319. $count += $candidate['votes']['allCount'];
  320. ?>
  321. </td>
  322. </tr>
  323. <?php
  324. $i++;
  325. if ($i == $count_candidates) {
  326. ?>
  327. <tr>
  328. <th class="text-right" colspan="3">Total</th>
  329. <th class="text-right"><?= $legal_vote ?></th>
  330. <th class="text-right"><?= $ilegal_vote ?></th>
  331. <th class="text-right"><?= $count ?></th>
  332. </tr>
  333. <?php
  334. $i = 0;
  335. $legal_vote = 0;
  336. $ilegal_vote = 0;
  337. $count = 0;
  338. }
  339. ?>
  340. <?php
  341. }
  342. ?>
  343. </tbody>
  344. </table>
  345. </div>
  346. </div>
  347. </div>
  348. <div class="clearfix"></div>
  349. <div class="text-center">
  350. <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>
  351. </div>
  352. </main>
  353. <footer>
  354. <div class="clearfix"></div>
  355. <div class="text-center">
  356. <img class="img-responsive one" src="public/images/banner2.png">
  357. <div class="lists-footer">
  358. <p style="margin:0 5px;">Copyright &copy; <?= date('Y') ?> IT Support Pemira</p>
  359. </div>
  360. </div>
  361. </footer>
  362. <script src="public/js/jquery-3.3.1.min.js"></script>
  363. <script src="public/js/bootstrap.min.js"></script>
  364. <script src="public/js/chart.js"></script>
  365. <script src="public/js/chart-label.js"></script>
  366. <script>
  367. function beforePrintHandler () {
  368. for (var id in Chart.instances) {
  369. Chart.instances[id].resize()
  370. }
  371. }
  372. var $ctxSema = document.getElementById("sema-chart").getContext('2d');
  373. var $semaChart = new Chart($ctxSema,{
  374. type: 'pie',
  375. data: {
  376. datasets: [{
  377. data: [
  378. <?php
  379. foreach($sema as $key => $value) {
  380. echo $value['votes']['count'].",";
  381. }
  382. ?>
  383. ],
  384. backgroundColor: [
  385. 'rgba(255, 99, 132, 1)',
  386. 'rgba(54, 162, 235, 1)',
  387. 'rgba(255, 206, 86, 1)',
  388. 'rgba(75, 192, 192, 1)',
  389. 'rgba(153, 102, 255, 1)',
  390. 'rgba(255, 159, 64, 1)'
  391. ]
  392. }],
  393. labels: [
  394. <?php
  395. foreach($sema as $key => $value) {
  396. echo "'".$value['nama_calon']."',";
  397. }
  398. ?>
  399. ],
  400. },
  401. options: {
  402. plugins : {
  403. labels : {
  404. render : function (args) {
  405. return ((args.value / <?=$semaTotalVotes?>) * 100).toFixed(2) + " %" ;
  406. },
  407. precision : 0,
  408. fontColor : "#FFF",
  409. fontSize : 15,
  410. fontStyle : 'bold'
  411. }
  412. },
  413. responsive : true,
  414. legend: {
  415. display: false
  416. },
  417. tooltips: {
  418. callbacks: {
  419. label: function(tooltipItem, data) {
  420. let dataset = data.datasets[tooltipItem.datasetIndex];
  421. let currentValue = dataset.data[tooltipItem.index];
  422. return " " + currentValue + ' Suara';
  423. },
  424. title: function(tooltipItem, data) {
  425. return data.labels[tooltipItem[0].index];
  426. }
  427. }
  428. }
  429. }
  430. });
  431. var $ctxSemaLegend = document.getElementById("sema-legend").getContext('2d');
  432. var $semaLegend = new Chart($ctxSemaLegend,{
  433. type: 'pie',
  434. data: {
  435. datasets: [{
  436. data: [
  437. <?php
  438. foreach($sema as $key => $value) {
  439. echo $value['votes']['count'].",";
  440. }
  441. ?>
  442. ],
  443. backgroundColor: [
  444. 'rgba(255, 99, 132, 1)',
  445. 'rgba(54, 162, 235, 1)',
  446. 'rgba(255, 206, 86, 1)',
  447. 'rgba(75, 192, 192, 1)',
  448. 'rgba(153, 102, 255, 1)',
  449. 'rgba(255, 159, 64, 1)'
  450. ],
  451. }],
  452. labels: [
  453. <?php
  454. foreach($sema as $key => $value) {
  455. echo "'".$value['nama_calon']."',";
  456. }
  457. ?>
  458. ],
  459. },
  460. options: {
  461. cutoutPercentage : 100,
  462. plugins : {
  463. labels : {
  464. fontColor : "#FFF",
  465. }
  466. },
  467. }
  468. });
  469. var $ctxBalmaLegend = document.getElementById("balma-legend").getContext('2d');
  470. var $balmaLegend = new Chart($ctxBalmaLegend,{
  471. type: 'pie',
  472. data: {
  473. datasets: [{
  474. data: [
  475. <?php
  476. foreach($balma as $key => $value) {
  477. echo $value['votes']['count'].",";
  478. }
  479. ?>
  480. ],
  481. backgroundColor: [
  482. 'rgba(75, 192, 192, 1)',
  483. 'rgba(153, 102, 255, 1)',
  484. 'rgba(255, 159, 64, 1)',
  485. 'rgba(255, 99, 132, 1)',
  486. 'rgba(54, 162, 235, 1)',
  487. 'rgba(255, 206, 86, 1)',
  488. ]
  489. }],
  490. labels: [
  491. <?php
  492. foreach($balma as $key => $value) {
  493. echo "'".$value['nama_calon']."',";
  494. }
  495. ?>
  496. ],
  497. },
  498. options: {
  499. cutoutPercentage : 100,
  500. plugins : {
  501. labels : {
  502. fontColor : "#FFF",
  503. }
  504. },
  505. }
  506. });
  507. var $ctxBalma = document.getElementById("balma-chart").getContext('2d');
  508. var $balmaChart = new Chart($ctxBalma,{
  509. type: 'pie',
  510. data: {
  511. datasets: [{
  512. data: [
  513. <?php
  514. foreach($balma as $key => $value) {
  515. echo $value['votes']['count'].",";
  516. }
  517. ?>
  518. ],
  519. backgroundColor: [
  520. 'rgba(75, 192, 192, 1)',
  521. 'rgba(153, 102, 255, 1)',
  522. 'rgba(255, 159, 64, 1)',
  523. 'rgba(255, 99, 132, 1)',
  524. 'rgba(54, 162, 235, 1)',
  525. 'rgba(255, 206, 86, 1)',
  526. ]
  527. }],
  528. labels: [
  529. <?php
  530. foreach($balma as $key => $value) {
  531. echo "'".$value['nama_calon']."',";
  532. }
  533. ?>
  534. ],
  535. },
  536. options: {
  537. plugins : {
  538. labels : {
  539. render : function (args) {
  540. return ((args.value / <?=$balmaTotalVotes?>) * 100).toFixed(2) + " %" ;
  541. },
  542. precision : 0,
  543. fontColor : "#FFF",
  544. fontSize : 16,
  545. fontStyle : 'bold',
  546. showActualPercentages: true,
  547. showZero: true,
  548. }
  549. },
  550. legend: {
  551. display: false
  552. },
  553. responsive : true,
  554. tooltips: {
  555. callbacks: {
  556. label: function(tooltipItem, data) {
  557. let dataset = data.datasets[tooltipItem.datasetIndex];
  558. let currentValue = dataset.data[tooltipItem.index];
  559. return " " + currentValue + ' Suara';
  560. },
  561. title: function(tooltipItem, data) {
  562. return data.labels[tooltipItem[0].index];
  563. }
  564. }
  565. }
  566. }
  567. });
  568. </script>
  569. </body>
  570. </html>