<?php
session_start();
 if(!($_SESSION['log'])){
	  header("Location:index.php");
	  }  
  	 include('includes/php/dbconnection.php');
	 
//////////////////////delete images11////////////

if($_REQUEST['page'])
{

 $delsql="delete from tbl_gallery where id=".$_REQUEST['page'];
if(mysql_query($delsql))
{

$_SESSION['msg']= "gallery Image Deleted Successfully";
	header("location:gallery.php");
	exit;
}

}	 
//////////////////////////////////////change sort order////////////	 
	 if(isset($_GET["action"]))
	{
		if($_GET["action"] == "up" && $_GET["id"] != "")
		{
		
			$page_id = $_REQUEST['id'];
			$sort_id = $_REQUEST["sort"];
			
			$query  =  "SELECT id, sort_order FROM  `tbl_gallery` Order By sort_order DESC";
			$result  =  mysql_query($query);
			$flag= 0;
			while($row  =  mysql_fetch_array($result))
			{
				if($row["id"] == $_GET["id"])
				{
						$sort_order1 = $row["sort_order"];
						$page_id1= $row["id"];
						$flag =1;
						
				}
				elseif($flag == 1)
				{
						$sort_order2 = $row["sort_order"];
						$page_id2= $row["id"];
						$flag= 0;
				}
			}
			
			if($sort_order2 != "")
			{
				$str="update  `tbl_gallery` set sort_order ='".$sort_order2."' where id=". $page_id1 ;
				mysql_query($str);
				$str2="update  `tbl_gallery` set sort_order='".$sort_order1."' where id=". $page_id2 ;
				mysql_query($str2);
			}
			header("Location: ".$_SERVER['HTTP_REFERER']);
	
		}
		elseif($_GET["action"] == "down" && $_GET["id"] != "")
		{
			$page_id = $_REQUEST['id'];
			$sort_id = $_REQUEST["sort"];
			$query  =  "SELECT id, sort_order FROM  `tbl_gallery` Order By sort_order ASC";
			$result  =  mysql_query($query);
			$flag= 0;
			while($row  =  mysql_fetch_array($result))
			{
				if($row["id"] == $_GET["id"])
				{
						$sort_order1 = $row["sort_order"]; 
						$page_id1= $row["id"];
						$flag =1;
				}
				elseif($flag == 1)
				{
						$sort_order2 = $row["sort_order"];
						$page_id2= $row["id"];
						$flag= 0;
				}
			}
			if($sort_order2 != "")
			{
				$str="update  `tbl_gallery` set sort_order='".$sort_order2."' where id=". $page_id1 ;
				mysql_query($str);
				$str2="update  `tbl_gallery` set sort_order='".$sort_order1."' where id=". $page_id2 ;
				mysql_query($str2);
			}
			header("Location: ".$_SERVER['HTTP_REFERER']);
		}
	}
////////////////end of change sort order////////////////	
?>
<script language="javascript" type="text/javascript">
function confirmDelete()
{
var agree=confirm("Are you sure you want to delete this city?");
if (agree)
	return true ;
else
	return false ;
}

  function confirm_entry(pageid)
            {
            input_box=confirm("Are you sure you want to delete this Gallery Image?");
            if (input_box==true)

            {
                window.location.replace("gallery.php?page="+pageid);
            }

                 /* else
                  {
                  // Output when Cancel is clicked
                  alert ("Delete Cancelled");
                  }*/

            }

</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?php echo $page_title;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="includes/css/style.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
</script>
<link href="includes/php/style.css" rel="stylesheet" type="text/css">
<link href="includes/css/main.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {color: #999999}
.style3 {color: #2788BF; }
-->
</style>
</head>
<body topmargin="0" bottommargin="0">
<table width="80%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0"  class="border-leftt">
  <tr> 
    <td height="10" colspan="2"><?php include('includes/php/top.php'); ?></td>
  </tr>
  <tr> 
    <td width="25%" valign="top" align="center"  bgcolor="#F2F2F4" style="padding-top:10px" class="cat_repeat"><?php include("includes/php/left_new.php");?></td>
    <td width="75%"  valign="top" class="border-right">
<form name="form1" method="post" action="">
  <table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="100%" colspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" class="heading-nml">&nbsp;&nbsp;Manage Gallery </td>
    </tr>

    <tr>
      <td class="err-mesage"><?php echo $_SESSION['msg']; unset($_SESSION['msg']);?></td>
      <td align="right"><span class="welcome-text" style="padding-left: 5px;"><a href="add_gallery.php"><img src="images/icons/add.png" width="20" height="20" border="0" align="absbottom">Add New</a></span></td>
    </tr>
    <tr><td colspan="2" align="center" class="err-mesage"><table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#EDA846" bgcolor="">
          <tr class="">
            <td>
			
			
			
			
			
			<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
				
                <tr class="cpHeading" bgcolor="#618e20">
                  <td width="40%" height="23" bgcolor="#2788BF"   style="padding-left: 5px; color:#FFFFFF;">Image Name </td>
				  <td width="20%" bgcolor="#2788BF"   style="padding-left: 5px; color:#FFFFFF;"> Status </td>
				  <td width="19%"   style="padding-left: 5px; color:#FFFFFF;" bgcolor="#2788BF">Order</td>
				  <td width="15%"   style="padding-left: 5px; color:#FFFFFF;" bgcolor="#2788BF">Edit</td>
				  <td width="6%" bgcolor="#2788BF"   style="padding-left: 5px; color:#FFFFFF;">Delete</td>
				  </tr>
                
				 <?php  
				$loginQuery = "SELECT * FROM tbl_gallery order by (sort_order) DESC";
				$loginResult = mysql_query($loginQuery)or die(mysql_error());
				while($row=mysql_fetch_array($loginResult))
				{
				 ?>
                <tr >
                  <td height="25" class="welcome-text" style="padding-left: 5px;"><?php echo $row['img_name'];?></td>
                  <td height="25" class="welcome-text" style="padding-left: 5px;"><?php  if($row['status']==1){echo 'Enable';} else {echo"Disable";}?> </td>
                  <td height="25" class="welcome-text" style="padding-left: 5px;">
				  
				 <a href='gallery.php?action=up&id=<?php echo $row['id']; ?>&sort=<?php echo $row['sort_order']; ?>'><img src="images/icons/up.gif" width="17" height="17" border="0"></a>
				  
				  
				  
				  <a href='gallery.php?action=down&id=<?php echo $row['id']; ?>&sort=<?php echo $row['sort_order']; ?>'><img src="images/icons/down.gif" width="17" height="17" border="0"></a>				  </td>
                  <td height="25" class="welcome-text" style="padding-left: 5px;">
				  
				  <a href="edit_gallery.php?page=<?php echo $row['id'];?>" class="style3"><img src="images/icons/edit.gif" width="20" height="20" border="0"></a>				  </td>
                  <td height="25" class="welcome-text" style="padding-left: 5px;">
				  
				  <a href="javascript:confirm_entry('<?php echo $row['id'];?>')"><img src="images/icons/delete.gif" width="17" height="17" border="0"></a>				</td>
                  </tr>
				<tr>
                  <td height="1" colspan="8" bgcolor="#dfd4d0"></td>
                </tr>
				<?php } ?>
            </table></td>
          </tr>
      </table>
	  </td>
    <tr>
      <td colspan="2" align="left">
	  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#EDA846">
          <tr>
            <td height="18" colspan="5" align="center">&nbsp;</td>
          </tr>
      </table></td>
    </tr>
  </table>
</form>
    </td>
  </tr>
  <tr> 
    <td height="10" colspan="2"><?php include('includes/php/bottom.php'); ?></td>
  </tr>
</table>
</body>
</html>