-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperHTMLDef.php
More file actions
executable file
·231 lines (191 loc) · 5.32 KB
/
SuperHTMLDef.php
File metadata and controls
executable file
·231 lines (191 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?
// SuperHTML Class Def
// Andy Harris
// PHP / MySQL Programming for the Absolute Beginner
// 2nd Ed.
class SuperHTML{
//properties
var $title;
var $thePage;
function __construct($tTitle = "Super HTML"){
//constructor
$this->setTitle($tTitle);
} // end constructor
function getTitle(){
return $this->title;
} // end getTitle
function setTitle($tTitle){
$this->title = $tTitle;
} // end setTitle
function getPage(){
return $this->thePage;
} // end getPage
//most basic tags
function addText($content){
//given any text (including HTML markup)
//adds the text to the page
$this->thePage .= $content;
$this->thePage .= "\n";
} // end addText
function gAddText($content){
//given any text (including HTML markup)
//returns the text
$temp= $content;
$temp .= "\n";
return $temp;
} // end addText
function buildTop(){
$temp = <<<HERE
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>$this->title</title>
</head>
<body>
<center>
<h1>$this->title</h1>
</center>
HERE;
$this->addText($temp);
} // end buildTop;
function buildBottom(){
//builds the bottom of a generic web page
$temp = <<<HERE
</body>
</html>
HERE;
$this->addText($temp);
} // end buildBottom;
//general tag function
function tag($tagName, $contents){
//given any tag, surrounds contents with tag
//improve so tag can have attributes
$this->addText($this->gTag($tagName, $contents));
} // end tag
function gTag($tagName, $contents){
//given any tag, surrounds contents with tag
//improve so tag can have attributes
//returns tag but does not add it to page
$temp = "<$tagName>\n";
$temp .= " " . $contents . "\n";
$temp .= "</$tagName>\n";
return $temp;
} // end tag
//header functions
function h1($stuff){
$this->tag("h1", $stuff);
} // end h1
function h2($stuff){
$this->tag("h2", $stuff);
} // end h2
function h3($stuff){
$this->tag("h3", $stuff);
} // end h3
function h4($stuff){
$this->tag("h4", $stuff);
} // end h4
function h5($stuff){
$this->tag("h5", $stuff);
} // end h5
function h6($stuff){
$this->tag("h6", $stuff);
} // end h6
function gBuildList($theArray, $type = "ul"){
//given an array of values, builds a list based on that array
$temp= "<$type> \n";
foreach ($theArray as $value){
$temp .= " <li>$value</li> \n";
} // end foreach
$temp .= "</$type> \n";
return $temp;
} // end gBuildList
function buildList($theArray, $type = "ul"){
$temp = $this->gBuildList($theArray, $type);
$this->addText($temp);
} // end buildList
function gBuildTable($theArray){
//given a 2D array, builds an HTML table based on that array
$table = "<table border = 1> \n";
foreach ($theArray as $row){
$table .= "<tr> \n";
foreach ($row as $cell){
$table .= " <td>$cell</td> \n";
} // end foreach
$table .= "</tr> \n";
} // end foreach
$table .= "</table> \n";
return $table;
} // end gBuildTable
function buildTable($theArray){
$temp = $this->gBuildTable($theArray);
$this->addText($temp);
} // end buildTable
function startTable($border = "0"){
$this->thePage .= "<table border = \"$border\">\n";
} // end startTable
function tRow ($rowData, $rowType = "td"){
//expects an array in rowdata, prints a row of th values
$this->thePage .= "<tr> \n";
foreach ($rowData as $cell){
$this->thePage .= " <$rowType>$cell</$rowType> \n";
} // end foreach
$this->thePage .= "</tr> \n";
} // end thRow
function endTable(){
$this->thePage .= "</table> \n";
} // end endTable
//form elements
function gTextbox($name, $value = ""){
// returns but does not print
// an input type = text element
// used if you want to place form elements in a table
$temp .= <<<HERE
<input type = "text"
name = "$name"
value = "$value" />
HERE;
return $temp;
} // end textBox
function textbox($name, $value = ""){
$this->addText($this->gTextbox($name, $value));
} // end textBox
function gSubmit($value = "Submit Query"){
// returns but does not print
// an input type = submit element
// used if you want to place form elements in a table
$temp .= <<<HERE
<input type = "submit"
value = "$value" />
HERE;
return $temp;
} // end submit
function submit($value = "Submit Query"){
$this->addText($this->gSubmit($value));
} // end submit
function gSelect($name, $listVals){
//given an associative array,
//prints an HTML select object
//Each element has the appropriate
//value and displays the associated name
$temp = "";
$temp .= "<select name = \"$name\" >\n";
foreach ($listVals as $val => $desc){
$temp .= " <option value = \"$val\">$desc</option> \n";
} // end foreach
$temp .= "</select> \n";
return $temp;
} // end gSelect
function select($name, $listVals){
$this->addText($this->gSelect($name, $listVals));
} // end buildSelect
function formResults(){
//returns the names and values of all form elements
//in an HTML table
$this->startTable();
foreach ($_REQUEST as $name => $value){
$this->tRow(array($name,$value));
} // end foreach
$this->endTable();
} // end formResults
} // end class def
?>