<?php
$addon_path="../../";

include $addon_path."includes/config.php";
include $addon_path."includes/database.php";
include $addon_path."includes/keyword.php";
include $addon_path."includes/function.php";
include $addon_path."includes/session.php";



?>

<html>
<head>
<title><?php echo $eox_browser_title; ?></title>

<meta http-equiv=content-type content="text/html; charset=GB2312">


<LINK href="<?php print $addon_path."theme/desktop/".$cssPath1; ?>" rel=stylesheet >
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath2; ?>" rel=stylesheet >
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath3; ?>" rel=stylesheet >
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath4; ?>" rel=stylesheet >
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath5; ?>" rel=stylesheet >



<LINK href="<?php print $addon_path.$fontPath; ?>" rel=stylesheet>




<script language="javascript" src="<?php print $addon_path.$jsPath1; ?>"></script>
<script language="javascript" src="<?php print $addon_path.$jsPath2; ?>"></script>
<script language="javascript" src="<?php print $addon_path.$jsPath3; ?>"></script>
<script language="javascript" src="<?php print $addon_path.$jsPath4; ?>"></script>
</head>

<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onload="mon_on_load_init()">
<table align=left width=100% ><tr><td>
<?php




if(isset($_POST['upload']) && $_FILES['uploader_file']['size'] > 0)
{
    $fileName = $_FILES['uploader_file']['name'];
    $tmpName  = $_FILES['uploader_file']['tmp_name'];
    $fileSize = $_FILES['uploader_file']['size'];
    $fileType = $_FILES['uploader_file']['type'];
    
    
    $fp= fopen($tmpName, 'r');
	$content = fread($fp, filesize($tmpName));
	
	//$content = addslashes($content);
	fclose($fp);
					
	if(!get_magic_quotes_gpc())
		{
		$fileName = addslashes($fileName);
	}


				if($file_storage_method=="OS")
				{
				  	$content2=$content;
					$content="";
				}
				
		$fileName_array=explode(".",$fileName);
		$ext=$fileName_array[count($fileName_array)-1];
			
				
				$query = "INSERT INTO t_".$key_table_prefix."_file
										(fil_name, 
										fil_size, 
										fil_type, 					
										fil_mod,
										fil_mod_id,
										fil_mod_field,	
										fil_storage_method,		
										fil_binary_content,
										CREATED_DATE,
										MODIFIED_DATE) 
						        		VALUES 
										('".$fileName."',
										'$fileSize', 
										'$fileType', 
										'".$_REQUEST["mod"]."',
										'".$_REQUEST["mod_id"]."',
										'".$_REQUEST["mod_field"]."',
										'$file_storage_method',
										'$content',
										'".date("Y-m-d H:i:s")."',
										'".date("Y-m-d H:i:s")."')";
										
				mysqli_query($dbconn,$query) or die('Photo Saving Fail - Err msg  '.mysqli_error($dbconn));     			
				$file_id=mysqli_insert_id($dbconn);			
						
				if($file_storage_method=="OS")
				{
					
				  	if($fp2=fopen(realpath("../../")."/".$file_storage_folder."".$file_id.".".$ext, 'a'))
					    {
					    fwrite($fp2, $content2);
					    fclose($fp2);
					  	}
					$content="";
				}			
			
			
	
						      
				//======END of RESIZE============
		   			
			
					
        
    }
  
?>




<?php

if($_REQUEST["action"]=="DELETE")
{
  	
  	$delete_id=$_REQUEST["d"];
  	$query="Select fil_name , fil_storage_method 
    	FROM t_".$key_table_prefix."_file 
		where fil_id='".$delete_id."' ;"; 
	$result = mysqli_query($dbconn,$query) or die("Unable to get data! - Err msg ". mysqli_error($dbconn));               //Your error message

	if($line_delete=mysqli_fetch_array($result,MYSQLI_ASSOC))
	{
		  $fileName_array=explode(".",$line_delete["fil_name"]);
			$ext=$fileName_array[count($fileName_array)-1];
		
		
		  if(is_writable("../../".$file_storage_folder.$delete_id.".".$ext.""))
		  {
			unlink("../../".$file_storage_folder.$delete_id.".".$ext."");
		  }  
		 	
	    $query_delete="delete from t_".$key_table_prefix."_file where fil_id='$delete_id';";
	    $result_delete = mysqli_query($dbconn,$query_delete) or die("Photo Deletion failed - Err msg ". mysqli_error($dbconn));
		
		
	}
	
	
    
}



?>



<?php
//Open File:

$query="Select fil_id, fil_name, fil_size, fil_type, fil_storage_method 
    	FROM t_".$key_table_prefix."_file 
		where fil_mod='".$_REQUEST["mod"]."' 
		and fil_mod_id='".$_REQUEST["mod_id"]."' 
		and fil_mod_field='".$_REQUEST["mod_field"]."' ;"; 
	  
$result = mysqli_query($dbconn,$query) or die("Unable to get data! - Err msg ". mysqli_error($dbconn));               //Your error message
$num_rows = mysqli_num_rows($result);

if($num_rows>0)
{
		if($line = mysqli_fetch_array($result, MYSQLI_ASSOC))
			{	
			 $storage_method=$line["fil_storage_method"];
			 
			$fileName_array=explode(".",$line["fil_name"]);
			$ext=$fileName_array[count($fileName_array)-1];
			
			
			  if($line["fil_storage_method"]=="OS")
			  	{
			      echo "<a href='../../".$file_storage_folder.$line["fil_id"].".".$ext."' target=_blank >".$line["fil_name"]."</a>";	
			 	}
			else
				{
				echo "<a href='../../mod/fuploader/file.php?id=".$line["fil_id"]."' >".$line["fil_name"]."</a>";	
				}
			  
			  
			  echo "<br><br><input type=button class='button button-red' value='Remove File' onclick='delete_file(".$line["fil_id"].")'>";
			}
}
else
	{
		
	 echo "<form name='uploader' action='' method='post' enctype='multipart/form-data' >";
	 echo "<table><tr><td valign=top >";
	 echo "<input size=10 type=file name='uploader_file' class=upload ><br><br>";
	 echo "<input type=hidden name='mod' value='".$_REQUEST["mod"]."' >";
	 echo "<input type=hidden name='mod_id'  value='".$_REQUEST["mod_id"]."' >";
	 echo "<input type=hidden name='mod_field'  value='".$_REQUEST["mod_field"]."' >";
	 echo "<input type=submit value='Attach Now' name='upload' class='button button-blue' ><br>";
	 
 	 echo "	</td></tr></table>";
	 echo "</form>";	
		
		
	}
?>


				
				
								
								
				




<script language=javascript>
function delete_file(id)
{
	  	if(confirm("Are you sure want to delete this file?"))
		  	{
		  	 
		  	window.location="index.php?action=DELETE&d="+id+"&mod=<?php echo $_REQUEST["mod"]; ?>&mod_id=<?php echo $_REQUEST["mod_id"]; ?>&mod_field=<?php echo $_REQUEST["mod_field"]; ?>";
			}
	
  
}
</script>

<?php
//include "../include/include_post_nofooter.php";
?>
</td></tr></table>
</body>