<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}

$slideshow_delay = getSettingsValue('slideshow_delay');

if(isset($_POST['slideshow_delay']))
{
    $query = "UPDATE ".$tableprefix."settings SET  slideshow_delay = '" . mysql_real_escape_string($_POST['slideshow_delay']) . "' ";
    mysql_query($query) or die(mysql_error());
    $slideshow_delay = $_POST['slideshow_delay'];
    $message =  SLIDE_SHOW_SPEED."!!";
}


if(isset($_GET["txtSearch"]) and $_GET["txtSearch"]!="")
{
	$txtSearch = $_GET["txtSearch"];
	$cmbSearchType = $_GET["cmbSearchType"];
}
else if(isset($_POST["txtSearch"]) and $_POST["txtSearch"]!="")
{
	$txtSearch = $_POST["txtSearch"];
	$cmbSearchType = $_POST["cmbSearchType"];
}


/*---------Patch-----------*/


if(isset($_GET['msg']))
{
	$message = BANNER_DETAILS_UPDATED."!!";
}

/*---------Patch-----------*/

if($_GET['delete_permanent'] == 'N')
{

	switch($_GET['delete_status'])
	{
	
		CASE 'N':
			$delete_bannner = "UPDATE ".$tableprefix."homepagebanners SET deleted = 'Y' WHERE homepage_banner_id = ".$_GET['del_id'];
			mysql_query($delete_bannner) or die(mysql_error());
			
			header("Location:homepagebanners.php?page=".$_GET['page']."&txtSearch=".$_GET['txtSearch']);
			
		break;
		CASE 'Y':
			$delete_bannner = "UPDATE ".$tableprefix."homepagebanners SET deleted = 'N' WHERE homepage_banner_id = ".$_GET['del_id'];
			mysql_query($delete_bannner) or die(mysql_error());
			
			header("Location:homepagebanners.php?page=".$_GET['page']."&txtSearch=".$_GET['txtSearch']);
			
		break;	
	
	}
}
else if($_GET['delete_permanent'] == 'Y')
{

	$select_banner_images = "SELECT image FROM ".$tableprefix."homepagebanners WHERE homepage_banner_id = ".$_GET['del_id'];
	$result_banner_images = mysql_query($select_banner_images) or die(mysql_error());
	
	if(mysql_num_rows($result_banner_images) > 0)
	{
		while($banner_images_row = mysql_fetch_array($result_banner_images))	
		{
			unlink("../homepagebanners/".$banner_images_row['image']);
		}
	}
	
	
	$delete_banner = "DELETE FROM ".$tableprefix."homepagebanners WHERE homepage_banner_id = ".$_GET['del_id'];
	mysql_query($delete_banner) or die(mysql_error());
	
	header('Location:homepagebanners.php');

}


if(isset($_POST['gotoPage']))
{

	header("Location:".$_SERVER['PHP_SELF']."?page=".$_POST['gotoPage']);
	
		
}


$qryopt="";
if($txtSearch != "")
{
    $qryopt .= "  WHERE image  like '%" . addslashes($txtSearch) . "%'";
}
$sql  = " SELECT *
		  FROM ".$tableprefix."homepagebanners " . $qryopt . " order by homepage_banner_id DESC ";

	if(!(isset($pagenum)))
	{
		$pagenum = 1;
	} 
	
	$limit = getSettingsValue('npagination_limit');
	
	$page = isset($_GET['page'])? trim($_GET['page']):1;

	
	$page = $_GET['page'];
	
	if(empty($page))
	{
		$page = 1;
	}
	
	$result=mysql_query($sql) or die(mysql_error());						
	
	$totalrows = mysql_num_rows($result);
	
	$limitvalue = ($page - 1) * $limit;
	
	$query_string = " LIMIT $limitvalue, $limit";
	
	$sql = $sql.$query_string;
	   
	$rs = mysql_query($sql) or die(mysql_error());

	$numofpages = ceil($totalrows / $limit);

include "../includes/htmltop.php";
?>
<script language="JavaScript" type="text/JavaScript" src="../js/javascript_check.js"></script>
<script language="JavaScript" type="text/JavaScript">
function clickSearch()
{

  var form_name = new Array('txtSearch');		
  var display_name = new Array('Banner Name');
  var count = 1;	
 document.frmBanners.submit();	
  if(check_fields('frmBanners',form_name,display_name,count))	
  {
  
  	
	 document.frmBanners.submit();	
   
  }
  else
  {
  
  		return false;
  
  }
     
}


function deleteBanner()
{

			
	return confirm("<?php echo DELETE_BANNER_CONFIRM;?>!!")

}


function blockBanner(val)
{

			
	if(val == 'N')
	{

		return confirm("<?php echo DISABLE_BANNER_CONFIRM;?>!!")
	
	}
	else if(val == 'Y')
	{
	
		return confirm("<?php echo ENABLE_BANNER_CONFIRM;?>!!")
	
	}	

}


</script>

		<body>
		
		<center>
		
		<div align="right" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="right" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="right" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo HOMEPAGE_BANNERS;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
                    <br>
				<div align="left">																			
		
					<form action="" method="post" name="slideshow_delay">
                                            <table width="40%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
                                                <tr>
                                                	<td align="left" valign="middle">                                                       
                                                    	<strong><?php echo SLIDE_SHOW_SPEED;?> </strong> (<?php echo SECONDS;?>)&nbsp;&nbsp;</td><td>
                                                    	 <input type="text" name="slideshow_delay" size="10" maxlength="3" value="<?php echo(htmlentities($slideshow_delay)); ?>" class="textbox"> 
													</td>
                                                    <td align="left" valign="middle">
                                                    	&nbsp;&nbsp;&nbsp;<input type="submit" class="button" value="<?php echo BTN_UPDATE;?>" />
                                                    </td>
                                                    
                                                </tr>
                                            </table>
					</form>
					
					</div>							
					<div align="left">																			
		
					<form action="" method="get" name="frmBanners">

							<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
								<tr>
								<td width="75%" align="left" valign="middle" class=''>
									<?php echo SEARCH_BY_BAN_IMAGE;?>										
										<input type="text" name="txtSearch" size="20" maxlength="50" value="<?php echo(htmlentities($txtSearch)); ?>" class="textbox">
										<a onClick="return clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a>
										&nbsp;										
									</td></tr><tr>
                                                                    <td align="right"><a href="homepagebanner-add.php" style="cursor:pointer" class="add_new_button"><?php echo BTN_ADD_NEW; ?></a></td>
								</tr>								
							</table>
						
					
					</form>
					
					</div>
						
					<div align="left">
						
					<form action="" method="post" name="frmBanners1">
					
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
						
						<tr class="page_title2">
							<th width="3%" align="center">#</th>
							<th width="17%" class="boxalternatecolor2" align="right"><?php echo BAN_IMG_NAME;?></th>
							<th width="17%" align="center"><?php echo BANNER_IMAGE;?></th>
							<th width="13%" align="center"><?php echo ACTIVE;?></th>						
							<th width="22%" align="center"><?php echo ACTION;?></th>
						</tr>
<?php
if(mysql_num_rows($result) > 0 )
{
	$i = 1;
	
	while($row = mysql_fetch_array($rs))
	{
	
																															
?>
						<tr class="">
						<td align="center"><?php echo $i?></td>
						<td align="center"><?php echo $link .htmlentities($row["image"])."</a>";?></td>
							<td align="center"><img height="30" width="100" src="../homepagebanners/<?php echo $row["image"]?>"></td>
							<td align="center"><?php echo $row['deleted'] == 'Y' ? NO1 : YES ?></td>
							<td align="center"><a href="homepagebanner-edit.php?edit_id=<?php echo $row["homepage_banner_id"]?>&qstring=<?php echo $_SERVER['QUERY_STRING']?>"><img src="../images/btn_edit.gif" border="0" title="<?php echo TITLE_EDIT_BANNER; ?>"></a>&nbsp;/&nbsp;<a href="homepagebanners.php?del_id=<?php echo $row["homepage_banner_id"]?>&delete_status=<?php echo $row['deleted']?>&delete_permanent=Y" style="cursor:pointer" onClick="return deleteBanner('<?php echo $row['deleted']?>')"><img src="../images/btn_del.gif" border="0" title="<?php echo TITLE_DELETE_BANNER; ?>"></a>&nbsp;/&nbsp;
							
<?php

	
	if($row['deleted'] == "Y")
	{

?>									
                                                            <a href="homepagebanners.php?del_id=<?php echo $row["homepage_banner_id"]?>&delete_status=<?php echo $row['deleted']?>&delete_permanent=N&page=<?php echo $page?>&txtSearch=<?php echo $txtSearch?>" style="cursor:pointer" onClick="return blockBanner('<?php echo $row['deleted']?>')" class="enable_button"><?php echo LINK_ENABLE; ?></a>
									
<?php

	}
	else
	{
	
?>		
		
                                                            <a href="homepagebanners.php?del_id=<?php echo $row["homepage_banner_id"]?>&delete_status=<?php echo $row['deleted']?>&delete_permanent=N&page=<?php echo $page?>&txtSearch=<?php echo $txtSearch?>" style="cursor:pointer" onClick="return blockBanner('<?php echo $row['deleted']?>')" class="disable_button"><?php echo LINK_DISABLE; ?></a>
		
<?php		
	}
	
?>										
							
							
							
							</td>
							
						
							
							
							
						</tr>
<?php
	$i++;
	
	}
											
}
else
{
										
?>					
							<tr>
									<td align="center" valign="middle" colspan="6"  class="text_information"><?php echo NO_RECORDS_FOUND;?> !!</td>
							</tr>					
<?php										
}
							
							if($page > 1)
							{
								$pageprev = $page-1;
								
								$previous_page = "<a href=".$_SERVER['PHP_SELF']."?page=$pageprev alt='Previous' border='0'><img src='../images/previous_btn_admin.gif' alt='Next' border='0'/></a>";
								
							}
																											
																				
							if($page < $numofpages)
							{
								$pagenext = ($page + 1);
								
								$next = "<a href=".$_SERVER['PHP_SELF']."?page=$pagenext alt='Next' border='0'><img src='../images/next_btn_admin.gif' alt='Next' border='0'/></a>";
								
							}	



?>

								
										<tr>
											<td width="13%" align="right" valign="middle">
											<a onClick="Javascript:document.frmBanners1.submit();" style="cursor:pointer"><img src="../images/go_btn.gif" alt="" width="37" height="19" /></a>			
											<select name="gotoPage">
<?php
									for($i=1;$i<=$numofpages;$i++)
									{		
										
										
										if($i == $_GET['page'])
										{
											$page_selected = "selected";
										}
										else
										{
											$page_selected = "";
										}
										
										
?>									
									<option value="<?php echo $i?>" <?php echo $page_selected?>><?php echo $i?></option>
									
<?php
									}
									
?>									
										</select>	
															
										</td>
											<td align="left" valign="middle" class="page_nos" colspan="2"><?php echo PAGE."(".S.")";?> <?php echo $page ?>/<?php echo $numofpages?>&nbsp;&nbsp;<?php echo GO_TO;?></td>
											<td class="page_nos"  align="center" colspan="2"><?php echo $previous_page?>&nbsp;<?php echo $next?></td>
											
										</tr>
										</table>
										
										</form>
										
																	

						</div>
						
						
				<!--content area end-->
								
				</div>
				
								
					<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
?>