-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathedit_languages.php
344 lines (299 loc) · 15.9 KB
/
edit_languages.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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php
/**************************************************************
"Learning with Texts" (LWT) is released into the Public Domain.
This applies worldwide.
In case this is not legally possible, any entity is granted the
right to use this work for any purpose, without any conditions,
unless such conditions are required by law.
Developed by J. Pierre in 2011.
***************************************************************/
/**************************************************************
Call: edit_languages.php?....
... refresh=[langid] ... reparse all texts in lang
... del=[langid] ... do delete
... op=Save ... do insert new
... op=Change ... do update
... new=1 ... display new lang. screen
... chg=[langid] ... display edit screen
Manage languages
***************************************************************/
include "connect.inc.php";
include "settings.inc.php";
include "utilities.inc.php";
pagestart('My Languages',true);
$message = '';
// REFRESH
if (isset($_REQUEST['refresh'])) {
$id = $_REQUEST['refresh'] + 0;
$message2 = runsql('delete from sentences where SeLgID = ' . $id,
"Sentences deleted");
$message3 = runsql('delete from textitems where TiLgID = ' . $id,
"Text items deleted");
adjust_autoincr('sentences','SeID');
adjust_autoincr('textitems','TiID');
$sql = "select TxID, TxText from texts where TxLgID = " . $id . " order by TxID";
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid Query: $sql");
while ($record = mysql_fetch_assoc($res)) {
$txtid = $record["TxID"];
$txttxt = $record["TxText"];
splitText($txttxt, $id, $txtid );
}
mysql_free_result($res);
$message = $message2 . " / " . $message3 . " / Sentences added: " . get_first_value('select count(*) as value from sentences where SeLgID = ' . $id) . " / Text items added: " . get_first_value('select count(*) as value from textitems where TiLgID = ' . $id);
}
// DEL
if (isset($_REQUEST['del'])) {
$anztexts = get_first_value(
'select count(TxID) as value from texts where TxLgID = ' .
$_REQUEST['del']);
$anzarchtexts = get_first_value(
'select count(AtID) as value from archivedtexts where AtLgID = ' .
$_REQUEST['del']);
$anzwords = get_first_value(
'select count(WoID) as value from words where WoLgID = ' .
$_REQUEST['del']);
if ( $anztexts > 0 || $anzarchtexts > 0 || $anzwords > 0) {
$message = 'You must first delete texts, archived texts and words with this language!';
} else {
$message = runsql('delete from languages where LgID = ' . $_REQUEST['del'],
"Deleted");
adjust_autoincr('languages','LgID');
}
}
// INS/UPD
elseif (isset($_REQUEST['op'])) {
// INSERT
if ($_REQUEST['op'] == 'Save')
$message = runsql('insert into languages (LgName, LgDict1URI, LgDict2URI, LgGoogleTranslateURI, LgTextSize, LgCharacterSubstitutions, LgRegexpSplitSentences, LgExceptionsSplitSentences, LgRegexpWordCharacters, LgRemoveSpaces, LgSplitEachChar, LgRightToLeft) values(' .
convert_string_to_sqlsyntax($_REQUEST["LgName"]) . ', ' .
convert_string_to_sqlsyntax($_REQUEST["LgDict1URI"]) . ', '.
convert_string_to_sqlsyntax($_REQUEST["LgDict2URI"]) . ', '.
convert_string_to_sqlsyntax($_REQUEST["LgGoogleTranslateURI"]) . ', '.
$_REQUEST["LgTextSize"] . ', '.
convert_string_to_sqlsyntax_notrim_nonull($_REQUEST["LgCharacterSubstitutions"]) . ', '.
convert_string_to_sqlsyntax($_REQUEST["LgRegexpSplitSentences"]) . ', '.
convert_string_to_sqlsyntax_notrim_nonull($_REQUEST["LgExceptionsSplitSentences"]) . ', '.
convert_string_to_sqlsyntax($_REQUEST["LgRegexpWordCharacters"]) . ', '.
$_REQUEST["LgRemoveSpaces"] . ', '.
$_REQUEST["LgSplitEachChar"] . ', '.
$_REQUEST["LgRightToLeft"] .
')', 'Saved');
// UPDATE
elseif ($_REQUEST['op'] == 'Change')
$message = runsql('update languages set ' .
'LgName = ' . convert_string_to_sqlsyntax($_REQUEST["LgName"]) . ', ' .
'LgDict1URI = ' . convert_string_to_sqlsyntax($_REQUEST["LgDict1URI"]) . ', ' .
'LgDict2URI = ' . convert_string_to_sqlsyntax($_REQUEST["LgDict2URI"]) . ', ' .
'LgGoogleTranslateURI = ' . convert_string_to_sqlsyntax($_REQUEST["LgGoogleTranslateURI"]) . ', ' .
'LgTextSize = ' . $_REQUEST["LgTextSize"] . ', ' .
'LgCharacterSubstitutions = ' . convert_string_to_sqlsyntax_notrim_nonull($_REQUEST["LgCharacterSubstitutions"]) . ', ' .
'LgRegexpSplitSentences = ' . convert_string_to_sqlsyntax($_REQUEST["LgRegexpSplitSentences"]) . ', ' .
'LgExceptionsSplitSentences = ' . convert_string_to_sqlsyntax_notrim_nonull($_REQUEST["LgExceptionsSplitSentences"]) . ', ' .
'LgRegexpWordCharacters = ' . convert_string_to_sqlsyntax($_REQUEST["LgRegexpWordCharacters"]) . ', ' .
'LgRemoveSpaces = ' . $_REQUEST["LgRemoveSpaces"] . ', ' .
'LgSplitEachChar = ' . $_REQUEST["LgSplitEachChar"] . ', ' .
'LgRightToLeft = ' . $_REQUEST["LgRightToLeft"] .
' where LgID = ' . $_REQUEST["LgID"], 'Updated');
}
// NEW
if (isset($_REQUEST['new'])) {
?>
<h4>New Language <a target="_blank" href="info.htm#howtolang"><img src="icn/question-frame.png" title="Help" alt="Help" /></a> </h4>
<form class="validate" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table class="tab3" cellspacing="0" cellpadding="5">
<tr>
<td class="td1 right">Language:</td>
<td class="td1"><input type="text" class="notempty setfocus" name="LgName" value="" maxlength="40" size="40" /> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" /></td>
</tr>
<tr>
<td class="td1 right">Dictionary 1 URI:</td>
<td class="td1"><input type="text" class="notempty" name="LgDict1URI" value="http://translate.google.com/?ie=UTF-8&sl=••&tl=••&text=###" maxlength="200" size="60" /> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" /></td>
</tr>
<tr>
<td class="td1 right">Dictionary 2 URI:</td>
<td class="td1"><input type="text" name="LgDict2URI" value="" maxlength="200" size="60" /></td>
</tr>
<tr>
<td class="td1 right">GoogleTranslate URI:</td>
<td class="td1"><input type="text" name="LgGoogleTranslateURI" value="http://translate.google.com/?ie=UTF-8&sl=••&tl=••&text=###" maxlength="200" size="60" /></td>
</tr>
<tr>
<td class="td1 right">Text Size:</td>
<td class="td1"><select name="LgTextSize" class="notempty"><?php echo get_languagessize_selectoptions(150); ?></select></td>
</tr>
<tr>
<td class="td1 right">Character Substitutions:</td>
<td class="td1"><input type="text" name="LgCharacterSubstitutions" value="´='|`='|’='|‘='|...=…|..=‥" maxlength="500" size="60" /></td>
</tr>
<tr>
<td class="td1 right">RegExp Split Sentences:</td>
<td class="td1"><input type="text" class="notempty" name="LgRegexpSplitSentences" value=".!?:;" maxlength="500" size="60" /> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" /></td>
</tr>
<tr>
<td class="td1 right">Exceptions Split Sentences:</td>
<td class="td1"><input type="text" name="LgExceptionsSplitSentences" value="Mr.|Dr.|[A-Z].|Vd.|Vds." maxlength="500" size="60" /></td>
</tr>
<tr>
<td class="td1 right">RegExp Word Characters:</td>
<td class="td1"><input type="text" class="notempty" name="LgRegexpWordCharacters" value="a-zA-ZÀ-ÖØ-öø-ȳ" maxlength="500" size="60" /> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" /></td>
</tr>
<tr>
<td class="td1 right">Make each character a word:</td>
<td class="td1"><select name="LgSplitEachChar"><?php echo get_yesno_selectoptions(0); ?></select> (e.g. for Chinese, Japanese, etc.)</td>
</tr>
<tr>
<td class="td1 right">Remove spaces:</td>
<td class="td1"><select name="LgRemoveSpaces"><?php echo get_yesno_selectoptions(0); ?></select> (e.g. for Chinese, Japanese, etc.)</td>
</tr>
<tr>
<td class="td1 right">Right-To-Left Script:</td>
<td class="td1"><select name="LgRightToLeft"><?php echo get_yesno_selectoptions(0); ?></select> (e.g. for Arabic, Hebrew, Farsi, Urdu, etc.)</td>
</tr>
<tr>
<td class="td1 right" colspan="2"><input type="button" value="Cancel" onclick="location.href='edit_languages.php';" />
<input type="submit" name="op" value="Save" /></td>
</tr>
</table>
</form>
<?php
}
// CHG
elseif (isset($_REQUEST['chg'])) {
$sql = 'select * from languages where LgID = ' . $_REQUEST['chg'];
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid Query: $sql");
if ($record = mysql_fetch_assoc($res)) {
?>
<h4>Edit Language <a target="_blank" href="info.htm#howtolang"><img src="icn/question-frame.png" title="Help" alt="Help" /></a> </h4>
<form class="validate" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="LgID" value="<?php echo $_REQUEST['chg']; ?>" />
<table class="tab3" cellspacing="0" cellpadding="5">
<tr>
<td class="td1 right">ID:</td>
<td class="td1"><?php echo $_REQUEST['chg']; ?></td>
</tr>
<tr>
<td class="td1 right">Language:</td>
<td class="td1"><input type="text" class="notempty setfocus" name="LgName" maxlength="40" size="40" value="<?php echo tohtml($record['LgName']); ?>" /> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" /></td>
</tr>
<tr>
<td class="td1 right">Dictionary 1 URI:</td>
<td class="td1"><input type="text" class="notempty" name="LgDict1URI" value="<?php echo tohtml($record['LgDict1URI']); ?>" maxlength="200" size="60" /> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" /></td>
</tr>
<tr>
<td class="td1 right">Dictionary 2 URI:</td>
<td class="td1"><input type="text" name="LgDict2URI" value="<?php echo tohtml($record['LgDict2URI']); ?>" maxlength="200" size="60" /></td>
</tr>
<tr>
<td class="td1 right">GoogleTranslate URI:</td>
<td class="td1"><input type="text" name="LgGoogleTranslateURI" value="<?php echo tohtml($record['LgGoogleTranslateURI']); ?>" maxlength="200" size="60" /></td>
</tr>
<tr>
<td class="td1 right">Text Size:</td>
<td class="td1"><select name="LgTextSize"><?php echo get_languagessize_selectoptions($record['LgTextSize']); ?></select></td>
</tr>
<tr>
<td class="td1 right">Character Substitutions:</td>
<td class="td1"><input type="text" name="LgCharacterSubstitutions" value="<?php echo tohtml($record['LgCharacterSubstitutions']); ?>" maxlength="500" size="60" /></td>
</tr>
<tr>
<td class="td1 right">RegExp Split Sentences:</td>
<td class="td1"><input type="text" class="notempty" name="LgRegexpSplitSentences" value="<?php echo tohtml($record['LgRegexpSplitSentences']); ?>" maxlength="500" size="60" /> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" /></td>
</tr>
<tr>
<td class="td1 right">Exceptions Split Sentences:</td>
<td class="td1"><input type="text" name="LgExceptionsSplitSentences" value="<?php echo tohtml($record['LgExceptionsSplitSentences']); ?>" maxlength="500" size="60" /></td>
</tr>
<tr>
<td class="td1 right">RegExp Word Characters:</td>
<td class="td1"><input type="text" class="notempty" name="LgRegexpWordCharacters" value="<?php echo tohtml($record['LgRegexpWordCharacters']); ?>" maxlength="500" size="60" /> <img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" /></td>
</tr>
<tr>
<td class="td1 right">Make each character a word:</td>
<td class="td1"><select name="LgSplitEachChar"><?php echo get_yesno_selectoptions($record['LgSplitEachChar']); ?></select> (e.g. for Chinese, Japanese, etc.)</td>
</tr>
<tr>
<td class="td1 right">Remove spaces:</td>
<td class="td1"><select name="LgRemoveSpaces"><?php echo get_yesno_selectoptions($record['LgRemoveSpaces']); ?></select> (e.g. for Chinese, Japanese, etc.)</td>
</tr>
<tr>
<td class="td1 right">Right-To-Left Script:</td>
<td class="td1"><select name="LgRightToLeft"><?php echo get_yesno_selectoptions($record['LgRightToLeft']); ?></select> (e.g. for Arabic, Hebrew, Farsi, Urdu, etc.)</td>
</tr>
<tr>
<td class="td1 right" colspan="2"><input type="button" value="Cancel" onclick="location.href='edit_languages.php';" />
<input type="submit" name="op" value="Change" /></td>
</tr>
</table>
</form>
<?php
}
mysql_free_result($res);
}
// DISPLAY
else {
echo error_message_with_hide($message,0);
$current = (int) getSetting('currentlanguage');
$recno = get_first_value('select count(*) as value from languages');
?>
<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?new=1"><img src="icn/plus-button.png" title="New" alt="New" /> New Language ...</a></p>
<?php
if ($recno==0) {
?>
<p>No languages found.</p>
<?php
} else {
?>
<table class="sortable tab1" cellspacing="0" cellpadding="5">
<tr>
<th class="th1 sorttable_nosort">Curr.<br />Lang.</th>
<th class="th1 sorttable_nosort">Test<br />↓↓↓</th>
<th class="th1 sorttable_nosort">Actions</th>
<th class="th1 clickable">Language</th>
<th class="th1 sorttable_numeric clickable">Texts,<br />Re-Parse</th>
<th class="th1 sorttable_numeric clickable">Arch.<br />Texts</th>
<th class="th1 sorttable_numeric clickable">Terms</th>
</tr>
<?php
$sql = 'select LgID, LgName from languages order by LgName';
if ($debug) echo $sql;
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid Query: $sql");
while ($record = mysql_fetch_assoc($res)) {
$textcount = get_first_value('select count(TxID) as value from texts where TxLgID=' . $record['LgID']);
$archtextcount = get_first_value('select count(AtID) as value from archivedtexts where AtLgID=' . $record['LgID']);
$wordcount = get_first_value('select count(WoID) as value from words where WoLgID=' . $record['LgID']);
echo '<tr>';
if ( $current == $record['LgID'] ) {
$tdth = 'th';
echo '<th class="th1"><img src="icn/exclamation-red.png" title="Current Language" alt="Current Language" /></th>';
} else {
$tdth = 'td';
echo '<td class="td1 center"><a href="save_setting_redirect.php?k=currentlanguage&v=' . $record['LgID'] . '&u=edit_languages.php"><img src="icn/tick-button.png" title="Set as Current Language" alt="Set as Current Language" /></a></td>';
}
echo '<' . $tdth . ' class="' . $tdth . '1 center"><a href="do_test.php?lang=' . $record['LgID'] . '"><img src="icn/question-balloon.png" title="Test" alt="Test" /></a></' . $tdth . '>';
echo '<' . $tdth . ' class="' . $tdth . '1 center" nowrap="nowrap"> <a href="' . $_SERVER['PHP_SELF'] . '?chg=' . $record['LgID'] . '"><img src="icn/document--pencil.png" title="Edit" alt="Edit" /></a>';
if ($textcount == 0 && $archtextcount == 0 && $wordcount == 0)
echo ' <span class="click" onclick="if (confirm (\'Are you sure?\')) location.href=\'' . $_SERVER['PHP_SELF'] . '?del=' . $record['LgID'] . '\';"><img src="icn/minus-button.png" title="Delete" alt="Delete" /></span>';
else
echo ' <img src="icn/placeholder.png" title="Delete not possible" alt="Delete not possible" />';
echo ' </' . $tdth . '>';
echo '<' . $tdth . ' class="' . $tdth . '1 center">' . tohtml($record['LgName']) . '</' . $tdth . '>';
if ($textcount > 0)
echo '<' . $tdth . ' class="' . $tdth . '1 center"><a href="edit_texts.php?page=1&query=&filterlang=' . $record['LgID'] . '">' . $textcount . '</a> <a href="' . $_SERVER['PHP_SELF'] . '?refresh=' . $record['LgID'] . '"><img src="icn/lightning.png" title="Re-Parse Texts" alt="Re-Parse Texts" /></a>';
else
echo '<' . $tdth . ' class="' . $tdth . '1 center">0 <img src="icn/placeholder.png" title="No texts to re-parse" alt="No texts to re-parse" />';
echo '</' . $tdth . '>';
echo '<' . $tdth . ' class="' . $tdth . '1 center">' . ($archtextcount > 0 ? '<a href="edit_archivedtexts.php?page=1&query=&filterlang=' . $record['LgID'] . '">' . $archtextcount . '</a>' : '0' ) . '</' . $tdth . '>';
echo '<' . $tdth . ' class="' . $tdth . '1 center">' . ($wordcount > 0 ? '<a href="edit_words.php?page=1&query=&text=&status=&filterlang=' . $record['LgID'] . '&status=&tag12=0&tag2=&tag1=">' . $wordcount . '</a>' : '0' ) . '</' . $tdth . '>';
echo '</tr>';
}
mysql_free_result($res);
?>
</table>
<?php
}
}
pageend();
?>