Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
if (!isset($_GET['id'])) {
die("Anda tidak dizinkan mengakses langsung script ini!");
} else {
if ($_GET['id'] <> '76310EEFF2B5D3C887F238976A421B638CFEB0942AB8249CD0A29B125C91B3E5') {
die("Anda tidak dizinkan mengakses langsung script ini!");
}
}
include "../config/config.default.php";
include "../config/config.function.php";
$pengawas = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM pengawas WHERE id_pengawas=$_SESSION[id_pengawas]"));
if ($pengawas['level'] == 'admin') {
$nilaiq = "";
} elseif ($pengawas['level'] == 'pengawas') {
$nilaiq = "and siswa.ruang='$pengawas[ruang]'";
} else {
$nilaiq = "AND c.id_guru = $_SESSION[id_pengawas] ";
}
//----------------------------------------------------------------------------------
$requestData = $_REQUEST;
$columns = array(
0 => 'nis',
1 => 'nama',
2 => 'kelas',
3 => 'mapel',
4 => 'selisih',
5 => 'jml_benar',
6 => 'skor',
7 => 'ipaddress',
8 => 'status_ujian',
9 => 'status_ujian'
);
//----------------------------------------------------------------------------------
//join 2 tabel dan bisa lebih, tergantung kebutuhan
$sql = " SELECT id_nilai, nis, siswa.nama, kelas.nama as kelas, c.nama as mapel, ipaddress, mapel.level,s.kode_ujian,";
$sql .= " IF(ujian_selesai !='', 'Tes Selesai','Masih Dikerjakan') as status_ujian,total, jml_benar, jml_salah,skor";
$sql .= " ujian_berlangsung, ujian_mulai, ujian_selesai,";
$sql .= " timediff(ujian_berlangsung, ujian_mulai) as selisih";
$sql .= " FROM nilai s";
$sql .= " LEFT JOIN ujian c ON s.id_ujian=c.id_ujian";
$sql .= " LEFT JOIN siswa ON s.id_siswa=siswa.id_siswa";
$sql .= " LEFT JOIN kelas ON siswa.id_kelas=kelas.id_kelas";
$sql .= " LEFT JOIN mapel ON s.id_mapel = mapel.id_mapel";
$sql .= " WHERE c.status='1' and s.id_siswa<>''and DATE(ujian_mulai) = CURDATE() $nilaiq";
$query = mysqli_query($koneksi, $sql) or die($koneksi->error);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
//----------------------------------------------------------------------------------
$sql = " SELECT id_nilai, nis, siswa.nama, kelas.nama as kelas, c.nama as mapel, ipaddress, mapel.level,s.kode_ujian,";
$sql .= " IF(ujian_selesai !='', 'Tes Selesai','Masih Dikerjakan') as status_ujian,total, jml_benar, jml_salah,skor,";
$sql .= " ujian_berlangsung, ujian_mulai, ujian_selesai,";
$sql .= " timediff(ujian_berlangsung, ujian_mulai) as selisih";
$sql .= " FROM nilai s";
$sql .= " LEFT JOIN ujian c ON s.id_ujian=c.id_ujian";
$sql .= " LEFT JOIN siswa ON s.id_siswa=siswa.id_siswa";
$sql .= " LEFT JOIN kelas ON siswa.id_kelas=kelas.id_kelas";
$sql .= " LEFT JOIN mapel ON s.id_mapel = mapel.id_mapel";
$sql .= " WHERE c.status='1' and s.id_siswa<>''and DATE(ujian_mulai) = CURDATE() $nilaiq";
if (!empty($requestData['search']['value'])) {
//----------------------------------------------------------------------------------
$sql .= " AND ( siswa.nama LIKE '%" . $requestData['search']['value'] . "%' ";
$sql .= " OR siswa.nama LIKE '%" . $requestData['search']['value'] . "%' )";
}
//----------------------------------------------------------------------------------
$limit = $requestData['length'] === '-1' ? " " :
" LIMIT " . $requestData['start'] . " ," . $requestData['length'] . " ";
$query = mysqli_query($koneksi, $sql) or die($koneksi->error);
$totalFiltered = mysqli_num_rows($query);
$sql .= " ORDER BY " . $columns[$requestData['order'][0]['column']] . " " . $requestData['order'][0]['dir'] . $limit;
$query = mysqli_query($koneksi, $sql) or die($koneksi->error);
//----------------------------------------------------------------------------------
$data = array();
while ($row = mysqli_fetch_array($query)) {
$sumber = $row["status_ujian"] === 'Masih Dikerjakan' ? strtotime($row['ujian_berlangsung']) : strtotime($row['ujian_selesai']);
$selisih = $sumber - strtotime($row['ujian_mulai']);
$nestedData = array();
$nestedData[] = $row["nis"];
$nestedData[] = $row["nama"];
$nestedData[] = $row["kelas"];
$nestedData[] = "<small class='label bg-red'>$row[kode_ujian]</small>
<small class='label bg-purple'>$row[mapel]</small>
<small class='label bg-blue'>$row[level]</small>";
$nestedData[] = $row["status_ujian"] === 'Masih Dikerjakan' ? lamaujian($selisih) : lamaujian($selisih, true);
$nestedData[] = $row["status_ujian"] === 'Masih Dikerjakan' ?
' - ' :
"<small class='label bg-green'>$row[jml_benar] <i class='fa fa-check'></i></small>
<small class='label bg-red'>$row[jml_salah] <i class='fa fa-times'></i></small>";
$nestedData[] = $row["status_ujian"] === 'Masih Dikerjakan' ?
' - ' :
"<small class='label bg-green'>" . number_format($row['skor'], 2, '.', '') . "</small>";
$nestedData[] = $row["ipaddress"];
$nestedData[] = $row["status_ujian"] === 'Masih Dikerjakan' ?
"<label class='label label-danger'><i class='fa fa-spin fa-spinner' title='Sedang ujian'></i>&nbsp;Masih Dikerjakan</label>" :
"<label class='label label-success'>Tes Selesai</label>";
$nestedData[] = $row["status_ujian"] === 'Tes Selesai' ?
"<button onclick='ulang_ujian(" . $row['id_nilai'] . ")' class='ulang btn btn-xs btn-danger'>ulang</button>" :
"<button onclick='selesaikan_ujian(" . $row['id_nilai'] . ")'class='hapus btn btn-xs btn-danger'>selesai</button>";
$data[] = $nestedData;
}
//----------------------------------------------------------------------------------
$json_data = array(
"draw" => intval($requestData['draw']),
"recordsTotal" => intval($totalData),
"recordsFiltered" => intval($totalFiltered),
"recordssFiltered" => $requestData['search']['value'],
"data" => $data);
//----------------------------------------------------------------------------------
echo json_encode($json_data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment