-
Notifications
You must be signed in to change notification settings - Fork 0
/
glossary.php
201 lines (172 loc) · 8.4 KB
/
glossary.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
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
<?php
include("static/header.php");
$glossary = htmlspecialchars($_GET['glossary']);
$sort = htmlspecialchars($_GET['sort']);
if ($glossary == 'all') {
$refcode = "P";
$gloname = "Tous";
} else if($glossary == 'tf') {
$refcode = "P01";
$gloname = "Titres et fonctions";
} else if($glossary == 'es') {
$refcode = "P02";
$gloname = "Enseignement supérieur";
} else {
die("Glossaire inconnu.");
}
include('static/retour.php');
if($sort == "fr") {
$cible = "en";
$other_lang = "l'anglais";
} else {
$cible = "fr";
$other_lang = "le français";
}
$conn = mysqli_connect($server, $username, $password) or die("Unable to connect to '$server'");
$conn -> set_charset("utf8");
mysqli_select_db($conn, $database) or die("Could not open the database '$database'");
if ($conn) {
$query = "SELECT * FROM termgroup WHERE termlexid LIKE '$refcode%$sort' ORDER BY termtext";
$result = mysqli_query($conn, $query);
$num_rows = mysqli_num_rows($result);
// How many items to list per page
if(isset($_GET['limit'])) {
$limit = htmlspecialchars($_GET['limit']);
} else {
$limit = 10;
}
// How many pages will there be
$pages = ceil($num_rows / $limit);
// What page are we currently on?
$page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
'options' => array(
'default' => 1,
'min_range' => 1,
),
)));
// Calculate the offset for the query
$offset = ($page - 1) * $limit;
// Some information to display to the user
$start = $offset + 1;
$end = min(($offset + $limit), $num_rows);
// The "back" link
$prevlink = ($page > 1) ? '<a href="?glossary='.$glossary.'&sort='.$sort.'&page=1&limit='.$limit.'" title="Première page">«</a> <a href="?glossary='.$glossary.'&sort='.$sort.'&page='.($page - 1).'&limit='.$limit.'" title="Page précedente">‹</a>' : '<span class="disabled">«</span> <span class="disabled">‹</span>';
// The "forward" link
$nextlink = ($page < $pages) ? '<a href="?glossary='.$glossary.'&sort='.$sort.'&page='.($page + 1).'&limit='.$limit.'" title="Page suivante">›</a> <a href="?glossary='.$glossary.'&sort='.$sort.'&page='.$pages.'&limit='.$limit.'" title="Dernière page">»</a>' : '<span class="disabled">›</span> <span class="disabled">»</span>';
echo "<b>Domaine : " . $gloname . "</b> | ";
echo "<a href='?glossary=" . $glossary . "&sort=" . $cible . "'>Trier en se basant sur " . $other_lang . "</a><br><br>";
echo "<b>" . $num_rows . " entrées</b> trouvées<br><br>";
if ($num_rows > 0) {
// Display the paging information
echo '<div id="paging"><p>', $prevlink, ' Page ', $page, ' sur ', $pages, ' (entrées ', $start, '-', $end, ') ', $nextlink, ' </p></div>';
echo "<table class='results_table'>";
$query = "SELECT * FROM termgroup WHERE termlexid LIKE '$refcode%$sort' ORDER BY termtext LIMIT $limit OFFSET $offset";
$main_result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_assoc($main_result)) {
echo "<tr>";
$lang = strtoupper(explode("-", $row['termlexid'])[3]);
$mf = False;
echo "<td width='45'>" . $lang . "</td>";
echo "<td><details><summary>";
echo "<span title='Cliquez sur le terme pour voir sa définition.'>" . $row['termtext'];
$variant = $row['variant'];
if($variant != NULL) {
echo " | ";
echo $variant;
$mf = True;
}
$langroup_source = $row['langroup'];
$abbrev = $row['abbrev'];
if($abbrev == 1) {
$result = mysqli_query($conn, "SELECT * FROM termgroup WHERE langroup=$langroup_source");
$row2 = mysqli_fetch_assoc($result);
$termtextfull = $row2['termtext'];
$termtextfull_variant = $row2['variant'];
echo " (" . $termtextfull;
if($termtextfull_variant) {
echo " | " . $termtextfull_variant;
}
echo ")";
$mf = True;
} else {
$result = mysqli_query($conn, "SELECT * FROM termgroup WHERE langroup=$langroup_source AND abbrev=1");
$row2 = mysqli_fetch_assoc($result);
if($row2) {
$acro = $row2['termtext'];
echo " (" . $acro . ")";
}
}
echo "</span></summary>";
$pos_id = $row['pos'];
if($pos_id == 1) {
$pos = "Nom";
} else {
$pos = "Adjectif";
}
$gender_id = $row['gender'];
if($gender_id == 4 or $mf) {
$gender = "masculin ou féminin";
} else if($gender_id == 2) {
$gender = "masculin";
} else if($gender_id == 8) {
$gender = "féminin";
} else {
$gender = "";
}
echo "<br>" . $pos . " " . $gender . "<br>";
$result = mysqli_query($conn, "SELECT termid FROM langroup WHERE id=$langroup_source");
$termid = mysqli_fetch_assoc($result)['termid'];
$result = mysqli_query($conn, "SELECT definition FROM langroup WHERE termid=$termid AND lang LIKE 'fr%'");
$definition = mysqli_fetch_assoc($result)['definition'];
if(!empty($definition)) {
$result = mysqli_query($conn, "SELECT * FROM source WHERE termid=$termid AND type='def'");
$row = mysqli_fetch_assoc($result);
$bib_id = $row['biblio'];
$source_text_def = $row['text'];
$result = mysqli_query($conn, "SELECT title FROM biblio WHERE id=$bib_id");
$bib_title_def = mysqli_fetch_assoc($result)['title'];
echo "<br><u>Définition</u> : " . $definition . " (<i>" . $bib_title_def . "</i>, " . $source_text_def . ")";
}
$result = mysqli_query($conn, "SELECT explanation FROM langroup WHERE termid=$termid AND lang LIKE '$sort%'");
$explanation = mysqli_fetch_assoc($result)['explanation'];
if(!empty($explanation)) {
$result = mysqli_query($conn, "SELECT * FROM source WHERE termid=$termid AND type='exp'");
$row = mysqli_fetch_assoc($result);
$bib_id = $row['biblio'];
$source_text_exp = $row['text'];
$result = mysqli_query($conn, "SELECT title FROM biblio WHERE id=$bib_id");
$bib_title_exp = mysqli_fetch_assoc($result)['title'];
echo "<br><br><u>Explication</u> : " . $explanation . " (<i>" . $bib_title_exp . "</i>, " . $source_text_exp . ")";
}
echo "</details></td></tr>";
$result = mysqli_query($conn, "SELECT id FROM langroup WHERE termid=$termid AND lang LIKE '$cible%'");
$langroup_target = mysqli_fetch_assoc($result)['id'];
$results_pref = mysqli_query($conn, "SELECT * FROM termgroup WHERE langroup=$langroup_target AND auth=7");
if($results_pref === FALSE) {
print_r(mysqli_errors(), true);
print_r($langroup_target);
}
$results_admi = mysqli_query($conn, "SELECT * FROM termgroup WHERE langroup=$langroup_target AND auth IN (0,9)");
$results_depr = mysqli_query($conn, "SELECT * FROM termgroup WHERE langroup=$langroup_target AND auth=10");
$num_pref = mysqli_num_rows($results_pref);
echo "<tr><td>" . strtoupper($cible) . "</td><td>";
show_trad($conn, $results_pref, $cible, "privilégié");
if($num_pref == 0) {
show_trad($conn, $results_admi, $cible, "admis");
show_trad($conn, $results_depr, $cible, "à éviter");
}
echo "</td></tr>";
// Blank separation between two rows
if(--$num_rows > 0) {
echo "<tr><th></th></tr><tr><th></th></tr>";
}
}
echo "</table>";
// Display the paging information
echo '<div id="paging"><p>', $prevlink, ' Page ', $page, ' sur ', $pages, ' (entrées ', $start, '-', $end, ') ', $nextlink, ' </p></div>';
}
else {
echo "Aucune entrée trouvée dans ce glossaire.";
}
}
?>