#!/usr/bin/perl
# EasyHost
# Built by CyberScript
# Website: http://www.cyberscript.net
# Email: rcampbell@cyberscript.net
# (C) Copyright 2001, All Rights Reserved.
#####################################################
# The following code may not be modified            #
# or redistributed by anyone other then CyberScript #
#####################################################

$pwd = ($0 =~ /^(.+)[\/\\]/)[0] || '.';
require ("$pwd/cs-lib.pl");

&prepare;

print &ct("text/html").&display("category");

exit (0);

sub prepare {
	return (0) if (!$tokens{id});

	&error("The id field is required") if (!$tokens{id});
	&error("The id field contains invaild characters") if ($tokens{id} !~ /^[\w_]*$/);

	if (open(FILE,"$tokens{data_dir}/categories/$tokens{id}")) {
		foreach (<FILE>) {
			chop if (/\n/);
			@line=split(/=/,$_,2);
			$tokens{$line[0]}=$line[1];
		}
		close(FILE);
	} else {
		&error("The id you entered wasn't found in our database");
	}

	$tokens{total} = @users = sort { lc($a) cmp lc($b) } &index_display('category',$tokens{id});

	$tokens{page} ||= 1;
	$tokens{limit} ||= 10;

	$tokens{start} = $tokens{page} * $tokens{limit} - $tokens{limit} + 1;
	$tokens{end} = $tokens{page} * $tokens{limit};
	$tokens{end} = $tokens{total} if ($tokens{end} > $tokens{total});

	$tokens{page_end} = $tokens{total} / $tokens{limit};
	$tokens{page_end} = int($tokens{page_end} + 1) if ($tokens{page_end} != int($tokens{page_end}));

	$tokens{page_prev} = $tokens{page} - 1 if ($tokens{page} > 1);
	$tokens{page_next} = $tokens{page} + 1 if ($tokens{page} < $tokens{page_end});

	$tokens{c} = 'category';
}