<?php
//error_reporting(E_ALL);
require_once('../config/config.php');
require_once(CLASS_DIR.'dbClass.php');

$page = $_GET['page'];
$obj = new DBClass();
$obj21 = new DBClass();

if(isset($_GET['action']) && $_GET['action'] == 'delete'){
	$sql1 = "DELETE FROM hit_counter WHERE id = '".$_GET['id']."' ";
	$rs1 = $obj->executeQry($sql1,$link);
	$info[] = 'Record deleted successfully';
}

$sql = "SELECT * FROM hit_counter";

$rs = $obj->executeQry($sql,$link);
$totalrows = $obj->getrow();

$limit = 100;
if(empty($page)) {
$page = 1;
}
$limitvalue = ($page - 1) * $limit;
$adjacents = 3;


$sql = "SELECT * FROM hit_counter ORDER BY id DESC LIMIT $limitvalue, $limit";

$rs = $obj->executeQry($sql,$link);
$row = $obj->fetchrow();
$rownum = $obj->getrow();

if($rownum < 1){
	$error[] = 'No records forund........';
}

if($page > 1){     
	$prevpage = $page-1;
	//$pagination = '<a href=\''.ADMPAGES.'?page='.$prevpage.'\'>'.$prevpage.'</a>&nbsp;';
}

$numofpages = ceil($totalrows / $limit);
$lpm1 = $numofpages - 1;
if ($numofpages < 7 + ($adjacents * 2))
{    
	for ($counter = 1; $counter <= $numofpages; $counter++){
		if($page == $counter)
		$pagination .= $counter."&nbsp;";
		
		else 
		$pagination .= '<a href=hitCounterPage.php?page='.$counter.'\'>'.$counter.'</a>&nbsp;';
		
	}
}

if ($numofpages >= 7 + ($adjacents * 2))
{
	if($page < 1 + ($adjacents * 3)){
		for ($counter = 1; $counter <= 4 + ($adjacents * 2); $counter++){
			if($page == $counter)
			$pagination .= $counter."&nbsp;";
			
			else 
			$pagination .= '<a href=hitCounterPage.php?page='.$counter.'\'>'.$counter.'</a>&nbsp;';
			
		}
		$pagination .= "...";
		$pagination .= "<a href=hitCounterPage.php?page=" . $lpm1 . "\">$lpm1</a>&nbsp;";
		$pagination .= "<a href=hitCounterPage.php?page=" . $numofpages . "\">$numofpages</a>&nbsp;";
	}
	
	elseif($numofpages - ($adjacents * 2) > $page && $page > ($adjacents * 2))
	{
		$pagination .= "<a href=hitCounterPage.php?page=" . "1\">1</a>&nbsp;";
		$pagination .= "<a href=hitCounterPage.php?page=" . "2\">2</a>&nbsp;";
		$pagination .= "...";
		for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
		{
			if ($counter == $page)
				$pagination .= $counter;
			else
				$pagination .= "<a href=hitCounterPage.php?page=" . $counter . "\">$counter</a>&nbsp;";					
		}
		$pagination .= "...";
		$pagination .= "<a href=hitCounterPage.php?page=" . $lpm1 . "\">$lpm1</a>&nbsp;";
		$pagination .= "<a href=hitCounterPage.php?page=" . $numofpages . "\">$numofpages</a>&nbsp;";		
	}
	else
	{
		$pagination .= "<a href=hitCounterPage.php?page=" . "1\">1</a>&nbsp;";
		$pagination .= "<a href=hitCounterPage.php?page=" . "2\">2</a>&nbsp;";
		$pagination .= "...";
		for ($counter = $numofpages - (1 + ($adjacents * 3)); $counter <= $numofpages; $counter++)
		{
			if ($counter == $page)
				$pagination .= $counter;
			else
				$pagination .= "<a href=hitCounterPage.php?page=" . $counter . "\">$counter</a>&nbsp;";					
		}
	}

}
?>
<script type="text/javascript" src="ibox.js"></script>
<?php require_once(INCLUDES_DIR.'admin-headerrefresh.php'); ?>
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="29" align="center" class="submenu"><a href="hitCounterPageHindi.php">Hit Counter Hindi</a></td>
    
  </tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="17"></td>
  </tr>
  <tr>
    <td><table width="910" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td class="pagehead"><table width="900" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="315" height="35">Manage Hit Counter</td>
            <td width="63"><!--Sort By:--></td>
           <td width="131" height="35" style="float:right;margin-right:30px;">Total Hit  <?php
	
$sql21 = "SELECT SUM(hit) as hit FROM hit_counter";
$rs21 = $obj21->executeQry($sql21,$link);
$row21 = $obj21->fetchrow();

echo $row21['hit'];

	?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#FFFFFF"><table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="25" class="error"><?php ShowError($error); ShowInfo($info);?></td>
          </tr>
          <!--<tr>
            <td class="bg_message"><table width="800" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="39"><img src="images/icon_mess.jpg" width="39" height="26" /></td>
                <td><?php ShowInfo($info);?></td>
              </tr>
            </table></td>
          </tr>-->
          <tr>
            <td height="9"></td>
          </tr>
          <tr>
            <td></td>
          </tr>
	<?php if($rownum > 0) { ?>
          <tr>
            <td class="bdr1"><table width="801" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="8" class="bg1" ><img src="../images/bg1.PNG" width="7" height="8" /></td>
              </tr>
              <tr>
                <td><table width="801" border="0" cellpadding="0" cellspacing="0" class="main">
                  <tr>
                    <td width="66" height="30" align="center" valign="middle" class="bdr2">S. No.</td>
                    <td width="300" align="center" valign="middle" class="bdr2">Page Name</td>
                    <td width="150" align="center" valign="middle" class="bdr2">Hit</td>
                    <td width="100" align="center" valign="middle" class="bdr3">Actions</td>
                  </tr>
<?php           
		$i = 1;
		do {
			
?>

                  <tr class="<?php echo (($i%2) == 0) ? "bg_td1" : "bg_td2";?>">
                    <td align="center"><?php echo $i;?></td>
                    <td><?php echo $row['page_name'];?></td>
                    <td align="center"><?php echo $row['hit']; ?></td>
	                <td align="center">
			<a href="hitCounterPage.php?action=delete&id=<?=$row['id'];?>&page=<?php echo $page;?>" onClick="if(confirm('Are you sure, You want delete this record?')){location.replace('hitCounterPage.php?action=delete&id=<?=$row['id']?>&page=<?php echo $page;?>');}return false;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image66','','../images/icon_del2.png',1)"><img src="../images/icon_del1.png" name="Image66" width="28" height="24" border="0" id="Image66" /></a>
			</td>
                  </tr>
		<?php $i++; } while($row = $obj->fetchRow());
		
		?>
                  </table></td>
              </tr>
              <tr>
                <td height="2" class="bg2"><img src="../images/bg2.PNG" width="12" height="2" /></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          </table></td>
      </tr>
      <tr>
        <td valign="top" class="bg_innerfoot"><table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td align="right" class="footer_num"><?php if ($rownum > 0) echo $pagination;?></td>
            </tr>
          </table></td>
      </tr><?php } ?>
      </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

<?php require_once(INCLUDES_DIR.ADMFOOTER); ?>