<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
if(!$statuslogin) exit;
$mod = basename(__FILE__, '.php');
$page->tbJs($mod);
if(isset($_GET['id'])){
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Nama Pelajaran/Kegiatan Baru");
	$nama="";
	$kode="";
	$idjenis=0;
	$idsekolah=0;
	if($id>0){
		$page->setJudul("Edit Nama Pelajaran/Kegiatan");
		$query="SELECT t1.`id`,
			t1.idsekolah,
			t1.`idjenis`,
			t1.`kode`,
			t1.`nama`,
			t1.`status`,
			t2.nama as namajenis
		FROM tb_pelajaran as t1
		inner join tb_jenis_pelajaran as t2 on t1.idjenis=t2.id
		WHERE t1.id=? ";
		$rs=$db->loadAssoc($query,array($id));
		if(isset($rs['id'])){
			$nama=$rs['nama'];
			$kode=$rs['kode'];
			$idjenis=$rs['idjenis'];
			$idsekolah=$rs['idsekolah'];
		}
	}
	$page->addLoad("masterpelajaran.edit(".json_encode(array('id'=>$id,"idjenis"=>$idjenis,
		"idsekolah"=>$idsekolah)).")");
	?>
	<div class="box_main_konten">
	<div class="group_form">
		<title>Sekolah</title>
		<div class="col10">
			<select id="sl_sekolah">
				<?php
				$arrpush=array();
				$wh="";
				if($_SESSION['profile']['modesekolah']==1){
					$wh.="where id=? ";
					array_push($arrpush,$_SESSION['profile']['idsekolah']);
				}
				
				$query="select * from tb_jenis_sekolah ".$wh."order by id asc";
				$rs=$db->getObj($query,$arrpush);
				foreach ($rs as $obj) {
					?>
					<option value="<?php echo $obj->id;?>"><?php echo $obj->nama;?></option>
					<?php
				}
				?>
			</select>
			
		</div>
	</div>
	<div class="group_form">
		<title>Jenis</title>
		<div class="col10">
			<select id="sl_jenis">
				<?php
				$query="select * from tb_jenis_pelajaran order by id asc";
				$rsl=$db->getObj($query);
				foreach ($rsl as $obj) {
					?>
					<option value="<?php echo $obj->id;?>"><?php echo $obj->nama;?></option>
					<?php
				}
				?>
			</select>
		</div>
	</div>
	<div class="group_form">
		<title>Kode</title>
		<div class="col10"><input id="kode" value="<?php echo $kode;?>" />
			
		</div>
	</div>
	<div class="group_form">
		<title>Nama</title>
		<div class="col10"><input id="nama" value="<?php echo $nama;?>" />
			
		</div>
	</div>
	<div style="clear: both"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_level_err" class="error"></div>
		<span class="btmerah btncancel" onclick="masterpelajaran.kembali()">Kembali</span>&nbsp;&nbsp;<span onclick="masterpelajaran.simpan()" class="bthijau btnsave">Simpan</span>
	</div>
	<?php
}else{
	$page->addLoad("masterpelajaran.load()");
	$page->setJudul("Master Data Pelajaran/Kegiatan");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="masterpelajaran.loade()">
			<option value="30">30</option>
			<option value="50">50</option>
			<option value="100">100</option>
		</select> &nbsp;
		Hal: <select id="hal_ke" class="slkecil" onchange="masterpelajaran.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama Pelajaran" onkeypress="masterpelajaran.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="masterpelajaran.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="masterpelajaran.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_masterpelajaran"></div>
	<div class="box_button_bawah">
		<span onclick="masterpelajaran.buat(0)" class="bthijau btninput">Input Nama Pelajaran/Kegiatan Baru</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="icon_del" onclick="masterpelajaran.hapus(#{id})"></span>
		<span class="icon_edit" onclick="masterpelajaran.buat(#{id})"></span>
	</div>
	<span id="btstatus" style="display: none" class="#(#{status}==1)?'mini_ok':'mini_dis'#" onclick="masterpelajaran.status(#{id},##{jumlah_tabel},##{baris_tabel},this)" class="bthijau btninput"></span>
	<?php
}
?>
