<?php
require_once ("../config.inc.php");
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/Pager/Pager.php");

$message	= $_REQUEST['msg'];
$pages		= "";
$data		= array();
$array		= array();
$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
//selected language for filtering
$ddlCategory=($_POST['ddlCategory']!='')?$_POST['ddlCategory']:$_GET['ddlCategory'];

if (!$objDB) 
{
	$message	= "Unable to Locate Database Server.";
}//end if
else 
{
	//delete help category
	if(isset($_POST['ids']) && $_POST['ids']!='')
	{
		foreach ($_POST['ids'] as $val)
		{
			//check if it in use
			$check_category=mysql_query("SELECT * FROM ".TABLEPREFIX."Help WHERE hcid='".$val."'") or die (mysql_error());
			if(mysql_num_rows($check_category)>0)
			{
				$message = "This Help category cannot be deleted since it is in use!";
			}//end if
			else
			{
				$sqlDel = mysql_query("DELETE FROM ".TABLEPREFIX."HelpCategory WHERE hcid='".$val."'") or die(mysql_error());
				$message = "<font color='green'>Help category deleted successfully.</font>";
			}//end else
		}//end foreach
	}//end if

	//add this link to ordering 
	if(isset($ddlCategory) && $ddlCategory!='')
	{
		$order_category='&ddlCategory='.$ddlCategory;
	}//end if
					
	if(isset($ddlCategory))
	{
		if($ddlCategory!='All')
		{
			//requested language category listing
			$query = "SELECT * FROM ".TABLEPREFIX."HelpCategory where htype='".$ddlCategory."' ORDER BY hcposition desc";
		}//end if
		else
		{
			//all category listing
			$query = "SELECT * FROM ".TABLEPREFIX."HelpCategory ORDER BY hcposition desc";
		}//end else
	}//end if
	else
	{
		//all category listing
		$query = "SELECT * FROM ".TABLEPREFIX."HelpCategory ORDER BY hcposition desc";
	}//end else

	$res=mysql_query($query) or die(mysql_error());
	$cnt=mysql_num_rows($res);

	if (@mysql_num_rows($res) > 0) 
	{
		while($row = @mysql_fetch_array($res)) 
		{
			$array[]	= $row;
		}//end while loop
		@mysql_free_result($res);
	}//end if
	
	$params 	= array(
		'mode'      => 'Sliding',
		'perPage'   => PAGESIZE,
		'urlVar'    => 'page',
		'extraVars' => array(),
		'itemData'  => $array
	);
	$objP 		= & Pager::factory($params);
	$data  		= $objP->getPageData();
	if (empty($data))
		$message	.= "No record(s) exists.<br>";
}//end else

include_once('title.inc.php');


//ordering content
if(isset($_GET['Action']) && $_GET['Action']=='ordering')
{
	$oldId=$_GET['id'];
	$oldPosition=$_GET['pos'];
	$table=$tableprefix.TABLEPREFIX."HelpCategory";
	$PositionfieldName='hcposition'; //db field name
	$IdfieldName='hcid'; //db field name
	$returnPath='location:help.php';
	
	if(isset($_GET['move']) && $_GET['move']=='up')
	{
		$objST->OrderUp($table,$oldId,$oldPosition,$PositionfieldName,$IdfieldName,$returnPath);
	}//end 2nd if
	
	if(isset($_GET['move']) && $_GET['move']=='down')
	{
		$objST->OrderDown($table,$oldId,$oldPosition,$PositionfieldName,$IdfieldName,$returnPath);
	}//end 3rd if
}//end first if
?>
<script language="javascript" type="text/javascript">
function confirm_check()
{
 var where_to= confirm("Do you really want to delete these help category permenantly?");
 if (where_to== true)
 {
   return true;
 }
 else
 {
  return false;
  }
}
$(function(){
        // add multiple select / deselect functionality
        $("#checkAll").click(function () {
            $('.case').attr('checked', this.checked);
        });

        // if all checkbox are selected, check the selectall checkbox
        // and viceversa
        $(".case").click(function(){

            if($(".case").length == $(".case:checked").length) {
                $("#checkAll").attr("checked", "checked");
            } else {
                $("#checkAll").removeAttr("checked");
            }

        });
    });
</script>
<link href="../styles/tabcontent.css" type="text/css" rel="stylesheet">
<script language="javascript" type="text/javascript" src="../js/tabcontent.js"></script>
<?php include_once('tophtml.php');?>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100%" valign="top">
			<table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>
			<table width="100%"  border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td height="10">&nbsp;</td>
			</tr>
              <tr>
                <td class="headings1">Help Category
                <!--a href="add_category.php" class="signupbuttonlink r_float">Add New Help Category</a--></td>
              </tr>
			  </table>
			  <div class="bordernew padding2">
			  <table width="100%">
              <tr>
                
                <td class="maintext">
				
				<table width="100%" border="0" cellpadding="0" cellspacing="0" class="maintext">
                        <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="frmSearch">
						<tr>
							<td width="48%">&nbsp;</td>
                          <td scope="col" width="7%">Filter by Category</td>
                          <td scope="col" width="5%"><select name="ddlCategory" class="textbox" onChange="document.frmSearch.submit();">
								<option value="All">All</option>
								<?php
			//fectch language from music category table
			$language=mysql_query("select distinct(htype) from ".TABLEPREFIX."HelpCategory order by htype") or die(mysql_error());
			if(mysql_num_rows($language)>0){
				while($arr=mysql_fetch_array($language))
				{?>
				<option value="<?php echo $arr['htype'];?>" <?php if($_POST['ddlCategory']==$arr['htype']){echo 'selected';}else if($_GET['ddlCategory']==$arr['htype']){echo 'selected';}?>><?php echo ucfirst($arr['htype']);?></option>
				<?php
					}//end while
				}//end if
				else{
					echo '<option value="Nil">NIL</option>';
				}//end if?>
				</select></td>
				<td width="10%" align="right"><a href="add_category.php" class="add-btn">Add New Help Category</a></td>
						</tr>
						</form>
                      </table></td>
              </tr>
            </table>
					<?php include_once('help_menu.php');?>
		<div class="tabcontentstyle">
		<form name="form1" method="post" action="" onSubmit="return confirm_check();">
          <table width="100%"  border="0" cellspacing="0" cellpadding="5">
            <tr>
              <td><table width="100%"  border="0" cellspacing="1" cellpadding="0" class=" listing_tbl_admin">
				<?php if ($objDB) 
					  { 
                 			if (!empty($data)) 
							{ 
				?>
                <tr align="left">
                  <th align="center" class="maintext2">#</th>
                  <th class="maintext2">Category</th>
                  <th class="maintext2">Type</th>
                  <th class="maintext2" align="center">Active</th>
                  <th class="maintext2" align="center">Set Order</th>
                  <th class="maintext2" align="center">Action</th>
                  <th class="maintext2" align="center">&nbsp;<input type="checkbox" id="checkAll" name="checkAll" title="Check All / Uncheck All"/></th>
                  </tr>
					<?php 	if(isset($message) && $message!='')
							{
					?>
                <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="6" class="maintext2 warning"><?php echo $message;?></td>
                  </tr>
					<?php  	}//end if
							$count='1';
							foreach ($data as $key => $value) 
							{ 
				?>
                <tr align="left">
                  <td width="5%" align="center" class="maintext2"><?php echo $key+1;?></td>
                  <td width="26%" class="maintext2"><?php echo htmlspecialchars(stripslashes($value['hctitle']))?></td>
                  <td width="15%" class="maintext2"><?php echo $value['htype']?></td>
                  <td width="15%" align="center" class="maintext2"><?php if($value['active']=='1'){echo 'Yes';}else{echo 'No';}?></td>
                  <td width="10%" align="center" class="maintext2"><?php if($count!=1){?>
	<a href='help.php?Action=ordering&move=up&id=<?php echo $value["hcid"];?>&pos=<?php echo $value["hcposition"];?><?php echo $order_category;?>'>
<?php } ?>
<img src="../images/up.gif" alt="Up" border=0></a>

<?php if($cnt!=$count){?>
<a href="help.php?Action=ordering&move=down&id=<?php echo $value["hcid"];?>&pos=<?php echo $value["hcposition"];?><?php echo $order_category;?>">
<?php } ?>
<img src="../images/down.gif" alt="Down" border=0></a></td>
                  <td width="12%" align="center" class="maintext2"><a href="add_category.php?hcid=<?php echo $value['hcid']?>&page=<?php echo $objP->getCurrentPageID()?><?php echo $order_category;?>" class="signupbuttonlink">Edit</a></td>
                  <td width="6%" align="center" class="maintext2"><input name="ids[]" class="case" type="checkbox" value="<?php echo $value['hcid']?>"></td>
                  </tr>
				<?php 			$count++;
						}//end foreach
				?>
			   <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="5" class="maintext2">&nbsp;</td>
                  <td align="center" class="maintext2"><input type="submit" name="DelNow" value="Delete" class="loginbutton"></td>
                </tr>
			   <?php
					 		}//end if
						}//end first if
				?>
              </table>
				<?php if(!empty($data))
					  {
				?>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="82%">&nbsp;</td>
                    <td width="18%"><table width="100%"  border="0" cellspacing="1" cellpadding="0" class="pagination_style">
						<tr><td>&nbsp;</td></tr>
                        <tr align="center" class="textbox">
                          <td><?php echo $objP->links;?></td>
                          </tr>
                    </table></td>
                  </tr>
                </table><?php }//end if?>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="right"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                    </table>
                     </td>
                  </tr>
                </table></td>
            </tr>
          </table></form></div>
			<div class="clear"></div>
			</div>
			</td>
          </tr>
        </table>
		  </td>
        </tr>
    </table>      
    </td>
  </tr>
</table>
<?php include_once('bottomhtml.php');?>