<style>
img{
	border-radius: 50%;
	width:45px;
	height:45px;
}
</style>

<?php
require("../config/koneksi.php");
require("../config/function.php");
require("../config/crud.php");
$id_siswa = (isset($_SESSION['id_siswa'])) ? $_SESSION['id_siswa'] : 0;

if (isset($_GET['pg'])) {
	$pg = $_GET['pg'];
	if ($pg == 'waktu') {
		echo $waktu;
	} elseif ($pg == 'log') {
		$logC = 0;
		echo "<div class='direct-chat-messages' style='height:490px'>";
		$logQ = mysqli_query($koneksi, "SELECT * FROM log ORDER BY date DESC limit 6");
		while ($log = mysqli_fetch_array($logQ)) {
			$logC++;
			$siswa = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_siswa='$log[id_siswa]'"));
			if($siswa['jenis_kelamin']=='Laki-laki' AND $siswa['foto']==''){
			$grade	="<img src='../dist/img/laki.png' width=45>"; 
			}else if($siswa['jenis_kelamin']=='Laki-laki' AND $siswa['foto']<>''){
			$grade	="<img src='../foto/fotosiswa/$siswa[foto]' width=45>";	
			}else if($siswa['jenis_kelamin']=='Perempuan' AND $siswa['foto']==''){
				$grade	="<img src='../dist/img/prp.png' width=45>";
			}else if($siswa['jenis_kelamin']=='Perempuan' AND $siswa['foto']<>''){
				$grade	="<img src='../foto/fotosiswa/$siswa[foto]' >";	
			}				
			if ($log['type'] == 'login' || $log['type'] == 'logout') {
				
				?>
					
                              <div class="alert alert-custom" role="alert">
                                                    <div class="custom-alert-icon icon-success">
													<?= $grade ?>
													</div>
                                                    <div class="alert-content">
                                                        <span class="alert-title"><?= $siswa['nama'] ?></span>
                                                        <span><?= timeAgo($log['date']) ?> </span>
														<span class="badge badge-primary"><?= ucfirst($log['text']) ?></span>
														
                                                    </div>
                                                </div>
		                  	<?php }else{ ?>							
												
								 <div class="alert alert-custom" role="alert">
                                                    <div class="custom-alert-icon icon-success">
													<?= $grade ?>
													</div>
                                                    <div class="alert-content">
                                                        <span class="alert-title"><?= $siswa['nama'] ?></span>
                                                        <span class="alert-text"><?= timeAgo($log['date']) ?></span>
														<span class="badge badge-warning"><?= ucfirst($log['text']) ?></span>
														
                                                    </div>
                                                </div>				
                                        
	<?php } } ?>		
		
		<?php
		$id_user = (isset($_SESSION['id_user'])) ? $_SESSION['id_user'] : 0;
		} elseif ($pg == 'logguru') {
		$logC = 0;
		
		echo "<div class='direct-chat-messages' style='height:490px'>";
		$logQ = mysqli_query($koneksi, "SELECT * FROM log_guru ORDER BY date DESC limit 6");
		while ($logg = mysqli_fetch_array($logQ)) {
			$logC++;
			$guru = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM users WHERE id_user='$logg[id_user]' "));
			if($guru['foto']==''){
			$gra	="<img src='../dist/img/guru.png' width=45>"; 
			}else{
			$gra	="<img src='../$guru[foto]' width=45>";	
			
			}				
			
			if ($logguru['type'] == 'login' || $logg['type'] == 'logout') {
			
		?>
             <div class="alert alert-custom" role="alert">
                      <div class="custom-alert-icon icon-success">
				<?= $gra ?> 
							</div>
                                  <div class="alert-content">
                          <span class="alert-title"><?= $guru['nama'] ?> </span>
                       <span><?= timeAgo($logg['date']) ?> </span>
               <span class="badge badge-danger"><?= ucfirst($logg['text']) ?> </span>
														
                       </div>
               </div>
			   <?php }else{ ?>	
			   
			    <div class="alert alert-custom" role="alert">
                      <div class="custom-alert-icon icon-success">
				<?= $gra ?>  
							</div>
                                  <div class="alert-content">
                          <span class="alert-title"><?= $guru['nama'] ?> </span>
                       <span><?= timeAgo($logg['date']) ?> </span>
               <span class="badge badge-primary"><?= ucfirst($logg['text']) ?> </span>
														
                       </div>
               </div>
		<?php } } ?>
<?php
} elseif ($pg == 'pengumuman') {
		$logC = 0;
		
		$logQ = mysqli_query($koneksi, "SELECT * FROM pengumuman ORDER BY date DESC");

		while ($log = mysqli_fetch_array($logQ)) {
			$logC++;
			$user = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM users WHERE id_user='$log[user]'"));
			
			?>
			
                                <div class="card widget widget-connection-request">
                                    <div class="card-header">
                                        <h5 class="card-title"><?= $log['judul'] ?> <small> <?= $user['nama'] ?></small><span class="badge badge-secondary badge-style-light"><?= buat_tanggal('d-m-Y', $log['date']) ?> <?= buat_tanggal('h:i', $log['date']) ?></span></h5>
                                    </div>
                                    <div class="card-body">
                                        <div class="widget-connection-request-container d-flex">
                                            
                                            <div class="widget-connection-request-info flex-grow-1">
                                                <span class="widget-connection-request-info-name">
                                                  <?= ucfirst($log['text']) ?>
                                                </span>
                                                
                                            </div>
                                        </div>
                                        
                                    </div>
                                </div>
                          
			
<?php } } } ?>
