<div class='row'>
        <div class='col-md-12'>
            <div class='panel panel-default'>
               <div class="panel-heading" style="height:45px">
                  <h4 class='box-title'><i class="fas fa-pengawas-cog"></i> Profilku</h4></div>    
			  
			  <div class="box-body">
                    <div class="box-body no-padding ">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Profil</a></li>
                       
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab_1" >
						<br>
						<div class="panel panel-default">	
						<div class="box-body">
     <div class='col-md-1'></div>
     <div class='col-md-9'>
            <div class='box-body'>
	<form method="post" action="" enctype="multipart/form-data">
            <div class="card-body">
                    <div class="row">
						<div class="col-md-6">
                                <div class="form-group-sm">
								<?php
								$tgl=date('Y-m-d');
                            $query = mysqli_query($koneksi, "select * FROM users WHERE id_user='$_SESSION[id_user]' ");  
                            $pr = (mysqli_fetch_array($query));
                               
                            ?>
							  <center>
							<?php if($pr['foto']==''){ ?>
					  <img src="<?= $homeurl ?>/dist/img/guru.png" width="200">
							<?php }else{ ?>
					  <img src="../foto/fotoguru/<?= $pr['foto'] ?>" width="200">
					  <?php } ?>
					  </center>
					  
                    </div>
					</div>
					<div class="col-md-6">
					<div class="form-group-sm">
                        <label>Username</label>
                      <input  type="text" class="form-control" value="<?= $pr['username'] ?>" readonly />
                    <input  type="hidden" name="id" class="form-control" value="<?= $pr['id_user'] ?>"  />					  
                    </div>
					<?php if($pengawas['level']<>'admin'){ ?>
					<div class="form-group-sm">
                        <label>Password</label>
                      <input  type="text" class="form-control" name="pass" value="<?= $pr['password'] ?>" readonly />  	                                 
                    </div>
					<?php } ?>
					<div class="form-group-sm">
                        <label>Ambil Photo</label>
                      <input name="MAX_FILE_SIZE" type="hidden" value="3000000" />  
	                                  <input name="file" class="form-control" type="file" accept="image/*" capture / required>
                    </div>
					</div>
					</div>
					<div class="modal-footer">					
                  <button name="gantiphoto" type="submit" class="btn btn-success" > Ubah Profil</button>				  
                </div>
                    </form>
            </div>
              </div>
            </div>
        </div>
 
  <?php            
            if (isset($_POST['gantiphoto'])) {
				function compressImage($source, $destination, $quality) { 
   
    $imgInfo = getimagesize($source); 
    $mime = $imgInfo['mime']; 
  
    switch($mime){ 
        case 'image/jpeg': 
            $image = imagecreatefromjpeg($source); 
            break; 
        case 'image/png': 
            $image = imagecreatefrompng($source); 
            break; 
        case 'image/gif': 
            $image = imagecreatefromgif($source); 
            break; 
        default: 
            $image = imagecreatefromjpeg($source); 
    } 
	 imagejpeg($image, $destination, $quality); 
     
   
    return $destination; 
} 
				$foto = $_FILES['file']['name'];
	$tmp = $_FILES['file']['tmp_name'];
	$fotobaru = date('dmYHis').$foto;
	$path = "../foto/fotoguru/".$fotobaru;
      $guru = $_SESSION['id_user'];
				
	$query = "SELECT * FROM users WHERE id_user='".$guru."'";
		$sql = mysqli_query($koneksi, $query); 
		$data = mysqli_fetch_array($sql);

		if(is_file("../foto/fotoguru/".$data['foto'])) 
			unlink("../foto/fotoguru/".$data['foto']); 
		 $compressedImage = compressImage($tmp, $path, 32);
	mysqli_query($koneksi,"UPDATE users SET foto='$fotobaru' WHERE id_user='$guru'");
	echo "
	  <script type='text/javascript'>
		setTimeout(function () { 	
			swal({
				title: 'Sukses !!!',
				text:  'Photo Profil Berhasil diubah',
				type: 'success',
				timer: 2000,
				showConfirmButton: true
			});		
		},10);	
		window.setTimeout(function(){ 
			window.location.replace('?pg=');
		} ,2000);	
	  </script>";
	
			}
            ?>