<?php 
//error_reporting(E_ALL);
require_once('../config/config.php');
require_once(CLASS_DIR.'dbClass.php');
$cupage = 'cat';
$page = $_GET['page'];
$obj = new DBClass();

if(isset($_GET['msg'])){
	if($_GET['msg'] == 'add'){
		$info[] = 'Listing Option Added Successfully';
	}
	if($_GET['msg'] == 'edit'){
		$info[] = 'Listing Option Updated Successfully';
	}
	if($_GET['msg'] == 'status'){
		$info[] = 'Listing Option Updated Successfully';
	}
	if($_GET['msg'] == 'del'){
		$info[] = 'Listing Option Deleted Successfully';
	}
}

if(isset($_GET['action']) && $_GET['action'] == 'statchng'){
	$sql = "SELECT * FROM ".TBL_OPTIONS." WHERE id = ".$_GET['id'];
	$rs = $obj->executeQry($sql,$link);
	$rows = $obj->fetchRow();
	$rowNum = $obj->getRow();
	if ($rowNum > 0){
		$updt = $rows['status']=='0'?'1':'0';
		$sql2 = "UPDATE ".TBL_OPTIONS." SET status = '".$updt."' WHERE id = '".$_GET['id']."'";
		$rs2 = $obj->executeQry($sql2,$link);
		if($rs2){
			@header('Location: options.php?info=status');
		}
	}
}

if(isset($_GET['action']) && $_GET['action'] == 'delete'){
	$sql1 = "DELETE FROM ".TBL_OPTIONS." WHERE id = '".$_GET['id']."' ";
	$rs1 = $obj->executeQry($sql1,$link);
	if($rs1){
		@header('Location: options.php?info=del');
	}
}

$sql = "SELECT * FROM ".TBL_OPTIONS." group by `option`";
$rs = $obj->executeQry($sql,$link);
$totalrows = $obj->getrow();

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

$sql = "SELECT * FROM ".TBL_OPTIONS." group by `option` 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=\''.ADOPTION.'?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=\''.ADOPTION.'?page='.$counter.'\'>'.$counter.'</a>&nbsp;';
			
		}
		$pagination .= "...";
		$pagination .= "<a href=\"" . ADOPTION."?page=" . $lpm1 . "\">$lpm1</a>&nbsp;";
		$pagination .= "<a href=\"" . ADOPTION."?page=" . $numofpages . "\">$numofpages</a>&nbsp;";
	}
	
	elseif($numofpages - ($adjacents * 2) > $page && $page > ($adjacents * 2))
	{
		$pagination .= "<a href=\"" . ADOPTION."?page=" . "1\">1</a>&nbsp;";
		$pagination .= "<a href=\"" . ADOPTION."?page=" . "2\">2</a>&nbsp;";
		$pagination .= "...";
		for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
		{
			if ($counter == $page)
				$pagination .= $counter;
			else
				$pagination .= "<a href=\"" . ADOPTION."?page=" . $counter . "\">$counter</a>&nbsp;";					
		}
		$pagination .= "...";
		$pagination .= "<a href=\"" . ADOPTION."?page=" . $lpm1 . "\">$lpm1</a>&nbsp;";
		$pagination .= "<a href=\"" . ADOPTION."?page=" . $numofpages . "\">$numofpages</a>&nbsp;";		
	}
	else
	{
		$pagination .= "<a href=\"" . ADOPTION."?page=" . "1\">1</a>&nbsp;";
		$pagination .= "<a href=\"" . ADOPTION."?page=" . "2\">2</a>&nbsp;";
		$pagination .= "...";
		for ($counter = $numofpages - (1 + ($adjacents * 3)); $counter <= $numofpages; $counter++)
		{
			if ($counter == $page)
				$pagination .= $counter;
			else
				$pagination .= "<a href=\"" . ADOPTION."?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="options.php">Manage Listing Options</a></td>
    <td align="center" class="submenu"><a href="add_options.php">Add New Listing Option</a></td>
    <td align="center" class="submenu"><a href="option_value.php">Manage Option Value</a></td>
    <td align="center" class="submenu"><a href="add_option_value.php">Add Options Value</a></td>
	<td align="center" class="submenu"><a href="packages.php">Packages</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" class="head_menu">Manage Listing Option</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>
                    <td width="66" height="30" align="center" valign="middle" class="bdr2">S. No.</td>
                    <td width="178" align="center" valign="middle" class="bdr2">Options</td>
                    <!--<td width="175" align="center" valign="middle" class="bdr2">Email</td>
                    <td width="122" align="center" valign="middle" class="bdr2">Phone</td>-->
                    <td width="85" align="center" valign="middle" class="bdr2">Status</td>
                    <td width="174" align="center" valign="middle" class="bdr3">Actions</td>
                  </tr>
<?php           
		$i = 1;
		do {
			$stat = ($row['status'] == '0')?'<img src="'.IMAGE_DIR.'icon_status1.png" name="Image62" width="28" height="24" border="0" id="Image62" title="Active" />':'<img src="'.IMAGE_DIR.'deactive_icon.png" border="0" title="Inactive" />';

?>

                  <tr class="<?php echo (($i%2) == 0) ? "bg_td1" : "bg_td2";?>">
                    <td align="center"><?php echo $i;?></td>
                    <td><?php echo $row['option'];?></td>
                    <!--<td><?php echo $row['email'];?></td>
                    <td><?php echo $row['phone'];?></td>-->
                    <td align="center"><a href="category.php?action=statchng&id=<?=$row['id'];?>&status=<?=$row['status'];?>" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image62','','../images/icon_status2.png',1)"><?=$stat;?></a></td>
                    <td align="center">&nbsp; &nbsp;&nbsp;<!--<a href="view_user.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;-->
			<a href="add_category.php?action=edit&id=<?php echo $row['id'];?>" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image65','','images/icon_edit2.png',1)"><img src="../images/icon_edit1.png" name="Image65" width="28" height="24" border="0" title="Edit" id="Image65" /></a>
			<a href="category.php?action=delete&id=<?=$row['id'];?>" onClick="if(confirm('Are you sure, You want delete this record?')){location.replace('category.php?action=delete&id=<?=$row['id']?>');}return false;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image66','','../images/icon_del2.png',1)"><img src="../images/icon_del1.png" name="Image66" width="28" title="Delete" 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); ?>