<?php

function renderUploadForm() {
  $output = '<form enctype="multipart/form-data" action="index.php" method="POST">';
  $output .= 'Here you can upload your translation files: <input name="uploaded_file" type="file"/>';
  $output .= '<input type="submit" value="Upload" />';
  $output .= '</form>';
  return $output;
}

function processUpload($dir) {
  if (!isset ($_FILES['uploaded_file']))
    return "";
  
  $path_parts = pathinfo($_FILES['uploaded_file']['name']);
  /*if (($path_parts['filename'] != "TranslatPopMenu") && ($path_parts['filename'] != "TranslatMapMenu") 
   && ($path_parts['filename'] != "TranslatInterface") && ($path_parts['filename'] != "TranslatStamp"))
    return "<span class=errormessage>WARNING! The file hasn't been uploaded yet. Use the TranslatInterface.xxx, TranslatStamp.xxx, TranslatPopMenu.xxx or TranslatMapMenu.xxx file names, where xxx is the language code like 'hun'. The names are case-sensitive.</span>";
  */ 
  
  if ($path_parts['filename'] != "Translat_Int" && $path_parts['filename'] != "TranslatePG")
    return "<span class=errormessage>WARNING! The file hasn't been uploaded yet. Use the Translat_Int.xxx file name, where xxx is the language code like 'hun'. The names are case-sensitive.</span>";
  
  $targetpath = $dir ."/". basename( $_FILES['uploaded_file']['name']) ;
  
  if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $targetpath))
    return "The file ". basename( $_FILES['uploaded_file']['name']). " has been uploaded";
  else
    return "Sorry, there was a problem uploading your file.";
}
?>