<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
if(!$statuslogin) exit;
$mod = basename(__FILE__, '.php');
$page->tbJs($mod);
$idmodule=$db->getidmodulenama($mod);

if(isset($_GET['id'])){
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Data Peserta Baru");
	$noid="T";
	$nama="";
	$nik="";
	$idjeniskelamin=0;
	$status=0;
	$idpropinsi=0;
	$idkota=0;
	$nohp="";
	$email="";
	$alamat="";
	
	$namastatus="";
	$bg="";
	$warna="";
	
	$urutan=1;
	$qr="select max(urutan) as urutan from tb_toko_peserta where id>0";
	$rsj=$db->loadAssoc($qr);
	if(isset($rsj['urutan'])) $nomorutut=$rsj['urutan']+1;
	
	$username="";
	$idmarketing=0;
	$editstatus=1;
	if($id>0){
		$page->setJudul("Detail Data Peserta");
		
		$whp="";
		$datapushp=array($_SESSION['profile']['level'],$id);
		if($_SESSION['profile']['marketing']==1){
			$whp.="and t1.idmarketing=? ";
			array_push($datapushp,$_SESSION['profile']['idmarketing']);
		}
		
		$query="SELECT 
					t1.`id`,
					t1.`kode`,
					t1.`urutan`,
					t1.`nama`,
					t1.idjeniskelamin,
					t1.idmarketing,
					t1.`nohp`,
					t1.`email`,
					t1.`nik`,
					t1.`alamat`,
					t1.`idpropinsi`,
					t1.`idkota`,
					t1.`omset`,
					t1.`point`,
					t1.`status`,
					if(t2.propinsi is null,'BELUM',t2.propinsi) as propinsi,
					if(t3.kota is null,'BELUM',t3.kota) as kota,
					if(t4.username is null,'',t4.username) as username,
					a1.nama as namastatus,
					a1.bg,a1.warna,
					if(b1.id is null,0,1) as edit
			FROM tb_toko_peserta as t1
			left join tb_propinsi as t2 on t1.idpropinsi=t2.id
			left join tb_kota as t3 on t1.idkota=t3.id
			left join tb_username as t4 on t1.id=t4.idpeserta
			inner join tb_master_status as a1 on t1.status=a1.id 
			left join tb_master_status_level as b1 on a1.id=b1.idstatus and b1.mode=0 and b1.idlevel=?
			WHERE t1.id=? ".$whp;
		$rs=$db->loadAssoc($query,$datapushp);
		if(isset($rs['id'])){
			$noid=$rs['kode'];
			$nama=$rs['nama'];
			$nik=$rs['nik'];
			$urutan=$rs['urutan'];
			$idpropinsi=$rs['idpropinsi'];
			$idkota=$rs['idkota'];
			$nohp=$rs['nohp'];
			$email=$rs['email'];
			$alamat=$rs['alamat'];
			$username=$rs['username'];
			
			$idjeniskelamin=$rs['idjeniskelamin'];
			$idmarketing=$rs['idmarketing'];
			$status=$rs['status'];
			
			$namastatus=$rs['namastatus'];
			$bg=$rs['bg'];
			$warna=$rs['warna'];
			
			$editstatus=$rs['edit'];
		}else{
			exit;
		}
	}else{
		exit;
	}
	$datahasil=array(
		"id"=>$id,
		"idpropinsi"=>$idpropinsi,
		"idkota"=>$idkota,
		"idjeniskelamin"=>$idjeniskelamin,
		"idmarketing"=>$idmarketing,
		"level"=>$_SESSION['profile']['level'],
		"status"=>$status
	);
	$page->addLoad("pesertastatus.edit(".json_encode($datahasil,true).")");
	$disabled="disabled=\"true\"";
	if($editstatus==1){
		$disabled="";
	}
	?>
	<div class="box_main_konten">
		<h3>DATA PROFILE</h3>
		<div class="group_form" id="boxkode" style="display: none;">
			<title>ID Peserta</title>
			<div class="col10">
				<input disabled="true"  value="<?php echo $noid;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Nama</title>
			<div class="col10">
				<input id="nama" <?php echo $disabled;?> value="<?php echo $nama;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Jenis Kelamin</title>
			<div class="col10">
				<?php
					$qr="select * from tb_jenis_kelamin where id>0 order by id asc";
					$rsjk=$db->loadAll($qr);
				?>
				<select id="sl_jk" <?php echo $disabled;?>>
					<option value="0">Pilih Jenis Kelamin</option>
					<?php
					foreach ($rsjk as $obj) {
						?>
						<option value="<?php echo $obj['id'];?>"><?php echo $obj['nama'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Nomor KTP</title>
			<div class="col10">
				<input id="nik" <?php echo $disabled;?> value="<?php echo $nik;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Nomor HP</title>
			<div class="col10">
				<input id="nohp" <?php echo $disabled;?> value="<?php echo $nohp;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Email</title>
			<div class="col10">
				<input id="email" <?php echo $disabled;?> value="<?php echo $email;?>" />
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>ALAMAT</h3>
		<div class="group_form">
			<title>Alamat</title>
			<div class="col10">
				<input id="alamat" <?php echo $disabled;?> value="<?php echo $alamat;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Propinsi</title>
			<div class="col10">
				<?php
					$qr="select * from tb_propinsi where status=1 order by propinsi asc";
					$rsprop=$db->loadAll($qr);
				?>
				<select id="sl_propinsi" <?php echo $disabled;?> onchange="pesertastatus.propch()">
					<option value="0">Pilih Propinsi</option>
					<?php
					foreach ($rsprop as $obp) {
						?>
						<option value="<?php echo $obp['id'];?>"><?php echo $obp['propinsi'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		<div class="group_form">
			<title>Kota/Kabupaten</title>
			<div class="col10">
				<select id="sl_kota" <?php echo $disabled;?>></select>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	
	<div class="box_main_konten">
		<h3>USER LOGIN</h3>
		<div class="group_form">
			<title>Username</title>
			<div class="col10">
				<input id="username" <?php echo $disabled;?> value="<?php echo $username;?>" />
			</div>
		</div>
		<span id="boxpass" style="display: none;">
			<div class="group_form">
				<title>Password</title>
				<div class="col10">
					<input id="pass1" <?php echo $disabled;?> type="password"/>
				</div>
			</div>
			<div class="group_form">
				<title>Ulang Password</title>
				<div class="col10">
					<input id="pass2" <?php echo $disabled;?> type="password"/>
				</div>
			</div>
		</span>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten" id="boxmarketing" style="display: none;">
		<h3>Marketing</h3>
		<div class="group_form">
			<title>Marketing</title>
			<div class="col10">
				<select id="sl_marketing" <?php echo $disabled;?>>
					<option value="0">Tidak Ada</option>
					<?php
					$query="select * from tb_marketing where status in (select idstatus from tb_master_status_view where idmodule=? )";
					
					$rss=$db->loadAll($query,array($idmodule));
					foreach ($rss as $obs) {
						?>
						<option value="<?php echo $obs['id'];?>"><?php echo $obs['nama'];?></option>
						<?php
					}
					?>
				</select>
			</div>
		</div>
		
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten" id="boxstatus" style="display: none;">
		<h3>STATUS</h3>
		<div class="group_form">
			<title>Status Peserta</title>
			<div class="col10">
				<span id="btstatus" style="padding:8px 10px;font-size: 16px;cursor: default;background: <?php echo $bg;?>" class="medium">
					<span style="color: <?php echo $warna;?>"><?php echo $namastatus;?></span>
				</span>
			</div>
		</div>
		
		<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_pesertastatus" class="error"></div>
		<span class="btmerah btncancel" onclick="pesertastatus.kembali()">Kembali</span>&nbsp;&nbsp;
	</div>
	<?php
}else{
	$page->addLoad("pesertastatus.load()");
	$page->setJudul("Data Peserta");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="pesertastatus.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="pesertastatus.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama" onkeypress="pesertastatus.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="pesertastatus.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="pesertastatus.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_pesertastatus"></div>
	<div id="loader_datapesertastatus" class="error"></div>
	<div id="btedit" style="display:none;">
		<span class="btlihat" onclick="pesertastatus.buat(#{id})"></span>
	</div>
	<span id="btstatus" style="display: none;cursor: default;background: #{bg}" class="medium">
		<span style="color: #{warna}">#{namastatus}</span>
	</span>
	<div id="btdetailpeserta" style="display: none;">
		<div>ID <b>#{kode}</b></div>
		<div><b>#{nama}</b> - <b>#{levelpeserta}</b></div>
		<div>#{jeniskelamin}</div>
		<div style="margin-top: 3px;">
			<div><b>Alamat</b></div>
			<div>#{alamat} #{kota},#{propinsi}</div>
			<div>No HP: <b>#{nohp}</b></div>
			<div>Email: <b>#{email}</b></div>
		</div>
		<div style="margin-top: 5px;">
			<div><b>Marketing</b></div>
			<div>#{namamarketing}</div>
		</div>
	</div>
	
	<?php
}
?>
