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

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

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

$sql = "SELECT * FROM expert";
$rs = $obj->executeQry($sql,$link);
$totalrows = $obj->getrow();

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

$sql = "SELECT * FROM expert ORDER BY date 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=expert.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=expert.php?page='.$counter.'\'>'.$counter.'</a>&nbsp;';
			
		}
		$pagination .= "...";
		$pagination .= "<a href=expert.php?page=" . $lpm1 . "\">$lpm1</a>&nbsp;";
		$pagination .= "<a href=expert.php?page=" . $numofpages . "\">$numofpages</a>&nbsp;";
	}
	
	elseif($numofpages - ($adjacents * 2) > $page && $page > ($adjacents * 2))
	{
		$pagination .= "<a href=expert.php?page=" . "1\">1</a>&nbsp;";
		$pagination .= "<a href=expert.php?page=" . "2\">2</a>&nbsp;";
		$pagination .= "...";
		for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
		{
			if ($counter == $page)
				$pagination .= $counter;
			else
				$pagination .= "<a href=expert.php?page=" . $counter . "\">$counter</a>&nbsp;";					
		}
		$pagination .= "...";
		$pagination .= "<a href=expert.php?page=" . $lpm1 . "\">$lpm1</a>&nbsp;";
		$pagination .= "<a href=expert.php?page=" . $numofpages . "\">$numofpages</a>&nbsp;";		
	}
	else
	{
		$pagination .= "<a href=expert.php?page=" . "1\">1</a>&nbsp;";
		$pagination .= "<a href=expert.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=expert.php?page=" . $counter . "\">$counter</a>&nbsp;";					
		}
	}

}
?>
<?php require_once(INCLUDES_DIR.ADMHEADER); ?>
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="29" align="center" class="submenu"><a href="enquiries.php">Enquiries</a></td>
    <td align="center" class="submenu"><a href="contactus.php">Contact Us</a></td>
	<td align="center" class="submenu">Expert Help</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="700" height="35">Manage Expert Help</td>
            <!--<td width="391">&nbsp;</td>-->
            <td width="63"><!--Sort By:--></td>
            <td width="131"><!--<select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
              <option>item1</option>
            </select>--></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 align="left">
                    <td width="80" valign="middle" class="bdr2" align="center">Date</td>
                    <td width="125" height="30" valign="middle" class="bdr2"  align="center">Name</td>
                    <td width="150" valign="middle" class="bdr2"  align="center">Email</td>
                    <td width="170" valign="middle" class="bdr2"  align="center">Phone/Mobile</td>
                    <td width="169" valign="middle" class="bdr2"  align="center">Organization</td>
                    <td width="107" align="center" valign="middle" class="bdr3"  align="center">Actions</td>
                  </tr>
<?php           
		$i = 1;
		do {

?>

                  <tr class="<?php echo (($i%2) == 0) ? "bg_td1" : "bg_td1";?>">
                    <td align="center"><?php echo date("d-m-Y", strtotime($row['date']));?></td>
                    <td align="center"><?php echo $row['name'];?></td>
                    <td align="center"><?php echo $row['email'];?></td>
                    <td align="center"><?php echo $row['contact'];?></td>
                    <td align="center"><?php echo $row['organizaion'];?></td>
                    <td align="center"><a href="view_expert.php?id=<?=$row['id'];?>" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image64','','../images/icon_view1.png',1)"><img src="../images/icon_view.png" name="Image64" width="28" height="24" border="0" id="Image64" /></a>&nbsp;&nbsp;&nbsp;
				<a href="expert.php?action=delete&id=<?=$row['id'];?>&page=<?php echo $page;?>" onClick="if(confirm('Are you sure, You want delete this record?')){location.replace('expert.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); ?>