<?php   
$PageSecurity = 1;
$table='visit_status';
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$msgErr='';
$status=true;
if($_REQUEST['Save'])
{
	if(empty($_REQUEST['name']))
	{
	   $msgErr[]='Please Enter Source Name ';
	   $status=false;
	}
	 
	 
	 	$condition="name='".$_REQUEST['name']."'";
		$allready=$s->GetRecord($table,  $condition);
		$row=DB_query($allready,$db);
		if(DB_num_rows($row)>0 && $action!='Edit')
		{
			 $msgErr[]='All Ready Exist';
			 $status=false;
		}
		
} 

//************************Delete*********************************************** 
if( $action=='del')
{
	$condition="id='".$_REQUEST['ID']."'";
	$s->DeleteRecord($table,$condition);
	prnMsg( _('Record deleted successfully'),'success');
	$s->pageLocation('index.php?route=visitStatus&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
 
  
//************************Edit*********************************************** 

if(!$_REQUEST['Save'] &&  $status && $action=='Edit')
{
	$condition="id='".$_REQUEST['ID']."'";
	$allready=$s->GetRecord($table,  $condition);
	$Select=DB_query($allready,$db);
	$RData=DB_fetch_array($Select);		
	$name=$RData['name'];
 
}
 

if($_REQUEST['Save'] &&  $status && $action=='Edit')
{
 $data['name']=$_REQUEST['name'];
 $cond="id='".$_REQUEST['ID']."'";
	$update= $s->EditRecord($table, $data, $cond);
	$row=DB_query($update,$db);
	if(!$row)
	{
	   die('Error'.DB_error());
	}
  prnMsg( _('Record Updated successfully'),'success');
	$s->pageLocation('index.php?route=visitStatus&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
 
//************************INSERT*********************************************** 
if($_REQUEST['Save'] &&  $status && $action=='')
{
   $data['name']=$_REQUEST['name'];
   $data['companyId'] = $_SESSION['ACGCompanyId'];
	$insert= $s->insertRecord($table, $data);
	$row=DB_query($insert,$db);
	if(!$row)
	{
	   die('Error'.DB_error());
	}
prnMsg( _('Record Inserted successfully'),'success');
	$s->pageLocation('index.php?route=visitStatus&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
?>
<form action="" method="post">
<table width="50%" border="0" cellspacing="3" cellpadding="3">
  <tr>
  <?php if($_REQUEST['action']=='Edit') {  ?>
  <td colspan="2"><h1>Edit Visit Status Details</h1></td>
 <?php }else { ?>
 <td colspan="2"><h1>Visit Status Details</h1></td>
  <?php } ?>
  </tr>
  
  <?php if(isset($daction))
  {?>
    <tr>
    <td colspan="2" ><div class="success"><?php echo "Record ".$daction." Successfully" ?></div></td>
  </tr>
  <?php }
  if(isset($msgErr)&&$msgErr!='' )
   {?>
    <tr>
  
    <td colspan="2" ><div class="error"><?php 
for($kp=0;$kp<count($msgErr);$kp++)
 {
		echo  $msgErr[$kp].'<br>';
 }
  ?></div></td>
  </tr>
   <?php }?>
  <tr>
    <th width="35%"> Source Name: </th>
    <td width="65%"><input name="name" type="text" size="27" value="<?php echo $name;?>"></td>
  </tr>
    <td>&nbsp;</td>
    <td> 
      <input type="submit" name="Save" value="<?php if($_REQUEST['action']=='Edit') { echo 'Upadate'; } else { echo 'Save'; } ?>">    </td>
  </tr>
</table>
</form>


<table width="70%" border="0" cellspacing="2" cellpadding="2">
   <tr>
     <th>Sr.no </th>
     <th>Name</th>
     <th>EDIT</th>
     <th>DELETE</th>
   </tr>
   <?php 
      // LIMIT $startpoint,$perpage
   $GetRecord = "Select * from $table 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 $RowData['name']; ?></td>
   
   <td width="20%"><div align="center"><a href="index.php?route=visitStatus&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=visitStatus&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid']?>&action=del&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>
