<?php
session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");
include("Functions_Purchase.php");
include("Forms_DataGrid1.php");


$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$querylog=" select ifNull(login_upload,0) As login_upload ".
		  " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}



$vform   	 = $_GET['vform']; if ($vform == ""){$vform = $_POST["vform"];}
$porderid	 = $_GET['porderid']; if ($porderid == ""){$porderid = $_POST["porderid"];}
$prqstid	 = $_GET['prqstid']; if ($prqstid == "") $prqstid = $_POST['prqstid'];


$actionmode  = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}
$picturename = $_POST["picturename"]; if ($picturename == ""){$picturename = $_GET["picturename"];}



$dest_dir='DocumentUploads';
if (!is_dir($dest_dir))
	mkdir($dest_dir, 0700);
														
 if($vform=='materialreq') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

	$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
	$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
	
	$dest_dir='DocumentUploads';
	$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
	
	$foldername = 'DocumentUploads';
	$foldername1 = 'DocumentUploads'."/"."MaterialRequisition";
	$foldername2 = 'DocumentUploads'."/"."MaterialRequisition"."/".$prqstid;
								
										
	if (!is_dir($foldername))
			mkdir($foldername, 0700);
			
	if (!is_dir($foldername1))
			mkdir($foldername1, 0700);

	if (!is_dir($foldername2))
			mkdir($foldername2, 0700);
			
	$fp1 = fopen($tmpName1, 'r');
	$content1 = fread($fp1, $fileSize1);
	$content1 = addslashes($content1);
	fclose($fp1);
	if(!get_magic_quotes_gpc())
		$fileName1 = addslashes($fileName1);
	
	$dest1 = $foldername2.'/'.$fileName1;
	$r1 = move_uploaded_file ($tmpName1, $dest1);	
	$actionmode='';	
	
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/MaterialRequisition'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}

print <<<HERE

<head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />



<link rel="stylesheet" type="text/css" media="all" href="css/style.css">

 



<script type="text/javascript" language="javascript">

function show_picture(vimagename){

document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}
function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/MaterialRequisition'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)
	 echo"<tr>		
		<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo"<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>
		</tr>";




$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
		
$filepath = './DocumentUploads/MaterialRequisition'.'/'.$prqstid.'/'.$picturename;
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";

 
echo"</td></tr>";


}


														
														
else if($vform=='prequest') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

	$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
	$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
	
	$dest_dir='DocumentUploads';
	$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
	
	$foldername = 'DocumentUploads';
	$foldername1 = 'DocumentUploads'."/"."PurchaseRequest";
	$foldername2 = 'DocumentUploads'."/"."PurchaseRequest"."/".$prqstid;
								
										
	if (!is_dir($foldername))
			mkdir($foldername, 0700);
			
	if (!is_dir($foldername1))
			mkdir($foldername1, 0700);

	if (!is_dir($foldername2))
			mkdir($foldername2, 0700);
			
	$fp1 = fopen($tmpName1, 'r');
	$content1 = fread($fp1, $fileSize1);
	$content1 = addslashes($content1);
	fclose($fp1);
	if(!get_magic_quotes_gpc())
		$fileName1 = addslashes($fileName1);
	
	$dest1 = $foldername2.'/'.$fileName1;
	$r1 = move_uploaded_file ($tmpName1, $dest1);	
	$actionmode='';	
	
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/PurchaseRequest'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}

print <<<HERE

<head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){

document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}
function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/PurchaseRequest'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)
	 echo"<tr>		
		<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo"<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>
		</tr>";




$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
		
$filepath = './DocumentUploads/PurchaseRequest'.'/'.$prqstid.'/'.$picturename;
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";

 
echo"</td></tr>";


}

else 
if($vform=='purchase') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."Purchase";
								$foldername2 = 'DocumentUploads'."/"."Purchase"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
										
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !=''){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/Purchase'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){

document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}
function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/Purchase'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)
	/* echo"<tr>		
		<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\"></span></td>
		</tr>";
*/
	echo"<tr>		
		<td align='left'><span class='style1'><a href='./DocumentUploads/Purchase/".$prqstid."/".$filename."'>$filename</a>";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo"<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</tr>";

$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='.pdf,image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";

		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;											
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
		
$filepath = './DocumentUploads/Purchase'.'/'.$prqstid.'/'.$picturename;
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";

 
echo"</td></tr>";


}

else 
if($vform=='GRN') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

	$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
	$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
	
	$dest_dir='DocumentUploads';
	$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
	
	$foldername = 'DocumentUploads';
	$foldername1 = 'DocumentUploads'."/"."GRN";
	$foldername2 = 'DocumentUploads'."/"."GRN"."/".$prqstid;
	
			
					if (!is_dir($foldername))
							mkdir($foldername, 0700);
							
					if (!is_dir($foldername1))
							mkdir($foldername1, 0700);
				
					if (!is_dir($foldername2))
							mkdir($foldername2, 0700);
							
					$fp1 = fopen($tmpName1, 'r');
					$content1 = fread($fp1, $fileSize1);
					$content1 = addslashes($content1);
					fclose($fp1);
					if(!get_magic_quotes_gpc())
						$fileName1 = addslashes($fileName1);
					
					$dest1 = $foldername2.'/'.$fileName1;
					$r1 = move_uploaded_file ($tmpName1, $dest1);	
			
					$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !=''){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/GRN'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){

document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}
function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/GRN'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)
	/* echo"<tr>		
		<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\"></span></td>
		</tr>";
*/
	echo"<tr>		
		<td align='left'><span class='style1'><a href='./DocumentUploads/GRN/".$prqstid."/".$filename."'>$filename</a>";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo"<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</tr>";

$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='.pdf,image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";

		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;											
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
		
$filepath = './DocumentUploads/GRN'.'/'.$prqstid.'/'.$picturename;
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";

 
echo"</td></tr>";


}

else if($vform=='purchaseorder') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $porderid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."PurchaseOrder";
								$foldername2 = 'DocumentUploads'."/"."PurchaseOrder"."/".$porderid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
										
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $porderid !=''){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/PurchaseOrder'.'/'.$porderid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){

document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}
function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/PurchaseOrder'.'/'.$porderid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)
	 echo"<tr>		
		<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo"<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>
		</tr>";


$i+=1;
 }


echo"<tr><td><hr></td></tr>";


echo"<td>";



echo "<input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>";

echo"		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";

		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;											
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
		
$filepath = './DocumentUploads/PurchaseOrder'.'/'.$porderid.'/'.$picturename;
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";

 
echo"</td></tr>";


}

// modify here here 

else if($vform=='salesorder') {
	
	
	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}
	
	

if ($actionmode=='upload' and $porderid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."SalesOrder";
								$foldername2 = 'DocumentUploads'."/"."SalesOrder"."/".$porderid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
										
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $porderid !=''){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/SalesOrder'.'/'.$porderid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){

document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}
function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>

<style type = "text/css">
 
 table input{
 border: 0 transparent;min-height: 28px;font-size: 14px;cursor: pointer;background: #e4e4e4;color: blue;
 
 |

</style>

</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>
			
			$headermode
			
			
			
			</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=100%><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px   

>";

$arr=scandir('./DocumentUploads/SalesOrder'.'/'.$porderid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)
	 echo"<tr>		
		<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		
		
		
		
		if ($_GET['readonly'] == "readonly")
	
	{
		echo "&nbsp;";
	}
	else
	{
echo " <img src='img/delete.png'
		width='20' height='20' 
		onmouseover=\"style.cursor='pointer'\"
		style='cursor: pointer;' title='Remove File'
		onclick=\"removefile('$filename');\" >";		
	}
	
		
		
		
		
		echo "</span></td>
		</tr>";


$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td>";


echo "<!-- <input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>	-->";


if ($_GET['readonly'] == "readonly")
	
	{
		echo "&nbsp;";
	}
	else
	{
echo " <input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>	";		
	}


echo"	</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'>";


if ($_GET['readonly'] == "readonly")
	
	{
		echo "&nbsp;";
	}
	else
	{
echo " <input type='button' value='Submit' onclick='uploadimage()'>	";		
	}
	





echo "</span>";

		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;											
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
		
$filepath = './DocumentUploads/SalesOrder'.'/'.$porderid.'/'.$picturename;




$info = pathinfo($picturename);



//http://php.net/manual/en/function.in-array.php

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
$listofimageextensions = array(
"jpg" , "jpeg"  ,  "JPG"  ,  "JPEG" ,   "png"  ,  "PNG"  ,  "gif"  ,   "GIF" ,  "TIFF"  ,  "tiff"
);


//if ($info["extension"] == "png") { 

if (in_array($info["extension"], $listofimageextensions)) {

 echo"<img  src='$filepath' width='250px' height='250px'>";
 
}

else if ($info["extension"] == "pdf")
 {
	 // echo $filepath;
	 echo "
<embed src=\"$filepath\" width=\"500\" height=\"375\" type='application/pdf'>	 
	 ";
 }

 
 else
 {
		 echo "
<a href =\"$filepath\"
style = 
'
 
font-size: 11px;
text-align: center;
font-weight: bold;
text-decoration: none;
text-transform: uppercase;
color: blue;
'

 width=\"500\" height=\"375\"   > Download File  </a>	

 
	 "; 
 }
 
 

 
 
 
echo "</td></tr>";

 
echo"</td></tr>";


}


if($vform=='Sales') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."Sales";
								$foldername2 = 'DocumentUploads'."/"."Sales"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/Sales'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/Sales'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/Sales'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}

if($vform=='Salesorder') {
	
	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}
	 

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."Salesorder";
								$foldername2 = 'DocumentUploads'."/"."Salesorder"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/Salesorder'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/Salesorder'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/Salesorder'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}


if($vform=='Delivery') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."Delivery";
								$foldername2 = 'DocumentUploads'."/"."Delivery"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/Delivery'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/Delivery'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/Delivery'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}


if($vform=='Payment') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."Payment";
								$foldername2 = 'DocumentUploads'."/"."Payment"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/Payment'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/Payment'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/Payment'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}

if($vform=='IN') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."IN";
								$foldername2 = 'DocumentUploads'."/"."IN"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/IN'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/IN'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/IN'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}


if($vform=='OUT') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."OUT";
								$foldername2 = 'DocumentUploads'."/"."OUT"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/OUT'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/OUT'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/OUT'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}


if($vform=='Transfer') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."Transfer";
								$foldername2 = 'DocumentUploads'."/"."Transfer"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/Transfer'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/Transfer'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/Transfer'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}



if($vform=='ADJUSTMENT') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."ADJUSTMENT";
								$foldername2 = 'DocumentUploads'."/"."ADJUSTMENT"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/ADJUSTMENT'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/ADJUSTMENT'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/ADJUSTMENT'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}



if($vform=='Receipt') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."Receipt";
								$foldername2 = 'DocumentUploads'."/"."Receipt"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/Receipt'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/Receipt'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/Receipt'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}

if($vform=='CreditNote') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."CreditNote";
								$foldername2 = 'DocumentUploads'."/"."CreditNote"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/CreditNote'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/CreditNote'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/CreditNote'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}

if($vform=='DebitNote') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."DebitNote";
								$foldername2 = 'DocumentUploads'."/"."DebitNote"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/DebitNote'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/DebitNote'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/DebitNote'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}

if($vform=='PurchaseJV') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."PurchaseJV";
								$foldername2 = 'DocumentUploads'."/"."PurchaseJV"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/PurchaseJV'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/PurchaseJV'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/PurchaseJV'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}

if($vform=='SalesJV') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."SalesJV";
								$foldername2 = 'DocumentUploads'."/"."SalesJV"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

}

 if ($actionmode=='removeFile' and $prqstid !='' ){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/SalesJV'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}
print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
//alert(vimagename);
document.upload.actionmode.value='showpicture';
document.upload.picturename.value=vimagename;
document.upload.submit();
}

function uploadimage(){
document.upload.actionmode.value='upload';
document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/SalesJV'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)   {
	 echo"<tr>";		
	 echo"<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo "<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>";
		echo"</tr>";

 }
$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;	
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);	
$filepath = './DocumentUploads/SalesJV'.'/'.$prqstid.'/'.$picturename;


if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}




if($vform=='Journal') {

	if ( $_GET['readonly'] == "readonly")
	{
			$headermode = "View Documents";
	}
	else{
		$headermode = "Upload Documents";
	}

if ($actionmode=='upload' and $prqstid !=''){

								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								$tmpName1  = $_FILES['userfile1']['tmp_name'];$fileSize1 = $_FILES['userfile1']['size'];
								
								$dest_dir='DocumentUploads';
								$fileType1 = $_FILES['userfile1']['type'];$fileName1 = $_FILES['userfile1']['name'];
								
								$foldername = 'DocumentUploads';
								$foldername1 = 'DocumentUploads'."/"."Journal";
								$foldername2 = 'DocumentUploads'."/"."Journal"."/".$prqstid;
								
										
												if (!is_dir($foldername))
														mkdir($foldername, 0700);
														
												if (!is_dir($foldername1))
														mkdir($foldername1, 0700);
											
												if (!is_dir($foldername2))
														mkdir($foldername2, 0700);
														
												$fp1 = fopen($tmpName1, 'r');
												$content1 = fread($fp1, $fileSize1);
												$content1 = addslashes($content1);
												fclose($fp1);
												if(!get_magic_quotes_gpc())
													$fileName1 = addslashes($fileName1);
												
												$dest1 = $foldername2.'/'.$fileName1;
												$r1 = move_uploaded_file ($tmpName1, $dest1);	
												$actionmode='';	
												
								

} if ($actionmode=='removeFile' and $prqstid !=''){
	$picremoved = $_POST['picremoved'];
	$filepath1 = './DocumentUploads/Journal'.'/'.$prqstid.'/'.$picremoved;
	unlink ($filepath1);
	$actionmode='';
	$picremoved = '';
	$r1 = '2';
}


print <<<HERE

<head><head><title>Upload Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" language="javascript">

function show_picture(vimagename){
	document.upload.actionmode.value='showpicture';
	document.upload.picturename.value=vimagename;
	document.upload.submit();
}

function uploadimage(){
	document.upload.actionmode.value='upload';
	document.upload.submit();
}

function removefile(vimagename){
	document.upload.actionmode.value = 'removeFile';
	document.upload.picremoved.value = vimagename;
	document.upload.submit();
}
</script>
</head>
<body>
<form name='upload' method='post' enctype='multipart/form-data'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='picturename' value='$picturename'>
<input type='hidden' name='picremoved' value='$picremoved'>
HERE;

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='950px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Upload Documents</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  
		 
echo "<table border=0 width=450px><col width=250><col width=250><tr><td valign=top>";
echo "<table border=0 width=400px>";

$arr=scandir('./DocumentUploads/Journal'.'/'.$prqstid.'/');
 $i=0;   
 
 
foreach ($arr as $filename) {

 if ($i>1)
	 echo"<tr>		
		<td align='left'><span class='style1'><input type='button' value='$filename' style='width:250px' onclick=\"show_picture('$filename')\">";
		if ($login_upload==1 && $_GET['readonly'] == "readonly")
		echo"<img src='img/delete.png' width='20' height='20' onmouseover=\"style.cursor='pointer'\" style='cursor: pointer;' title='Remove File' onclick=\"removefile('$filename');\" >
		</span></td>
		</tr>";


$i+=1;
 }


echo"<tr><td><hr></td></tr>";
echo"<td><input type='file'  name='userfile1'    id='userfile1' style='width:200px;' accept='image/jpeg,image/gif'>		</td>";
	echo"<tr>		
<td colspan=1 align='center'><span class='style1'><input type='button' value='Submit' onclick='uploadimage()'></span>";


		if($r1==1)
			echo "<font color=red>Image Uploaded Successfully..</font>";
		else if($r1==2){ 
			echo "<font color=red> Image Was Successfully Deleted!</font>";			
			
		} $r1=0;
echo"</td>
</tr>";

 echo"</table>";
echo"<td>";
	
$xx = substr($picturename, -3);
	
	
 
	$filepath = './DocumentUploads/Journal'.'/'.$prqstid.'/'.$picturename;
	
if($xx!='pdf')	
 echo"<img src='$filepath' width='450px' height='500px'></td></tr>";
else
print <<<HERE
 <object data="$filepath" type="application/pdf" width="450" height="500">
 
  <p>It appears you don't have a PDF plugin for this browser.
  No biggie... you can <a href="myfile.pdf">click here to
  download the PDF file.</a></p>
  
</object>
HERE;
 
echo"</td></tr>";


}

echo "</table>";
 echo "</td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";			 
	echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:560px;' valign='top'></td>
		<td id='search-bottom3' style='height:34px; width:31px;' valign='top'></td>";
echo" </tr>";
print <<<HERE
</form>
</body>

HERE;


function findexts ($filename) 
{ 
$filename = strtolower($filename) ; 
$exts = split("[/\\.]", $filename) ; 
$n = count($exts)-1; 
$exts = $exts[$n];
return $exts; 
}
?>