
<center><h1><?php  echo $page_title;?></h1></center>
 <?php  $table='tower_master';
$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;

function CheckZoneTitle($Zonetitle)
{
	global $db;
	$SQL="Select group_name from tower_master where group_name='".$Zonetitle."'";
	$result=DB_query($SQL,$db);
	$resultrow=DB_fetch_array($result);
	if(isset($resultrow['group_name'])){return false;}else{return true; }
	
	
}

 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);		
  	 $CompanyId=$RData['CompanyId'];
	  $subZone=$RData['group_name'];
	  $seq=$RData['sequence'];
	  $id=$RData['id'];
			 
}
  
//************************Edit*********************************************** 


if( $action=='Delete')
{
	  $sql="delete from  tower_master where id='".$_REQUEST['id']."'";
	  $Res=DB_query($sql,$db);
	  prnMsg(_('Deleted Successfully'));
	  echo "<script>location.href='index.php?route=CRM/Setup/tower_master&action=Addnew&action=&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
 

if($_REQUEST['Save']  && $action=='Edit')
{
 $data['CompanyId']=$_SESSION['ACGCompanyId'];
 $data['group_name']=$_REQUEST['group_name'];
 $data['sequence']=$_REQUEST['sequence_no'];
 $cond="id='".$_REQUEST['id']."'";
 	$update= $s->EditRecord($table, $data, $cond);
	$row=DB_query($update,$db);
	if(!$row)
	{
	   die('Error'.DB_error());
	}
 	
	
  $s->pageLocation($targetpage.'&action=Addnew&daction=Updated');
}
 
//************************INSERT*********************************************** 
if($_REQUEST['Save'] && $_REQUEST['action']!='Edit')
{
	
	if(CheckZoneTitle($_REQUEST['subzone']))
	{
   $data['CompanyId']=$_SESSION['ACGCompanyId'];
   $data['group_name']=$_REQUEST['group_name'];
   $data['sequence']=$_REQUEST['sequence_no'];
     // $data['Predefined']=$_REQUEST['Predefined'];
	$insert= $s->insertRecord($table, $data);
	$row=DB_query($insert,$db);
	
	if(!$row)
	{
	   die('Error'.DB_error());
	   
	}
	//prnMsg(_('Record inserted'),'Success');
	 $s->pageLocation($targetpage.'&action=Addnew&daction=Inserted');
 	}
	else
		 {
		 	prnMsg(_('This Group  name Already Exist'));
		
	}
 
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<?php if($_REQUEST['daction']!='') { ?>
<h1><a href="index.php?route=CRM/Setup/tower_master<?php echo $rurl; ?>&amp;action=Addnew">
  <input type="button" name="Add New" value="Add New" class="search" />
</a></h1>
<?php } ?>

 <form action="" method="post">
   <center>
  <?php if($_REQUEST['action']=='Addnew' || $_REQUEST['action']=='Edit' and $_REQUEST['daction']=='') { ?>
<table width="57%" border="1" cellspacing="3" cellpadding="3">
   
	 <tr class="row1">
  	<td class="tabledata1">Tower Name </td>
  	<td ><input type="text" name="group_name" id="group_name" value="<?php echo $subZone  ?>" ></td>
  	</tr>
		 <tr class="row1">
  	<td class="tabledata1">Sequence </td>
  	<td ><input type="text" name="sequence_no" id="sequence_no" value="<?php echo $seq  ?>" ></td>
  	</tr>

   
  <tr class="row1">
    <td>&nbsp;</td>
    <td > 
	
      <input type="submit" name="Save" value="Save" class="search" >    </td>
  </tr>
</table>
<?php } ?>
</center>
</form>
 


<?php  include('viewtower_name.php') ?> 
