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

$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$id			= isset($_REQUEST['id'])	?	trim($_REQUEST['id'])	:	"0";
$message	= "";

if (!$objDB) 
{
	$message	= "Unable to Locate Database Server.";
}//end if
else 
{
	$hcid = $_GET['hcid'];
	
	if (intval($hcid) != 0)
	{
		$sqlEdit = " SELECT * FROM ".TABLEPREFIX."HelpCategory WHERE hcid='$hcid'";
		$rsEdit = mysql_query($sqlEdit);
		if($arrEdit= mysql_fetch_array($rsEdit))
		{
 			@extract($arrEdit);
			$txtTitle=$arrEdit['hctitle'];
			$chkType=$arrEdit['htype'];
			$chkActive=$arrEdit['active'];
		}//end if
	}//end first if
        if(isset($_POST['BackNow']) && $_POST['BackNow']=='Back')
        {
	header('location:help.php');
	exit();
        }//     end if

	//add or update category
	if(isset($_POST['Call']) && $_POST['Call']=='save')
	{
			@extract($_POST);
			
                        $hcid = $_POST['hcid'] ;
                        $txtTitle = $_POST["txtTitle"];
                        $chkType = $_POST["chkType"];
                        $chkActive =  $_POST["chkActive"];
			

			if($hcid!='')
			{	
				$sqlUpdate = " UPDATE ".TABLEPREFIX."HelpCategory SET hctitle='".addslashes($txtTitle)."',active='".addslashes($chkActive)."',
								htype='".addslashes($chkType)."' WHERE hcid='$hcid' ";
				mysql_query($sqlUpdate) or die(mysql_error());
				$message = "<font color='green'>Help category updated successfully.</font>";
			}
			else
			{
				 $sql = mysql_query("SELECT MAX(hcposition) as max from ".TABLEPREFIX."HelpCategory") or die(mysql_error());
				 $rw = mysql_fetch_array($sql);
				 $maxorder = $rw['max']+1;
				 
				$sqlIns = " INSERT INTO ".TABLEPREFIX."HelpCategory (htype,hctitle,hcposition,active) VALUES ('".addslashes($chkType)."',
								'".addslashes($txtTitle)."','$maxorder','".addslashes($chkActive)."') ";
				mysql_query($sqlIns) or die(mysql_error());
				$message = "<font color='green'>Help category added successfully.</font>";
			}//end else
		header('location:help.php?ddlCategory='.$chkType.'&msg='.$message);
		exit();
	}//end if
	//$message
}//end else
include_once('title.inc.php');
?>
<script language="javascript" src="../js/validation.js" type="text/javascript"></script>
<script language="javascript">
function category_chk()
{

		var errorstr = '';
		var msgstr = "Sorry, we cannot complete your request.\nPlease provide us the missing or incorrect information enclosed below.\n\n";
		
		with(document.form1)
		{ 	
			if (trim(document.form1.txtTitle.value)=="") { errorstr += "- Please enter Category.\n";}
		}	
		
		if (errorstr != '')
		{
			msgstr = msgstr + errorstr;
			alert(msgstr);
			return false;
		}
		else
		{
			return true;
		}	
}
</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="5" cellpadding="0">
      <tr>
        <td width="72%" valign="top">
			<table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
              <tr>
                <td width="41%" class="headings1"><?php if($hcid!=''){?>
              Edit
                <?php }else{?>
                Add New
                <?php }?>
              Help Category</td>
               
              </tr>
            </table></td>
          </tr>
        </table><div class="bordernew padding1">
		<form name="form1" method="POST" action="<?php echo $PHP_SELF?>" >
  <input type=hidden name='Call' value="save">
  <input name='hcid' type=hidden id="hcid" value="<?php echo $hcid?>">
  <input name='ddlCategory' type=hidden id="ddlCategory" value="<?php echo $_GET['ddlCategory'];?>">
          <table width="100%"  border="0" cellspacing="0" cellpadding="5">
            <tr>
              <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
				<?php if ($objDB) 
					  { 
				?>
					<?php 	if(isset($message) && $message!='')
							{
					?>
                <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="2" class="maintext2 warning"><?php echo $message;?></td>
                  </tr>
					<?php  	}//end if?>
  				<tr align="left">
                  <td width="3%" class="maintext2">&nbsp;</td>
                  <td width="27%" class="maintext2">Type <span class="warning">*</span></td>
                  <td width="70%" class="maintext2"><input name="chkType" type="radio" value="client" <?php if($chkType=='client' || $_GET['ddlCategory']=='client'){echo 'checked';}if($chkType==''){echo 'checked';}?>>
						      Client <input type="radio" name="chkType" value="admin" <?php if($chkType=='admin' || $_GET['ddlCategory']=='admin'){echo 'checked';}?>>Admin</td>
  				</tr>
                 <tr align="left">
                  <td class="maintext2">&nbsp;</td>
                  <td class="maintext2">Category  <span class="warning">*</span></td>
                  <td class="maintext2"><input name="txtTitle" class="textbox3 txt-bx" id="txtTitle" value="<?php echo $txtTitle?>" size="35" maxlength="100"></td>
                 </tr>
                <tr align="left">
                  <td class="maintext2">&nbsp;</td>
                  <td class="maintext2">Active</td>
                  <td class="maintext2"><input name="chkActive" type="radio" value="1" <?php if($chkActive=='1'){echo 'checked';}if($chkActive==''){echo 'checked';}?>>
						      Yes <input type="radio" name="chkActive" value="0" <?php if($chkActive=='0'){echo 'checked';}?>>No</td>
                </tr>
				<?php 			
						}//end first if
				?>
              </table>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                    <tr align="left">
                    <td align="right"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                    </table>
                      <?php if ($objDB) 
					  { 
					?>
                      <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                      <tr>
                        <td align="center"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="30%">&nbsp;</td><td width="7%"><input name="BackNow" type="submit" class="back-btn" value="Back"></td>
                              <?php //if ($hcid > 0) { ?>
                              <td><input class="loginbutton" type="submit" value="<?php if($hcid!=''){?>Edit<?php }else{?>Add<?php }?> " name="submit2" onclick="return category_chk()"></td><td width="50%">&nbsp;</td>
								<?php //}//end if?>
                              </tr>
                        </table></td>
                      </tr>
                    </table>
					<?php 		
						}//end first if
				?></td>
                  </tr>
                </table></td>
            </tr>
          </table></form></div></td>
        </tr>
    </table>      
    </td>
  </tr>
</table>
<?php include_once('bottomhtml.php');?>