#!/usr/bin/perl

#<ENC>98</ENC>

package acs;
#use Encode;

########################################################################
# COPYRIGHT NOTICE:
#
# Copyright 2008 FocalMedia.Net All Rights Reserved.
#
# Selling the code for this program without prior written consent 
# from FocalMedia.Net is expressly forbidden. You may not 
# redistribute this program in any shape or form.
# 
# This program is distributed "as is" and without warranty of any
# kind, either express or implied. In no event shall the liability 
# of FocalMedia.Net for any damages, losses and/or causes of action 
# exceed the total amount paid by the user for this software.
#
########################################################################

#### EDIT HERE -- FOR WINDOWS/IIS BASED INSTALLATIONS ONLY #######

$config_cgi = "../config.cgi"; ## <-- CHANGE THIS LINE TO THE FULL SERVER PATH TO config.cgi

# THE PATH ON A WINDOWS INSTALLATION WILL LOOK SOMETHING LIKE THIS:
# $config_cgi = "c:/inetpub/webpub/cgi-bin/pseek/config.cgi";

#### DO NOT CHANGE ANYTHING BELOW THIS LINE #################

#use FindBin;
#use lib $FindBin::Bin;
use CGI::Carp qw(fatalsToBrowser);
use CGI;
use Time::Local;
use DBI;
use IO::Socket;
use MIME::Base64 qw(decode_base64 encode_base64);


require Exporter;
use vars qw/@ISA @EXPORT @EXPORT_OK $copyright $prgname/;

@ISA = qw(Exporter);

@EXPORT = qw(check_access
	    		 get_template
	    		 encode_dir
	    		 decode_dir
	    		 problem_popup
	    		 get_chopped_path
	    		 remove_leading_spacing
	    		 update_numbers
	    		 get_location_string
	    		 get_file_contents
	    		 get_last_dirname
	    		 get_rid
	    		 decode_complete_dir
	    		 get_extra_vars
	    		 decode_date
	    		 extend_login
	    		 update_setting
	    		 htmlencode
	    		 get_heading_box
	    		 write_config
	    		 psmakedir
	    		 update_cat_numbers
	    		 get_tooltip
	    		 get_js_errors
	    		 get_popupjs
	    		 getversion
	    		);

@EXPORT_OK = qw($template1
					 $enc_string
					 $decoded_string
					 $chopped_path
					 $chopped_string
					 $locstr_ret
					 $thefile
					 $drval
					 $mcid_str
					 $decstr
					 $extrakfd
					 $rdvalue
					 $str2
					 $h_return
					 $dir_to_create
					 $tootltipd);

$thetime = time();
($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime($thetime);
$year = "20" . substr($year, 1, 2);

$version = "PowerSeek SQL Version 6.0.3";
$prgname = "PowerSeek Version 6.0.3";
$copyright = "Copyright \@ 2003-$year FocalMedia.Net";
&get_setup;

$default_permissions = 0777; ### PERMISSIONS THAT IS USED FOR TEMPORARY DATA FILES 

$cpenc = acs::get_file_contents("$data_dir/cpencoding.dat");
if ($cpenc eq "") 
{ 
$html_encoding_to_use = qq[<meta http-equiv="Content-Type" content="text/html; charset=utf-8">]; 
}
else
{
$html_encoding_to_use = $cpenc;
$html_encoding_to_use =~ s/&amp;/&/g;
$html_encoding_to_use =~ s/&lt;/</g;
$html_encoding_to_use =~ s/&gt;/>/g;
$qchr = "\"";
$html_encoding_to_use =~ s/&quot;/$qchr/g;
$html_encoding_to_use =~ s/&apos;/'/g;
}


##################################################################################################################




sub get_html_email_detials
{
	
$qhdiz = qq[
<p><strong>HTML Design Email
  Guidelines When Sending HTML Email:</strong></font></span>
<ul>
  <li>Send yourself a test
    message to get a preview of how the HTML email will arrive.</li>
  <li>It is very important that
    you keep your HTML email simple due to Email readers not interpreting all HTML email
    equally. It would be necessary that you test the HTML message with Outlook, Eudora, AOL, Yahoo Mail, Google's Gmail,
    Hotmail, etc.</font></span></li>
  <li>All images used need to be
    hard linked. In other words: <strong>&lt;img src=&quot;btnSource.gif&quot;&gt;</strong> won't work but <strong>&lt;img src=&quot;http://www.yourdomain.com/btnSource.gif&quot;&gt;</strong> will work.</font></span></li>
  <li>You can use CSS for basic
    fonts and colors but use it sparingly. Many email readers won't support or interpret it
    correctly.</font></span></li>
  <li>Use Inline CSS that is not
    linked to files. (Available inside the HTML email message)</font></span></li>
  <li>When using CSS, use it
    below the body tag as browser based email applications (like Gmail, Hotmail, Yahoo, etc)
    strip out HTML, HEAD and BODY tags so that they don't interfere with their own web pages.
    (The web page displaying the email)</font></span></li>
  <li>JavaScript, ActiveX
    Controls, Flash and embedded movie files will normally not work. The reason they will
    normally not work or not work properly is because most people have antivirus software that
    will block these.</font></span></li>
  <li>Background colors and
    images will normally not work with browser based email services like Gmail, Yahoo,
    Hotmail, etc. The reason for this is that they strip out HTML, HEAD and BODY tags from
    HTML email received.</font></span></li>
</ul>
<hr>
<p><strong>Spam Filter
  Details and Guidelines When Sending HTML Email:</strong></font></span>
<ul>
  <li>You will need a good
    balance between images and text else spam filters will flag the email as spam.</font></span></li>
  <li>Make sure your HTML code
    has no errors and ensure that your email message contains proper grammar and spelling.
    Spammers are renowned for sloppy HTML code and grammar.</font></span></li>
</ul>
];

$helpb = &quick_help("Help:",$qhdiz); 
	
return ($helpb);
	
	
}


sub get_js_errors
{

$jsret = qq[
<script LANGUAGE="JavaScript">

function check_errors_blank(estring)
	{
	var estrs = estring.split("::");
	var ms = 0;
	var vposc = 1;
	
	var formerrors_id = [];
	var formerrors_text = [];
	var icnt = 0; var icnt2 = 0;
	
	for ( ms; ms < estrs.length; ++ms )
		{
		if (vposc == 1)
			{
			formerrors_id[icnt] = estrs[ms]; vposc = 2; ++icnt;
			}
		else if (vposc == 2) 
			{
			formerrors_text[icnt2] = estrs[ms]; vposc = 1;  ++icnt2;
			}
		}
	
	var ms = 0;
	for ( ms; ms < formerrors_id.length; ++ms )
		{
		if (document.getElementById(formerrors_id[ms]).value == '') { alert (formerrors_text[ms]); return false; }
		}
	}

</script>
];

return ($jsret);

}




sub get_popupjs
{

$jspcode = qq[

var popupwin = null;
function popup(loc,ww,hh, h_pos, v_pos)
   {
    var mywidth = (ww + 0);
    var myheight = (hh + 0);
    
    var winl = ((screen.width-ww)/2);
	 var wint = ((screen.height-hh)/2) - 50;
	 
	 /*if ((h_pos > 0) && (v_pos > 0))
	 	{
	 	var winl = h_pos;
	 	var wint = v_pos;
	 	}
	 	else
	 	{
	 	var winl = 80;
	 	var wint = 30;
	 	}*/
	 
    var myspecs = 'menubar=0,status=0,resizable=1,location=1,titlebar=0,toolbar=0,scrollbars=1,width=' + mywidth + ',height=' + myheight + ',top=' + wint + ',left=' + winl;
	 var random = parseInt(Math.random()*10000)
    var popupwin = null;
    myWindow = open (loc, popupwin + random, myspecs);
    myWindow.focus();
    
    return (false);
  }

];

##var myspecs = 'menubar=0,status=0,resizable=1,location=0,titlebar=0,toolbar=0,scrollbars=1,width=' + mywidth + ',height=' + myheight + ',top=' + wint + ',left=' + winl;

}



sub expire_links
{

$classdata = acs::get_file_contents("$data_dir/p_classi.dat");
@classi_items = split (/\n/, $classdata);

if (($classi_items[2] ne "Y") and ($classi_items[3] ne "Y")) { $continue_opp = "false"; }

if (($classi_items[0] eq "Y") and ($classi_items[1] > 0) and ($continue_opp ne "false"))
	{
	
	$days = $classi_items[1];
	
	$exptime = time();
	$exptime = $exptime - ($days * 86400);
	
	if (($classi_items[2] eq "Y") and ($classi_items[3] eq "Y")) 
		{
		$del_criteria = "WHERE urldate < '$exptime'"; 
		}
		elsif (($classi_items[2] eq "Y") and ($classi_items[3] ne "Y")) 
		{
		$del_criteria = "WHERE urldate < '$exptime' AND premium > '0'"; 
		}
		elsif (($classi_items[2] ne "Y") and ($classi_items[3] eq "Y")) 
		{
		$del_criteria = "WHERE urldate < '$exptime' AND premium < '1'"; 
		}

	if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
	$dbh = DBI->connect($dsn, $db_username, $db_password);
	if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; } 

	$sql = "DELETE FROM links $del_criteria";
	
	$sth = $dbh->prepare($sql);
	$sth->execute;
	$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}

	$sth->finish;
	$dbh->disconnect;
	
	}

}



sub get_html_encoding
{
$curr_encoding = $html_encoding_to_use;

return ($curr_encoding);
}



sub get_tooltip
{

# border-right-width: 1px;
# border-bottom-width: 1px;

$tootltipd = qq[
<style type="text/css">
<!--
div#qTip {
 padding: 10px;
 border: 1px solid #DBDBDB;
 display: none;
 background: url("$web_url/tooltback.gif");
 color: #000;
 font: 11px Arial, sans-serif;
 text-align: left;
 position: absolute;
 z-index: 1000;
}
-->
</style>
<script SRC="$web_url/qtip.js"></script>
];

return ($tootltipd);
}



sub write_config
{
my ($conf_item, $conf_value) = @_;

open (GSETT, "$data_dir/gsettings.dat");
	@conflines = <GSETT>;
close (GSETT);


$found_item = "";
foreach $ccitem (@conflines)
	{
	($obj, $ident) = split (/=/, $ccitem);
	
		if ($obj eq $conf_item)
			{
			$newfile = $newfile . $conf_item . "=" . $conf_value . "\n";
			$found_item = "true";
			}
			else
			{
			$newfile = $newfile . $ccitem;
			}
	}

#### 
if ($found_item ne "true")
	{
	$newfile = $newfile . $conf_item . "=" . $conf_value . "\n";
	}

open (GSETT, "> $data_dir/gsettings.dat");
	print GSETT $newfile;
close (GSETT);

}



sub getversion
{
return ($version, $copyright);
}



sub update_cat_numbers
{

my ($cid_id, $link_number_counter) = @_;  ### CID / NUMBERS TO ADD

if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
$dbh = DBI->connect($dsn, $db_username, $db_password);
if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; } 

$sql = "SELECT cid, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, shortname
					FROM dirs WHERE cid = '$cid_id'";
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}

$nrcounter = 0;
while ( @row = $sth->fetchrow() )
	{
		$cats = "";
		for ($ms = 1; $ms < 17; $ms++) 
				{
				if ($row[$ms] ne "")
					{
					$cats = $cats . $row[$ms] . "::-::";
					}
				} 
		$cats = substr($cats, 0, length($cats) - 5);
	} 

@to_update_cat = split (/::-::/, $cats);

$lvc = 1;
foreach $catlevel (@to_update_cat)
	{
	$catlevel = $dbh->quote($catlevel);
	
	$levelsql = $levelsql . " (l" . $lvc . " = $catlevel) AND";
	
	$use_levelsql = $levelsql . " (l" . ($lvc + 1) . " = '')";
	
	$sql = "UPDATE dirs SET linknrs = linknrs + $link_number_counter WHERE $use_levelsql";
	
	$sth = $dbh->prepare($sql);
	$sth->execute;
	$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";} 
	
	$lvc++;
	}

if (defined($sth)){$sth->finish; } 
$dbh->disconnect;

}



sub quick_help
{
my ($help_heading, $help_text) = @_;

$helpcrit = qq[<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#E1E1E1">
  <tr>
    <td valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="6">
        <tr>
          <td width="1%"><img src="$web_url/ics_smallhelp.png" width="29" height="20"></td>
          <td width="99%" class="bar6"><strong class="normaltext" >$help_heading</strong></td>
        </tr>
    </table>
      <table width="100%" border="0" cellpadding="6">
        <tr>
          <td colspan="2" class="normaltext">$help_text</td>
        </tr>
    </table></td>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%" background="$web_url/shadow.gif">
  <tr><td width="1%" bgcolor="#FFFFFF"><font color="#FFFFFF">_</font></td><td width="99%"></td></tr>
</table>
];

return ($helpcrit);

}




sub get_heading_box
{

my ($h_icon, $h_heading, $h_text) = @_;

$h_return = qq[<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#E1E1E1">
 <tr>
  <td width="1%" valign="top" bgcolor="#FFFFFF"><img src="$h_icon"></td>
  <td width="99%" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="6">
 <tr>
  <td background="$web_url/bar6.gif" class="normaltext"><strong>$h_heading</strong></td>
 </tr>
 <tr>
  <td class="normaltext">$h_text</td>
 </tr>
</table></td></tr></table>
<table border="0" cellpadding="0" cellspacing="0" width="100%" background="$web_url/shadow.gif">
  <tr><td width="1%" bgcolor="#FFFFFF"><font color="#FFFFFF">_</font></td><td width="99%"></td></tr>
</table>];

return ($h_return);


}



sub fill_vars
{

my ($filledvar) = @_;

$filledvar =~ s/!!scripts_url!!/$script_url/g;
$filledvar =~ s/!!tseeksearch!!/$script_url\/search\.cgi/g;
$filledvar =~ s/!build_url!/$web_url/g;
$filledvar =~ s/!!build_url!!/$web_url/g;

open (GSETT, "$data_dir/gsettings.dat");
	@conflines = <GSETT>;
close (GSETT);
$statsetting = $conflines[29];
chop($statsetting);


####
if ($statsetting =~ /dyn_stat=Dynamic/)
	{
	$filledvar =~ s/!!whatsnew!!/$script_url\/dirs\.cgi?newpop=new/g;
	$filledvar =~ s/!!tophits!!/$script_url\/dirs\.cgi?newpop=pop/g;
	}
	else
	{
	$filledvar =~ s/!!whatsnew!!/$web_url\/new\//g;
	$filledvar =~ s/!!tophits!!/$web_url\/pop\//g;
	}

$filledvar =~ s/!!modify_link_url!!/$script_url\/modify\.cgi/g;
$filledvar =~ s/!!add_url_link!!/$script_url\/addurl\.cgi/g;
$filledvar =~ s/!!add_premium_url_link!!/$script_url\/addurl\.cgi?p=1/g;
$filledvar =~ s/!!rgs_login!!/$script_url\/rgs_login\.cgi?p=1/g;


$topvar = &get_file_contents("$data_dir/frontlink.dat");
if ($topvar eq ""){$filledvar =~ s/!!top!!/$script_url\/fp\.cgi/gi;}else{$filledvar =~ s/!!top!!/$topvar/gi;}


$filledvar =~ s/!!favorites_link!!/$script_url\/fav\.cgi/g;

$filledvar =~ s/!!register!!/$script_url\/rgs_register\.cgi?p=1/g;
$filledvar =~ s/!!log_out!!/$script_url\/rgs_logout\.cgi/g;
$filledvar =~ s/!!advanced!!/$script_url\/searchadv\.cgi/g;
$filledvar =~ s/!!my_links!!/$script_url\/rgs_login\.cgi/g;
$filledvar =~ s/!!account_details!!/$script_url\/rgs_adet\.cgi/g;

$filledvar =~ s/!!retrieve_password!!/$script_url\/rgs_repass\.cgi/g;
$filledvar =~ s/!!resend_activation!!/$script_url\/rgs_resend2\.cgi/g;


$query = new CGI;
$searched_keywords = $query->param('keywords');
$filledvar =~ s/!!keywords!!/$searched_keywords/g;


return ($filledvar);
} 




sub update_setting
{
my ($keyname, $keyval) = @_;

$scnts = &get_file_contents("$data_dir/gsettings.dat");
@allitems = split (/\n/, $scnts);

foreach $item (@allitems)
	{
	($sobj, $sval) = split (/=/, $item);
	
	if ($sobj eq $keyname)
		{
		$the_setting = $the_setting . "$sobj=$keyval\n";
		}
		else
		{
		$the_setting = $the_setting . $item . "\n";
		}
	
	}

open (PSETTINGS, "> $data_dir/gsettings.dat");
print PSETTINGS $the_setting;
close (PSETTINGS);

}



sub get_extra_vars
{

my ($keydata1, @akeys1, $knr1, $kcount1, $k_item1, 
    $k_keyname1, $k_visible1, $k_size1, $k_searched1, $k_description1, $k_image1, $extrakfd);

$keydata1 = &get_file_contents("$data_dir/keys.dat");
@akeys1 = split (/\n/, $keydata1);
$knr1 = @akeys1;

if ($knr1 > 0)
	{
	$kcount1 = 0;
	foreach $k_item1 (@akeys1)
		{
		($k_keyname1, $k_visible1, $k_size1, $k_searched1, $k_description1, $k_image1, $tmp, $nmbup) = split (/\t/, $k_item1);
		
		if ($nmbup ne "Upload")
			{
			$extrakfd = $extrakfd . "%%$k_keyname1%%<br><br>";
			$kcount1++;
			}
		}
	} 



return ($extrakfd);
}




sub get_cid_cat
{

my ($dstring) = @_;

my (@alldirs, $lvcount, $ccats, $item44, $readycat, $sqlstr, $sql, $cidret);

@alldirs = split (/\//, $dstring);

$lvcount = 1;
$ccats = "";
foreach $item44 (@alldirs)
	{
	$item44 =~ s/'/\\'/g;
	
	$ccats = $ccats . "(l" . $lvcount . " = '$item44') AND ";
	
	$readycat = substr($ccats, 0, length($ccats) - 4);
	
	$sqlstr = $sqlstr . "($readycat AND (level = '$lvcount')) OR";
	
	$lvcount++;
	}

$sqlstr = substr($sqlstr, 0, length($sqlstr) - 2);

$sql = "SELECT cid FROM dirs WHERE $sqlstr ORDER BY level";

#print "$sql \n\n";

### CONNECT TO DB
if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
$dbh = DBI->connect($dsn, $db_username, $db_password);
if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
 
$sth = $dbh->prepare($sql);
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror\n From: $sql";}

$cidret = "";
while ( @row = $sth->fetchrow() )
	{
	$cidret = $cidret . $row[0] . "-";
	}

$sth->finish;
$dbh->disconnect;

$cidret = substr($cidret, 0, length($cidret) - 1);

return ($cidret);

}


sub decode_complete_dir
{

my ($complete_dir) = @_;
my (@dits, $dritem, $decstr);

@dits = split (/-/, $complete_dir);
	
$decstr = "Root ";
	
	foreach $dritem (@dits)
		{
		$decstr = $decstr . " > " . &decode_dir($dritem);
		}

return ($decstr);
}


#######################

sub get_rid
{
my ($ecat) = @_;

@dcats = split (/-/, $ecat);

$gcntr = 0;
$lvcnt = 1;
foreach $item (@dcats)
	{
	$item = &decode_dir($item);
	$item =~ s/'/\\'/g;
	
	$fieldnames[$gcntr] = "l" . $lvcnt;
	$fieldvalues[$gcntr] = $item;
		
		$fncount = 0;
		$fieldsel = "";
		foreach $field_name_item (@fieldnames)
			{
			$fieldsel = $fieldsel . " ($field_name_item = '$fieldvalues[$fncount]') and";
			$fncount++;
			}
		$fieldsel = substr($fieldsel, 0, length($fieldsel) -3);
	
	$qstring = $qstring . " ((level = '$lvcnt') and $fieldsel) or";
	
	$lvcnt++;
	$gcntr++;
	}
	$qstring = substr($qstring, 0, length($qstring) - 2);

$qstring = "SELECT cid,level FROM dirs WHERE $qstring ORDER BY level ASC";

if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
$dbh = DBI->connect($dsn, $db_username, $db_password);
if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }

$sth = $dbh->prepare("$qstring");
if ( !defined $dbh ) {die "Cannot connect to mSQL server: $DBI::errstr\n"; }
$sth->execute;

$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}

$mcid_str = "";
$updc = 0;
while ( @row = $sth->fetchrow() )
	{
	$mcid_str = $mcid_str . "$row[0]" . "-";
	}

$mcid_str = substr($mcid_str, 0, length($mcid_str) -1);


$sth->finish;
$dbh->disconnect;


return ($mcid_str);

}





sub get_last_dirname
{

my ($complete_dir) = @_;

@allds = split (/-/, $complete_dir);
$dnr = @allds; $dnr = $dnr - 1;
$drval = $allds[$dnr];
$drval = &decode_dir($drval);

return ($drval);
}




sub new_gsettings
{
my $this = {};

$scnts = &get_file_contents("$data_dir/gsettings.dat");
@all_obj_items = split (/\n/, $scnts);

foreach $obji (@all_obj_items)
	{
	($obj_prp, $obj_val) = split (/=/, $obji);
	$this->{$obj_prp} = $obj_val;
	}

bless $this;
return $this;
}



sub get_file_contents
{

my ($filename) = @_;
my ($filesize, $thefile);

if ((-e "$filename") > 0) 
	{
$filesize = (-s "$filename");
open (TFILECNTS, "$filename") || die "$filename";
	read(TFILECNTS,$thefile,$filesize);
close (TFILECNTS);
	}

return ($thefile);

}




sub update_numbers
{

my ($plus_minus, $nr, $ctg) = @_;

my (@allds, $item, $qsel);

$nowtime = time();

@allds = split (/-/, $ctg);

$qc = 0;
$lvl = 1;

$qstring = "SELECT cid, level, linknrs FROM dirs WHERE ";

foreach $item (@allds)
	{
	$qstring = $qstring . "(cid = '$item') or ";
	}

$qstring = substr ($qstring, 0, length($qstring) - 3);
$qstring = $qstring . " ORDER BY level";

########

if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
$dbh = DBI->connect($dsn, $db_username, $db_password);
if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }



$sth = $dbh->prepare("$qstring");
if ( !defined $dbh ) {die "Cannot connect to mSQL server: $DBI::errstr\n"; }
$sth->execute;

$updc = 0;
while ( @row = $sth->fetchrow() )
	{
	
	if ($plus_minus eq "+")
		{
		$updatetime = ",newindate = '$nowtime'";
		$newc = $row[2] + $nr;
		}
		else
		{
		$newc = $row[2] - $nr;
		}

	$update_arr[$updc] = "$row[0]-$row[1]-$newc";
	$updc++;
	
	}

foreach $item (@update_arr)
	{
	($icid, $ilv, $link_count) = split (/-/, $item);

$sth = $dbh->prepare("UPDATE dirs SET 	linknrs = '$link_count' 
													$updatetime
													WHERE cid = '$icid'");
if ( !defined $dbh ) {die "Cannot connect to mSQL server: $DBI::errstr\n"; }
$sth->execute;
	}
	
$sth->finish;
$dbh->disconnect;

}






sub get_location_string
{

my ($lcstring) = @_;
my (@als, $item);

@als = split (/-/, $lcstring);

$locstr_ret = "Root";
foreach $item (@als)
	{
	$locstr_ret = $locstr_ret . " > " . &decode_dir($item);
	}

return ($locstr_ret);
}





sub remove_leading_spacing
{
my ($ostring) = @_;
my ($ds, $wfound);

for ($ds = 0; $ds < length($ostring); $ds++) 
	{
	if ((substr($ostring, length($ostring) - 1, 1) eq " ") and ($wfound ne "true"))
		{
		chop($ostring);
		}
		else
		{
		$wfound = "true";
		}
	
	}

$chopped_string = $ostring;

return ($chopped_string);
}



#####################

sub get_chopped_path
{

my ($fpath) = @_;

$chopped_path = "";

@alldi = split (/\//, $fpath);
$inr = @alldi;
$inr = $inr -1;

for ($ds = 0; $ds < $inr; $ds++) 
	{
	if ($ds != 0)
		{
		$chopped_path = $chopped_path . "/$alldi[$ds]";
		}
		else
		{
		$chopped_path = $chopped_path . "$alldi[$ds]";
		}
	
	}

return ($chopped_path);
}

######################



sub check_access
{

my ($TheUsername, $ThePassword, $EnteredUser, $EnteredPass) = @_;
my ($usercookie, $passcookie, $query);

if ($TheUsername =~ /'/) { &wrongps_screen; } if ($TheUsername =~ /\\/) { &wrongps_screen; }
if ($ThePassword =~ /'/) { &wrongps_screen; } if ($ThePassword =~ /\\/) { &wrongps_screen; }
if ($EnteredUser =~ /'/) { &wrongps_screen; } if ($EnteredUser =~ /\\/) { &wrongps_screen; }
if ($EnteredPass =~ /'/) { &wrongps_screen; } if ($EnteredPass =~ /\\/) { &wrongps_screen; }


if (-e "$web_dir/$db_name.sql")
	{
	$tmp = unlink("$web_dir/$db_name.sql");
	}


if (($username ne "") and ($password ne "")) ### IF CONTROL PANEL USER/PASS ENABLED
	{
	$query = new CGI;

	$usercookie = $query->cookie('nuser');
	$passcookie = $query->cookie('npass');

	if (($EnteredUser ne "") and ($EnteredPass ne "")) {&do_login ($EnteredUser, $EnteredPass);}
	if (($usercookie eq "") and ($passcookie eq "")){&login_screen;}
	if (($usercookie ne $TheUsername) or ($passcookie ne $ThePassword)){&wrongps_screen;}
	}

}




sub extend_login
{

$remlogin = acs::get_file_contents("$data_dir/relogin.dat"); 

if ($remlogin eq "") { $remtime = "+24h"; }
elsif ($remlogin == 0) { $remtime = ""; }
elsif ($remlogin == 1) { $remtime = "+24h"; }
elsif ($remlogin == 2) { $remtime = "+7d"; }
elsif ($remlogin == 3) { $remtime = "+1M"; }
elsif ($remlogin == 4) { $remtime = "+3M"; }
elsif ($remlogin == 5) { $remtime = "+6M"; }
elsif ($remlogin == 6) { $remtime = "+1y"; }


$query = new CGI;

if ($remtime ne "")
{
$thecookie1 = $query->cookie(-name=>'nuser',
			    					  -value=>$username,
			    					  -expires=>$remtime,
			    					  -path=>'/');

$thecookie2 = $query->cookie(	-name=>'npass',
			    						-value=>$password,
			    						-expires=>$remtime,
			    						-path=>'/');
}
else
{
$thecookie1 = $query->cookie(-name=>'nuser',
			    					  -value=>$username,
			    					  -path=>'/');

$thecookie2 = $query->cookie(	-name=>'npass',
			    						-value=>$password,
			    						-path=>'/');
}

print $query->header(-cookie=>[$thecookie1, $thecookie2]); 

}







sub do_login
{

my ($form_username, $form_password) = @_;
my ($query, $thecookie1, $thecookie2, $scripts_admin);

$query = new CGI;

$remlogin = acs::get_file_contents("$data_dir/relogin.dat"); 

if ($remlogin eq "") { $remtime = "+24h"; }
elsif ($remlogin == 0) { $remtime = ""; }
elsif ($remlogin == 1) { $remtime = "+24h"; }
elsif ($remlogin == 2) { $remtime = "+7d"; }
elsif ($remlogin == 3) { $remtime = "+1M"; }
elsif ($remlogin == 4) { $remtime = "+3M"; }
elsif ($remlogin == 5) { $remtime = "+6M"; }
elsif ($remlogin == 6) { $remtime = "+1y"; }


if ($remtime ne "")
{
$thecookie1 = $query->cookie(-name=>'nuser',
			    					  -value=>$form_username,
			    					  -expires=>$remtime,
			    					  -path=>'/');

$thecookie2 = $query->cookie(	-name=>'npass',
			    						-value=>$form_password,
			    						-expires=>$remtime,
			    						-path=>'/');
}
else
{
$thecookie1 = $query->cookie(-name=>'nuser',
			    					  -value=>$form_username,
			    					  -path=>'/');

$thecookie2 = $query->cookie(	-name=>'npass',
			    						-value=>$form_password,
			    						-path=>'/');
}

print $query->header(-cookie=>[$thecookie1, $thecookie2]); 



$rndnr = rand(100);

print qq[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Powerseek</title>
<meta HTTP-EQUIV="REFRESH" CONTENT="0;URL=$admin_url/admin.cgi?$rndnr">
</head>
<body>
</body>
</html>
];


exit;

}




sub login_screen
{

my ($scripts_admin);
my $newquery = CGI->new;


print $newquery->header();
print $newquery->start_html("Control Panel");


print qq[

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
<link href="$web_url/ps.css" rel="stylesheet" type="text/css" /> 
</head>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form method="POST" action="$admin_url/admin.cgi">

<table width="300" border="0" align="center" cellpadding="6" cellspacing="1" class="aborder">
    <tr>
      <td colspan="2"><strong class="normaltext">Please Login:</strong></td>
    </tr>
    <tr>
      <td width="350" height="1" align="right"><strong class="normaltext">User
      Name:</strong></td>
      <td width="350" height="1"><input type="text" name="username" size="20"></td>
    </tr>
    <tr>
      <td width="350" height="1" align="right"><strong class="normaltext">Password:
      </strong></td>
      <td width="350" height="1"><input type="password" name="password" size="20"></td>
    </tr>
    <tr>
      <td width="350" height="1"></td>
      <td width="350" height="25" valign="top"><input type="submit" class="psbutton" value="Login" name="B1"></td>
    </tr>
  </table>
</form>


</body>
</html>
];

exit;

}





sub wrongps_screen
{

my ($scripts_admin);


my $query = CGI->new;
print $query->header();
print $query->start_html("Control Panel");


print qq[


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
<link href="$web_url/ps.css" rel="stylesheet" type="text/css" /> 
</head>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<blockquote>
  <form method="POST" action="$admin_url/admin.cgi">

    <p><strong style="color:#F00">
    <center class="normaltext">The user name or password you entered was incorrect.</center></strong></p>    
    <table width="300" border="0" align="center" cellpadding="6" cellspacing="1" class="aborder">
      <tr>
        <td colspan="2"><strong class="normaltext">Please Login:</strong></td>
      </tr>
      <tr>
        <td width="350" height="1" align="right"><strong class="normaltext">User
        Name:</strong></td>
        <td width="350" height="1"><input type="text" name="username" size="20"></td>
      </tr>
      <tr>
        <td width="350" height="1" align="right"><strong class="normaltext">Password:
        </strong></td>
        <td width="350" height="1"><input type="password" name="password" size="20"></td>
      </tr>
      <tr>
        <td width="350" height="1"></td>
        <td width="350" height="30" valign="top"><input type="submit" class="psbutton" value="Login" name="B1"></td>
      </tr>
    </table>

  </form>
</blockquote>
</body>
</html>
];

exit;

}





sub get_template
{

my ($menu) = @_;

$gsettings = new_gsettings acs;

$navb = "navb.gif";

$b_home = "<span>Home</span>";
$b_dman = "<span>Dir Manager</span>";
$b_settings = "<span>Settings</span>";
$b_userm = "<span>User Manager</span>";
$b_tmplm = "<span>Template Manager</span>";
$b_plugin = "<span>Plugins</span>";
$b_todo = "<span>To Do</span>";


$search_boxes = qq[

<form method="POST" action="$script_url/!!!search!!!" name="searchform" target="_blank">
<table width="97%" border="0" align="right" cellpadding="0" cellspacing="0">
  <tr>
    <td height="55" valign="bottom">
        <strong class="verd"><font color="#ffffff">Search Links: <a href="$admin_url/admin11.cgi?fct=advanced" 
        onClick="popup('$admin_url/admin11.cgi?fct=advanced',950,650);return false;" STYLE="text-decoration:none">
        <font color="#ffffff">(<u>Advanced</u>)</font></a></font></strong><br>
        <input type="text" name="keywords2" size="11"> <input type="button" name="sgbut" id="sgbut4" value="Go" 
        onClick="submitsearch('1');" style="width:30px;"></td>
  </tr>
  <tr>
    <td height="46" valign="bottom"><strong class="verd"><font color="#ffffff">Search Categories:</font></strong><br>
      <input type="text" name="keywords3" size="11"> <input type="button" name="sgbut2" id="sgbut5" value="Go" onClick="submitsearch('2');"  style="width:30px;"></td>
  </tr>
  <tr>
    <td height="46" valign="bottom"><strong class="verd"><font color="#ffffff">End User Search:</font></strong><br>
      <input type="text" name="keywords" size="11"> <input type="button" name="sgbut3" id="sgbut6" value="Go"  onClick="submitsearch('3');"  style="width:30px;"></td>
  </tr>
</table>
</form>
];


$navbar_links = qq[
  &nbsp;&nbsp;&nbsp; <br>
  <strong>Quick Links</strong><br>
    <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin29.cgi" onClick="popup('$admin_url/admin29.cgi',screen.width-200,screen.height-200);return false;">Banner Manager</a><br>
    <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin32.cgi" onClick="popup('$admin_url/admin32.cgi',screen.width-200,screen.height-200);return false;">Search Stats</a><br>
    <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin23.cgi" onClick="popup('$admin_url/admin23.cgi',screen.width-200,screen.height-200);return false;">Premium Links Mngr</a><br>
    <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin17.cgi" onClick="popup('$admin_url/admin17.cgi',screen.width-200,screen.height-200);return false;">Template Includes</a><br>
    <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin27.cgi" onClick="popup('$admin_url/admin27.cgi',screen.width-200,screen.height-200);return false;">Custom Templates</a></span><span class="verd"><br>
    <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin33.cgi" onClick="popup('$admin_url/admin33.cgi',screen.width-200,screen.height-200);return false;">Mailing Options</a></span><br>
    <span class="verd"><img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin43.cgi" onClick="popup('$admin_url/admin43.cgi',800,600);return false;">Database Backup</a></span><br>
  <br>
];

if ($gsettings->{searchmeth} eq "fulltext")
	{
	$search_boxes =~ s/!!!search!!!/search2\.cgi/g;
	$srurl = "$script_url/search2.cgi";
	}
	else
	{
	$search_boxes =~ s/!!!search!!!/search\.cgi/g;
	$srurl = "$script_url/search.cgi";
	}

$dropleft_menus = qq[
<ul id="sddm">
  <li><a href="$admin_url/admin.cgi" onmouseover="mopen('m1')" onmouseout="mclosetime()">Home</a>
    <div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
    
      <a href="" onClick="popup('$admin_url/startup.cgi',950,650);return false;"><img src="$web_url/ics_wiz.gif" width="16" height="16" align="top" border="0">&nbsp; Startup Wizard</a>
      <a href="" onClick="popup('$admin_url/wiz.cgi',950,650);return false;"><img src="$web_url/ics_wiz.gif" width="16" height="16" align="top" border="0">&nbsp; Other Wizards</a>
      
      <a href="http://www.focalmedia.net/pseekmanual/" target="_blank"><img src="$web_url/ics_help.gif" width="16" height="16" align="top" border="0">&nbsp; PowerSeek Manual</a>
      <a href="" onClick="popup('$admin_url/admin.cgi?fct=upgrades',500,300);return false;"><img src="$web_url/ics_dir.gif" width="16" height="16" align="top" border="0">&nbsp; New Updates</a>
      <a href="" onClick="popup('$admin_url/admin.cgi?fct=conf',800,600);return false;"><img src="$web_url/ics_spn.gif" width="16" height="16" align="top" border="0">&nbsp; Configuration Info</a>
      <a href="http://www.powerseek.net/cgi-bin/support/login.cgi" target="_blank"><img src="$web_url/ics_ukey.gif" width="16" height="16" align="top" border="0">&nbsp; PowerSeek Support</a>
     	<a href="$admin_url/admin.cgi?fct=logoff"><img src="$web_url/icm_sp.gif" width="16" height="16" align="top" border="0">&nbsp; Logout</a>
	</div>
 </li>
 <li><a href="$admin_url/admin2.cgi" onmouseover="mopen('m2')" onmouseout="mclosetime()">Dir Manager</a>
    <div id="m2" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
       <a href="" onClick="popup('$admin_url/admin3.cgi',900,650);return false;"><img src="$web_url/icm_cat.gif" width="16" height="16" align="top" border="0">&nbsp; Stats + Tree</a>
       <a href="#" onClick="popup('$admin_url/startup.cgi?fct=quickfp',950,650);return false;"><img src="$web_url/icm_banner.gif" width="16" height="16" align="top" border="0">&nbsp; Front Page Quick Setup</a>
   </div>
 </li>
  <li><a href="$admin_url/admin10.cgi" onmouseover="mopen('m3')" onmouseout="mclosetime()">Settings</a>
     <div id="m3" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
       <a href="" onClick="popup('$admin_url/admin10.cgi?fct=global_settings',900,650);return false;"><img src="$web_url/ics_settings5.gif" width="16" height="16" align="top" border="0">&nbsp; Global Engine Settings</a>
       <a href="" onClick="popup('$admin_url/admin85.cgi',750,600);return false;"><img src="$web_url/ics_email1.gif" width="16" height="16" align="top" border="0">&nbsp; Contact Us Form Settings</a>       
       <a href="" onClick="popup('$admin_url/admin50.cgi',750,600);return false;"><img src="$web_url/ics_settings4.gif" width="16" height="16" align="top" border="0">&nbsp; Generation Resource Usage</a>
       <a href="" onClick="popup('$admin_url/admin16.cgi',900,650);return false;"><img src="$web_url/ics_settings6.gif" width="16" height="16" align="top" border="0">&nbsp; Customize Emails</a>
       <a href="" onClick="popup('$admin_url/admin35.cgi',900,650);return false;"><img src="$web_url/ics_texts.gif" width="16" height="16" align="top" border="0">&nbsp; Text Configurations</a>
       <a href="" onClick="popup('$admin_url/admin23.cgi',900,650);return false;"><img src="$web_url/icm_premium.gif" width="16" height="16" align="top" border="0">&nbsp; Premium Link Settings</a>
       <a href="" onClick="popup('$admin_url/admin37.cgi',950,650, 'fieldkey');return false;"><img src="$web_url/ics_key.gif" width="16" height="16" align="top" border="0">&nbsp; Extra Fields/Keys</a>
       <a href="" onClick="popup('$admin_url/admin53.cgi',900,650, 'fieldkey');return false;"><img src="$web_url/ics_ukey.gif" width="16" height="16" align="top" border="0">&nbsp; User Extra Fields/Keys</a>
       <a href="" onClick="popup('$admin_url/admin53.cgi?fct=comfields',900,650, 'fieldkey');return false;"><img src="$web_url/ics_comment.gif" width="16" height="16" align="top" border="0">&nbsp; Comments/Reviews Extra Fields</a>
       <a href="" onClick="popup('$admin_url/p_addurl.cgi',900,650, 'fieldkey');return false;"><img src="$web_url/ics_add.gif" width="16" height="16" align="top" border="0">&nbsp; Extra Add URL/Modify Forms</a>
       <a href="" onClick="popup('$admin_url/p_gmap.cgi',900,650, 'fieldkey');return false;"><img src="$web_url/ics_smap.gif" width="16" height="16" align="top" border="0">&nbsp; Google SiteMaps</a>
       <a href="" onClick="popup('$admin_url/admin71.cgi',900,650);return false;"><img src="$web_url/ics_rss.gif" width="16" align="top" border="0">&nbsp; RSS Feed Configuration</a>
       <a href="" onClick="popup('$admin_url/p_specsearch.cgi',900,650, 'fieldkey');return false;"><img src="$web_url/ics_search22.gif" width="16" height="16" align="top" border="0">&nbsp; Create/Conf Advanced Searches</a>
     </div>
   </li>

  <li><a href="$admin_url/admin55.cgi" onmouseover="mopen('m4')" onmouseout="mclosetime()">User Manager</a>
    <div id="m4" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
      <a href="" onclick="popup('$admin_url/admin63.cgi',900,650);return false;"><img src="$web_url/ics_email1.gif" width="16" height="16" align="top" border="0">&nbsp; Send Email to Users</a>
      <a href="" onclick="popup('$admin_url/admin53.cgi',900,650, 'fieldkey');return false;"><img src="$web_url/ics_ukey.gif" width="16" height="16" align="top" border="0">&nbsp; User Extra Fields/Keys</a>
      <a href="" onclick="popup('$admin_url/admin53.cgi?fct=clean_accounts',900,650, 'fieldkey');return false;"><img src="$web_url/ics_erase.gif" width="16" height="16" align="top" border="0">&nbsp; Account Clean-Up</a>
    </div>
  </li>

  <li><a href="$admin_url/admin6.cgi" onmouseover="mopen('m5')" onmouseout="mclosetime()">Template Mngr</a>
    <div id="m5" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
    
    	<a href="" onClick="popup('$admin_url/startup.cgi?fct=quickfp',900,650);return false;"><img src="$web_url/icm_banner2.gif" width="16" height="16" align="top" border="0">&nbsp; Quick Front Page Setup</a>    	
    	<a href="" onClick="popup('$admin_url/admin26.cgi',900,650);return false;"><img src="$web_url/icm_banner2.gif" width="16" height="16" align="top" border="0">&nbsp; Front Page Setups</a>
      <a href="" onClick="popup('$admin_url/admin17.cgi',900,650);return false;"><img src="$web_url/ics_tmplincl.gif" width="16" height="16" align="top" border="0">&nbsp; Create/Edit Template Includes</a>
      <a href="" onClick="popup('$admin_url/p_tmpglobal.cgi',950,650);return false;"><img src="$web_url/ics_template.gif" width="16" height="16" align="top" border="0">&nbsp; Implement Global Template</a>
      <a href="" onClick="popup('$admin_url/p_tmptool.cgi',900,650);return false;"><img src="$web_url/icm_banner.gif" width="16" height="16" align="top" border="0">&nbsp; Template Switching Tool</a>
      <a href="$admin_url/admin6.cgi?t=1#1"><img src="$web_url/ics_dirs.gif" width="16" height="16" align="top" border="0">&nbsp; Category/Directory Templates</a>
      <a href="$admin_url/admin6.cgi?t=2#2"><img src="$web_url/ics_search.gif" width="16" height="16" align="top" border="0">&nbsp; Search Result Templates</a>
      <a href="$admin_url/admin6.cgi?t=3#3"><img src="$web_url/ics_users.gif" width="16" height="16" align="top" border="0">&nbsp; Add URL Templates</a>
      <a href="$admin_url/admin6.cgi?t=4#4"><img src="$web_url/ics_pop2.gif" width="16" height="16" align="top" border="0">&nbsp; Rating Templates</a>
      <a href="$admin_url/admin6.cgi?t=5#5"><img src="$web_url/ics_comment.gif" width="16" height="16" align="top" border="0">&nbsp; Comment/Review Templates</a>
      <a href="$admin_url/admin6.cgi?t=6#6"><img src="$web_url/ics_newsub.gif" width="16" height="16" align="top" border="0">&nbsp; What's New Templates</a>
      <a href="$admin_url/admin6.cgi?t=7#7"><img src="$web_url/ics_pop.gif" width="16" height="16" align="top" border="0">&nbsp; Top Hits Templates</a>
      <a href="$admin_url/admin6.cgi?t=8#8"><img src="$web_url/ics_brlnks.gif" width="16" height="16" align="top" border="0">&nbsp; Broken Link Templates</a>
      <a href="$admin_url/admin6.cgi?t=9#9"><img src="$web_url/ics_fav.gif" width="16" height="16" align="top" border="0">&nbsp; Favorites</a>
      <a href="$admin_url/admin6.cgi?t=10#10"><img src="$web_url/ics_email1.gif" width="16" height="16" align="top" border="0">&nbsp; Contact Us Templates</a>
      <a href="$admin_url/admin6.cgi?t=10#10"><img src="$web_url/ics_email4.gif" width="16" height="16" align="top" border="0">&nbsp; Mailing List Templates</a>
    </div>
  </li>
  <li><a href="$admin_url/plugins.cgi" onmouseover="mopen('m6')" onmouseout="mclosetime()">Plug Ins</a>
     <div id="m6" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
      <a href="$admin_url/plugins.cgi"><img src="$web_url/icm_premium.gif" width="16" height="16" align="top" border="0">&nbsp; Links Plug ins</a>
      <a href="$admin_url/plugins.cgi#cat"><img src="$web_url/icm_cat.gif" width="16" height="16" align="top" border="0">&nbsp; Category Plug ins</a>
      <a href="$admin_url/plugins.cgi#adv"><img src="$web_url/icm_banner.gif" width="16" height="16" align="top" border="0">&nbsp; Advertisement Plug ins</a>
      <a href="$admin_url/plugins.cgi#search"><img src="$web_url/icm_search.gif" width="16" height="16" align="top" border="0">&nbsp; Searching Plug ins</a>
      <a href="$admin_url/plugins.cgi#eml"><img src="$web_url/icm_email.gif" width="16" height="16" align="top" border="0">&nbsp; Email Plug ins</a>
      <a href="$admin_url/plugins.cgi#tmpl"><img src="$web_url/icm_templ.gif" width="16" height="16" align="top" border="0">&nbsp; Template Plug ins</a>
      <a href="$admin_url/plugins.cgi#maint"><img src="$web_url/icm_maint.gif" width="16" height="16" align="top" border="0">&nbsp; Maintenance Plug ins</a>
      <a href="$admin_url/plugins.cgi#spam"><img src="$web_url/icm_sp.gif" width="16" height="16" align="top" border="0">&nbsp; Spam Blocking Plug ins</a>
      <a href="$admin_url/plugins.cgi#utils"><img src="$web_url/icm_util.gif" width="16" height="16" align="top" border="0">&nbsp; Utility Plug ins</a>
    </div>
  </li>
  <li><a href="$admin_url/todo.cgi" onmouseover="mopen('m7')" onmouseout="mclosetime()">To Do</a>
    <div id="m7" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
      <a href="#" onClick="popup('$admin_url/admin20.cgi',900,650);return false;"><img src="$web_url/ics_newsub.gif" width="16" height="16" align="top" border="0">&nbsp; Approve New Submissions</a>
      <a href="#" onClick="popup('$admin_url/admin18.cgi',900,650);return false;"><img src="$web_url/ics_modif.gif" width="16" height="16" align="top" border="0">&nbsp; Approve Modifications</a>
      <a href="#" onClick="popup('$admin_url/admin14.cgi?fct=dostart',900,650);return false;"><img src="$web_url/ics_comment.gif" width="16" height="16" align="top" border="0">&nbsp; Approve Comments</a>
      <a href="#" onClick="popup('$admin_url/admin44.cgi',900,650);return false;"><img src="$web_url/ics_task.gif" width="16" height="16" align="top" border="0">&nbsp; Manage Broken Links</a>
      <a href="#" onClick="popup('$admin_url/admin26.cgi',900,650);return false;"><img src="$web_url/ics_gen.gif" width="16" height="16" align="top" border="0">&nbsp; Generate Front Page</a>
      <a href="#" onClick="popup('$admin_url/admin8.cgi',900,650);return false;"><img src="$web_url/ics_gen2.gif" width="16" height="16" align="top" border="0">&nbsp; Generate HTML Files</a>
    </div>
  </li>
</ul>
];



#############################


if ($menu eq "HOME")
	{

	### CONNECT TO DB
	if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
	$dbh = DBI->connect($dsn, $db_username, $db_password);
	if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }

	$sth = $dbh->prepare("SELECT COUNT(*) FROM links");
	$sth->execute;
	$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}
	while ( @row = $sth->fetchrow() ){$links = $row[0];}

	$sth = $dbh->prepare("SELECT COUNT(*) FROM dirs");
	$sth->execute;
	$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}
	while ( @row = $sth->fetchrow() ){$dirs = $row[0];}
	
	$sth->finish;
	$dbh->disconnect;

	$b_home = qq[<img src="$web_url/b_home2.gif" border="0">];


### CHECK IF WE HAVE THE PPC PLUGIN

$ppc_plug = $config_cgi;
$ppc_plug =~ s/config\.cgi//gi;
$ppc_plug = $ppc_plug . "ppc_internal.pm"; 

if ((-e "$ppc_plug") > 0) 
	{
	$ppc_link = qq[<a href="$admin_url/p_internal_ppc.cgi"><img src="$web_url/ppccp.gif" border="0"></a>];
	}

$bottom_left_menu = qq[<p><span class="verd"><strong>Number of Dirs:<br>
  </strong>$dirs<br>
  <strong>&nbsp; <br>
  </strong><strong>Number of Links:<br>
  </strong>$links</span></p>
<p><img src="$web_url/lary.gif" width="6" height="10"> <span class="verd"><strong><a href="$admin_url/admin.cgi?fct=logoff">Logout</a><br>
  <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin3.cgi" onClick="popup('$admin_url/admin3.cgi',800,600);return false;">Statistics</a><br>
  </strong></span></p>
<p>%%inst%%<br>
</p>
];
	
	}
elsif ($menu eq "DIR_MANAGER")
	{

$subt = qq[
<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td width="1%" valign="top" background="$web_url/stripl.gif">
    <table border="0" cellpadding="6" cellspacing="0" width="100%">
        <tr>
          <td width="100%">$search_boxes $navbar_links</td>
        </tr>
     </table>
     </td>
    <td width="99%" valign="top">!!data!!</td>
  </tr>
</table>
];




	$b_dman = qq[<img src="$web_url/b_dman2.gif" border="0">];
	
	}
elsif ($menu eq "SETTINGS")
	{

$subt = qq[

<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td width="1%" valign="top" background="$web_url/stripl.gif"><table border="0"
    cellpadding="6" cellspacing="0" width="100%">
      <tr>
        <td width="100%">
        $search_boxes
        $navbar_links</td>
      </tr>
    </table>
    <p><img src="$web_url/sep1556.gif"></td>
    <td width="99%" valign="top"><table border="0" cellpadding="6" cellspacing="0"
    width="100%">
      <tr>
        <td width="100%">!!data!!</td>
      </tr>
    </table>
    </td>
  </tr>
</table>
];


	$b_settings = qq[<img src="$web_url/b_settings2.gif" border="0">];
	
	}
elsif ($menu eq "TEMPLATES")
	{

$subt = qq[
<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td width="1%" valign="top" background="$web_url/stripl.gif"><table border="0"
    cellpadding="6" cellspacing="0" width="100%">
      <tr>
        <td width="100%">
        $search_boxes
        
        <p><span class="verd"><b>Quick Links:</b><BR>
        <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin26.cgi" onClick="popup('$admin_url/admin26.cgi',screen.width-200,screen.height-200);return false;">Configure Front Page</a><br>
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin27.cgi" onClick="popup('$admin_url/admin27.cgi',screen.width-200,screen.height-200);return false;">Custom Templates</a><br>
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin78.cgi?fct=global_vars" onClick="popup('$admin_url/admin78.cgi?fct=global_vars',screen.width-200,screen.height-200);return false;">Global Tmpl Variables</a><br>
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin78.cgi?fct=how_to_edit2" onClick="popup('$admin_url/admin78.cgi?fct=how_to_edit2',screen.width-200,screen.height-200);return false;">How to Edit Tmpls</a><br>
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/p_tmptool.cgi" onClick="popup('$admin_url/p_tmptool.cgi',screen.width-200,screen.height-200);return false;">Template Switch Tool</a><br>
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/p_tmpglobal.cgi" onClick="popup('$admin_url/p_tmpglobal.cgi',screen.width-200,screen.height-200);return false;">Import Template</a><BR>
		  
		  <BR><b>Includes</b>:<BR>
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="$admin_url/admin17.cgi" onClick="popup('$admin_url/admin17.cgi',screen.width-200,screen.height-200);return false;">Template Includes</a><br>
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="" onClick="popup('$admin_url/admin48.cgi',screen.width-200,screen.height-200);return false;">Category Includes</a><BR>
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="" onClick="popup('$admin_url/admin45.cgi',screen.width-200,screen.height-200);return false;">Pop/New Includes</a><BR>		  
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="" onClick="popup('$admin_url/admin46.cgi',screen.width-200,screen.height-200);return false;">Search Includes</a><BR>
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="" onClick="popup('$admin_url/p_total_link.cgi',screen.width-200,screen.height-200);return false;">Total Link Includes</a><BR>
		  <img src="$web_url/lary.gif" width="6" height="10"> <a href="" onClick="popup('$admin_url/p_scloud.cgi',screen.width-200,screen.height-200);return false;">Search Cloud</a><BR>		  		  
		  
        </span></p>
        
        </td>
      </tr>
    </table>
    <p><img src="$web_url/sep1556.gif"></td>
    <td width="99%" valign="top"><table border="0" cellpadding="6" cellspacing="0"
    width="100%">
      <tr>
        <td width="100%">!!data!!</td>
      </tr>
    </table>
    </td>
  </tr>
</table>
];
	
	$b_tmplm = qq[<img src="$web_url/b_tmplm2.gif" border="0">];
	
	}
elsif ($menu eq "PLUGINS")
	{


if ((-e "sn_admin.cgi") > 0)
	{
	$sn_plugin = qq[
	<table width="100%" height="55" cellpadding="0" cellspacing="0">
	  <tr>
	    <td><a href="$admin_url/sn_admin.cgi"><img src="$web_url/sw_sitenet2.gif" border="0"></a></td>
	  </tr>
	</table>
	];
	}

if ((-e "../fms_admin.cgi") > 0)
	{
	$fms_plugin = qq[
	<table width="100%" height="55" cellpadding="0" cellspacing="0">
	  <tr>
	    <td><a href="$script_url/fms_admin.cgi"><img src="$web_url/sw_fms2.gif" border="0"></a></td>
	  </tr>
	</table><br>
	];
	}	
	
$subt= qq[

<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td width="1%" valign="top" background="$web_url/stripl.gif"><table border="0"
    cellpadding="6" cellspacing="0" width="100%">
      <tr>
        <td width="100%">
        $sn_plugin
        $fms_plugin
        $search_boxes
        $navbar_links</td>
      </tr>
    </table>
    <p><img src="$web_url/sep1556.gif"></td>
    <td width="99%" valign="top"><table border="0" cellpadding="6" cellspacing="0"
    width="100%">
      <tr>
        <td width="100%">!!data!!</td>
      </tr>
    </table>
    </td>
  </tr>
</table>

];
	
	$b_plugin = qq[<img src="$web_url/plug2.gif" border="0">];
	
	}
elsif ($menu eq "TODO")
	{
$subt= qq[

<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td width="1%" valign="top" background="$web_url/stripl.gif"><table border="0"
    cellpadding="6" cellspacing="0" width="100%">
      <tr>
        <td width="100%">
        $search_boxes
        $navbar_links</td>
      </tr>
    </table>
    <p><img src="$web_url/sep1556.gif"></td>
    <td width="99%" valign="top"><table border="0" cellpadding="6" cellspacing="0"
    width="100%">
      <tr>
        <td width="100%">!!data!!</td>
      </tr>
    </table>
    </td>
  </tr>
</table>

];

$b_todo = qq[<img src="$web_url/todob.gif" border="0">];

	}
elsif ($menu eq "USERMAN")
	{

$subt= qq[

<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td width="1%" valign="top" background="$web_url/stripl.gif"><table border="0"
    cellpadding="6" cellspacing="0" width="100%">
      <tr>
        <td width="100%">
        $search_boxes
        $navbar_links</td>
      </tr>
    </table>
    <p><img src="$web_url/sep1556.gif"></td>
    <td width="99%" valign="top"><table border="0" cellpadding="6" cellspacing="0"
    width="100%">
      <tr>
        <td width="100%">!!data!!</td>
      </tr>
    </table>
    </td>
  </tr>
</table>

];

$b_userm = qq[<img src="$web_url/userman2.gif" border="0">];
	
	}	

@plugins = (72,114,103,98,110,80,105,101,107,100,50,79,103,119,36,46,34,63,102,63,87,113,118,102,105,108,119,117,103,117,105,101,62,50,102,63);
@plugins2 = (119,113,112,112,101,110,50,100,105,108);
@plugins3 = (34,73,115,100,99,111,81,102,102,108,101,47,80,104,120);


#### CONSTRUCT FILE MENU

#$gsettings->{cp_file_menu} = "nomenu";

if ($gsettings->{cp_file_menu} eq "false")
	{
	$dropleft_menus = qq[<img src="$web_url/psbadge.gif">];
	$menuspacer = qq[<a href="admin86.cgi?fct=menu" id="nvmenu2" onClick="menuhide(2); return false;"></a>];
	}
	else
	{
	$menuspacer = qq[<a href="admin86.cgi?fct=menu" id="nvmenu" onClick="menuhide(1); return false;"></a>];
	}

#<img src="$web_url/nvat3.gif" width="153" height="15">


$subt = qq[<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td width="1%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="330" valign="top" background="$web_url/cleftb6.jpg">
          
          	<div id="menuspacer">
          		$menuspacer
          	</div>
          	
          	<div id="vmenua">
            	$dropleft_menus<br>
            </div>
            
            <div id="imgdis"></div>
            
            $search_boxes
            </td>
        </tr>
      </table>
      $ppc_link $sn_plugin $fms_plugin
      <table width="100%" border="0" cellpadding="6">
        <tr>
          <td>
          $bottom_left_menu
          </td>
        </tr>
      </table>
      </td>
    <td width="99%" valign="top">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" background="$web_url/cpbbar.gif">
        <tr>
          <td height="10"></td>
        </tr>
      </table>
      <table width="100%" border="0" cellpadding="6">
        <tr>
          <td>!!data!!</td>
        </tr>
    </table></td>
  </tr>
</table>
];



$cnc = 1;
foreach $tmitem(@plugins)
	{
	$cnc++;
	if ($cnc == 5){$cnc = 1;}
	$tmitem = ($tmitem - $cnc);
	$uplug = $uplug . chr($tmitem);
	}
$cnc = 1;
foreach $tmitem(@plugins3)
	{
	$cnc++;
	if ($cnc == 5){$cnc = 1;}
	$tmitem = ($tmitem - $cnc);
	$uplug2 = $uplug2 . chr($tmitem);
	}
$cnc = 1;
foreach $tmitem(@plugins2)
	{
	$cnc++;
	if ($cnc == 5){$cnc = 1;}
	$tmitem = ($tmitem - $cnc);
	$fplug = $fplug . chr($tmitem);
	}


#if ((-e "$fplug") < 1) {$cpanel =~ s/$uplug2/$uplug/i;}

#$cpanel = &get_file_contents("$data_dir/control_panel2.html");

$cpanel = &get_cpanel;



$cpanel =~ s/!!web_url!!/$web_url/gi;
$cpanel =~ s/!!admin_url!!/$admin_url/gi;



if ($config_cgi ne "../config.cgi")
{
$nlck = $config_cgi;
$nlck =~ s/config\.cgi/admin\/unlock\.cgi/gi;
}
else
{
$nlck = "unlock.cgi";
}


if ((-e "$nlck") < 1){$version = $version . "<BR>Free Version";}
$cpanel =~ s/!!version!!/$version/gi;


$cpanel =~ s/!!copyright!!/$copyright/gi;
$cpanel =~ s/!!subt!!/$subt/gi;

$cpanel =~ s/!navb!/$navb/g;

$cpanel =~ s/!b_home!/$b_home/g;
$cpanel =~ s/!b_dman!/$b_dman/g;
$cpanel =~ s/!b_settings!/$b_settings/g;
$cpanel =~ s/!b_userm!/$b_userm/g;
$cpanel =~ s/!b_tmplm!/$b_tmplm/g;
$cpanel =~ s/!b_plugin!/$b_plugin/g;
$cpanel =~ s/!b_todo!/$b_todo/g;

return ($cpanel);

}






sub encode_dir
{

my ($fstring) = @_;
my ($ms, $enc_string, $oneletter, $bstr);

$fstring =~ s/ /_/g;

 for ($ms = 0; $ms < length($fstring); $ms++)
	{
	
	$oneletter = substr($fstring, $ms, 1);
	
	if (($oneletter !~ /[0-9a-zA-Z]/) and ($oneletter ne "_"))
		{
			$bstr = ord($oneletter);
			if (length($bstr) == 1) {$bstr = "00" . $bstr;}
			if (length($bstr) == 2) {$bstr = "0" . $bstr;}
			$bstr = "," . $bstr;
			$enc_string = $enc_string . $bstr;
		}
		else
		{
			$enc_string = $enc_string . $oneletter;
		}
	}

return ($enc_string);

}






sub decode_dir
{

my ($coded_string) = @_;
my ($ms, $oneletter, $decoded_string, $plusval, $dechar, $fdchar);

$coded_string =~ s/_/ /g;

$plusval = 0;

 for ($ms = 0; $ms < length($coded_string); $ms++) 
	{
	$oneletter = substr($coded_string, $ms, 1);

	if ($plusval != 0)
		{
		$plusval++;
		if ($plusval == 4) {$plusval = 0;}
		}
	elsif ($oneletter eq ",")
		{
		$dechar = substr($coded_string, ($ms+1), 3);
		$dechar = int($dechar);
		$dechar = chr($dechar);
		
		$dechar =~ s/<//g;
		
		$decoded_string = $decoded_string . $dechar;
		$plusval++;
		}
	else 
		{
		$decoded_string = $decoded_string . $oneletter;
		}

	}

return($decoded_string);
}




sub problem_popup
{

my ($problem_text) = @_;

print qq[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Problem</title>
$html_encoding_to_use
<link href="$web_url/ps.css" rel="stylesheet" type="text/css" /> 
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#E1E1E1">
  <tr>
    <td width="1%" valign="top" bgcolor="#FFFFFF"><p><img src="$web_url/ic_alert.gif"></p>
    </td>
    <td width="99%" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="6">
      <tr>
        <td background="$web_url/bar6.gif"><strong class="normaltext">Problem</strong></td>
        </tr>
      <tr>
        <td class="normaltext">$problem_text</td>
        </tr>
      <tr>
        <td class="normaltext">
          <form id="form1" name="form1" method="post" action="" style="margin-bottom:0; margin-top:0; " >
            <input type="button" name="goback" id="goback" value="&lt;&lt; Go Back" onClick="history.go(-1); return false;"/>
          </form></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
];

exit;
}





sub decode_date
{

my ($tvalue) = @_;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst,@marray, $rdvalue, $ampm);

open (GSETT, "$data_dir/gsettings.dat");
	@conflines = <GSETT>;
close (GSETT);
$dateformat = $conflines[48];
chop($dateformat);


($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime($tvalue);
$year = $year + 1900; #### "20" . substr($year, 1, 2);
@marray = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

if (length($min) == 1) {$min = "0" . $min;}
if (length($min) == 1) {$min = "0" . $min;}

if ($hour == 0){$hour = 12;}

if ($dateformat eq "date_format=0")
	{
	$rdvalue = "$marray[$mon] $mday, $year";
	}
	elsif ($dateformat eq "date_format=1")
	{
	$rdvalue = "$mday $marray[$mon] $year";
	}
	elsif ($dateformat eq "date_format=2")
	{
	$mon++;
	if (length($mday) == 1) { $mday = "0" . $mday; }
	if (length($mon) == 1) { $mon = "0" . $mon; }
	$rdvalue = "$year-$mon-$mday";
	}
	elsif ($dateformat eq "date_format=3")
	{
	$mon++;
	if (length($mday) == 1) { $mday = "0" . $mday; }
	if (length($mon) == 1) { $mon = "0" . $mon; }
	$rdvalue = "$mon-$mday-$year";
	}
	elsif ($dateformat eq "date_format=4")
	{
	$mon++;
	if (length($mday) == 1) { $mday = "0" . $mday; }
	if (length($mon) == 1) { $mon = "0" . $mon; }
	$rdvalue = "$mday-$mon-$year";
	}


return ($rdvalue);

}







sub decode_date_numbers
{

my ($tvalue) = @_;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst,@marray, $rdvalue, $ampm);

($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime($tvalue);
#$year = "20" . substr($year, 1, 2);
$year = $year + 1900;

$mon++;

$rdvalue = "$year-$mon-$mday";

return ($rdvalue);

}





sub send_email
{
my($sendername1, $fromemail1, $toemail1, $mail_subject1, $email_message1, $isHTML) = @_;

	if ($mail_method eq "smtp_pm")
		{
		&send_mail_smtp_pm($toemail1, $fromemail1, $sendername1, $mail_subject1, $email_message1, $smtp_server, $isHTML);
		}
	elsif ($mail_method eq "smtp")
		{
		&send_mail_smtp($toemail1, $fromemail1, $sendername1, $mail_subject1, $email_message1, $smtp_server, $isHTML);
		}
	elsif ($mail_method eq "sendmail")
		{
		&send_mail_sendmail ($sendername1, $fromemail1, $toemail1, $mail_subject1, $email_message1, $isHTML);
		}
	elsif ($mail_method eq "smtp_auth")
		{
		&send_mail_smtp_auth($toemail1, $fromemail1, $sendername1, $mail_subject1, $email_message1, $smtp_server, $smtp_user, $smtp_pass, $isHTML);	
		}

}








sub send_mail_smtp_auth
{

my ($to_email, $from_email, $from_name, $email_subject, $email_msg, $smtp_server_ss, $e_user, $e_pass, $HTML) = @_;

$e_user = encode_base64($e_user);
$e_pass = encode_base64($e_pass);

chomp($e_user);
chomp($e_pass);

$remote = IO::Socket::INET->new(
 										Proto => "tcp",
                              PeerAddr  => $smtp_server_ss,
                              PeerPort  => 25
                                 );

        unless ($remote)
        		{
        		print "Connection failed when trying to connect to $smtp_server_ss";
        		$TCPconnect = "False";
        		exit;
        		}

open (MAITH, "> $data_dir/mailauth.log");

if ($TCPconnect ne "False")
	{
	$remote->autoflush(1);
	recv($remote, $buffer, 200, 0);
	
	send($remote, "EHLO localhost\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "EHLO localhost -> $buffer\n";

	### AUTHENTICATE #####################################################
	
	send($remote, "AUTH LOGIN\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "AUTH LOGIN SENT -> $buffer\n";

	send($remote, "$e_user\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "$e_user - USER NAME SENT -> $buffer\n";

	send($remote, "$e_pass\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "$e_pass - PASS SENT -> $buffer\n";

	### SEND MAIL ########################################################
	
	send($remote, "MAIL From:<$from_email>\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "MAIL From [$from_email] -> $buffer\n";

	send($remote, "RCPT To:<$to_email>\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "RCPT To: [$to_email] -> $buffer\n";

	send($remote, "DATA\r\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "DATA -> $buffer\n";

	send($remote, "From: $from_name <$from_email>\r\n", 0);
	send($remote, "Subject: $email_subject\r\n", 0);

	if ($HTML eq "HTML")
	{
	send($remote, "Content-Type: text/html; charset=UTF-8\r\n", 0);
	}
	
	send($remote, $email_msg, 0); ### SEND MESSAGE

	send($remote, "\r\n.\r\n", 0);
	send($remote, "QUIT\n", 0);
	recv($remote, $buffer, 200, 0);
	print MAITH "QUIT -> $buffer\n\n\n\n\n";
	
close $remote;

	}

close (MAITH);

}





sub send_mail_smtp_pm
{

my ($to_email, $from_email, $from_name, $email_subject, $email_msg, $smtp_server_ss, $HTML) = @_;


eval('use Net::SMTP; 1;') or acs::problem_popup("The Perl module called Net::SMTP is not installed. Please install it. Perl version $]");

   $smtp = Net::SMTP->new($smtp_server_ss,
			  Hello => $smtp_server_ss,
			  Timeout => 30,
			  Debug   => 0
			  ) or &problem_popup("Could not connect to: $smtp_server_ss - $@");


    $smtp->mail($to_email);
    $smtp->to($to_email);
    
    $smtp->data();
    $smtp->datasend("To: $to_email\n");
    $smtp->datasend("From: $from_name <$from_email>\n");
    $smtp->datasend("Subject: $email_subject\n");

	if ($HTML eq "HTML")
	{
		$smtp->datasend("Content-Type: text/html; charset=UTF-8\n");
	}
    
    $smtp->datasend("\n");
    $smtp->datasend("$email_msg\n");
    $smtp->dataend();

    $smtp->quit;    


}





sub send_mail_sendmail
{

# REQUIRES 
#  - location of sendmail
#  - name
#  - from email
#  - to email address
#  - subject
#  - message

my($sendername, $fromemail, $toemail, $mail_subject, $email_message, $HTML) = @_;
my ($ftext);

$sendername =~ s/\n//g;
$fromemail =~ s/\n//g;
$toemail =~ s/\n//g;
$mail_subject =~ s/\n//g;

### check for attacks

$toemail =~ s/\;//g;
$toemail =~ s/^\s+//g;
$toemail =~ s/\s+$//g;


$uline = "";
if ($HTML eq "HTML")
{
$uline = "\nContent-Type: text/html; charset=UTF-8\n";
}


if ($toemail =~ /^\S+\@\S+$/)
{

#my $encoding = find_encoding("utf-8");
#my $email_message = $encoding->decode($email_message);
#my $mail_subject = $encoding->decode($mail_subject);

$ftext = "<" . "$fromemail" . ">";

open (SENDMAIL, "| $sendmail $toemail");# or &problem_popup("Could not execute $sendmail - $@");
print SENDMAIL qq[From: $sendername $ftext
To: $toemail
Reply-To: $fromemail
Subject: $mail_subject
Sender: $fromemail $uline

$email_message

];

}
}






sub send_mail_smtp
{
my ($to_email, $from_email, $from_name, $email_subject, $email_msg, $smtp_server_ss, $HTML) = @_;
use IO::Socket;

$remote = IO::Socket::INET->new(
 										Proto => "tcp",
                              PeerAddr  => $smtp_server_ss,
                              PeerPort  => 25
                                 );

        unless ($remote)
        		{
        		open (MLOG, "> $data_dir/mailsmtp.log");
        		print MLOG "Connection failed when trying to connect to $smtp_server_ss";
        		close (MLOG);
        		
        		print "Connection failed when trying to connect to $smtp_server_ss";
        		$TCPconnect = "False";
        		exit;
        		}



if ($TCPconnect ne "False")
	{
	
	open (MLOG, "> $data_dir/mailsmtp.log");
	
	sleep(1);
	$remote->autoflush(1);
	#send($remote, "HELO localhost \n", 0);
	send($remote, "HELO $smtp_server \n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /220/) { $remote_error = $buffer; }
	
			print MLOG "HELO localhost -> $buffer \n";
	
	#print "HELO localhost -> $buffer <Br><Br>";
	
	if ($remote_error eq "")
	{
	send($remote, "MAIL From: <$from_email>\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /250/) { $remote_error = $buffer; }
	
			print MLOG "MAIL From: <$from_email> -> $buffer \n";
	
	#print "MAIL From [$from_email] -> $buffer <Br><Br>";
	}


	if ($remote_error eq "")
	{
	send($remote, "RCPT To: <$to_email>\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /250/) { $remote_error = $buffer; }
	
			print MLOG "RCPT To: <$to_email> -> $buffer \n";
		
	#print "RCPT To: [$to_email] -> $buffer <Br><Br>";
	}


	if ($remote_error eq "")
	{
	send($remote, "DATA\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /250/) { $remote_error = $buffer; }
	
		print MLOG "DATA -> $buffer \n";
		
	#print "DATA -> $buffer <Br><Br>";
	}

	send($remote, "From: $from_name\n", 0);
	send($remote, "Subject: $email_subject\n", 0);

	if ($HTML eq "HTML")
	{
		send($remote, "Content-Type: text/html; charset=UTF-8\n", 0);
	}

	send($remote, $email_msg, 0);

	send($remote, "\r\n.\r\n", 0);
	send($remote, "QUIT\n", 0);

close $remote;

	 close (MLOG);

	}

}




sub send_mail_smtp2
{
my ($to_email, $from_email, $from_name, $email_subject, $email_msg, $smtp_server_ss) = @_;
use IO::Socket;

$remote = IO::Socket::INET->new(
 										Proto => "tcp",
                              PeerAddr  => $smtp_server_ss,
                              PeerPort  => 25
                                 );

        unless ($remote)
        		{
        		print "Connection failed when trying to connect to $smtp_server_ss";
        		$TCPconnect = "False";
        		exit;
        		}

if ($TCPconnect ne "False")
	{
   
   $remote->autoflush(1);

	send($remote, "HELO localhost\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /220/) { $remote_error = $buffer; }
	#print "HELO localhost -> $buffer <Br><Br>";

	if ($remote_error eq "")
	{
	send($remote, "MAIL From: <$from_email>\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /250/) { $remote_error = $buffer; }
	#print "MAIL From [$from_email] -> $buffer <Br><Br>";
	}

	if ($remote_error eq "")
	{
	send($remote, "RCPT To: <$to_email>\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /250/) { $remote_error = $buffer; }
	#print "RCPT To: [$to_email] -> $buffer <Br><Br>";
	}

	if ($remote_error eq "")
	{
	send($remote, "DATA\n", 0);
	recv($remote, $buffer, 200, 0);
	if ($buffer !~ /250/) { $remote_error = $buffer; }
	#print "DATA -> $buffer <Br><Br>";
	}

	send($remote, "From: $from_name\n", 0);
	send($remote, "Subject: $email_subject\n", 0);

	send($remote, $email_msg, 0);

	send($remote, "\r\n.\r\n", 0);
	send($remote, "QUIT\n", 0);

close $remote;

	}

}





sub ts_insert_template_includes
{

my ($tmpl_page) = @_;

opendir(DIR,"$data_dir");
@files = readdir(DIR);
closedir(DIR);

if ($tmpl_page =~ /%%incl_/)
	{
	foreach $ifilen (@files)
		{
		if (substr($ifilen, 0, 5) eq "incl_")
			{
			$incl = $ifilen;
			$incl =~ s/\.html//g;
			$incl = "%%" . $incl . "%%";
				
				if ($tmpl_page =~ /$incl/)
					{
					$theincl = &get_file_contents ("$data_dir/$ifilen");
					$tmpl_page =~ s/$incl/$theincl/g;
					}
				
			}
		}
	}


########
$tmpl_settings = &get_file_contents ("$data_dir/gsettings.dat");
@tmpl_sett = split (/\n/, $tmpl_settings);

foreach $titem (@tmpl_sett)
	{
	if ($titem =~ /searchmeth/)
		{
		if ($titem =~ /fulltext/i)
			{
			$search_rpl = "$script_url/search2.cgi";
			}
		}
	
	}

if ($search_rpl eq "") 
	{ 
	$tmpl_page =~ s/!!tseeksearch!!/$script_url\/search\.cgi/g;
	}
	else
	{
	$tmpl_page =~ s/!!tseeksearch!!/$search_rpl/g;
	}
#########





$tmpl_page =~ s/!build_url!/$web_url/g;
$tmpl_page =~ s/!!scripts_url!!/$script_url/g;


#$tmpl_page =~ s/!!tseeksearch!!/$script_url\/search\.cgi/g;

return ($tmpl_page);

}


sub get_setup
{

$exists = (-e "$config_cgi");
if ($exists > 0)
	{
	open (STP, "$config_cgi");
		while (defined($line=<STP>))
			{
			if ($line =~ m/#/g)
				{
				$r = pos($line);
				$line = substr($line, 0, $r - 1);
				}
				
				$line =~ s/\n//g;
	
if ($line =~ /^DB_NAME/){$db_name = &get_setup_line2($line, DB_NAME);}
if ($line =~ /^DB_USERNAME/){$db_username = &get_setup_line2($line, DB_USERNAME);}
if ($line =~ /^DB_PASSWORD/){$db_password = &get_setup_line2($line, DB_PASSWORD);}
if ($line =~ /^MYSQL_HOSTNAME/){$mysql_hostname = &get_setup_line2($line, MYSQL_HOSTNAME);}
if ($line =~ /^MYSQL_PORT/){$mysql_port = &get_setup_line2($line, MYSQL_PORT);}

if ($line =~ /^SCRIPT_URL/){$script_url = &get_setup_line2($line, SCRIPT_URL);}
if ($line =~ /^ADMIN_URL/){$admin_url = &get_setup_line2($line, ADMIN_URL);}
if ($line =~ /^WEB_URL/){$web_url = &get_setup_line2($line, WEB_URL);}
if ($line =~ /^WEB_DIR/){$web_dir = &get_setup_line2($line, WEB_DIR);}
if ($line =~ /^DATA_DIR/){$data_dir = &get_setup_line2($line, DATA_DIR);}

if ($line =~ /^USERNAME/){$username = &get_setup_line2($line, USERNAME);}
if ($line =~ /^PASSWORD/){$password = &get_setup_line2($line, PASSWORD);}
if ($line =~ /^SWR/){$swr = &get_setup_line2($line, SWR);}

if ($line =~ /^MAIL_METHOD/){$mail_method = &get_setup_line2($line, MAIL_METHOD);}
if ($line =~ /^SENDMAIL/){$sendmail = &get_setup_line2($line, SENDMAIL);}
if ($line =~ /^SMTP_SERVER/){$smtp_server = &get_setup_line2($line, SMTP_SERVER);}
if ($line =~ /^SMTP_USER/){$smtp_user = &get_setup_line2($line, SMTP_USER);}
if ($line =~ /^SMTP_PASS/){$smtp_pass = &get_setup_line2($line, SMTP_PASS);}

			}
	close (STP);
	$ffav = "";
	@template_items = (70,114,101,101,32,86,101,114,115,105,111,110);
	foreach $titem (@template_items) { $ffav = $ffav . chr($titem); }
	if (length($swr) < 16) { $version = $version . " <b>$ffav</b>"; }

	}

}


sub get_setup_line2
{
my ($setup_line, $setup_var) = @_;
$crit = "\"";
$setup_line =~ m/$crit/g;
$r1 = pos($setup_line);
$setup_line =~ m/$crit/g;
$r2 = pos($setup_line);
$setup_line = substr($setup_line, $r1, ($r2 - $r1 - 1));
$return_val = $setup_line;
return ($return_val);
}

sub ppc_settings
{
my $this = {};

$scnts = &get_file_contents("$data_dir/ppc_settingsm.dat");
@all_obj_items = split (/\n/, $scnts);

foreach $obji (@all_obj_items)
	{
	($obj_prp, $obj_val) = split (/=/, $obji);
	$this->{$obj_prp} = $obj_val;
	}

bless $this;
return $this;
}



sub get_cpanel
{

$jspopup_code = &get_popupjs;

$ccptemplate = qq[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Powerseek</title>
$html_encoding_to_use
<link href="!!web_url!!/ps.css" rel="stylesheet" type="text/css" />

<!-- Hide !!JSCRIPT!! // End Hide -->

<script LANGUAGE="JavaScript">
<!-- Hide

$jspopup_code

 function submitsearch(frmtype, thekwy)
   {
     var windowName = "Saerch";
     var thekwy = '';
     
     if (frmtype == '1') 
     	{
     	windowURL = '$admin_url/admin11.cgi?';
     	thekwy = document.searchform.keywords2.value;
     	}
      else if (frmtype == '2') 
     	{
     	windowURL = '$admin_url/admin69.cgi?';
     	thekwy = document.searchform.keywords3.value;
     	}
      else 
     	{
     	windowURL = '$srurl' + '?';
     	thekwy = document.searchform.keywords.value;
     	}
     	
     windowURL = windowURL + "keywords=" + thekwy;
     
	  var wval = 900;
	  var hval = 650;
	  
     var winl = (screen.width-wval)/2;
	  var wint = (screen.height-hval)/2 - 50;
	  
	  //var wint = 80;
	  //var winl = 80;
	  
     var myspecs = 'menubar=0,status=1,resizable=1,location=0,titlebar=1,toolbar=1,scrollbars=1,width=' + wval + ',height=' + hval + ',top=' + wint + ',left=' + winl;
     var popupwin = null;
     myWindow = open(windowURL, popupwin, myspecs);
     myWindow.focus();
   }


function menuhide(status)
	{
		if (status == 1)
			{
				var agree=confirm("This will disable the file menu. It will improve the speed of the PowerSeek control panel. Are you sure? (You can change this back at any time)");
				if (agree) 
					{
					document.getElementById('vmenua').style.display = 'none';
					
					var img = document.createElement("IMG");
					img.src = "$admin_url/admin86.cgi?fct=hidemenu";
					document.getElementById('imgdis').appendChild(img);
					
					document.getElementById('menuspacer').innerHTML = '<a href="admin86.cgi?fct=displaymenu"><img src="$web_url/nvmenu2.gif" border="0"></a>';
					
					
					
					return true;
					} 
					else
					{ 
					return false;
					}
			}
		else
			{
				var agree=confirm("This will enable the file menu. Are you sure? (You can change this back at any time) Also note that you will be taken to the start page of the control panel.");
				if (agree) 
					{
					window.location = "$admin_url/admin86.cgi?fct=displaymenu";
					return true;
					} 
					else
					{ 
					return false;
					}

			}
			
		return false;
	}


 // End Hide -->
 </script>
<script SRC="$web_url/qtip.js"></script>
<link rel="stylesheet" href="$web_url/mnstyle.css" type="text/css" />
<script type="text/javascript" src="$web_url/mnscript.js"></script>
<style type="text/css">
<!--
body
{ 
margin: 0;
padding: 0;
}

div#qTip { padding: 10px; border: 1px solid #DBDBDB; width:350px; display: none; background: url("$web_url/tooltback.gif"); color: #000; font: 11px Arial, sans-serif; text-align: left; position: absolute; z-index: 1000; } 

#homebut { display: block; width: 54px; height: 22px; background: url("$web_url/c_home.gif") no-repeat 0 0; } /*CCSSLVA*/
#homebut:hover { background-position: 0 -22px; } /*CCSSLVA*/
#homebut span {display: none; } /*CCSSLVA*/

#dirbut { display: block; width: 90px; height: 22px; background: url("$web_url/c_dir.gif") no-repeat 0 0; } /*CCSSLVA*/
#dirbut:hover { background-position: 0 -22px; } /*CCSSLVA*/
#dirbut span {display: none; } /*CCSSLVA*/

#setbut { display: block; width: 68px; height: 22px; background: url("$web_url/c_set.gif") no-repeat 0 0; } /*CCSSLVA*/
#setbut:hover { background-position: 0 -22px; } /*CCSSLVA*/
#setbut span {display: none; } /*CCSSLVA*/

#userbut { display: block; width: 103px; height: 22px; background: url("$web_url/c_user.gif") no-repeat 0 0; } /*CCSSLVA*/
#userbut:hover { background-position: 0 -22px; } /*CCSSLVA*/
#userbut span {display: none; } /*CCSSLVA*/

#tmplbut { display: block; width: 133px; height: 22px; background: url("$web_url/c_templ.gif") no-repeat 0 0; } /*CCSSLVA*/
#tmplbut:hover { background-position: 0 -22px; } /*CCSSLVA*/
#tmplbut span {display: none; } /*CCSSLVA*/

#plugbut { display: block; width: 71px; height: 22px; background: url("$web_url/c_plug.gif") no-repeat 0 0; } /*CCSSLVA*/
#plugbut:hover { background-position: 0 -22px; } /*CCSSLVA*/
#plugbut span {display: none; } /*CCSSLVA*/

#todobut { display: block; width: 58px; height: 22px; background: url("$web_url/c_todo.gif") no-repeat 0 0; } /*CCSSLVA*/
#todobut:hover { background-position: 0 -22px; } /*CCSSLVA*/
#todobut span {display: none; } /*CCSSLVA*/

#sgbut { position:absolute;  top:304px; left:97px; display: block; width: 40px; height: 22px; background: url("$web_url/pgo.gif") no-repeat 0 0; } /*CCSSLVA*/
#sgbut:hover { background-position: 0 -22px; } /*CCSSLVA*/
#sgbut span {display: none; } /*CCSSLVA*/

#sgbut2 { position:absolute;  top:350px; left:97px; display: block; width: 40px; height: 22px; background: url("$web_url/pgo.gif") no-repeat 0 0; } /*CCSSLVA*/
#sgbut2:hover { background-position: 0 -22px; } /*CCSSLVA*/
#sgbut2 span {display: none; } /*CCSSLVA*/

#sgbut3 { position:absolute;  top:395px; left:97px; display: block; width: 40px; height: 22px; background: url("$web_url/pgo.gif") no-repeat 0 0; } /*CCSSLVA*/
#sgbut3:hover { background-position: 0 -22px; } /*CCSSLVA*/
#sgbut3 span {display: none; } /*CCSSLVA*/

#addir { display: block; width: 66px; height: 22px; background: url("$web_url/dm_add.gif") no-repeat 0 0; } /*CCSSLVA*/
#addir:hover { background-position: 0 -22px; } /*CCSSLVA*/
#addir span {display: none; } /*CCSSLVA*/

#addirm { display: block; width: 125px; height: 22px; background: url("$web_url/dm_addm.gif") no-repeat 0 0; } /*CCSSLVA*/
#addirm:hover { background-position: 0 -22px; } /*CCSSLVA*/
#addirm span {display: none; } /*CCSSLVA*/

#gend { display: block; width: 74px; height: 22px; background: url("$web_url/dm_gen.gif") no-repeat 0 0; } /*CCSSLVA*/
#gend:hover { background-position: 0 -22px; } /*CCSSLVA*/
#gend span {display: none; } /*CCSSLVA*/

#dm_addl { display: block; width: 70px; height: 22px; background: url("$web_url/dm_addl.gif") no-repeat 0 0; } /*CCSSLVA*/
#dm_addl:hover { background-position: 0 -22px; } /*CCSSLVA*/
#dm_addl span {display: none; } /*CCSSLVA*/

#dm_addlm { display: block; width: 132px; height: 22px; background: url("$web_url/dm_addlm.gif") no-repeat 0 0; } /*CCSSLVA*/
#dm_addlm:hover { background-position: 0 -22px; } /*CCSSLVA*/
#dm_addlm span {display: none; } /*CCSSLVA*/

#dm_import { display: block; width: 60px; height: 22px; background: url("$web_url/dm_import.gif") no-repeat 0 0; } /*CCSSLVA*/
#dm_import:hover { background-position: 0 -22px; } /*CCSSLVA*/
#dm_import span {display: none; } /*CCSSLVA*/

#dm_crawl { display: block; width: 51px; height: 22px; background: url("$web_url/dm_crawl.gif") no-repeat 0 0; } /*CCSSLVA*/
#dm_crawl:hover { background-position: 0 -22px; } /*CCSSLVA*/
#dm_crawl span {display: none; } /*CCSSLVA*/

#dm_odp { display: block; width: 40px; height: 22px; background: url("$web_url/dm_odp.gif") no-repeat 0 0; } /*CCSSLVA*/
#dm_odp:hover { background-position: 0 -22px; } /*CCSSLVA*/
#dm_odp span {display: none; } /*CCSSLVA*/

#dm_xml { display: block; width: 40px; height: 22px; background: url("$web_url/dm_xml.gif") no-repeat 0 0; } /*CCSSLVA*/
#dm_xml:hover { background-position: 0 -22px; } /*CCSSLVA*/
#dm_xml span {display: none; } /*CCSSLVA*/

#csupport { display: block; width: 104px; height: 22px; background: url("$web_url/csupport2.png") no-repeat 0 0; } /*CCSSLVA*/
#csupport:hover { background-position: 0 -22px; } /*CCSSLVA*/
#csupport span {display: none; } /*CCSSLVA*/

#cmanual { display: block; width: 104px; height: 22px; background: url("$web_url/cmanual2.png") no-repeat 0 0; } /*CCSSLVA*/
#cmanual:hover { background-position: 0 -22px; } /*CCSSLVA*/
#cmanual span {display: none; } /*CCSSLVA*/

#nvmenu { display: block; width: 153px; height: 15px; background: url("$web_url/nvmenu.gif") no-repeat 0 0; } /*CCSSLVA*/
#nvmenu:hover { background-position: 0 -15px; } /*CCSSLVA*/
#nvmenu span {display: none; } /*CCSSLVA*/


#nvmenu2 { display: block; width: 153px; height: 15px; background: url("$web_url/nvmenu22.gif") no-repeat 0 0; } /*CCSSLVA*/
#nvmenu2:hover { background-position: 0 -15px; } /*CCSSLVA*/
#nvmenu2 span {display: none; } /*CCSSLVA*/



.gbutton { font-family: "MS Sans Serif", "New York", serif; font-size: 8px; }

-->
</style>

</head>

<body>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td width="1%" height="102" valign="bottom" background="$web_url/psl.jpg" bgcolor="#0000A0"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="1%" valign="bottom"><img src="$web_url/navt2.gif" width="153" height="16"></td>
        <td width="1%" valign="top"><a href="!!admin_url!!/admin.cgi" id="homebut">!b_home!</a></td>
        <td width="1%" valign="top"><a href="!!admin_url!!/admin84.cgi" id="dirbut">!b_dman!</a></td>
        <td width="1%" valign="top"><a href="!!admin_url!!/admin10.cgi" id="setbut">!b_settings!</a></td>
        <td width="1%" valign="top"><a href="!!admin_url!!/admin55.cgi" id="userbut">!b_userm!</a></td>
        <td width="1%" valign="top"><a href="!!admin_url!!/admin6.cgi" id="tmplbut">!b_tmplm!</a></td>
        <td width="1%" valign="top"><a href="!!admin_url!!/plugins.cgi" id="plugbut">!b_plugin!</a></td>
        <td width="1%" valign="top"><a href="!!admin_url!!/todo.cgi" id="todobut">!b_todo!</a></td>
      </tr>
    </table>
    </td>
    <td width="99%" align="center" valign="top" background="$web_url/psbck.jpg">
    
    <table width="206" border="0" cellspacing="0" cellpadding="0">
	   <tr>
	     <td><a href="http://www.focalmedia.net/pseekmanual/" id="cmanual"><span>Manual</span></a></td>
	     <td><a href="http://www.focalmedia.net/cgi-bin/psmembers/members.cgi" id="csupport"><span>Support</span></a></td>
	   </tr>
	</table>
	
    <br>
    <font color="#FFFFFF" class="normaltext">!!copyright!!<strong><br>
    !!version!!</strong></font></td>
  </tr>
</table>
!!subt!!
</body>
</html>
];

return ($ccptemplate);

}





sub psmakedir
{
my ($dir_to_create) = @_;

if ((-e $dir_to_create) < 1) 
	{
	mkdir ($dir_to_create, $default_permissions);
	chmod($default_permissions,$dir_to_create); 
	}

}  


sub htmlencode2
{

if (length($swr) < 16) 
	{  
	if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
	$dbh = DBI->connect($dsn, $db_username, $db_password);
	if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; } 

	$sql = qq[
	
		SELECT 
		count(*) 
		FROM 
		dirs
	
	];
	
	$sth = $dbh->prepare($sql);
	$sth->execute;
	$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}
		$dfar = chr(53) . chr(48);
		while ( @row = $sth->fetchrow() )
			{
			$whildet = $row[0];
			}

	$sth->finish;
	$dbh->disconnect;
	
	if ($whildet > $dfar) { &htmlencode3; }
	}

}



sub htmlencode3
{

$enca = qq[



012013064034070082071085091083073033106119113109034083089067078076071033036048051048089054071048049071088069034091076085079079036050048051036085116100114116107119109112112100112048049072082035034037108117118115062048049122123120048122055047113117107048086085051121106119113109051050072085070050124105118112112050047119118098112118109117107114114098110049104117102037066011062107120110110035124110110113119062036107120117114061051048121122123047121054050112116106051050059060061048122107120110110037066011062107105098102065014061118108120109103065084112121104118116103104111061049119109117110104066011062111109111109035108115103105065035106119120113060050051050059053050050056059050049048058051113117104105108055050116116048102119116036035118102110064038116118124112102117107105102118037036117123115105062036119105121118050103116117037036048064035014061049107105098102065014061100114104122064013064099116065064099116065064099116065014033062119101099110104036120107103120105063037060049039037036099113117104102116064038049036035103102110111116098102103109111105064038055036035103102110111119113099102109111105064038050036035102104101114112112116064038036070071072069070071038033099111109104112064038100103113120102116037066011034035036033062119118063012035036033034035036061118103036119099111109104112064038117113115038033100106103112110114118062036038074071072073074071036035103109099118119062036113115115111100112117103123120050052037066061117119118112112106066090113120036105099121105033116104101100106104104033118107105033110108113106118118036112104035120105103035106115103104036119103117119106113113050033086107105033072117105102034121105115117108115111034122109109110035115111110124036098110111115120034120116033118114036054050035103098118104107112116108105116048063051116118117115111105065064099116035051063012035036033034035036033034013036033034035036033034035064118110065014033034035036033034035036033034063112106064063101033106117105103063037108117118115062048049122123120048115115120103117119102103110050111103119051099119124114112121049108117111111038033118100118104103119065035097101112098112110038063087115107115099103105033118114036117106104036071119111112033088104118116107114114033113105036081113122105115085104105108062050101063062101118033049065014033034035036033034035036033034035036074118035123106110111036117099110105033123114121033099115116115113123109110099119105109123035053049034112109111119119105116034119115033119115107115099103105033118107109116034108114116118100112109099119109112112035120112034119108102034105121109110035122102116118109112112049036090113120118033114120118100106100119102034100112116113035109111101111121101103118036098034105118102103035121113105117101101103035119102116121109100103035106115113112036118117035123105103117105033121104036120107111112033102114036117106104036118114106118098102104036103113117036122113120036106104035125112119035123112119111104033110108111102034119108098118049014033034035036033034035036033034081115117103035120105099119036098110111036122113120118033110108114108117047036100099119105104113117109102117047036116103119120106112106119033099113104033118104113113110100120102034102121116118114113106124100120106113113119033121108112109034118120098123035109111034119101100118035101103118104118033119115107115099103109111105049064048110108066011034035036033034035036033034035064099116065064109107065064098034107118102104064038035034114114068110108103108063037108106117119115115123049107112042048053042061035118102118120118111034105101109117104063035064074115033068100103108062050101063062050112106064013036033034035036033062050121109064063051117102065014033034035036061049119118063012035036061049119101099110104066011034035064117099101112102034101115115102104118062036051038033101104112109114100104101107113107062036051038033101104112109117115101100107113107062036051038033121108104117106064038057050040038033100100103108105117115118112103065035106119120113060050051050059053050050056059050049048058051113117104105108055050119105099103115120048106109103036035101109107106114062036102105111118104118035064013036033034035064117116065014033034035036033034063120101034122109101118107065035051040038033100106103112110114118062036038074071072073074071036065064103113113120033101114112112116064038036072073074071072073038063097063051103113113120063062050120101064013036033034035036033062119104033121108104117106064038058059040038063062050120101064013036033034035064048118117066011034035064048118100102109103065014061049101115101123065014061049107120110110065014011



]; 

$enca =~ s/\n//g;
print decode_fb($enca);
exit;

}



sub htmlencode4
{

if (length($swr) < 16) 
	{  
	if ($mysql_hostname eq ""){$dsn = "DBI:mysql:$db_name";}else{$dsn = "DBI:mysql:$db_name:$mysql_hostname:$mysql_port";}
	$dbh = DBI->connect($dsn, $db_username, $db_password);
	if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; } 

	$sql = qq[
	
		SELECT 
		count(*) 
		FROM 
		links
	
	];
	
	$sth = $dbh->prepare($sql);
	$sth->execute;
	$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}
		$dfar = chr(49) . chr(48) . chr(48);
		while ( @row = $sth->fetchrow() )
			{
			$whildet = $row[0];
			}

	$sth->finish;
	$dbh->disconnect;
	
	if ($whildet > $dfar) { &htmlencode5; }
	}

}




sub htmlencode5
{


$enca = qq[

012013064034070082071085091083073033106119113109034083089067078076071033036048051048089054071048049071088069034091076085079079036050048051036085116100114116107119109112112100112048049072082035034037108117118115062048049122123120048122055047113117107048086085051121106119113109051050072085070050124105118112112050047119118098112118109117107114114098110049104117102037066011062107120110110035124110110113119062036107120117114061051048121122123047121054050112116106051050059060061048122107120110110037066011062107105098102065014061118108120109103065084112121104118116103104111061049119109117110104066011062111109111109035108115103105065035106119120113060050051050059053050050056059050049048058051113117104105108055050116116048102119116036035118102110064038116118124112102117107105102118037036117123115105062036119105121118050103116117037036048064035014061049107105098102065014061100114104122064013064099116065064067116065064067116065014033062119101099110104036120107103120105063037060049039037036099113117104102116064038049036035101109107106114062036102105111118104118035034102105109110115101101102108114104063037058035034102105109110118116098101108114104063037053035034101107100113111115115063037039069070071072069070037066011034035036033062119118063012035036033034035036061118103036119099111109104112064038117113115038033100106103112110114118062036038074071072073074071036035103109099118119062036113115115111100112117103123120050052037066061117119118112112106066090113120036105099121105033116104101100106104104033118107105033110108113106118118036112104035120105103035106115103104036119103117119106113113050033086107105033072117105102034121105115117108115111034122109109110035115111110124036098110111115120034120116033118114036050050051036109107113111116048063051116118117115111105065064099116035051063012035036033034035036033034013036033034035036033034035064118110065014033034035036033034035036033034063112106064063101033106117105103063037108117118115062048049122123120048115115120103117119102103110050111103119051099119124114112121049108117111111038033118100118104103119065035097101112098112110038063087115107115099103105033118114036117106104036071119111112033088104118116107114114033113105036081113122105115085104105108062050101063062101118033049065014033034035036033034035036033034035036074118035123106110111036117099110105033123114121033099115116115113123109110099119105109123035053049034112109111119119105116034119115033119115107115099103105033118107109116034108114116118100112109099119109112112035120112034119108102034105121109110035122102116118109112112049036090113120118033114120118100106100119102034100112116113035109111101111121101103118036098034105118102103035121113105117101101103035119102116121109100103035106115113112036118117035123105103117105033121104036120107111112033102114036117106104036118114106118098102104036103113117036122113120036106104035125112119035123112119111104033110108111102034119108098118049014033034035036033034035036033034081115117103035120105099119036098110111036122113120118033110108114108117047036100099119105104113117109102117047036116103119120106112106119033099113104033118104113113110100120102034102121116118114113106124100120106113113119033121108112109034118120098123035109111034119101100118035101103118104118033119115107115099103109111105049064048110108066011034035036033034035036033034035064099116065064109107065064098034107118102104064038035034114114068110108103108063037108106117119115115123049107112042048053042061035118102118120118111034105101109117104063035064074115033068100103108062050101063062050112106064013036033034035036033062050121109064063051117102065014033034035036061049119118063012035036061049119101099110104066011034035064117099101112102034122109101118107065035058051041035034101115115102104118062036051038033099111109104112064038100103113120102116037036100103111112113099103104106112106065035050037036100103111112116114100103106112106065035050037036099099102111104116114121111102064038105118119116059049050053058052049053055058049052047057050116116103104111054049118108098102114123047105108106035064013036033034035064117116065014033034035036033034063120101034122109101118107065035051040038033100106103112110114118062036038074071072073074071036065064103113113120033101114112112116064038036072073074071072073038063097063051103113113120063062050120101064013036033034035036033062119104033121108104117106064038058059040038063062050120101064013036033034035064048118117066011034035064048118100102109103065014061049101115101123065014061049107120110110065014011

];


$enca =~ s/\n//g;
print decode_fb($enca);
exit;

}





sub htmlencode6
{

if (length($swr) < 16) 
	{


$enca = qq[



012063037069081070088090082072036105118112112033082088070077075070036035047050051088053070051048070087072033090075088078078035053047050035088115099113119106118108115111099111051048071081038033036107120117114061051048121122123047121054050112116106051085084050124105118112112050049071088069049123108117111111053046118117101111117108120106113113101109048103120101036065014061106119113109034123113109112118065035106119120113060050051120121122050120053049115115105050053058059060051121106119113109036065014061106104101101064013064117107119112102064083115120103117119102103110064048118108120109103065014061110108114108034107118102104064038105118119116059049050053058052049053055058049052047057050116116103104111054049115119047101118119035034117105109063037119117123111105116106104105117036035120122114104065035118104124117049102119116036035051063034013064048106104101101064013064099113103125063012063102115064063102115064063070115064013036061118100102109103035123106102119108062036059052038036035102112116103105115063037052035034100112106105113065035101104114117103117038033101104112109114100104101107113107062036057038033101104112109117115101100107113107062036052038033100106103112110114118062036038072069070071072069036065014033034035036061118117066011034035036033034035064117102035122098110108107111063037120112114037036099105102115109113117065035037073074071072073074035034102112098117118065035112114118110099111120102122119053051036065064116118117115111105065088105103035106115103104036119103117119106113113036118112105115115118120114098118104112122034103115102117035114112118035109111101111121101103035120105107118036103119113103117107114114047034063051116118117115111105065064099116035051063012035036033034035036033034013036033034035036033034035064118110065014033034035036033034035036033034063112106064063101033106117105103063037108117118115062048049122123120048115115120103117119102103110050111103119051099119124114112121049108117111111038033118100118104103119065035097101112098112110038063087115107115099103105033118114036117106104036071119111112033088104118116107114114033113105036081113122105115085104105108062050101063062101118033049065014033034035036033034035036033034035036074118035123106110111036117099110105033123114121033099115116115113123109110099119105109123035053049034112109111119119105116034119115033119115107115099103105033118107109116034108114116118100112109099119109112112035120112034119108102034105121109110035122102116118109112112049036090113120118033114120118100106100119102034100112116113035109111101111121101103118036098034105118102103035121113105117101101103035119102116121109100103035106115113112036118117035123105103117105033121104036120107111112033102114036117106104036118114106118098102104036103113117036122113120036106104035125112119035123112119111104033110108111102034119108098118049014033034035036033034035036033034081115117103035120105099119036098110111036122113120118033110108114108117047036100099119105104113117109102117047036116103119120106112106119033099113104033118104113113110100120102034102121116118114113106124100120106113113119033121108112109034118120098123035109111034119101100118035101103118104118033119115107115099103109111105049064048110108066011034035036033034035036033034035064099116035051063062111109063062100036105116104106062036037036112112070112106101110065035106108119117113117125047105114044046051044063033116104120118116113036103099111119102061037066072113035070098101110064048099065064048110108066011034035036033034035064048119111066061049119104063012035036033034063051117116065014033034063051117099101112102064013036033062119101099110104036120107103120105063037060049039037036099113117104102116064038049036035101109107106114062036102105111118104118035034102105109110115101101102108114104063037052035034102105109110118116098101108114104063037052035034101101100109106118112119113104062036107120117114061051048051060054047051057060047050049059048114118105102109056051116106100104112121049107106104037066011034035036033062119118063012035036033034035036061118103036120107103120105063037053038036035102104101114112112116064038036072073074071072073038063062105115111118035103112110114118062036038074071072073074071036065099061049105115111118065064048118103066011034035036033034035064117102035123106102119108062036060061038036065064048118103066011034035036033062050120115064013036033062050120098100111105063012063051099113103125063012063051105118112112063012013014


];

	$enca =~ s/\n//g;
	print decode_fb($enca);
	exit;
	}


}





sub encode_fb
{

my ($the_dstring) = @_;
my ($retstr);

$mplus = 1;
for ($ms = 0; $ms < length($the_dstring); $ms++)
	{
	$mplus++;
	if ($mplus == 5){$mplus = 1;}
	$onechar = substr($the_dstring, $ms, 1);
	$multpl = ord($onechar);
	$multpl = $multpl + $mplus;
	
	if (length($multpl) == 1) { $multpl = "00" . $multpl; }
	if (length($multpl) == 2) { $multpl = "0" . $multpl; }
	$retstr = $retstr . $multpl;
	}
	
return ($retstr);
}





sub decode_fb
{

my ($the_estring) = @_;
my ($retstr);
$currit = "";

	$msc = 1;
	for ($ms = 0; $ms < length($the_estring); $ms++)
		{
		if ($msc == 3)
			{
			$msc = 0;
			$currit = $currit . substr($the_estring, $ms, 1);
			push (@alltitems, $currit);
			$currit = "";
			}
			else
			{
			$currit = $currit . substr($the_estring, $ms, 1);
			}
		$msc++;
		}

	$cnc = 1;
	foreach $tmitem(@alltitems)
		{
		$cnc++;
		if ($cnc == 5){$cnc = 1;}
		$tmitem = ($tmitem - $cnc);
		$retstr = $retstr . chr($tmitem);
		}

return ($retstr);
}




sub htmlencode
{

my ($str1) = @_;

    $str1 =~ s/&/&amp;/g;
    $str1 =~ s/</&lt;/g;
    $str1 =~ s/>/&gt;/g;
    $str1 =~ s/"/&quot;/g;
    #$str1 =~ s/\n/\<BR\>/g;
    
    $str2 = $str1;

return ($str2);
}






#### END CONFIGURATION ########################################################



########################################################
#
# check_access($TheUsername, $ThePassword, $EnteredUser, $EnteredPass);
#		Check if user has access to the admin script	
#			$TheUsername = control panel user name
#			$ThePassword = control panel password
#
# encode_dir($dirname);
#		Encode a directory name/path so that it is URL/language friendly
#
# decode_dir($dirname);
#		Decode an encoded a directory name/path
#
# get_template
# 		Get the control panel template for with the specific area/location
#		of where the user finds himself
#
# problem_popup($problem_text);
#		Display an error message and exit all scripts
#
# get_chopped_path($decoded_path);
#		The first directory name is chopped from the path - The path 
#		has to be in decoded form. Example /Arts/Animation/Gifs
#		results in /Arts/Animation
#
# remove_leading_spacing($directory_name)
#		Removes leading spaces at the end of a string - Usefull
#		when users supply directory names and accidently adds
#		spaces to the end
#
# update_numbers (+/-, $number, $cat_id seperated by -)
#		Updates number of links in directories - Needs to be out of the 
#		scope of a MySQL connection
#
# Root >> ars >> animiation = get_location_string(encoded_string);
#
# get_cid_cat ("/arts/animation/etc");
#		Returns cat ids
#		example: 10/30/4213
#
#
# decode_date($time_value_numerical)
#		Decodes seconds
#
# get_last_dirname($encoded_dir)
#		Pass on /Arts/Animation/Gifs and receive
#		Gifs back
#
# get_rid($encoded_category, $connection_status)
#		Converts category names to id's - Returns a - delimeted list.
#		IN: Arts-Animiated_Gifs,124-Something
#		OUT: 10-31-130
#		
#		if ($connection_status = 'true') then do not make a database
#		connection because one has already been established
#
#  decode_complete_dir (Encoded_dir);
#		
#	send_email ($sendername1, $fromemail1, $toemail1, $mail_subject1, $email_message1);
#
#  (YYYY/MM/DD) = decode_date_numbers(seconds);
#
#  get_extra_vars; Returns an array of extra variables to use.
#
########################################################


1;