Added initial revision of survey tool.

git-svn-id: svn://10.0.0.236/trunk@187805 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mike.morgan%oregonstate.edu 2006-01-19 02:07:16 +00:00
parent 0156b2d303
commit d1ecf17f31
9 changed files with 264 additions and 0 deletions

View File

View File

View File

@ -0,0 +1,56 @@
<?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');
/**
* Set runtime options.
*/
/**
* 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();
?>

View File

@ -0,0 +1,110 @@
<?php
/**
* PEAR::DB wrappers for SQL queries.
* @package amo
* @subpackage lib
* @author Monte Ohrt <monte [AT] ohrt [DOT] com>
*/
// Define query types.
define('SQL_NONE', 1);
define('SQL_ALL', 2);
define('SQL_INIT', 3);
// Define the query formats.
define('SQL_ASSOC', 1);
define('SQL_INDEX', 2);
class SQL {
var $db = null;
var $result = null;
var $error = null;
var $record = null;
/**
* Class constructor.
*/
function SQL() { }
/**
* Connect to the database.
*
* @param string $dsn the data source name
* @return bool
*/
function connect($dsn) {
$this->db =& DB::connect($dsn);
if(PEAR::isError($this->db)) {
$this->error =& $this->db->getMessage();
return false;
}
return true;
}
/**
* Disconnect from the database.
*/
function disconnect() {
$this->db->disconnect();
}
/**
* Query the database.
*
* @param string $query the SQL query
* @param string $type the type of query
* @param string $format the query format
*/
function query($query, $type = SQL_NONE, $format = SQL_INDEX) {
$this->record = array();
$_data = array();
// Determine fetch mode (index or associative).
$_fetchmode = ($format == SQL_ASSOC) ? DB_FETCHMODE_ASSOC : null;
$this->result = $this->db->query($query);
if (DB::isError($this->result)) {
$this->error = $this->result->getMessage();
return false;
}
switch ($type) {
case SQL_ALL:
// Get all the records.
while($_row = $this->result->fetchRow($_fetchmode)) {
$_data[] = $_row;
}
$this->result->free();
$this->record = $_data;
break;
case SQL_INIT:
// Get the first record.
$this->record = $this->result->fetchRow($_fetchmode);
break;
case SQL_NONE:
default:
// Records will be looped over with next().
break;
}
return true;
}
/**
* Select next row in result.
* @param string $format the query format
*/
function next($format = SQL_INDEX) {
// Fetch mode (index or associative).
$_fetchmode = ($format == SQL_ASSOC) ? DB_FETCHMODE_ASSOC : null;
if ($this->record = $this->result->fetchRow($_fetchmode)) {
return true;
} else {
$this->result->free();
return false;
}
}
}
?>

View File

@ -0,0 +1,57 @@
<?php
/**
* Survey master class. This class contains global application logic.
* @package amo
* @subpackage lib
*/
class Survey
{
var $db;
/**
* AMO_Object constructor.
*/
function Survey() {
global $db;
$this->db =& $db;
}
/**
* Get possible intentions.
* @return arrayory names.
*/
function getIntends()
{
// Return array.
$retval = array();
// Gather intend list.
$this->db->query("SELECT * FROM intend ORDER BY pos, description", SQL_INIT, SQL_ASSOC);
do {
$retval[$this->db->record['id']] = $this->db->record['description'];
} while ($this->db->next(SQL_ASSOC));
return $retval;
}
/**
* Get possible issues.
* @return array
*/
function getIssues()
{
// Return array.
$retval = array();
// Gather platforms..
$this->db->query("SELECT * FROM issue ORDER BY pos, description", SQL_INIT, SQL_ASSOC);
do {
$retval[$this->db->record['id']] = $this->db->record['description'];
} while ($this->db->next(SQL_ASSOC));
return $retval;
}
}
?>

View File

@ -0,0 +1,4 @@
# Auto-prepend our init.php script.
# 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

View File

@ -0,0 +1,37 @@
<?php
/**
* Uninstall survey.
* @package survey
* @subpackage docs
*/
$intends = $app->getIntends();
$issues = $app->getIssues();
if (empty($_POST['submit'])) {
echo '<form action="./" method="post">';
// Create intend block.
echo '<h2>How did you intend to use Firefox when you installed it?</h2>';
echo '<ul>';
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 '</ul>';
// Create issue block.
echo '<h2>What issues, if any, did you have? (select all that apply)</h2>';
echo '<ul>';
foreach ($issues as $id=>$text) {
echo '<li><input type="checkbox" name="issue_id[]" id="iss'.$id.'" value="'.$id.'" /> <label for="iss'.$id.'">'.$text.'</label></li>';
}
echo '</ul>';
echo '<h2>Other comments or suggestions?</h2>';
echo '<textarea name="comments"></textarea>';
echo '<div><input name="submit" type="submit" class="submit" value="Submit"/></div>';
echo '</form>';
}
?>