blob: 5e2e0005b3fcf670d17dbf32baf6b5ced51a5c80 [file] [log] [blame]
droy6b0166c2008-07-23 17:23:07 +00001<?php
2/*******************************************************************************
droy66dcd2c2019-09-18 15:28:36 -04003 * Copyright (c) 2008-2019 Eclipse Foundation and others.
droy6b0166c2008-07-23 17:23:07 +00004 * 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
syoshida90ca1df2015-10-12 17:02:33 +090011 * Satoru Yoshida - [470120] it is nice if translation hint will prefer front match.
droy6b0166c2008-07-23 17:23:07 +000012*******************************************************************************/
13require_once("cb_global.php");
14
atoulme3e5e9342009-01-23 17:34:30 +000015$tr_string = getHTTPParameter("tr_string", "POST");
droy6b0166c2008-07-23 17:23:07 +000016
syoshida90ca1df2015-10-12 17:02:33 +090017//if contains ampersand, remove before matching
18$tr_string = preg_replace('/\&/', '', $tr_string, 1);
19if (strlen(trim($tr_string)) < 1) {
20 return false;
21}
22
droy6b0166c2008-07-23 17:23:07 +000023if(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
syoshida90ca1df2015-10-12 17:02:33 +090031//At first, performs front match
droy04fa0d02010-01-08 20:36:55 +000032$query = "SELECT DISTINCT t.value
33FROM 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
syoshida90ca1df2015-10-12 17:02:33 +090036WHERE s.value like '" . addslashes($tr_string). "%'
droy04fa0d02010-01-08 20:36:55 +000037 AND t.is_active
droy04fa0d02010-01-08 20:36:55 +000038 AND t.language_id = '".addslashes($language)."'
39ORDER BY LENGTH(t.value) ASC LIMIT 15";
droy6b0166c2008-07-23 17:23:07 +000040
kitlo2c8d8a92018-04-19 13:25:09 -040041$res = mysqli_query($dbh, $query);
kitlo1d027092018-04-19 17:44:07 -040042if(mysqli_affected_rows($dbh) > 0) {
droy6b0166c2008-07-23 17:23:07 +000043 echo "<ul>";
droya3815a52019-09-25 12:49:18 -040044 while($line = mysqli_fetch_array($res, MYSQLI_ASSOC)){
syoshida90ca1df2015-10-12 17:02:33 +090045 echo "<li>", $line['value'], "</li>";
droy6b0166c2008-07-23 17:23:07 +000046 }
47 echo "</ul>";
48}
49else {
droy6b0166c2008-07-23 17:23:07 +000050
syoshida90ca1df2015-10-12 17:02:33 +090051 //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
droy66dcd2c2019-09-18 15:28:36 -040057 INNER JOIN release_trains as rt ON rt.train_id = tr.train_id AND rt.is_active
syoshida90ca1df2015-10-12 17:02:33 +090058 WHERE s.value like '%" . addslashes($tr_string). "%'
59 AND t.is_active
syoshida90ca1df2015-10-12 17:02:33 +090060 AND t.language_id = '".addslashes($language)."'
61 ORDER BY LENGTH(t.value) ASC LIMIT 15";
droy66dcd2c2019-09-18 15:28:36 -040062
kitlo2c8d8a92018-04-19 13:25:09 -040063 $res = mysqli_query($dbh, $query2);
kitlo1d027092018-04-19 17:44:07 -040064 if(mysqli_affected_rows($dbh) > 0) {
syoshida90ca1df2015-10-12 17:02:33 +090065 echo "<ul>";
droya3815a52019-09-25 12:49:18 -040066 while($line = mysqli_fetch_array($res, MYSQLI_ASSOC)){
syoshida90ca1df2015-10-12 17:02:33 +090067 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}
droy6b0166c2008-07-23 17:23:07 +000076?>