sub show_entries
{
# Declare our variables as local to this subroutine:
my (@templatefile,@entryfile,$cookie,$sortby);

# Get the HTML for the "View Entries" page:
@entryfile = getfile($entriesfile,0);


	# Get the sort order for the entries by checking for the following:

	# 1. The supplied paramter (field) "sortby".
	# 2. If we don't have that, check for a previously stored cookie.
	# 3. If we don't have either of these, default to entry number descending.

$sortby = param("sortby") || retrieve_cookie("sort");
$sortby ||= 'entry,desc';
$cookie = setcookie('sort',$sortby,'+1y');


	# Print the following headers ready for our content:

	# 1. "Cache-Control", this is to stop the page being cached.
	# 2. "Set-Cookie", this sends the cookie to remember the sort order.
	# 3. "Content-Type", which tells it we're sending HTML.

print "Cache-Control: max-age=0, must-revalidate\n";
print "Set-Cookie: $cookie\n";
print "Content-type: text/html\n\n";


	# Now we loop over each line of HTML from the template and do the following:

	# 1. If the line contains the content tag to start printing entries (see manual):
	#	a. Print the line incase it contains other HTML as well as the special tag.
	#	b. Call prepare_entries() with the sort-order to print the actual entries.

	# 2. If the line doesn't contain the above tag:
	#	a. Feed it through expand_vars() to handle other special content tags.
	#	b. Print the line as normal.

foreach my $line (@entryfile){
 if ($line =~ /<!--BEGIN ENTRIES-->/){
  print $line;
  prepare_entries($sortby);
 }else{
  $line = expand_vars($line,'');
  print "$line";
 }
}

# That's it, now we can finish (exit):
exit;
}
1;