Browse Source

Modularity started

master
Stephen Downward 2 years ago
parent
commit
4a519daa40
4 changed files with 137 additions and 6 deletions
  1. +50
    -0
      example.php
  2. +0
    -5
      index.php
  3. +86
    -0
      survey_func.php
  4. +1
    -1
      template.html

+ 50
- 0
example.php View File

@@ -0,0 +1,50 @@
<?php
require_once("survey_func.php");


survey_start("Stephen's survey", "this is my survey");

$radio = array(
"Linux" => "lin",
"Windows" => "win",
"Mac OS" => "mac"
);

gen_recurring("Operating System", "What OS do you use?", "choice_os", "radio", $radio);

$chkbox = array(
"CS" => "cs",
"Art" => "art",
"Business" => "business"
);

gen_recurring("Major", "What are you majoring in?", "major", "checkbox", $chkbox);

gen_num_input("Age", "How old are you?", "age", "years");


$rankings = array(
"Strongly agree",
"Agree",
"Neutral",
"Disagree",
"Strongly Disagree"
);

$ranking_questions = array(
"foss" => "I believe in FOSS ideology",
"rms" => "Richard Stallman is the one true god"
);

gen_ranking("Ranking", "Please rank the following from strongly agree to strongly disagree", $rankings, $ranking_questions);

$countries = array(
"Canada",
"United States",
"Germany"
);

gen_dropdown("Country", "What country do you live in?", "country", $countries);

survey_end();
?>

+ 0
- 5
index.php View File

@@ -1,5 +0,0 @@
<?php


?>

+ 86
- 0
survey_func.php View File

@@ -0,0 +1,86 @@
<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

function survey_start($title, $subtext)
{
echo "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"><title>$title</title></head><body><div id=\"container\"><h1>$title</h1><p>$subtext</p>";
//Ready for <div templates>
}

function survey_end()
{
echo "</div></body></html>";
}

function gen_recurring($title, $subtext, $name, $type, $options)
{
echo "<hr><div class=\"template\">";
echo "<h2>$title</h2>";
echo "<p>$subtext</p>";
foreach ($options as $option => $value)
{
echo "<div><label>$option</label><input type=\"$type\" name=\"$name\" value=\"$value\"/></div>";
}
echo "</div>";
}

function gen_num_input($title, $subtext, $name, $unit) //TODO: Min/max values
{
echo "<hr><div class=\"template\">";
echo "<h2>$title</h2>";
echo "<p>$subtext</p>";
echo "<input type=\"number\" class=\"number other\" /> $unit";
echo "</div>";
}

function gen_ranking($title, $subtext, $rankings, $options) //Rankings go along the top, options go along the side
{
echo "<hr><div class=\"template\">";
echo "<h2>$title</h2>";
echo "<p>$subtext</p>";
echo "<table>";


//Generate top bar
echo "<tr><th></th>";
foreach($rankings as $ranking)
{
echo "<th>$ranking</th>";
}
echo "</tr>";

//Generate options
foreach($options as $op_name => $op_val)
{
echo "<tr>";
echo "<td>$op_val</td>";
foreach($rankings as $ranking)
{
echo "<td><input class=\"except\" type=\"radio\" name=\"$op_name\" value=\"$ranking\" /></td>";
}
echo "</tr>";
}

echo "</table></div>";
}

function gen_dropdown($title, $subtext, $name, $options)
{
echo "<hr><div class=\"template\">";
echo "<h2>$title</h2>";
echo "<p>$subtext</p>";
echo "<select name=\"$name\">";
foreach($options as $option)
{
echo "<option>$option</option>";
}

echo "</select></div>";
}
?>

+ 1
- 1
template.html View File

@@ -1,6 +1,6 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<!--TODO: Divide into 2 columns-->


Loading…
Cancel
Save