Added SQL inserts to process user entries and store them in the db.

Made some modifications to store product, useragent and the server ua string.


git-svn-id: svn://10.0.0.236/trunk@191287 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mike.morgan%oregonstate.edu 2006-02-26 23:58:00 +00:00
parent 943d619c60
commit 4e3d7152a3
3 changed files with 69 additions and 6 deletions

View File

@ -4,6 +4,10 @@
padding: .5em 0;
}
.survey li {
margin: 3px 0 0 0;
}
h2 {
margin: .5em 0;
}

View File

@ -2,3 +2,8 @@
# This allows us to have our web documents anywhere we want
# and keep our includes, etc. in a safe directory.
php_value auto_prepend /YOURPATH/inc/init.php
# Set up rewrites so we can get our app data in.
RewriteEngine On
RewriteBase /survey/web/root
RewriteRule ^(.+)/(.+)/(.+)/exit.html index.php?version=$1&product=$2&useragent=$3

View File

@ -7,16 +7,68 @@
$intends = $app->getIntends();
$issues = $app->getIssues();
if (!empty($_POST['submit'])) {
// Do the inserts and stuff.
// Redirect to thank you page.
/**
* If the user has submitted, process and complete the transaction.
*/
if (!empty($_POST['submit'])) {
// Clean inputs. Yes, I know, it should probably be done in the DBI.
// We're not going to be validation nazis here, since the form is optional.
$sql = array();
// The easy stuff.
$sql['product'] = !empty($_POST['product'])?mysql_real_escape_string($_POST['product']):null;
$sql['useragent'] = !empty($_POST['useragent'])?mysql_real_escape_string($_POST['useragent']):null;
$sql['http_user_agent'] = mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']);
$sql['intend_id'] = !empty($_POST['intend_id'])?mysql_real_escape_string($_POST['intend_id']):null;
$sql['intend_text'] = !empty($_POST['intend_text'])?mysql_real_escape_string($_POST['intend_text']):null;
$sql['comments'] = !empty($_POST['comments'])?mysql_real_escape_string($_POST['comments']):null;
// For each issue, we need to log the other text.
$sql['issue_id'] = array();
if (!empty($_POST['issue_id']) && is_array($_POST['issue_id'])) {
foreach ($_POST['issue_id'] as $issue_id) {
$sql['issue_id'][mysql_real_escape_string($issue_id)] = !empty($_POST[$issue_id.'_text'])?mysql_real_escape_string($_POST[$issue_id.'_text']):'';
}
}
// Insert the stuff.
$query = "";
// Result record.
$query .= "
INSERT INTO
result(intend_id, intend_text, product, useragent, http_user_agent, comments, date_submitted)
VALUES(
'{$sql['intend_id']}', '{$sql['intend_text']}', '{$sql['product']}', '{$sql['useragent']}', '{$sql['http_user_agent']}', '{$sql['comments']}', NOW()
);\n
";
if (!empty($sql['issue_id']) && count($sql['issue_id']) > 0) {
foreach ($sql['issue_id'] as $id => $text) {
$query .= "
INSERT INTO issue_result_map() VALUES(LAST_INSERT_ID(), '{$id}', '{$text}');\n
";
}
}
// Do the query.
$db->query($query);
// Redirect to thank you page, and we're done.
header('Location: http://'.$_SERVER['HTTP_HOST'].WEB_PATH.'/thanks.php');
exit;
/**
* If we haven't submitted, show the form by default.
*/
} else {
require_once(HEADER);
echo '<form action="./" method="post" id="surveyform">';
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" id="surveyform">';
// Create intend block.
echo '<h2>How did you intend to use Firefox when you installed it?</h2>';
@ -24,7 +76,7 @@ echo '<ul class="survey">';
foreach ($intends as $id=>$text) {
echo '<li><input type="radio" name="intend_id" id="int'.$id.'" value="'.$id.'" /> <label for="int'.$id.'">'.$text.'</label></li>';
}
echo '<li><input type="radio" name="intend_id" id="int0" value="0" /> <label for="intother" onclick="getElementById(\'int0\').checked=true;">Other, please specify: </label> <input type="text" name="other" id="intother" /></li>';
echo '<li><input type="radio" name="intend_id" id="int0" value="0" /> <label for="intother" onclick="getElementById(\'int0\').checked=true;">Other, please specify: </label> <input type="text" name="intend_text" id="intother" /></li>';
echo '</ul>';
// Create issue block.
@ -36,8 +88,10 @@ foreach ($issues as $id=>$text) {
echo '</ul>';
echo '<h2>Other comments or suggestions?</h2>';
echo '<div><textarea name="comments" rows="11" cols="80"></textarea></div>';
echo '<div><textarea name="comments" rows="7" cols="60"></textarea></div>';
echo '<input type="hidden" name="product" value="'.htmlentities($_GET['product']).'"/>';
echo '<input type="hidden" name="useragent" value="'.htmlentities($_GET['useragent']).'"/>';
echo '<div><input name="submit" type="submit" class="submit" value="Submit &raquo;"/></div>';
echo '</form>';