<?php
include(“connection.php”);
$id1=$_GET[‘news_id’];
if(isset($_GET[‘action’])==’Delete’)
{
$del=mysql_query(“delete from news where news_id=’$id1′”);

}

if($_SESSION[“UserId”]==””)
{
$_SESSION[“lgnError”] = “<p class=\”lgnShowError\” id=\”errUserId\”>Please login…</p>”;
$_SESSION[“lgnError”] = $_SESSION[“lgnError”].”<p class=\”lgnError\” id=\”errPassword\”></p>”;
header(“Location:index.php”);
}

/* $sql = “SELECT P.product_name,P.image,S.subcat_name,P.subcat_id,S.content,S.status
FROM subcategories as S INNER JOIN product as P ON P.subcat_id = S.subcat_id WHERE S.status =1 ORDER BY P.product_name “;
$result= mysql_query($sql);

*/

mysql_query(“SET SESSION time_zone = ‘+5:30′”);

/* Start Pagination code */

/*
Place code to connect to your DB here.
*/
//include(‘config.php’); // include your code to connect to DB.

$tbl_name=”candidate_profile”; //your table name
// How many adjacent pages should be shown on each side?
$adjacents = 3;

/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = “SELECT * FROM news ORDER BY news_id”;
$total_pages = mysql_num_rows(mysql_query($query));
//$total_pages = $total_pages[num];

/* Setup vars for query. */
$targetpage = “viewnews.php”; //your file name (the name of this file)
$limit = 10; //how many items to show per page
$page = $_GET[‘page’];
if($page)
$start = ($page – 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0

/* Get data. */
$sql = “SELECT * FROM news ORDER BY news_id LIMIT $start, $limit”;
$result = mysql_query($sql);

/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page – 1; //previous page is page – 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage – 1; //last page minus 1

/*
Now we apply our rules and draw the pagination object.
We’re actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = “”;
if($lastpage > 1)
{
$pagination .= “<div class=\”pagination\”>”;
//previous button
if ($page > 1)
$pagination.= “<a href=\”$targetpage?page=$prev\”>◄ previous</a>”;
else
$pagination.= “<span class=\”disabled\”>◄ previous</span>”;

//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= “<span class=\”current\”>$counter</span>”;
else
$pagination.= “<a href=\”$targetpage?page=$counter\”>$counter</a>”;
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= “<span class=\”current\”>$counter</span>”;
else
$pagination.= “<a href=\”$targetpage?page=$counter\”>$counter</a>”;
}
$pagination.= “…”;
$pagination.= “<a href=\”$targetpage?page=$lpm1\”>$lpm1</a>”;
$pagination.= “<a href=\”$targetpage?page=$lastpage\”>$lastpage</a>”;
}
//in middle; hide some front and some back
elseif($lastpage – ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= “<a href=\”$targetpage?page=1\”>1</a>”;
$pagination.= “<a href=\”$targetpage?page=2\”>2</a>”;
$pagination.= “…”;
for ($counter = $page – $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= “<span class=\”current\”>$counter</span>”;
else
$pagination.= “<a href=\”$targetpage?page=$counter\”>$counter</a>”;
}
$pagination.= “…”;
$pagination.= “<a href=\”$targetpage?page=$lpm1\”>$lpm1</a>”;
$pagination.= “<a href=\”$targetpage?page=$lastpage\”>$lastpage</a>”;
}
//close to end; only hide early pages
else
{
$pagination.= “<a href=\”$targetpage?page=1\”>1</a>”;
$pagination.= “<a href=\”$targetpage?page=2\”>2</a>”;
$pagination.= “…”;
for ($counter = $lastpage – (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= “<span class=\”current\”>$counter</span>”;
else
$pagination.= “<a href=\”$targetpage?page=$counter\”>$counter</a>”;
}
}
}

//next button
if ($page < $counter – 1)
$pagination.= “<a href=\”$targetpage?page=$next\”>next ►</a>”;
else
$pagination.= “<span class=\”disabled\”>next ►</span>”;
$pagination.= “</div>\n”;
}

/* End of Pagination */

?>

<!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″ />
<title>Admin Upload </title>
<link href=”css/style.css” rel=”stylesheet” type=”text/css” />
<link rel=”stylesheet” href=”Uploadify-scriptData-Sample/uploadify/uploadify.css” type=”text/css” />
<script type=”text/javascript” src=”Uploadify-scriptData-Sample/js/jquery-1.3.2.min.js”></script>
<script type=”text/javascript” src=”Uploadify-scriptData-Sample/js/jquery.uploadify.js”></script>
<link rel=”stylesheet” href=”uploadify/uploadify.css” type=”text/css” />
<link href=”css/pagination.css” rel=”stylesheet” type=”text/css” />

<script type=”text/javascript”>
$(document).ready(function() {

$(“#fileUpload3″).fileUpload({
‘uploader’: ‘uploadify/uploader.swf’,
‘cancelImg’: ‘uploadify/cancel.png’,
‘script’: ‘upload.php’,
‘folder’: ‘files’,
‘fileDesc’: ‘Image Files’,
‘fileExt’: ‘*.jpg;*.jpeg;*.gif;*.png’,
‘multi’: true,
‘auto’: true
});
});

</script>
<script type=”text/javascript”>
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{ jsddm_canceltimer();
jsddm_close();
ddmenuitem = $(this).find(‘ul’).eq(0).css(‘visibility’, ‘visible’);}

function jsddm_close()
{ if(ddmenuitem) ddmenuitem.css(‘visibility’, ‘hidden’);}

function jsddm_timer()
{ closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{ if(closetimer)
{ window.clearTimeout(closetimer);
closetimer = null;}}

$(document).ready(function()
{ $(‘#jsddm > li’).bind(‘mouseover’, jsddm_open);
$(‘#jsddm > li’).bind(‘mouseout’, jsddm_timer);});

document.onclick = jsddm_close;
</script>
<script type=”text/javascript”>
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{ jsddm_canceltimer();
jsddm_close();
ddmenuitem = $(this).find(‘ul’).eq(0).css(‘visibility’, ‘visible’);}

function jsddm_close()
{ if(ddmenuitem) ddmenuitem.css(‘visibility’, ‘hidden’);}

function jsddm_timer()
{ closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{ if(closetimer)
{ window.clearTimeout(closetimer);
closetimer = null;}}

$(document).ready(function()
{ $(‘#jsddm > li’).bind(‘mouseover’, jsddm_open);
$(‘#jsddm > li’).bind(‘mouseout’, jsddm_timer);});

document.onclick = jsddm_close;
</script>
</head>
<body>
<div id=”wrapper”>
<? include(“includes/header.php”);?>
<div class=”middle”>
<div class=”login-middle”>
<div style=”height:30px; width:980px;”></div>

<div class=”admin-upload”>
<? include(“includes/menu.php”);?>
<div class=”clear”></div>
<div class=”article”>
<div class=”article-upload”>
<span>View News:</span>
<hr class=”color”/>
<table width=”664″ border=”1″ cellpadding=”10″ align=”center”>
<tr>
<td width=”67″><strong>Image</strong></td>
<td width=”63″><strong>Category</strong></td>
<td width=”63″><strong>Title</strong></td>

<!– <td width=”87″><strong>Description</strong></td>–>
<td width=”141″><strong>Post Date & Time</strong></td>
<td width=”37″><strong>Delete</strong></td>
<td width=”121″><strong>update</strong></td>
</tr>
<?php while($row = mysql_fetch_array($result)) { ?>

<tr class=”color1″>

<td>
<?php if($row[‘image’]!=NULL) { ?>

<img src=”newsimages/<?php echo $row[‘image’];?>” width=”30″ title=”<?php echo $row[‘title’];?>” />
<?php } else {?>
<img src=”newsimages/default.jpg” width=”30″ title=”Default Image” />
<?php } ?>

</td>
<td><? echo $row[‘cat_id’]?></td>
<td><? echo substr($row[‘title’],0,20); ?></td>
<!– <td><?// echo substr($row[‘description’],0,50); ?></td>–>
<td><?php echo date(‘d-M-Y h:i:s A’,strtotime($row[‘postdate’]));?></td>

<td><a href=”viewnews.php?action=Delete&news_id=<? echo $row[‘news_id’]; ?>” onclick=”confirm(‘Do you sure want to delete this.’)”>
<img src=”images/delete.png” title=”Delete ” />
</a>
</td>
<td width=”121″><a href=”newsupdate.php?action=update&news_id=<? echo $row[‘news_id’]; ?>” style=”color:#000″>
Update
</a></td>

</tr>
<?php } ?>
</table>
<p>&nbsp;</p>
</div>

<div style=”float:right;margin-top:30px;”><?=$pagination?></div>

</div>
<div class=”clear”></div>
</div>
<!–WrapperEnd–>
</body>
</html>