<?php 
	class dataUjian extends mysql{
		function get_tahun($kolom,$a,$type){
			if($type == '') return trim ($this->sql_order_seek($sql,$kolom,$a));
			$sql = "select tahun from tbuas group by tahun";
			//echo $sql;
			$this->query = $this->execute($sql,'');
			if ($type == 'jumlah') return $this->sql_order_count($sql);
		}
		function get_data_uts_laporan($kolom,$a,$type, $semester, $tahun){
			if($type == '') return trim ($this->sql_order_seek($sql,$kolom,$a));
			$sql = "select * from tbuas where hadir <> 0 and sm = '".$semester."' and tahun = '".$tahun."' group by dosen";
			//echo $sql;
			$this->query = $this->execute($sql,'');
			if ($type == 'jumlah') return $this->sql_order_count($sql);
		}
		function get_data_uts_nama($kolom,$a,$type, $nama, $semester, $tahun){
			if($type == '') return trim ($this->sql_order_seek($sql,$kolom,$a));
			$sql = "select tbuas.*, (select sum(hadir) from tbuas where dosen = '".$nama."' and sm = '".$semester."' and tahun = '".$tahun."' group by dosen) as jmlhadir, tbnorek.norek from tbuas left join tbnorek on tbuas.dosen = tbnorek.dosen where tbuas.dosen = '".$nama."' and tbuas.hadir <> 0 group by tbuas.dosen";
			//echo $sql;
			$this->query = $this->execute($sql,'');
			if ($type == 'jumlah') return $this->sql_order_count($sql);
		}
		function get_koreksi($kolom){
			if($this->cek_result != "on"){
			$sql = "select * from tbsetkoreksi";
			//echo $sql;
			$this->result = $this->execute($sql,'order');
			$this->cek_result = "on";
			return trim($this->result[$kolom]);
			}
				else return trim($this->result[$kolom]);
		}
		function get_jadwal_single_by_id($kolom,$id){
			if($this->cek_result != "on"){
			$sql = "select * from tbuas where id='".$id."'";
			//echo $sql;
			$this->result = $this->execute($sql,'order');
			$this->cek_result = "on";
			return trim($this->result[$kolom]);
			}
				else return trim($this->result[$kolom]);
		}
		function get_uts_id($kolom, $id){
			if($this->cek_result != "on"){
			$sql = "select * from tbuas where id = '".$id."'";
			//echo $sql;
			$this->result = $this->execute($sql,'order');
			$this->cek_result = "on";
			return trim($this->result[$kolom]);
			}
				else return trim($this->result[$kolom]);
		}
		function update_koreksi($koreksiuts, $naskahuts, $koreksiuas, $naskahuas){
		    $sql = "update tbsetkoreksi set koreksiuts = '".$koreksiuts."', naskahuts = '".$naskahuts."', koreksiuas = '".$koreksiuas."', naskahuas = '".$naskahuas."'";
		    $this->query = $this-> execute($sql,''); 
		}
		function update_uts($id, $hadir, $seharusnya, $tidakhadir, $tambahan){
		    $sql = "update tbuas set hadir = '".$hadir."', seharusnya = '".$seharusnya."', tidakhadir = '".$tidakhadir."', tambahan = '".$tambahan."' where id = '".$id."'";
		    $this->query = $this-> execute($sql,''); 
		}
		function get_data_uas($kolom,$a,$type, $hari, $semester, $tahun, $program){
			if($type == '') return trim ($this->sql_order_seek($sql,$kolom,$a));
			if($program == 'REGULER'){
				if($hari == 'SEMUA HARI'){
					$sql = "select * from tbuas where sm = '".$semester."' and tahun = '".$tahun."' and substring(tbuas.kelas, 1, 1) <> 'E'";
				}else{
					$sql = "select * from tbuas where hari = '".$hari."' and sm = '".$semester."' and tahun = '".$tahun."' and substring(tbuas.kelas, 1, 1) <> 'E'";
				}
			}elseif($program == 'SEMUA'){
				if($hari == 'SEMUA HARI'){
					$sql = "select * from tbuas where sm = '".$semester."' and tahun = '".$tahun."'";
				}else{
					$sql = "select * from tbuas where hari = '".$hari."' and sm = '".$semester."' and tahun = '".$tahun."'";
				}
			}else{
				if($hari == 'SEMUA HARI'){
					$sql = "select * from tbuas where sm = '".$semester."' and tahun = '".$tahun."' and substring(tbuas.kelas, 1, 1) = 'E'";
				}else{
					$sql = "select * from tbuas where hari = '".$hari."' and sm = '".$semester."' and tahun = '".$tahun."' and substring(tbuas.kelas, 1, 1) = 'E'";
				}
			}
			//echo $sql;
			$this->query = $this->execute($sql,'');
			if ($type == 'jumlah') return $this->sql_order_count($sql);
		}
		function get_data_uts_all($kolom,$a,$type, $semester, $tahun){
			if($type == '') return trim ($this->sql_order_seek($sql,$kolom,$a));
			$sql = "select * from tbuas where sm = '".$semester."' and tahun = '".$tahun."' group by dosen";
			//echo $sql;
			$this->query = $this->execute($sql,'');
			if ($type == 'jumlah') return $this->sql_order_count($sql);
		}
		function add_jadwal_uas($idmatakuliah, $matakuliah, $dosen, $sks, $semester, $jurusan, $kelas, $hari, $ruang, $waktu, $sm, $tahun){
		    $sql = "insert into tbuas (idmatakuliah, matakuliah, dosen, sks, semester, jurusan, kelas, hari, ruang, waktu, sm, tahun, hadir, seharusnya, tidakhadir, tambahan) values ('".$idmatakuliah."', '".$matakuliah."', '".$dosen."', '".$sks."', '".$semester."', '".$jurusan."', '".$kelas."', '".$hari."', '".$ruang."', '".$waktu."', '".$sm."', '".$tahun."', 0, 0, 0, 0)";
			//echo $sql;
		    $this->query = $this-> execute($sql,''); 
		}
		function edit_jadwal_uas($id, $idmatakuliah, $matakuliah, $dosen, $sks, $semester, $jurusan, $kelas, $hari, $ruang, $waktu, $sm, $tahun){
		    $sql = "update tbuas set idmatakuliah = '".$idmatakuliah."', matakuliah= '".$matakuliah."', dosen = '".$dosen."', sks='".$sks."', semester='".$semester."', jurusan='".$jurusan."', kelas='".$kelas."', hari='".$hari."', ruang='".$ruang."', waktu='".$waktu."', sm='".$sm."', tahun='".$tahun."' where id ='".$id."'";
		    $this->query = $this-> execute($sql,''); 
		}
		function delete_jadwal($id){
		    $sql = "delete from tbuas where id = '".$id."'";
		    $this->query = $this-> execute($sql,''); 
		}
	}
?>	