header("Content-type: text/plain");
include "global.php";
InitPage("");
$headless = 1;
# See http://wiki.eclipse.org/Babel_/_Large_Contribution_Import_Process
#
# !!  IMPORTANT !!
# Set to 1 unless the translations were authored (and tested/reviewed in context) by professionals
# This doesn't mean all incoming translations will be fuzzy --
# only those that are 'replacing' a non-fuzzy one
$fuzzy = 1;
require dirname(__FILE__) . "/../file/file.class.php";
require_once "json_encode.php";
$pageTitle = "Babel - Import Translation archive";
$pageKeywords = "import,properties,translation,language,nlpack,pack,eclipse,babel";
$USER = getGenieUser()->userid;
$PROJECT_ID = "eclipse";
$VERSION = "3.3.1";
# TODO
$indir = "/tmp/tmp-babel/import";
chdir($indir);
# sub-structure: ./XX/eclipse/plugins/ where XX is the iso code for the language
exec('find . -type f', $lines);
# loop through files
foreach ($lines as $line) {
    $line = trim($line);
    echo $line . "<br />";
    if (preg_match("/^\\.\\/([a-zA-Z0-9_-]+)\\/(.+\\.properties)\$/", $line, $matches)) {
        $language = $matches[1];
        $file = $matches[2];
        # Find a matching file
 *    Kit Lo (IBM) - Bug 266250, Map file processor not running properly on live server
 *    Kit Lo (IBM) - Bug 272176, Support "bundle" element type in map file
 *    Kit Lo (IBM) - Bug 257332, NLS warnings appear unnecessarily in runtime log
 *    Kit Lo (IBM) - Bug 302834, Add plugin filtering supports to map files process
 *    Kit Lo (IBM) - [382800] CSSUIPluginResources.properties is missing on translator tool
*******************************************************************************/
$temp_dir = "/tmp/tmp-babel/";
$files = array();
$files_collected = array(array());
header("Content-type: text/plain");
include "global.php";
InitPage("");
$headless = 0;
if (!isset($User)) {
    echo "User not defined - running headless\n";
    $User = getGenieUser();
    $headless = 1;
}
require dirname(__FILE__) . "/../classes/file/file.class.php";
$html_spacer = "  ";
global $dbh;
$temp_downloads_dir = $temp_dir . "downloads/";
if (!is_dir($temp_downloads_dir)) {
    mkdir($temp_downloads_dir) || die("Cannot create a working directory");
}
chdir($temp_downloads_dir) || die("Cannot use working directory");
$sql = "SELECT * FROM map_files AS m \nINNER JOIN release_train_projects AS r ON r.project_id = m.project_id AND r.version = m.version \nINNER JOIN release_trains AS t on t.train_id = r.train_id \nWHERE m.is_active = 1 AND m.is_map_file = 1 AND t.is_active = 1";
$rs_maps = mysql_query($sql, $dbh);
while ($myrow_maps = mysql_fetch_assoc($rs_maps)) {
    $location = $myrow_maps['location'];
    $project_id = $myrow_maps['project_id'];