<html>
<body >

<?
session_start();
include("opendb.php");
include("test.php");
if($save)
{
$code=substr($subname,0,3).substr(time(),7,3).date("s"); 
 $code=str_replace(' ','-',$code);

$sql="insert into subgroupmasterparts values('$code','$gname','$subname','$tax')";
mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error($db));

print "<script>document.location='subgrmasterparts.php'</script>";
return;
}
?>
<title>Xpress</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="scripts/jquery-latest.js"></script>
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />
<script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
<script>
function valid()
{
}
</script>
<body background="back_ground.jpg">
<?php //include('logo2.php'); ?>
<?php include('includes/top.php'); ?>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()" method='post'> 

<br>
<table class="container"><tr><td>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Service >> <a href="service_menu.php" style="text-decoration:none;">Service</a> >> Sub Group Master</font>
<br>
<style>
th{background-color:steelblue;color:white}

#pg{
       text-decoration:none;
}
#pg button{
       background-color:#3b5998;
}
</style>
<script>
function valid()
{
 
 if(document.f1.subname.value.length<=0)
 {
   alert("Invalid sub group name.");
   document.f1.subname.focus();
   return false;
 }

}

var stax=[];

function settax()
{
  var x= document.f1.gname.selectedIndex ; 
  if(x>0)
	
    document.f1.tax.value=stax[document.f1.gname.selectedIndex];
   else
    document.f1.tax.value='';
}
function pgnfn(str){
            document.getElementById('pgbtn'+str).style.background = "#ccc";
}
</script>
<?
$xx=$_GET['id']+1;
?>
<body onload='pgnfn(<? echo $xx;?>)'>

<center>
<table cellspacing=1 cellpadding=1 bgcolor=black>
<tr><td align=center bgcolor='white'>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">
<table cellspacing=1 cellpadding=3 width='350' class=form>
<th colspan=2><font size=3>SUB GROUP MASTER</th>
<tr><td>Group </td><td><select name='gname' size=1 >
<option></option>
<?
$gp=mysqli_query($db,"select * from groupmasterparts");
$i=1;
while($gprow=mysqli_fetch_array($gp))
{
print "<option>$gprow[gname]</option>";
print "<script>stax[$i]='$gprow[tax]'</script>";
$i++;
}
?>
</select>
</td>
    </tr>
<tr><td>Sub Group Name</td><td><input type=text name='subname' size=25></td></tr>


<th colspan=2><input type=submit value='Save' name='save'></td></tr>
</table>
</form>
</td></tr>
</table>


<?


if(!isset($_GET['id'])){
     $_GET['id']=0;
  }
$qry=mysqli_query($db,"select count(*) from subgroupmasterparts");

$qry1=mysqli_fetch_array($qry);
$cnt=$qry1[0];

$rowcnt=10;
$pgno=floor($cnt/$rowcnt);
if(($cnt%$rowcnt)>0){
   $pgno=$pgno+1;
}
print "<table align='center' id='pagen'><tr>";

  if($pgno>6){
      
     if($_GET['id']>0)
        $m=$_GET['id']-1;
     else
        $m=$_GET['id'];
      
  }
$nxtid=$_GET['id']+2;
$nxtval=$_GET['id']+1;
$prvid=$_GET['id']-2;
$prval=$_GET['id']-1;
$flg=1;

for($i=$m;$i<$pgno;$i++){
    
    $j=$i+1;
     
    if(($flg==1)&& ($_GET['id']>0)){
       print "<td><a href='subgrmasterparts.php?id=$prval' id='pg'><input type='button' class='pgbtn' id='pgbtn".$prvid."' value='Previous' /></a></td>";
    }

    if(($_GET['id']==2) && ($flg==1)){
       print "<td><a href='subgrmasterparts.php?id=0' id='pg'><input type='button' class='pgbtn' id='pgbtn1' value='1' /></a></td>";
    }

    if(($_GET['id']>=3) && ($flg==1)) {
       print "<td><a href='subgrmasterparts.php?id=0' id='pg'><input type='button' class='pgbtn' id='pgbtn1' value='1' /></a></td><td>...</td>";
    }

    if($flg<5){
       print "<td><a href='subgrmasterparts.php?id=$i' id='pg'><input type='button' class='pgbtn' id='pgbtn".$j."' value='".$j."' /></a></td>";
    }

    if($flg==5){
       print "<td>.</td><td>.</td><td>.</td>"; 
       $i=$pgno-2; 
    }

    if($flg==6){  
 	  
       print "<td><a href='subgrmasterparts.php?id=$i' id='pg'><input type='button' class='pgbtn' id='pgbtn".$j."' value='".$j."' /></a></td>";
 	print "<td><a href='subgrmasterparts.php?id=$nxtval' id='pg'><input type='button' class='pgbtn' id='pgbtn".$nxtid."' value='Next' /></a></td>";  
    }
  
    $flg++;
}
print "</tr></table>";
?>



<br>
<table cellspacing=1 cellpadding=5 class=form>
<th>No <th>Group <th>Sub Group Name<th>Tax %<th>Edit<th>Del
<?
$lmt1=$_GET['id']*$rowcnt;
$k=$lmt1+1;
$res=mysqli_query($db,"select * from subgroupmasterparts order by subname limit $lmt1,$rowcnt");
while($row=mysqli_fetch_array($res))
{
 print "<tr bgcolor='white' onMouseOver=bgColor='b8d7b4'; onMouseOut=bgColor='white'>";
 print "<td>".$k++."</td><td>$row[gname]</td><td>$row[subname]</td>";
 print "<td align=right>$row[tax]</td><td><input type=button value='Edit' onClick=window.open('editsubgr.php?code=$row[code]',menubar=false,resizable=false)></td>";
 print "<td><input type=button value='Del' name='del' onClick=delfun('$row[code]')></td></tr>";
}
?>
</table>

<script>
 function delfun(x)
 {
  if (confirm('do you want to delete '+x+' ?'))
   document.location='delsubgrmasterparts.php?code='+x;
 }
 
   
</script>
