
<?php
if(isset($_POST['save']))
{           
		extract($_REQUEST['sub_activity_defination']);
		if($s->RecordInsert('sub_activity_defination',$_REQUEST['sub_activity_defination']))
		{
		
		}
		unset($_REQUEST['sub_activity_defination']);	
				//print_r($_REQUEST); exit;
		$_SESSION['success_msg']="Saved Successfully";	
		echo "<script>location.href='index.php?route=SubContractors/Masters/activity_defination_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
$sql=DB_query("select Max(display_order) from sub_activity_defination",$db);
$check=DB_fetch_array($sql);
if($check['Max(display_order)']==null)
{
$num=1;	
}
else {
	$num=$check['Max(display_order)']+1;
}
if($_REQUEST['action']=='edit' and $_REQUEST['opn']!='')
{
$recEdit=DB_fetch_array($s->GetRecordById('sub_activity_defination','id='.$_REQUEST['opn']));
extract($recEdit);		
}
if(isset($_REQUEST['update']))
{
	 $s->RecordEdit('sub_activity_defination',$_REQUEST['sub_activity_defination'],"id=".$_REQUEST['opn']);
		$_SESSION['success_msg']="Update Successfully";
		echo "<script>location.href='index.php?route=SubContractors/Masters/activity_defination_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<style>
.label{
background-color: #B7B7B7;
    color: #000000;
    font-size: 10.5px;
    font-weight: bold !important;
    padding: 5px 10px;
    text-align: left;
}
</style>
<h3> Activity Group</h3>
<div align="center">
<form action="" method="post">
<table width="70%" border="0" cellspacing="2" cellpadding="2" align="center"><tr><td>
<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
  <td width="39%" class="label"><strong>Activity Group  </strong></td>
    <td width="61%"><font color="#FF0000" size="3"> * </font><select  name="sub_activity_defination[group_name]" id="group_name"  onchange="getgroupcode(this.value);">
    <option value="">Select Activity Group</option>
    <?php $groupdata=DB_query("select * from sub_activity_group",$db);
	while($group=DB_fetch_array($groupdata))
	{
	$t='';
	if($group['id']==$group_name)
	{
		$t="selected";
	}
		?>	
    <option value="<?php echo $group['id']; ?>"<?php echo $t; ?>><?php echo $group['group_name']; ?></option>
    <?php } ?>	
    	
    	
    </select></td>
  </tr>
  <tr>
   <td width="39%" class="label"><strong>Activity Group code</strong></td>
    <td width="61%" id="groupcode"><font color="#FF0000" size="3">&nbsp;  </font><input type="text" name="sub_activity_defination[group_code]" id="group_code" value="<?php echo $group_code;?>" size="30" readonly /></td>
  </tr>
  <tr>
   <td width="39%" class="label"><strong>Activity Name  </strong></td>
    <td width="61%"><font color="#FF0000" size="3"> * </font><input type="text" name="sub_activity_defination[activity_name]" id="activity_name" value="<?php echo $activity_name;?>" size="30"  /></td>
  </tr>
   <tr>
   <td width="39%" class="label"><strong>Activity Code  </strong></td>
    <td width="61%"><font color="#FF0000" size="3"> * </font><input type="text" name="sub_activity_defination[activity_code]" id="activity_code" value="<?php  echo $activity_code; ?>" size="30"  /></td>
  </tr>
  <tr>
   <td width="39%" class="label"><strong>Display Order  </strong></td>
    <td width="61%"><font color="#FF0000" size="3"> * </font><input type="text" name="sub_activity_defination[display_order]" id="display_order" value="<?php if($_REQUEST['action']=='edit') echo $display_order; else echo $num;?>" size="30"  readonly/></td>
  </tr>
  <tr>
   <td width="39%" class="label"><strong>Unit Of Measurement  </strong></td>
    <td width="61%"><font color="#FF0000" size="3"> * </font><select  name="sub_activity_defination[unit]" id="unit"  >
    	<option value="">Select</option>
    	<?php $unitdata=DB_query("select * from unitsofmeasure",$db);
		while($unitrow=DB_fetch_array($unitdata))
		{
		$c='';
		if($unitrow['unitid']==$unit)
		{
			$c="selected";
		}	
			?>
			<option value="<?php echo $unitrow['unitid']; ?>"<?php echo $c; ?>><?php echo $unitrow['unitname']; ?></option>
			<?php } ?>
    	
    </select></td>
  </tr>
  <tr>
   <td width="39%" class="label"><strong>Rate  </strong></td>
    <td width="61%"><font color="#FF0000" size="3"> * </font><input type="text" name="sub_activity_defination[rate]" id="rate" value="<?php echo $rate; ?>" size="30"  /></td>
  </tr>
  <tr>
   <td width="39%" class="label"><strong>Work Description  </strong></td>
    <td width="61%"><font color="#FF0000" size="3">&nbsp;  </font><input type="text" name="sub_activity_defination[work_description]" id="work_description" value="<?php echo $work_description; ?>" size="30"  /></td>
  </tr>
  <tr>
   <td width="39%" class="label"><strong>Tally Ledger  </strong></td>
    <td width="61%"><font color="#FF0000" size="3">&nbsp;  </font><input type="text" name="sub_activity_defination[tally_ledger]" id="tally_ledger" value="<?php echo $display_order; ?>" size="30"  /></td>
  </tr>
  <tr>
   <td width="39%" class="label"><strong>Status  </strong></td>
    <td width="61%"><font color="#FF0000" size="3">&nbsp;  </font><input type="radio" name="sub_activity_defination[status]" id="status"  size="30"  value="Active" <?php if($status=='Active'){ ?> checked="checked" <?php }?>/>Active
    <input type="radio" name="sub_activity_defination[status]" id="status"  size="30"  value="InActive" <?php if($status=='InActive'){ ?> checked="checked" <?php }?>/>InActive</td>
  </tr>
  
  
	
  <tr><td>&nbsp;</td></tr>
  <tr><td>&nbsp;</td>
    <td align="center"><input type="submit" value="<?php if($_REQUEST['action']=='edit') echo 'update'; else echo 'save'; ?>" name="<?php if($_REQUEST['action']=='edit') echo 'update'; else echo 'save'; ?>"><input type="reset" name="cancel" value="Reset" /><a href="index.php?route=SubContractors/Masters/Other_Addition_Master_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" name="back" value="Cancel" /></a></td>
  </tr>
</table>
</td></tr></table>
</form>
</div>
<script language="JavaScript"> 
function getgroupcode(str) 
{	 
	
if (str.length==0)
  {
  document.getElementById("groupcode").innerHTML="";
 
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("groupcode").innerHTML=xmlhttp.responseText;
      }
  }
 
xmlhttp.open("GET","get_group_data.php?site="+str,true);
xmlhttp.send();
}
</script>