XarayaTranslationMemory  1.6
WebGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /***************************************************************************
4  * Copyright (C) 2005-2020 by Ferenc Veres *
5  * lion@netngine.hu *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  ***************************************************************************/
20 include('WebBackend.php');
21 
23 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
24 <html>
25 <head>
26 <title>TranslationMemory</title>
27 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
28 <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
29 <script type="text/javascript" src="script.js"></script>
30 <script type="text/javascript" src="diff.js"></script>
31 </head>
32 <body>
33 <?php
34 /**** Process postback events ***/
35 
36 
38 $backend->EventHandler();
39 
40 ?>
41 <form action="WebGUI.php" method="post" name="__Form" id="__Form">
42 <input type="hidden" name="__Event" value="" id="__Event" />
43 
44 <!-- backend variables (documented in TranslationBackend class) -->
45 <input type="hidden" name="xStringID" value="<?php echo $backend->xStringID ?>" id="xStringID" />
46 <input type="hidden" name="xProjectID" value="<?php echo $backend->xProjectID ?>" id="xProjectID" />
47 <input type="hidden" name="xActiveRootID" value="<?php echo $backend->xActiveRootID ?>" id="xActiveRootID" />
48 <input type="hidden" name="xOldLocaleID" value="<?php echo $backend->xOldLocaleID ?>" id="xOldLocaleID" />
49 
50 <input type="hidden" name="xStringStack" value="<?php echo $backend->xStringStack ?>" id="xStringStack" />
51 <input type="hidden" name="xBrowserHelper" value="<?php echo $backend->xBrowserHelper ?>" id="xBrowserHelper" />
52 <input type="hidden" name="xDelStringID" value="0" id="xDelStringID" />
53 <input type="hidden" name="xDelProjectID" value="0" id="xDelProjectID" />
54 
55 <!-- client side variables -->
56 
57 <!-- Editor field changed and operation requires confirmation -->
58 <input type="hidden" name="htmlEditorChanged" value="0" id="htmlEditorChanged" />
59 
60 <!-- Value of the stack when this page was loaded, to mark older items -->
61 <input type="hidden" name="htmlPageLoadStack" value="<?php echo $backend->xStringStack ?>" id="htmlPageLoadStack" />
62 
63 <!-- The English original of the current string, for diff.js comparison -->
64 <input type="hidden" name="htmlOriginalString" value="<?php
65  if(!empty($backend->LocatedString))
66  {
67  echo FixQuot($backend->LocatedString->GetOriginal());
68  }
69  ?>" id="htmlOriginalString"/>
70 
71 <table class="layout"><!-- for ideal width -->
72 <tr><td valign="top">
73 
74  <!-- *** PROJECT TREE *** -->
75 
76 <?php
77 // Show project tree ListItem
78 function showProjectLine(TranslationProject $proj, $c) {
79  global $backend;
80  // css class for current project
81  $css = "";
82  if($proj->GetID() == $backend->xProjectID)
83  {
84  $css = " class=\"current\"";
85  }
86  // Show UL and LI
87  echo "<li$css><a href=\"javascript:__TriggerEvent('setproject', true, 'xProjectID','". $proj->GetID()."')\">";
88  echo htmlspecialchars($proj->GetName());
89  //echo "**$c***";
90  echo "</a>";
91 
92  // Dead project? (Was not seen on last import.)
93  if($proj->GetRootID() != 0
94  && $backend->RootProjects[$proj->GetRootID()]->GetLastSeen() > $proj->GetLastSeen())
95  {
96  echo " +";
97  }
98 }
99 
100  if(!empty($backend->LocatedProjects))
101  {
102  $root = $backend->LocatedProjects[count($backend->LocatedProjects)-1];
103  if($root->GetID() != $backend->xActiveRootID) {
104  echo("<h1>Root switched to ".htmlspecialchars($root->GetName())."</h1>");
105  echo("<h1>Root switched to ".htmlspecialchars($root->GetName())."</h1>");
106  echo("<h1>Root switched to ".htmlspecialchars($root->GetName())."</h1>");
107  }
108 
109  // Display project parents from root in nested LI-st.
110  for($i = count($backend->LocatedProjects)-1; $i > 0; $i--)
111  {
112  // This leaves ULs and LIs open as each item is a new level!
113  $css = ($i == count($backend->LocatedProjects)-1 ? " class=\"projecttree\"" : "");
114  echo "<ul$css>\n";
115  showProjectLine($backend->LocatedProjects[$i], "t");
116  }
117 
118  // Display current project's level (siblings)
119  if($backend->SiblingProjects->valid())
120  {
121  // This renders exactly one UL with multiple LIs and and the current-LI having a nested UL
122  if(count($backend->LocatedProjects) == 1)
123  {
124  echo "<ul class=\"projecttree\">\n";
125  } else {
126  echo "<ul>\n";
127  }
128  foreach($backend->SiblingProjects as $project)
129  {
130  showProjectLine($project,"s");
131 
132  // Current project, nest children!
133  if($project->GetID() == $backend->xProjectID) {
134 
135  // Any childprojects in the iterator?
136  if($backend->ChildProjects->valid())
137  {
138  echo "<ul>\n";
139  foreach($backend->ChildProjects as $project)
140  {
141  showProjectLine($project,"c");
142  echo("</li>\n");
143  }
144  echo "</ul>";
145  }
146  }
147  }
148  }
149 
150  // Close all opened ULs
151  for($i = count($backend->LocatedProjects)-1; $i >= 0; $i--)
152  {
153  echo "</li>\n</ul>\n";
154  }
155  }
156 ?>
157 </td>
158 
159 <td valign="top">
160 
161  <!-- *** ONE STRING EDITOR *** -->
162 
163 <?php
164  // Show one string details if it was a locate event
165  if(!empty($backend->LocatedString))
166  {
167  ?>
168  <h1>Translation string editor area</h1>
169 
170  <?php
171  $stringIsDead = ($backend->GetProject()->GetRootID() != 0
172  && $backend->RootProjects[$backend->GetProject()->GetRootID()]->GetLastSeen() > $backend->LocatedString->GetLastSeen());
173  if($stringIsDead)
174  {
175  // Open a dark gray area
176  echo("<p>Dead string, not editable.</p>");
177  echo("<div class=\"located-dead\">");
178  }
179  ?>
180  <table class="located">
181  <tr><th>Project Path</th>
182  <td><?php
183 
184  // Display project path
185  if(!empty($backend->LocatedProjects))
186  {
187  for($i = count($backend->LocatedProjects)-1; $i >= 0; $i--)
188  {
189  // FIXME: Hardcoded Xaraya stuff
190  $style = "";
191  if($i == 0 && $backend->LocatedProjects[$i]->GetName() == "fuzzy.xml")
192  {
193  $style = "style=\"font-size: 25px\"";
194  }
195 
196  // Display project path entries
197  echo "<a $style href=\"javascript:__TriggerEvent('setproject', true, 'xProjectID','". $backend->LocatedProjects[$i]->GetID()."')\">";
198  echo $backend->LocatedProjects[$i]->GetName();
199  echo "</a>";
200  if($i != 0)
201  {
202  echo " -&gt; ";
203  }
204  }
205  }
206  ?></td></tr>
207  <tr><th>Original</th>
208  <td><?php echo FixQuot($backend->LocatedString->GetOriginal()) ?></td></tr>
209  <tr><th><u>E</u>dit translation</th>
210  <td><?php
211  $disableField = ($stringIsDead ? "disabled=\"disabled\"" : "");
212  // Long or short input fields for editing
213  if(strlen($backend->LocatedString->GetOriginal()) < 100)
214  {
215  echo "<input spellcheck=\"true\" class=\"editshort\" type=\"text\" accesskey=\"e\" name=\"txtEditString_".$backend->xBrowserHelper."\" id=\"txtEditString_".$backend->xBrowserHelper."\" value=\"";
216  echo FixQuot($backend->LocatedString->GetTranslation());
217  echo "\" onchange=\"editorChanged();\" tabindex=\"1\" $disableField/>";
218  }
219  else
220  {
221  echo "<textarea class=\"editlong\" cols=\"80\" rows=\"8\" accesskey=\"e\" name=\"txtEditString_".$backend->xBrowserHelper."\" id=\"txtEditString_".$backend->xBrowserHelper."\" onchange=\"editorChanged();\" tabindex=\"1\" $disableField>";
222  echo FixQuot($backend->LocatedString->GetTranslation());
223  echo "</textarea>";
224  }
225  ?>
226  </td></tr>
227  </table>
228  <?php
229  // Enable/disable various buttons
230  $stackLength = 0;
231  if($backend->xStringStack != "")
232  {
233  $stackLength = count(split(',', $backend->xStringStack));
234  }
235  $saveDisabled = "class=\"button-disabled\" disabled=\"disabled\"";
236  $saveEnabled = "class=\"button\"";
237  if($stringIsDead)
238  {
239  // Close dark gray area
240  echo("</div>");
241 
242  $saveType = $saveDisabled;
243  $saveTypePop = $saveDisabled;
244  }
245  else
246  {
247  $saveType = $saveEnabled;
248  $saveTypePop = $saveEnabled;
249 
250  // If no stack disable "save + pop" and "save to all stacked"
251  if($stackLength == 0)
252  {
253  $saveTypePop = $saveDisabled;
254  }
255  }
256  ?>
257  <input <?php echo $saveType; ?> type="button" onclick="__TriggerEvent('savenext', false);" value="Save + Next" tabindex="2" />
258  <button <?php echo $saveType; ?> type="button" onclick="__TriggerEvent('savenextmissing', false);" tabindex="3" accesskey="s"><u>S</u>ave + Next missing</button>
259  <input <?php echo $saveType; ?> type="button" onclick="__TriggerEvent('save', false);" value="Save" tabindex="4" />
260  <!-- input class="button" type="button" onclick="__TriggerEvent('previous');" value="Previous" />
261  <input class="button" type="button" onclick="__TriggerEvent('previoumissing');" value="Previous missing" / -->
262  <input class="button" type="button" onclick="__TriggerEvent('next', true);" value="Next" tabindex="5" />
263  <button class="button" type="button" onclick="__TriggerEvent('nextmissing', true);" tabindex="6" accesskey="n" tabindex="6"><u>N</u>ext missing</button>
264 
265  Stack control: <button <?php echo $saveTypePop; ?> type="button" onclick="__TriggerEvent('savepopstack', false);" tabindex="7" accesskey="p" id="btnSavePopStack">Save + <u>p</u>op</button>
266  <input <?php echo $saveType; ?> type="button" onclick="if(confirm('Operation will OVERWRITE all selected strings and current string!')) { __TriggerEvent('savetoallchecked', false); }" value="Save to all chekced" tabindex="8" />
267  <?php
268  }
269 
270 ?>
271  <!-- *** STACK *** -->
272 
273 <div id="stack">
274 <h1>Stack</h1>
275 Contents: [<span id="plhStackView"></span>]
276 <?php
277 if(!empty($backend->LocatedString))
278 {
279  ?>
280  <input class="codebutton" type="button" onclick="pushToStack('<?php echo($backend->LocatedString->GetStringID()); ?>');" value="push" tabindex="7" />
281  <?php
282 }
283 ?>
284 <input class="codebutton" type="button" onclick="popFromStack();" value="pop" tabindex="9" />
285 <input class="codebutton" type="button" onclick="clearStack();" value="clear" tabindex="10" />
286 </div>
287 <?php
288 
289 if(!empty($backend->CurrentStrings))
290 {
291  ?>
292 
293  <!-- *** CURRENT PROJECT'S STRINGS *** -->
294 
295  <p><a href="javascript:toggleStrings()" accesskey="t"><span class="underunder">t</span>oggle strings</a></p>
296  <div id="divStrings">
297  <h1>Strings in the currently selected file</h1>
298  <?php
299 
300  $addHeader = true;
301  foreach($backend->CurrentStrings as $str)
302  {
303  // Draw header if not done yet
304  if($addHeader)
305  {
306  ?>
307  <table class="strings">
308  <tr><th>Original string</th>
309  <th>Translated string</th>
310  <th>Action</th></tr>
311  <?php
312  $addHeader = false;
313  }
314  if(!empty($backend->LocatedString) && $backend->LocatedString->GetStringID() == $str->GetStringID())
315  {
316  echo("<tr class=\"selected\">");
317  }
318  else
319  {
320  echo("<tr>");
321  }
322 
323  echo("<td class=\"string-original\">".FixQuot($str->GetOriginal())."</td>");
324  echo("<td class=\"string-translation\">".FixQuot($str->GetTranslation())."</td>");
325  echo("<td><a href=\"javascript:__TriggerEvent('editstring', true, 'xStringID','".$str->GetStringID()."');\">Edit</a>");
326 
327  // Dead string?
328  if($backend->GetProject()->GetRootID() != 0
329  && $backend->RootProjects[$backend->GetProject()->GetRootID()]->GetLastSeen() > $str->GetLastSeen())
330  {
331  echo " +++ ";
332  echo("<a href=\"javascript:if(confirm('Are you sure to delete from Translation Memory?')) { __TriggerEvent('deletestring', true, 'xDelStringID', '".$str->GetStringID()."'); }\">Del</a>");
333  }
334 
335  echo("</td>");
336  echo("</tr>\n");
337  }
338  if($addHeader)
339  {
340  // No strings for this project: "next" buttons only
341  ?>
342  <p>There are no strings in the current project.</p>
343  Find strings: <input class="button" type="button" onclick="__TriggerEvent('next', true);" value="Next" />
344  <button class="button" type="button" onclick="__TriggerEvent('nextmissing', true);" accesskey="n"><u>N</u>ext missing</button>
345  <?php
346 
347  // Deletion of empty and dead projects
348  $backend->ChildProjects->rewind();
349 
350  if($backend->GetProject()->GetRootID() != 0
351  && $backend->RootProjects[$backend->GetProject()->GetRootID()]->GetLastSeen() > $backend->GetProject()->GetLastSeen()
352  && !$backend->ChildProjects->valid())
353  {
354  echo("<p>The <em>".$backend->GetProject()->GetName()."</em> is an empty and dead project. ");
355  echo("<input class=\"button\" type=\"button\" onclick=\"javascript:if(confirm('Are you sure to delete from Translation Memory?')) { __TriggerEvent('deleteproject', false, 'xDelProjectID', '". $backend->GetProject()->GetID()."'); }\" value=\"Delete project\"/></p>");
356  }
357 
358  }
359  else
360  {
361  echo("</table>");
362  }
363  ?></div><?php
364 }
365 
366 $sel = " selected=\"selected\"";
367 ?> <h1>Search</h1><a name="searchresults"></a>
368 
369  <!-- *** CUSTOM SEARCH BOX *** -->
370 
371 <p>
372 <select name="ddlSearchType" id="ddlSearchType">
373 <option value="0"<?php echo ($backend->ddlSearchType == 0 ? $sel : ""); ?>>Word index</option>
374 <option value="1"<?php echo ($backend->ddlSearchType == 1 ? $sel : ""); ?>>Part in original</option>
375 <option value="2"<?php echo ($backend->ddlSearchType == 2 ? $sel : ""); ?>>Part in translation</option>
376 </select>
377 <a href="javascript:clearFindText();">clear></a>
378 <input type="text" size="35" id="txtFindText" name="txtFindText" value="<?php echo FixQuot( $backend->txtFindText); ?>">
379 <input class="button" type="button" value="Find" onclick="__TriggerEvent('find', true);"/>
380 <!-- input class="button" type="button" value="Original"/--></p>
381 
382 
383  <!-- *** SEARCH RESULTS *** -->
384 
385 
386 <?php
387 // Show search results if there is any!
388 if(!empty($backend->Translations))
389 {
390  $keyindex = 0;
391  ?>
392  <table class="guesses" id="tblGuesses">
393  <tr><th></th>
394  <th>Match</th>
395  <th>Original string</th>
396  <?php
397  if(!empty($backend->LocatedString))
398  {
399  echo("<th>alt</th>");
400  }
401  ?>
402  <th>Translated string (take by click)</th>
403  <th>Action</th>
404  <th>Root</th></tr>
405  <?php
406 
407  $accesskeys = array("m"); // Was '1'-'9' but that switches tabs so only one now... https://code.google.com/p/chromium/issues/detail?id=21624
408  foreach($backend->Translations as $id => $tr)
409  {
410  foreach($tr["strings"] as $key => $str)
411  {
412  // Selected color or normal table row
413  if(!empty($backend->LocatedString) && $backend->LocatedString->GetStringID() == $str->GetStringID())
414  {
415  echo("<tr id=\"tr_search_".$str->GetStringID()."\" class=\"selected\">");
416  }
417  else
418  {
419  echo("<tr id=\"tr_search_".$str->GetStringID()."\">");
420  }
421 
422  // Find string root project for dead string checks
423  $strProject = ProjectIterator::$ProjectList[$str->GetLocaleID()][$str->GetProjectID()];
424  $strRoot = $backend->RootProjects[$strProject->GetRootID()];
425 
426  // Checkbox column
427  echo("<td class=\"guess-checkbox\">");
428  if($strRoot->GetLastSeen() <= $str->GetLastSeen())
429  {
430  echo(" <input type=\"checkbox\" name=\"chkSearchSelects[]\" value=\"".$str->GetStringID()."\"/>");
431  }
432  echo("</td>");
433 
434  // Percent column
435  if($backend->ddlSearchType == 0)
436  {
437  // Exact match? (Not only 100%, word index match, but same string.)
438  if(!empty($backend->LocatedString) && $backend->LocatedString->GetOriginal() == $str->GetOriginal()) {
439  echo("<td class=\"guess-identical\">");
440  echo("identical");
441  }
442  else
443  {
444  echo("<td class=\"guess-percent\">");
445  echo($tr["percent"]."%");
446  echo(" <a id=\"diffLink_".$str->GetStringID()."\" href=\"javascript:diffToOriginal(".$str->GetStringID().");\">(?)</a>");
447  }
448  }
449  else
450  {
451  echo("<td class=\"guess-percent\">");
452  }
453  echo("</td>");
454 
455  // String columns
456  echo("<td id=\"original_".$str->GetStringID()."\" class=\"guess-original\">".FixQuot($str->GetOriginal())."</td>");
457 
458  // Add "Take string" link if editing one, no link otherwise
459  if(!empty($backend->LocatedString))
460  {
461  // Accesskey 1-9
462  echo("<td class=\"guess-accesskey\">");
463  if($keyindex < count($accesskeys) && $str->GetTranslation() != "")
464  {
465  echo("<a accesskey=\"".$accesskeys[$keyindex]."\" href=\"javascript:takeTranslation(".$str->GetStringID().");\"><span class=\"underunder\">".$accesskeys[$keyindex]."</span></a>");
466  $keyindex++;
467  }
468  echo("</td>");
469 
470  // Translation with take link
471  echo("<td class=\"guess-translated\">");
472  if($str->GetTranslation() != "")
473  {
474  echo("<a id=\"results_".$str->GetStringID()."\" href=\"javascript:takeTranslation(".$str->GetStringID().");\">".FixQuot($str->GetTranslation())."</a>");
475  }
476  echo("</td>");
477  }
478  else
479  {
480  // Not pickable translation
481  echo("<td class=\"guess-translated\">");
482  echo(FixQuot($str->GetTranslation()));
483  echo("</td>");
484  }
485 
486  echo("<td class=\"guess-action\">");
487 
488  // Edit link (for dead strings too, to identify them)
489  echo("<a href=\"javascript:__TriggerEvent('editstring', true, 'xStringID', '".$str->GetStringID()."');\">Edit</a>");
490 
491  // Del link (for dead strings ) or push link otherwise
492  if($strRoot->GetLastSeen() > $str->GetLastSeen())
493  {
494  // Plus sign and Del link
495  echo " +++ ";
496  echo("<a href=\"javascript:if(confirm('Are you sure to delete from Translation Memory?')) { __TriggerEvent('deletestring', true, 'xDelStringID', '".$str->GetStringID()."'); }\">Del</a>");
497  }
498  else
499  {
500  // Not dead, "push" to stack link
501  echo(" | <a href=\"javascript:pushToStack('".$str->GetStringID()."');\">push</a>");
502  }
503  echo("</td>\n");
504  echo("<td>".$strRoot->GetName()."</td></tr>\n");
505  }
506  }
507  ?></table><?php
508  if($backend->ddlSearchType != 0)
509  {
510  echo("Displayed ".count($backend->Translations)." results.<br/>");
511  }
512 }
513 ?>
514 
515  <!-- *** SEARCH REFRESH CONTROLS *** -->
516 
517 <select name="ddlFindPercent">
518 <?php
519 foreach(array(30,40,50,60,70,80,90) as $percent)
520 {
521  $sel = "";
522  if($backend->ddlFindPercent == $percent)
523  {
524  $sel = " selected=\"selected\"";
525  }
526  echo "<option value=\"$percent\"$sel>&gt; $percent%</option>";
527 }
528 ?>
529 </select>
530 <input type="button" value="Refresh" class="button" onclick="__TriggerEvent('find', true);"/>
531 <input type="button" value="Check all identical empty" class="button" onclick="checkGuesses(false);" />
532 <input type="button" value="Uncheck all" class="button" onclick="checkGuesses(true);" />
533 
534 </td>
535 
536 </tr>
537 </table>
538 <div class="localeswitch">
539 <?php
540  echo "<select name=\"ddlLocaleID\">\n";
541  foreach(TranslationProject::$LocaleIDCache as $name => $id)
542  {
543  $sel = "";
544  if($backend->ddlLocaleID == $id)
545  {
546  $sel = " selected=\"selected\"";
547  }
548  echo "<option value=\"$id\"$sel>$name</option>\n";
549  }
550  echo "</select>\n";
551 ?>
552 <input type="button" value="Switch Locale" class="button" onclick="__TriggerEvent('setlocale', true);"/> |
553 <!-- Root project switch -->
554 <select name="ddlActiveRoot">
555 <?php
556  foreach($backend->RootProjects as $id => $rootProject)
557  {
558  $sel = ($backend->xActiveRootID == $id ? " selected=\"selected\"" : "");
559  echo "<option value=\"$id\"$sel>".htmlspecialchars($rootProject->GetName())."</option>\n";
560  }
561 ?>
562 </select>
563 <input type="button" value="Switch Root" class="button" onclick="__TriggerEvent('setroot', true);"/> |
564 
565 <?php if($CONFIG['enable_web_export']) { ?>
566 <input type="button" value="Export language pack" class="button" onclick="__TriggerEvent('exportpack', true);"/> |
567 <?php } ?>
568 
569 <a href="http://xartm.xaraya.hu">Homepage</a> | <a href="doc/">Documentation</a> | (c) 2006-2020 Ferenc 'Lion/Kempelen' Veres
570 </div>
571 </form>
572 
573 <script type="text/javascript">
574 
575 // Clear eventhandler
576 document.getElementById('__Event').value = '';
577 document.getElementById('__Form').onsubmit = __FormSubmit();
578 STR_UNIQUE = "<?php echo $backend->xBrowserHelper ?>";
579 
580 showStack();
581 
582 <?php if(!empty($backend->LocatedString))
583 {
584 ?>
585  var txtEditString = document.getElementById('txtEditString_<?php echo $backend->xBrowserHelper; ?>');
586  txtEditString.focus();
587 <?php
588 }
589 ?>
590 </script>
591 
592 <?php
593 ShowMicroTime($guiTime, "GUI");
594 ?>
595 </body>
596 </html>
FixQuot($text)
Definition: Common.php:49
$backend
Definition: WebGUI.php:37
GetMicroTime()
Definition: Common.php:107
$guiTime
Definition: WebGUI.php:22