gobrien | 4827546 | 2007-11-29 21:29:17 +0000 | [diff] [blame] | 1 | <?php |
| 2 | /******************************************************************************* |
| 3 | * Copyright (c) 2007 Eclipse Foundation and others. |
| 4 | * All rights reserved. This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License v1.0 |
| 6 | * which accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Paul Colton (Aptana)- initial API and implementation |
| 11 | * Eclipse Foundation |
droy | 68ee494 | 2008-02-04 21:24:28 +0000 | [diff] [blame] | 12 | * Eclipse Contributors (bug 217257) |
syoshida | 4d3138f | 2015-10-12 17:25:55 +0900 | [diff] [blame] | 13 | * Satoru Yoshida - [373204] Babel server getting slow |
gobrien | 4827546 | 2007-11-29 21:29:17 +0000 | [diff] [blame] | 14 | *******************************************************************************/ |
| 15 | |
| 16 | require_once("cb_global.php"); |
| 17 | |
gobrien | 1bc0e19 | 2008-01-31 15:43:41 +0000 | [diff] [blame] | 18 | |
atoulme | 3e5e934 | 2009-01-23 17:34:30 +0000 | [diff] [blame] | 19 | $string_id = getHTTPParameter("string_id", "POST"); |
| 20 | $translation = getHTTPParameter("translation", "POST"); |
| 21 | $fuzzy_state = getHTTPParameter("fuzzy", "POST"); |
gobrien | 1c01c75 | 2008-01-10 18:34:31 +0000 | [diff] [blame] | 22 | |
| 23 | $language_id = $_SESSION["language"]; |
| 24 | $project_id = $_SESSION['project']; |
gobrien | 755df67 | 2008-01-18 01:01:33 +0000 | [diff] [blame] | 25 | $version = $_SESSION["version"]; |
| 26 | |
gobrien | 4827546 | 2007-11-29 21:29:17 +0000 | [diff] [blame] | 27 | $user_id = $User->userid; |
| 28 | |
droy | 2da63a1 | 2008-03-27 18:13:05 +0000 | [diff] [blame] | 29 | # TODO: refactor these ifs |
| 30 | $do_nothing = false; |
| 31 | |
droy | c62694d | 2008-05-14 18:51:30 +0000 | [diff] [blame] | 32 | $affected_rows = 0; |
| 33 | |
droy | 68ee494 | 2008-02-04 21:24:28 +0000 | [diff] [blame] | 34 | if (empty($translation) || (trim($translation) == '')) { |
| 35 | |
droy | 2da63a1 | 2008-03-27 18:13:05 +0000 | [diff] [blame] | 36 | $do_nothing = true; |
droy | 68ee494 | 2008-02-04 21:24:28 +0000 | [diff] [blame] | 37 | |
| 38 | } else if($_POST['translate_action'] != "all"){ |
gobrien | 34a08cb | 2008-02-06 18:44:48 +0000 | [diff] [blame] | 39 | $query = "update |
| 40 | translations |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 41 | set |
gobrien | 34a08cb | 2008-02-06 18:44:48 +0000 | [diff] [blame] | 42 | is_active = 0 |
| 43 | where |
| 44 | string_id = '".addslashes($string_id)."' |
| 45 | and |
| 46 | language_id = '".addslashes($language_id)."' |
| 47 | and |
| 48 | is_active = 1 |
| 49 | "; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 50 | $res = mysqli_query($dbh, $query); |
gobrien | 34a08cb | 2008-02-06 18:44:48 +0000 | [diff] [blame] | 51 | |
| 52 | $query = "insert into |
| 53 | translations |
| 54 | set |
| 55 | string_id = '".addslashes($string_id)."', |
| 56 | language_id = '".addslashes($language_id)."', |
| 57 | value = '".addslashes($translation)."', |
| 58 | userid = '".addslashes($user_id)."', |
droy | e3dc111 | 2008-11-19 18:21:28 +0000 | [diff] [blame] | 59 | possibly_incorrect = '".addslashes($fuzzy_state)."', |
gobrien | 34a08cb | 2008-02-06 18:44:48 +0000 | [diff] [blame] | 60 | created_on = NOW() |
| 61 | "; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 62 | $res = mysqli_query($dbh, $query); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 63 | $affected_rows += mysqli_affected_rows($dbh); |
gobrien | c5749b7 | 2008-02-28 21:43:51 +0000 | [diff] [blame] | 64 | |
gobrien | 198300d | 2008-03-04 23:22:36 +0000 | [diff] [blame] | 65 | // print $query; |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 66 | }else{ |
gobrien | 34a08cb | 2008-02-06 18:44:48 +0000 | [diff] [blame] | 67 | //FIND ALL STRINGS THAT ARE THE SAME ACROSS VERSIONS |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 68 | $query = "select |
droy | a102afc | 2008-05-21 19:15:42 +0000 | [diff] [blame] | 69 | s.string_id |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 70 | from |
droy | a102afc | 2008-05-21 19:15:42 +0000 | [diff] [blame] | 71 | strings as s |
| 72 | INNER JOIN files AS f on s.file_id = f.file_id |
| 73 | INNER JOIN files AS the_file_selected_for_translation on the_file_selected_for_translation.file_id = (select file_id from strings where string_id = '".addslashes($string_id)."') |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 74 | where |
droy | a102afc | 2008-05-21 19:15:42 +0000 | [diff] [blame] | 75 | s.value = (select value from strings where string_id = '".addslashes($string_id)."') |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 76 | and |
droy | a102afc | 2008-05-21 19:15:42 +0000 | [diff] [blame] | 77 | s.name = (select name from strings where string_id = '".addslashes($string_id)."') |
| 78 | and f.name = the_file_selected_for_translation.name |
| 79 | and f.project_id = the_file_selected_for_translation.project_id |
| 80 | and s.is_active = 1"; |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 81 | |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 82 | $res = mysqli_query($dbh, $query); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 83 | while($row = mysqli_fetch_assoc($res)){ |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 84 | $string_ids[] = $row['string_id']; |
| 85 | } |
| 86 | |
| 87 | //GET CURRENT TRANSLATION FOR THIS STRING |
droy | a102afc | 2008-05-21 19:15:42 +0000 | [diff] [blame] | 88 | $query= "select value from translations where string_id = '".addslashes($string_id)."' and language_id = '".addslashes($language_id)."' and is_active = 1 order by version limit 1"; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 89 | $res = mysqli_query($dbh, $query); |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 90 | $string_translation = ""; |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 91 | while($row = mysqli_fetch_assoc($res)){ |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 92 | $string_translation = $row['value']; |
| 93 | } |
| 94 | |
| 95 | //GET ALL STRINGS WITH SAME TRANSLATIONS |
| 96 | if($string_translation){ |
| 97 | $query = " |
| 98 | select |
gobrien | 70d6664 | 2008-02-06 18:50:40 +0000 | [diff] [blame] | 99 | translation_id,string_id,language_id |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 100 | from |
| 101 | translations |
| 102 | where |
| 103 | string_id in (".addslashes(implode(',',$string_ids)).") |
| 104 | and |
| 105 | value = '".addslashes($string_translation)."' |
| 106 | and |
| 107 | is_active = 1 |
droy | a102afc | 2008-05-21 19:15:42 +0000 | [diff] [blame] | 108 | and language_id = '" . addslashes($language_id)."' |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 109 | "; |
gobrien | 755df67 | 2008-01-18 01:01:33 +0000 | [diff] [blame] | 110 | |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 111 | $res = mysqli_query($dbh, $query); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 112 | while($row = mysqli_fetch_assoc($res)){ |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 113 | //DE-ACTIVATE ALL OLD TRANSLATIONS |
| 114 | $query = "update translations set is_active = 0 where translation_id = '".addslashes($row['translation_id'])."'"; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 115 | $res2 = mysqli_query($dbh, $query); |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 116 | |
| 117 | //INSERT NEW TRANSLATIONS |
| 118 | $query = "insert into |
| 119 | translations |
| 120 | set |
| 121 | string_id = '".addslashes($row['string_id'])."', |
gobrien | 70d6664 | 2008-02-06 18:50:40 +0000 | [diff] [blame] | 122 | language_id = '".addslashes($row['language_id'])."' , |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 123 | value = '".addslashes($translation)."', |
| 124 | userid = '".addslashes($user_id)."', |
droy | e3dc111 | 2008-11-19 18:21:28 +0000 | [diff] [blame] | 125 | possibly_incorrect = '".addslashes($fuzzy_state)."', |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 126 | created_on = NOW() |
| 127 | "; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 128 | $res2 = mysqli_query($dbh, $query); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 129 | $affected_rows += mysqli_affected_rows($dbh); |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 130 | |
| 131 | } |
gobrien | 755df67 | 2008-01-18 01:01:33 +0000 | [diff] [blame] | 132 | |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 133 | }else{ |
| 134 | $query = " |
| 135 | select |
| 136 | strings.string_id |
| 137 | from |
| 138 | strings |
| 139 | left join |
| 140 | translations |
| 141 | on |
| 142 | strings.string_id = translations.string_id |
| 143 | and |
| 144 | translations.value is NULL |
| 145 | where |
| 146 | strings.string_id in (".addslashes(implode(',',$string_ids)).") |
| 147 | "; |
gobrien | 755df67 | 2008-01-18 01:01:33 +0000 | [diff] [blame] | 148 | |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 149 | $res = mysqli_query($dbh, $query); |
gobrien | 755df67 | 2008-01-18 01:01:33 +0000 | [diff] [blame] | 150 | |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 151 | while($row = mysqli_fetch_assoc($res)){ |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 152 | $translation_ids[] = $row['string_id']; |
| 153 | //INSERT NEW TRANSLATIONS |
| 154 | $query = "insert into |
| 155 | translations |
| 156 | set |
| 157 | string_id = '".addslashes($row['string_id'])."', |
| 158 | language_id = '".addslashes($language)."' , |
| 159 | value = '".addslashes($translation)."', |
droy | e3dc111 | 2008-11-19 18:21:28 +0000 | [diff] [blame] | 160 | possibly_incorrect = '".addslashes($fuzzy_state)."', |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 161 | userid = '".addslashes($user_id)."', |
| 162 | created_on = NOW() |
| 163 | "; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 164 | $res2 = mysqli_query($dbh, $query); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 165 | $affected_rows += mysqli_affected_rows($dbh); |
droy | 2da63a1 | 2008-03-27 18:13:05 +0000 | [diff] [blame] | 166 | } |
| 167 | } |
gobrien | d6da697 | 2008-01-26 00:28:20 +0000 | [diff] [blame] | 168 | } |
droy | 2da63a1 | 2008-03-27 18:13:05 +0000 | [diff] [blame] | 169 | |
| 170 | if(!$do_nothing) { |
| 171 | # Find all string_id's that have the same binary value as the one we're translating |
| 172 | # *and* have no translation yet, and update those too. |
droy | e3dc111 | 2008-11-19 18:21:28 +0000 | [diff] [blame] | 173 | if(!$fuzzy_state) { |
| 174 | $sql = "SELECT s.string_id, COUNT(t.string_id) AS tr_count |
| 175 | FROM strings AS s |
| 176 | LEFT JOIN translations AS t ON t.string_id = s.string_id AND t.language_id = '".addslashes($language_id)."' |
syoshida | 4d3138f | 2015-10-12 17:25:55 +0900 | [diff] [blame] | 177 | WHERE s.value = BINARY (select value from strings where string_id = '".addslashes($string_id)."') |
droy | e3dc111 | 2008-11-19 18:21:28 +0000 | [diff] [blame] | 178 | AND s.is_active = 1 AND t.value IS NULL GROUP BY s.string_id HAVING tr_count = 0"; |
droy | 2da63a1 | 2008-03-27 18:13:05 +0000 | [diff] [blame] | 179 | |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 180 | $res = mysqli_query($dbh, $sql); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 181 | $str_count = mysqli_affected_rows($dbh); |
droy | 2da63a1 | 2008-03-27 18:13:05 +0000 | [diff] [blame] | 182 | |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 183 | while($myrow = mysqli_fetch_assoc($res)) { |
droy | e3dc111 | 2008-11-19 18:21:28 +0000 | [diff] [blame] | 184 | $sql = "insert into |
| 185 | translations |
| 186 | set |
| 187 | string_id = " . $myrow['string_id'] . ", |
| 188 | language_id = '".addslashes($language_id)."', |
| 189 | value = '".addslashes($translation)."', |
| 190 | userid = '".addslashes($user_id)."', |
| 191 | created_on = NOW()"; |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 192 | mysqli_query($dbh, $sql); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 193 | $affected_rows += mysqli_affected_rows($dbh); |
droy | e3dc111 | 2008-11-19 18:21:28 +0000 | [diff] [blame] | 194 | } |
droy | 2da63a1 | 2008-03-27 18:13:05 +0000 | [diff] [blame] | 195 | } |
| 196 | } |
gobrien | 5239b3c | 2008-06-17 06:51:12 +0000 | [diff] [blame] | 197 | |
| 198 | $response['translationString'] = htmlspecialchars($translation); |
| 199 | |
| 200 | $response['translationArea'] = "<br /><br /><br /> |
droy | 749bf84 | 2008-07-17 16:10:42 +0000 | [diff] [blame] | 201 | <center><b>Translated $affected_rows string". ($affected_rows > 1 || $affected_rows == 0 ? "s" : "" ) ." across all Babel projects. |
gobrien | 5239b3c | 2008-06-17 06:51:12 +0000 | [diff] [blame] | 202 | </b></center>"; |
| 203 | |
| 204 | print json_encode($response); |
| 205 | |
| 206 | ?> |