<?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	= "";
$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)
		{
			//remove deleted Help file from the Help folder 
			@unlink("../help/".$_GET['hfile']);
			$sqlDel = mysql_query("DELETE FROM ".TABLEPREFIX."Help WHERE hid='".$val."'") or die(mysql_error());
			$message = "Help deleted successfully.";
		}//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 h.*,hc.* FROM ".TABLEPREFIX."Help h left join ".TABLEPREFIX."HelpCategory hc
							on h.hcid=hc.hcid where hc.htype='admin' and hc.hcid='".$ddlCategory."' ORDER BY h.hposition desc";
		}//end if
		else
		{
			//whole category listing
			$query = "SELECT h.*,hc.* FROM ".TABLEPREFIX."Help h left join ".TABLEPREFIX."HelpCategory hc
							on h.hcid=hc.hcid where hc.htype='admin' ORDER BY h.hposition desc";
		}//end else
	}//end if
	else
	{
		//all category listing
		$query = "SELECT h.*,hc.* FROM ".TABLEPREFIX."Help h left join ".TABLEPREFIX."HelpCategory hc
					on h.hcid=hc.hcid where hc.htype='admin' ORDER BY h.hposition 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."Help";
	$PositionfieldName='hposition'; //db field name
	$IdfieldName='hid'; //db field name
	$returnPath='location:help_admin.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 admin help for 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="72%" valign="top">
			<table width="100%"  border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
              <tr>
                <td width="32%" class="headings1" colspan="2">Admin Help</td>
                <!--td width="68%" align="right" class="headings1"><a href="add_admin_help.php" class="signupbuttonlink">Add New Admin Help</a></td-->
              </tr>
			  </table>
			  <div class="bordernew padding2">
			  <table width="100%">
              <tr>
                <td align="right" class="maintext"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="maintext">
                        <form action="help_admin.php?rghMenu=<?php echo $_GET['rghMenu'];?>" method="post" name="frmHelpCategory">
						<tr>
							<td width="48%">&nbsp;</td>
                          <td align="left" scope="col" width="7%">Filter by Category</td>
                          <td scope="col" width="5%"><select name="ddlCategory" class="textbox" onChange="document.frmHelpCategory.submit();">
								<option value="All">All</option>
								<?php
			//fectch language from Help category table
			$language=mysql_query("select * from ".TABLEPREFIX."HelpCategory where active='1' and htype='admin' order by hcposition desc") or die(mysql_error());
			if(mysql_num_rows($language)>0){
				while($arr=mysql_fetch_array($language))
				{?>
				<option value="<?php echo $arr['hcid'];?>" <?php if($_POST['ddlCategory']==$arr['hcid']){echo 'selected';}else if($_GET['ddlCategory']==$arr['hcid']){echo 'selected';}?>><?php echo $arr['hctitle'];?></option>
				<?php
					}//end while
				}//end if
				else{
					echo '<option value="Nil">NIL</option>';
				}//end if?>
				</select></td>
						<td align="right" width="9%"><a href="add_admin_help.php" class="add-btn">Add New Admin Help</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(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
					  if ($objDB) 
					  { 
                 			if (!empty($data)) 
							{ 
				?>
                <tr align="left">
                  <th align="center" class="maintext2">#</th>
                  <th class="maintext2">Help</th>
                  <th class="maintext2">Category</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  	
							$count='1';
							foreach ($data as $key => $value) 
							{ 
				?>
                <tr align="left">
                  <td width="5%" align="center" class="maintext2"><?php echo $key+1;?></td>
                  <td width="30%" class="maintext2"><?php echo htmlspecialchars(stripslashes($value['htitle']))?></td>
                  <td width="20%" class="maintext2"><?php echo $value['hctitle']?></td>
                  <td width="10%" 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_admin.php?Action=ordering&move=up&id=<?php echo $value["hid"];?>&pos=<?php echo $value["hposition"];?><?php echo $order_category;?>'>
<?php } ?>
<img src="../images/up.gif" alt="Up" border=0></a>

<?php if($cnt!=$count){?>
<a href="help_admin.php?Action=ordering&move=down&id=<?php echo $value["hid"];?>&pos=<?php echo $value["hposition"];?><?php echo $order_category;?>">
<?php } ?>
<img src="../images/down.gif" alt="Down" border=0></a></td>
                  <td width="10%" align="center" class="maintext2"><a href="add_admin_help.php?hid=<?php echo $value['hid']?>&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['hid']?>"></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>&nbsp;</td></tr>
                  <tr>
                    <td width="82%">&nbsp;</td>
                    <td width="18%"><table width="100%"  border="0" cellspacing="1" cellpadding="0" class="pagination_style">
                        <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');?>