source: trunk/Modules/Translation/Form.php@ 651

Last change on this file since 651 was 651, checked in by maron, 11 years ago
  • Modified: search names only at quest like text
File size: 13.1 KB
RevLine 
[43]1<?php
[49]2
[550]3class PageTranslationForm extends Page
4{
[633]5 var $GroupId;
6 var $ID;
[614]7 function ReplaceTranslated($orig,$tran,$Text,$ID,$Group) {
[633]8 $tran_replace = str_replace(' ','&nbsp;',htmlspecialchars($tran));
9 $orig_replace = str_replace(' ','&nbsp;',htmlspecialchars($orig));
[628]10
[633]11 // if (strlen($orig) < strlen($Text)-1) {
[629]12 if ($Group <> '') {
13 $Text = str_replace(' '.$orig,' <span Title="Přelož jako:&nbsp;'.$tran_replace.'" class="edit"><a class="edit" target="_NEW2" href="'.$this->System->Link('/form.php?group='.$Group.'&amp;ID='.$ID).'">'.$orig_replace.'</a></span>',$Text);
14 } else {
15 $Text = str_replace(' '.$orig,' <span Title="Přelož jako:&nbsp;'.$tran_replace.'" class="edit"><a class="edit" target="_NEW2" href="'.$this->System->Link('/dictionary/?search='.$tran).'">'.$orig_replace.'</a></span>',$Text);
16 }
[633]17 // }
[629]18 return ($Text);
[614]19 }
20 function ReplaceNotTranslated($orig,$tran,$Text,$ID,$Group) {
[633]21// echo $orig.'-'.$Text.'<br>';
22 $orig_replace = str_replace(' ','&nbsp;',htmlspecialchars($orig));
[628]23
[633]24 $Text = str_replace(' '.$orig,' <span title="Kliknutím přeložíš" class="needtran"><a class="needtran" target="_NEW2" href="'.$this->System->Link('/form.php?group='.$Group.'&amp;ID='.$ID).'">'.$orig_replace.'</a></span>',$Text);
[614]25 return ($Text);
26 }
27
[550]28 function ColorNames($Text, $names)
29 {
[614]30 $Text = ' '.$Text;
[633]31 $Text = str_replace('$B$B','$B$B ',$Text);
[629]32
33 $Text = str_replace('$B','<span Title="Znamená odřádkování, překladu zachovej na stejné pozici." class="edit">$B</span>',$Text);
34 $Text = str_replace('$N','<span Title="Znamená jméno hráče, překladu zachovej na stejné pozici." class="edit">$N</span>',$Text);
35 $Text = str_replace('$R','<span Title="Znamená rasu hráče, překladu zachovej na stejné pozici." class="edit">$R</span>',$Text);
36 $Text = str_replace('$G','<span Title="Vybere oslovení podle pohlaví hráče, překladu zachovej na stejné pozici." class="edit">$G</span>',$Text);
37 $Text = str_replace('$b','<span Title="Znamená odřádkování, překladu zachovej na stejné pozici." class="edit">$B</span>',$Text);
38 $Text = str_replace('$n','<span Title="Znamená jméno hráče, překladu zachovej na stejné pozici." class="edit">$N</span>',$Text);
39 $Text = str_replace('$r','<span Title="Znamená rasu hráče, překladu zachovej na stejné pozici." class="edit">$R</span>',$Text);
40 $Text = str_replace('$g','<span Title="Vybere oslovení podle pohlaví hráče, překladu zachovej na stejné pozici." class="edit">$G</span>',$Text);
[550]41 foreach($names as $Line) {
[633]42 if (($this->ID <> $Line[0]) or ($Line[1] <> $this->GroupId))
43 if ($Line[3] <> '') {
[614]44 $Text = $this->ReplaceTranslated($Line[2],$Line[3],$Text,$Line[0],$Line[1]);
45
[550]46 } else {
[614]47 $Text = $this->ReplaceNotTranslated($Line[2],$Line[3],$Text,$Line[0],$Line[1]);
[550]48 }
49 }
50 return $Text;
[561]51 }
[552]52
53 function Show()
54 {
[636]55 $this->Title = T('Translation');
[561]56 $Action = '';
57 if(array_key_exists('action', $_GET)) $Action = $_GET['action'];
58
59 if($Action == 'delete') $Output = $this->Delete();
60 else $Output = $this->ShowForm();
61 return($Output);
62 }
63
64 function ShowForm()
65 {
[577]66 global $TranslationTree;
[561]67
[552]68 $Output = '';
[550]69
[552]70 $GroupId = LoadGroupIdParameter();
[633]71 $this->GroupId = $GroupId;
[552]72 $Table = $TranslationTree[$GroupId]['TablePrefix'];
73 if(array_key_exists('action', $_GET)) $Action = $_GET['action'];
74 else $Action = '';
75
76 if(array_key_exists('ID', $_GET))
77 {
78 $TextID = $_GET['ID'] * 1;
[633]79 $this->ID = $TextID;
[552]80
[577]81 $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE `ID` = '.$TextID);
[552]82 $Line = $DbResult->fetch_assoc();
83 if(!$Line)
84 {
85 $Output .= ShowMessage('Překlad nenalezen.', MESSAGE_CRITICAL);
86 } else
[577]87 {
[629]88 if ($this->System->Config['OriginalLanguage'] == $Line['Language']){
89 $LineAJ = $Line;
90 $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE '.
91 '(`Language` != '.$this->System->Config['OriginalLanguage'].') AND '.
[633]92 '(`Entry` = '.$Line['Entry'].') ORDER BY `ModifyTime` DESC LIMIT 1');
[629]93 $LineSearch = $DbResult->fetch_assoc();
94 foreach($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
95 if($TextItem['Visible'] == 1)
96 if (($LineAJ[$TextItem['Column']] <> '') and ($LineSearch[$TextItem['Column']] <> '')) $Line[$TextItem['Column']] = $LineSearch[$TextItem['Column']];
97
98 } else {
99 $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE '.
[577]100 '(`Language` = '.$this->System->Config['OriginalLanguage'].') AND '.
101 '(`Entry` = '.$Line['Entry'].') AND (`VersionEnd` = '.$Line['VersionEnd'].') LIMIT 1');
[629]102 $LineAJ = $DbResult->fetch_assoc();
103 }
[552]104 if(!$LineAJ)
105 {
106 $Output .= ShowMessage('Anglický originál k překladu nenalezen.', MESSAGE_CRITICAL);
107 } else
108 {
109
110 if($Line['User'] != '')
111 {
[577]112 $IDUser = $this->Database->query('SELECT * FROM `User` WHERE `ID` = '.$Line['User']);
[552]113 $LineUser = $IDUser->fetch_array();
114 } else
115 $LineUser = array('Name' => '');
116
117 $Output .= 'Skupina: <strong>'.$TranslationTree[$GroupId]['Name'].'</strong><br />';
118
119 if(($Line['Language'] <> 0) and ($LineUser['Name'] <> ''))
120 $Output .= 'Přeložil: <strong>'.$LineUser['Name'].'</strong> dne '.HumanDate($Line['ModifyTime']).'<br />';
121 if(($Line['Take'] <> 0) and ($Line['Take'] <> $Line['ID']))
122 {
[577]123 $DbResult = $this->Database->query('SELECT `Language`,`VersionStart`,`VersionEnd` FROM `'.$Table.'` WHERE `ID` = '.$Line['Take']);
[552]124 $Language = $DbResult->fetch_assoc();
125 // echo $Language['Language'].' '.$Line['Take'];
126
[577]127 $DbResult = $this->Database->query('SELECT `Name` FROM `Language` WHERE `Id` ='.$Language['Language']);
[552]128 $Lang = $DbResult->fetch_assoc();
129
130 $Output .= 'Původní text: <strong>'.
[577]131 ' ID <a href="form.php?group='.$GroupId.'&amp;ID='.$Line['Take'].'">'.$Line['Take'].'</a></strong>'.
132 ' ('.$Lang['Name'].')'.
133 ' <br />';
[552]134 }
135 $Output .= 'Text: ';
136 if($Line['Language'] <> 0)
137 {
138 if($Line['Complete'] == 1) $Output .= ' <b>Hotov</b>';
139 else $Output .= ' <b> Uložen v rozepsaných</b> ';
140 } else $Output .= ' <b>Anglická, původní verze</b> ';
141
142 $Output .= '<br />'.
143 'Verze: <b>'.GetVersionWOW($Line['VersionStart']).' - '.GetVersionWOW($Line['VersionEnd']).'</b>'.
144 '<br />';
145
[577]146 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$Table.'` WHERE '.
[613]147 '(`Entry` = '.$Line['Entry'].')');
[552]148 $Version = $DbResult->fetch_row();
149 $Version = $Version[0];
150 if($Version > 0)
151 {
[577]152 $Output .= '<form action="comparison.php" method="get"><a href="TranslationList.php?group='.
153 $GroupId.'&amp;user=0&amp;state=2&amp;entry='.$Line['Entry'].'&amp;text=">Počet verzí: <strong>'.$Version.'</strong></a>
[552]154 <input type="hidden" name="group" value="'.$GroupId.'" />
155 <input type="hidden" name="entry" value="'.$Line['Entry'].'" />
156 <input type="hidden" name="ID2" value="'.$TextID.'" />
157 <select onchange="this.form.submit();" name="ID1">
158 <option value="-1">Vyberte text k porovnání</option>
159 <option value="-1">Zobrazit/porovnat všechny</option>';
[630]160 $DataID = $this->Database->query('SELECT *, (SELECT `User`.`Name` AS `UserName` FROM `User` WHERE `User`.`ID` = `'.$Table.'`.`User`) AS `UserName` FROM `'.$Table.'` WHERE (`Entry` = '.$Line['Entry'].') AND (`ID` <> '.$Line['ID'].')');
[552]161 while($Version = $DataID->fetch_array())
162 {
[577]163 if($Version['ID'] == $Line['Take']) $Output .= '<option value="'.
164 $Version['ID'].'">'.$Version['ID'].' - '.$Version['User'].' (převzato)</option>';
[552]165 else
166 {
167 if($Version['Language'] == 0) $Version['UserName'] = 'Předloha';
168 $Output .= '<option value="'.$Version['ID'].'">'.$Version['ID'].' - '.
169 $Version['UserName'].' ('.GetVersionWOW($Version['VersionStart']).' - '.
170 GetVersionWOW($Version['VersionEnd']).')</option>';
171 }
172 }
173 $Output .= '</select></form>';
174 } else
175 {
[577]176 $Output .= '<a href="TranslationList.php?group='.$GroupId.'&amp;user=0&amp;state=2&amp;entry='.
177 $Line['Entry'].'&amp;text=">Počet verzí: <strong>'.$Version.'</strong></a>';
[552]178 }
179
180 // Special characters: $B - New line, $N - Name, $C - profession
[577]181 if($this->System->User->Licence(LICENCE_USER))
[552]182 {
183 $Output .= '<form action="save.php?group='.$GroupId.'" method="post"><div>';
[569]184 // TODO: Remove fixed group id condition
[629]185 // if(($GroupId < 4) or ($GroupId == 10) or ($GroupId == 11))
[569]186 $Output .= '<a href="'.$this->System->Link('/dictionary/?action=group&amp;group='.$GroupId.'&amp;ID='.$LineAJ['ID']).'" target="_blank" title="Zobrazit přeložené názvy věci, postav, a herních objektů k tomuto překladu">Vyhledat v názvech</a>';
[552]187 $Output .= ' <input type="submit" value="Uložit do rozepsaných" name="save" title="Klikněte na uložit pro pozdější dokončení překladu" />'.
188 '<input type="submit" value="Dokončeno" name="End" title="Klikněte na Dokončeno jesli jsou všechny texty hotové a chcete již publikovat" /> ';
189 FollowingTran($TextID, $Table, $GroupId, true);
190 FollowingTran($TextID, $Table, $GroupId);
191 }
192
193 if($TranslationTree[$GroupId]['WowheadName'] != '')
194 $WowheadLink = '<a href="http://www.wowhead.com/?'.$TranslationTree[$GroupId]['WowheadName'].'='.$LineAJ['Entry'].'">'.$LineAJ['Entry'].'</a>';
195 else $WowheadLink = $LineAJ['Entry'];
196
197 $Output .= '<input type="hidden" name="entry" value="'.$LineAJ['Entry'].'" />
[577]198 <input type="hidden" name="user" value="'.$this->System->User->Id.'" />
[552]199 <input type="hidden" name="ID" value="'.$TextID.'" />
200 <table class="BaseTable">
201 <tr>
202 <th>Číslo textu: '.$WowheadLink.'</th>
203 <th>Nepřeložené</th>
204 <th>Přeložené</th>
205 </tr>
206 <tr>
207 <th>Jazyk</th>
208 <td>Anglický</td>
209 <td>';
210 if($Line['Language'] <> 0) $Language = $Line['Language'];
[577]211 else if($this->System->User->Id != 0)
[552]212 {
[577]213 $Language = $this->System->User->Language;
[552]214 } else $Language = 0;
[577]215 if($this->System->User->Licence(LICENCE_USER)) $Output .= WriteLanguages($Language);
[552]216 else {
[577]217 $DbResult3 = $this->Database->select('Language', '`Id`, `Name`', '`Enabled` = 1');
[552]218 if($DbResult3->num_rows > 0)
219 {
220 $Language = $DbResult3->fetch_assoc();
221 $Output .= $Language['Name'];
222 }
223 }
224
225 $Output .= '</td></tr>';
226
227 // Difference highlighting
228 $Text = '';
229 foreach($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
230 if($TextItem['Visible'] == 1)
231 $Text = $Text.' '.$LineAJ[$TextItem['Column']];
232
[651]233 if(($GroupId < 4) or ($GroupId == 10) or ($GroupId == 11)) {
[552]234 //<span class="edit">barvou.</span>
[593]235 $names = GetTranslatNames($Text, 0, GetTranslatNamesArray());
[651]236 } else {
237 $names = GetTranslatNames($Text, 0, array('Dictionary' => 'Text'));
238 }
[552]239
240 foreach($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
241 if($TextItem['Visible'] == 1)
242 {
243 if(($LineAJ[$TextItem['Column']] <> '') or ($Line[$TextItem['Column']] <> ''))
244 {
[577]245 if(($TextItem['Name'] == 'Text') and (($Table == 'global_strings') or ($Table == 'glue_strings')))
[552]246 $Output .= '<tr><th>'.$LineAJ['ShortCut'].'</th>';
247 else $Output .= '<tr><th>'.$TextItem['Name'].'</th>';
248 $Output .= '<td>'.str_replace("\n", '<br/>', $this->ColorNames(htmlspecialchars($LineAJ[$TextItem['Column']]),$names)).'</td>
249 <td>';
[577]250 if($this->System->User->Licence(LICENCE_USER))
251 $Output .= '<textarea rows="8" cols="40" onkeydown="ResizeTextArea(this)" class="textedit" id="'.$TextItem['Column'].'" name="'.$TextItem['Column'].'">';
[552]252 $Output .= htmlspecialchars($Line[$TextItem['Column']]);
[577]253 if($this->System->User->Licence(LICENCE_USER)) $Output .= '</textarea></td></tr>';
[552]254 }
255 } else
256 {
257 $Output .= '<input id="'.$TextItem['Column'].'" name="'.$TextItem['Column'].'" type="hidden" value="'.htmlspecialchars($Line[$TextItem['Column']]).'" />';
258 }
259 $Output .= '</table></div>';
[577]260 if($this->System->User->Licence(LICENCE_USER)) $Output .= '</form>';
[552]261 }
262 }
263 } else $Output = ShowMessage('Nebylo zadáno ID.', MESSAGE_CRITICAL);
264 return($Output);
[561]265 }
266
267 function Delete()
268 {
[577]269 if($this->System->User->Licence(LICENCE_MODERATOR))
[561]270 {
271 $TextID = $_GET['ID'];
[577]272 $this->Database->query('DELETE FROM `'.$Table.'` WHERE `ID` = '.$TextID.' AND `Language` <> '.$this->System->Config['OriginalLanguage']);
[561]273 $Output = ShowMessage('Překlad byl smazán.');
[582]274 $this->System->ModuleManager->Modules['Log']->WriteLog('Překlad byl smazán! <a href="'.$this->System->Link('/form.php?group='.$GroupID.'&amp;ID='.$TextID).'">'.$TextID.'</a>', LOG_TYPE_MODERATOR);
[609]275 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
[561]276 return($Output);
[552]277 }
[550]278}
Note: See TracBrowser for help on using the repository browser.