Rev 1 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
<?php
/*
Copyright 2006
Daily Data, Inc.
All rights reserved
Name: $Id: contact_us_lib.php,v 1.7 2006/11/30 03:58:26 rodolico Exp $
Description:
Set of library script for contact_us.php
$Date: 2006/11/30 03:58:26 $
$Revision: 1.7 $
Revision History:
$Log: contact_us_lib.php,v $
Revision 1.7 2006/11/30 03:58:26 rodolico
Beginning work on connection to payment center. Still needs a little work
*/
define (VERSION, '1.1');
function verifyForm( $fields ) {
$fieldCount = 0;
$valid = true;
foreach ( $fields as $field => $value ) { // scan each field for required
$fieldCount += strlen($_POST[$value['varname']]); // ensure at least one field has a value
if ($value['required'] === true && strlen( $_POST[$value['varname']] ) == 0 ) {
$valid = false;
} // if
} // foreach
return ($fieldCount > 0 && $valid);
}
function sendMessage( $categories, $fields ) {
$values = getCategoryInfo(escapeshellcmd($_POST['category']), $categories, $fields );
$subject = $values[0] or DEFAULT_SUBJECT;
$to_email = $values[1] or DEFAULT_EMAIL;
$message = str_repeat('-', 40) . "\n";
foreach ($fields as $field => $value ) { // look through the outer array, determining sort order
$message .= $value['title'] . ' -- ';
if ( $value['type'] == 'textarea' ) { $message .= "\n";}
$message .= $_POST[$value['varname']] . "\n" . str_repeat("-", 40) . "\n";
}
$from = escapeshellcmd($_POST['email']) or DEFAULT_FROM;
//$message = "To: $to_email\nFrom: $from\nSubject: $subject\n" . $message;
//print "<pre>$message</pre>\n";
return mail ( $to_email, $subject, $message, "From: $from" );
}
function makeSafeSQLValue ( $value, $type='S' ) {
if(get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
$value = mysql_real_escape_string( $value );
if (($type == 'S') and strlen($value) > 0) { // put quotes around strings
$value = "'" . $value . "'";
} elseif (strlen($value) == 0) { // and substitue null for empty values otherwise;
$value = 'null';
}
return $value;
}
function storeMessage ( $categories, $fields ) {
mysql_connect("localhost", DB_USERNAME, DB_PASSWORD) or die(mysql_error());
mysql_select_db(DATABASE) or die(mysql_error());
$fieldnames = array();
$formValues = array();
foreach ($fields as $field => $value ) { // look through the outer array, determining sort order
$fieldnames[] = $value['varname'];
$formValues[] .= makeSafeSQLValue($_POST[$value['varname']]);
}
$sql = 'insert into ' . DB_TABLE . ' (' . implode(',', $fieldnames) . ') values (' . implode(',', $formValues) . ')';
mysql_query($sql) or die ('MYSQL ERROR #'.mysql_errno().' : <small>' . mysql_error(). "</small><br><VAR>$sql</VAR>");
} // function storeMessage
function makeForm ($form, $maxDisplayWidth ) {
$result = '';
foreach ($form as $field => $value ) { // look through the outer array, determining sort order
$result .= '<tr><td>' . $value['title'];
if ($value['required'] == 1) {
$result .= ' *';
}
$result .= '</td><td>';
if ( $value['type'] == 'textarea' ) {
$result .= "<textarea name='" . $value['varname'] . "' ";
$result .= "cols='" . ( $value['columns'] ? $value['columns'] : $maxDisplayWidth ) . "' ";
$result .= "rows='" . ( $value['rows'] ? $value['rows'] : 10 ) . "' ";
$result .= "class='" . ( $value['class'] ? $value['class'] : 'text-area' ) . "'";
$result .= '>' . $_POST[$value['varname']] . '</textarea>';
} else {
$result .= "<input type='text' name='";
$result .= $value['varname'] . "' ";
if ($value['max length']) {
$result .= "maxlength='" . $value['max length'] . "' ";
$result .= "size='" . ($value['size'] ? $value['size'] : min($value['max length'], $maxDisplayWidth) ) . "' ";
} else {
$result .= "size='" . ($value['size'] ? $value['size'] : $maxDisplayWidth ) . "' ";
}
$result .= "class='" . ( $value['class'] ? $value['class'] : 'text-field' ) . "'";
$result .= "value='". $_POST[$value['varname']] . "'>";
} // else
$result .= "</td></tr>\n";
} // foreach
return $result;
} // makeForm
function getCategoryInfo( $categoryCode, $categories ) {
return array(
strlen($categories[$categoryCode]['subject']) ? $categories[$categoryCode]['subject'] : $categories[$categoryCode]['title'],
$categories[$categoryCode]['email']
);
} // getCategoryInfo
function getAvailableCategoryList( $categories ) {
$returnValue = '';
foreach ($categories as $field => $value ) { // look through the outer array, determining sort order
$returnValue .= "<option value=$field>" . $value['title'] . '</option>' . "\n";
}
return $returnValue;
}
?>
Generated by GNU Enscript 1.6.5.90.