-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbrowse.php
165 lines (154 loc) · 5.54 KB
/
browse.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
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
<?php
header("Expires: Mon, 20 Dec 1998 01:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<?php/*
All code, unless otherwise indicated, is original, and subject to the terms of
the GNU GPLv3 or, at your option, any later version of the GPL.
All content is derived from public domain, promotional, or otherwise-compatible
sources and published uniformly under the
Creative Commons Attribution-Share Alike 3.0 license.
See license.README for details.
(C) Neil Tallim, 2009
*/?>
<?php include 'common/constants.php'; ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hymmnoserver - Main</title>
<?php include 'common/resources.xml'; ?>
</head>
<body>
<?php include 'common/header.xml'; ?>
<div style="font-size: 0.90em; text-align: center;">
<?php
//Determine the nature of the requested display; default if unintelligible.
$page = '';
if(isset($_REQUEST['page'])){
$page = trim($_REQUEST['page']);
}
if($page == ''){//Assume 'a' by default.
$page = 'a';
}else{
if(is_numeric($page)){
$page = intval($page);
if($page == 0){//0 means any numeric/special entity.
$page = '0';
}elseif($page < 1 || $page > 14){//1-14 are lexical class identifiers.
$page = 1;
}
}else{
$page = strtolower($page[0]);
$page_ord = ord($page);
if(($page_ord < 97 || $page_ord > 122)){//Detect alpha-range.
$page = 'a';
}
}
}
#Render the alphabetical bar.
$characters = range('a', 'z');
$characters[] = '0';
$sections = array();
foreach($characters as $character){
$section = '<a href="./browse.php?page='.$character.'">';
if($character == $page){
$section .= '<span style="font-weight: bold; font-size: 1em;">'.$character.'</span>';
}else{
$section .= $character;
}
$sections[] = $section.'</a>';
}
echo implode(' / ', $sections);
echo '<br/>';
//Render the syntax class bar.
$sections = array();
$i = 0;
foreach(array(
'E.S. (I)', 'E.S. (II)', 'E.S. (III)', 'E.V.',
'adj.', 'adv.', 'conj.', 'cnstr.', 'intj.', 'n.',
'prep.', 'pron.', 'prt.', 'v.'
) as $class){//Force an enumerable order from 1-14.
$i++;
$section = '<a href="./browse.php?page='.$i.'">';
if($i == $page){
$section .= '<span style="font-weight: bold; font-size: 1em;">'.$class.'</span>';
}else{
$section .= $class;
}
$sections[] = $section.'</a>';
}
echo implode(' / ', $sections);
?>
</div>
<hr/>
<div>
<span style="color: red; font-size: 0.8em;">
<?php
require 'secure/db.php';
if($mysql->connect_error){
die('Failed to connect to database: '.htmlentities($mysql->connect_error));
}
if($page != '0'){//0 means all non-alpha-started entries.
if(is_numeric($page)){//Looking up records by syntax class.
$stmt = $mysql->prepare('SELECT word, meaning, kana, dialect, class FROM hymmnos WHERE class IN ('.implode(',', $SYNTAX_CLASS_REV[$page]).') ORDER BY word ASC');
}else{#Looking up records by starting letter.
$stmt = $mysql->prepare('SELECT word, meaning, kana, dialect, class FROM hymmnos WHERE word LIKE ? ORDER BY word ASC');
$page = $page.'%';
$stmt->bind_param('s', $page);
}
}else{//Get all non-alpha-started entries.
$stmt = $mysql->prepare("SELECT word, meaning, kana, dialect, class FROM hymmnos WHERE word RLIKE '^[^[:alpha:]].*'");
}
$stmt->execute();
$stmt->store_result();
$plural = '';
if($stmt->num_rows != 1){
$plural = 's';
}
printf('<b>%d record%s found</b>', $stmt->num_rows, $plural);
?>
(Hymmnos entries will open in a popup window)
</span>
</div>
<table>
<tr>
<th class="result-header" style="width: 100px;">Hymmnos</th>
<th class="result-header" style="width: 155px;">Meaning</th>
<th class="result-header" style="width: 75px;">Class</th>
<th class="result-header" style="width: 90px;">Kana</th>
<th class="result-header" style="width: 220px;">Dialect</th>
</tr>
<?php
if($stmt->num_rows > 0){//Render results only if there are results.
$stmt->bind_result($word, $meaning, $kana, $dialect, $class);
while($stmt->fetch()){//Render each result in its own row.
$html_word = htmlentities($word, ENT_COMPAT, "UTF-8");
echo '<tr>';
echo '<td class="result-cell result-dialect-'.$dialect.'">';
echo '<a href="javascript:popUpWord(\''.$html_word.'\', '.$dialect.')">'.$html_word.'</a>';
echo '</td>';
echo '<td class="result-cell result-dialect-'.$dialect.'">'.htmlentities($meaning, ENT_COMPAT, "UTF-8").'</td>';
echo '<td class="result-cell result-dialect-'.$dialect.'">';
echo $SYNTAX_CLASS[$class];
echo '</td>';
echo '<td class="result-cell result-dialect-'.$dialect.'">'.htmlentities($kana, ENT_COMPAT, "UTF-8").'</td>';
echo '<td class="result-cell result-dialect-'.$dialect.'">';
echo $DIALECT[$dialect];
echo '</td>';
echo '</tr>';
}
}else{
echo '<tr><td colspan="5" style="color: red; font-weight: bold; text-align: center;">No records found</td></tr>';
}
$stmt->free_result();
$stmt->close();
$mysql->close();
?>
</table>
<?php include 'common/footer.xml'; ?>
</body>
</html>