droy | 6b0166c | 2008-07-23 17:23:07 +0000 | [diff] [blame] | 1 | <?php |
| 2 | /******************************************************************************* |
droy | 66dcd2c | 2019-09-18 15:28:36 -0400 | [diff] [blame] | 3 | * Copyright (c) 2008-2019 Eclipse Foundation and others. |
droy | 6b0166c | 2008-07-23 17:23:07 +0000 | [diff] [blame] | 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 | * Eclipse Foundation - initial API and implementation |
syoshida | 90ca1df | 2015-10-12 17:02:33 +0900 | [diff] [blame] | 11 | * Satoru Yoshida - [470120] it is nice if translation hint will prefer front match. |
droy | 6b0166c | 2008-07-23 17:23:07 +0000 | [diff] [blame] | 12 | *******************************************************************************/ |
| 13 | require_once("cb_global.php"); |
| 14 | |
atoulme | 3e5e934 | 2009-01-23 17:34:30 +0000 | [diff] [blame] | 15 | $tr_string = getHTTPParameter("tr_string", "POST"); |
droy | 6b0166c | 2008-07-23 17:23:07 +0000 | [diff] [blame] | 16 | |
syoshida | 90ca1df | 2015-10-12 17:02:33 +0900 | [diff] [blame] | 17 | //if contains ampersand, remove before matching |
| 18 | $tr_string = preg_replace('/\&/', '', $tr_string, 1); |
| 19 | if (strlen(trim($tr_string)) < 1) { |
| 20 | return false; |
| 21 | } |
| 22 | |
droy | 6b0166c | 2008-07-23 17:23:07 +0000 | [diff] [blame] | 23 | if(isset($_SESSION['language']) and isset($_SESSION['version']) and isset($_SESSION['project'])){ |
| 24 | $language = $_SESSION['language']; |
| 25 | $version = $_SESSION['version']; |
| 26 | $project_id = $_SESSION['project']; |
| 27 | }else{ |
| 28 | return false; |
| 29 | } |
| 30 | |
syoshida | 90ca1df | 2015-10-12 17:02:33 +0900 | [diff] [blame] | 31 | //At first, performs front match |
droy | 04fa0d0 | 2010-01-08 20:36:55 +0000 | [diff] [blame] | 32 | $query = "SELECT DISTINCT t.value |
| 33 | FROM translations as t |
| 34 | INNER JOIN strings AS s ON s.string_id = t.string_id |
| 35 | INNER JOIN files AS f ON s.file_id = f.file_id |
syoshida | 90ca1df | 2015-10-12 17:02:33 +0900 | [diff] [blame] | 36 | WHERE s.value like '" . addslashes($tr_string). "%' |
droy | 04fa0d0 | 2010-01-08 20:36:55 +0000 | [diff] [blame] | 37 | AND t.is_active |
droy | 04fa0d0 | 2010-01-08 20:36:55 +0000 | [diff] [blame] | 38 | AND t.language_id = '".addslashes($language)."' |
| 39 | ORDER BY LENGTH(t.value) ASC LIMIT 15"; |
droy | 6b0166c | 2008-07-23 17:23:07 +0000 | [diff] [blame] | 40 | |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 41 | $res = mysqli_query($dbh, $query); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 42 | if(mysqli_affected_rows($dbh) > 0) { |
droy | 6b0166c | 2008-07-23 17:23:07 +0000 | [diff] [blame] | 43 | echo "<ul>"; |
droy | a3815a5 | 2019-09-25 12:49:18 -0400 | [diff] [blame] | 44 | while($line = mysqli_fetch_array($res, MYSQLI_ASSOC)){ |
syoshida | 90ca1df | 2015-10-12 17:02:33 +0900 | [diff] [blame] | 45 | echo "<li>", $line['value'], "</li>"; |
droy | 6b0166c | 2008-07-23 17:23:07 +0000 | [diff] [blame] | 46 | } |
| 47 | echo "</ul>"; |
| 48 | } |
| 49 | else { |
droy | 6b0166c | 2008-07-23 17:23:07 +0000 | [diff] [blame] | 50 | |
syoshida | 90ca1df | 2015-10-12 17:02:33 +0900 | [diff] [blame] | 51 | //At second, performs partial match |
| 52 | $query2 = "SELECT DISTINCT t.value |
| 53 | FROM translations as t |
| 54 | INNER JOIN strings AS s ON s.string_id = t.string_id |
| 55 | INNER JOIN files AS f ON s.file_id = f.file_id |
| 56 | INNER JOIN release_train_projects AS tr ON tr.project_id = f.project_id AND tr.version = f.version |
droy | 66dcd2c | 2019-09-18 15:28:36 -0400 | [diff] [blame] | 57 | INNER JOIN release_trains as rt ON rt.train_id = tr.train_id AND rt.is_active |
syoshida | 90ca1df | 2015-10-12 17:02:33 +0900 | [diff] [blame] | 58 | WHERE s.value like '%" . addslashes($tr_string). "%' |
| 59 | AND t.is_active |
syoshida | 90ca1df | 2015-10-12 17:02:33 +0900 | [diff] [blame] | 60 | AND t.language_id = '".addslashes($language)."' |
| 61 | ORDER BY LENGTH(t.value) ASC LIMIT 15"; |
droy | 66dcd2c | 2019-09-18 15:28:36 -0400 | [diff] [blame] | 62 | |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 63 | $res = mysqli_query($dbh, $query2); |
kitlo | 1d02709 | 2018-04-19 17:44:07 -0400 | [diff] [blame] | 64 | if(mysqli_affected_rows($dbh) > 0) { |
syoshida | 90ca1df | 2015-10-12 17:02:33 +0900 | [diff] [blame] | 65 | echo "<ul>"; |
droy | a3815a5 | 2019-09-25 12:49:18 -0400 | [diff] [blame] | 66 | while($line = mysqli_fetch_array($res, MYSQLI_ASSOC)){ |
syoshida | 90ca1df | 2015-10-12 17:02:33 +0900 | [diff] [blame] | 67 | echo "<li>", $line['value'], "</li>"; |
| 68 | } |
| 69 | echo "</ul>"; |
| 70 | } |
| 71 | else { |
| 72 | echo "No hints found. Press [clear] to start over."; |
| 73 | } |
| 74 | |
| 75 | } |
droy | 6b0166c | 2008-07-23 17:23:07 +0000 | [diff] [blame] | 76 | ?> |