-
Notifications
You must be signed in to change notification settings - Fork 17
/
selesai.php
85 lines (81 loc) · 2.64 KB
/
selesai.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
require("config/config.default.php");
require("config/config.function.php");
require("config/functions.crud.php");
$idm = $_POST['id_mapel'];
$ids = $_POST['id_siswa'];
$idu = $_POST['id_ujian'];
$where = array(
'id_mapel' => $idm,
'id_siswa' => $ids,
'id_ujian' => $idu
);
$benar = $salah = 0;
$mapel = fetch($koneksi, 'mapel', array('id_mapel' => $idm));
$siswa = fetch($koneksi, 'siswa', array('id_siswa' => $ids));
$ceksoal = select($koneksi, 'soal', array('id_mapel' => $idm, 'jenis' => 1));
$ceksoalesai = select($koneksi, 'soal', array('id_mapel' => $idm, 'jenis' => 2));
$arrayjawabesai = array();
foreach ($ceksoalesai as $getsoalesai) {
$w2 = array(
'id_siswa' => $ids,
'id_mapel' => $idm,
'id_soal' => $getsoalesai['id_soal'],
'jenis' => 2
);
// $cekjwbesai = rowcount($koneksi, 'jawaban', $w2);
// if ($cekjwbesai <> 0) {
$getjwb2 = fetch($koneksi, 'jawaban', $w2);
if ($getjwb2) {
$jawabxx = str_replace("'", "`", $getjwb2['esai']);
$jawabxx = str_replace("#", ">>", $jawabxx);
$jawabxx = preg_replace('/[^A-Za-z0-9\@\<\>\$\_\&\-\+\(\)\/\?\!\;\:\`\"\[\]\*\{\}\=\%\~\`\÷\× ]/', '', $jawabxx);
$arrayjawabesai[$getsoalesai['id_soal']] = $jawabxx;
} else {
$arrayjawabesai[$getsoalesai['id_soal']] = 'Tidak Diisi';
}
// } else {
// $arrayjawabesai[$getjwb2['id_soal']] = 'tidak diisi';
// }
}
$arrayjawab = array();
foreach ($ceksoal as $getsoal) {
$w = array(
'id_siswa' => $ids,
'id_mapel' => $idm,
'id_soal' => $getsoal['id_soal'],
'jenis' => 1
);
// $cekjwb = rowcount($koneksi, 'jawaban', $w);
// if ($cekjwb <> 0) {
$getjwb = fetch($koneksi, 'jawaban', $w);
if ($getjwb) {
$arrayjawab[$getsoal['id_soal']] = $getjwb['jawaban'];
} else {
$arrayjawab[$getsoal['id_soal']] = 'X';
}
($getjwb['jawaban'] == $getsoal['jawaban']) ? $benar++ : $salah++;
// } else {
// $arrayjawab[$getjwb['id_soal']] = 'X';
// $salah++;
// }
}
$bagi = $mapel['jml_soal'] / 100;
$bobot = $mapel['bobot_pg'] / 100;
$skor = ($benar / $bagi) * $bobot;
$data = array(
'ujian_selesai' => $datetime,
'jml_benar' => $benar,
'jml_salah' => $salah,
'skor' => $skor,
'total' => $skor,
'online' => 0,
'jawaban' => serialize($arrayjawab),
'jawaban_esai' => serialize($arrayjawabesai)
);
$simpan = update($koneksi, 'nilai', $data, $where);
echo mysqli_error($koneksi);
if ($simpan) {
delete($koneksi, 'jawaban', $where);
}
mysqli_query($koneksi, "INSERT INTO log (id_siswa,type,text,date) VALUES ('$ids','login','Selesai Ujian','$tanggal $waktu')");