1
|
<?
|
2
|
Header("Pragma: no-cache");
|
3
|
Header("Cache-Control: no-cache");
|
4
|
Header("Expires: ".GMDate("D, d M Y H:i:s")." GMT");
|
5
|
?>
|
6
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
7
|
|
8
|
<html>
|
9
|
<head>
|
10
|
<title>Update tabulky OBTEXTS</title>
|
11
|
</head>
|
12
|
|
13
|
<body bgcolor="Silver">
|
14
|
<CENTER><H2>Update tabulky OBTEXTS</H2></CENTER>
|
15
|
<?
|
16
|
|
17
|
|
18
|
function chyba()
|
19
|
{
|
20
|
global $radek;
|
21
|
|
22
|
printf("\n<BR>Pri zpracovani radku %s se vyskytla chyba!!!!!\n<BR>",$radek);
|
23
|
echo "</body></html>";
|
24
|
exit();
|
25
|
}
|
26
|
|
27
|
function zpracuj_heslo()
|
28
|
{
|
29
|
global $heslo;
|
30
|
global $pocet_hesel;
|
31
|
global $slovnik;
|
32
|
global $radek2;
|
33
|
|
34
|
$pocet_hesel++;
|
35
|
|
36
|
$heslo2=" ";
|
37
|
$ignoruj=Array("[","]","⌈","⌉","<D:>","<B:>" ); //slova pro ignorovani
|
38
|
// printf("\n<BR>Puvodni heslo je : %s",$heslo);
|
39
|
|
40
|
$heslo2.=$heslo;
|
41
|
for ($k=0;$k<Count($ignoruj);$k++):
|
42
|
$delka2=strlen($heslo2);
|
43
|
$pomocny="";
|
44
|
// echo "<BR> Hledam: ".$ignoruj[$k];
|
45
|
|
46
|
if ($pos=StrPos($heslo2,$ignoruj[$k]))
|
47
|
{
|
48
|
// echo " nalezeno na pozici: ".$pos;
|
49
|
$t=strlen($ignoruj[$k]);
|
50
|
if ($pos==0)
|
51
|
{
|
52
|
for ($t;$t<=$delka2;$t++) { $pomocny.=$heslo2[$t];}
|
53
|
}
|
54
|
else
|
55
|
{
|
56
|
for ($s=0;$s<$pos;$s++) { $pomocny.=$heslo2[$s];}
|
57
|
for ($pos+$t;$pos+$t<$delka2;$pos++) {$pomocny.=$heslo2[$pos+$t];}
|
58
|
}
|
59
|
$heslo2=$pomocny;
|
60
|
$k--;
|
61
|
}
|
62
|
// else echo " Nenalezeno";
|
63
|
endfor;
|
64
|
|
65
|
// printf("\n<BR>Upravene heslo je : %s ",$heslo2);
|
66
|
// echo "<BR>Hledam v : ".$slovnik[$heslo2];
|
67
|
|
68
|
$radek2.=" ";
|
69
|
if (IsSet($slovnik[$heslo2]))
|
70
|
{
|
71
|
$radek2.=odkaz1;
|
72
|
$pokus = ($slovnik[$heslo2][1]);
|
73
|
|
74
|
|
75
|
$pokus = rtrim($pokus);
|
76
|
$pokus = urlencode($pokus);
|
77
|
$radek2.=$pokus;
|
78
|
$radek2.=odkaz2;
|
79
|
$radek2.=$heslo;
|
80
|
$radek2.=odkaz3;
|
81
|
|
82
|
reset($slovnik[$heslo2]);
|
83
|
while (next($slovnik[$heslo2]))
|
84
|
{
|
85
|
$radek2.=" ";
|
86
|
$radek2.=odkaz1;
|
87
|
$radek2.=current($slovnik[$heslo2]);
|
88
|
$radek2.=odkaz2;
|
89
|
$radek2.=odkaz4;
|
90
|
$radek2.=key($slovnik[$heslo2]);
|
91
|
$radek2.=odkaz5;
|
92
|
$radek2.=odkaz3;
|
93
|
}
|
94
|
|
95
|
// printf ("\n<BR><FONT color=\"Green\">Nalezeno!<HR></FONT>");
|
96
|
}
|
97
|
else
|
98
|
{
|
99
|
$radek2.=$heslo;
|
100
|
// printf ("\n<BR><FONT color=\"Red\" >Nenalezeno!<HR></FONT>");
|
101
|
}
|
102
|
|
103
|
$heslo="";
|
104
|
$heslo2="";
|
105
|
return;
|
106
|
}
|
107
|
|
108
|
|
109
|
|
110
|
function zpracuj_radek()
|
111
|
{
|
112
|
global $radek;
|
113
|
global $heslo;
|
114
|
|
115
|
$i=0;
|
116
|
$d=strlen($radek);
|
117
|
$stav=0;
|
118
|
|
119
|
while ($i<$d)
|
120
|
{
|
121
|
$c=$radek[$i];
|
122
|
$i++;
|
123
|
switch($stav)
|
124
|
{
|
125
|
case 0: if($c=='<') {$stav=1;break;}
|
126
|
if($c==' ') break;
|
127
|
else {$stav=9;$heslo.=$c;$j=1;break;}
|
128
|
|
129
|
case 1: if(($c=='a')||($c=='A')) {$stav=2;}
|
130
|
else chyba();
|
131
|
break;
|
132
|
|
133
|
case 2: if($c=='>') {$stav=3;}
|
134
|
break;
|
135
|
|
136
|
case 3: if($c=='<') {$stav=4;}
|
137
|
else {$heslo.=$c;}
|
138
|
break;
|
139
|
|
140
|
case 4: if (($c=='b')||($c=='B')) {$stav=5;break;}
|
141
|
if ($c=='/'){$stav=7;zpracuj_heslo();}
|
142
|
else chyba();
|
143
|
break;
|
144
|
|
145
|
case 5: if((($c=='a')||($c=='A'))&&($radek[$i-2]=='/')) $stav=6;
|
146
|
break;
|
147
|
|
148
|
case 6: if ($c=='>') {$stav=0;}
|
149
|
else chyba();
|
150
|
break;
|
151
|
|
152
|
case 7: if(($c=='a')||($c=='A')) $stav=8;
|
153
|
else chyba();
|
154
|
break;
|
155
|
|
156
|
case 8: if($c=='>') {$stav=0;}
|
157
|
else chyba();
|
158
|
break;
|
159
|
|
160
|
case 9: if ($c==' ') {zpracuj_heslo(); $stav=0;}
|
161
|
else {$heslo.=$c;}
|
162
|
break;
|
163
|
|
164
|
default: break;
|
165
|
}
|
166
|
}
|
167
|
|
168
|
if ($stav==9) {zpracuj_heslo();}
|
169
|
if (($stav==9)||($stav==0)) /*printf("\n<BR>Probehlo to OK!")*/;
|
170
|
else chyba();
|
171
|
|
172
|
return;
|
173
|
}
|
174
|
|
175
|
|
176
|
static $heslo ="";
|
177
|
static $heslo2 ="";
|
178
|
static $radek ="";
|
179
|
static $radek2 ="";
|
180
|
static $pocet_hesel=0;
|
181
|
static $pocet_zmen=0;
|
182
|
static $slovnik=array();
|
183
|
static $pocc=0;
|
184
|
static $duplicity=0;
|
185
|
static $odstraneno=0;
|
186
|
|
187
|
define("odkaz1","<A HREF=\"http://www.klinopis.cz/utf/s.php?chain=");
|
188
|
define("odkaz2","\">");
|
189
|
define("odkaz3","</A>");
|
190
|
define("odkaz4","<b><SUP>");
|
191
|
define("odkaz5","</SUP></b>");
|
192
|
|
193
|
@$spojeni = Pg_Connect("user=dbowner dbname=klinopis");
|
194
|
if (!$spojeni):
|
195
|
echo "Nepodarilo se pripojit k PostgreSQL.<BR>\n";
|
196
|
die ("</body></html>");
|
197
|
endif;
|
198
|
|
199
|
@$vysledek = Pg_Exec($spojeni, "SELECT item1,refer1 FROM dictrefer order by item1,refer1");
|
200
|
if (!$vysledek):
|
201
|
echo "Doslo k chybe pri zpracovani dotazu v databazi slovicek.<BR>\n";
|
202
|
die ("</body></html>");
|
203
|
endif;
|
204
|
echo "V tabulce dictrefer je <FONT color=\"Green\"><b>".Pg_NumRows($vysledek)."</b> </FONT>slovicek.<BR>\n";
|
205
|
|
206
|
for ($m=0; $m < Pg_NumRows($vysledek); $m++):
|
207
|
$existuje=0;
|
208
|
$pocc++;
|
209
|
|
210
|
$zaznam = Pg_Fetch_Array($vysledek, $m);
|
211
|
// echo "Zaznam c.".$pocc." ".$zaznam["item1"]." ".$zaznam["refer1"]."<BR>";
|
212
|
|
213
|
if (IsSet($slovnik[$zaznam["refer1"]]))
|
214
|
{
|
215
|
end ($slovnik[$zaznam["refer1"]]);
|
216
|
$d=key($slovnik[$zaznam["refer1"]]);
|
217
|
|
218
|
for ($uk=1;$uk<=$d;$uk++)
|
219
|
{
|
220
|
if (strcmp($slovnik[$zaznam["refer1"]][$uk],$zaznam["item1"])==0)
|
221
|
{
|
222
|
$duplicity++;
|
223
|
$existuje=1;
|
224
|
echo " <FONT color=\"red\"><b>Tento odkaz jiz existuje !</b></FONT><BR><BR>\n";
|
225
|
$item1_pom=$zaznam["item1"];
|
226
|
$refer1_pom=$zaznam["refer1"];
|
227
|
|
228
|
$vysledek_del = Pg_Exec($spojeni,"Delete FROM dictrefer where item1='$item1_pom' and refer1='$refer1_pom'");
|
229
|
if (!$vysledek_del) echo " <FONT color=\"red\"><b>Doslo k chybe pri DELETE v tabulce DICTREFER!</b></FONT><BR><BR>\n";
|
230
|
else
|
231
|
{
|
232
|
$vysledek_vloz = Pg_Exec($spojeni,"insert into dictrefer(item1,refer1) VALUES ('$item1_pom','$refer1_pom')");
|
233
|
if (!$vysledek_vloz):
|
234
|
echo " <FONT color=\"red\"><b>Doslo k chybe pri INSERT do tabulky DICTREFER!</b></FONT><BR><BR>\n";
|
235
|
endif;
|
236
|
}
|
237
|
if (($vysledek_vloz)&&($vysledek_vloz))
|
238
|
{
|
239
|
$odstraneno+=1;
|
240
|
echo " <FONT color=\"green\"><b>Duplicita odstranena!</b></FONT><BR><BR>\n";
|
241
|
}
|
242
|
break;
|
243
|
}
|
244
|
}
|
245
|
|
246
|
|
247
|
$d+=1;
|
248
|
}
|
249
|
else $d=1;
|
250
|
if ($existuje==0) $slovnik[$zaznam["refer1"]][$d]=$zaznam["item1"];
|
251
|
|
252
|
endfor;
|
253
|
|
254
|
if ($duplicity==0)
|
255
|
printf("\n<BR><FONT color=\"green\"><b>V tabulce dictrefer nenalezeny zadne duplicity.</b></FONT><BR><HR>");
|
256
|
else
|
257
|
{
|
258
|
printf("\n<BR><FONT color=\"red\"><b>V tabulce dictrefer nalezeno %d duplicit!!!</b></FONT><BR>",$duplicity);
|
259
|
printf("<FONT color=\"green\"><b>Uspesne odstraneno %d duplicit!!!</b></FONT><BR><HR>",$odstraneno);
|
260
|
}
|
261
|
|
262
|
|
263
|
// Vypis slovniku0
|
264
|
/*
|
265
|
$pocc=0;
|
266
|
reset ($slovnik);
|
267
|
do
|
268
|
{
|
269
|
$ukazatel=key($slovnik);
|
270
|
reset ($slovnik[$ukazatel]);
|
271
|
echo "<HR><BR>".$ukazatel."<BR>";
|
272
|
do
|
273
|
{
|
274
|
$pocc++;
|
275
|
echo "Slovicko c.".$pocc."\n<BR>";
|
276
|
echo key($slovnik[$ukazatel])."\n<BR>";
|
277
|
echo current($slovnik[$ukazatel])."\n<BR>";
|
278
|
}while (next($slovnik[$ukazatel]));
|
279
|
|
280
|
}while (next($slovnik));
|
281
|
|
282
|
*/
|
283
|
|
284
|
@$vysledek = Pg_Exec($spojeni, "SELECT * FROM obtexts");
|
285
|
if (!$vysledek):
|
286
|
echo "Doslo k chybe pri zpracovani dotazu v databazi.<BR>\n";
|
287
|
die ("</body></html>");
|
288
|
endif;
|
289
|
echo "<HR>\n<BR>V tabulce obtexts je <FONT color=\"Green\"><b>".Pg_NumRows($vysledek)."</b></FONT> radku.<BR>\n";
|
290
|
|
291
|
for ($m=0; $m < Pg_NumRows($vysledek); $m++):
|
292
|
$zaznam = Pg_Fetch_Array($vysledek, $m);
|
293
|
// echo $zaznam["bookandchapter"]." ".$zaznam["paragraph"]." ".$zaznam["transliteration"]."<BR>\n";
|
294
|
$radek=$zaznam["transliteration"];
|
295
|
$radek2="";
|
296
|
echo "<BR>Radek s oznacenim : ".$zaznam["bookandchapter"]." ".$zaznam["paragraph"]."<BR>".$radek;
|
297
|
zpracuj_radek();
|
298
|
$radek2.=" ";
|
299
|
if(strcmp($radek,$radek2)==0)
|
300
|
{
|
301
|
echo "<BR>Radek s oznacenim : ".$zaznam["bookandchapter"]." ".$zaznam["paragraph"]."<BR>".$radek;
|
302
|
}
|
303
|
else
|
304
|
{
|
305
|
$pocet_zmen++;
|
306
|
echo "<b><FONT color=\"Red\" >Zmena!</FONT></b>";
|
307
|
echo "<BR>Opraveny radek: <BR><FONT FACE=\"Arial Unicode MS, TITUS Cyberbit Basic, Code2000\" color=#2288ff>".$radek2;
|
308
|
echo "</FONT>";
|
309
|
// echo $zaznam["bookandchapter"]; #3399ff
|
310
|
$bookandchapter = $zaznam["bookandchapter"];
|
311
|
$paragraph = $zaznam["paragraph"];
|
312
|
$podminka = "(bookandchapter = '$bookandchapter' AND paragraph = '$paragraph')";
|
313
|
|
314
|
$vysledek2 = Pg_Exec($spojeni,"UPDATE obtexts SET transliteration = '$radek2' WHERE $podminka");
|
315
|
if (!$vysledek2){
|
316
|
echo "Doslo k chybe pri updatu databaze.<BR>\n";
|
317
|
die ("</body></html>");
|
318
|
}
|
319
|
else
|
320
|
{
|
321
|
echo "<BR>Ulozen!!!";
|
322
|
}
|
323
|
|
324
|
}
|
325
|
echo "<HR>";
|
326
|
endfor;
|
327
|
|
328
|
echo "\n<BR>Text obsahuje <FONT color=\"Green\"><b>".$pocet_hesel."</b></FONT> hesel. <BR>";
|
329
|
echo "\n<BR>Bylo zmeneno <FONT color=\"Green\"><b>".$pocet_zmen."</b></FONT> radku. <BR>";
|
330
|
|
331
|
?>
|
332
|
</body>
|
333
|
</html>
|