<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-body">
	
	<div class="page-header">
			<h2>Biodata</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-user"> Biodata </i></li>
            </ol>
		</div>



<?php


error_reporting(0);
if(isset($_POST['button'])){
	if($_SESSION['jabatan']=='admin')
	{
		$fileName = $_FILES['gambar']['name'];
		move_uploaded_file($_FILES['gambar']['tmp_name'], "asset/img/user/".$_FILES['gambar']['name']);
				$sc2=sprintf("Update user Set gambar='$fileName' Where id_user='".$_SESSION['id_user']."'");
				$q2=mysql_query($sc2);
				if($q2){
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=1";</script><?php
				}else{
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=0";</script><?php
				}
	}else if($_SESSION['jabatan']=='perusahaan')
	{
		$fileName = $_FILES['gambar']['name'];
		move_uploaded_file($_FILES['gambar']['tmp_name'], "asset/img/user/".$_FILES['gambar']['name']);
				$sc2=sprintf("Update perusahaan Set gambar='$fileName' Where id_perusahaan='".$_SESSION['id_perusahaan']."'");
				$q2=mysql_query($sc2);
				if($q2){
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=1";</script><?php
				}else{
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=0";</script><?php
				}
	}else if($_SESSION['jabatan']=='panitia')
	{
		$fileName = $_FILES['gambar']['name'];
		move_uploaded_file($_FILES['gambar']['tmp_name'], "asset/img/user/".$_FILES['gambar']['name']);
				$sc2=sprintf("Update user Set gambar='$fileName' Where id_user='".$_SESSION['id_user']."'");
				$q2=mysql_query($sc2);
				if($q2){
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=1";</script><?php
				}else{
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=0";</script><?php
				}
	}
}



if(isset($_POST['submit']))
{
	if($_SESSION['jabatan']=='admin')
	{
	
			$sc2=sprintf("Update user Set nama='".$_POST['nama']."', username='".$_POST['username']."' Where id_user='".$_SESSION['id_user']."'");
				$q2=mysql_query($sc2);
				if($q2){
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=1";</script><?php
				}else{
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=0";</script><?php
				}
	}else if($_SESSION['jabatan']=='perusahaan')
	{
		$sc2=sprintf("Update perusahaan Set nama='".$_POST['nama']."', username='".$_POST['username']."' Where id_perusahaan='".$_SESSION['id_perusahaan']."'");
				$q2=mysql_query($sc2);
				if($q2){
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=1";</script><?php
				}else{
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=0";</script><?php
				}
	}
	else if($_SESSION['jabatan']=='panitia')
	{
		$sc2=sprintf("Update user Set nama='".$_POST['nama']."', username='".$_POST['username']."' Where id_user='".$_SESSION['id_user']."'");
				$q2=mysql_query($sc2);
				if($q2){
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=1";</script><?php
				}else{
					?><script language="javascript">document.location.href="?cat=web&page=profil&sukses=0";</script><?php
				}
	}
				
}


$sukses1 = (isset($_GET['sukses'])&& $_GET['sukses'] =='1');
if($sukses1){
?> 
					<div class="row">
					<div class="col-xs-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 diubah</center>
					
					</div></div></div>
<?php
}

$sukses0 = (isset($_GET['sukses'])&& $_GET['sukses'] =='0');
if($sukses0){
?> 
					<div class="row">
					<div class="col-xs-offset-2 col-md-8">
					<div class="alert alert-danger  alert-dismissable">
					<button type="button" class="close" data-dismiss="alert">x</button>
						<center>Data Gagal diubah</center>
					
					</div></div></div>
<?php
}
	
	
	
?>

<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>

<div class="col-md-12">
	<div class="col-md-5">
 		<?php
		echo "<td><a href='#'><img id='blah' src='./asset/img/user/".$row['gambar']."'  width='100%' class='img-circle'/></a></td>";
		?>
 		<p></p>
 		<script>
			function change(id,vis){
			document.getElementById (id).style.display=vis;
			}
		</script>
		<div style="display:inline" id="super" onclick="change ('qu','block');change ('super','none');">
			<button type="button" class="btn btn-success btn-lg btn-block">Ganti Foto</button>
		</div>

		<div style="display:none" id="qu" onclick="change ('super','none');change ('qu','qu');">		
 			<form id="test" class="form-horizontal"  runat="server" method="post" action="" enctype="multipart/form-data">
 			<div class="form-group">
				<label for="foto" class=" col-md-4 control-label">Pilih Foto:</label>
				<div class="col-md-4">
					<input type="file" id="gambar" name="gambar" onchange="readURL(this);" required>
				</div>
			</div>
			<button name="button" id="button" type="submit" class="btn btn-success btn-lg btn-block">Ubah</button>
			</form>
		</div>
	</div>

<div class="col-md-7">
	<div class="panel panel-info">
		<div class="panel-heading">
		<h4 align="center"><i class="fa fa-user"> Biodata </i></h4>
		</div>
		<div class="panel-body">
			<table class="table table-striped">
				<thead>
					<tr>
    					<td align="center">Nama</td>
						<td align="center"> <?php echo $row['nama']; ?> </td>
					</tr>
					<tr>
   						<td align="center">Jabatan</td>
						<td align="center"> <?php echo $row['jabatan']; ?> </td>
					</tr>
					
					<?php
					if($_SESSION['jabatan']=='perusahaan')
					{
					?>
					<tr>
   						<td align="center">Alamat</td>
						<td align="center"> <?php echo $row['alamat']; ?> </td>
					</tr>
					<tr>
   						<td align="center">Telepon</td>
						<td align="center"> <?php echo $row['telepon']; ?> </td>
					</tr>
					<tr>
   						<td align="center">Email</td>
						<td align="center"> <?php echo $row['email']; ?> </td>
					</tr>
					<?php
					}
					?>
					<tr>
   						<td align="center">Username</td>
						<td align="center"> <?php echo $row['username']; ?> </td>
					</tr>
				</thead>
			</table>
		</div>
	</div>
</div>

<div class="col-md-7">
 <button data-toggle="modal" data-target="#myModal"class="btn btn-lg btn-block btn-primary"> Ubah</button>     
</div>


</div>



<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Ubah Biodata</h4>
      </div>
      <div class="modal-body">

      <form class="form-horizontal" action="" method="post" name="a">
		<div class="form-group">
       		<label for="nama" class="col-xs-4 control-label">Nama</label>
      		<div class="col-md-6">
        		<input type="text" class="form-control" id="nama" name="nama" value="<?php echo $row['nama']; ?>" required > 
      		</div>
      	</div>
      	<?php
		if($_SESSION['jabatan']=='perusahaan')
		{?>
			<div class="form-group">
       		<label for="alamat" class="col-xs-4 control-label">Alamat</label>
      		<div class="col-md-6">
        		  <textarea class="form-control" rows="3" name="alamat" id="alamat" required><?php echo $row['alamat']; ?></textarea>
  	</div>
      	</div>
      	<div class="form-group">
       		<label for="telepon" class="col-xs-4 control-label">Telepon</label>
      		<div class="col-md-6">
        		<input type="text" class="form-control" id="telepon" name="telepon" value="<?php echo $row['telepon']; ?>" required > 
      		</div>
      	</div>
      	<div class="form-group">
       		<label for="email" class="col-xs-4 control-label">Email</label>
      		<div class="col-md-6">
        		<input type="text" class="form-control" id="email" name="email" value="<?php echo $row['email']; ?>" required > 
      		</div>
      	</div>
      	
      	<?php
		}
		?>
      	<div class="form-group">
      		<label for="nama" class="col-xs-4 control-label">Username</label>
      		<div class="col-md-6">
        		<input type="text" class="form-control" id="username" name="username" value="<?php echo $row['username']; ?>" required > 
      		</div>
   		</div> 
   		</div> 
      <div class="modal-footer">
        <button type="submit" name="submit" id="submit" class="btn btn-primary">Update</button>
        </form> 
      </div>
    
    </div>
  </div>
</div>






</div> </div> </div>

