<?php
$namaku=$this->session->userdata('nama');
$username=$this->session->userdata('user_id');
$result=$this->db->query("SELECT * FROM web_setting WHERE id='1'");
foreach ($result->result() as $baris)  {
$nama=$baris->nama;
$alamat=$baris->alamat;
$telp=$baris->telp;
$email=$baris->email;
$logo=$baris->logo;
$back=$baris->back;
$tapel=$baris->tapel;
$kop=$baris->kop;
$namakepsek=balikin($baris->namakepsek);
$nipkepsek=$baris->nipkepsek;
$penilaian=$baris->penilaian;
$kabupaten=$baris->kabupaten;
$jam_masuk=$baris->jam_masuk;
$batas_jam=$baris->batas_jam;
$jam_pulang=$baris->jam_pulang;
$batas_pulang=$baris->batas_jampulang;
$latx=$baris->lat_x;
$laty=$baris->lat_y;
$radius=$baris->radius;
$latx2=$baris->lat_x2;
$laty2=$baris->lat_y2;
}

?>

<section class="content-header">

	<h1>

		Setting Aplikasi

	</h1>

	<ol class="breadcrumb">

		<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>

		<li class="active">Setting</li>

	</ol>

</section>



<section class="content">

	<div class="row">

        <div class="col-md-12">

            <div class="box box-primary">

                <div class='box-header with-border'>

					  <h3 class="box-title">Edit Setting</h3>

					</div>

					<div class="box-body">

						<form action="" method="post" enctype="multipart/form-data" class="form-horizontal">

							<div class="form-body">

								<div class="form-group">

									<label class="control-label col-md-3">Nama Instansi</label>

									<div class="col-md-9">

										<input name="nama" placeholder="Nama Instansi" class="form-control" type="text" value="<?php echo $nama;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Alamat Instansi</label>

									<div class="col-md-9">

										<input name="alamat" placeholder="Alamat Instansi" class="form-control" type="text" value="<?php echo $alamat;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Kabupaten</label>

									<div class="col-md-9">

										<input name="kabupaten" placeholder="Masukkan Kabupaten" class="form-control" type="text" value="<?php echo $kabupaten;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Telepon</label>

									<div class="col-md-9">

										<input name="telepon" placeholder="No Telepon/HP" class="form-control" type="text" value="<?php echo $telp;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Email</label>

									<div class="col-md-9">

										<input name="email" placeholder="Email Instansi" class="form-control" type="text" value="<?php echo $email;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Logo</label>



									<div class="col-md-9">

										<img src="<?php echo base_url('assets/back/'.$logo.'');?>" width="100" height="100" />

										<input id="file-id" type="file" name="filelogo" class="form-control" data-show-upload="false" data-show-remove="false">

										<input name="logoku" type="hidden" value="<?php echo $logo;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Background</label>



									<div class="col-md-9">

										<img src="<?php echo base_url('assets/back/'.$back.'');?>" width="200" height="100" />

										<input id="file-id2" type="file" name="fileback" class="form-control" data-show-upload="false" data-show-remove="false">

										<input name="backku" type="hidden" value="<?php echo $back;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Nama Kepala Instansi</label>

									<div class="col-md-9">

										<input name="namakepsek" placeholder="Nama Kepala Instansi" class="form-control" type="text" value="<?php echo $namakepsek;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">NIP Kepala Instansi</label>

									<div class="col-md-9">

										<input name="nipkepsek" placeholder="Nama Kepala Instansi" class="form-control" type="text" value="<?php echo $nipkepsek;?>">

										<span class="help-block"></span>

									</div>

								</div>
								<!--
								<div class="form-group">

									<label class="control-label col-md-3">Mulai Absen Masuk</label>

									<div class="col-md-9">

										<input name="mulai_masuk" placeholder="Mulai Jam Masuk" class="form-control" type="text" value="04:00:00" readonly>

										<span class="help-block"></span>

									</div>

								</div>


								<div class="form-group">

									<label class="control-label col-md-3">Batas Masuk Terlambat</label>

									<div class="col-md-9">

										<input name="jam_masuk" placeholder="Jam Masuk" class="form-control" type="text" value="<?php echo $jam_masuk;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Batas Jam Masuk</label>

									<div class="col-md-9">

										<input name="batas_jam" placeholder="Batas Jam Masuk" class="form-control" type="text" value="<?php echo $batas_jam;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Jam Pulang</label>

									<div class="col-md-9">

										<input name="jam_pulang" placeholder="Jam Pulang" class="form-control" type="text" value="<?php echo $jam_pulang;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Batas Jam Pulang</label>

									<div class="col-md-9">

										<input name="batas_jampulang" placeholder="Jam Pulang" class="form-control" type="text" value="<?php echo $batas_pulang;?>">

										<span class="help-block"></span>

									</div>

								</div>
							-->
								<div class="form-group">

									<label class="control-label col-md-3">Koordinat X</label>

									<div class="col-md-9">

										<input name="latx" placeholder="KoordinatX" class="form-control" type="text" value="<?php echo $latx;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Koordinat Y</label>

									<div class="col-md-9">

										<input name="laty" placeholder="KoordinatY" class="form-control" type="text" value="<?php echo $laty;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Radius</label>

									<div class="col-md-9">

										<input name="radius" placeholder="Radius dalam Meter" class="form-control" type="text" value="<?php echo $radius;?>">

										<span class="help-block"></span>

									</div>

								</div>
								<div class="form-group">

									<label class="control-label col-md-3">Koordinat X2</label>

									<div class="col-md-9">

										<input name="latx2" placeholder="KoordinatX" class="form-control" type="text" value="<?php echo $latx2;?>">

										<span class="help-block"></span>

									</div>

								</div>

								<div class="form-group">

									<label class="control-label col-md-3">Koordinat Y2</label>

									<div class="col-md-9">

										<input name="laty2" placeholder="KoordinatY" class="form-control" type="text" value="<?php echo $laty2;?>">

										<span class="help-block"></span>

									</div>

								</div>
							</div>

							<div class="form-group">

							<div class="col-md-3">

							</div>

							<div class="col-md-9">

								<button type="submit" name="btnsave" class="btn btn-primary">

								<span class="glyphicon glyphicon-save"></span> &nbsp; Simpan

								</button>



							</div>

							</div>

						</form>



					</div>

				</div>



			</div>

		</div>

</section>

<?php

	if(isset($_POST['btnsave']))

 {

  $nama = $_POST['nama'];

  $alamat = $_POST['alamat'];

  $kabupaten = $_POST['kabupaten'];

  $telp = $_POST['telepon'];

  $email = $_POST['email'];

  $namakepsek = cegah($_POST['namakepsek']);

  $nipkepsek = $_POST['nipkepsek'];

  /*$jam_masuk = $_POST['jam_masuk'];

  $batas_jam = $_POST['batas_jam'];

  $jam_pulang = $_POST['jam_pulang'];

	$batas_jampulang = $_POST['batas_jampulang'];*/

	$latx = $_POST['latx'];

	$laty = $_POST['laty'];
	$latx2 = $_POST['latx2'];

	$laty2 = $_POST['laty2'];
	$radius = $_POST['radius'];

  $imgFilelogo = $_FILES['filelogo']['name'];

  $tmp_dirlogo = $_FILES['filelogo']['tmp_name'];

  $imgFileback = $_FILES['fileback']['name'];

  $tmp_dirback = $_FILES['fileback']['tmp_name'];



  if(empty($nama)){

   $errMSG = "Please Enter Nama.";

  }

  else if(empty($alamat)){

   $errMSG = "Please Enter Alamat.";

  }

  else if(empty($telp)){

   $errMSG = "Please Enter Telepon.";

  }

  else if(empty($email)){

   $errMSG = "Please Enter Email.";

  }



	if(empty($imgFilelogo))

	{

		$logopic=$_POST['logoku'];

	}

	else

	{

	   $upload_dir = './assets/back/'; // upload directory

	   $imgExt = strtolower(pathinfo($imgFilelogo,PATHINFO_EXTENSION));

	   $valid_extensions = array('jpeg', 'jpg', 'png', 'gif');

	   $logopic = rand(1000,1000000).".".$imgExt;

	   move_uploaded_file($tmp_dirlogo,$upload_dir.$logopic);

	}



	if(empty($imgFileback))

	{

		$backpic=$_POST['backku'];

	}

	else

	{

	   $upload_dir = './assets/back/'; // upload directory

	   $imgExt = strtolower(pathinfo($imgFileback,PATHINFO_EXTENSION));

	   $valid_extensions = array('jpeg', 'jpg', 'png', 'gif');

	   $backpic = rand(1000,1000000).".".$imgExt;

	   move_uploaded_file($tmp_dirback,$upload_dir.$backpic);



	}





  if(!isset($errMSG))

  {

	  $result=$this->db->query("UPDATE web_setting SET nama ='$nama', alamat='$alamat',

			telp='$telp', email='$email', logo='$logopic', back='$backpic',
			namakepsek='$namakepsek', nipkepsek='$nipkepsek',
			kabupaten='$kabupaten', lat_x='$latx', lat_y='$laty', radius='$radius', lat_x2='$latx2', lat_y2='$laty2' WHERE id='1'");



	  header("refresh:1;setting");

  }

 }



?>
