PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/sugarcrm/SugarCE-Full-5.0.0/translate/totrx.php

http://twpug.googlecode.com/
PHP | 144 lines | 116 code | 15 blank | 13 comment | 44 complexity | bb5d03cbf3e916317d40882ada5d173e MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /* =================================================================================================
  3. * Sugar Translation Suite
  4. * January, 2006
  5. * Web Based Translation tool for SugarCRM application
  6. * Copyright (c) http://www.grupa-atlantis.pl
  7. * Authors : Romain Girardot, David Konig
  8. * =================================================================================================
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation at
  12. * http://www.gnu.org/copyleft/gpl.html#SEC3.
  13. *
  14. */
  15. include('def.inc');
  16. start($html_charset,$db_charset);
  17. function showTrxEntryForm($query) {
  18. global $ref_text,$ref_sel,$from_row,$to_row,$rem_blank;
  19. $results = query_db($query);
  20. msg("Displaying ".count($results)." entry");
  21. $count_entry = showDicoEntry($query,true);
  22. if ($count_entry > 0 ) {
  23. ?>
  24. <BR>
  25. <TABLE width=300px align=center><TR>
  26. <TD align=center><INPUT TYPE=submit value='Commit Changes' name='commit' class='btn' /></TD><TD align=center><INPUT TYPE=submit value='Update' name='update' class='btn'/></TD>
  27. </TR><TABLE>
  28. <?php
  29. }
  30. }
  31. my_header($title,$html_charset);
  32. $isPost = isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "POST";
  33. function runSearch() {
  34. global $ref_text,$ref_sel,$from_row,$to_row, $rem_blank;
  35. $query = "SELECT * FROM sugar_lang_trx ";
  36. $next = "WHERE ";
  37. if ($ref_text != "") {
  38. $query .= $next . " ref like ".getLikeClause($ref_text,$ref_sel)." ";
  39. $next = "AND ";
  40. }
  41. if ($rem_blank == "on") {
  42. $query .= $next . " trx = '' ";
  43. }
  44. $query .= " LIMIT ". $from_row .", ".$to_row;
  45. showTrxEntryForm($query);
  46. }
  47. function showSearchForm() {
  48. global $ref_text,$ref_sel,$from_row,$to_row, $rem_blank;
  49. $done = query_db("SELECT count(*) result FROM sugar_lang_trx where trx != ''",true);
  50. $total = query_db("SELECT count(*) result FROM sugar_lang_trx",true);
  51. $done = $done->result;
  52. $total = $total->result;
  53. $percent = ($total == 0 ? 100 : round(($done/$total) * 100,1));
  54. print "<BR>";
  55. msg("Translation status : $done/$total ( $percent %)");
  56. ?>
  57. <form name="search" method="post" action="<?php print $_SERVER['PHP_SELF']; ?>">
  58. <TABLE align=center cellspacing=0 width="600px" class='tabform'>
  59. <TR class='title'><TD colspan=3>Search for entry to translate</TD></TR>
  60. <TR><TD width=15%><STRONG>English :</STRONG></TD><TD width=15%><?php printSelect("ref_sel",$ref_sel); ?></TD><TD><INPUT TYPE=text size=70 name='ref_text' value='<?php echo $ref_text?>' /></TD></TR>
  61. <TR><TD width=15% colspan=2><STRONG>From Row :</STRONG></TD><TD><INPUT TYPE=text size=70 name='from_row' value='<?php echo $from_row?>' /></TD></TR>
  62. <TR><TD width=15% colspan=2><STRONG>Row Count :</STRONG></TD><TD><INPUT TYPE=text size=70 name='to_row' value='<?php echo $to_row?>' /></TD></TR>
  63. <TR><TD width=15% colspan=2><STRONG>Only Blanks :</STRONG></TD><TD><INPUT TYPE=CHECKBOX class=checkbox name='rem_blank' <?php echo (isset($rem_blank) && $rem_blank == "on" ? "CHECKED" : "")?> /></TD></TR>
  64. </TABLE>
  65. <BR>
  66. <CENTER><INPUT TYPE=submit value='Search' class='btn' name='search' /></CENTER>
  67. <BR>
  68. <?php
  69. }
  70. if($isPost) {
  71. $ref_text = $_POST['ref_text'];
  72. $ref_sel = $_POST['ref_sel'];
  73. $from_row = $_POST['from_row'];
  74. $to_row = $_POST['to_row'];
  75. $rem_blank = isset($_POST['rem_blank']);
  76. if (isset($_POST['search'])) {
  77. $action = "search";
  78. } else if (isset($_POST['update'])) {
  79. $action = "update";
  80. } else if (isset($_POST['next'])) {
  81. $action = "update";
  82. $from_row += $to_row;
  83. } else if (isset($_POST['back'])) {
  84. $action = "update";
  85. if ($from_row - $to_row >= 0) $from_row -= $to_row;
  86. } else if (isset($_POST['commit'])) {
  87. $action = "commit";
  88. }
  89. } else {
  90. $ref_text = "";$ref_sel = "";$from_row=0;$to_row=30;$rem_blank="";$action = "";
  91. }
  92. if (!isset($from_row) || ! is_numeric($from_row)) $from_row= 0;
  93. if (!isset($to_row) || ! is_numeric($to_row)) $to_row= 30;
  94. if($isPost) {
  95. if ($action == "search") {
  96. showSearchForm();
  97. runSearch();
  98. } else if ($action == "update") {
  99. $updated = Array();
  100. foreach($_POST as $name => $value) {
  101. if (ereg("entry", $name)) {
  102. $id = substr($name, 5);
  103. $dico_entry = query_db("SELECT trx FROM sugar_lang_trx WHERE id = ".$id);
  104. if ($dico_entry[0]->trx != $value) {$updated[$id] = $value;}
  105. }
  106. }
  107. foreach ($updated as $id => $value) {
  108. mysql_query("update sugar_lang_trx set trx = '". mysql_real_escape_string($value) ."' WHERE id = ".$id);
  109. }
  110. showSearchForm();
  111. msg(count($updated) . " value(s) updated");
  112. runSearch();
  113. } else if ($action == "commit") {
  114. $counts = query_db("SELECT COUNT(*) cnt FROM sugar_lang_trx WHERE trx != '' and ref NOT IN (SELECT ref FROM sugar_lang_dico)");
  115. $count = $counts[0]->cnt;
  116. mysql_query("INSERT INTO sugar_lang_dico (ref,trx) SELECT ref,trx FROM sugar_lang_trx where trx != ''");
  117. mysql_query("DELETE FROM sugar_lang_trx where trx != ''");
  118. showSearchForm();
  119. msg("Commited ".$count." translation(s) to dictionary");
  120. runSearch();
  121. }
  122. } else {
  123. showSearchForm();
  124. }
  125. ?>
  126. </FORM>
  127. <BR>
  128. </BODY>
  129. </HTML>