<?php
  
  $qry=mysqli_query($mysqli,"SELECT * FROM m_gallery ORDER BY id_gallery DESC");

  echo "<h3 align=\"right\" style=\"padding-right:10px\"><a href='?action=add_album' style=\"color:#FF0066\">Tambah Album</a></h3>";
  
  if(mysqli_num_rows($qry)>0){
    
    $no=1;
    
    echo "<table width='100%' align='center' cellpadding='0' cellspacing='0' border='1' bgcolor='#C4D9FF'>";
    echo "<tr bgcolor='#fffccc'>
        <th width='5%'>No.</th>
        <th>Sampul Album</th>
		<th>Judul Album</th>
		<th>Ringkasan</th>
		<th>Jumlah Foto</th>
		<th>Tanggal</th>
        <th width='10%'>Opsi</th>
        </tr>"; 
    while($data=mysqli_fetch_array($qry)){
      if(!empty($data["foto_album"])){
        $foto="<img src='../foto_berita/$data[foto_album]' width='80' height='60'/>";
      }else{
        $foto="";
      }
	  
	  //menghitung jumlah foto di album ini
	  
	  $qa=mysqli_query($mysqli, "SELECT * FROM t_gallery WHERE id_gallery='$data[id_gallery]'");
	  $jum_foto=mysqli_num_rows($qa);
	  
      echo "<tr bgcolor=\"#fffcfc\">
          <td align=\"center\" valign=\"top\">$no</td>
          <td valign=\"top\">$foto</td>
		  <td valign=\"top\">$data[judul]</td>
		  <td valign=\"top\">$data[ringkasan]</td>
		  <td valign=\"top\">$jum_foto<br/><a href='?page=ls_gallery&id_gallery=$data[id_gallery]'>Kelola Foto</a></td>
		  <td valign=\"top\">$data[tanggal]</td>
          
          <td valign=\"top\" align=\"center\"><a href=\"?action=edit_album&id=$data[id_gallery]\"><img src=\"images/edit.gif\" /></a>&nbsp;|&nbsp;<a href=\"_del_album.php?id=$data[id_gallery]\" onclick=\"return confirm('Yakin akan menghapus album dengan judul $data[judul] ?')\"><img src=\"images/delete.gif\" /></a></td>
          
           </tr>";
      $no++;  
    }
    
    echo "</table>";
  }else{
  
    echo "<table width='100%' align='center' cellpadding='0' cellspacing='0' border='1' bgcolor='#C4D9FF'>";
    echo "<tr bgcolor='#fffccc'>
        <th width='5%'>No.</th>
        <th>Sampul Album</th>
		<th>Judul Album</th>
		<th>Ringkasan</th>
		<th>Jumlah Foto</th>
		<th>Tanggal</th>
		
        <th width='10%'>Opsi</th>
        </tr>";
    
    echo "<tr>
          <td colspan='7' align='center'>Tidak ditemukan album</td>
           </tr>";    
    echo "</table>";
  }
?>