<script type="text/javascript">

function validation()
{ 
    if(document.getElementById("doc_type_name").value=='')
        {
            alert("Enter Document Type");
            document.getElementById("doc_type_name").focus();
            return false;
        }else{
    return true;}
}
</script>



<center><h1><?php  echo $page_title;?></h1></center>
 <?php  $table='dms_doc_type_mstr';
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$msgErr='';
$status=true;
 $modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$url="&modid=".$modid."&frmid=".$frmid;
$targetpage="index.php?route=".$_REQUEST['route'].$url;
if($_REQUEST['Save'] && !$action=='Edit')
{
	$data['doc_type_name']=$_REQUEST['doc_type_name'];	 
	$data['Company_id']=$_SESSION['ACGCompanyId'];
        $data['created_by']=$_SESSION['UserID'];
        $data['created_date']=date("Y-m-d H:i:s");
        $s->RecordInsert($table,$data);
        
        echo '<div class="success">Record Inserted Succesfully!!</div>';
        $s->pageLocation("index.php?route=DMS/doc_type".$rurl);
} 

  
//************************Edit*********************************************** 

if($action=='Edit')
{
	$condition="id='".$_REQUEST['id']."'";
	$allready=$s->GetRecord($table,  $condition);
	$Select=DB_query($allready,$db);
	$RData=DB_fetch_array($Select);		
  	$type_name=$RData['doc_type_name'];
}
if($action=='Edit' && $_REQUEST['Save'])
{
	$dataUp['doc_type_name']=$_REQUEST['doc_type_name'];
        $dataUp['modified_by']=$_SESSION['UserID'];
        $dataUp['modified_date']=date("Y-m-d H:i:s");
        
        $update= $s->EditRecord($table, $dataUp, $condition);
	$row=DB_query($update,$db);
        echo '<div class="success">Record Updated Succesfully!!</div>';
        $s->pageLocation("index.php?route=DMS/doc_type".$rurl);
}
        



if($action=='Del')
{
	$SQLDel=DB_query("Delete From $table where id='".$_REQUEST['id']."'",$db);
        echo '<div class="success">Record Deleted Succesfully!!</div>';
	$s->pageLocation($targetpage);
}

?>


 <form action="" method="post" onsubmit='return validation();'>
<table width="50%" border="0" cellspacing="3" cellpadding="3">
   <input type='hidden' name='mainID' value='<?php echo $_REQUEST['id']; ?>' />
   
  <tr>
    <td width="35%">Type Name <font style='color:red;'>*</font><td>
    <td ><input type="text" name="doc_type_name" id="doc_type_name" style='width:245px;' value="<?php echo $type_name  ?>">
    	
    </td>
  </tr>
  
  <tr>
    
    <td colspan="3" style="text-align:center;"> 
	<?php if($_REQUEST['action']=='Edit'){?>
      <input type="submit" name="Save" value="Save" <?php if($_SESSION['frmEdit']=='0'){?>disabled<?php } ?>><?php } else {?>
      <input type="submit" name="Save" value="Save" <?php if($_SESSION['frmcreate']=='0'){?>disabled<?php } ?>><?php }?>
       
    </td>
  </tr>
</table>
</form>
 
<table width="80%" border="0" cellspacing="2" cellpadding="2">
<tr>
   <th>Sr No.</th>
   <th>Type Name</th>
  
  <?php if($_SESSION['frmEdit']=='1'){?> <th>Edit</th><?php } ?>
    <?php if($_SESSION['frmDelete']=='1'){?><th>Delete</th><?php } ?>
</tr>
   <?php 
   
      // LIMIT $startpoint,$perpage
   $GetRecord = "Select * from $table where Company_id='".$_SESSION['ACGCompanyId']."' order by id";
   $ResultData = DB_query($GetRecord,$db);
   $i=1;
   if(DB_num_rows($ResultData)==0)
   echo "<td colspan='4' style='color:red;'>No Record Found !!</td>";
   while($RowData = DB_fetch_array($ResultData))
   {?>
<tr bgcolor="#FFFFFF"> <td width="10%"><div align="center"><?php echo $i; ?></div></td>
	<td width="30%"><?php echo $RowData['doc_type_name']; ?></td>
	
	<?php if($_SESSION['frmEdit']=='1'){?><td width="10%"><div align="center"><a href="<?php echo $targetpage?>&amp;action=Edit&amp;id=<?php echo $RowData['id']; ?>"><img src="images/icon-edit.png"  width="10" height="10"/></a></div></td><?php } ?>
	<?php if($_SESSION['frmDelete']=='1'){?><td width="10%"><div align="center"><a href="<?php echo $targetpage?>&amp;action=Del&amp;id=<?php echo $RowData['id']; ?>"><img src="images/Icon_Delete.png"  width="10" height="10"/></a></div></td><?php } ?>
</tr>
 <?php $i++;} ?> 
    
</table>
