<?php include('_header.php'); ?>

  <main class="main">

    <!-- Hero Section -->
    <section id="contact" class="hero section dark-background">

      <br/><br/><br/>

      <svg class="hero-waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28 " preserveAspectRatio="none">
        <defs>
          <path id="wave-path" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"></path>
        </defs>
        <g class="wave1">
          <use xlink:href="#wave-path" x="50" y="3"></use>
        </g>
        <g class="wave2">
          <use xlink:href="#wave-path" x="50" y="0"></use>
        </g>
        <g class="wave3">
          <use xlink:href="#wave-path" x="50" y="9"></use>
        </g>
      </svg>

    </section><!-- /Hero Section -->


    <!-- Recent Posts Section -->
    <section id="recent-posts" class="recent-posts section">

      <!-- Section Title -->
      <div class="container section-title" data-aos="fade-up">
        <h2>LASUMA</h2>
        <p>Events & Updates<br></p>
      </div><!-- End Section Title -->

      <div class="container">

        <div class="row gy-4">


<?php
$type='event';

$rowsPerPage = 20;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;


$query  = "SELECT * FROM post WHERE category = '$type' ORDER BY id DESC LIMIT $offset, $rowsPerPage";

$result = mysqli_query($conn,$query) or die(mysqli_error($conn));

if (mysqli_num_rows($result) == 0) {
 print "SORRY: no data...";
 
}else{
			while($info = mysqli_fetch_array($result))
			{
			 		 
				$id=$info['id'];
				
				$image_name=$info['image_name'];
				$title=$info['title'];
				$date_day=$info['date_day'];
				$date_month=$info['date_month'];
				$date_year=$info['date_year'];
				$body=$info['body'];
				$posted_by=$info['posted_by'];
				$category=$info['category'];
				$cat=$info['artist_id'];
				
				
				
					
				$date="$date_day-$date_month-$date_year";	
				$date = strtotime($date); 	
				$date = date('d M Y', $date);
				
				$body = str_replace("\n", '<br />', $body);	
				
				$limit_body = substr($body, 0, 200)."...";
				$limit_body = str_replace("\n", '<br />', $limit_body);	
				
				if($image_name != ""){
					$image_path="<img src=\"admin/piks/$image_name\" class='img-fluid'>";
				}else{
					$image_path="<img src=\"images/lasuma_logo.png\" class='img-fluid'>";
				}
				
				print '
				<div class="col-xl-4 col-md-6" data-aos="fade-up" data-aos-delay="100">
				<article>

			      <h2 class="title">
					<a href="detail.php?id='.$id.'&type='.$type.'">'.$title.'</a>
				  </h2><br/><br/>
				  <div class="post-img">
					<a href="detail.php?id='.$id.'&type='.$type.'">'.$image_path.'</a>
				  </div>
				 

				</article>
			  </div><!-- End post list item -->
                ';
				
			}
			
	}		
			
?> 


        </div><!-- End recent posts list -->
</section><!-- /Recent Posts Section -->	
	


  
     
<?php
// how many rows we have in database
$query   = "SELECT COUNT(id) AS numrows FROM post WHERE category = '$type'";
$result  = mysqli_query($conn,$query) or die(mysqli_error($conn));
$row     = mysqli_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];


// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
	if ($page == $pageNum)
	{
		$nav .= " $page ";   // no need to create a link to current page
	}
	else
	{
		$nav .= " <a href=\"$self?page=$page&type=$type\">$page</a> ";
	}		
}

// creating previous and next link
// plus the link to go straight to
// the first and last page

if ($pageNum > 1)
{
	$page = $pageNum - 1;
	$prev = " <a href=\"$self?page=$page&type=$type\">[Prev]</a> ";
	
	$first = " <a href=\"$self?page=1&type=$type\"> [First Page]</a> ";
} 
else
{
	$prev  = '&nbsp;'; // we're on page one, don't print previous link
	$first = '&nbsp;'; // nor the first page link
}

if ($pageNum < $maxPage)
{
	$page = $pageNum + 1;
	$next = " <a href=\"$self?page=$page&type=$type\">[Next]</a> ";
	
	$last = " <a href=\"$self?page=$maxPage&type=$type\">[Last Page]</a> ";
} 
else
{
	$next = '&nbsp;'; // we're on the last page, don't print next link
	$last = '&nbsp;'; // nor the last page link
}

// print the navigation link
echo "<p align='center'><b>".$first . $prev . $nav . $next . $last."</b></p>";


?>
 </div>
    
</main>	

<?php include('_footer.php'); ?>