package LBCGI::forum::topic::poll::read;
BEGIN
{
	use strict;
	use vars qw ($DEFAULT_CLASS);
#	die ('ERROR0') if (!grep (/LBCGI\.pm$/, keys (%INC)));
#	die ('ERROR1') if (!defined ($main::versionnumber));
	$DEFAULT_CLASS = __PACKAGE__;
}

sub readfile
{
	my ($self, $forumid, $pollid) = @_;
	return -1 if ($forumid !~ /^[0-9]+$/);
	return -2 if ($pollid !~ /^[0-9]+$/);
	my $pollfile = $main::lbdir . 'forum' . $forumid . '/' . $pollid . '.poll.cgi';
	my $postfile = $main::lbdir . 'forum' . $forumid . '/' . $pollid . '.thd.cgi';
	return -3 if (! -e $pollfile || ! -e $postfile);
	open (POST, '<', $postfile);
	my $post = <POST>;
	my @item = split (/<BR>/i, (split (/\t/, $post))[7]);
	my @tmp = split (/\t/, $post);
	my @item = split (/<BR>/i, $tmp[7]);
	my $hidepoll = $tmp[6] =~ /\[hidepoll\]$/;
	close (POST);
	$post =~ /¡¯¡­¡I¡®¡¯([^\t]+)\t/;
#	$post =~ /£ª£££¡£¦£ª([^\t]+)\t/;
	$self->{poll}->{$forumid}->{$pollid}->{topic} = $1;
	$self->{poll}->{$forumid}->{$pollid}->{hidepoll} = $hidepoll;
	my $i = 0;
	$self->{poll}->{$forumid}->{$pollid}->{itemcount} = 0;
	foreach (@item)
	{
		$self->{poll}->{$forumid}->{$pollid}->{item}->{$i++} = {'itemname' => $_, 'pollcount',  => 0};
		$self->{poll}->{$forumid}->{$pollid}->{itemcount}++;
	}
	$self->{poll}->{$forumid}->{$pollid}->{pollcount} = 0;
	open (POLL, '<', $pollfile);
	my @poll = <POLL>;
	close (POLL);
	$self->{poll}->{$forumid}->{$pollid}->{poller} = "\t";
	map
	{
		my @tmp = split (/\t/, $_);
		$self->{poll}->{$forumid}->{$pollid}->{item}->{($tmp[1]) - 1}->{'pollcount'}++;
		$self->{poll}->{$forumid}->{$pollid}->{pollcount}++;
		$tmp[0] =~ s/^¡¯¡I¡­¡®¡¯//;
#		$tmp[0] =~ s/^£ª£££¡£¦£ª//;
		$self->{poll}->{$forumid}->{$pollid}->{poller}->{$tmp[0]}++;
	} @poll;
}

sub new
{
	bless {}, $DEFAULT_CLASS;
}
1;
