<?php

/**
 * @file
 * popup window for isdn and anolog groups
 */

chdir("..");

include "./includes/variables.php";
include "./misc/database.php";
$ba = new beroAri();
require_once ('./includes/lang.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="icon" href="../includes/images/favicon.ico" type="image/x-icon">
<script type="text/javascript" language="javascript" src="../includes/validation_modul.js"></script>

<script>
function resize(){
	if(window.sizeToContent) window.sizeToContent();
}
function closeW(){
	this.window.close();
}

function hide_fields(){
	var direction=document.getElementById("call_direction");
	var to_cause_isdn=document.getElementById("to_cause_isdn");
	var to_cause_isgw=document.getElementById("to_cause_isgw");
	var to_cause_sip=document.getElementById("to_cause_sip");
	var from_cause_isdn=document.getElementById("from_cause_isdn");
	var from_cause_isgw=document.getElementById("from_cause_isgw");
	var from_cause_sip=document.getElementById("from_cause_sip");
	var sip_response_message=document.getElementById("sip_response_message");
	var fr=document.getElementById("fr");
	var to=document.getElementById("to");
	if (direction.selectedIndex==0){
		to_cause_isgw.style.display="";
		to_cause_isdn.style.display="none";
		to_cause_sip.style.display="none";
		from_cause_sip.style.display="";
		from_cause_isdn.style.display="none";
		from_cause_isgw.style.display="none";
		sip_response_message.style.display="";
		to.innerHTML="<b><?php echo TO_CAUSE_DIS; ?> (SIP):</b>";
		fr.innerHTML="<b><?php echo FROM_CAUSE_DIS; ?> (ISGW):</b>";
	}
	if (direction.selectedIndex==1){
		to_cause_isgw.style.display="none";
		to_cause_isdn.style.display="";
		to_cause_sip.style.display="none";
		from_cause_sip.style.display="";
		from_cause_isdn.style.display="none";
		from_cause_isgw.style.display="none";
		sip_response_message.style.display="";
		to.innerHTML="<b><?php echo TO_CAUSE_DIS; ?> (SIP):</b>";
		fr.innerHTML="<b><?php echo FROM_CAUSE_DIS; ?> (ISDN):</b>";
	}
	if (direction.selectedIndex==2){
		to_cause_isgw.style.display="";
		to_cause_isdn.style.display="none";
		to_cause_sip.style.display="none";
		from_cause_sip.style.display="none";
		from_cause_isdn.style.display="";
		from_cause_isgw.style.display="none";
		sip_response_message.style.display="none";
		to.innerHTML="<b><?php echo TO_CAUSE_DIS; ?> (ISDN):</b>";
		fr.innerHTML="<b><?php echo FROM_CAUSE_DIS; ?> (ISGW):</b>";
	}
	if (direction.selectedIndex==3){
		to_cause_isgw.style.display="none";
		to_cause_isdn.style.display="none";
		to_cause_sip.style.display="";
		from_cause_sip.style.display="none";
		from_cause_isdn.style.display="";
		from_cause_isgw.style.display="none";
		sip_response_message.style.display="none";
		to.innerHTML="<b><?php echo TO_CAUSE_DIS; ?> (ISDN):</b>";
		fr.innerHTML="<b><?php echo FROM_CAUSE_DIS; ?> (SIP)</b>";
	}
	
}

</script>
<TITLE>CAUSES MAP</TITLE>
<link rel="stylesheet" href="../includes/template_css.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body onload='hide_fields(); resize();'>
<script type="text/javascript" src="../includes/notes/wz_tooltip.js"></script>
<center>
<?php
@session_start();
if((isset($_SESSION['beroari_time']))&&(($_SESSION['beroari_time']+1200)<time())){
        @session_unset();
        @session_destroy();
        echo "<script>window.opener.location='../index.php?m=sip'</script>";
        echo "<script>this.window.close();</script>";
}else{
        $_SESSION['beroari_time']=time();
}

function to_cause_isdn($dir,$to_cause){
	global $isdn_causes;
	$ret="<select name='to_cause_isdn' id='to_cause_isdn' size='4'>";
	if ($to_cause==="ANY") $ret.="<option value='ANY' selected>ANY</option>";
	else $ret.="<option value='ANY'>ANY</option>";
		foreach ($isdn_causes as $key=>$value){
			foreach ($value as $key1=>$value1){
				if (strval($key1)===strval($to_cause)) $ret.="<option value='".$key1."' selected>".$value1."</option>";
				else $ret.="<option value='".$key1."'>".$value1."</option>";
			}
		}
	$ret.="</select>";
	return $ret;
}
function to_cause_sip($dir,$to_cause){
	global $sip_response;
	$ret="<select name='to_cause_sip' id='to_cause_sip' size='4'>";
	if ($to_cause==="ANY") $ret.="<option value='ANY' selected>ANY</option>";
	else $ret.="<option value='ANY'>ANY</option>";
		foreach ($sip_response as $key=>$value){
			foreach ($value as $key1=>$value1){
				if (strval($key1)===strval($to_cause)) $ret.="<option value='".$key1."' selected>".$value1."</option>";
				else $ret.="<option value='".$key1."'>".$value1."</option>";
			}
		}
	$ret.="</select>";
	return $ret;
}
function to_cause_isgw($dir,$to_cause){
	global $isgw_cause;
	$ret="<select name='to_cause_isgw' id='to_cause_isgw' size='4'>";
	if ($to_cause==="ANY") $ret.="<option value='ANY' selected>ANY</option>";
	else $ret.="<option value='ANY'>ANY</option>";
		foreach ($isgw_cause as $key=>$value){
			foreach ($value as $key1=>$value1){
				if ($key1==$to_cause) $ret.="<option value='".$key1."' selected>".$value1."</option>";
				else $ret.="<option value='".$key1."'>".$value1."</option>";
			}
		}
	$ret.="</select>";
	return $ret;
}
function from_cause_isdn($dir,$from_cause){
	global $isdn_causes;
	$ret="<select name='from_cause_isdn' id='from_cause_isdn' size='4'>";
		foreach ($isdn_causes as $key=>$value){
			foreach ($value as $key1=>$value1){
				if (strval($key1)===strval($from_cause)) $ret.="<option value='".$key1."' selected>".$value1."</option>";
				else $ret.="<option value='".$key1."'>".$value1."</option>";
			}
		}
	$ret.="</select>";
	return $ret;
}
function from_cause_sip($dir,$from_cause){
	global $sip_response;
	$ret="<select name='from_cause_sip' id='from_cause_sip' size='4'>";
		foreach ($sip_response as $key=>$value){
			foreach ($value as $key1=>$value1){
				if ($key1==$from_cause) $ret.="<option value='".$key1."' selected>".$value1."</option>";
				else $ret.="<option value='".$key1."'>".$value1."</option>";
			}
		}
	$ret.="</select>";
	return $ret;
}
function from_cause_isgw($dir,$from_cause){
	global $isgw_cause;
	$ret="<select name='from_cause_isgw' id='from_cause_isgw' size='4'>";
		foreach ($isgw_cause as $key=>$value){
			foreach ($value as $key1=>$value1){
				if ($key1==$from_cause) $ret.="<option value='".$key1."' selected>".$value1."</option>";
				else $ret.="<option value='".$key1."'>".$value1."</option>";
			}
		}
	$ret.="</select>";
	return $ret;
}
function call_direction($dir){
	$ret="<select name='call_direction' id='call_direction' onchange='hide_fields();'>";
	if ($dir=="SIP-ISGW") $ret.="<option value='SIP-ISGW' selected>SIP-ISGW</option>";
	else $ret.="<option value='SIP-ISGW'>SIP-ISGW</option>";
	if ($dir=="SIP-ISDN") $ret.="<option value='SIP-ISDN' selected>SIP-ISDN</option>";
	else $ret.="<option value='SIP-ISDN'>SIP-ISDN</option>";
	if ($dir=="ISDN-ISGW") $ret.="<option value='ISDN-ISGW' selected>ISDN-ISGW</option>";
	else $ret.="<option value='ISDN-ISGW'>ISDN-ISGW</option>";
	if ($dir=="ISDN-SIP") $ret.="<option value='ISDN-SIP' selected>ISDN-SIP</option>";
	else $ret.="<option value='ISDN-SIP'>ISDN-SIP</option>";
	$ret.="</select>";
	return $ret;
}

function get_data(){
	$ba=new beroAri();
	if (isset($_GET['id'])){
		$q=$ba->select("select * from isgw_causes where id='".$_GET['id']."'");
		$e=sqlite_fetch_all($q);
		return $e;
	}
}
//echo "<script>window.opener.location='../index.php?m=isdn'</script>";
print "<br><table align=\"center\" bgcolor=\"#f0f0ec\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450\">
<colgroup>
<col width=\"39\"></col>
</colgroup>
<tbody><tr>
<td colspan=\"2\"><img src=\"../includes/images/bg_top.png\"></td>
</tr>
<tr>
<td background=\"../includes/images/bg_left.png\" style='background-repeat:repeat-y;' width=\"30\"><img src=\"../includes/images/trans.gif\" height=\"10\" width=\"39\"></td>
<td><p align='left'><img src=\"../includes/images/berofixlogo.png\"/><hr size= \"1\" noshade></p><p><center><font size='3'>CAUSES MAP</font></p><br><br>";
$data=get_data();
	echo ("<form class='extensions_form' name='isdn' action='causes_submit.php' method='POST'>

			<table border='1' style='border-collapse:collapse' width='560'>
			<tr>
			<td><b>".CALL_DIRECTION_DIS.":</b>&nbsp;</td>
			<td>".call_direction($data[0]['direction'])."</td>
			</tr>
			<tr>
			<td id='to'><b>".TO_CAUSE_DIS.":</b>&nbsp;</td>
				<td>".from_cause_isdn($data[0]['direction'],$data[0]['from_cause']).
				from_cause_isgw($data[0]['direction'],$data[0]['from_cause']).
				from_cause_sip($data[0]['direction'],$data[0]['from_cause'])."</td>
			</tr>
			<tr>
			<td id='fr'><b>".FROM_CAUSE_DIS.":</b>&nbsp;</td>
			<td>".to_cause_isdn($data[0]['direction'],$data[0]['to_cause']).
				to_cause_sip($data[0]['direction'],$data[0]['to_cause']).
				to_cause_isgw($data[0]['direction'],$data[0]['to_cause'])."</td>
			</tr>
			<tr id='sip_response_message'>
			<td><b>".SIP_RESPONSE_MESSAGE_DIS.":</b>&nbsp;</td>
			<td><input type='text' name='sip_response_message' value='".$data[0]['sip_response_message']."'></td>
			</tr>			
			</table>
			<br/>");
		if (isset($_GET['id'])) echo" <input type='hidden' name='id_upd' value='". $_GET['id']."'>";
		echo ("<input name='submit' type='submit' value='".BUTTON_SAVE."'>
			 &nbsp;&nbsp;<input name='close' type='button' value='".BUTTON_CLOSE."' onclick='javascript:closeW();' onmouseover=\"Tip('".POPUPS_BUTTON_CLOSE."');\" onmouseout='UnTip();'>
			</form>");



print "<hr size= \"1\" noshade>";
print "<br><a href=\"http://www.beronet.com\" target=\"_blank\" onfocus=\"if (this.blur()) { this.blur(); }\"><img src=\"../includes/images/beroLogo.gif\" align=\"right\" border=\"0\"></a>";
print "</center></td></tr>
<tr>
<td colspan=\"2\" style=\"background-repeat:no-repeat\" background=\"../includes/images/bg_bottom.png\"><img src=\"../includes/images/trans.gif\" border=\"0\" height=\"39\" width=\"10\"><div style=\"color: white;\" align=\"right\">&nbsp;&nbsp;&nbsp;</div>
</td></tr></table>";
?>
</center>
</body>
</html>

