1 | <?php
|
---|
2 |
|
---|
3 | class PageTranslationForm extends Page
|
---|
4 | {
|
---|
5 | var $GroupId;
|
---|
6 | var $ID;
|
---|
7 |
|
---|
8 | function Show(): string
|
---|
9 | {
|
---|
10 | $this->Title = T('Translation');
|
---|
11 | $Action = '';
|
---|
12 | if (array_key_exists('action', $_GET)) $Action = $_GET['action'];
|
---|
13 |
|
---|
14 | if ($Action == 'delete') $Output = $this->Delete();
|
---|
15 | else $Output = $this->ShowForm();
|
---|
16 | return $Output;
|
---|
17 | }
|
---|
18 |
|
---|
19 | function ShowForm(): string
|
---|
20 | {
|
---|
21 | $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
|
---|
22 | $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
|
---|
23 |
|
---|
24 | $Output = '';
|
---|
25 |
|
---|
26 | $GroupId = LoadGroupIdParameter();
|
---|
27 | $this->GroupId = $GroupId;
|
---|
28 | $Table = $TranslationTree[$GroupId]['TablePrefix'];
|
---|
29 | if (array_key_exists('action', $_GET)) $Action = $_GET['action'];
|
---|
30 | else $Action = '';
|
---|
31 |
|
---|
32 | $TextID = 0;
|
---|
33 | if (TryGetUrlParameterInt('ID', $TextID))
|
---|
34 | {
|
---|
35 | $this->ID = $TextID;
|
---|
36 |
|
---|
37 | $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE `ID` = '.$TextID);
|
---|
38 | $Line = $DbResult->fetch_assoc();
|
---|
39 | if (!$Line)
|
---|
40 | {
|
---|
41 | $Output .= ShowMessage('Překlad nenalezen.', MESSAGE_CRITICAL);
|
---|
42 | } else
|
---|
43 | {
|
---|
44 | if (Core::Cast($this->System)->Config['OriginalLanguage'] == $Line['Language']){
|
---|
45 | $LineAJ = $Line;
|
---|
46 |
|
---|
47 | if ($User->Language <> '') $Language = '`Language` = '.$User->Language;
|
---|
48 | else $Language = '`Language` != '.Core::Cast($this->System)->Config['OriginalLanguage'];
|
---|
49 | $Columns = '';
|
---|
50 | foreach ($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
|
---|
51 | $Columns .= ' `Orig`.`'.$TextItem['Column'].'` as `Orig_'.$TextItem['Column'].'`, `Tran`.`'.$TextItem['Column'].'` as `'.$TextItem['Column'].'`,';
|
---|
52 |
|
---|
53 | $sql = 'SELECT '.$Columns.' Tran.`Entry` FROM `'.$Table.'` as Tran';
|
---|
54 | $join = ' JOIN `'.$Table.'` as `Orig` ON `Orig`.`Language` = 0 AND `Tran`.`Entry` = `Orig`.`Entry` AND `Tran`.`VersionEnd` = `Orig`.`VersionEnd` ';
|
---|
55 | $where = ' WHERE '.'( `Tran`.'.$Language.' ) AND '.'(`Tran`.`Entry` = '.$Line['Entry'].') ORDER BY `Tran`.`ModifyTime` DESC';
|
---|
56 | $DbResult = $this->Database->query($sql.$join.$where);
|
---|
57 | while ($LineSearch = $DbResult->fetch_assoc())
|
---|
58 | {
|
---|
59 | foreach ($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
|
---|
60 | {
|
---|
61 | if ($TextItem['Visible'] == 1)
|
---|
62 | {
|
---|
63 | if (($LineAJ[$TextItem['Column']] <> '') and
|
---|
64 | ($LineSearch[$TextItem['Column']] <> '') and
|
---|
65 | ($LineSearch['Orig_'.$TextItem['Column']] <> $LineSearch[$TextItem['Column']]) and
|
---|
66 | ($LineAJ[$TextItem['Column']] == $Line[$TextItem['Column']])
|
---|
67 | )
|
---|
68 | {
|
---|
69 | $Line[$TextItem['Column']] = $LineSearch[$TextItem['Column']];
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 | } else
|
---|
75 | {
|
---|
76 | $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE '.
|
---|
77 | '(`Language` = '.Core::Cast($this->System)->Config['OriginalLanguage'].') AND '.
|
---|
78 | '(`Entry` = '.$Line['Entry'].') AND (`VersionEnd` = '.$Line['VersionEnd'].') LIMIT 1');
|
---|
79 | $LineAJ = $DbResult->fetch_assoc();
|
---|
80 | }
|
---|
81 | if (!$LineAJ)
|
---|
82 | {
|
---|
83 | $Output .= ShowMessage('Anglický originál k překladu nenalezen.', MESSAGE_CRITICAL);
|
---|
84 | } else
|
---|
85 | {
|
---|
86 | if ($Line['User'] != '')
|
---|
87 | {
|
---|
88 | $IDUser = $this->Database->query('SELECT * FROM `User` WHERE `ID` = '.$Line['User']);
|
---|
89 | $LineUser = $IDUser->fetch_array();
|
---|
90 | } else
|
---|
91 | $LineUser = array('Name' => '');
|
---|
92 |
|
---|
93 | $Output .= T('Group').': <strong>'.$TranslationTree[$GroupId]['Name'].'</strong><br />';
|
---|
94 |
|
---|
95 | if (($Line['Language'] <> 0) and ($LineUser['Name'] <> ''))
|
---|
96 | $Output .= T('Translated by').': <a href="'.$this->System->Link('/user/?user='.$Line['User']).'"><strong>'.$LineUser['Name'].'</strong></a> dne '.HumanDate($Line['ModifyTime']).'<br />';
|
---|
97 | if (($Line['Take'] <> 0) and ($Line['Take'] <> $Line['ID']))
|
---|
98 | {
|
---|
99 | $DbResult = $this->Database->query('SELECT `Language`,`VersionStart`,`VersionEnd` FROM `'.$Table.'` WHERE `ID` = '.$Line['Take']);
|
---|
100 | $Language = $DbResult->fetch_assoc();
|
---|
101 |
|
---|
102 | $DbResult = $this->Database->query('SELECT `Name` FROM `Language` WHERE `Id` ='.$Language['Language']);
|
---|
103 | $Lang = $DbResult->fetch_assoc();
|
---|
104 |
|
---|
105 | $Output .= T('Original text').': <strong>'.
|
---|
106 | ' ID <a href="'.$this->System->Link('/form.php?group='.$GroupId.'&ID='.$Line['Take']).'">'.$Line['Take'].'</a></strong>'.
|
---|
107 | ' ('.T($Lang['Name']).')'.
|
---|
108 | ' <br />';
|
---|
109 | }
|
---|
110 | $Output .= 'Text: ';
|
---|
111 | if ($Line['Language'] <> 0)
|
---|
112 | {
|
---|
113 | if ($Line['Complete'] == 1) $Output .= ' <b>'.T('Completed').'</b>';
|
---|
114 | else $Output .= ' <b>'.T('Stored in unfinished').'</b> ';
|
---|
115 | } else $Output .= ' <b>'.T('Original version').'</b> ';
|
---|
116 |
|
---|
117 | $Output .= '<br />'.
|
---|
118 | T('Version').': <b><a href="'.$this->System->Link('/client-version/?action=item&id='.GetVersionWOWId($Line['VersionStart'])).'">'.GetVersionWOW($Line['VersionStart']).
|
---|
119 | '</a> - <a href="'.$this->System->Link('/client-version/?action=item&id='.GetVersionWOWId($Line['VersionEnd'])).'">'.GetVersionWOW($Line['VersionEnd']).'</a></b>'.
|
---|
120 | '<br />';
|
---|
121 |
|
---|
122 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$Table.'` WHERE '.
|
---|
123 | '(`Entry` = '.$Line['Entry'].')');
|
---|
124 | $Version = $DbResult->fetch_row();
|
---|
125 | $Version = $Version[0];
|
---|
126 | if ($Version > 0)
|
---|
127 | {
|
---|
128 | $Output .= '<form action="comparison.php" method="get"><a href="'.$this->System->Link('/TranslationList.php?group='.
|
---|
129 | $GroupId.'&user=0&state=2&entry='.$Line['Entry'].'&text=').'">'.T('Number of versions').': <strong>'.$Version.'</strong></a>
|
---|
130 | <input type="hidden" name="group" value="'.$GroupId.'" />
|
---|
131 | <input type="hidden" name="entry" value="'.$Line['Entry'].'" />
|
---|
132 | <input type="hidden" name="ID2" value="'.$TextID.'" />';
|
---|
133 |
|
---|
134 | if ($User->Licence(LICENCE_USER)) { // allow to compare only to user
|
---|
135 | $Output .= '<select onchange="this.form.submit();" name="ID1">
|
---|
136 | <option value="-1">'.T('Select text for comparison').'</option>
|
---|
137 | <option value="-1">'.T('Show/compare all').'</option>';
|
---|
138 | $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'].')');
|
---|
139 | while ($Version = $DataID->fetch_array())
|
---|
140 | {
|
---|
141 | if ($Version['ID'] == $Line['Take']) $Output .= '<option value="'.
|
---|
142 | $Version['ID'].'">'.$Version['ID'].' - '.$Version['User'].' ('.T('taken over').')</option>';
|
---|
143 | else
|
---|
144 | {
|
---|
145 | if ($Version['Language'] == 0) $Version['UserName'] = T('Original');
|
---|
146 | $Output .= '<option value="'.$Version['ID'].'">'.$Version['ID'].' - '.
|
---|
147 | $Version['UserName'].' ('.GetVersionWOW($Version['VersionStart']).' - '.
|
---|
148 | GetVersionWOW($Version['VersionEnd']).')</option>';
|
---|
149 | }
|
---|
150 | }
|
---|
151 | $Output .= '</select>';
|
---|
152 | }
|
---|
153 | $Output .= '</form>';
|
---|
154 | } else
|
---|
155 | {
|
---|
156 | $Output .= '<a href="'.$this->System->Link('/TranslationList.php?group='.$GroupId.'&user=0&state=2&entry='.
|
---|
157 | $Line['Entry'].'&text=').'">'.T('Number of versions').': <strong>'.$Version.'</strong></a>';
|
---|
158 | }
|
---|
159 |
|
---|
160 | // Special characters: $B - New line, $N - Name, $C - profession
|
---|
161 | if ($User->Licence(LICENCE_USER))
|
---|
162 | {
|
---|
163 | $Output .= '<form action="'.$this->System->Link('/save.php?group='.$GroupId).'" method="post"><div>';
|
---|
164 | // TODO: Remove fixed group id condition
|
---|
165 | // if (($GroupId < 4) or ($GroupId == 10) or ($GroupId == 11))
|
---|
166 | $Output .= '<a href="'.$this->System->Link('/dictionary/?action=group&group='.
|
---|
167 | $GroupId.'&ID='.$LineAJ['ID']).'" target="_blank" title="Zobrazit přeložené názvy věci, postav, a herních objektů k tomuto překladu">'.T('Search in names').'</a>';
|
---|
168 | $Output .= ' <input type="submit" value="'.T('Store to unfinished').
|
---|
169 | '" name="save" title="Klikněte na uložit pro pozdější dokončení překladu" />'.
|
---|
170 | '<input type="submit" value="'.T('Finished').'" name="End" title="Klikněte na Dokončeno jesli jsou všechny texty hotové a chcete již publikovat" /> ';
|
---|
171 | FollowingTran($TextID, $Table, $GroupId, true);
|
---|
172 | FollowingTran($TextID, $Table, $GroupId);
|
---|
173 | }
|
---|
174 |
|
---|
175 | if ($TranslationTree[$GroupId]['WowheadName'] != '')
|
---|
176 | $WowheadLink = '<a href="https://www.wowhead.com/?'.$TranslationTree[$GroupId]['WowheadName'].
|
---|
177 | '='.$LineAJ['Entry'].'">'.$LineAJ['Entry'].'</a>';
|
---|
178 | else $WowheadLink = $LineAJ['Entry'];
|
---|
179 |
|
---|
180 | $Output .= '<input type="hidden" name="entry" value="'.$LineAJ['Entry'].'" />'.
|
---|
181 | '<input type="hidden" name="user" value="'.$User->Id.'" />'.
|
---|
182 | '<input type="hidden" name="ID" value="'.$TextID.'" />'.
|
---|
183 | '<table class="BaseTable">'.
|
---|
184 | '<tr>'.
|
---|
185 | '<th>'.T('Text number').': '.$WowheadLink.'</th>'.
|
---|
186 | '<th>'.T('Not translated').'</th>'.
|
---|
187 | '<th>'.T('Translated').'</th>'.
|
---|
188 | '</tr>'.
|
---|
189 | '<tr>'.
|
---|
190 | '<th>'.T('Language').'</th>'.
|
---|
191 | '<td>'.T('Original').'</td>'.
|
---|
192 | '<td>';
|
---|
193 | if ($Line['Language'] <> 0) $Language = $Line['Language'];
|
---|
194 | else if ($User->Id != 0)
|
---|
195 | {
|
---|
196 | $Language = $User->Language;
|
---|
197 | } else $Language = 0;
|
---|
198 | if ($User->Licence(LICENCE_USER))
|
---|
199 | {
|
---|
200 | $Output .= WriteLanguages($Language);
|
---|
201 | }
|
---|
202 | else
|
---|
203 | {
|
---|
204 | $DbResult3 = $this->Database->select('Language', '`Id`, `Name`', '(`Enabled` = 1) AND (`Id`='.$Language.')');
|
---|
205 | if ($DbResult3->num_rows > 0)
|
---|
206 | {
|
---|
207 | $Language = $DbResult3->fetch_assoc();
|
---|
208 | $Output .= T($Language['Name']);
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | $Output .= '</td></tr>';
|
---|
213 |
|
---|
214 | // TODO: javascript
|
---|
215 |
|
---|
216 | $Output .= '<script src="'.$this->System->Link('/style/jquery.js').'"></script>'.
|
---|
217 | '<script>';
|
---|
218 | $Output .= '$(document).ready(function() {';
|
---|
219 | foreach ($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
|
---|
220 | {
|
---|
221 | $Output .= '$("#'.$TextItem['Column'].'").load("'.$this->System->Link('/LoadNames.php?ID='.$LineAJ['ID'].'&Column='.$TextItem['Column'].'&GroupId='.$GroupId).'");';
|
---|
222 | }
|
---|
223 |
|
---|
224 | $Output .= '});'.
|
---|
225 | '</script>';
|
---|
226 |
|
---|
227 | foreach ($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
|
---|
228 | {
|
---|
229 | if ($TextItem['Visible'] == 1)
|
---|
230 | {
|
---|
231 | if (($LineAJ[$TextItem['Column']] <> '') or ($Line[$TextItem['Column']] <> ''))
|
---|
232 | {
|
---|
233 | if (($TextItem['Name'] == 'Text') and (($Table == 'global_strings') or ($Table == 'glue_strings')))
|
---|
234 | $Output .= '<tr><th>'.$LineAJ['ShortCut'].'</th>';
|
---|
235 | else $Output .= '<tr><th>'.T($TextItem['Name']).'</th>';
|
---|
236 | $Output .= '<td id="'.$TextItem['Column'].'">'.str_replace("\n", '<br/>', htmlspecialchars($LineAJ[$TextItem['Column']])).'</td>
|
---|
237 | <td>';
|
---|
238 | if ($User->Licence(LICENCE_USER))
|
---|
239 | $Output .= '<textarea rows="8" cols="40" onkeydown="ResizeTextArea(this)" class="textedit" id="'.$TextItem['Column'].'" name="'.$TextItem['Column'].'">';
|
---|
240 | $Output .= htmlspecialchars($Line[$TextItem['Column']]);
|
---|
241 | if ($User->Licence(LICENCE_USER)) $Output .= '</textarea></td></tr>';
|
---|
242 | }
|
---|
243 | } else
|
---|
244 | {
|
---|
245 | $Output .= '<input id="'.$TextItem['Column'].'" name="'.$TextItem['Column'].'" type="hidden" value="'.htmlspecialchars($Line[$TextItem['Column']]).'" />';
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | $Output .= '</table></div>';
|
---|
250 | if ($User->Licence(LICENCE_USER))
|
---|
251 | {
|
---|
252 | $Output .= '</form>';
|
---|
253 |
|
---|
254 | if (isset(Core::Cast($this->System)->Config['Web']['EnableGoogleTranslate']) and
|
---|
255 | Core::Cast($this->System)->Config['Web']['EnableGoogleTranslate'])
|
---|
256 | {
|
---|
257 | $Output .= '<br/><table class="BaseTable">'.
|
---|
258 | '<tr><th>'.T('Google translator').':</th><th>'.T('Not translated').'</th><th>'.T('Translated').'</th>';
|
---|
259 | foreach ($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
|
---|
260 | {
|
---|
261 | if ($TextItem['Visible'] == 1)
|
---|
262 | {
|
---|
263 | if ($LineAJ[$TextItem['Column']] <> '')
|
---|
264 | {
|
---|
265 | $Output .= '<tr><td>'.$TextItem['Column'].'</td>'.
|
---|
266 | '<td>'.$LineAJ[$TextItem['Column']].'</td>'.
|
---|
267 | '<td>'.GetTranslateGoogle($this->System, $LineAJ[$TextItem['Column']]).'</td></tr>';
|
---|
268 | }
|
---|
269 | }
|
---|
270 | }
|
---|
271 | $Output .= '</table>';
|
---|
272 | }
|
---|
273 | }
|
---|
274 | }
|
---|
275 | }
|
---|
276 | } else $Output = ShowMessage('Nebylo zadáno ID.', MESSAGE_CRITICAL);
|
---|
277 | return $Output;
|
---|
278 | }
|
---|
279 |
|
---|
280 | function Delete()
|
---|
281 | {
|
---|
282 | $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
|
---|
283 | $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
|
---|
284 |
|
---|
285 | if ($User->Licence(LICENCE_MODERATOR))
|
---|
286 | {
|
---|
287 | $GroupId = LoadGroupIdParameter();
|
---|
288 | $this->GroupId = $GroupId;
|
---|
289 | $Table = $TranslationTree[$GroupId]['TablePrefix'];
|
---|
290 | $TextID = $_GET['ID'];
|
---|
291 | $this->Database->query('DELETE FROM `'.$Table.'` WHERE `ID` = '.$TextID.' AND `Language` <> '.Core::Cast($this->System)->Config['OriginalLanguage']);
|
---|
292 | $Output = ShowMessage('Překlad byl smazán.');
|
---|
293 | $this->System->ModuleManager->Modules['Log']->WriteLog('Překlad byl smazán! <a href="'.$this->System->Link('/form.php?group='.$this->GroupId.'&ID='.$TextID).'">'.$TextID.'</a>', LOG_TYPE_MODERATOR);
|
---|
294 | } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
|
---|
295 | return $Output;
|
---|
296 | }
|
---|
297 | }
|
---|