<?php
 session_start();
 include "header.php";
 include "sidebar.php";
 
 ?>
<script type="text/javascript">
  
 function hanyaAngka(evt) {
   var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
 
     return false;
   return true;
 }
 
 function validasiEkstensi(){
    var inputFile = document.getElementById('ffoto');
    var pathFile = inputFile.value;
    var ekstensiOk = /(\.png)$/i;
	
	var size=3048576; // ukuran 3MB
	var file_size=document.getElementById('ffoto').files[0].size;
	if(file_size>=size){
		alert('File logo terlalu besar');
		inputFile.value = '';
		document.getElementById('fotosiswa').innerHTML ="";
		return false;
		
	};
		
    if(!ekstensiOk.exec(pathFile)){
        alert('Silahkan upload file logo yang sesuai dengan ekstensi .png');
        inputFile.value = '';
		document.getElementById('fotosiswa').innerHTML ="";
        return false;
    }else{
        // Preview gambar
		
        if (inputFile.files && inputFile.files[0]) {
            var reader = new FileReader();
            reader.onload = function(e) {
                document.getElementById('fotosiswa').innerHTML = '<img src="'+e.target.result+'" style="height:100px"/>';
            };
            reader.readAsDataURL(inputFile.files[0]);
        }
    }
}


</script>
 
  <main id="main" class="main">

    <div class="pagetitle">
      <h1>Dashboard</h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="index.php">Home</a></li>
          <li class="breadcrumb-item active">Seting Cetak</li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    
			
			   
                 <?php
				
					include 'config.php';
					$aa= mysqli_query($mysqli,"SELECT Idcetak,logo FROM print");
					$kop= mysqli_fetch_array($aa);
					$kodecetak=$kop['Idcetak'];
					$logo="assets/img/".$kop['logo'];
					
				
				?>	
					
       <section class="section">
      <div class="row">
        <div class="col-lg-12">
    
		 <div class="card info-card customers-card">
		 <h5 class="card-title">Seting Logo</h5>
		 <?php
			if (isset($_GET['ed'])) {
					echo "<p><font color='green'>Logo berhasil di update.</font></p>";
						echo "<br> ";
				}	
		 ?>

		              
              <!-- Horizontal Form -->
              <form name="edit" method="post" action="editlogoAction.php" enctype="multipart/form-data">
                 <input type="hidden" class="form-control" name="ikodecetak" id="ikodecetak" width="100" value="<?php echo $kodecetak ?>" >
                 <table>
                  <tr>
					<td width="200">Logo </td>
					<td> <div class="col-sm-10"> <?php echo "<img src=\"$logo\" height=\"100\">" ?>  </div></td>
                  </tr>
				  <tr>
					<td>Pilih Logo Baru </td>
					<td> 
					    <div class="form-group">
						  <input type="file" class="form-control-file" name="ffoto" id="ffoto" onchange="return validasiEkstensi()" required>
						  <p style="color: red">Ekstensi yang diperbolehkan .png </p>
						  <div id="fotosiswa"> </div>
							<br> 
						</div>
						</div>
					</td>
                  </tr>
				 <tr>
					<td></td>
					<td> <button type="submit" name="update" class="btn btn-primary">&nbsp;&nbsp;&nbsp;Simpan&nbsp;&nbsp;&nbsp;</button></td>
                  </tr>
                  </table> 
                 
                   
                
               
               
				
				
				
             
			<?php
					
				?>
             

            
           
        </div><!-- End Left side columns -->

      
      </div>
    </section>
<?php
 include "footer.php";
?>
 