<?php 
include "../../db_function.php";
if(isset($_POST['subdelete'])){
	$id=$_POST['txtID'];
	
	$str="SELECT image FROM tbl_moreimages WHERE id=$id";
	$sql=mysql_query($str);
	while($row=mysql_fetch_array($sql)){
		if(!empty($row['image'])){
			$dr=$row['image'];
			$file=fopen("../../Site/images/more_images/$dr","w");
			fclose($file);
			unlink("../../Site/images/more_images/$dr");
			
			$file1=fopen("../../Site/images/more_images/$dr","w");
			fclose($file1);
			unlink("../../Site/images/more_images/$dr");
		}
	}
	
	$delete = "DELETE FROM tbl_moreimages WHERE id= $id";
	mysql_query($delete);
				
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>AJAX File Upload - Web Developer Plus Demos</title>
<script type="text/javascript" src="js/jquery-1.3.2.js" ></script>
<script type="text/javascript" src="js/ajaxupload.3.5.js" ></script>
<style rel="stylesheet" type="text/css" >

#upload {
	position:relative;
	top:10px; padding:10px;
	cursor:pointer;
	font-weight:bold; font-size:16px;
	font-family:Arial, Helvetica, sans-serif;
	text-align:center;
	background:#f2f2f2;
	color:#3366cc;
	border:1px solid #ccc;
	width:120px;
	-moz-border-radius:5px; 
	-webkit-border-radius:5px;
}

.darkbg{
	background:#ddd !important;
}
#status{
	font-family:Arial; padding:0px;
}
ul#files{ list-style:none; padding:0; margin:0; }
ul#files li{ padding:5px; margin-top:10px; width:auto; float:left; margin-right:10px; position: relative;}
ul#files li img{ max-width:130px; max-height:150px; position: relative; }
.success{ background:#FFFFFF; border:1px solid #cccccc; }
.error{ background:#f0c6c3; border:1px solid #cc6622; }

.view{
	float:left;
	list-style:none;
	margin-left:3px;
	background:#FFFFFF; border:1px solid #cccccc;
	padding:3px;
	height:100px;
}
#oldimage{
	position: relative;
	background:red;
}
.icon-2{
	position: absolute;
	cursor:pointer;
	bottom:0;
	right:0;
	z-index:100;
	width:18px;
	border:0;
	float:right;
	height:18px;
	background:url('table_icon_2.png') no-repeat top left;
}
.icon-2:hover{
	background:url('table_icon_2.png') no-repeat bottom left;
}
</style>
<script type="text/javascript" >
	$(function(){
		var btnUpload=$('#upload');
		var status=$('#status');
		new AjaxUpload(btnUpload, {
			action: 'upload-file.php<?php echo'?aid='.$_GET['aid'].''; ?>',
			name: 'uploadfile',
			onSubmit: function(file, ext){
				 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
                    // extension is not allowed 
					status.text('Only JPG, PNG or GIF files are allowed');
					return false;
				}
				status.html('<img src="../facefiles/loading.gif" />');
			},
			onComplete: function(file, response){
				//On completion clear the status
				status.text('');
				//Add uploaded file to list
				if(response==="success"){
					$('<li></li>').appendTo('#files').html('<img src="../../Site/images/more_images/'+file+'" alt="" height="100" />').addClass('success');
				} else{
					$('<li></li>').appendTo('#files').text(file).addClass('error');
				}
			}
		});
		
	});
</script>
</head>
<body>
<?php
if (isset($_GET['view'])){
		$gid=$_GET['aid'];
		//$name=$_GET['name'];
	echo'
		<div id="mainbody">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
		<tr><td>
		<span id="status" style="color: #FF0000; font-weight: bold; font-size: 18px; position: relative; margin-left: 20px;">Images Size:&nbsp;&nbsp;(660 x 820)px</span>';?>
	
	<p>
	</td></tr>
	<tr><td>
	<div id="upload" ><span>Add more</span></div>
		<ul id="files" ></ul>
	</td></tr>
	</table>
	</p><br />
		<?php 
		
		$str="SELECT * FROM tbl_moreimages WHERE aid='$gid'";
		$sql=mysql_query($str);
			while ($row=mysql_fetch_array($sql)){			
				echo'
				<form name="" method="POST" action="index.php?aid='.$_GET['aid'].'&view" enctype="multipart/form-data">
				<span>
				<input type="hidden" name="txtID" value="'.$row['id'].'" size="2" />
					<li class="view"><div style="position: relative;"><img src="../../Site/images/more_images/'.$row['image'].'" height="100" /><br />
					<input type="submit" name="subdelete" value="" title="Delete" class="icon-2 info-tooltip" '; ?> onclick="return confirm('Are you sure want to delete this Item?')" <?php echo ' >
					</div></li>
				</span>
				</form>
				';
			}
		?>
		
	<?php
		echo'
		</div>
	';
}else{
	echo'
		<div id="mainbody" >
		<font style="font-family: Arial;font-size:16px;color:#444444;"><i>Click on the button to browse <b>'.$_GET['name'].'</b>';?>'s photos..</i></font>
		<!-- Upload Button, use any id you wish-->
		<div id="upload" ><span>Browse<span></div><span id="status" ></span>
		
		<ul id="files" ></ul>
</div> <?php 
	}
?>

</body>