<script type="text/javascript">
function getSite(str)
{
	
if(str.length==0)
{
	document.getElementById("SiteName").innerHTML="";
	return;
	
}
if(window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	  	
		document.getElementById("SiteName").innerHTML=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","getSite.php?Company="+str,true);
xmlhttp.send();	
	
	
} 
</script>



<center><h1><?php  echo $page_title;?></h1></center>
 <?php  $table='dashboard_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;
if($_REQUEST['Save'])
{
	if(empty($_REQUEST['dashboard']))
	{
	   $msgErr[]='Please Enter Dashboard Name';
	   $status=false;
	}
	
	 
	 
	 
		
} 
function CheckTransportName($dashboard)
{
	global $db;
	$SQL="Select dashboard_name from dashboard_master where dashboard_name='".$dashboard."'";
	$result=DB_query($SQL,$db);
	$resultrow=DB_fetch_array($result);
	if(isset($resultrow['dashboard_name'])){return false;}else{return true; }
	
	
}

 
  
//************************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);		
  	
	  $dashboard=$RData['dashboard_name'];
	  $dashboard_url=$RData['dashboard_url'];
	  
  $id=$RData['id'];
			 
}

 

if($_REQUEST['Save']  && $action=='Edit')
{
 
  $data['dashboard_name']=$_REQUEST['dashboard'];
   $data['dashboard_url']=$_REQUEST['dashboard_url']; 
   $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'] &&  $status )
{
	
	if(CheckTransportName($_REQUEST['dashboard']))
	{
     $data['dashboard_url']=$_REQUEST['dashboard_url']; 
    $data['dashboard_name']=$_REQUEST['dashboard'];
  //print_r($data);
// $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 Zone Already Exist'));
		
	}
 
}
?>


 <form action="" method="post">
<table width="50%" border="0" cellspacing="3" cellpadding="3">
   <tr>
   <td colspan="2"><!-- <div align="right"> <a href="index.php?route=Setup/dashboard_master<?php echo $rurl; ?>&action=Addnew">Add New</a></div>--></td>
   </tr>
  <?php if(isset($daction))
  {?>
    <tr>
  
    <td colspan="2" ><div class="success">
	<?php 
	 if($_REQUEST['daction']!=1 && $_REQUEST['daction']!=2)
	 echo "Record ".$_REQUEST['daction']." Successfully";
	 elseif($_REQUEST['daction']==1)
	 	 echo "Can't Delete This Record because AccountName Attatch with LedgerDayBook table ";
	 elseif($_REQUEST['daction']==2)		 
		 echo "Can't Delete This Record. First Delete it's Parent Record   ";
		 ?>
	</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>
    <td width="35%">DashBoard Name </td>
    <td width="65%"><input  type="text" name="dashboard" id="dashboard" value="<?php echo $dashboard; ?>"   />   </td>
  </tr>
   <tr>
    <td width="35%">DashBoard URL </td>
    <td width="65%"><input  type="text" name="dashboard_url" id="dashboard_url" value="<?php echo $dashboard_url; ?>"   />   </td>
  </tr>
 
  <tr>
    <td>&nbsp;</td>
    <td> 
	
      <input type="submit" name="Save" value="Save">
    
    </td>
  </tr>
</table>
</form>
 


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