#!/usr/bin/perl
######################################################################
#  BEFORE TRYING TO EDIT OR USE THIS SCRIPT, READ DIRECTIONS BELOW!
######################################################################
#
# Directions for self-installation on Surfari Internet Services:
# 
# Surfari Internet provides this script for use by it's customers.
# It is assumed that you are somewhat familiar with HTML programming
# and familiar with the Unix enviroment (ie. know how to create a 
# sub-directory off of your web directory).
# The instructions will refer to 'account_name', which refers to your
# logon or account name (such as jdoe or mjohnson).
# If you are not comfortable with these tasks, please contact 
# webinfo@surfari.net and we can set up a counter on
# your page, please check our rates page for the cost of services.
#
#
# 1. Make a directory off of your web directory (public_html) called
#    /cgi-bin, by typing in: mkdir cgi-bin
#
# (example) /usr/home/account_name/public_html/cgi-bin/
#
# 2. FTP or copy the counter.cgi script into this directory. Then create
#    a text file called account_name.txt, where account_name is your 
#    login or account name. This file should contain only "numbers",
#    preferably 0 (to start your page counter at 0).
# 3. Edit the script in *ONLY* the area it says too, messing with any
#    of the other parameters will cause it to not function.
# 4. Now, make the script and the account_name.txt files executable by
#    the system by typing in:
#    chmod 777 counter.cgi 
#    chmod 777 account_name.txt
# 5. On your homepage (or the html page you choose) put in the command 
#    exactly like like below where you wish the counter to appear on your
#    page (the "#" is not a comment, leave it in!):
#
# <!--#exec cmd="/usr/home/account_name/public_html/cgi-bin/counter.cgi"-->
#
######################################################################
#
# ONLY EDIT THIS PART OF THE SCRIPT!!

# Below is the option for you to select how many digits you wish your 
# counter to have, the maximum is 10 digits, 4 is recommended.

$number_of_digits = 4;

# Here, you have the option to not use graphic images, this counter will 
# also work as a "text" counter. Selecting this to "no" will give you a 
# plain counter, no images needed or involved.  If you select "no", the
# rest of the options can be ignored:

$graphics = "yes";

# Below is the location/style of the graphic image you selected, refer
# to http://www.surfari.net/countergif.html for the style you want to use:

$pathtoimages = "http://www.surfari.net/1gif/";

# Below is the location of your text file that keeps track of the number
# of 'hits' to your page:

$pathtocounter = "/usr/home/account_name/public_html/cgi-bin/account_name.txt";

# DO NOT EDIT BELOW THIS LINE!! OR IT WILL NOT WORK!
############################################################################

$end = ".gif";

# Tell Browser

# print ("Content-type: text/html\n\n");

# Get Count

open (COUNTER, "$pathtocounter");
$count = <COUNTER>;
chop ($count) if $count =~ /\n$/;
close (COUNTER);

# Increase Count

$count += 1;

open (COUNTER, ">$pathtocounter");
print COUNTER ("$count");
close (COUNTER);

@digits = split(//, $count);

if ($number_of_digits eq "") {
        $howmany = @digits;
} else {
        $howmany = $number_of_digits;
}

# Give empty digits a value

$spline = '%0' . $howmany . 'd';
$count = sprintf("$spline", $count);

@digitimages = split(//, $count);

# Print Output Counter

foreach $digitimage (@digitimages) {
     if ($graphics eq yes) {
        $image = "<img src=$pathtoimages" . "$digitimage" . "$end>\n";
     print ("$image");
     } else {
        $plain = $digitimage;
     print ("$plain");
     }
}

exit;
