<?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>

<LINK REL="SHORTCUT ICON" HREF="images/cloud.ico" >

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

        
<meta http-equiv=content-type content="text/html; charset=GB2312">
    
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath1; ?>" rel=stylesheet media="(min-width: 641px)">
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath2; ?>" rel=stylesheet media="(min-width: 641px)">
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath3; ?>" rel=stylesheet media="(min-width: 641px)">
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath4; ?>" rel=stylesheet media="(min-width: 641px)">


<LINK href="<?php print $addon_path."theme/mobile/".$cssPath1; ?>" rel=stylesheet media="(max-width: 640px)">
<LINK href="<?php print $addon_path."theme/mobile/".$cssPath2; ?>" rel=stylesheet media="(max-width: 640px)">
<LINK href="<?php print $addon_path."theme/mobile/".$cssPath3; ?>" rel=stylesheet media="(max-width: 640px)">
<LINK href="<?php print $addon_path."theme/mobile/".$cssPath4; ?>" rel=stylesheet media="(max-width: 640px)">


<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>
   

<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(($fileType=="image/jpeg") or ($fileType=="image/pjpeg") or ($fileType=="image/gif"))
		{
						      
			//=========RESIZE===============
				$oSourceImage = imagecreatefromstring($content); 
						      
				$nWidth = imagesx($oSourceImage); // get original source image width
				$nHeight = imagesy($oSourceImage); // and height
							
				$img_ratio=$nHeight/$nWidth;
								
				// create small thumbnail
				if($file_resize_width!="")
				{
					$nDestinationWidth = $file_resize_width;
					$nDestinationHeight = $file_resize_width*$img_ratio;
                  	
				}
			    else
				{
					$nDestinationWidth = $nWidth;
					$nDestinationHeight = $nHeight;
					
				}         

				$oDestinationImage = imagecreatetruecolor($nDestinationWidth, $nDestinationHeight);
				imagecopyresized(
					$oDestinationImage, $oSourceImage,
					0, 0, 0, 0,
					$nDestinationWidth, $nDestinationHeight,
					$nWidth, $nHeight
				); // resize the image
							
				
				if($file_stamp_logo)
					{
								  
						$logo = imagecreatefromgif("../../".$file_stamp_path);
						imagealphablending ($logo, true);
						imagecopy($oDestinationImage, $logo, $nDestinationWidth-120, $nDestinationHeight-80, 0, 0, 120, 80);
						
					}	
				
				
			
				$content=$sBinaryThumbnail;
				$fileType="image/jpeg";	
				
				
				if($file_storage_method=="OS")
				{
					$content="";
				}
				else
				{
				 
				 	ob_start(); // Start capturing stdout.
					imageJPEG($oDestinationImage);
					$sBinaryThumbnail = ob_get_contents(); // the raw jpeg image data.
					$sBinaryThumbnail = addslashes($sBinaryThumbnail);
					ob_end_clean(); // Dump the stdout so it does not screw other output.
		
					$content=$sBinaryThumbnail;
				}
				$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 
										('blog_".$CurrentShopID.".gif',
										'$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));     			
				$photo_id=mysqli_insert_id($dbconn);			
						
							
				if($file_storage_method=="OS")
				{
					//imageGIF($oDestinationImage); // As though output to browser.
					imageJPEG($oDestinationImage ,"../../".$file_storage_folder.$photo_id.'.jpg');
				}
			
	
						      
				//======END of RESIZE============
		   			
			
		}				
        
    }
  
?>




<?php

if($_REQUEST["action"]=="DELETE")
{
  	
  	$delete_id=$_REQUEST["d"];
  	
	  if(is_writable("../../".$file_storage_folder.$delete_id.".jpg"))
	  {
		unlink("../../".$file_storage_folder.$delete_id.".jpg");
	  }  
	 	
    $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"];
			  if($line["fil_storage_method"]=="OS")
			  	{
			      echo "<img width=100 src='../../".$file_storage_folder.$line["fil_id"].".jpg' >";	
			 	}
			else
				{
				echo "<img width=100 src='../../mod/uploader/file.php?id=".$line["fil_id"]."' >";	
				}
			  
			  
			  echo "<br><br><input type=button class=button value='Remove File' onclick='delete_photo(".$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='checkbox' class='checkbox' name='pho_stamp' value='YES' ><font color=000000 size=1 > Stamp with Logo.</font><br><br>";
	 echo "<input type=submit value='Attach Now' name='upload' class=button ><br>";
	 
 	 echo "	</td></tr></table>";
	 echo "</form>";	
		
		
	}
?>


				
				
								
								
				




<script language=javascript>
function delete_photo(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>
