Add another
[apertium.git] / apertium-dictionary-form / index.php
blob66d8569687827f3c4020404686565e7076aec3c8
1 <?
2 require_once 'config.php';
3 require_once 'pair.php';
5 /*
7 * Set up variables
9 */
11 // session_start();
13 /* If not already loaded for this session, load the config,
14 otherwise set the $config variable to the existing config. */
16 if(!isset($_SESSION['config'])) {
17 $config = new Config('config/config.xml');
18 $_SESSION['config'] = $config;
19 } else {
20 $config = $_SESSION['config'];
23 $pairs = $config->pairs();
24 if(!isset($_POST['selected_pair'])) {
25 $pair_names = array_keys($pairs);
26 $current_pair = $pair_names[0];
27 } else {
28 $current_pair = $_POST['selected_pair'];
30 $pair = $config->get_pair($current_pair);
32 if(!isset($_POST['selected_tag'])) {
33 $tags = $pair->tags();
34 $tag_names = array_keys($tags);
35 $current_tag = $tag_names[0];
36 } else {
37 $current_tag = $_POST['selected_tag'];
40 $template = "none";
41 if(isset($_POST['selected_template'])) {
42 $template = $_POST['selected_template'];
45 $left_lemma = $_POST['left_lemma'];
46 $left_paradigm = $_POST['left_paradigm'];
47 $left_comment = $_POST['left_comment'];
49 $right_lemma = $_POST['right_lemma'];
50 $right_paradigm = $_POST['right_paradigm'];
51 $right_comment = $_POST['right_comment'];
53 $left_lemma_exists = "false";
54 $right_lemma_exists = "false";
56 $left_lemma_exists = $_POST['left_lemma_exists'];
57 $right_lemma_exists = $_POST['right_lemma_exists'];
59 $dictionary_left = $pair->dictionary('left');
60 $left_lemma_exists = $dictionary_left->lemma_exists($left_lemma, $current_tag);
62 $dictionary_right = $pair->dictionary('right');
63 $right_lemma_exists = $dictionary_right->lemma_exists($right_lemma, $current_tag);
65 $restriction = $_POST['restriction'];
67 if(isset($_POST['preview_box'])) {
68 if($_POST['preview_box'] == _('Preview')) {
69 print $_POST['preview_box'];
70 print ' (' . $template . ')';
71 $previewing = 'on';
75 if(isset($_POST['commit_box'])) {
76 if($_POST['commit_box'] == _('Commit')) {
77 print $_POST['commit_box'];
78 print ' (' . $template . ')';
79 $committing = 'on';
83 if(isset($_POST['clear_box'])) {
84 if($_POST['clear_box'] == _('Clear')) {
85 $right_lemma = '';
86 $left_lemma = '';
87 $right_paradigm = '';
88 $left_paradigm = '';
89 $restriction = '';
95 <html>
96 <head>
97 <title><? print _('Dictionary management'); ?></title>
98 <link rel="stylesheet" type="text/css" href="styles/default.css"/>
99 <script src="js/boxover.js"></script>
100 </head>
101 <body>
102 <form action="index.php" method="POST" name="dixform">
103 <div id="language_bar">
104 ca · en · es
105 </div>
106 <div>
107 <div width="100%"> <!-- Header -->
108 <? print _('Language pair:'); ?> <select name="selected_pair" onChange="dixform.submit();">
110 $pairs = $config->pairs();
112 foreach($pairs as $pair) {
113 $pair = trim($pair->name);
114 print ' <option value="' . $pair . '"' . ($pair == $current_pair ? ' selected' : '') . '>' . $pair . '</option>' . "\n ";
117 print "\n";
119 </select>
120 <? print _('Part-of-speech:'); ?> <select name="selected_tag" onChange="dixform.submit();">
122 $pair = $config->get_pair($current_pair);
123 $tags = $pair->tags();
125 foreach($tags as $tag) {
126 $tag = trim($tag);
127 print '<option value="' . $tag . '"' . ($tag == $current_tag ? ' selected' : '') . '>' . $tag . '</option>' . "\n";
130 </select>
131 </div>
133 <hr/>
134 <div>
135 <!-- Left side -->
136 <div id="left">
138 $pair = $config->get_pair($current_pair);
139 $dictionary = $pair->dictionary('left');
141 print _($dictionary->language) . ' <br /><small>(';
142 print $dictionary->file . ' )</small>';
145 Lemma:<sup><span class="tooltip" title="header=[Lemma] body=[Type in the lemma, or citation form of the word you wish to add.]">?</span></sup>
146 <input type="text" name="left_lemma" value="<? print $left_lemma; ?>" <? if($left_lemma_exists == "true") { print 'id="known_word"'; } ?>>
148 <? if($left_lemma_exists == "true") { print _("Known lemma"); } ?>
149 </p>
151 <? print _('Paradigm'); ?>:
152 <sup><span class="tooltip" title="header=[Paradigm] body=[Paradigms define how a word inflects, select the one that fits the lemma you added.]">?</span></sup>
153 <select name="left_paradigm">
155 $pair = $config->get_pair($current_pair);
156 $dictionary = $pair->dictionary('left');
157 $paradigms = $dictionary->paradigms($current_tag);
158 $display_mode = $dictionary->get_display_mode($current_tag);
160 $glosses = $dictionary->glosses();
162 foreach($paradigms as $paradigm) {
163 // if we're in "list mode and there is no gloss for this
164 // paradigm, don't display it
165 if($display_mode == "list" && $glosses[$paradigm->name] == "") {
166 continue;
168 print '<option value="' . $paradigm->name . '"';
169 if($paradigm->name == $left_paradigm) {
170 print ' selected';
172 if($glosses[$paradigm->name] != "") {
173 print '>' . $glosses[$paradigm->name] . '</option>'. "\n";
174 } else {
175 print '>' . $paradigm->name . '</option>'. "\n";
179 </select>
180 </p>
182 <? print _('Comment'); ?>:
183 <sup><span class="tooltip" title="header=[Comment] body=[You can leave a comment here.]">?</span></sup>
184 <input type="text" name="left_comment" value="<? print $left_comment; ?>" />
185 </p>
188 if($previewing == 'on') {
189 $pair = $config->get_pair($current_pair);
190 $dictionary = $pair->dictionary('left');
192 $par = $dictionary->get_paradigm($left_paradigm, $current_tag);
193 $stems = $par->stems();
194 $show_stems = $pair->shows($current_tag);
195 $templates = $pair->templates("l");
197 foreach(array_keys($stems) as $stem) {
198 if(sizeof($show_stems) > 1) {
199 // if there is a tag whitelist, use it.
200 foreach($show_stems as $show) {
201 if($show == $stems[$stem][0]) {
202 print $dictionary->incondicional($left_lemma, $left_paradigm) . $stem . '<br />';
203 print '<span id="symbol_list">' . $stems[$stem][0] . '</span>';
204 print '<br/>';
207 } else {
208 // if not, display all stem-tag pairs.
209 print $dictionary->incondicional($left_lemma, $left_paradigm) . $stem . '<br />';
210 print '<span id="symbol_list">' . $stems[$stem][0] . '</span>';
211 print '<br/>';
214 // if some templates have been retrieved for this pair
215 // check the stem tags of the current paradigm against
216 // the ones stored for each template. if any match, set
217 // the current template.
218 if(sizeof($templates) > 0) {
219 foreach(array_keys($templates) as $tmpl_tag) {
220 if(strstr($stems[$stem][0], $tmpl_tag)) {
221 $template = $templates[$tmpl_tag];
225 } else {
226 $template = "none";
230 $dictionary = $pair->dictionary('left');
231 $left_entrada = $dictionary->generate_monodix_entrada($left_lemma, $left_paradigm, $left_comment, "webform");
233 print '<p>';
234 print '<span id="monodix_entrada"><pre>';
235 print str_replace('>', '&gt;', str_replace('<', '&lt;', $left_entrada));
236 print '</pre></span>';
239 </p>
240 </div>
241 <!-- Bidix side -->
242 <div id="centre">
243 Direction restriction:<sup><span class="tooltip" title="header=[Direction restriction] body=[Please indicate the direction in which this word pair should be translated.]">?</span></sup>
244 <br />
245 <input type="radio" name="restriction" value="none" <? if($restriction == 'none' || $restriction == '') print ' checked'; ?>>←→<br />
246 <input type="radio" name="restriction" value="LR" <? if($restriction == 'LR') print ' checked'; ?>>→→<br />
247 <input type="radio" name="restriction" value="RL" <? if($restriction == 'RL') print ' checked'; ?>>←←
249 <input type="submit" name="clear_box" value="<? print _('Clear'); ?>">
250 <input type="submit" name="preview_box" value="<? print _('Preview'); ?>">
251 <input type="submit" name="commit_box" value="<? print _('Commit'); ?>">
252 </p>
255 if($previewing == "on") {
256 $pair = $config->get_pair($current_pair);
258 $dictionary = $pair->dictionary('bilingual');
263 </p>
264 </div>
265 <!-- Right side -->
266 <div id="right">
268 $pair = $config->get_pair($current_pair);
269 $dictionary = $pair->dictionary('right');
271 print $dictionary->language . ' <br /><small>(';
272 print $dictionary->file . ' )</small>';
275 Lemma:<sup>&nbsp;</sup><input type="text" name="right_lemma" value="<? print $right_lemma; ?>" <? if($right_lemma_exists == "true") { print 'id="known_word"'; } ?>>
276 <? if($right_lemma_exists == "true") { print "Known lemma"; } ?>
277 </p>
279 Paradigm:<sup>&nbsp;</sup><select name="right_paradigm">
281 $pair = $config->get_pair($current_pair);
282 $dictionary = $pair->dictionary('right');
283 $paradigms = $dictionary->paradigms($current_tag);
284 $display_mode = $dictionary->get_display_mode($current_tag);
286 foreach($paradigms as $paradigm) {
287 // if we're in "list mode and there is no gloss for this
288 // paradigm, don't display it
289 if($display_mode == "list" && $glosses[$paradigm->name] == "") {
290 continue;
292 print '<option value="' . $paradigm->name . '"';
293 if($paradigm->name == $right_paradigm) {
294 print ' selected';
296 print '>' . $paradigm->name . '</option>'. "\n";
299 </select>
300 </p>
302 <? print _('Comment'); ?>:
303 <input type="text" name="right_comment" value="<? print $right_comment; ?>" />
304 </p>
307 if($previewing == 'on') {
308 $pair = $config->get_pair($current_pair);
309 $dictionary = $pair->dictionary('right');
311 $par = $dictionary->get_paradigm($right_paradigm, $current_tag);
312 $stems = $par->stems();
313 $show_stems = $pair->shows($current_tag);
314 $templates = $pair->templates("r");
316 foreach(array_keys($stems) as $stem) {
317 if(sizeof($show_stems) > 1) {
318 foreach($show_stems as $show) {
319 if($show == $stems[$stem][0]) {
320 print $dictionary->incondicional($right_lemma, $right_paradigm) . $stem . '<br />';
321 print '<span id="symbol_list">' . $stems[$stem][0] . '</span>';
322 print '<br/>';
325 } else {
326 print $dictionary->incondicional($right_lemma, $right_paradigm) . $stem . '<br />';
327 print '<span id="symbol_list">' . $stems[$stem][0] . '</span>';
328 print '<br/>';
331 if(sizeof($templates) > 0) {
332 foreach(array_keys($templates) as $tmpl_tag) {
333 if(strstr($stems[$stem][0], $tmpl_tag)) {
334 $template = $templates[$tmpl_tag];
337 } else {
338 $template = "none";
342 $dictionary = $pair->dictionary('right');
343 $right_entrada = $dictionary->generate_monodix_entrada($right_lemma, $right_paradigm, $right_comment, "webform");
345 print '<p>';
346 print '<span id="monodix_entrada"><pre>';
347 print str_replace('>', '&gt;', str_replace('<', '&lt;', $right_entrada));
348 print '</pre></span>';
351 </p>
352 </div>
353 </div>
354 <div>
356 $pair = $config->get_pair($current_pair);
357 $dictionary = $pair->dictionary('bilingual');
359 if($template != "none") {
360 $bidix_entrada = $dictionary->generate_bidix_entrada_from_template($pair->template_dir(), $template, $left_lemma, $right_lemma, "", "webform");
361 print '<span id="bidix_entrada"><pre>';
362 $bidix_entrada = str_replace('><', '>\n<', str_replace('>', '&gt;', str_replace('<', '&lt;', $bidix_entrada)));
363 $bidix_entrada = str_replace("&lt;/e&gt;\n", "&lt;/e&gt;<br />", $bidix_entrada);
364 print $bidix_entrada;
365 print '</pre></span>';
366 } else {
367 $bidix_entrada = $dictionary->generate_bidix_entrada($left_lemma, $right_lemma, $current_tag, $restriction, "", "webform");
368 print '<span id="bidix_entrada"><pre>';
369 print str_replace('><', '>\n<', str_replace('>', '&gt;', str_replace('<', '&lt;', $bidix_entrada)));
370 print '</span></pre>';
373 print '<input type="hidden" name="selected_template" value="' . $template . '">';
375 </div>
376 <div width="100%">
379 if($committing == "on") {
380 $pair = $config->get_pair($current_pair);
382 $dictionary = $pair->dictionary('left');
383 $left_entrada = $dictionary->generate_monodix_entrada($left_lemma, $left_paradigm, $left_comment, "webform");
385 $dictionary = $pair->dictionary('bilingual');
386 if($template != "none") {
387 $bidix_entrada = $dictionary->generate_bidix_entrada_from_template($pair->template_dir(), $template, $left_lemma, $right_lemma, "", "webform");
388 } else {
389 $bidix_entrada = $dictionary->generate_bidix_entrada($left_lemma, $right_lemma, $current_tag, $restriction, "", "webform");
392 $dictionary = $pair->dictionary('right');
393 $right_entrada = $dictionary->generate_monodix_entrada($right_lemma, $right_paradigm, $right_comment, "webform");
395 print '<span id="monodix_entrada">';
396 print str_replace('>', '&gt;', str_replace('<', '&lt;', $left_entrada));
397 print '</span>';
398 print '<p>';
399 print '<span id="bidix_entrada">';
400 print str_replace('>', '&gt;', str_replace('<', '&lt;', $bidix_entrada));
401 print '</span>';
402 print '<p>';
403 print '<span id="monodix_entrada">';
404 print str_replace('>', '&gt;', str_replace('<', '&lt;', $right_entrada));
405 print '</span>';
407 $pair->commit($left_entrada, $bidix_entrada, $right_entrada);
410 </div>
411 </div>
412 </form>
413 </body>
414 </html>