1 |
rodolico |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
Copyright 2006
|
|
|
5 |
Daily Data, Inc.
|
|
|
6 |
All rights reserved
|
|
|
7 |
Name: $Id: contact_us_lib.php,v 1.7 2006/11/30 03:58:26 rodolico Exp $
|
|
|
8 |
Description:
|
|
|
9 |
Set of library script for contact_us.php
|
|
|
10 |
|
|
|
11 |
$Date: 2006/11/30 03:58:26 $
|
|
|
12 |
$Revision: 1.7 $
|
|
|
13 |
Revision History:
|
|
|
14 |
$Log: contact_us_lib.php,v $
|
|
|
15 |
Revision 1.7 2006/11/30 03:58:26 rodolico
|
|
|
16 |
Beginning work on connection to payment center. Still needs a little work
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
*/
|
|
|
20 |
|
|
|
21 |
define (VERSION, '1.1');
|
|
|
22 |
|
|
|
23 |
function verifyForm( $fields ) {
|
|
|
24 |
$fieldCount = 0;
|
|
|
25 |
$valid = true;
|
|
|
26 |
foreach ( $fields as $field => $value ) { // scan each field for required
|
|
|
27 |
$fieldCount += strlen($_POST[$value['varname']]); // ensure at least one field has a value
|
|
|
28 |
if ($value['required'] === true && strlen( $_POST[$value['varname']] ) == 0 ) {
|
|
|
29 |
$valid = false;
|
|
|
30 |
} // if
|
|
|
31 |
} // foreach
|
|
|
32 |
return ($fieldCount > 0 && $valid);
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
function sendMessage( $categories, $fields ) {
|
|
|
36 |
$values = getCategoryInfo(escapeshellcmd($_POST['category']), $categories, $fields );
|
|
|
37 |
$subject = $values[0] or DEFAULT_SUBJECT;
|
|
|
38 |
$to_email = $values[1] or DEFAULT_EMAIL;
|
|
|
39 |
$message = str_repeat('-', 40) . "\n";
|
|
|
40 |
foreach ($fields as $field => $value ) { // look through the outer array, determining sort order
|
|
|
41 |
$message .= $value['title'] . ' -- ';
|
|
|
42 |
if ( $value['type'] == 'textarea' ) { $message .= "\n";}
|
|
|
43 |
$message .= $_POST[$value['varname']] . "\n" . str_repeat("-", 40) . "\n";
|
|
|
44 |
}
|
|
|
45 |
$from = escapeshellcmd($_POST['email']) or DEFAULT_FROM;
|
|
|
46 |
//$message = "To: $to_email\nFrom: $from\nSubject: $subject\n" . $message;
|
|
|
47 |
//print "<pre>$message</pre>\n";
|
|
|
48 |
return mail ( $to_email, $subject, $message, "From: $from" );
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
function makeSafeSQLValue ( $value, $type='S' ) {
|
|
|
52 |
if(get_magic_quotes_gpc()) {
|
|
|
53 |
$value = stripslashes($value);
|
|
|
54 |
}
|
|
|
55 |
$value = mysql_real_escape_string( $value );
|
|
|
56 |
if (($type == 'S') and strlen($value) > 0) { // put quotes around strings
|
|
|
57 |
$value = "'" . $value . "'";
|
|
|
58 |
} elseif (strlen($value) == 0) { // and substitue null for empty values otherwise;
|
|
|
59 |
$value = 'null';
|
|
|
60 |
}
|
|
|
61 |
return $value;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
function storeMessage ( $categories, $fields ) {
|
|
|
66 |
mysql_connect("localhost", DB_USERNAME, DB_PASSWORD) or die(mysql_error());
|
|
|
67 |
mysql_select_db(DATABASE) or die(mysql_error());
|
|
|
68 |
$fieldnames = array();
|
|
|
69 |
$formValues = array();
|
|
|
70 |
foreach ($fields as $field => $value ) { // look through the outer array, determining sort order
|
|
|
71 |
$fieldnames[] = $value['varname'];
|
|
|
72 |
$formValues[] .= makeSafeSQLValue($_POST[$value['varname']]);
|
|
|
73 |
}
|
|
|
74 |
$sql = 'insert into ' . DB_TABLE . ' (' . implode(',', $fieldnames) . ') values (' . implode(',', $formValues) . ')';
|
|
|
75 |
mysql_query($sql) or die ('MYSQL ERROR #'.mysql_errno().' : <small>' . mysql_error(). "</small><br><VAR>$sql</VAR>");
|
|
|
76 |
} // function storeMessage
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
function makeForm ($form, $maxDisplayWidth ) {
|
|
|
80 |
$result = '';
|
|
|
81 |
foreach ($form as $field => $value ) { // look through the outer array, determining sort order
|
|
|
82 |
$result .= '<tr><td>' . $value['title'];
|
|
|
83 |
if ($value['required'] == 1) {
|
|
|
84 |
$result .= ' *';
|
|
|
85 |
}
|
|
|
86 |
$result .= '</td><td>';
|
|
|
87 |
if ( $value['type'] == 'textarea' ) {
|
|
|
88 |
$result .= "<textarea name='" . $value['varname'] . "' ";
|
|
|
89 |
$result .= "cols='" . ( $value['columns'] ? $value['columns'] : $maxDisplayWidth ) . "' ";
|
|
|
90 |
$result .= "rows='" . ( $value['rows'] ? $value['rows'] : 10 ) . "' ";
|
|
|
91 |
$result .= "class='" . ( $value['class'] ? $value['class'] : 'text-area' ) . "'";
|
|
|
92 |
$result .= '>' . $_POST[$value['varname']] . '</textarea>';
|
|
|
93 |
} else {
|
|
|
94 |
$result .= "<input type='text' name='";
|
|
|
95 |
$result .= $value['varname'] . "' ";
|
|
|
96 |
if ($value['max length']) {
|
|
|
97 |
$result .= "maxlength='" . $value['max length'] . "' ";
|
|
|
98 |
$result .= "size='" . ($value['size'] ? $value['size'] : min($value['max length'], $maxDisplayWidth) ) . "' ";
|
|
|
99 |
} else {
|
|
|
100 |
$result .= "size='" . ($value['size'] ? $value['size'] : $maxDisplayWidth ) . "' ";
|
|
|
101 |
}
|
|
|
102 |
$result .= "class='" . ( $value['class'] ? $value['class'] : 'text-field' ) . "'";
|
|
|
103 |
$result .= "value='". $_POST[$value['varname']] . "'>";
|
|
|
104 |
} // else
|
|
|
105 |
$result .= "</td></tr>\n";
|
|
|
106 |
} // foreach
|
|
|
107 |
return $result;
|
|
|
108 |
} // makeForm
|
|
|
109 |
|
|
|
110 |
function getCategoryInfo( $categoryCode, $categories ) {
|
|
|
111 |
return array(
|
|
|
112 |
strlen($categories[$categoryCode]['subject']) ? $categories[$categoryCode]['subject'] : $categories[$categoryCode]['title'],
|
|
|
113 |
$categories[$categoryCode]['email']
|
|
|
114 |
);
|
|
|
115 |
} // getCategoryInfo
|
|
|
116 |
|
|
|
117 |
function getAvailableCategoryList( $categories ) {
|
|
|
118 |
$returnValue = '';
|
|
|
119 |
foreach ($categories as $field => $value ) { // look through the outer array, determining sort order
|
|
|
120 |
$returnValue .= "<option value=$field>" . $value['title'] . '</option>' . "\n";
|
|
|
121 |
}
|
|
|
122 |
return $returnValue;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
?>
|