<?php
include_once("config.php");
include_once("bsw/utils.php");

if ($_REQUEST["performingUpload"] != "yes")
{
}
else
if ($_FILES["file"]["error"] > 0)
{
	$_REQUEST["currentWatchList"] = "NA";
	$_REQUEST["uploadWatchListStatus"] = "Upload file error: " . $_FILES["file"]["error"];
        }
else
{

        $uploadFileDir = __DIR__.DIRECTORY_SEPARATOR."upload_file";
        $filePath = $uploadFileDir.DIRECTORY_SEPARATOR;       
        if (!file_exists($uploadFileDir)) {
        mkdir($uploadFileDir, 0777, true);
        }
    		

	if (move_uploaded_file($_FILES["file"]["tmp_name"], $filePath. $_FILES["file"]["name"]))
		{
		$_REQUEST["currentWatchList"] = $_FILES["file"]["name"];			
		if (loadList($filePath, $_FILES["file"]["name"],$ivEntityMatcherService))
		{
			$query = "/IVEnvelope/Request/LoadWatchList/InputParameters/WatchList";
			$_REQUEST["watchListName"] = getWatchListName($filePath. "Watchlist.xml",$query);
			$_REQUEST["uploadWatchListStatus"] = "Target list: ". $_REQUEST["watchListName"] . " uploaded";
		}
		else 
			$_REQUEST["uploadWatchListStatus"] = "Load Target list failed" . ($errormsg || $errorcode? "with error message: " . $errormsg . ", code: " . $errorcode : "");
}
	else
	{
		$_REQUEST["uploadWatchListStatus"] = "Failed copying uploaded file";
	}
}
include('insertPage.php');
?>
