#!/usr/bin/perl

use strict;

use lib qw(/var/www/sites/ubuyne/cgi-perl/modules/);

use PW2_Functions;

use PW2_PrintBits;

my $ip=$ENV{'REMOTE_ADDR'}; 
if (	($ip eq '91.232.96.2') ||
	($ip eq '94.242.255.187')||
	($ip eq '94.242.255.202')
){exit;}

&process_main();

exit;

# --------------------------------------------------------------------------------------------------------------------------

sub process_main {

undef my %FORM;

&process_form_any2(\%FORM);

my $comments	=$FORM{'pw2msg'};
my $email	=$FORM{'pw2from'};

if ($comments gt'')
{
&process_message(\$comments,\$email);
}

&print_myheader();

&html_top_of_page();

&print_contactpage(\$comments);

&print_footer(\0);

undef %FORM;

}1;
# --------------------------------------------------------------------------------------------------------------------------

sub process_message{

my $comments	=shift;		# A reference
my $email	=shift;		# 	"

if ($$email eq'')
{
$$email="no_e-mail\@contact.form";	# Otherwise we won't receive anything at all ...
}
else
{
&cleanse_email_fields($email);		# Cleanse
};


$$comments=lc($$comments);		# Lowercase all the comments, and then cleanse
$$comments=~tr/a-zA-Z0-9_\/.\@ / /c;
$$comments=~s/   / _ /g;
$$comments=~s/\@/*/g;
$$comments=~s/\./^/g;

# https://stackoverflow.com/questions/9538542/counting-number-of-occurrences-of-a-string-inside-another-perl/9538604
my @c = $comments =~ /http/g;
my $count = @c;

my @words=('good site','pay day','payday','youtube','phentermine','viagra','viagara','sexy',' sex','girls','drugs',' btc ','bitcoin',' earn ','how to earn','how to make','how to get','how to invest');

for (@words) {
  if (index($$comments,$_)!=-1) {$count=99;last;}
}

my $spacecount = ($$comments=~ tr/ //);
if ($spacecount<6){$count=99};		# Ignore if less than 6 spaces (ie. probably seven words)

# ---

# Only send the message if it has one or less links in it ... because it's most likely a spammer otherwise (probably is anyway). However, it will
# still appear as if the message was sent, because we won't clear out $comments.

if ($count<=1)
{
	if (length($$comments)>15)
	{
	$$comments=join('',$ip,"\n\n--\n",$$comments);

	&send_email_message($email,\'helius@gmail.com',$comments,\'Price-Wizard User Comments',\'Price-Wizard Contact Form');
	}
	else
	{
	$$comments='';
	}
}

}1;
# --------------------------------------------------------------------------------------------------------------------------

sub print_contactpage{

my $comments	=shift;		# A reference

my $html='';

if ($$comments eq'')
{
$html=qq~
<br>
<div class="pad5">
<h2>Contact Us:</h2>
<span class="lh25">
Please use the form below to contact us if you have any questions or comments. However, please note that we are unable to 
intervene on your behalf with any of the merchants listed on our website.
<br><br>
<span class="f_green">If your request requires a response, then please remember to provide your e-mail address or a contact telephone number.</span>
</span>
<br><br>
<div class="just_c flex_container w3-padding-16" id="contactdiv">
	<div class="pad10">
	<div class="just_l"><b>Comments:</b></div>
	<br>
	<form method="post" action="https://price-wizard.com/cgi-perl/pw.contact.cgi">
	<textarea id="contactarea" name="pw2msg"></textarea></td>
	</div>

	<div class="pad10"> 
	<div class="just_l"><b>E-mail:</b></div>
	<br>
	<input type="email" name="pw2from" value="" maxlength="50" class="w3-margin-right">
	<br><br>
	<input type="submit" value="Send Message" class="w3-padding-8">
	</div>
</div>

</form>
<br><br>
<div class="just_c w3-padding-32">
<a href="../links2/intf.html" title="Interflora Flowers &amp; Gifts">
<img src="../images/interflora.730x92.webp" alt="Interflora" width="730" class="responsive_img">
</a>
</div>
~;
}
else
{
$html=qq~
<br>
<div class="just_c w3-padding-32"><h1 class="f_green">Thank you! Your message has been sent.</h1></div>
<br>
<div class="lh25 w75 w3-padding-48 automargin">
If your message requires a reply, and you have provided your contact details, we will try and respond as quickly as possible, but please allow a day or two.
</div>
<br>
<div class="just_c w3-padding-32"><h2>... <a href="http://price-wizard.com/">continue shopping</a></h2></div>
<br>
<div class="just_c w3-padding-32">
<a href="../links2/intf.html" title="Interflora Flowers &amp; Gifts">
<img src="../images/interflora.730x92.jpg" alt="Interflora" width="730" class="responsive_img">
</a>
</div>

</div>
<br><br>
~;
}

print $html;

}1;
# --------------------------------------------------------------------------------------------------------------------------

