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.

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