-
Notifications
You must be signed in to change notification settings - Fork 30
/
html.php
111 lines (104 loc) · 3.79 KB
/
html.php
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
<?php
/**
* PHP REST SQL HTML renderer class
* This class renders the REST response data as HTML.
*/
class PHPRestSQLRenderer {
/**
* @var PHPRestSQL PHPRestSQL
*/
var $PHPRestSQL;
/**
* Constructor. Takes an output array and calls the appropriate handler.
* @param PHPRestSQL PHPRestSQL
*/
function render($PHPRestSQL) {
$this->PHPRestSQL = $PHPRestSQL;
switch($PHPRestSQL->display) {
case 'database':
$this->database();
break;
case 'table':
$this->table();
break;
case 'row':
$this->row();
break;
}
}
/**
* Output the top level table listing.
*/
function database() {
header('Content-Type: text/html');
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">'."\n";
echo '<html>'."\n";
echo '<head>'."\n";
echo '<title>PHP REST SQL : Database "'.htmlspecialchars($this->PHPRestSQL->config['database']['database']).'"</title>'."\n";
echo '</head>'."\n";
echo '<body>'."\n";
echo '<h1>Tables in database "'.htmlspecialchars($this->PHPRestSQL->config['database']['database']).'"</h1>'."\n";
if (isset($this->PHPRestSQL->output['database'])) {
echo '<ul>'."\n";
foreach ($this->PHPRestSQL->output['database'] as $table) {
echo '<li><a href="'.htmlspecialchars($table['xlink']).'">'.htmlspecialchars($table['value']).'</a></li>'."\n";
}
echo '</ul>'."\n";
}
echo '</body>'."\n";
echo '</html>'."\n";
}
/**
* Output the rows within a table.
*/
function table() {
header('Content-Type: text/html');
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">'."\n";
echo '<html>'."\n";
echo '<head>'."\n";
echo '<title>PHP REST SQL : Table "'.htmlspecialchars($this->PHPRestSQL->table).'"</title>'."\n";
echo '</head>'."\n";
echo '<body>'."\n";
echo '<h1>Records in table "'.htmlspecialchars($this->PHPRestSQL->table).'"</h1>'."\n";
if (isset($this->PHPRestSQL->output['table'])) {
echo '<ul>'."\n";
foreach ($this->PHPRestSQL->output['table'] as $row) {
echo '<li><a href="'.htmlspecialchars($row['xlink']).'">'.htmlspecialchars($row['value']).'</a></li>'."\n";
}
echo '</ul>'."\n";
}
echo '</body>'."\n";
echo '</html>'."\n";
}
/**
* Output the entry in a table row.
*/
function row() {
header('Content-Type: text/html');
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">'."\n";
echo '<html>'."\n";
echo '<head>'."\n";
echo '<title>PHP REST SQL : Record #'.htmlspecialchars(join('/', $this->PHPRestSQL->uid)).'</title>'."\n";
echo '</head>'."\n";
echo '<body>'."\n";
echo '<h1>Record #'.htmlspecialchars(join('/', $this->PHPRestSQL->uid)).'</h1>'."\n";
if (isset($this->PHPRestSQL->output['row'])) {
echo '<table>'."\n";
foreach ($this->PHPRestSQL->output['row'] as $field) {
echo '<tr>'."\n";
echo '<th>'.htmlspecialchars($field['field']).'</th>'."\n";
echo '<td>'."\n";
if (isset($field['xlink'])) {
echo '<a href="'.htmlspecialchars($field['xlink']).'">'.htmlspecialchars($field['value']).'</a>'."\n";
} else {
echo htmlspecialchars($field['value'])."\n";
}
echo '</td>'."\n";
echo '</tr>'."\n";
}
echo '</table>'."\n";
}
echo '</body>'."\n";
echo '</html>'."\n";
}
}