<?php
// Main logic old
// preset variables
$nothere = 1;
// Main Logic
top_of_page(); // Show the top of the HTML page
// If form is submitted, validate and process it, or redisplay
// If not submitted, display form
if ($_POST['_submit_check']) {
// If validaed_form() returns errors, pass them to show_errors()
if($form_errors = validate_form()) {
show_form($form_errors);
} else {
// submitted data is valid so processes it
process_form();
}
} else {
// The form wasn't submitted so do it
show_form();
}
// end main logic
function show_form($errors = '') {
if ($_POST['_submit_check']) {
$defaults = $_POST;
} else {
// otherwise set our defaults
$defaults = array('sender_name' => '',
'email' => '',
'subject_line' => '',
'wordcount' => '0',
'msgs' => '',
'trigspam' => '1');
}
// if errors were passed, put them in $error_text (with HTML mark up)
if ($errors) {
$error_text = '<span class="d1"><tr><td colspan="2" align="center"><b style="color:red" font-size="130%">You need to correct the following errors:</b<br />';
$error_text .= '<ul><li>';
$error_text .= implode('</li><li>', $errors);
$error_text .= '</li></lu></td></tr></span>';
} else {
// No errors? Then error_text is blank
$error_text = '';
}
// jump out of PHP mode to make displaying all the HTML tags easer
?>
<form name="msgform" method="post" action="<?php print $_SERVER['PHP_SELF']; ?>">
<!-- Show body of form -->
<table align="center" border="0" cellpadding="0" cellspacing="0">
<?php print $error_text ?>
<!-- Senders Name -->
<tr>
<td align="left" valign="top">
<p class="c14"><font color="red">*</font> Your Name:
<?php input_text('sender_name', $defaults, 50, 50, 1) ?>
</td>
<br /><br />
<!-- Get senders email address -->
<tr>
<td align="left" valign="top">
<p class="c14"><font color="red">*</font> Your Email address:
<?php input_text('email', $defaults, 50, 50, 1) ?>
</td>
<br /><br />
<!-- Subject -->
<tr>
<td align="left" valign="top">
<p class="c14"><font color="red">*</font> Subject:
<?php input_text('subject_line', $defaults, 50, 50, 1) ?>
</td>
<br /><br />
<tr> <td>
<!-- Show word count for Text box -->
<font color="red">*</font> Message in plain text: (UP TO 100 words max):
<font size="1" color="red"><strong>Total words:</strong></font>
<?php input_text('wordcount', $defaults, 5, 5) ?><br />
<!-- Show Text box -->
<?php input_textarea('msgs', $defaults, 70, 5, 2) ?> <br />
<!-- make hidden varable for submitted form -->
<input type="hidden" name="_submit_check" value="1" /> <br />
<!-- Show word count for spam trigger -->
<?php input_htext('trigspam', $defaults) ?>
</p>
</tr> </td>
</tr>
</table>
<!-- Show Action buttons -->
<table align="center" width="50%" style="background-color: transparent" border="4" frame="box" rules="none" cellspacing="28" cellpadding="0">
<tr>
<td align="left" valign="top"><input type="submit" style="border-color: 1; border-width: 3; background-color: white; color: green; font-weight: bold; font-size: 140%; font-decoration: underline; text-align: center" value="Send Message" tabindex="3" /></td>
<td align="center" valign="top"><input type="reset" style="border-color: 1; border-width: 3; background-color: white; color: blue; font-weight: bold; font-size: 140%; font-decoration: underline; text-align: center" value="Reset" tabindex="4" /></td>
<td align="right" valign="top"><a href="../index.html" style="border-color: 1; border-width: 3; background-color: white; color: red; font-weight: bold; font-size: 140%; font-decoration: underline; text-align: center" tabindex="5">Cancel</a></td>
</tr>
</table>
</form>
<br /><br /><br /><br /><br /><br />
</center>
<!-- End Show body of form -->
<?php
}
// Print a text box (tab has default arguement)
function input_text($element_name, $values, $size, $maxl, $tab = '') {
print "<input type=\"text\" name=\"$element_name\" size=\"$size\" maxlength=\"$maxl\" tabindex=\"$tab\" value=\"";
print htmlentities($values[$element_name]) . '" />';
}
function input_textarea($element_name, $values, $cols, $rows, $tabit) {
print "<textarea name=\"$element_name\" cols=\"$cols\" rows=\"$rows\" tabindex=\"$tabit\" onkeyup=\"countit(event)\" >";
print htmlentities($values[$element_name]) . '</textarea>';
}
function input_select($element_name,$selected,$options) {
// Print <select> tag
print '<select name="' . $element_name .'" . size="7" >';
// set up list of things to be selected
$selected_options[ $selected[$element_name] ] = true;
// Print <option> tag
foreach ($options as $option => $lable) {
print '<option value="' . htmlentities($option) . '"' ;
if ($selected_options[$option]) {
print ' selected="selected"';
}
print '>' . htmlentities($option) . '</option>';
}
print '</select>';
}
// Print a hidden text box
/*function input_htext($element_name, $values) {
global $defaults;
$varir = $values[$element_name];
print "<input type=\"hidden\" name=\"$element_name\" value=\"$varir\" />";
// print htmlentities($values[$element_name]) . '" />';
} */
function input_htext($element_name, $values) {
global $defaults;
$varir = $values[$element_name];
print "<input type=\"hidden\" name=\"$element_name\" value=\"$varir\" />";
// print htmlentities($values[$element_name]) . '" />';
}
function validate_form() {
$errors = array();
// senders email address required
if(check_var('email', 5)) {
$errors[] = 'Missing Email address.';
}
if(! posision_char()) {
$errors[] = 'Invalid message address.';
}
$email = $_POST['email'];
if(! preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $_POST['email'])) {
$errors[] = 'Invalid Email address.';
}
// senders name required
if(check_var('sender_name', 3)) {
$errors[] = 'Missing Senders Name.';
}
// subject required
if(check_var('subject_line', 2)) {
$errors[] = 'Missing Subject.';
}
// Clean up the messge
// If no message
// print $_POST['msg'];
if(strlen($_POST['msgs'] ) < 1) {
$errors[] = 'No Message to send.';
}
rem_htt($_POST['msgs']);
// if a spam use function and pass subject and userid
spam_ck_ip();
if(($_POST['trigspam']) || ($_POST['subj'] == 'Bad')) {
$errors[] = 'Invalid message. Message not sent.';
}
return $errors;
}
function process_form() {
// Set up information and send the email to the approprate party
global $person_contact;
// senders IP
$userip = $_SERVER['REMOTE_ADDR'];
// MEssage headder information
$sender = $_POST['sender_name'];
$email = $_POST['email'];
$submec = $_POST['subject_line'];
// the message
$message = "Comments: \n";
$message .= $_POST['msgs'];
$message = strip_tags($message);
$message .= "\n\n Sent by $sender $email at IP: $userip";
// test parameters
// print "HERE ";
// print "subject_line $subjctline"; //
// print $submec;
// print "Mesg: $message"; // good
// print "Sender: $email"; // good
// http://php.net/manual/en/ref.mail.php
if( mail("nramcsgv@nramcsgv.org","$submec","$message","From:$email\r\nReply-to:$email")) {
print "<br /><br /><center><b>Your message has been sent, return to main menu</b></center><br /><br />";
print "<a href=\"../index.html\" style=\"border-color: 1; border-width: 3; background-color: white; color: green; font-weight: bold; font-size: 140%; font-decoration: underline; text-align: center\" >Click to Return to Main page</a>";
}
else {
print "<br /><br /><center><b>An error was encountered in processing your message</b></center><br /><br />";
}
}
// Check for spam
function spam_ck_ip() {
// ck sender IP for banned sender
$ipadd = $_SERVER['REMOTE_ADDR'];
// get first two ip number of sender
$fstdot = strpos($ipadd,'.');
$firstip = substr($ipadd, 0, $fstdot);
$secdot = strpos($ipadd, '.', $fstdot + 1);
$secip = substr($ipadd, $fstdot + 1, ($secdot - 2));
// First two numbers of spammers range
if($firstip == 60 || $firstip == 163 || $firstip == 67 || $secip == 188 ||
$firstip == 193 || $secip == 189) {
if($secip == 190 || $secip == 191 || $secip == 24 || $secip == 207 || $secip == 143) {
$_POST['msgs'] = '';
$_POST['email'] = '';
$errors[] = 'Unknown error.';
}
}
return $errors;
}
// Validate string for email
function posision_char() {
$chrstr = $_POST['email'];
$pops1 = strpos($chrstr, '@',1);
$pops2 = strpos($chrstr, '.', $pops1);
if ($pops1 <= 2) {
return false; }
if ($pops2 <= 2) {
return false; }
else {
return true; }
}
// Clean up variables
function check_var($varname, $length) {
$clean_var = trim(strip_tags($_POST[$varname]));
if (strlen($clean_var) > $length) {
// no errors
$_POST[$varname] = $clean_var;
return false;
} else {
// bad input
$_POST[$varname] = $clean_var;
return true;
}
}
// Remove html, gif substrigs and charcters
function rem_htt($messg) {
$messg = trim($messg);
$key_string = array("http", "gif","<",">","/","=","&","script","//");
$messgs = str_replace($key_string, "*Bad words*", $messg);
$_POST['msgs'] = $messgs;
}
function top_of_page() {
// Show top of page
print <<<MAIN_HEADING
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?xml-stylesheet type="text/css" href="../stylesheet.css"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>SGV MC Send Message</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Send Aproprate Messages" />
<meta name="robots" content="noindex,nofollow" />
<meta name="keywords" content="NRA, Members Council,SGVMC" />
<link rel="stylesheet" type="text/css" href="../stylesheet1.css" />
<script type="text/javascript"> <!--
function countit()
{
var count=0
var len=0
var formcontent=document.msgform.msgs.value // grab the text from the textarea
formcontent=formcontent.split(" ") // split the words into an array
for(i=0;i<formcontent.length;i++)
{
if(formcontent[i]=="") // Count the number of spaces or nulls
{
count++
}
}
len=formcontent.length-count // subtract spaces or nulls from the length
document.msgform.wordcount.value=len
if (len > 100) {
alert("No more than 100 words allowed!")
return false
}
}
-->
</script>
</head>
<body oncontextmenu="return false">
<!-- Page Headiing -->
<table align="center" border="6" cellspacing="2" cellpadding="7" bgcolor="#ffffff" summary="MC Contact">
<tr align="center" valign="middle">
<td align="center" valign="middle">
<b>
<a href="http://www.nramcsgv.org/index.html">SGVMC Home</a> |
<a href="http://www.nramcsgv.org/meetings.html">Meetings</a> |
<a href="http://www.nramcsgv.org/legislation.html">Legislation</a> |
<a href="http://www.nramcsgv.org/membership.html">Membership</a> |
<a href="#">Contact</a> |
<a href="http://www.nramcsgv.org/links.html">Links</a>
</b>
</td>
</tr>
</table>
<br />
<table frame="void" border="0" cellspacing="3" cellpadding="3" align="center" summary="none">
<tr>
<!-- Page Title in box if used -->
<td valign="top">
<h2 class="c2"><b class="c4">Contact Information</b></h2>
</td>
</tr>
</table>
<br />
<!-- end of top_of_page -->
<table width="75%" border="0" align="center" cellpadding="8" cellspacing="2">
<tr>
<td>
<p><font face="Times New Roman,Georgia,Times" size="+1">This website is an outreach by the NRA Members Council of San Gabriel Valley in it ’s efforts to enhance the knowledge and rescorces help to serve the needs of California firearms owners and enthusiasts. We do this through metings and email updates on improtant issues for firearms owners. We would like for you to join us in the fight to keep your rights. Sign up for our email list below.
<br /><br />
We can be reached through snail mail at: P.O. Box 90531, Pasadena, CA 91109-0531
</font>
</p>
<hr size="5" width="90%" noshade="noshade" align="center" />
<span style='font-size:10.0pt;font-family:Verdana'>
<p><b>
Visitors:<br /> Interested in learning more about the group? complete the contact form:
<br />
<p class="g11"><font color="red">"*"</font> = Required field</p>
MAIN_HEADING;
// end of top_of_page
}
?>