Projekt

Obecné

Profil

Stáhnout (12.9 KB) Statistiky
| Větev: | Tag: | Revize:
1 6daefa8c Petr Lukašík
<?php
2
require_once("./functions/dictionary.php");
3
4
function get_pocet_slov_ve_zkouseni($examing) {
5
  require_once("./classes/db.php");
6
  $spojeni = new DB_Sql();
7
  //vybereme exam
8
  $dotaz = "SELECT count FROM examing
9
              WHERE \"IDexaming\" = '$examing'";
10
  $spojeni->query($dotaz);
11
  $spojeni->next_record();
12
  return $spojeni->Record["count"];
13
}
14
15
function get_pocet_spatnych_slov($examing) {
16
  require_once("./classes/db.php");
17
  $spojeni = new DB_Sql();
18
  //vybereme exam
19
  $dotaz = "SELECT status FROM exam
20
              WHERE examing = '$examing'
21
              AND status = 0";
22
  $spojeni->query($dotaz);
23
  return $spojeni->num_rows();
24
}
25
26
function insert_new_examing($user, $source, $lection, $count, $type, $learning) {
27
  require_once("./classes/db.php");
28
  $spojeni = new DB_Sql();
29
30
  $dotaz = "INSERT INTO examing (\"user\", date, rating, source, count, type, lection, learning)
31
            VALUES ('$user', 'NOW', -1, '$source', '$count', '$type', '$lection', '$learning')";
32
  $spojeni->query($dotaz);
33
  if ($spojeni->Errno != 0) {
34
    print_hlasku(lang("Chyba při vytváření zkoušení."));
35
    return NULL;
36
  }
37
  $dotaz = "SELECT currval('examing_id_seq')";
38
  $spojeni->query($dotaz);
39
40
  if ($spojeni->Errno != 0) {
41
    print_hlasku(lang("Chyba při vytváření zkoušení."));
42
    return NULL;
43
  }
44
  $spojeni->next_record();
45
  return $spojeni->Record["currval"];
46
}
47
48
function words_to_repeat($source, $lection, $user) {
49
  require_once("./classes/db.php");
50
  $spojeni = new DB_Sql();
51
  $dotaz = "SELECT *
52
            FROM exam e, examing ex
53
            WHERE e.examing = ex.\"IDexaming\"
54
              AND ex.source = '$source'
55
              AND ex.\"user\" = '$user'
56
              AND ex.lection = '$lection'
57
              AND e.status = 0";
58
  $spojeni->query($dotaz);
59
  if ($spojeni->Errno != 0) {
60
    print_hlasku(lang("Chyba při vytváření zkoušení."));
61
    return NULL;
62
  }
63
  return $spojeni;
64
}
65
66
function create_examing($user, $source, $lection, $count, $type, $learning) {
67
  require_once("./classes/db.php");
68
  $spojeni = new DB_Sql();
69
  //vytvori novou polozku v tabulce examing
70
  $new_examing = insert_new_examing($user, $source, $lection, $count, $type, $learning);
71
72
  //zjisti moznosti opetovneho zkouseni
73
  $spojeni_k_opakovani = words_to_repeat($source, $lection, $user);
74
  $pocet_k_opakovani = $spojeni_k_opakovani->num_rows();
75
76
  if ($pocet_k_opakovani == $count) {
77
    while ($spojeni_k_opakovani->next_record()) {
78
      $dotaz = "UPDATE exam
79
                SET examing = $new_examing,
80
                    status = NULL
81
                WHERE \"IDexam\" = ".$spojeni_k_opakovani->Record["IDexam"];
82
      $spojeni->query($dotaz);
83
    }
84
  }
85
  else if($pocet_k_opakovani > $count) {
86
    for ($i = 0 ; $i < $count ;$i++) {
87
      $spojeni_k_opakovani->next_record();
88
      $dotaz = "UPDATE exam
89
                SET examing = $new_examing,
90
                    status = NULL
91
                WHERE \"IDexam\" = ".$spojeni_k_opakovani->Record["IDexam"];
92
      $spojeni->query($dotaz);
93
    }
94
    while ($spojeni_k_opakovani->next_record()) {
95
      $dotaz = "DELETE FROM exam
96
                WHERE \"IDexam\" = ".$spojeni_k_opakovani->Record["IDexam"];
97
      $spojeni->query($dotaz);
98
    }
99
  }
100
  else { //if ($pocet_k_opakovani < $count)
101
    $pomoc = "";
102
    while ($spojeni_k_opakovani->next_record()) {
103
      $dotaz = "UPDATE exam
104
                SET examing = $new_examing,
105
                    status = NULL
106
                WHERE \"IDexam\" = ".$spojeni_k_opakovani->Record["IDexam"];
107
      $spojeni->query($dotaz);
108
      //tohle se pouzije az dale
109
      $pomoc .= " AND NOT \"IDdict\" = ".$spojeni_k_opakovani->Record["dict"];
110
    }
111
    $dotaz = "SELECT *
112
              FROM dict
113
              WHERE source = '$source' AND
114
                    lection = '$lection'";
115
    $dotaz .= $pomoc;
116
    $dotaz .= " ORDER BY random()
117
                LIMIT ".($count-$pocet_k_opakovani);
118
    $spojeni->query($dotaz);
119
    if ($spojeni->Errno != 0) {
120
      print_hlasku(lang("Chyba při vytváření zkoušení."));
121
      return NULL;
122
    }
123
    $spojeni_na_vkladani = new DB_Sql();
124
125
    while ($spojeni->next_record()) {
126
      //echo($spojeni->Record["czech"] . "<br />\n");
127
      $dotaz = "INSERT INTO exam (examing, status, dict)
128
                       VALUES ('$new_examing', NULL, ".$spojeni->Record["IDdict"].")";
129
      $spojeni_na_vkladani->query($dotaz);
130
      if ($spojeni_na_vkladani->Errno != 0) {
131
        print_hlasku(lang("Chyba při vytváření zkoušení."));
132
        return NULL;
133
      }
134
    }
135
  }
136
  return $new_examing;
137
}
138
139
function get_exam_word($examing, $step) {
140
  require_once("./classes/db.php");
141
  $spojeni = new DB_Sql();
142
  //vybereme exam
143
  $dotaz = "SELECT e.\"IDexam\", d.* FROM exam e, dict d
144
              WHERE e.examing = '$examing'
145
              	AND e.status is NULL
146
              	AND e.dict = d.\"IDdict\"
147
              ORDER BY random()
148
              LIMIT 1";
149
  $spojeni->query($dotaz);
150
  if ($spojeni->Errno != 0) {
151
    print_hlasku(lang("Chyba při zkoušení."));
152
    return NULL;
153
  }
154
  if ($spojeni->num_rows() == 0) {
155
    return NULL;
156
  }
157
158
  $spojeni->next_record();
159
  return $spojeni->Record;
160
}
161
162
function exam_word($IDdict, $IDexam, $type, $to) {
163
  require_once("./classes/db.php");
164
  
165
  
166
  
167
  $spojeni = new DB_Sql();
168
  $dotaz = "SELECT * FROM dict
169
            WHERE \"IDdict\" = '$IDdict'";
170
171
  if(empty($to)) {
172
    $dotaz .= " AND 1 = 0 ";
173
  }
174
  switch ($type) {
175
    case ("to_cz"):
176
    	$word = mb_strtolower($to, "UTF-8");
177
        $word = get_token_regexp($word); 
178
      $dotaz .= " AND lower(czech) ~ ('$word')";
179
    break;
180
    case("to_en"):
181
    	$word = mb_strtolower($to, "UTF-8");
182
        $word = get_token_regexp($word);
183
      $dotaz .= " AND lower(english) = ('$word')";
184
    break;
185
    case("from_cz"):
186
    case("from_en"):
187
      $to = hebrew_add_vowel($to);
188
      $to = get_token_regexp($to);
189
      /*
190
      SELECT * FROM dict
191
            WHERE language = $language AND
192
                  ((present ~ ('$word')) OR
193
                   (past    ~ ('$word')) OR
194
                   (valence ~ ('$word')))
195
                   */
196
      $dotaz .= " AND ((present ~ ('$to')) OR
197
                   (past    ~ ('$to')) OR
198
                   (valence ~ ('$to')))";
199
    break;
200
    default:
201
      echo lang("Chyba");
202
  }
203
  //echo $dotaz;
204
  $spojeni->query($dotaz);
205
  if ($spojeni->num_rows() == 0) {
206
    //echo "nic";
207
    set_exam_status($IDexam, 0);
208
    require_once("./administration/word.php");
209
    return get_word($IDdict);
210
  }
211
  else {
212
    //echo "neco";
213
  	set_exam_status($IDexam, 1);
214
  	$spojeni->next_record();
215
    return NULL;
216
217
  }
218
}
219
220
function set_exam_status($IDexam, $status) {
221
222
  require_once("./classes/db.php");
223
  $spojeni = new DB_Sql();
224
  $dotaz = "UPDATE exam SET status = $status WHERE \"IDexam\" = '$IDexam'";
225
  $spojeni->query($dotaz);
226
  if ($spojeni->Errno != 0) {
227
    print_hlasku(lang("Chyba při zkoušení."));
228
  }
229
}
230
231
function uklid($examing, $rating) {
232
  require_once("./classes/db.php");
233
  $spojeni = new DB_Sql();
234
  $dotaz = "DELETE FROM exam WHERE examing = '$examing'
235
                             AND status = 1";
236
  $spojeni->query($dotaz);
237
  if ($spojeni->Errno != 0) {
238
    print_hlasku(lang("Chyba při zkoušení."));
239
  }
240
  $dotaz = "UPDATE examing SET rating = $rating WHERE \"IDexaming\" = '$examing'";
241
  $spojeni->query($dotaz);
242
}
243
244
function delete_exam($IDexam) {
245
  require_once("./classes/db.php");
246
  $spojeni = new DB_Sql();
247
  $dotaz = "DELETE FROM exam WHERE \"IDexam\" = '$IDexam'";
248
  $spojeni->query($dotaz);
249
  if ($spojeni->Errno != 0) {
250
    print_hlasku(lang("Chyba při zkoušení."));
251
  }
252
}
253
254
function get_typ($identifikator) {
255
  switch ($identifikator) {
256
    case("from_cz"):
257
      return lang("Z Čestiny");
258
    break;
259
    case("to_cz"):
260
      return lang("Do Češtiny");
261
    break;
262
    case("from_en"):
263
      return lang("Z Angličtiny");
264
    break;
265
    case("to_en"):
266
      return lang("Do Angličtiny");
267
    break;
268
    default:
269
      return lang("Špatný formát");
270
  }
271
}
272
273
/**
274
 *  Pomocna funkce, vraci do tabulky zformatovane slovo
275
 *
276
 *  @param $Record polozka slovniku nactena z db
277
 *  @return do tabulky zformatovany zaznam
278
 */
279
function get_row_of_table_examing($learning, $Record) {
280
  $navrat .= "<tr class=\"akt\">\n     ";
281
  $navrat .= '<td>'.$Record["date"].'</td>';
282
  $pomoc = ($learning == 'TRUE')? 'learning' : 'exam';
283
  if ($Record["rating"] == -1)
284
    $navrat .= '<td>'.lang("Nebylo dokončeno").' <br /><a href="?nav_id=do_'.$pomoc.'&examing='.$Record["IDexaming"].
285
               '&type='.$Record["type"].'">'.lang("dokončit").'</a></td>';
286
  else
287
    $navrat .= '<td>'.$Record["rating"].'</td>';
288
  $navrat .= '<td>'.$Record["title"].'</td><td>'.$Record["lection"].'</td>';
289
  $navrat .= '<td>'.$Record["count"].'</td>';
290
  $navrat .= '<td>'.get_typ($Record["type"]).'</td>';
291
  $navrat .= "</tr> \n  ";
292
  return $navrat;
293
}
294
295
296
function get_pocet_zkouseni() {
297
  global $ses_IDuser;
298
  require_once("./classes/db.php");
299
  $spojeni = new DB_Sql();
300
  $dotaz = "SELECT \"IDexaming\" FROM examing WHERE \"user\" = $ses_IDuser";
301
  $spojeni->query($dotaz);
302
  return $spojeni->num_rows();
303
}
304
305
function get_razeni_of_table_examing($l_order = "IDexaming", $l_od = 0, $l_limit = 30) {
306
  global $order;
307
  global $od;
308
  global $limit;
309
310
  global $nav_id;
311
312
  $order = $l_order;
313
  $od    = $l_od;
314
  $limit = $l_limit;
315
  $pocet_zdroju = get_pocet_zkouseni();
316
  $nav = $nav_id;
317
318
  $navrat = "<p class=\"akt\"></p>";
319
  $navrat .= "<table>
320
      <tr class=\"nadpis_sekce\"><td><form action\"\" method=\"post\" name=\"razeni\"> ".
321
      sprintf(lang("Zobrazeno %d zkoušení od %d.  (celkem %d)"), $limit, $od,$pocet_zdroju )."<br />
322
       ".lang("Řadit podle")."
323
       <select name=\"order\">
324
         <option value=\"IDexaming\">".lang("Identifikátor")."</option>
325
         <option value=\"date\">".lang("datum")."</option>
326
         <option value=\"rating\">".lang("úspěšnost")."</option>
327
         <option value=\"source\">".lang("zdroj")."</option>
328
         <option value=\"lection\">".lang("lekce")."</option>
329
         <option value=\"count\">".lang("počet")."</option>
330
       </select>
331
       ".lang("od:")." <input type=\"text\" name=\"od\" value=\"$od\" size=\"5\" />
332
       ".lang("počet:")." <input type=\"text\" name=\"limit\" value=\"$limit\" size=\"5\" />
333
       <input type=\"submit\" name=\"serad\" value=\"".lang("Zobraz")."\" /> </form>
334
       </td></tr>
335
       <tr class=\"nadpis_sekce\"><td align=\"center\">
336
        <a href=\"?nav_id=$nav&serad=true&order=$order&od=0&limit=$limit\">
337
            ".lang("Na začátek")." </a> |       ";
338
  if ($od-$limit >= 0)
339
    $navrat .="<a href=\"?nav_id=$nav&serad=true&order=$order&od=".
340
              ($od-$limit)."&limit=$limit\">
341
              ".lang("Předchozích")." $limit </a> |       ";
342
  if ($od+$limit < $pocet_zdroju)
343
    $navrat .="<a href=\"?nav_id=$nav&serad=true&order=$order&od=".
344
              ($od+$limit)."&limit=$limit\">
345
              ".lang("Dalších")." $limit </a> |   ";
346
  $navrat .="<a href=\"?nav_id=$nav&serad=true&order=$order&od=".
347
             (($pocet_zdroju-$limit < 0)? 0: $pocet_zdroju-$limit)."&limit=$limit\">
348
             ".lang("Na konec")." </a></td>
349
  ";
350
  $navrat .= "</td></tr></table>";
351
  return $navrat;
352
}
353
354
function get_header_of_table_examing() {
355
return "<tr class=\"nadpis_sekce\">
356
  <td>".lang("Datum")."</td>
357
  <td>".lang("Úspěšnost")." [%]</td>
358
  <td>".lang("Zdroj")."</td>
359
  <td>".lang("Lekce")."</td>
360
  <td>".lang("Počet slovíček")."</td>
361
  <td>".lang("Směr")."</td>
362
</tr>";
363
}
364
365
function get_foot_of_table_examing() {
366
  return '<tr class="nadpis_sekce"><td></td><td></td><td></td><td></td><td></td><td></td></tr>';
367
}
368
369
370
function print_table_of_examing($learning, $order = "IDexaming", $od = 0, $limit = 30) {
371
  global $ses_IDuser;
372
  require_once("./classes/db.php");
373
  $spojeni = new DB_Sql();
374
  $dotaz = "SELECT s.title, e.* FROM examing e";
375
  $dotaz .= " LEFT OUTER JOIN source s ON (e.source = s.\"IDsource\")";
376
  $dotaz .= " WHERE e.\"user\" = $ses_IDuser AND e.learning = $learning";
377
  $dotaz .= " ORDER BY \"$order\" OFFSET $od LIMIT $limit";
378
  $spojeni->query($dotaz);
379
  $navrat = "<h3 class=\"nadpis2\">".lang("Výpis zkoušení")."</h3>";
380
  $navrat .= get_razeni_of_table_examing($order, $od, $limit);
381
  $navrat .= "<table><form action=\"\" method=\"post\">";
382
  $navrat .= get_header_of_table_examing();
383
  while ($spojeni->next_record()) {
384
    $navrat .= get_row_of_table_examing($learning, $spojeni->Record);
385
  }
386
  $navrat .= get_foot_of_table_examing();
387
  $navrat .= '';
388
  $navrat .= "</form></table>";
389
  echo $navrat;
390
}
391
392
function get_vyslednou_hlasku($rating) {
393
  global $LaId;
394
  require_once("./classes/db.php");
395
  $spojeni = new DB_Sql();
396
  $ratio = floor($rating / 10);
397
  $ratio = ($ratio == 0) ? $ratio+1 : $ratio;
398
  //echo($ratio);
399
  $dotaz = "SELECT ";
400
  $dotaz .= (($LaId == "cz")? "czech" : "english");
401
  $dotaz .= " FROM report WHERE ratio = $ratio";
402
  //echo $dotaz;
403
  $spojeni->query($dotaz);
404
  $spojeni->next_record();
405
  return $spojeni->Record[0];
406
}
407
 /*
408
409
 SELECT distinct ex.date,*
410
            FROM exam e, examing ex
411
            WHERE e.examing = ex."IDexaming"
412
              AND ex.source = 5
413
              AND ex.user = 2
414
              AND e.status = 0
415
416
 */
417
?>