<?php
include "asset/fungsi/fungsi_indotgl.php";
include "asset/fungsi/fungsi_rupiah.php";
?>
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-body">

	<div class="page-header">
			<h2>Pengaturan Aplikasi</h2>
			<ol class="breadcrumb">

				<li><a href="dashboard.php"><i class="fa fa-home"> Home</i></a></li>
				<li class="active"><i class="fa fa-tasks"> Pengaturan Aplikasi </i></li>
            </ol>
	</div>
	
<?php



if(isset($_POST['tambah']))
{
	$rs1=mysql_query("UPDATE setting SET value='".$_POST['nama']."' WHERE id =1");
  $rs2=mysql_query("UPDATE setting SET value='".$_POST['alamat']."' WHERE id =2");
  $rs3=mysql_query("UPDATE setting SET value='".$_POST['telepon']."' WHERE id =3");
  $rs4=mysql_query("UPDATE setting SET value='".$_POST['email']."' WHERE id =4");
  $rs5=mysql_query("UPDATE setting SET value='".$_POST['facebook']."' WHERE id =5");
  $rs6=mysql_query("UPDATE setting SET value='".$_POST['twitter']."' WHERE id =6");
  $rs7=mysql_query("UPDATE setting SET value='".nl2br($_POST['syarat'])."' WHERE id =7");
  $rs9=mysql_query("UPDATE setting SET value='".$_POST['slogan']."' WHERE id =9");

  if (!empty($_FILES['logo']['name'])) 
  {
    $fileName = $_FILES['logo']['name'];
  move_uploaded_file($_FILES['logo']['tmp_name'], "asset/img/".$_FILES['logo']['name']);
  $rs8=mysql_query("UPDATE setting SET value='$fileName' WHERE id =8");
  }
  
	if($rs1 && $rs2 && $rs3 && $rs4 && $rs5 && $rs6 && $rs7 || $rs8)
	{
		?>
      <div class="row">
          <div class="col-md-offset-2 col-md-8">
          <div class="alert alert-success  alert-dismissable">
          <button type="button" class="close" data-dismiss="alert">x</button>
            <center>Data Berhasil ditambahkan</center>
          
          </div></div></div>
    <?php
	}else
	{
		?>
      <div class="row">
          <div class="col-md-offset-2 col-md-8">
          <div class="alert alert-danger  alert-dismissable">
          <button type="button" class="close" data-dismiss="alert">x</button>
            <center>Terjadi kesalahan <?php echo mysql_error();?></center>
          
          </div></div></div>
    <?php
	}
  
}



$query=mysql_query("SELECT * FROM setting WHERE id=1");
$data=mysql_fetch_array($query);
if ($data['value'] == NULL) 
{
  $nama = "";
}else{
  $nama = $data['value'];
}



$query=mysql_query("SELECT * FROM setting WHERE id=2");
$data=mysql_fetch_array($query);
if ($data['value'] == NULL) 
{
  $alamat = "";
}else{
  $alamat = $data['value'];
}

$query=mysql_query("SELECT * FROM setting WHERE id=3");
$data=mysql_fetch_array($query);
if ($data['value'] == NULL) 
{
  $telepon = "";
}else{
  $telepon = $data['value'];
}

$query=mysql_query("SELECT * FROM setting WHERE id=4");
$data=mysql_fetch_array($query);
if ($data['value'] == NULL) 
{
  $email = "";
}else{
  $email = $data['value'];
}

$query=mysql_query("SELECT * FROM setting WHERE id=5");
$data=mysql_fetch_array($query);
if ($data['value'] == NULL) 
{
  $facebook = "";
}else{
  $facebook = $data['value'];
}

$query=mysql_query("SELECT * FROM setting WHERE id=6");
$data=mysql_fetch_array($query);
if ($data['value'] == NULL) 
{
  $twitter = "";
}else{
  $twitter = $data['value'];
}

$query=mysql_query("SELECT * FROM setting WHERE id=7");
$data=mysql_fetch_array($query);
if ($data['value'] == NULL) 
{
  $syarat = "";
}else{
  $syarat = str_replace("<br />", "", $data['value']);
}

$query=mysql_query("SELECT * FROM setting WHERE id=8");
$data=mysql_fetch_array($query);
if ($data['value'] == NULL) 
{
  $logo = "";
}else{
  $logo = $data['value'];
}

$query=mysql_query("SELECT * FROM setting WHERE id=9");
$data=mysql_fetch_array($query);
if ($data['value'] == NULL) 
{
  $slogan = "";
}else{
  $slogan = $data['value'];
}


?>


<form class="form-horizontal" id="paket" action="dashboard.php?cat=web&page=setting" method="post" role="form" enctype="multipart/form-data">
  
<div class="form-group">
    <label for="nama_paket" class="col-sm-3 control-label" >Nama Aplikasi</label>
      <div class="col-md-9">
         <input type="text" class="form-control" id="nama_paket" name="nama" placeholder="Nama Aplikasi"  value="<?php echo $nama;?>"  > 
      </div>
   </div>
   <div class="form-group">
    <label for="nama_paket" class="col-sm-3 control-label" >Slogan</label>
      <div class="col-md-9">
         <input type="text" class="form-control" id="nama_paket" name="slogan" placeholder="Slogan"  value="<?php echo $slogan;?>"  > 
      </div>
   </div>
   <div class="form-group">
     <label for="nama_proyek" class="col-sm-3 control-label" >Telepon</label>
      <div class="col-md-9">
      
         <input type="text" class="form-control" id="nama_proyek" name="telepon" placeholder="Telepon"  value="<?php echo $telepon;?>" > 
      </div>
   </div>
   
    
   <div class="form-group">
   <label for="kecamatan" class="col-sm-3 control-label">Email </label>
      <div class="col-md-9">
         <input type="email" class="form-control" id="kecamatan" name="email" placeholder="Email Aktif" value="<?php echo $email;?>" > 
      </div>
   </div>
    <div class="form-group">
   <label for="kecamatan" class="col-sm-3 control-label">Alamat Facebook </label>
      <div class="col-md-9">
         <input type="text" class="form-control" id="kecamatan" name="facebook" placeholder="Facebook" value="<?php echo $facebook;?>" > 
      </div>
   </div>
    <div class="form-group">
   <label for="kecamatan" class="col-sm-3 control-label">Alamat Twitter </label>
      <div class="col-md-9">
         <input type="text" class="form-control" id="kecamatan" name="twitter" placeholder="Twitter" value="<?php echo $twitter;?>" > 
      </div>
   </div>
    <div class="form-group">
   <label for="kecamatan" class="col-sm-3 control-label">Alamat Kantor </label>
      <div class="col-md-9">
         <textarea type="text" rows="3" class="form-control" id="kecamatan" name="alamat" placeholder="Alamat kantor"  ><?php echo $alamat;?></textarea>
      </div>
   </div>
   <div class="form-group">
   <label for="kecamatan" class="col-sm-3 control-label">Logo Aplikasi </label>
      <div class="col-md-9">
        <script type="text/javascript">
        function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#blah').attr('src', e.target.result);
                }

                reader.readAsDataURL(input.files[0]);
            }
        }
    </script>
        <?php
    echo "<td><a href='#'><img id='blah' src='./asset/img/".$logo."'  width='100%' class='img-responsive'/></a></td>";
    ?>
         <input type="file" class="form-control" id="gambar"  onchange="readURL(this);" name="logo" > 
      </div>
   </div>
    <div class="form-group">
   <label for="kecamatan" class="col-sm-3 control-label">Syatar dan Ketentuan </label>
      <div class="col-md-9">
         <textarea type="text" rows="15" class="form-control" id="kecamatan" name="syarat" placeholder="Alamat kantor"  ><?php echo $syarat;?></textarea>
      </div>
   </div>


   <div class="form-group">
   <label for="kecamatan" class="col-sm-3 control-label"> </label>
      <div class="col-md-9">
     <button type="submit" name="tambah" class="btn btn-primary">Simpan</button> </div>
   </div>
  
            </form>
</div></div></div>

