<?php 
if($_REQUEST['Save'])
{
   $data['frm_id']=$_REQUEST['Doc_Type'];
	$data['moduleid ']=$_REQUEST['Mod_Type'];
	$data['reason_type']=$_REQUEST['Rtype'];
	$data['reason']=$_REQUEST['reason'];
	$data['created_date']=date('Y-m-d');
	$data['modify_date']=date('Y-m-d');
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['Created_By']=$_SESSION['UserID'];
	
	$s->RecordInsert('reason_master',$data);
	$s->pageLocation("index.php?route=reason_master".$rurl);
}

if($_REQUEST['Update'])
{
     $dataE['moduleid ']=$_REQUEST['Mod_Type'];
	$dataE['frm_id']=$_REQUEST['Doc_Type'];
	$dataE['reason_type']=$_REQUEST['Rtype'];
	$dataE['reason']=$_REQUEST['reason'];
	//$dataE['parant_id']=$_REQUEST['parantid'];
	$Cond="id='".$_REQUEST['id']."'";
	$s->RecordEdit('reason_master',$dataE,$Cond);
	$s->pageLocation("index.php?route=reason_master".$rurl);
}

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

}

if($_REQUEST['action']=='Delete')
{
	$id="id='".$_REQUEST['id']."'";
	$s->DeleteRecord('reason_master', $id);
	$s->pageLocation("index.php?route=reason_master".$rurl);
}
?>
<script type="text/javascript" language="javascript">
function validate()
{
		if(document.getElementById("Mod_Type").value=='')
		{
			alert("Please Select The Mod Type");
			return false
		}
		if(document.getElementById("Doc_Type").value=='')
		{
			alert("Please Select The Doc Type");
			return false
		}
		//if(document.getElementById("reason").value=='')
		//{
			//alert("Please Fill The  Reason");
			//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","getform.php?formid="+val,true);
	xmlhttp.send();	
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Reason</h1>
<form method="post" action="">

<?php
/*$data1=array();

$mod1=DB_query("select * from module_form_categories where cat_desc not in('Reports','QC Master Setup','Control Panel')",$db);  
while($row11=DB_fetch_array($mod1))
{
$data1[]=$row11['id'];
}
$data11=implode("','",$data1);*/



 ?>


<table width="60%" align="center" border="0" cellpadding="3" cellspacing="0">
 <tr class="row1">
    <td class="tabledata1"><strong>Module</strong></td>
	<!--where module_form_category_id  in('".$data11."')-->
    <td><select name="Mod_Type" id="Mod_Type" style="width:200px;" onchange="getterms(this.value)">
      <option value="">--Select--</option>
	  <?php $mosql=DB_query("SELECT * FROM modules order by modulename ",$db);
	  while($mo=DB_fetch_array($mosql)){?>
	  <option value="<?php echo $mo['id']; ?>"<?php echo($moduleid==$mo['id']?'selected':''); ?>><?php echo $mo['modulename']; ?></option>
	  <?php }?>
    </select>
    </td>
</tr>
  <tr class="row1">
    <td class="tabledata1"><strong>Form Name</strong></td>
	<!--where module_form_category_id  in('".$data11."')-->
    <td><select name="Doc_Type" id="parantid" style="width:200px;">
      <option value="">--Select--</option>
	  
	  <?php 
	 
	  $DOCsql=DB_query("SELECT * FROM modules_form order by frm_name ",$db);
	  while($Doc=DB_fetch_array($DOCsql)){?>
	  <option value="<?php echo $Doc['id']; ?>"<?php echo($frm_id==$Doc['id']?'selected':''); ?>><?php echo $Doc['frm_name']; ?></option>
	  <?php }?>
    </select>
    </td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Reason Type</strong></td>
    <td><select name="Rtype" id="typeid" style="width:200px;">
			<option value="0">Root</option>
			<option value="1" <?php if($reason_type==1) { ?> selected="selected" <?php } ?>  >Cancel</option>
			<option value="2" <?php if($reason_type==2) { ?> selected="selected" <?php } ?>>Edit</option>
			<option value="3" <?php if($reason_type==3) { ?> selected="selected" <?php } ?>>Delete</option>
			
		</select>
		<!--<input name="Terms" id="Terms" type="text" value="<?php echo $terms ?>" style="width:150px;" />-->
    </td>
</tr>
<tr class="row1">
	 <td class="tabledata1"><strong>Reason</strong></td>
     <td><input name="reason" id="reason" style="width:200px;" value="<?php echo $reason; ?>"></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>
<table width="70%" border="0" cellspacing="2" cellpadding="2">
   <tr>
     <th>Sr.no </th>
   <!--  <th>GROUP CODE </th>-->
     <th> Module Name</th>
     <th>Form Name</th>
	 <th>Reason Type</th>
	 <th>Reason</th>
	
	 
     <th>EDIT</th>
     <th>DELETE</th>
   </tr>

<?php 
      // LIMIT $startpoint,$perpage
   $GetRecord = "Select * from reason_master order by id";
   $ResultData = DB_query($GetRecord,$db);
   $i=1;
   if(DB_num_rows($ResultData)==0)
   echo "<td>--No Record--</td>";
   
   while($RowData = DB_fetch_array($ResultData))
   {?>
 <tr align="center" bgcolor="#FFFFFF" valign="top"> 
   <td width="20%"><div align="center"><?php echo $i;//.$RowData['VoucherType']; ?></div>	  </td>
    <td width="20%"><?php echo $s->getField('modules','id',$RowData['moduleid'],'modulename');?></td>
 	     <td width="20%"><?php echo $s->getField('modules_form','id',$RowData['frm_id'],'frm_name');?></td>
		 <td width="20%"><?php echo $RowData['reason_type']; ?></td>
  <td width="20%"><?php echo $RowData['reason']; ?></td>
   
   <td width="20%"><div align="center"><a href="index.php?route=reason_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid']?>&action=Edit&id=<?php echo $RowData['id']; ?>"><img src="images/icon-edit.png"  width="10" height="10"/></a></div></td>
	<td width="20%"><div align="center"><a href="index.php?route=reason_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid']?>&action=Delete&id=<?php echo $RowData['id']; ?>" onClick="return confirm('Do You Want To Delete This Record')"><img src="images/Icon_Delete.png" width="10" height="10" /></a></div></td>	
  </tr>
 
	<?php $i++;}   
   ?> 
   <tr>
 </table>
