Current location: Hot Scripts Forums » Programming Languages » Perl » Classified Ads

Classified Ads

 
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 12-27-03, 12:34 AM
skipper23 skipper23 is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Classified Ads

Hello all,
I need to change this code to fit my site but any
changes i have made dont show up when the page is
viewed. The site I'm working on is for domaine sales,
this script is for Classified Ads. So where it reads
"type of Ad" it should be "Asking Price" without the
drop down menu. Also where it says "Subject" it
should be "Domain Name". If anyone can give me
a hand with this I would appricate it. You can see
the site here... http://www.ipirates.com
Kind Regards
Dave


Code:
#!/usr/bin/perl


##########################################################################
#
#	TITLE: index.cgi
#	
#	FUNCTION: web-based interface portion of My Classifieds
#	
#	DATE: last edited 11-11-2003
#	
#	AUTHOR: Erin Spice
#	
#	PACKAGE: My Classifieds
#
#	DETAILS: This script allows users to register a username and 
#	password, log in, place ads, edit or delete existing ads, 
#	browse existing ads, and search existing ads.
#
##########################################################################

##########################################################################
#
#	Function Table of Contents: (line numbers are approximate)
#
#	printpage		210
#	frontpage		249
#	place			368
#	deletead		565
#	dodelete		730
#	edit			773
#	login			920
#	confirmdelete		1033
#	newregister		1130
#	newlogin		1209
#	firststuff		1285
#	dologout		1356
#	savead 			1383
#	updatead		1531
#	viewsinglead		1673
#	viewcategory		1815
#	editad			1934
#	logout			2129
#	searchpage		2175
#	searchresults		2257
#	redirect		2473
#
##########################################################################


# THINGS TO MAKE THE PROGRAM WORK ########################################
use lib "./lib";
use strict;
use CGI;
use Digest::MD5 qw(md5_hex);
use common;
use sitevariables;
use functions;
use lang;


package default;




# PREPARATIONS ###########################################################
our $cur = CGI->new;
our $mode = $cur->param('mode');
our $viewcategory = $cur->param('viewcategory');
$viewcategory =~ s/_/ /ig;
our $adindex = $cur->param('adindex');
our $emailcookie = $cur->cookie('email');
our $passcookie = $cur->cookie('pass');

our $randlimit = 1000000000000;
srand(time);

our $content;




# log in/out stuff must be done before the page is printed ###############
if ($mode eq "newlogin" or $mode eq $lang::register){
	firststuff();
}elsif($mode eq "logout"){
	dologout();
}
if ($svb::runautodelete eq "yes" && $svb::autodelete != 0){
	`./autodelete.pl`;
}




### MAIN PROGRAM #########################################################
print "Content-type:text/html\n\n";




## if they just came to index.cgi print the front page ###################
if (!$mode){
	$content .= frontpage();




# if the mode needs a password check #####################################
}elsif($mode eq "place" or 
	$mode eq "edit" or 
	$mode eq "deletead" or 
	$mode eq $lang::submit_ad or 
	$mode eq $lang::update_ad or 
	$mode eq "confirm"){




# do password check and send them on to the right page if its correct ####
	if (fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		if ($mode eq "place"){
			$content .= place();
		}elsif($mode eq "edit" && $adindex){
			$content .= editad();
		}elsif($mode eq $lang::update_ad){
			$content .= updatead();
		}elsif($mode eq "edit"){
			$content .= edit();
		}elsif($mode eq "deletead" && $adindex){
			$content .= confirmdelete();
		}elsif($mode eq "deletead"){
			$content .= deletead();
		}elsif($mode eq $lang::submit_ad){
			$content .= savead();
		}elsif($mode eq "confirm"){
			$content .= dodelete();
			$content .= deletead();
		}




# if its wrong, go back to login page ####################################
	}else{
		$content .= login();
	}




# for pages that dont require password checks, send them straight there ##
}elsif($mode eq "login"){
	$content .= login();
}elsif($mode eq "view" && $adindex){
	$content .= viewsinglead();
}elsif($mode eq "view" && $viewcategory){
	$content .= viewcategory();
}elsif($mode eq "view"){
	$content .= frontpage();
}elsif($mode eq $lang::register){
	$content .= redirect("registerpage");
}elsif($mode eq "registerpage"){
	$content .= newregister();
}elsif($mode eq "newlogin"){
	$content .= redirect("loginpage");
}elsif($mode eq "loginpage"){
	$content .= newlogin();
}elsif($mode eq "search"){
	$content .= searchpage();
}elsif($mode eq $lang::search){
	$content .= searchresults();
}elsif($mode eq "email"){
	$content .= email();
}elsif($mode eq "logout"){
	$content .= logout();
}else{
	$content .= frontpage();
}





# make the page and print it out #########################################
print printpage($content);






### PRINTPAGE ############################################################
#
#	TITLE: printpage
#
#	INPUT: $content - data from other functions.
#	
#	FUNCTION: Adds $cmn::fuzzymonkey to the data received from the
#	script and inserts that data into the template.
#	
#	OUTPUT: HTML for the entire page, printed out to the browser.
#	
#	FUNCTIONS CALLED: 	cmn::dienice
#
#	CALLED BY: 		index.cgi
#
##########################################################################
sub printpage {
	my $content = $_[0];
	$content .= $cmn::fuzzymonkey; 
	my $page;
	open (TEMPLATE, "./$svb::templatefile")
			|| cmn::dienice("$lang::read_file_error ./$svb::templatefile\: $!");
	while (<TEMPLATE>){
		$page .= $_;
	}
	$page =~ s/<!-- ?content ?-->/$content/ig;
	close TEMPLATE;
	return $page;
}







### FRONTPAGE ############################################################
#
#	TITLE: frontpage
#
#	INPUT: none
#	
#	FUNCTION: Checks for cookies and prints a user message if there
#	is one, prints the entry page to browsing ads, along with a
#	menu on the left with links for other pages.
#	
#	OUTPUT: HTML for the entire page, printed out to the browser.
#	
#	FUNCTIONS CALLED: 	fcn::checkcookie
#				cmn::leftmenu
#				fcn::get_ad_count_scalar
#
#	CALLED BY:		index.cgi
#
##########################################################################
sub frontpage {
	my $urlcat;
	my $filename;
	my $count;
	my $count2;
	my $category;
	my $return;
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";
			





# print the personalization ##############################################
	if(fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}
	$return .= "						<tr>
								<td align=center colspan=2>
$svb::fontheader <b>$lang::view_classifieds</b><br>
								</td>
							</tr>
				<tr>
					<td valign=top>";
	$return .= cmn::leftmenu();
	
	
	$return .= "
					</td>
					<td valign=top>
						<table bgcolor=$svb::darkcolor width=100% valign=top align=right cellpadding=0 cellspacing=0 border=0><tr><td>
						<table width=100%>

							<tr>
								<td bgcolor=$svb::headercellcolor>
$svb::fontsmall <b>$lang::browse_classifieds\:</b><br>
								</td>
							</tr>
							<tr>
								<td bgcolor=$svb::lightcolor>
$svb::fontsmall <blockquote>$lang::click_text<br>\n";	
	$count = 0;
	




# print out a link for each category for browsing ########################
	foreach $category(@svb::categories){
		$filename = $category;
		$filename =~ s/[_ \s\/\.!#\$\&\\\[\]\(\),-=\+]//ig;
		unless (-e "./data/$filename.dat"){
			open (OUTFILE,">>./data/$filename.dat")
					||cmn::dienice("$lang::write_file_error $./data/$filename.dat: $!!");
			close OUTFILE;
		}
		$count2 = fcn::get_ad_count_scalar($filename);
		$urlcat = $category;
		$urlcat =~ s/ /_/ig;
		$return .= "<a href=index.cgi?mode=view&viewcategory=$urlcat>$svb::categories[$count]</a> ($count2)<br>\n";
		$count++;
	}
	
	$return .= "</blockquote></font>
								</td>
							</tr>
						</table>
						</td></tr></table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>";
	return $return;
}








### PLACE ################################################################
#
#	TITLE: place
#
#	INPUT: none
#	
#	FUNCTION: Checks for cookies and prints a user message if there
#	is one, prints the entry page to browsing ads, along with a
#	menu on the left with links for other pages.
#	
#	OUTPUT: HTML for the entire page, printed out to the browser.
#	
#	FUNCTIONS CALLED: 		fcn::checkcookie
#					cmn::dienice
#					cmn::leftmenu
#	
#	CALLED BY: 			index.cgi
#
##########################################################################
sub place{
	my $return;
	my $category;
	my $count;
	



# check cookie - they aren't allowed to post if they aren't logged in ####
	my $checkcookie = fcn::checkcookie($emailcookie,$passcookie);
	unless($checkcookie eq "yes"){
		cmn::dienice("$lang::invalid_email_and_password");
	}
	



# find out what needs to be printed out in the form and add the personalization and left menu to $return.
	$count = 4;
	if($svb::allowpicurl eq "yes"){
		$count++;
	}
	if($svb::allowpicupload eq "yes"){
		$count++;
	}
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";




# print the personalization ##############################################
	if($checkcookie eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}
	$return .= "
				<tr>
					<td colspan=4>
$svb::fontheader <center>$lang::place_an_ad</center></font>
					</td>
				</tr>
				<tr>
					<td valign=top>\n";
	$return .= cmn::leftmenu();





# put the form together and add it to $return ############################
	$return .= "
					</td>
					<td>
&nbsp;
					</td>
					<td colspan=2>
						<table>
							<tr>
								<td>
<form method=post action=index.cgi enctype='multipart/form-data'>
$svb::fontsmall*&nbsp;$lang::category\:&nbsp;&nbsp;
								</td>
								<td>
<select name=itemcategory><option disabled selected>- $lang::please_choose_a_category -</option>
<option disabled>----------------------------</option>";
	foreach $category(@svb::categories){
		$return .= "<option value='$category'>$category</option>\n";
	}
	$return .= "</select>
								</td>
							</tr>
							<tr>
								<td width=100>
$svb::fontsmall* $lang::type_of_ad\:&nbsp;&nbsp;
								</td>
								<td>
<select name=adtype>
<option disabled selected>- $lang::please_choose_a_type -</option>
<option disabled>------------------------<option>
<option>$lang::for_sale</option>
<option>$lang::want_to_buy</option>
<option>$lang::for_rent</option>
<option>$lang::want_to_rent</option>
<option>$lang::for_free</option>
<option>$lang::want_for_free</option></select>
								</td>
							</tr>
							<tr>
								<td width=100>
$svb::fontsmall* $lang::subject\:&nbsp;&nbsp;
								</td>
								<td>
<input type=text name=subject value='5-50 $lang::characters'>
								</td>
							</tr>\n";
	if($svb::allowpicurl eq "yes"){
		$return .= "
							<tr> 

								<td width=100>
$svb::fontsmall $lang::picture_url\:&nbsp;&nbsp;
								</td>
								<td>
<input type=text name=picurl size=40>
								</td>
							</tr>\n";
	}
	$return .= "
							<tr> 

								<td width=100>
$svb::fontsmall $lang::website_url\:&nbsp;&nbsp;
								</td>
								<td>
<input type=text name=weburl size=40>
								</td>
							</tr>\n";

	if($svb::allowpicupload eq "yes"){
		$return .= "
							<tr>
								<td width=100>
$svb::fontsmall $lang::upload_a_picture\:&nbsp;&nbsp;
								</td>
								<td>
<input type=file name=picture>
								</td>
							</tr>\n";
	}
	$return .= "
							<tr>
								<td width=100 valign=top>
$svb::fontsmall*&nbsp;$lang::description\:&nbsp;&nbsp;
								</td>
								<td>
<textarea name=descrip rows=8 cols=40>$lang::descrip_text</textarea>
								</td>
							</tr>
							<tr>
								<td>
<input type=submit name=mode value='$lang::submit_ad'>
								<td>
<font face=$svb::fontface size=1 color=$svb::darkcolor>* - $lang::required_fields.</font>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>\n";
	return $return;
}









### DELETEAD #############################################################
#
#	TITLE: deletead
#
#	INPUT: none
#	
#	FUNCTION: Lists all the current users ads for them to choose 
#	which one to delete.
#	
#	OUTPUT: HTML for the page, and sends the adindex of that ad
#	to confirmdelete.
#	
#	FUNCTIONS CALLED: 		fcn::get_own_dates_array
#					fcn::get_own_data_array
#					cmn::leftmenu
#					fcn::checkcookie
#
#	CALLED BY: 			index.cgi
#
##########################################################################
sub deletead{
	my ($return,$urlcat,$filename,$count,@temp,$pre,$count2,$date,$line,
	@dates,$category,%alldata,$email,$itemcategory,$subject,$adtype,
	$picurl,$adindex,$descrip,$weburl,$datenum,$prettydate);
	
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";








# print the personalization ##############################################
	if(fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}
	$return .= "
				<tr>
					<td colspan=4>
$svb::fontheader <center>$lang::delete_your_ads</center></font>
					</td>
				</tr>
				<tr>
					<td valign=top>\n";
	$return .= cmn::leftmenu();
	$return .= "
					</td>
					<td width=75% valign=top>
						<table bgcolor=$svb::darkcolor width=100% align=right cellpadding=0 cellspacing=0 border=0><tr><td>
						<table width=100%>";







# print out every ad belonging to the logged in user #####################
	foreach $category(@svb::categories){
		$count = 0;
		$urlcat = $category;
		$urlcat =~ s/ /_/ig;
		$filename = $category;
		$filename =~ s/[_ \s\/\.!#\$\&\\\[\]\(\),-=\+]//ig;
		($count,@dates) = fcn::get_own_dates_array($filename);
		@temp = fcn::get_own_data_array($filename);
		foreach $pre(@temp){
			chomp $pre;
			($email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$weburl,$datenum) = split(/###/,$pre);
			$alldata{$datenum} = $pre;
		}
		undef @temp;
		if ($count){
			$return .= "
							<tr>
								<td colspan=3 bgcolor=$svb::headercellcolor>
$svb::fontsmall<b>$category</b> ";
			$return .= "</font>
								</td>
							</tr>";
		}
		$count2 = $count2 + $count;
		$count = 0;
		@dates = sort(@dates);
		@dates = reverse(@dates);
		foreach $date (@dates){
			my $prettydate = cmn::mydate($date);
			($email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$weburl,$datenum) = split(/###/,$alldata{$date});
			if ($email){
				$return .= "
							<tr bgcolor=$svb::cellcolors[$count]>
								<td>
$svb::fontsmall $adtype</font>
								</td>
								<td>
$svb::fontsmall <a href='index.cgi?mode=deletead&viewcategory=$urlcat&adindex=$adindex'>$subject</a></font>
								</td>
								<td>
$svb::fontsmall $prettydate</font>
								</td>
							</tr>";
			}
			$count++;
			if ($count == 2){
				$count = 0;
			}
		}
		undef %alldata;
		undef @dates;
	}
	if (!$count2){
		$return .= "
							<tr>
								<td colspan=3 bgcolor=$svb::headercellcolor>
$svb::fontsmall<b>$lang::no_ads</b></font>
								</td>
							</tr>";

	}
	$return .= "
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
		</td>
	</tr>
</table>
		</td>
	</tr>
</table>";
	return $return;

}











### DODELETE #############################################################
#
#	TITLE: dodelete
#
#	INPUT: $adindex, $viewcategory
#	
#	FUNCTION: deletes the chosen ad and prints out the page of that
#	users ads to choose another to delete.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		fcn::dodelete
#					fcn::get_all_data_array
#					fcn::get_own_data_array
#					fcn::get_own_dates_array
#					cmn::leftmenu
#					fcn::checkcookie
#					cmn::mydate
#
#	CALLED BY: 			index.cgi
#
##########################################################################
sub dodelete{
	my $curadindex = $cur->param('adindex');
	my $filename = $cur->param('viewcategory');
	my ($return,$line,$count,$count2,$urlcat,$category,$prettydate,$date,$pre,@temp,
		@dates,%alldata,$email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$datenum);
	$curadindex =~ s/[\D]+//ig;
	$filename =~ s/[_ \s\/\.!#\$\&\\\[\]\(\),-=\+]//ig;
	my @data = fcn::get_all_data_array($filename);
	fcn::func_dodelete($filename,$curadindex,@data);
	undef @data;
}
	











### EDIT #################################################################
#
#	TITLE: edit
#
#	INPUT: none
#	
#	FUNCTION: Lists all the current users ads for them to choose 
#	which one to edit.
#	
#	OUTPUT: HTML for the page, and sends the adindex of that ad
#	to editad.
#	
#	FUNCTIONS CALLED: 		fcn::get_own_dates_array
#					fcn::get_own_data_array
#					cmn::leftmenu
#					fcn::checkcookie
#
#	CALLED BY: 			index.cgi
#
##########################################################################
sub edit{
	my ($email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$weburl,$datenum,$return,
		$count,$filename,$urlcat,@dates,%alldata,$line,$date,$category,$pre,@temp,$prettydate);
	
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";









# print the personalization ##############################################
	if(fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}
	$return .= "
				<tr>
					<td colspan=4>
$svb::fontheader <center>$lang::edit_your_ads</center></font>
					</td>
				</tr>
				<tr>
					<td valign=top>\n";
	$return .= cmn::leftmenu();
	$return .= "
					</td>
					<td width=75% valign=top>
						<table bgcolor=$svb::darkcolor width=100% align=right cellpadding=0 cellspacing=0 border=0><tr><td>
						<table width=100%>";









# print out all the ads of the logged in user ############################
	foreach $category(@svb::categories){
		$count = 0;
		$urlcat = $category;
		$urlcat =~ s/ /_/ig;
		$filename = $category;
		$filename =~ s/[_ \s\/\.!#\$\&\\\[\]\(\),-=\+]//ig;
		($count,@dates) = fcn::get_own_dates_array($filename);
		@temp = fcn::get_own_data_array($filename);
		foreach $pre(@temp){
			chomp $pre;
			($email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$weburl,$datenum) = split(/###/,$pre);
			$alldata{$datenum} = $pre;
		}
		if ($count != 0){
		$return .= "
							<tr>
								<td colspan=3 bgcolor=$svb::headercellcolor>
$svb::fontsmall<b>$category</b></font>
								</td>
							</tr>";
		}
		$count = 0;
		@dates = sort(@dates);
		@dates = reverse(@dates);
		foreach $date (@dates){
			$prettydate = cmn::mydate($date);
			($email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$weburl,$datenum) = split(/###/,$alldata{$date});
			if ($email){
				$return .= "
							<tr bgcolor=$svb::cellcolors[$count]>
								<td>
$svb::fontsmall $adtype</font>
								</td>
								<td>
$svb::fontsmall <a href='index.cgi?mode=edit&viewcategory=$urlcat&adindex=$adindex'>$subject</a></font>
								</td>
								<td>
$svb::fontsmall $prettydate</font>
								</td>
							</tr>";
			}
			$count++;
			if ($count == 2){
				$count = 0;
			}
		}
		undef %alldata;
		undef @dates;
	}
	$return .= "
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
		</td>
	</tr>
</table>
		</td>
	</tr>
</table>";
	return $return;
}










### LOGIN ################################################################
#
#	TITLE: login
#
#	INPUT: none
#	
#	FUNCTION: Prints out a login/register form.
#	
#	OUTPUT: HTML for the page, and sends the login info to 
#	firststuff.
#	
#	FUNCTIONS CALLED: 		none
#
#	CALLED BY: 			index.cgi
#
##########################################################################
sub login{
	my $return;
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>
				<tr>
					<td valign=top colspan=3>
<center>$svb::fontheader <b>$lang::please_log_in</b></center>
					</td>
				</tr>
				<tr>
					<td align=right>
						<table>
							<tr>
								<td colspan=2>
<center>$svb::fontsmall <b>$lang::log_in</b></font></center>
								</td>
							</tr>
							<tr>
								<td>
<form method=post action=index.cgi>
$svb::fontsmall $lang::email\:<br>
$lang::password\:
								</td>
								<td>
<input type=text name=email><br><input type=password name=pass>
								</td>
							</tr>
							<tr>
								<td>
&nbsp;
								</td>
								<td>
<input type=submit value='$lang::log_in'><input type=hidden name=mode value=newlogin>
</form>
								</td>
							</tr>
						</table>
					</td>
					<td width=100>
		&nbsp;
					</td>
					<td>
						<table>
							<tr>
								<td colspan=2>
<center>$svb::fontsmall <b>$lang::register</b></font></center>
								</td>
							</tr>
							<tr>
								<td>
<form method=post action=index.cgi>$svb::fontsmall $lang::email\:<br>
$lang::password\:
								</td>
								<td>
<input type=text name=email><br><input type=password name=pass>
								</td>
							</tr>
							<tr>
								<td>
&nbsp;
								</td>
								<td>
<input type=submit value='$lang::register'><input type=hidden name=mode value=$lang::register>
<input type=hidden name=count value=one>
</form>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>";
	
	return $return;
}













### CONFIRMDELETE ########################################################
#
#	TITLE: edit
#
#	INPUT: none
#	
#	FUNCTION: Builds a page confirming that the user wishes to
#	delete the selected ad.
#	
#	OUTPUT: HTML for the page, and sends the adindex of that ad
#	to dodelete.
#	
#	FUNCTIONS CALLED: 		fcn::get_one_ad_array
#					cmn::leftmenu
#					cmn::dienice
#					fcn::checkcookie
#
#	CALLED BY: 			index.cgi
#
##########################################################################
sub confirmdelete {
	my $return;
	my $line;
	my ($email,$itemcategory,$subject,$adtype,$picurl,$curadindex,$descrip,$datenum);
	my @stuff;
	
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";











# print the personalization ##############################################
	if(fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}

	my $urlcat = $cur->param('viewcategory');
	my $curadindex = $cur->param('adindex');
	my $filename = $urlcat;
	$urlcat =~ s/ /_/ig;
	$filename =~ s/[_ \s\/\.!#\$\&\\\[\]\(\),-=\+]//ig;
	@stuff = fcn::get_one_ad_array($filename,$curadindex);
	unless ($emailcookie eq $stuff[0]){
		cmn::dienice("$lang::ownership_error");
	}
	
	$return .= "
				<tr>
					<td colspan=2>
<center>$svb::fontheader <b>$lang::confirm_delete</b></center>
					</td>
				</tr>
				<tr>
					<td valign=top>";
	$return .= cmn::leftmenu();
	$return .= "</td>
					<td>
$svb::fontsmall $lang::delete_this_ad (\"$stuff[2]\")?<br><br><center>
<a href=index.cgi?mode=confirm&viewcategory=$urlcat&adindex=$adindex>$lang::delete</a><br><a href=index.cgi?mode=deletead>$lang::cancel</a></font>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>";

	return $return;
}











### NEWREGISTER ##########################################################
#
#	TITLE: newregister
#
#	INPUT: none
#	
#	FUNCTION: Prints "thank you for registering" page.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		cmn::leftmenu
#					fcn::checkcookie
#
#	CALLED BY: 			index.cgi
#
##########################################################################
sub newregister{
	my $return;
	
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";







# print the personalization ##############################################
	if(fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}
	$return .= "
				<tr>
					<td colspan=2>
<center>$svb::fontheader <b>$lang::thanks_register</b></center>
					</td>
				</tr>
				<tr>
					<td valign=top>";
	$return .= cmn::leftmenu();
	$return .= "			</td>
					<td>
$svb::fontsmall $lang::thanks_register_text
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>";

	return $return;
}












### NEWLOGIN #############################################################
#
#	TITLE: newlogin
#
#	INPUT: none
#	
#	FUNCTION: Prints out the "thank you for logging in" page.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		cmn::leftmenu
#					fcn::checkcookie
#
#	CALLED BY: 			index.cgi
#
##########################################################################
sub newlogin{
	my $return;
	
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";








# print the personalization ##############################################
	if(fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}
	$return .= "
				<tr>
					<td colspan=2>
<center>$svb::fontheader <b>$lang::welcome_back</b></center>
					</td>
				</tr>
				<tr>
					<td valign=top>";
	$return .= cmn::leftmenu();
	$return .= "
					</td>
					<td>
$svb::fontsmall $lang::welcome_back_text
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>";

	return $return; 
}





### FIRSTSTUFF ###########################################################
#
#	TITLE: firststuff
#
#	INPUT: $email, $pass, $mode
#	
#	FUNCTION: Sets cookies if logging in or registering.
#	
#	OUTPUT: Returns "yes" if login is valid and NULL if invalid.
#	
#	FUNCTIONS CALLED: 		fcn::checkcookie
#					cmn::dienice
#					fcn::compare_email_for_register
#					fcn::add_user
#
#	CALLED BY: 			index.cgi
#
##########################################################################
sub firststuff{
	my $email = $cur->param('email');
	my $pass = $cur->param('pass');
	my $passmd5 = Digest::MD5::md5_hex($pass);
	my ($line,$allow);
	if ($email !~ /^[\w\-\.]+\@[\w\-\.]+\.[\w\-\.]+$/i){
		print "Content-type:text/html\n\n";
		cmn::dienice("$lang::invalid_email");
	}
	if($pass !~ /\w+/i){
		print "Content-type:text/html\n\n";
		cmn::dienice("$lang::invalid_password");
	}

	
	
	
# If we are logging in ###################################################
	if($mode eq "newlogin"){
		$allow = fcn::checkcookie($email,$passmd5);
		if($allow eq "BANNED"){
			print "Content-type:text/html\n\n";
			cmn::dienice($lang::you_have_been_banned);
		}
		if($allow ne "yes"){
			print "Content-type:text/html\n\n";
			cmn::dienice("$lang::invalid_login_combo");
		}
	}



# If we are registering for the first time ###############################
	if ($mode eq $lang::register){
		if ($pass =~ /\W/i or !$pass){
		print "Content-type:text/html\n\n";
				cmn::dienice("$lang::valid_password_check");
		}
		unless($email =~ /[\w\-]+\@[\w\-]+\.[\w\-]+/i){
			print "Content-type:text/html\n\n";
			cmn::dienice("$lang::invalid_email");
		}
		my $already = fcn::compare_email_for_register($email);
		unless ($already eq "yes"){
			fcn::add_user($email,$passmd5);
		}else{
			print "Content-type:text/html\n\n";
			cmn::dienice("$lang::unique_email");
		}
	}
	print "Set-Cookie: email=$email\n";
	print "Set-Cookie: pass=$passmd5\n";
}



### DOLOGOUT #############################################################
#
#	TITLE: dologout
#
#	INPUT: none
#	
#	FUNCTION: Sets blank cookies.
#	
#	OUTPUT: NULL
#	
#	FUNCTIONS CALLED: 		none
#
#	CALLED BY: 			index.cgi
#
##########################################################################
sub dologout{
	print "Set-Cookie: email=\n";
	print "Set-Cookie: pass=\n";
}



### SAVEAD ###############################################################
#
#	TITLE: savead
#
#	INPUT: $itemcategory, $adtype, $subjec, $picurl, $picture, 
#	$descrip, $weburl, $email    
#	
#	FUNCTION: Gets the data input by the user and saves the new
#	ad, and prints a success message.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		fcn::checkcookie
#					cmn::dienice
#					cmn::leftmenu
#					writedata
#
#	CALLED BY: 			index.cgi
#	
##########################################################################
sub savead {
	my ($return,$itemok,$picturename,$category,$count,$buffer,$urlcat);
	my $itemcategory = $cur->param('itemcategory');
	my $adtype = $cur->param('adtype');
	my $subject = $cur->param('subject');
	my $picurl = $cur->param('picurl');
	my $weburl = $cur->param('weburl');
	my $picture = $cur->param('picture');
	my $descrip = $cur->param('descrip');
	my $email = $cur->cookie('email');
	my $adindex = int(rand($randlimit));
	$adindex =~ s/\.\d+$//i;
	if ($picurl && $picurl !~ /http:\/\//i){
		$picurl = "http://$picurl";
	}
	if ($weburl && $weburl !~ /http:\/\//i){
		$weburl = "http://$weburl";
	}

# check everything for hack attempts, illegal characters, and stupidity ##
	$descrip =~ s/<table[\w\d\s\=\-\.\'\"\$\%\#\/\\]+>//ig;
	$descrip =~ s/<td[\w\d\s\=\-\.\'\"\$\%\#\/\\]+>//ig;
	$descrip =~ s/<tr[\w\d\s\=\-\.\'\"\$\%\#\/\\]+>//ig;
	$descrip =~ s/<\/table>//ig;
	$descrip =~ s/<\/td>//ig;
	$descrip =~ s/<\/tr>//ig;
	$descrip =~ s/<img[\w\d\s\=\-\.\'\"\$\%\#\/\\]+>//ig;
	foreach $category(@svb::categories){
		if ($itemcategory eq $category){
			$itemok = "okeydokey";
		}		
	}
	unless ($adtype){
		cmn::dienice("$lang::please_choose_a_type");
	}
	unless ($itemok eq "okeydokey"){
		cmn::dienice("$lang::choose_category");
	}
	unless ($subject =~ /^.{5,50}$/i){
		cmn::dienice("$lang::check_subject");
	}
	if ($subject eq "5-50 $lang::characters"){
		cmn::dienice("$lang::fill_in_subject");
	}
	unless (!$picture){
		unless($picture =~ /\.jpg$/i or 
			$picture =~ /\.png$/i or 
			$picture =~ /\.gif$/i){
			cmn::dienice("$lang::file_type");
		}
	}
	if ($descrip =~ /\S{30,30}/i){
		cmn::dienice("$lang::check_long_words");
	}
	$picturename = $adindex;
# right now we are only checking picture filetypes by extension in order to cut down on the number of dependancies
	if ($picture =~ /\.jpg$/i){
		$picturename .= ".jpg";
	}elsif($picture =~ /\.png/i){
		$picturename .= ".png";
	}elsif($picture =~ /\.gif/i){
		$picturename .= ".gif";
	}

# get the picture from the user's computer and save it to the appropriate directory
	unless (-d "$svb::htmlsystempath/pictures"){
		mkdir "$svb::htmlsystempath/pictures";
	}
	if ($svb::allowpicupload eq "yes"){
		if ($picture){
			open (OUTFILE,">$svb::htmlsystempath/pictures/$picturename")
					||cmn::dienice("$lang::write_file_error $svb::htmlurl/pictures/$picturename\: $!!"); 
			while(my $bytesread = read($picture,$buffer,1024)){
				print OUTFILE $buffer;
				$count++;
				if ($count > $svb::maxpicsize){
					unlink "$svb::htmlsystempath/pictures/$picturename";
					cmn::dienice("$lang::pic_too_big");
				}
			}
			close OUTFILE;
		}
	}

# write the data out to the data files ###################################
	fcn::add_ad($itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$email,$weburl);


# print the successful message ###########################################
	$urlcat = $itemcategory;
	$urlcat =~ s/ /_/ig;

# print the personalization ##############################################
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellspacing=0 cellpadding=2 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellspacing=0 cellpadding=5>
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td valign=top>";
	$return .= cmn::leftmenu(); # make the left menu
	$lang::placed_successfully =~ s/<link1>/<a href='index.cgi?mode=view&viewcategory=$urlcat&adindex=$adindex'>$lang::here<\/a>/;
	$return .= "
					</td>
					<td><br>
$svb::fontsmall $lang::placed_successfully 
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>";
	return $return; # spit out the results
}
  


### UPDATEAD #############################################################
#
#	TITLE: updatead
#
#	INPUT: $itemcategory, $adtype, $subjec, $picurl, $picture, 
#	$descrip, $weburl, $email    
#	
#	FUNCTION: Gets the data input by the user and saves the newly
#	edited ad, and prints a success message.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		fcn::checkcookie
#					cmn::dienice
#					cmn::leftmenu
#					fcn::update_ad
#
#	CALLED BY: 			index.cgi
#
##########################################################################
sub updatead {
	my ($return,$itemok,$buffer,$count,$urlcat,$category,$picturename);
	my $itemcategory = $cur->param('itemcategory');
	my $adtype = $cur->param('adtype');
	my $subject = $cur->param('subject');
	my $picurl = $cur->param('picurl');
	my $weburl = $cur->param('weburl');
	my $picture = $cur->param('picture');
	my $descrip = $cur->param('descrip');
	my $email = $cur->cookie('email');
	my $adindex = $cur->param('adindex');

# check everything for hack attempts, illegal characters and stupidity ###
	foreach $category(@svb::categories){
		if ($itemcategory eq $category){
			$itemok = "okeydokey";
		}		
	}
	if ($picurl && $picurl !~ /http:\/\//i){
		$picurl = "http://$picurl";
	}
	if ($weburl && $weburl !~ /http:\/\//i){
		$weburl = "http://$weburl";
	}
	unless ($adtype){
		cmn::dienice("$lang::please_choose_a_type");
	}
	unless ($itemok eq "okeydokey"){
		cmn::dienice("$lang::choose_category");
	}
	unless ($subject =~ /^.{5,50}$/i){
		cmn::dienice("$lang::check_subject");
	}
	if ($subject eq "5-50 $lang::characters"){
		cmn::dienice("$lang::fill_in_subject");
	}
	if ($subject =~ /.{30,30}/i){
		$subject =~ s/(\S{30,30})/$1 /ig;
	}
	unless (!$picture){
		unless($picture =~ /\.jpg$/i or 
			$picture =~ /\.png$/i or 
			$picture =~ /\.gif$/i){
			cmn::dienice("$lang::file_type");
		}
	}
	if ($descrip =~ /\S{46,46}/i){
		cmn::dienice("$lang::check_long_words");
	}
	$picturename = $adindex;
	
# right now we are only checking picture filetypes by extension in order to cut down on the number of dependancies
	if ($picture =~ /\.jpg$/i){
		$picturename .= ".jpg";
	}elsif($picture =~ /\.png$/i){
		$picturename .= ".png";
	}elsif($picture =~ /\.gif$/i){
		$picturename .= ".gif";
	}

	if ($picture){
		unlink "$svb::htmlsystempath/pictures/$adindex.jpg";
		unlink "$svb::htmlsystempath/pictures/$adindex.gif";
		unlink "$svb::htmlsystempath/pictures/$adindex.png";
	}
# upload a new picture if applicable #####################################
	if ($svb::allowpicupload eq "yes"){
		if ($picture){
			open (OUTFILE,">$svb::htmlsystempath/pictures/$picturename")
					||cmn::dienice("$lang::write_file_error $svb::htmlurl/pictures/$picturename\: $!!");
			while(my $bytesread = read($picture,$buffer,1024)){
				print OUTFILE $buffer;
				$count++;
				if ($count > $svb::maxpicsize){
					cmn::dienice("$lang::pic_too_big");
				}
			}
			close OUTFILE;
		}
	}

# write the data out to the mysql database ###############################
	fcn::update_ad($adindex,$itemcategory,$subject,$adtype,$picurl,$descrip,$weburl);

	$urlcat = $itemcategory; 
	$urlcat =~ s/ /_/ig;

	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td valign=top>";
	$return .= cmn::leftmenu();
	$lang::updated_successfully =~ s/<link1>/<a href='index.cgi?mode=view&viewcategory=$urlcat&adindex=$adindex'>$lang::here<\/a>/;
	$return .= "
					</td>
					<td><br>
$svb::fontsmall $lang::updated_successfully  
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>";
	return $return;
}





### VIEWSINGLEAD #########################################################
#
#	TITLE: viewsinglead
#
#	INPUT: $selectedadindex, $viewcategory   
#	
#	FUNCTION: Prints out a single classified ad selected by the user.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		fcn::checkcookie
#					cmn::leftmenu
#					function::get_one_ad_array
#					cmn::mydate
#
#	CALLED BY: 			index.cgi
#	
##########################################################################
sub viewsinglead{
	
	my ($return,$email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,
	$weburl,$datenum,$urlcat,$line,$filename,$prettydate,@addata,$atag,$aclose);
	my $selectedadindex = $cur->param('adindex');
	my $viewcategory = $cur->param('viewcategory');
	$viewcategory =~ s/_/ /ig;
	$urlcat = $viewcategory;
	$urlcat =~ s/ /_/ig;
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";

# print the personalization ##############################################
	if(fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}
	$return .= "
				<tr>
					<td colspan=4>
$svb::fontheader <center>$lang::view_classifieds</center></font>
					</td>
				</tr>
				<tr>
					<td valign=top>\n";
	$return .= cmn::leftmenu();
	$return .= "
					</td>
					<td width=75% valign=top>
						<table bgcolor=$svb::darkcolor width=100% align=right cellpadding=0 cellspacing=0 border=0><tr><td>
						<table width=100%>";
	$return .= "
							<tr>
								<td colspan=3 bgcolor=$svb::headercellcolor>
$svb::fontsmall<b>$viewcategory</b> - <a href=index.cgi?mode=view&viewcategory=$urlcat>$lang::back</a></font>
								</td>
							</tr>";

# print out the ad formatted very nicely #################################
	$filename = $viewcategory;
	$filename =~ s/[ _\s\/\.!#\$\&\\\[\]\(\),-=\+]//ig;
	@addata = fcn::get_one_ad_array($filename,$selectedadindex);
	$prettydate = cmn::mydate($addata[8]);
	$return .= "
							<tr>
								<td bgcolor=$svb::cellcolors[0]>
								<table width=100%>
								<tr>
								<td>$svb::fontsmall <b>$addata[2]</b> - $prettydate</font>
								</td>
								<td bgcolor=$svb::cellcolors[0]>$svb::fontsmall <a href='email.cgi?viewcategory=$viewcategory&adindex=$addata[5]'>$lang::email_the_seller</a></font>
								</td>
								</tr>";
	$return .= "
								<tr>
								<td>
								$svb::fontsmall $addata[3]:  $addata[6]</font>
								</td>
								</tr>";
	if ($addata[7]){
		$atag = "<a href=$addata[7] target='_new'>";
		$aclose = "</a>";
	}
	if ($svb::allowpicurl =~ /yes/i){
		if ($addata[4]){
			$return .= "<tr><td colspan=2><center>$atag<img src='$addata[4]' border=0>$aclose</center></td></tr>";
			undef $atag;
			undef $aclose;
		}
	}
	if ($svb::allowpicupload =~ /yes/i){
		if (-e "$svb::htmlsystempath/pictures/$addata[5].png"){
			$return .= "<tr><td colspan=2><center>$atag<img src='$svb::htmlurl/pictures/$addata[5].png' border=0>$aclose</center></td></tr>";
			undef $atag;
			undef $aclose;
		}
		if (-e "$svb::htmlsystempath/pictures/$addata[5].jpg"){
			$return .= "<tr><td colspan=2><center>$atag<img src='$svb::htmlurl/pictures/$addata[5].jpg' border=0>$aclose</center></td></tr>";
			undef $atag;
			undef $aclose;
		}
		if (-e "$svb::htmlsystempath/pictures/$addata[5].gif"){
			$return .= "<tr><td colspan=2><center>$atag<img src='$svb::htmlurl/pictures/$addata[5].gif' border=0>$aclose</center></td></tr>";
			undef $atag;
			undef $aclose;
		}
	}
	if ($atag){
		$return .= "<tr><td colspan=2 align=center>$svb::fontsmall$atag$lang::click_for_info$aclose</font></td></tr>";
	}
	$return .= "
								</table>
							</tr>
						</table>
					</td>
				</tr>
			</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>";

	return $return;

}



### VIEWCATEGORY #########################################################
#
#	TITLE: viewcategory
#
#	INPUT: $adindex, $viewcategory 
#	
#	FUNCTION: Lists all the ads in the category.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		fcn::checkcookie
#					cmn::leftmenu
#					fcn::get_all_dates_array
#					fcn::get_all_data_array
#					cmn::mydate
#
#	CALLED BY: 			index.cgi
#	
##########################################################################
sub viewcategory{ 
	
	my ($return,$email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,
		$weburl,$datenum,@dates,%alldata,$count,@temp,$pre,$date);
	my $adindex = $cur->param('adindex');
	my $viewcategory = $cur->param('viewcategory');
	$viewcategory =~ s/_/ /ig;
	my $urlcat = $viewcategory;
	$urlcat =~ s/ /_/ig;
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";

# print the personalization ##############################################
	if(fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}
	$return .= "
				<tr>
					<td colspan=4>
$svb::fontheader <center>$lang::view_classifieds</center></font>
					</td>
				</tr>
				<tr>
					<td valign=top>\n";
	$return .= cmn::leftmenu();
	$return .= "
					</td>
					<td width=75% valign=top>
						<table bgcolor=$svb::darkcolor width=100% align=right cellpadding=0 cellspacing=0 border=0><tr><td>
						<table width=100%>";
	$return .= "
							<tr>
								<td colspan=3 bgcolor=$svb::headercellcolor>
$svb::fontsmall<b>$viewcategory</b>";

# get the data and print out all the ads from the category ###############
	my $filename = $viewcategory;
	$filename =~ s/[ _\s\/\.!#\$\&\\\[\]\(\),-=\+]//ig;
	($count,@dates) = fcn::get_all_dates_array($filename);
	@temp = fcn::get_all_data_array($filename);
	foreach $pre(@temp){
		chomp $pre;
		($email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$weburl,$datenum) = split(/###/,$pre);
		$alldata{$datenum} = $pre;
	}
	undef @temp;
	@dates = sort(@dates);
	@dates = reverse(@dates);
	$count = 0;
	foreach $date(@dates){
		my $prettydate = cmn::mydate($date);
		($email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$weburl,$datenum) = split(/###/,$alldata{$date});
		$return .= "
							<tr bgcolor=$svb::cellcolors[$count]>
								<td>
$svb::fontsmall $adtype</font>
								</td>
								<td>
$svb::fontsmall <a href='index.cgi?mode=view&viewcategory=$urlcat&adindex=$adindex'>$subject</a></font>
								</td>
								<td>
$svb::fontsmall $prettydate</font>
								</td>
							</tr>";	
		$count++;
		if ($count == 2){
			$count = 0; # go back to the first color
		}                 ###
	}
	
	$return .= "
						</td></tr></table>
						</table>
					</td
				</tr>
			</table>
		</td>
	</tr>
</table>";

	return $return;
}



### EDITAD ###############################################################
#
#	TITLE: editad
#
#	INPUT: $adindex, $viewcategory 
#	
#	FUNCTION: Print the form for editing the ad selected by
#	the user.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		fcn::checkcookie
#					cmn::leftmenu
#					fcn::get_one_ad_array
#					cmn::mydate
#					cmn::dienice
#
#	CALLED BY: 			index.cgi
#	
##########################################################################
sub editad{
	my ($return,$count,$category,$line,@stuff,$forsale,$wanttobuy,$forrent,
		$wanttorent,$forfree,$wantforfree,$filename);
	my $viewcategory = $cur->param('viewcategory');
	$viewcategory =~ s/_/ /ig;
	my $adindex = $cur->param('adindex');

# make sure the user is logged in ########################################
	my $checkcookie = fcn::checkcookie($emailcookie,$passcookie);
	unless($checkcookie eq "yes"){
		cmn::dienice("$lang::invalid_login_combo");
	}

# figure out how we need to format the form ##############################
	$count = 4;
	if($svb::allowpicurl eq "yes"){
		$count++;
	}
	if($svb::allowpicupload eq "yes"){
		$count++;
	}
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";

# print the personalization ##############################################
	if(fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}
	$return .= "
				<tr>
					<td colspan=4>
$svb::fontheader <center>$lang::edit_an_ad</center></font>
					</td>
				</tr>
				<tr>
					<td valign=top>\n";
	$return .= cmn::leftmenu();
	$filename = $viewcategory;
	$filename =~ s/[_ \s\/\.!#\$\&\\\[\]\(\),-=\+]//ig;
	@stuff = fcn::get_one_ad_array($filename,$adindex);
	unless ($emailcookie eq $stuff[0]){
		cmn::dienice("$lang::ownership_error");
	}
	$return .= "
					</td>
					<td>
&nbsp;
					</td>
					<td colspan=2>
						<table>
							<tr>
								<td>
<form method=post action=index.cgi enctype='multipart/form-data'>
$svb::fontsmall*&nbsp;$lang::category:&nbsp;&nbsp;
								</td>
								<td>
<select name=itemcategory><option disabled selected>- $lang::please_choose_a_category -</option>
<option disabled>----------------------------</option>";
	foreach $category(@svb::categories){
		if ($category eq $stuff[1]){
			$return .= "<option selected value='$category'>$category</option>\n";
		}else{
			$return .= "<option value='$category'>$category</option>\n";
		}
	}
	if ($stuff[3] =~ $lang::for_sale){
		$forsale = "selected";
	}elsif ($stuff[3] =~ $lang::want_to_buy){
		$wanttobuy = "selected";
	}elsif ($stuff[3] =~ $lang::for_rent){
		$forrent = "selected";
	}elsif ($stuff[3] =~ $lang::want_to_rent){
		$wanttorent = "selected";
	}elsif ($stuff[3] =~ $lang::for_free){
		$forfree = "selected";
	}elsif ($stuff[3] =~ $lang::want_for_free){
		$wantforfree = "selected";
	}
		$return .= "</select>
								</td>
							</tr>
							<tr>
								<td width=100>
$svb::fontsmall* $lang::type_of_ad\:&nbsp;&nbsp;
								</td>
								<td>
<select name=adtype>
<option disabled selected>- $lang::please_choose_a_type -</option>
<option disabled>------------------------<option>
<option $forsale >$lang::for_sale</option>
<option $wanttobuy >$lang::want_to_buy</option>
<option $forrent >$lang::for_rent</option>
<option $wanttorent >$lang::want_to_rent</option>
<option $forfree >$lang::for_free</option>
<option $wantforfree >$lang::want_for_free</option></select>
								</td>
							</tr>
							<tr>
								<td width=100>
$svb::fontsmall* $lang::subject\:&nbsp;&nbsp;
								</td>
								<td>
<input type=text name=subject value='$stuff[2]'>
								</td>
							</tr>\n";
	if($svb::allowpicurl eq "yes"){
		$return .= "
							<tr>
								<td width=100>
$svb::fontsmall $lang::picture_url\:&nbsp;&nbsp;
								</td>
								<td>
<input type=text name=picurl size=40 value='$stuff[4]'>
								</td>
							</tr>\n";
	}
	$return .= "
							<tr>
								<td width=100>
$svb::fontsmall $lang::website_url\:&nbsp;&nbsp;
								</td>
								<td>
<input type=text name=weburl size=40 value='$stuff[7]'>
								</td>
							</tr>\n";

	if($svb::allowpicupload eq "yes"){
		$return .= "
							<tr>
								<td width=100>
$svb::fontsmall $lang::upload_a_picture\:&nbsp;&nbsp;
								</td>
								<td>
<input type=file name=picture>
								</td>
							</tr>\n";
	}
	$return .= "
							<tr>
								<td width=100 valign=top>
$svb::fontsmall*&nbsp;$lang::description\:&nbsp;&nbsp;
								</td>
								<td>
<textarea name=descrip rows=8 cols=40>$stuff[6]</textarea>
								</td>
							</tr>
							<tr>
								<td>
<input type=hidden name=adindex value=$adindex>
								<input type=submit name=mode value='$lang::update_ad'>
								<td>
<font face=$svb::fontface size=1 color=$svb::darkcolor>* - $lang::required_fields.</font>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>\n";
	return $return;
}



### LOGOUT #########################################################
#
#	TITLE: logout
#
#	INPUT: none 
#	
#	FUNCTION: Prints successful message after a logout.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		cmn::leftmenu
#
#	CALLED BY: 			index.cgi
#	
##########################################################################
sub logout{
	my $return;

	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>
				<tr>
					<td valign=top colspan=3>
<center>$svb::fontheader <b>$lang::logout</b></center>
					</td>
				</tr>
				<tr>
									<td valign=top>\n";
	$return .= cmn::leftmenu();
	$return .= "
					</td>
					<td align=center>
					$svb::fontsmall $lang::logout_successful</td>
				</tr>
			</table>
		</td>
	</tr>
</table>";
	
	return $return;
}



### SEARCHPAGE ###########################################################
#
#	TITLE: searchpage
#
#	INPUT: none 
#	
#	FUNCTION: Prints the search form.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		cmn::leftmenu
#
#	CALLED BY: 			index.cgi
#	
##########################################################################
sub searchpage{
	my ($return,$category);

	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>
				<tr>
					<td valign=top colspan=3>
<center>$svb::fontheader <b>$lang::search</b></center>
					</td>
				</tr>
				<tr>
					<td rowspan=4 valign=top>\n";
	$return .= cmn::leftmenu();
	$return .= "
					</td>
					<td align=right valign=bottom>
					<form action=index.cgi method=post>
					$svb::fontsmall $lang::search_this_category\:</font></td>
					<td valign=bottom><select name=viewcategory>
					<option selected>$lang::all_categories
					<option disabled>------------------------";
	foreach $category(@svb::categories){
		$return .= "<option>$category\n";
	}
	$return .= "</select>
					</td>
				</tr>
				<tr height=40>
					<td align=right valign=top>
					$svb::fontsmall $lang::search_for\:</font>
					</td>
					<td valign=top>
					<input type=text name=searchfor>
					</td>
				</tr>
				<tr height=40>
					<td>
					&nbsp;
					</td>
					<td valign=top>
					<input type=submit name=mode value=$lang::search>
					</td>
				</tr>
				<tr>
					<td>
					&nbsp;
					</td>
					<td>
					&nbsp;
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>";
	
	return $return;
}



### SEARCHRESULTS ########################################################
#
#	TITLE: searchresults
#
#	INPUT: $searchfor, $viewcategory 
#	
#	FUNCTION: Lists all the search results.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		fcn::checkcookie
#					cmn::leftmenu
#					fcn::func_search
#					cmn::mydate
#
#	CALLED BY: 			index.cgi
#	
##########################################################################
sub searchresults{
	my ($email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$weburl,$datenum,
		$return,$urlcat,$count4,$category,$entry,$searchthing,$filename,@searcharray,
		$count,$count1,$count2,$count3,$count4,$line,$prettydate,$number);
	my $viewcategory = $cur->param('viewcategory');
	$viewcategory =~ s/_/ /ig;
	my $searchfor = $cur->param('searchfor');
	if($viewcategory =~ /-{10,10}/i){
		cmn::dienice($lang::search_category);
	}
	my @searchthings = split(/ /,$searchfor);
	if(!$searchthings[0]){
		$searchthings[0] = " ";
	}
	
	$return .= "
<table bgcolor=$svb::tableborder width=98% cellpadding=2 cellspacing=0 align=center>
	<tr>
		<td>
			<table bgcolor=$svb::tablebg width=100% cellpadding=5 cellspacing=0>";

# print the personalization ##############################################
	if(fcn::checkcookie($emailcookie,$passcookie) eq "yes"){
		$return .= "
				<tr>
					<td>
						<table>
							<tr>
								<td align=left valign=top height=5>
<font face=$svb::fontface color=$svb::darkcolor size=-1>$lang::logged_in_as\:<br>  $emailcookie
								</td>
							</tr>
						</table>
					</td>
				</tr>";
	}
	$return .= "
				<tr>
					<td colspan=4>
<center>$svb::fontheader $lang::your_search_results</font><br>
$svb::fontsmall <a href=index.cgi?mode=search>$lang::search_again</a></font></center>
					</td>
				</tr>
				<tr>
					<td valign=top>\n";
	$return .= cmn::leftmenu();
	$return .= "
					</td>
					<td width=75% valign=top>
						<table bgcolor=$svb::darkcolor width=100% align=right cellpadding=0 cellspacing=0 border=0><tr><td>
						<table width=100%>";
	if($viewcategory =~ /$lang::all_categories/i){
		$count4 = 0;
		foreach $category(@svb::categories){
			$urlcat = $category;
			$urlcat =~ s/ /_/ig;
			$filename = $category; 
			$filename =~ s/[_ \s\/\.!#\$\&\\\[\]\(\),-=\+]//ig;
			(@searcharray) = fcn::get_all_data_array($filename);
			$number = @searcharray;
			foreach $searchthing(@searchthings){
				$count1 = 0; # total in the array
				$count2 = 0; # index number for the search array
				$count3 = 0; # start over counting the total search results for each category
				while ($count1 <= $number){
					if ($searcharray[$count2] =~ /$searchthing/i){
						$count3++; # count the matches in this category
						$count1++; # count all attempts
						$count2++; # only move to the next entry to search through if we dont delete one - if we delete one, it will shift the array, so no moving is necessary.
					}else{ 
						splice(@searcharray,$count2,1);
						$count1++;
					}
				}
			}
			$count4 = $count4 + $count3;
			if ($count3 != 0){
				$return .= "
							<tr>
								<td colspan=3 bgcolor=$svb::headercellcolor>
$svb::fontsmall<b>$category</b></font>
								</td>
							</tr>";
			}
			$count = 0; # start the count over for colors
			foreach $entry (@searcharray){
				chomp $entry;
				($email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$weburl,$datenum) = split(/###/,$entry);
				$prettydate = cmn::mydate($datenum);
				if ($subject){
					$return .= "
							<tr bgcolor=$svb::cellcolors[$count]>
								<td>
$svb::fontsmall $adtype</font>
								</td>
								<td>
								$svb::fontsmall <a href='index.cgi?mode=view&viewcategory=$urlcat&adindex=$adindex'>$subject</a></font>
								</td>
								<td>
$svb::fontsmall $prettydate</font>
								</td>
							</tr>";
					$count++; # go to the next color
				}
				if ($count == 2){
					$count = 0;
				}
			}
			undef @searcharray;
		}
		if ($count4 == 0){
			$return .= "<tr><td bgcolor=$svb::lightcolor>$svb::fontsmall $lang::no_ads_found</font></td></tr>"
		}
	}else{
		$count4 = 0; # count the total matches overall - not just the current category
		$urlcat = $viewcategory;
		$urlcat =~ s/ /_/ig;
		$filename = $viewcategory;
		$filename =~ s/[_ \s\/\.!#\$\&\\\[\]\(\),-=\+]//ig;
		(@searcharray) = fcn::get_all_data_array($filename);
		$number = @searcharray;
		foreach $searchthing(@searchthings){
			$count1 = 0; # total in the array
			$count2 = 0; # index number for the search array
			$count3 = 0; # start over counting the total search results for each category
			while ($count1 <= $number){
				if ($searcharray[$count2] =~ /$searchthing/i){
					$count3++; # count the matches in this category
					$count1++; # count all attempts
					$count2++;    # only move to the next entry to search through if we dont delete one - if we delete one, it will shift the array, so no moving is necessary.
				}else{
					splice(@searcharray,$count2,1);
					$count1++; # count all attempts
				}
			}
		}
		$count4 = $count4 + $count3;
		if ($count3 != 0){
			$return .= "
							<tr>
								<td colspan=3 bgcolor=$svb::headercellcolor>
$svb::fontsmall<b>$viewcategory</b></font>
								</td>
							</tr>";
		}
		$count = 0; # start the count over for colors
		foreach $entry (@searcharray){
			chomp $entry;
			($email,$itemcategory,$subject,$adtype,$picurl,$adindex,$descrip,$weburl,$datenum) = split(/###/,$entry);
			$prettydate = cmn::mydate($datenum);
			if ($subject){
				$return .= "
						<tr bgcolor=$svb::cellcolors[$count]>
								<td>
$svb::fontsmall $adtype</font>
								</td>
								<td>
$svb::fontsmall <a href='index.cgi?mode=view&viewcategory=$urlcat&adindex=$adindex'>$subject</a></font>
								</td>
								<td>
$svb::fontsmall $prettydate</font>
								</td>
							</tr>";
				$count++; # go to the next color
			}
			if ($count == 2){
				$count = 0;
			}
		}
		undef @searcharray;
		if ($count4 == 0){
			$return .= "<tr><td bgcolor=$svb::lightcolor>$svb::fontsmall $lang::no_ads_found</font></td></tr>"
		}

	}


	$return .= "
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
		</td>
	</tr>
</table>
		</td>
	</tr>
</table>";
	return $return;
}








### REDIRECT #############################################################
#
#	TITLE: redirect
#
#	INPUT: $mode 
#	
#	FUNCTION: Redirects so that cookies can be accessed upon
#	first full page load after login or register.
#	
#	OUTPUT: HTML for the page.
#	
#	FUNCTIONS CALLED: 		none
#
#	CALLED BY: 			index.cgi
#	
##########################################################################
sub redirect{
        my $return .= "                                                                                           
<html>
<head>
<title>$svb::title</title>
<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=index.cgi?mode=$_[0]\">
</head>
<body bgcolor=#FFFFFF>
<center>
$svb::fontsmall$lang::logging_you_in</font>
</center>
</body>
</html>";
	return $return;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Advertising Solution adsjunction General Advertisements 0 10-09-03 01:12 PM
Classified Ads System Coach General HotScripts Site Discussion 6 06-08-03 08:35 AM


All times are GMT -5. The time now is 01:57 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.