PageRenderTime 54ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/translation/index.php

https://github.com/atutor/AChecker
PHP | 287 lines | 223 code | 46 blank | 18 comment | 73 complexity | 83ab5e72154673601bf9e5c36a403fd2 MD5 | raw file
  1. <?php
  2. /************************************************************************/
  3. /* AChecker */
  4. /************************************************************************/
  5. /* Copyright (c) 2008 - 2011 */
  6. /* Inclusive Design Institute */
  7. /* */
  8. /* This program is free software. You can redistribute it and/or */
  9. /* modify it under the terms of the GNU General Public License */
  10. /* as published by the Free Software Foundation. */
  11. /************************************************************************/
  12. // $Id$
  13. define('AC_INCLUDE_PATH', '../include/');
  14. include_once(AC_INCLUDE_PATH.'vitals.inc.php');
  15. include_once(AC_INCLUDE_PATH.'classes/DAO/DAO.class.php');
  16. include_once(AC_INCLUDE_PATH.'classes/DAO/LanguagesDAO.class.php');
  17. include_once(AC_INCLUDE_PATH.'classes/DAO/LanguageTextDAO.class.php');
  18. global $msg, $addslashes;
  19. $dao = new DAO();
  20. $languagesDAO = new LanguagesDAO();
  21. $languageTextDAO = new LanguageTextDAO();
  22. if (isset($_REQUEST['reset_filter'])) unset($_REQUEST);
  23. if (isset($_REQUEST['submit']) || isset($_REQUEST['search']))
  24. {
  25. if (isset($_REQUEST['submit']))
  26. {
  27. if (isset($_REQUEST['term_type']) && $_REQUEST['term_type'] <> '') $term_type = $_REQUEST['term_type'];
  28. $sql = "SELECT * FROM ".TABLE_PREFIX."language_text
  29. WHERE language_code='".DEFAULT_LANGUAGE_CODE."'";
  30. if ($term_type <> '') $sql .= " AND variable = '".$term_type."'";
  31. if (isset($_REQUEST['new_or_translated']) && ($_REQUEST['new_or_translated'] == 1 || $_REQUEST['new_or_translated'] == 2))
  32. {
  33. $subquery = "(SELECT term FROM ".TABLE_PREFIX."language_text
  34. WHERE language_code='".$_REQUEST['lang_code']."'
  35. AND text <> '')";
  36. if ($_REQUEST['new_or_translated'] == 1) $sql .= " AND term NOT IN ".$subquery;
  37. if ($_REQUEST['new_or_translated'] == 2) $sql .= " AND term IN ".$subquery;
  38. }
  39. if (isset($_REQUEST['new_or_translated']) && $_REQUEST['new_or_translated'] == 3)
  40. {
  41. $sql = "select * from ".TABLE_PREFIX."language_text a
  42. where language_code='".DEFAULT_LANGUAGE_CODE."'
  43. and exists (select 1 from ".TABLE_PREFIX."language_text b
  44. where language_code = '".$_REQUEST['lang_code']."'
  45. and a.term = b.term
  46. and a.revised_date > b.revised_date)";
  47. }
  48. }
  49. if (isset($_REQUEST['search']))
  50. {
  51. $sql = "SELECT * FROM ".TABLE_PREFIX."language_text
  52. WHERE language_code='".DEFAULT_LANGUAGE_CODE."'
  53. AND lower(term) like '%".$addslashes(strtolower(trim($_REQUEST['search_phase'])))."%'";
  54. }
  55. $rows = $dao->execute($sql);
  56. if (is_array($rows)) $num_results = count($rows);
  57. else $num_results = 0;
  58. }
  59. if (isset($_REQUEST["save"]))
  60. {
  61. $sql_save = "REPLACE INTO ".TABLE_PREFIX."language_text VALUES ('".$_POST["lang_code"]."', '".$_POST["variable"]."', '".$_POST["term"]."', '".$addslashes($_POST["translated_text"])."', NOW(), '')";
  62. if (!$dao->execute($sql_save)) {
  63. $success_error = '<div class="error">Error: changes not saved!</div>';
  64. }
  65. else {
  66. $success_error = '<div class="feedback2"">Success: changes saved.</div>';
  67. }
  68. }
  69. $rows_lang = $languagesDAO->getAll();
  70. include(AC_INCLUDE_PATH.'header.inc.php');
  71. ?>
  72. <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  73. <div class="input-form">
  74. <div class="row">
  75. <div class="required" title="<?php echo _AC('required_field'); ?>">*</div>
  76. <label for="lang_code"><?php echo _AC('choose_lang'); ?></label>:
  77. <select name="lang_code" id="lang_code">
  78. <?php
  79. foreach ($rows_lang as $row_lang)
  80. {
  81. ?>
  82. <option value="<?php echo $row_lang['language_code']; ?>" <?php if ($_REQUEST["lang_code"] == $row_lang['language_code'] || $row_lang['language_code'] == $_SESSION['lang']) echo 'selected="selected"'; ?>><?php echo htmlspecialchars($row_lang["english_name"]); ?></option>
  83. <?php
  84. }
  85. ?>
  86. </select>
  87. </div>
  88. <?php ?>
  89. <fieldset class="group_form"><legend class="group_form"><?php echo _AC('filter'); ?></legend>
  90. <?php if (isset($num_results)) { ?>
  91. <div class="row">
  92. <h2><?php echo _AC('results_found', $num_results); ?></h2>
  93. </div>
  94. <?php } ?>
  95. <div>
  96. <?php echo _AC('new_or_translated'); ?><br />
  97. <input type="radio" name="new_or_translated" value="0" id="u0" <?php if (!isset($_REQUEST['new_or_translated']) || $_REQUEST['new_or_translated'] == 0) { echo 'checked="checked"'; } ?> /><label for="u0"><?php echo _AC('all'); ?></label>
  98. <input type="radio" name="new_or_translated" value="1" id="u1" <?php if ($_REQUEST['new_or_translated'] == 1) { echo 'checked="checked"'; } ?> /><label for="u1"><?php echo _AC('new_terms'); ?></label>
  99. <input type="radio" name="new_or_translated" value="2" id="u2" <?php if ($_REQUEST['new_or_translated'] == 2) { echo 'checked="checked"'; } ?> /><label for="u2"><?php echo _AC('translated_terms'); ?></label>
  100. <input type="radio" name="new_or_translated" value="3" id="u3" <?php if ($_REQUEST['new_or_translated'] == 3) { echo 'checked="checked"'; } ?> /><label for="u3"><?php echo _AC('updated_terms'); ?></label>
  101. </div>
  102. <div>
  103. <?php echo _AC('term_type'); ?><br />
  104. <input type="radio" name="term_type" value="" id="t0" <?php if (!isset($_REQUEST['term_type']) || $_REQUEST['term_type'] == "") { echo 'checked="checked"'; } ?> /><label for="t0"><?php echo _AC('all'); ?></label>
  105. <input type="radio" name="term_type" value="_template" id="t1" <?php if ($_REQUEST['term_type'] == "_template") { echo 'checked="checked"'; } ?> /><label for="t1"><?php echo _AC('interface_terms'); ?></label>
  106. <input type="radio" name="term_type" value="_msgs" id="t2" <?php if ($_REQUEST['term_type'] == "_msgs") { echo 'checked="checked"'; } ?> /><label for="t2"><?php echo _AC('msg_terms'); ?></label>
  107. <input type="radio" name="term_type" value="_check" id="t3" <?php if ($_REQUEST['term_type'] == "_check") { echo 'checked="checked"'; } ?> /><label for="t3"><?php echo _AC('check_terms'); ?></label>
  108. <input type="radio" name="term_type" value="_guideline" id="t4" <?php if ($_REQUEST['term_type'] == "_guideline") { echo 'checked="checked"'; } ?> /><label for="t4"><?php echo _AC('guideline_terms'); ?></label>
  109. <input type="radio" name="term_type" value="_test" id="t5" <?php if ($_REQUEST['term_type'] == "_test") { echo 'checked="checked"'; } ?> /><label for="t5"><?php echo _AC('test_terms'); ?></label>
  110. </div>
  111. <div>
  112. <input type="submit" name="search" value="<?php echo _AC('search_phase'); ?>" class="submit" style="display:none;" />
  113. <input type="submit" name="submit" value="<?php echo _AC('submit'); ?>" class="submit" />
  114. <input type="submit" name="reset_filter" value="<?php echo _AC('reset_filter'); ?>" class="submit" />
  115. </div>
  116. <div>
  117. <label for="search_phase"><?php echo _AC('or'). ",<br /><br />" . _AC('search_text'); ?></label>
  118. </div>
  119. <div>
  120. <input size="60" type="text" name="search_phase" id="search_phase" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['search_phase'])); ?>" />
  121. </div>
  122. <div>
  123. <input type="submit" name="search" value="<?php echo _AC('search_phase'); ?>" class="submit" />
  124. </div>
  125. </fieldset>
  126. </div>
  127. </form>
  128. <?php
  129. if (isset($_REQUEST['selected_term']))
  130. {
  131. $sql_english = "SELECT * FROM ".TABLE_PREFIX."language_text WHERE language_code='".DEFAULT_LANGUAGE_CODE."' AND term='".$_REQUEST["selected_term"]."'";
  132. if ($_REQUEST["term_type"] <> "") $sql_english .= " AND variable='".$_REQUEST["term_type"]."' ";
  133. $rows_english = $dao->execute($sql_english);
  134. $row_english = $rows_english[0];
  135. $rows_selected = $languageTextDAO->getByTermAndLang($_REQUEST["selected_term"], $_REQUEST["lang_code"]);
  136. function trans_form() {
  137. global $row_english, $rows_selected;
  138. global $langs;
  139. global $success_error;
  140. global $db;
  141. global $addslashes;
  142. if (!is_array($rows_selected)) // add new term
  143. $add_new = true;
  144. else // update existing one
  145. {
  146. $row_selected = $rows_selected[0];
  147. $add_new = false;
  148. }
  149. ?>
  150. <br />
  151. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>#anchor">
  152. <input type="hidden" name="selected_term" value="<?php echo $_REQUEST['selected_term']; ?>" />
  153. <input type="hidden" name="lang_code" value="<?php echo $_REQUEST['lang_code']; ?>" />
  154. <input type="hidden" name="new_or_translated" value="<?php echo $_REQUEST['new_or_translated']; ?>" />
  155. <input type="hidden" name="term_type" value="<?php echo $_REQUEST['term_type']; ?>" />
  156. <input type="hidden" name="search_phase" value="<?php echo htmlspecialchars(stripslashes($_REQUEST['search_phase'])); ?>" />
  157. <input type="hidden" name="variable" value="<?php echo $row_english['variable']; ?>" />
  158. <input type="hidden" name="term" value="<?php echo $row_english['term']; ?>" />
  159. <?php if (isset($_REQUEST["submit"])) { ?>
  160. <input type="hidden" name="submit" value="1" />
  161. <?php } ?>
  162. <?php if (isset($_REQUEST["search"])) { ?>
  163. <input type="hidden" name="search" value="1" />
  164. <?php } ?>
  165. <table border="0" cellspacing="0" cellpadding="2" width="100%" align="left" class="box">
  166. <tr>
  167. <th class="box" colspan="2">Edit</th>
  168. </tr>
  169. <?php if ($row_english['context'] <> "") { ?>
  170. <tr>
  171. <td align="right"><b><?php echo _AC('english_context'); ?>:</b></td>
  172. <td><?php echo htmlspecialchars(stripslashes($row_english['context'])); ?></td>
  173. </tr>
  174. <tr>
  175. <td align="right"><b><?php echo _AC('translated_context'); ?>:</b></td>
  176. <td><input type="text" name="translated_context" class="input" value="<?php echo htmlspecialchars(stripslashes($row_selected['context'])); ?>" size="45" /></td>
  177. </tr>
  178. <?php } ?>
  179. <tr>
  180. <td valign="top" align="right" nowrap="nowrap"><b><?php echo _AC('english_text'); ?>:</b></td>
  181. <td><?php echo nl2br(htmlspecialchars(stripslashes($row_english['text']))); ?></td>
  182. </tr>
  183. <tr>
  184. <td valign="top" align="right" nowrap="nowrap"><b><label for="translated_text"><?php echo _AC('translated_text'); ?></label>:</b></td>
  185. <td><textarea rows="4" cols="75" name="translated_text" id="translated_text" class="input2"><?php echo htmlspecialchars(stripslashes($row_selected['text']));?></textarea></td>
  186. </tr>
  187. <tr>
  188. <td colspan="2" align="center"><input type="submit" name="save" value="Save ALT-S" class="submit" accesskey="s" />
  189. </td>
  190. </tr>
  191. </table>
  192. </form>
  193. <?php
  194. echo $success_error;
  195. }
  196. }
  197. //displaying templates
  198. if ($num_results > 0)
  199. {
  200. echo '<h3 class="indent">'. _AC("result") .'</h3>'."\n";
  201. echo '<div class="input-form">'."\n";
  202. echo '<br /><ul>'."\n";
  203. if (is_array($rows))
  204. {
  205. if (isset($_REQUEST["submit"]))
  206. $submits = htmlspecialchars(SEP)."submit=1";
  207. if (isset($_REQUEST["search"]))
  208. $submits .= htmlspecialchars(SEP)."search=1";
  209. foreach ($rows as $row)
  210. {
  211. if ($row['term'] == $_REQUEST["selected_term"])
  212. echo '<li>'."\n".'<a name="anchor" title="anchor"></a>'."\n";
  213. else
  214. echo '<li>'."\n";
  215. // if ($row['term'] == $_REQUEST["search_phase"]) {
  216. echo '<a href="'.$_SERVER['PHP_SELF'].'?selected_term='.$row['term'].htmlspecialchars(SEP).'lang_code='.$_REQUEST['lang_code'].htmlspecialchars(SEP).'new_or_translated='.$_REQUEST["new_or_translated"].htmlspecialchars(SEP).'term_type='.$_REQUEST["term_type"].htmlspecialchars(SEP).'search_phase='.$_REQUEST["search_phase"].$submits.'#anchor" ';
  217. if ($row['term'] == $_REQUEST["selected_term"]) echo 'class="selected"';
  218. echo '>';
  219. echo $row['term'];
  220. echo '</a>'."\n";
  221. // }
  222. // display if the term is new or translated
  223. $rows_check = $languageTextDAO->getByTermAndLang($row['term'], $_REQUEST['lang_code']);
  224. $row_check = $rows_check[0];
  225. // check if the term is new
  226. if ($row_check['text'] == '')
  227. echo '&nbsp;<small>*New*</small>'."\n";
  228. // compare revised_date to see if the term is updated since last translation
  229. if ($row_check['revised_date'] <> '' && $row['revised_date'] > $row_check['revised_date'])
  230. echo '&nbsp;<small>*Updated*</small>'."\n";
  231. echo '<br /><br/>';
  232. // display translation form
  233. if ($row['term'] == $_REQUEST["selected_term"]) trans_form();
  234. echo '</li>'."\n";
  235. }
  236. }
  237. echo '</ul>'."\n";
  238. echo '</div>'."\n";
  239. }
  240. include(AC_INCLUDE_PATH.'footer.inc.php');
  241. ?>