#!/usr/local/bin/perl

#
#Container for page's parts.
#

use CGI::Carp qw(fatalsToBrowser);
use CGI;
use CGI qw(:standard);

$query = new CGI;

$filename=$query->param('id');



$path="/home/yourid/public_html/cntdata";
$datapath="/home/yourid/public_html/cntdata/data";

if (&outputSwf("$path/$filename")<0){
	print "Content-type: text/html\r\n\r\n";
	print "<html><body>";
	print "<h1>Can't find specify source. Sorry.</h1>";
	print "</body></html>";
};

exit;                 

sub outputSwf {


    local($file) = @_;
    local($data,$len);
    open(INF,$file);
    $len = (stat(INF))[7];
    binmode(INF);
    $filelen=read(INF,$data,$len);
    close(INF);

    if($filelen<2){return -1};

#get cookie!
    $cookie_check="prostocountercheck";
    $check=cookie($cookie_check);

    open(INF, "< $datapath/$filename");
    @cnt=<INF>;
    close INF;
    $visits=$cnt[0];
    
    unless($check){
	$visits++;
	open(INF, "> $datapath/$filename");
	print INF "$visits";
	close INF;
	$setc=1;
    };

    $newstring=sprintf "%.7d",$visits;
    $data=~s/0000000/$newstring/;

    $now_string = gmtime(time);  
    $exp_string = gmtime(time+360);  
    print "Content-type: application/x-shockwave-flash\r\n";
    if($setc){
	print "Set-cookie: prostocountercheck=yes; expires=$exp_string GMT \r\n";
    };
    print "Expires: $now_string\r\n";
    print "Content-length: $len\r\n\r\n";
    print $data;

    return 1;
}



