<?php
    session_start();    
    if(empty($_SESSION['Chhu0nM3ngNew$'])) header('location:login.php?goto=index');

	if(empty ($_GET['p'])){
		$_GET['p']="index";
	}

	include('templates/header.php'); 

?>
<body> 
<!-- Start: page-top-outer -->
<?php 
	
	include('templates/menu.php'); 
	include "../db_function.php";  

	
	$action="slider.php?p=slider";
	$par_paging="";
	
	if(!empty ($_GET['page'])){
		$action .= "&page=".$_GET['page']."";
	}
	if(!empty ($_GET['search'])){
		$action .= "&search=".$_GET['search']."";
		$par_paging .= "&search=".$_GET['search']."";
	}
	if(empty ($_GET['page'])){
		$_GET['page']=1;
	}
	
?>
<?php	

	$change="";
	$table="tbl_banner";
	$fid="banner_id";
	$fimage="banner_image";
	$uploadUrl1="../Site/images/slide/";
		
if(isset($_POST['save'])){
		
		
		$id = $_POST['txtID'];

		include('templates/resizeimage.php'); 
		$newwidth1=940;
		$newheight1=300;
		$uploadUrl2="";
		$newwidth2="";
		$newheight2="";
		$field="image";
		$mp3_album_image = mbResizeImage($table,$id,$field,$uploadUrl1,$newwidth1,$newheight1,$uploadUrl2,$newwidth2,$newheight2);
		
		if($mp3_album_image!==1) {
			
			$str5="SELECT $fimage FROM $table WHERE $fid=$id ";  
			$sql5=mysql_query($str5);
			while($row5=mysql_fetch_array($sql5)){
				if ($mp3_album_image=="2"){
						$mp3_album_image =$row5[$fimage];
					
				}else{
					if(!empty($row5[$fimage])){
					$dr1=$row5[$fimage];
					$file1=fopen("$uploadUrl1/$dr1","w");
					fclose($file1);
					unlink("$uploadUrl1/$dr1");
					}
				}
			}
			$str="UPDATE $table SET $fimage='$mp3_album_image'
			WHERE $fid=$id ";
			$suse=mysql_query($str);
			if($suse){
				$masg=0;
				}else{
				$masg=1;
				}
		}else{
			$masg = 2;
		}
	}// end if
	
//Delete here/////////////////////////////////////////////////////////////
		else if(isset($_POST['subdelete'])){
				$id=$_POST['txtID'];
				
				$str5="SELECT $fimage FROM $table WHERE $fid=$id ";  
				$sql5=mysql_query($str5);
				while($row5=mysql_fetch_array($sql5)){
						if(!empty($row5[$fimage])){
						$dr1=$row5[$fimage];
						$file1=fopen("$uploadUrl1/$dr1","w");
						fclose($file1);
						unlink("$uploadUrl1/$dr1");
						}
				}
				
				$delete = "DELETE FROM $table WHERE $fid= $id";
				mysql_query($delete);
				
				$masg=3;
				
		}
	
 ?>	
	
<!-- start content-outer ........................................................................................................................START -->
<div id="content-outer">
<!-- start content -->
<div id="content">

	<!--  start page-heading -->
	<div id="page-heading">
		<h1>Banner Slider</h1>
		
				<!--  start top-search -->
				
		
 	<!--  end top-search -->
 	<div class="clear"></div>
	</div>
	<!-- end page-heading -->

	
	
	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td>
		<!--  start content-table-inner ...................................................................... START -->
		<div id="content-table-inner">
		<?php
	if(isset($masg) && $masg==0 ){
	echo'
	<div id="message-green">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
		<tr>
			<td class="green-left">Your update success.</td>
			<td class="green-right"><a class="close-green"><img src="images/table/icon_close_green.gif" alt="" /></a></td>
		</tr>
		</table>
	</div>';
	}
	else if(isset($masg) && $masg==1){
	echo'
	<div id="message-red">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
			<tr>
					<td class="red-left">Your update is Fail. Please try again!</td>
				<td class="red-right"><a class="close-red"><img src="images/table/icon_close_red.gif"   alt="" /></a></td>
			</tr>
		</table>
	</div>';
	}
	else if(isset($masg) && $masg==2){
	echo'
	<div id="message-red">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
			<tr>
					<td class="red-left">Error Image Ilbum.</td>
				<td class="red-right"><a class="close-red"><img src="images/table/icon_close_red.gif"   alt="" /></a></td>
			</tr>
		</table>
	</div>';
	}
	else if(isset($masg) && $masg==3 ){
	echo'
	<div id="message-green">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
		<tr>
			<td class="green-left">Your delete suces.</td>
			<td class="green-right"><a class="close-green"><img src="images/table/icon_close_green.gif" alt="" /></a></td>
		</tr>
		</table>
	</div>';
	}
	?>
			<!--  start table-content  -->
			<div id="table-content">
			
				<!--  start Update Succes -->
			
				
				<!--  end message-green -->
		
		 
				<!--  start product-table ..................................................................................... -->
<?php
	include("include/paginator.php");
	//include the extension that makes the pre-made links
	include("include/paginator_html.php");
	//Makes the array used in this example.
	
	$query2 = "SELECT * FROM $table ";
	$result2=mysql_query($query2);
	echo mysql_error();
	$num_rows=mysql_num_rows($result2);
	
	$vlimit=3;
	//gets the total number of items
	//========================================================================
	//Parts used to make a new paginator 
	//========================================================================
	//Makes new Paginator_html.  Current page here is sent by the get method. 
	//$num_rows is the total items in the source.
	$a =new Paginator_html($_GET['page'],$num_rows);
//sets the number of records displayed
	//defaults to five
	$a->set_Limit($vlimit); 
	// if using numbered links this will set the number before and behind 
	//the current page.
	//defaults to five
	$a->set_Links(7);  
	//gets starting point.
	$limit1 = $a->getRange1();  
	//gets number of items displayed on page.
	$limit2 = $a->getRange2();  
	//=========================================================================
	//Printing out the items in the array
	?>
	<style rel="stylesheet"><!--
	tr.buztype:hover{
		background:#c8dfff;
	}
	.adminbox{
		border:1px solid #999999; 
	}
	.adminbox:focus{
		border:1px solid #94b52c; 
	}
	--></style>
				<table border="0" width="460" cellpadding="0" cellspacing="0" id="product-table">
				<tr>
					<th class="table-header-check"><a id="toggle-all" ></a> </th>
					<th class="table-header-repeat line-left minwidth-2"><a href="">Image</a></th>
					<th class="table-header-options line-left"><a href="">Options</a></th>
				</tr>
				
	<?php
	
	$query = "SELECT * FROM $table ORDER BY $fid DESC limit $limit1, $limit2 ";                                
    $result =mysql_query($query);
    echo mysql_error();
	$bgcolor="#d8d8d8";
	$j=1;
	while ($row = mysql_fetch_array($result))
	{
	
		echo'<form name="editservices" method="POST" action="'.$action.'" enctype="multipart/form-data">';
		echo'
		<tr class="buztype">
			<td><input name="checkbox" id="checkbox" type="checkbox"/></td>
				<input type="hidden" name="txtID" value="'.$row[$fid].'" />
			</td>
			<td>
				<img src="../Site/images/banners/'.$row[$fimage].'" height="250">
				<input type="file" name="image" size="100" style="border:0;"/>
			</td>
			<td class="options-width">
			<input type="submit" name="subdelete" value="&nbsp;" title="Delete" class="icon-2 info-tooltip" '; ?> onclick="return confirm('Are you sure want to delete this Item?')" <?php echo ' >
			<input type="submit" name="save" value="&nbsp;" title="Save" class="icon-5 info-tooltip">
			
			</td>
		</tr>
		
		';
		$j++;
		echo'</form>';
	}
	
	?>

		</table>		<!--  end product-table................................... --> 
	</form>
	
			</div>
			<!--  end content-table  -->
		
			<!--  start actions-box ............................................... -->
		
			<!-- end actions-box........... -->
			
			<!--  start paging..................................................... -->
			<table border="0" cellpadding="0" cellspacing="0" id="paging-table">
			<tr>
			<td valign="top" class="paging">
			<?php
			$a->previousNext($par_paging);
	echo '<br /><br /><br />';
	echo'<font size=2><b>Total: </b>';
	echo ceil($num_rows/$vlimit);
	echo' pages';
	echo ' ('.$num_rows.' Items) </font>';
			
			?>
				
			</td>
			<td valign="top" align="right">
			<select name="row" class="styledselect_pages">
				<option value="">Number of rows</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3">3</option>
				<option value="4">4</option>
				<option value="5">5</option>
				<option value="6">6</option>
				<option value="7">7</option>
			</select>
			</td>
			</tr>
			</table>
			<!--  end paging................ -->
			
			<div class="clear"></div>
		 
		</div>
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>

</div>
<!--  end content -->
<div class="clear">&nbsp;</div>
</div>
<!--  end content-outer........................................................END -->

<div class="clear">&nbsp;</div>
    
 <?php include('templates/footer.php'); ?>

 