Added multi-app support per requests made in bug 331632. Also separated out forms so we can localize things in the future. :)

This commit is contained in:
mike.morgan%oregonstate.edu 2006-04-18 18:51:59 +00:00
Родитель 45f4cf0085
Коммит e15441f2d0
5 изменённых файлов: 45 добавлений и 107 удалений

Просмотреть файл

@ -1,52 +0,0 @@
<?php
/**
* Init script.
*
* @package survey
* @subpackage inc
*/
/**
* Require config and required libraries.
*/
require_once('config.php');
require_once(ROOT_PATH.'/lib/sql.class.php');
require_once(ROOT_PATH.'/lib/survey.class.php');
/**
* Configure database.
*/
class Survey_SQL extends SQL {
function Survey_SQL() {
require_once("DB.php");
$dsn = array (
'phptype' => 'mysql',
'dbsyntax' => 'mysql',
'username' => DB_USER,
'password' => DB_PASS,
'hostspec' => DB_HOST,
'database' => DB_NAME,
'port' => DB_PORT
);
$this->connect($dsn);
// Test connection; display "gone fishing" on failure.
if (DB::isError($this->db)) {
die('Unable to connect to database. Try again in a few minutes.');
}
}
}
/**
* Set global variables.
*/
$db = new Survey_SQL();
$app = new Survey();
/**
* Set up arrays to hold cleaned inputs.
*/
$clean = array();
$html = array();
$sql = array();
?>

Просмотреть файл

@ -18,40 +18,55 @@ class Survey
/**
* Get possible intentions.
* @return arrayory names.
* @param int $id
* @return array of names.
*/
function getIntends()
function getIntends($id)
{
// Return array.
$retval = array();
// Gather intend list.
$this->db->query("SELECT * FROM intend ORDER BY pos DESC, description", SQL_INIT, SQL_ASSOC);
$this->db->query("SELECT * FROM intend WHERE app_id={$id} ORDER BY pos DESC, description", SQL_INIT, SQL_ASSOC);
do {
$retval[$this->db->record['id']] = $this->db->record['description'];
} while ($this->db->next(SQL_ASSOC));
if (!empty($this->db->record)) {
do {
$retval[$this->db->record['id']] = $this->db->record['description'];
} while ($this->db->next(SQL_ASSOC));
}
return $retval;
}
/**
* Get possible issues.
* @param int $id
* @return array
*/
function getIssues()
function getIssues($id)
{
// Return array.
$retval = array();
$this->db->query("SELECT * FROM issue WHERE app_id={$id} ORDER BY pos DESC, description", SQL_INIT, SQL_ASSOC);
// Gather platforms..
$this->db->query("SELECT * FROM issue ORDER BY pos DESC, description", SQL_INIT, SQL_ASSOC);
do {
$retval[$this->db->record['id']] = $this->db->record['description'];
} while ($this->db->next(SQL_ASSOC));
if (!empty($this->db->record)) {
do {
$retval[$this->db->record['id']] = $this->db->record['description'];
} while ($this->db->next(SQL_ASSOC));
}
return $retval;
}
/**
* Get an app_id and the template name based on app_name.
* The app_name is passed from the client in the GET string.
*
* @return array|false
*/
function getAppIdByName($name) {
$this->db->query("SELECT id FROM app WHERE app_name='{$name}' LIMIT 1", SQL_ALL, SQL_ASSOC);
if (!empty($this->db->record)) {
return $this->db->record[0]['id'];
} else {
return false;
}
}
}
?>

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -4,22 +4,17 @@
* @package survey
* @subpackage docs
*/
$intends = $app->getIntends();
$issues = $app->getIssues();
$sql['product'] = !empty($_POST['product'])?mysql_real_escape_string($_POST['product']):(!empty($_GET['product'])?mysql_real_escape_string($_GET['product']):null);
$sql['product_id'] = $app->getAppIdByName($sql['product']);
$intends = $app->getIntends($sql['product_id']);
$issues = $app->getIssues($sql['product_id']);
/**
* 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;
@ -60,35 +55,15 @@ exit;
* If we haven't submitted, show the form by default.
*/
} else {
require_once(HEADER);
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" id="surveyform">';
switch ($sql['product']) {
case 'Mozilla Thunderbird':
require_once('../tpl/thunderbird.php');
break;
// Create intend block.
echo '<h2>How did you intend to use Firefox when you installed it?</h2>';
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><label for="int0"><input type="radio" name="intend_id" id="int0" value="0"/> Other, please specify:</label> <input type="text" name="intend_text" id="intother" /></li>';
echo '</ul>';
// Create issue block.
echo '<h2>Why did you uninstall Firefox? (select all that apply)</h2>';
echo '<ul class="survey">';
foreach ($issues as $id=>$text) {
echo '<li><label for="iss'.$id.'"> <input type="checkbox" name="issue_id[]" id="iss'.$id.'" value="'.$id.'" />'.$text.'</label></li>';
}
echo '</ul>';
echo '<h2>How can we improve Firefox?</h2>';
echo '<p>Please share your ideas, suggestions or details about any issues below.</p>';
echo '<div><textarea name="comments" rows="7" cols="60"></textarea></div>';
echo '<input type="hidden" name="product" value="'.htmlentities(!empty($_GET['product'])?$_GET['product']:null).'"/>';
echo '<input type="hidden" name="useragent" value="'.htmlentities(!empty($_GET['useragent'])?$_GET['useragent']:null).'"/>';
echo '<div><input name="submit" type="submit" class="submit" value="Submit &raquo;"/></div>';
echo '</form>';
require_once(FOOTER);
case 'Mozilla Firefox':
default:
require_once('../tpl/firefox.php');
break;
}
}
?>