Browse Source

Modularity started

Stephen Downward 1 year 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

@ -0,0 +1,50 @@
1
<?php
2
require_once("survey_func.php");
3
4
5
survey_start("Stephen's survey", "this is my survey");
6
7
$radio = array(
8
	"Linux" => "lin",
9
	"Windows" => "win",
10
	"Mac OS" => "mac"
11
	);
12
13
gen_recurring("Operating System", "What OS do you use?", "choice_os", "radio", $radio);
14
15
$chkbox = array(
16
	"CS" => "cs",
17
	"Art" => "art",
18
	"Business" => "business"
19
	);
20
21
gen_recurring("Major", "What are you majoring in?", "major", "checkbox", $chkbox);
22
23
gen_num_input("Age", "How old are you?", "age", "years");
24
25
26
$rankings = array(
27
	"Strongly agree",
28
	"Agree",
29
	"Neutral",
30
	"Disagree",
31
	"Strongly Disagree"
32
	);
33
34
$ranking_questions = array(
35
	"foss" => "I believe in FOSS ideology",
36
	"rms" => "Richard Stallman is the one true god"
37
	);
38
39
gen_ranking("Ranking", "Please rank the following from strongly agree to strongly disagree", $rankings, $ranking_questions);
40
41
$countries = array(
42
	"Canada",
43
	"United States",
44
	"Germany"
45
	);
46
47
gen_dropdown("Country", "What country do you live in?", "country", $countries);
48
49
survey_end();
50
?>

+ 0 - 5
index.php

@ -1,5 +0,0 @@
1
<?php
2
3
4
	
5
?>

+ 86 - 0
survey_func.php

@ -0,0 +1,86 @@
1
<?php
2
3
ini_set('display_errors', 1);
4
ini_set('display_startup_errors', 1);
5
error_reporting(E_ALL);
6
7
function survey_start($title, $subtext)
8
{
9
	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>";
10
	//Ready for <div templates>
11
}
12
13
function survey_end()
14
{
15
	echo "</div></body></html>";
16
}
17
18
function gen_recurring($title, $subtext, $name, $type, $options)
19
{
20
	echo "<hr><div class=\"template\">";
21
	echo "<h2>$title</h2>";
22
	echo "<p>$subtext</p>";
23
	foreach ($options as $option => $value)
24
	{
25
		echo "<div><label>$option</label><input type=\"$type\" name=\"$name\" value=\"$value\"/></div>";
26
	}
27
	echo "</div>";
28
}
29
30
function gen_num_input($title, $subtext, $name, $unit) //TODO: Min/max values
31
{
32
	echo "<hr><div class=\"template\">";
33
	echo "<h2>$title</h2>";
34
	echo "<p>$subtext</p>";
35
	echo "<input type=\"number\" class=\"number other\" /> $unit";
36
	echo "</div>";
37
}
38
39
function gen_ranking($title, $subtext, $rankings, $options) //Rankings go along the top, options go along the side
40
{
41
	echo "<hr><div class=\"template\">";
42
	echo "<h2>$title</h2>";
43
	echo "<p>$subtext</p>";
44
	echo "<table>";
45
46
47
	//Generate top bar
48
	echo "<tr><th></th>";
49
	foreach($rankings as $ranking)
50
	{
51
		echo "<th>$ranking</th>";
52
	}
53
	echo "</tr>";
54
55
	//Generate options
56
	foreach($options as $op_name => $op_val)
57
	{
58
		echo "<tr>";
59
		echo "<td>$op_val</td>";
60
		foreach($rankings as $ranking)
61
		{
62
			echo "<td><input class=\"except\" type=\"radio\" name=\"$op_name\" value=\"$ranking\" /></td>";
63
		}
64
		echo "</tr>";
65
	}
66
67
	echo "</table></div>";
68
	
69
}
70
71
function gen_dropdown($title, $subtext, $name, $options)
72
{
73
	echo "<hr><div class=\"template\">";
74
	echo "<h2>$title</h2>";
75
	echo "<p>$subtext</p>";
76
	echo "<select name=\"$name\">";
77
	
78
	foreach($options as $option)
79
	{
80
		echo "<option>$option</option>";
81
	}
82
83
	echo "</select></div>";
84
}
85
	
86
?>

+ 1 - 1
template.html

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