<?php
session_start();

include "connection.php";

require_once ("loginfunctions.php");

$final_report="";

if(checkLoggedin()) 
{ 
}
else
{
 header("Location: index.php");
}

if( (isset($_GET['aid'])) && ($_GET['aid']!=''))
{
	$aid = $_GET['aid'];


	$qry = "select `imgname`,`tmb_img` from `gallery_image` where `aid`='$aid'";
	$res = mysql_query($qry) or die(mysql_error()) ;
	if(mysql_num_rows($res)>0)
	{
		while($row=mysql_fetch_array($res)	)
		{
		unlink("images/".$row['imgname']);
		unlink("images/".$row['tmb_img']);
		}
	}	
	
	$qry = "delete from `gallery_image` where `aid`='$aid'";
	mysql_query($qry) or die(mysql_error()) ;
	
	$qry = "delete from `pages` where `aid`='$aid'";
	$res = mysql_query($qry) or die(mysql_error()) ;
	if(mysql_affected_rows()==1){header("location:gallery_man.php");}
	else{}
}
?>

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<link href="css/dropdown.css" media="screen" rel="stylesheet" type="text/css" />
<link href="css/default.css" media="screen" rel="stylesheet" type="text/css" />
<title>GALLERY MANAGEMENT</title>
</head>

<body>

    <table width="100%" height="25" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td align="left"><img src="../images/logo2.jpg" border="0" height="70" width="322"/></td>
    <td align="right" valign="bottom">
    <?php include "menu.php"; ?>
    </td>
    </tr>
    </table>

    <table class="flasline" width="100%" height="5" border="0" cellspacing="0" cellpadding="0">
    <tr><td>
    </td></tr>
    </table>


    <table align="center" width="98%" style="margin-top:20px; text-align:center;">
    <tr>
    <td width="85%"></td>
    <td width="1%">|</td>
    <td width="5%"><a href="home.php">Home</a></td>
    <td width="1%">|</td>
    <td width="5%"><a href="gallery.php">Create </a></td>
    <td width="1%">|</td>
    </tr>
    </table>
  
  
<table width="800" align="center" cellpadding="6" cellspacing="2">

<tr><td colspan="6"><h3 align="center">GALLERY MANAGEMENT</h3></td></tr>

<?php
$query = "select * from `pages` where `type`='gallery' order by `aid` desc ";
$resultset = mysql_query($query);

if(mysql_num_rows($resultset)>0)
{
?>

<tr class="tdcolor">
<td width="2%" align="center">No.</td>
<td width="38%" align="center">Title</td>
<td width="15%" align="center">Image</td>
<td width="15%" align="center">Order</td>
<td width="10%" align="center">Status</td>
<td width="10%" align="center">Modify</td>
<td width="10%" align="center">Delete</td>
</tr>

	<?php
	$i=1;
    while($row=mysql_fetch_array($resultset))
    {
    ?>
    
    <tr bgcolor="#eeeeee">
    <td align="center"><?php echo $i;?></td>

    <td align="center"><?php echo $row['title'] ;?></td>
    
    
	<td align="center">
    
	<?php
	
    	
    $aid = $row['aid'];	
        
    $query1 = "select `tmb_img` from `gallery_image` where `aid`='$aid'";
	
    $resultset1 = mysql_query($query1);	
    
    if( mysql_num_rows($resultset1)>0 ){
    
    $row1 = mysql_fetch_array($resultset1);
    
    $img = $row1['tmb_img'];
    
	
    ?>
    
    <img src="gallery/<?=$img?>" width="60" height="60" />
    
    <? } ?>
    
    </td>
    <td align="center"><?=$row['slct']?></td>
    
    <td align="center">
  <?php 
    if($row['active']=="1")
    {
    echo '<img src="web_images/incorrect.png" width="20" height="20" />';
    echo "<br>"; 
    echo '<a href="changestatus.php?mod=1&aid='.$row['aid'].'&target=gallery_man.php">Activate?</a>';
    }
    else if($row['active']=="2")
    {
    echo '<img src="web_images/ok.png" width="20" height="20" />';
    echo "<br>";
    echo '<a href="changestatus.php?mod=2&aid='.$row['aid'].'&target=gallery_man.php">Suspend?</a>';
    }
    ?>
    </td>
    
<td align="center"><a href="gallery.php?aid=<?php echo $row['aid'];?>"><img src="web_images/edit.png" width="20" height="20" /></a></td>
<td align="center"><a href="gallery_man.php?aid=<?php echo $row['aid'];?>" onClick="return confirm('Are you sure you want to delete?')"><img src="web_images/delete.gif" width="20" height="20" /></a> 
</td>
</tr>
<?php
$i++;
}//end of while
}// end of if

?>
</table>

</body>
</html>
