blob: 7f7e2f4050b8d97ece68852f7a88ae69e78d8995 [file] [log] [blame]
gobrien48275462007-11-29 21:29:17 +00001<?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
droy68ee4942008-02-04 21:24:28 +000012 * Eclipse Contributors (bug 217257)
gobrien48275462007-11-29 21:29:17 +000013*******************************************************************************/
14
15require_once("cb_global.php");
16
gobriend6da6972008-01-26 00:28:20 +000017//print_r($_REQUEST);
gobrienad11d892007-12-19 08:33:25 +000018
droy2da63a12008-03-27 18:13:05 +000019// print_r($_POST);
gobrien1bc0e192008-01-31 15:43:41 +000020
gobrien48275462007-11-29 21:29:17 +000021$string_id = $App->getHTTPParameter("string_id", "POST");
22$translation = $App->getHTTPParameter("translation", "POST");
gobrien1c01c752008-01-10 18:34:31 +000023
24$language_id = $_SESSION["language"];
25$project_id = $_SESSION['project'];
gobrien755df672008-01-18 01:01:33 +000026$version = $_SESSION["version"];
27
gobrien48275462007-11-29 21:29:17 +000028$user_id = $User->userid;
29
droy2da63a12008-03-27 18:13:05 +000030# TODO: refactor these ifs
31$do_nothing = false;
32
droy68ee4942008-02-04 21:24:28 +000033if (empty($translation) || (trim($translation) == '')) {
34
droy2da63a12008-03-27 18:13:05 +000035 $do_nothing = true;
droy68ee4942008-02-04 21:24:28 +000036
37} else if($_POST['translate_action'] != "all"){
gobrien34a08cb2008-02-06 18:44:48 +000038 $query = "update
39 translations
gobriend6da6972008-01-26 00:28:20 +000040 set
gobrien34a08cb2008-02-06 18:44:48 +000041 is_active = 0
42 where
43 string_id = '".addslashes($string_id)."'
44 and
45 language_id = '".addslashes($language_id)."'
46 and
47 is_active = 1
48 ";
49 $res = mysql_query($query,$dbh);
50
51 $query = "insert into
52 translations
53 set
54 string_id = '".addslashes($string_id)."',
55 language_id = '".addslashes($language_id)."',
56 value = '".addslashes($translation)."',
57 userid = '".addslashes($user_id)."',
58 created_on = NOW()
59 ";
60 $res = mysql_query($query,$dbh);
gobrienc5749b72008-02-28 21:43:51 +000061
gobrien198300d2008-03-04 23:22:36 +000062// print $query;
gobriend6da6972008-01-26 00:28:20 +000063}else{
gobrien34a08cb2008-02-06 18:44:48 +000064 //FIND ALL STRINGS THAT ARE THE SAME ACROSS VERSIONS
gobriend6da6972008-01-26 00:28:20 +000065 $query = "select
66 string_id
67 from
68 strings,
69 files
70 where
71 files.file_id = strings.file_id
72 and
73 strings.value = (select value from strings where string_id = '".addslashes($string_id)."')
74 and
75 strings.name = (select name from strings where string_id = '".addslashes($string_id)."')
76 and
77 strings.is_active = 1
78 ";
79
80 $res = mysql_query($query,$dbh);
81
82 while($row = mysql_fetch_assoc($res)){
83 $string_ids[] = $row['string_id'];
84 }
85
86 //GET CURRENT TRANSLATION FOR THIS STRING
gobrien34a08cb2008-02-06 18:44:48 +000087 $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";
gobriend6da6972008-01-26 00:28:20 +000088 $res = mysql_query($query,$dbh);
89 $string_translation = "";
90 while($row = mysql_fetch_assoc($res)){
91 $string_translation = $row['value'];
92 }
93
94 //GET ALL STRINGS WITH SAME TRANSLATIONS
95 if($string_translation){
96 $query = "
97 select
gobrien70d66642008-02-06 18:50:40 +000098 translation_id,string_id,language_id
gobriend6da6972008-01-26 00:28:20 +000099 from
100 translations
101 where
102 string_id in (".addslashes(implode(',',$string_ids)).")
103 and
104 value = '".addslashes($string_translation)."'
105 and
106 is_active = 1
107 ";
gobrien755df672008-01-18 01:01:33 +0000108
gobriend6da6972008-01-26 00:28:20 +0000109 $res = mysql_query($query,$dbh);
110 while($row = mysql_fetch_assoc($res)){
111 //DE-ACTIVATE ALL OLD TRANSLATIONS
112 $query = "update translations set is_active = 0 where translation_id = '".addslashes($row['translation_id'])."'";
113 $res2 = mysql_query($query,$dbh);
114
115 //INSERT NEW TRANSLATIONS
116 $query = "insert into
117 translations
118 set
119 string_id = '".addslashes($row['string_id'])."',
gobrien70d66642008-02-06 18:50:40 +0000120 language_id = '".addslashes($row['language_id'])."' ,
gobriend6da6972008-01-26 00:28:20 +0000121 value = '".addslashes($translation)."',
122 userid = '".addslashes($user_id)."',
123 created_on = NOW()
124 ";
125 $res2 = mysql_query($query,$dbh);
126
127 }
gobrien755df672008-01-18 01:01:33 +0000128
gobriend6da6972008-01-26 00:28:20 +0000129 }else{
130 $query = "
131 select
132 strings.string_id
133 from
134 strings
135 left join
136 translations
137 on
138 strings.string_id = translations.string_id
139 and
140 translations.value is NULL
141 where
142 strings.string_id in (".addslashes(implode(',',$string_ids)).")
143 ";
gobrien755df672008-01-18 01:01:33 +0000144
145 $res = mysql_query($query,$dbh);
146
gobriend6da6972008-01-26 00:28:20 +0000147 while($row = mysql_fetch_assoc($res)){
148 $translation_ids[] = $row['string_id'];
149 //INSERT NEW TRANSLATIONS
150 $query = "insert into
151 translations
152 set
153 string_id = '".addslashes($row['string_id'])."',
154 language_id = '".addslashes($language)."' ,
155 value = '".addslashes($translation)."',
156 userid = '".addslashes($user_id)."',
157 created_on = NOW()
158 ";
159 $res2 = mysql_query($query,$dbh);
droy2da63a12008-03-27 18:13:05 +0000160 }
161 }
gobriend6da6972008-01-26 00:28:20 +0000162}
droy2da63a12008-03-27 18:13:05 +0000163
164if(!$do_nothing) {
165 # Find all string_id's that have the same binary value as the one we're translating
166 # *and* have no translation yet, and update those too.
167 $sql = "SELECT s.string_id, COUNT(t.string_id) AS tr_count
168 FROM strings AS s
169 LEFT JOIN translations AS t ON t.string_id = s.string_id AND t.language_id = '".addslashes($language_id)."'
170 WHERE BINARY s.value = (select value from strings where string_id = '".addslashes($string_id)."')
171 AND s.is_active = 1 AND t.value IS NULL GROUP BY s.string_id HAVING tr_count = 0";
172
173 $res = mysql_query($sql, $dbh);
174 $str_count = mysql_affected_rows();
175
176 while($myrow = mysql_fetch_assoc($res)) {
177 $sql = "insert into
178 translations
179 set
180 string_id = " . $myrow['string_id'] . ",
181 language_id = '".addslashes($language_id)."',
182 value = '".addslashes($translation)."',
183 userid = '".addslashes($user_id)."',
184 created_on = NOW()";
185 mysql_query($sql, $dbh);
186 }
droy8d8c2ce2008-04-08 01:44:40 +0000187
188 # refresh the scoreboard
189 # 25 of every 100 hits (25%) will clean up
190 if(rand(0, 100) < 25) {
191 require_once(BABEL_BASE_DIR . "classes/system/scoreboard.class.php");
192 $sb = new Scoreboard();
193 $sb->refresh();
194 }
droy2da63a12008-03-27 18:13:05 +0000195}
196
gobrien48275462007-11-29 21:29:17 +0000197?>