<?php

if (isset($_POST['update'])){
	
	$lokasi_file_kiri = $_FILES['flogokiri']['tmp_name'];
  	$nama_file_kiri   = $_FILES['flogokiri']['name'];

  	$lokasi_file_kanan = $_FILES['flogokanan']['tmp_name'];
  	$nama_file_kanan  = $_FILES['flogokanan']['name'];

  	// Apabila ada gambar yang diupload
  	if (!empty($lokasi_file_kiri)){
  		
  		UploadLogoKiri($nama_file_kiri);
  		if (!empty($lokasi_file_kanan)){
  			
  			UploadLogoKanan($nama_file_kanan);
			$query = mysql_query("UPDATE identitas SET nmSekolah='$_POST[nmSekolah]',
												alamat='$_POST[alamat]',
												kabupaten='$_POST[kabupaten]',
												propinsi='$_POST[propinsi]',
												nipKepsek='$_POST[nipKepsek]',
												nmKepsek='$_POST[nmKepsek]',
												nipKaTU='$_POST[nipKaTU]',
												nmKaTU='$_POST[nmKaTU]',
												nipBendahara='$_POST[nipBendahara]',
												nmBendahara='$_POST[nmBendahara]',
												link='$_POST[link]',
												logo_kiri='$nama_file_kiri',
												logo_kanan='$nama_file_kanan'
									WHERE npsn = '$_POST[npsn]'");
		}else{
			$query = mysql_query("UPDATE identitas SET nmSekolah='$_POST[nmSekolah]',
												alamat='$_POST[alamat]',
												kabupaten='$_POST[kabupaten]',
												propinsi='$_POST[propinsi]',
												nipKepsek='$_POST[nipKepsek]',
												nmKepsek='$_POST[nmKepsek]',
												nipKaTU='$_POST[nipKaTU]',
												nmKaTU='$_POST[nmKaTU]',
												nipBendahara='$_POST[nipBendahara]',
												link='$_POST[link]',
												nmBendahara='$_POST[nmBendahara]',
												logo_kiri='$nama_file_kiri'
									WHERE npsn = '$_POST[npsn]'");
		}
	}else{
		if (!empty($lokasi_file_kanan)){
			
			UploadLogoKanan($nama_file_kanan);
			$query = mysql_query("UPDATE identitas SET nmSekolah='$_POST[nmSekolah]',
												alamat='$_POST[alamat]',
												kabupaten='$_POST[kabupaten]',
												propinsi='$_POST[propinsi]',
												nipKepsek='$_POST[nipKepsek]',
												nmKepsek='$_POST[nmKepsek]',
												nipKaTU='$_POST[nipKaTU]',
												nmKaTU='$_POST[nmKaTU]',
												nipBendahara='$_POST[nipBendahara]',
												link='$_POST[link]',
												nmBendahara='$_POST[nmBendahara]',
												logo_kanan='$nama_file_kanan'
									WHERE npsn = '$_POST[npsn]'");
		}else{
			$query = mysql_query("UPDATE identitas SET nmSekolah='$_POST[nmSekolah]',
												alamat='$_POST[alamat]',
												kabupaten='$_POST[kabupaten]',
												propinsi='$_POST[propinsi]',
												nipKepsek='$_POST[nipKepsek]',
												nmKepsek='$_POST[nmKepsek]',
												nipKaTU='$_POST[nipKaTU]',
												nmKaTU='$_POST[nmKaTU]',
												nipBendahara='$_POST[nipBendahara]',
												link='$_POST[link]',
												nmBendahara='$_POST[nmBendahara]'
									WHERE npsn = '$_POST[npsn]'");
		}
	}

	if ($query){
	  echo "<div class='col-md-12'><div class='alert alert-success alert-dismissible fade in' role='alert'> 
		  <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
		  <span aria-hidden='true'>×</span></button> <strong>Sukses!</strong> - Data telah Berhasil Disimpan..
		  </div></div>";
	}else{
	  echo "<div class='col-md-12'><div class='alert alert-danger alert-dismissible fade in' role='alert'> 
		  <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
		  <span aria-hidden='true'>×</span></button> <strong>Gagal!</strong> - Data gagal disimpan...
		  </div></div>";
	}
}
$edit = mysql_query("SELECT * FROM identitas where npsn='10700295'");
$record = mysql_fetch_array($edit);

?>

<div class="col-md-8">
  <div class="box box-warning box-solid">
	<div class="box-header with-border">
	  <h3 class="box-title"><b>Setting Sekolah</h3></b>
	</div><!-- /.box-header -->
	<div class="box-body">
		<form method="post" action="" class="form-horizontal" enctype="multipart/form-data">
			<input type="hidden" name="npsn" value="<?php echo $record['npsn']; ?>" >
			<div class="form-group">
				<label for="" class="col-sm-4 control-label">Nama Sekolah</label>
				<div class="col-sm-4">
					<input type="text" name="nmSekolah" class="form-control" value="<?php echo $record['nmSekolah']; ?>" required>
				</div>
			</div>
			<div class="form-group">
				<label for="" class="col-sm-4 control-label">Alamat Sekolah</label>
				<div class="col-sm-6">
					<input type="text" name="alamat" class="form-control" value="<?php echo $record['alamat']; ?>" required>
				</div>
			</div>
			<div class="form-group">
				<label for="" class="col-sm-4 control-label">Kabupaten/Kota</label>
				<div class="col-sm-6">
					<input type="text" name="kabupaten" class="form-control" value="<?php echo $record['kabupaten']; ?>" required>
				</div>
			</div>
			<div class="form-group">
				<label for="" class="col-sm-4 control-label">Propinsi</label>
				<div class="col-sm-6">
					<input type="text" name="propinsi" class="form-control" value="<?php echo $record['propinsi']; ?>" required>
				</div>
			</div>
			
			<div class="form-group">
				<label for="" class="col-sm-4 control-label">Nama Kepsek</label>
				<div class="col-sm-4">
					<input type="text" name="nmKepsek" class="form-control" value="<?php echo $record['nmKepsek']; ?>" required>
				</div>
			</div>
		
			<div class="form-group">
				<label for="" class="col-sm-4 control-label">Nama Ka. TU</label>
				<div class="col-sm-4">
					<input type="text" name="nmKaTU" class="form-control" value="<?php echo $record['nmKaTU']; ?>" required>
				</div>
			</div>
			
			<div class="form-group">
				<label for="" class="col-sm-4 control-label">Nama Bendahara</label>
				<div class="col-sm-4">
					<input type="text" name="nmBendahara" class="form-control" value="<?php echo $record['nmBendahara']; ?>" required>
				</div>
			</div>
			<div class="form-group">
				<label for="" class="col-sm-4 control-label">Ganti Logo Kiri</label>
				<div class="col-sm-6">
					<input type="file" name="flogokiri" class="form-control" >
				</div>
			</div>
			<div class="form-group">
				<label for="" class="col-sm-4 control-label">Ganti Logo Kanan</label>
				<div class="col-sm-6">
					<input type="file" name="flogokanan" class="form-control" >
				</div>
			</div> 
			<div class="form-group">
				<label for="" class="col-sm-4 control-label">Client Key	Midtrans</label>
				<div class="col-sm-6">
					<input type="text" name="nipBendahara" class="form-control" value="<?php echo $record['nipBendahara']; ?>" >
				</div>
			</div>
				<div class="form-group">
				<label for="" class="col-sm-4 control-label">Server Key	</label>
				<div class="col-sm-6">
					<input type="text" name="nipKaTU" class="form-control" value="<?php echo $record['nipKaTU']; ?>" >
				</div>
			</div>
			<div class="form-group">
						<label for="" class="col-sm-4 control-label">Production/Sandbox</label>
						<div class="col-sm-6">
							<select class="form-control" name="nipKepsek" >
								<option value="<?php echo $record['nipKepsek']; ?>"><?php echo $record['nipKepsek']; ?></option>
								<option value="true">Production</option>
								<option value="false">Sandbox</option>
							
							
							</select>
								<p>false untuk mode Sandbox dan true untuk mode Production</p>
						</div>
					</div>
					<div class="form-group">
						<label for="" class="col-sm-4 control-label">Link Snap JS</label>
						<div class="col-sm-6">
							<select class="form-control" name="link" >
								<option value="<?php echo $record['link']; ?>"><?php echo $record['link']; ?></option>
								<option value="https://app.sandbox.midtrans.com/snap/snap.js">Sandbox</option>
								<option value="https://app.midtrans.com/snap/snap.js">Production</option>
							
							
							</select>
								<p>false untuk mode Sandbox dan true untuk mode Production</p>
						</div>
					</div>
			
			<div class="form-group">
				<label for="" class="col-sm-4 control-label"></label>
				<div class="col-sm-8">
					<input type="submit" name="update" value="Simpan Data" class="btn btn-primary">
					
				</div>
			</div>
		</form>
	</div>
  </div>
</div>

<div class="col-md-4">
  	<div class="box box-warning box-solid">
		<div class="box-header with-border">
		  <h3 class="box-title"> Logo Kop Surat</h3>
		</div><!-- /.box-header -->
		<div class="box-body">
			<table class="table table-bordered">
				<tr class="danger">
					<th class="text-center">Logo Kiri</th>
				</tr>
				<tr>
					<td class="text-center">
						<img src="./gambar/logo/<?php echo $record['logo_kiri']; ?>" width="160px">
					</td>
				</tr>
			</table>
			<hr>
			<table class="table table-bordered">
				<tr class="success">
					<th class="text-center">Logo Kanan</th>
				</tr>
				<tr>
					<td class="text-center">
						<img src="./gambar/logo/<?php echo $record['logo_kanan']; ?>" width="160px">
					</td>
				</tr>
			</table>
		</div>
	</div>
</div>