<?php include('_header.php'); 
$type='resource';
?>

  <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 -->
	
	
  <!-- About Section -->
    <section id="about" class="about section">

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

      <div class="container">

        <div class="row gy-4">

          <div class="col-lg-7 content" data-aos="fade-up" data-aos-delay="100">
<?php
if(isset($_REQUEST['view_id'])){
	
	$view_id = mysqli_escape_string($conn, $_REQUEST['view_id']);
	
	$query  = "SELECT * FROM post WHERE category = '$type' AND id='$view_id'";
	$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
	$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'];
				
				
				
				
				$body = str_replace("\n", '<br />', $body);	
			
				
				print "<h2>$title</h2> $body";
								
					$query_artist  = "SELECT * FROM post_more_picture WHERE art_id = '$id' AND art_cat=''";
					$result_artist = mysqli_query($conn,$query_artist) or die(mysqli_error($conn));
						
						while($info = mysqli_fetch_array($result_artist))
						{
							$filename=$info['filename'];
							$detail=$info['detail'];
							
							print "<hr/>$detail<br/><img src=\"admin/piks/$filename\" class='img-fluid'><br/>";
						}
			print ' <hr/>';
	
}

?>

           <?php


$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{
		print '<ul>';
			while($info = mysqli_fetch_array($result))
			{
			 		 
				$id=$info['id'];
				
				$image_name=$info['image_name'];
				$title=$info['title'];
				
				print '<a href="resources.php?view_id='.$id.'">'.$title.'</a><hr/>';
								
			}
			
	
		
		
		
		
		
			
	}	


// 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>

          <div class="col-lg-5" data-aos="fade-up" data-aos-delay="200">
			<h2>Documents/Files</h2>
            <p>

<?php

$query  = "SELECT * FROM post_more_picture WHERE art_id = ''  AND art_id='' ORDER BY id DESC";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));

if (mysqli_num_rows($result) == 0) {
 print "No record";

}else{


		while($info = mysqli_fetch_array($result))
		{
				 
			$id=$info['id'];
			$detail=$info['detail'];
			$filename=$info['filename'];
					
				
				 
			print " 
			$detail
			<br/>
			<small><a href=\"admin/piks/$filename\" target='_blank'>$filename</a></small><hr/>		
			";
			}
}
?>
			</p>
           
          </div>

        </div>

      </div>

    </section><!-- /About Section -->

  </main>

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