#!@PERL@

use strict;
use warnings;

use lib '@CGIBINDIR@';
use civs_common;
use CGI qw(:standard -utf8);
use Digest::MD5 qw(md5_hex);
use DB_File;

use Socket;
use IO::Handle;

my $thisurl = $civs_bin_path."/close@PERLEXT@";

HTML_Header($tx->CIVS_Ending_Poll);
use election;

my $control_key = param('key');

CIVS_Header($tx->Ending_poll);

CheckElectionID;
CheckStarted;
CheckControlKey($control_key);
CheckNotStopped;
CheckPostRequest;

if (!sysopen(STOPPED, $stopped_file, O_CREAT|O_EXCL|O_RDWR)) {
    print h1($tx->Error), p($tx->was_not_able_stop_the_poll);
} else {
    print STOPPED "stopped\n"; close(STOPPED);
    Log("Poll $title ($election_id) ended");
    print h1($tx->Poll_ended($title));
    print p($tx->The_poll_has_been_ended($election_end));
    if ($restrict_results ne 'yes') {
	print p("<a href=\"@PROTO@://$thishost$civs_bin_path/results@PERLEXT@?id=$election_id\">
	".$tx->View_poll_results.'</a>');
    } else {
	print p($tx->poll_results_available_to_authorized_users);
    }
}
print end_html();

$vdata{'last_vote_time'} = time();
$vdata{'close_time'} = time();

exit 0;
