<?php include "../../db_function.php";
if(empty($_GET['p'])){
	$_GET['p']=1;
}

$aid=$_GET['aid'];
$table=$_GET['table'];
$fid=$_GET['fid'];
$falbumname=$_GET['falbumname'];
$fitem=$_GET['fitem'];
$ftype=$_GET['ftype'];
$folder_th="../../Site/images/".$_GET['folder_th']."/";
$folder="../../Site/images/".$_GET['folder']."/";
$folder_sth="../../Site/images/".$_GET['folder_sth']."/";
$action='?aid='.$aid.'&table='.$table.'&fid='.$fid.'&falbumname='.$falbumname.'&fitem='.$fitem.'&ftype='.$ftype.'&folder_th='.$_GET['folder_th'].'&folder='.$_GET['folder'].'&folder_sth='.$_GET['folder_sth'].'';

if(isset($_POST['subdelete'])){
	$id=$_POST['txtID'];
	//echo "<script>alert('".$id."');</script>";
	
	$str="SELECT * FROM $table WHERE $fid=$id";
	$sql=mysql_query($str);
	while($row=mysql_fetch_array($sql)){
		if($row[$ftype]==1){
			if(!empty($row[$fitem])){
			$dr=$row[$fitem];
			$file=fopen($folder.$dr,"w");
			fclose($file);
			unlink($folder.$dr);
			
			$file1=fopen($folder_th.$dr,"w");
			fclose($file1);
			unlink($folder_th.$dr);
			
			//$file2=fopen($folder_sth.$dr,"w");
			//fclose($file2);
			//unlink($folder_sth.$dr);
			}
		}
	}
	
	$delete = "DELETE FROM $table WHERE  $fid= $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" >
body{
	font-family:Arial;
}
#mainbody{
	
}
#upload {
	position:relative;
	padding:7px;
	cursor:pointer;
	margin-bottom:10px;
	font-weight:bold; font-size:16px;
	font-family:Arial, Helvetica, sans-serif;
	text-align:center;
	background:#f2f2f2;
	color:#3366cc;
	border:1px solid #999999;
	width:100px;
	-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;
}
#menu{
	color:#446fea;
	font-family:Arial;
	position:relative;
	padding:10px;
	width:760px;
	font-size:13px;
	background:#00237c;
}
#menu a{
	font-size:16px;
	font-weight:bold;
	text-decoration:none;;
}
</style>

</head>
<body>

<div id="menu">
	Please select kind of gallery: &nbsp;&nbsp;&nbsp;
	<a href="<?php echo $action."&p=1"; ?>" style="color:#<?php if($_GET['p']==1){echo 'db0303';}else{echo'9bb7ff';}?>;">Image</a>&nbsp;&nbsp;|&nbsp;&nbsp;
	<a href="<?php echo $action."&p=2"; ?>" style="color:#<?php if($_GET['p']==2){echo 'db0303';}else{echo'9bb7ff';}?>;">Video</a>
</div>
<?php
		$bottonimage="Browe";
		
		$str1="SELECT $fitem FROM $table WHERE $falbumname='$aid'";
		$sql1=mysql_query($str1);
		$num_rows1=mysql_num_rows($sql1);
		if ($num_rows1>0){
			$bottonimage="Add More";
		}
		
	if($_GET['p']==1){
		include "isimage.php";
	}else{
		include "isvideo.php";
	}
	
	if ($num_rows1>0){
	echo'
		<div id="mainbody" >
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
		<tr><td>';
		
		$str="SELECT * FROM $table WHERE $falbumname='$aid' ORDER BY  $fid DESC";
		//echo $str;
		$sql=mysql_query($str);
		while ($row=mysql_fetch_array($sql)){
			
				echo'
				<form name="editservices" method="POST" action="'.$action.'&p='.$_GET['p'].'" enctype="multipart/form-data">
				<span>
					<input type="hidden" name="txtID" value="'.$row[$fid].'" size="2" >
					<li class="view"><div style="position: relative;">';
					if($row[$ftype]==0){
						echo'<img src="'.$folder_th.$row[$fitem].'" height="100" />';
					}else if($row[$ftype]==1){
						echo'<img src="http://img.youtube.com/vi/'.$row[$fitem].'/default.jpg" height="100" />
						<img src="../../Site/images/play.png" style="position:absolute; top:30px; left:45px;">
						';
					}
				echo'	<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>
				';
		}
	}

?>
