<?php 
if($_REQUEST['Save'])
{
	$data['frm_id']=$_REQUEST['Doc_Type'];
	$data['terms_conditions']=htmlspecialchars($_REQUEST['Condition'], ENT_QUOTES);
	$data['parant_id']=$_REQUEST['parantid'];
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['Created_By']=$_SESSION['UserID'];
	$s->RecordInsert('fabrication_group_parameter',$data);
	$s->pageLocation("index.php?route=CRM/Setup/fabrication_index".$rurl);
}

if($_REQUEST['Update'])
{
	$dataE['frm_id']=$_REQUEST['Doc_Type'];
	$dataE['terms_conditions']=htmlspecialchars($_REQUEST['Condition'], ENT_QUOTES);
	$dataE['parant_id']=$_REQUEST['parantid'];
	$Cond="id='".$_REQUEST['id']."'";
	$s->RecordEdit('fabrication_group_parameter',$dataE,$Cond);
	$s->pageLocation("index.php?route=CRM/Setup/fabrication_index".$rurl);
}

if($_REQUEST['action']=='Edit')
{
	$GetEditSQL=DB_query("select * from fabrication_group_parameter where id='".$_REQUEST['id']."'",$db);
	$GetEditData=DB_fetch_array($GetEditSQL);
	extract($GetEditData);
}

if($_REQUEST['action']=='Delete')
{
	$condition="id='".$_REQUEST['delid']."'";
	$s->DeleteRecord('fabrication_group_parameter', $condition);
	$s->pageLocation("index.php?route=CRM/Setup/fabrication_index".$rurl);
}
?>
<script type="text/javascript" language="javascript">
function validate()
{
		if(document.getElementById("Doc_Type").value=='')
		{
			alert("Please Select The Doc Type");
			return false
		}
		
		if(document.getElementById("Condition").value=='')
		{
			alert("Please Fill The  Condition");
			return false
		}
}
	
function getterms(val)
{
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("parantid").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","Getgroup_show.php?formid="+val,true);
	xmlhttp.send();	
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css"><div class="body_contain">
<div class="tab_div">
<h1>Fabrication Group </h1>
<form method="post" action="">
<table width="60%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td class="tabledata1"><strong>Group Name </strong></td>
    <td><select name="Doc_Type" id="Doc_Type" style="width:200px;" onchange="getterms(this.value)">
      <option value="">--Select--</option>
	  <?php $DOCsql=DB_query("SELECT * FROM fabrication_group order by id ASC",$db);
	  while($Doc=DB_fetch_array($DOCsql)){?>
	  <option value="<?php echo $Doc['id']; ?>"<?php echo($frm_id==$Doc['id']?'selected':''); ?>><?php echo $Doc['group_name']; ?></option>
	  <?php }?>
    </select>
    </td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Under Group </strong></td>
    <td><select name="parantid" id="parantid" style="width:200px;">
			<option value="0">Root</option>
			<?php $SQLp=DB_query("select * from fabrication_group_parameter where frm_id='".$frm_id."' and parant_id=0",$db);
			while($parant_val=DB_fetch_array($SQLp)) {?>
			<option value="<?php echo $parant_val['id']; ?>"<?php echo($parant_val['id']==$parant_id?'selected':''); ?>><?php echo $parant_val['terms_conditions']; ?></option>
			<?php }?>
		</select>
		<!--<input name="Terms" id="Terms" type="text" value="<?php echo $terms ?>" style="width:150px;" />-->
    </td>
</tr>
<tr class="row1">
	 <td class="tabledata1"><strong>Spacification</strong></td>
     <td><textarea name="Condition" id="Condition"   style="width:200px;height:90px;"><?php echo $terms_conditions; ?></textarea></td>
</tr>
</table>
<br />
<input type="submit" value="<?php if($_REQUEST['action']=='Edit'){echo 'Update';}else{echo 'Add';} ?>" name="<?php if($_REQUEST['action']=='Edit'){echo 'Update';}else{echo 'Save';} ?>" onclick="return validate()" class="search" />
<br /><br />
</form>


<?php 
$sql1=DB_query("Select distinct frm_id from fabrication_group_parameter",$db);
while($result1=DB_fetch_array($sql1)){
?>


<table width="100%">
<tr class="row1">
<td class="tabledata" colspan="2"><p style="color:#003366; font-size:15px;"><strong>
<?php echo $s->getField('fabrication_group','id',$result1['frm_id'],'sequence'); ?> -
<?php echo $s->getField('fabrication_group','id',$result1['frm_id'],'group_name');?></strong></p></td>
</tr>
</table>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
    <td class="tabledata"><strong>Parameter</strong></td>
    <td class="tabledata"><strong>Specification</strong></td>
	<td class="tabledata"><strong>Edit</strong></td>
	<td class="tabledata"><strong>Delete</strong></td>
</tr>
<?php  
$delper='';
$SQLGet=DB_query("SELECT * FROM fabrication_group_parameter where CompanyId='".$_SESSION['ACGCompanyId']."' and parant_id=0 and frm_id=".$result1['frm_id'],$db);
if(DB_num_rows($SQLGet)>0){
while($FetchArray=DB_fetch_array($SQLGet)){
$chkdelsql=DB_query("select * from fabrication_group_parameter where parant_id='".$FetchArray['id']."'",$db);
if(DB_num_rows($chkdelsql)>0)
{
	$delper=0;
}
else
{
	$delper=1;
}
?>
<tr class="row1" height="30">
	<td class="tabledata1" colspan="2" style="border:none;"><p style="color:#003366; font-size:13px;"><strong><?php echo $FetchArray['terms_conditions']; ?></strong></p></td>
	<td style="border:none;"><a href="index.php?route=CRM/Setup/fabrication_index&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=Edit&id=<?php echo $FetchArray['id']; ?>"><img height="10" src="images/icon_edit.gif" /></a></td>
	<td style="border:none;">
	<?php if($delper=='0'){ ?>
	<img height="10" alt="No Permission Because Has Some Conditions" title="No Permission Because Has Some Conditions" src="images/Icon_Delete3.gif" />
	<?php }else{?>
	<a href="index.php?route=CRM/Setup/fabrication_index&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=Delete&delid=<?php echo $FetchArray['id']; ?>"><img height="10" src="images/Icon_Delete3.gif" /></a>
	<?php }?>
	</td>
</tr>

<?php $i=0; $sqlrec=DB_query("select * from fabrication_group_parameter where parant_id='".$FetchArray['id']."'",$db);
while($underRec=DB_fetch_array($sqlrec)) {?>
  <tr class="row1">
    <td></td>
    <td><?php echo $underRec['terms_conditions']; ?></td>
	<td><a href="index.php?route=CRM/Setup/fabrication_index&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=Edit&id=<?php echo $underRec['id']; ?>"><img height="10" src="images/icon_edit.gif" /></a></td>
	<td><a href="index.php?route=CRM/Setup/fabrication_index&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=Delete&delid=<?php echo $underRec['id']; ?>"><img height="10" src="images/Icon_Delete3.gif" /></a></td>
  </tr>
<?php $i++;} }}?>
<!--<tr class="row1">
	<td class="tabledata1" style="color:#FF0000;" colspan="5">No Record Found</td>
</tr>-->
<?php /*?><?php }?><?php */?>
</table>
<br /><br/>
<?php } ?>



