-
Notifications
You must be signed in to change notification settings - Fork 0
/
vocabulary.php
127 lines (101 loc) · 3.65 KB
/
vocabulary.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
<?php
/*
This file is part of verb-o-matic. Copyright 2008 Luzius Thöny.
verb-o-matic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
verb-o-matic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with verb-o-matic. If not, see <http://www.gnu.org/licenses/>.
*/
session_start();
header('Content-Type: text/html; charset=utf-8');
$loadData=$_GET["loadData"];
$dataDir=$_GET["dir"];
$exerciseName = $_SESSION["exerciseName"];
$data = $_SESSION["data"];
$currentLemma = $_SESSION["currentLemma"];
//set things up
if ($loadData != "") {
$data = array();
$fileArray = file($dataDir . "/" . $loadData . ".txt");
foreach ($fileArray as &$line) {
$chunks = explode(" ", $line);
$lemma = trim($chunks[0]);
$goldSolutionsArray = explode(",", $chunks[1]);
$goldSolutions = array();
foreach ($goldSolutionsArray as &$goldSolution) {
$goldSolutions[] = str_replace("## ", ", ", trim($goldSolution));
}
$otherInfo = "";
if (count($chunks) == 3) $otherInfo = trim($chunks[2]);
$data[$lemma] = array($goldSolutions, 0, $otherInfo);
}
if (gettype($data) != 'array') $data = array($data);
selectEntry();
$_SESSION["totalLemmas"] = count($data);
$_SESSION["tries"] = 0;
$_SESSION["exerciseName"] = $loadData;
$exerciseName = $loadData;
} else {
selectEntry();
}
function selectEntry() {
global $currentLemma, $data;
$done = 0;
while ($done==0) {
if (gettype($data) != 'array') $data = array($data);
$randomLemma = array_rand($data);
if (($currentLemma != $randomLemma) || count($data==1)) { // never show the same lemma twice, except if it's the last one
$currentLemma = $randomLemma;
$done = 1;
}
}
}
// find out if we should show a comma warning
$commaWarning = 0;
$goldSolutions = $data[$currentLemma][0];
//if (gettype($goldSolutions) !== 'array') $goldSolutions = array($goldSolutions);
if (is_array($goldSolutions)) {
foreach($goldSolutions as &$goldSolution) {
if (strpos($goldSolution, ",") !== false) {
$commaWarning = 1;
}
}
}
$_SESSION["data"] = $data;
$_SESSION["currentLemma"] = $currentLemma;
?>
<?php include 'header.php';?>
<?php
?>
<form id="vForm" method="GET" action="vocabulary_feedback.php?<?=SID?>">
<table id="twoColTable" border="0">
<tr>
<td class="twoColTableLeft">
<h3>translate!</h3>
<span class="exercise"><?=$exerciseName?></span>
<div class="counters">words left: <?=count($data)?> - status: <?=$data[$currentLemma][1]?></div>
<div id="wordForm"> <?=$currentLemma?> </div>
</td>
<td class="twoColTableRight"> 
</td>
</tr>
<tr>
<td class="twoColTableLeft"> 
</td>
<td class="twoColTableRight">
<div class="vocabularyInput" id="vocabularyInput">
<input type="text" id="vocabularyInputButton" size="24" style="width:280px" name="solutions" value="">
<?php if ($commaWarning == 1) echo "<div class=\"note\">NOTE: The solution to this word seems to contain a comma. Since the comma is also used to seperate between multiple solutions, you need to wrap any single solution containing a comma in double quotes, like this: <span class=\"sample\">that, \"that, which\"</span></div>"; ?>
</div>
</td>
</tr>
</table>
<div id="submitButton" style="padding:1em;"><input type="submit" style="width:10em" value="OK"></div>
</form>
<?php include 'footer.php';?>