<?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();
}

/**
 * @file
 * popup window for playing recording
 */

chdir("..");
include './includes/variables.php';
require_once ('./includes/isgwtelnet.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" src="script/dialplan_popup.js">
</script>
<script type="text/javascript" src="../includes/validation_modul.js">
</script>

<TITLE>DIALPLAN</TITLE>
<link rel="stylesheet" href="../includes/template_css.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<?php
print "<body onload='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\"); resize();'>";



$page=$_GET['start'];
$dir=$_GET['dir'];
$search=$_GET['search'];
//echo "<script>window.opener.location='../index.php?m=dialplan&start=" . $page . "'</script>";
print "<br><table align=\"center\" bgcolor=\"#f0f0ec\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"690\">
<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\" border=\"0\"></td>
<td><p align='left'><img src=\"../includes/images/berofixlogo.png\"/></p><hr size= \"1\" noshade><p><center><font size='3'>".DIALPLAN_TITLE_DIS."</font></p><br><br>";



function fromSip($frId, $fromDirection){
	$ba=new beroAri();
	$query=$ba->select("SELECT name from sip");
	$ret="<fieldset id='FromSipBox' onmouseover=\"Tip('" . DIALPLAN_FROM_SIP . "')\" onmouseout='UnTip()'>";
	$ret.="<select id='match_type' name='matchType' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");'>";
	if (substr_count($frId,"p:")==1){
		$ret.="<option value='p:' selected>IP Address</option>";
		$ret.="<option value='d:'>From user</option>";
		$ret.="<option value='manual'>Manual Address</option>";
	}elseif(substr_count($frId,"d:")==1){
		$ret.="<option value='p:'>IP Address</option>";
		$ret.="<option value='d:' selected>From user</option>";
		$ret.="<option value='manual'>Manual Address</option>";
	}elseif($frId!=""){
		$ret.="<option value='p:' >IP Address</option>";
		$ret.="<option value='d:' >From user</option>";
		$ret.="<option value='manual' selected>Manual Address</option>";
	}elseif(sqlite_num_rows($query)>0){
		$ret.="<option value='p:' selected>IP Address</option>";
		$ret.="<option value='d:'>From user</option>";
		$ret.="<option value='manual'>Manual Address</option>";
	}else{
		$ret.="<option value='manual'>Manual Address</option>";
	}

	$ret.="</select><br><br>";
	$ret.="<select id='from_sip' name='fromIdSip' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");'>";
	while ($entry=$ba->fetch_array($query)){
		if (((substr_count($frId,"p:")==1) || (substr_count($frId,"d:")==1)) && (("p:".$entry['name']==$frId) || ("d:".$entry['name']==$frId))){
			$ret.="<option value='".$entry['name']."' selected>".$entry['name']."</option>";
		}else{
			$ret.="<option value='".$entry['name']."'>".$entry['name']."</option>";
		}
	}
	$ret.="</select>";
	//check if manual
	if (substr_count($frId,"p:")==0 && substr_count($frId,"d:")==0 && $fromDirection == 'sip'){
		$ret.="<input type='text' name='manualsipfrom' id='manualsipfrom' value='".stripslashes($frId)."'>";
	}else{
		$ret.="<input type='text' name='manualsipfrom' id='manualsipfrom'>";
	}
	$ret.="</fieldset>";
	return $ret;
}

function fromIsdn($frId){
	$ba=new beroAri();
	$b=false;
	$ret="<fieldset id='FromIsdnBox' onmouseover=\"Tip('" . DIALPLAN_FROM_ISDN . "')\" onmouseout='UnTip()'>";
	$query=$ba->select("SELECT distinct gr from isdn WHERE gr!='NULL'");
	$ret.="<select name='fromIdIsdn' id='from_isdn'>";
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($frId,"g:")==1) && ("g:".$entry['gr']==$frId)){
			$ret.="<option value='g:".$entry['gr']."' selected>g:".$entry['gr']."</option>";
			$b=true;
		}
		if(!$b)  $ret.="<option value='g:".$entry['gr']."'>g:".$entry['gr']."</option>";
		$b=false;
	}

	$query=$ba->select("SELECT port from isdn WHERE gr!='NULL'");
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($frId,"g:")==0) && ($entry['port']==$frId)){
			$ret.="<option value='".$entry['port']."' selected>".$entry['port']."</option>";
			$b=true;
		}
		if (!$b)  $ret.="<option value='".$entry['port']."'>".$entry['port']."</option>";
		$b=false;
	}
	$ret.="</select>";
	$ret.="</fieldset>";
	return $ret;
}
function fromAnalog($frId){
	$ba=new beroAri();
	$b=false;
	$ret="<fieldset id='FromAnalogBox' onmouseover=\"Tip('" . DIALPLAN_FROM_ANALOG . "')\" onmouseout='UnTip()'>";
	$query=$ba->select("SELECT distinct gr from analog WHERE gr!='NULL'");
	$ret.="<select name='fromIdAnalog' id='from_analog'>";
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($frId,"g:")==1) && ("g:".$entry['gr']==$frId)){
			$ret.="<option value='g:".$entry['gr']."' selected>g:".$entry['gr']."</option>";
			$b=true;
		}
		if(!$b)  $ret.="<option value='g:".$entry['gr']."'>g:".$entry['gr']."</option>";
		$b=false;
	}

	$query=$ba->select("SELECT port from analog WHERE gr!='NULL'");
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($frId,"g:")==0) && ($entry['port']==$frId)){
			$ret.="<option value='".$entry['port']."' selected>".$entry['port']."</option>";
			$b=true;
		}
		if (!$b)  $ret.="<option value='".$entry['port']."'>".$entry['port']."</option>";
		$b=false;
	}
	$ret.="</select>";
	$ret.="</fieldset>";
	return $ret;
}

function fromGsm($frId){
	$ba=new beroAri();
	$b=false;
	$ret="<fieldset id='FromGsmBox' onmouseover=\"Tip('" . DIALPLAN_FROM_GSM . "')\" onmouseout='UnTip()'>";
	$query=$ba->select("SELECT distinct gr from gsm WHERE gr!='NULL'");
	$ret.="<select name='fromIdGsm' id='from_gsm'>";
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($frId,"g:")==1) && ("g:".$entry['gr']==$frId)){
			$ret.="<option value='g:".$entry['gr']."' selected>g:".$entry['gr']."</option>";
			$b=true;
		}
		if(!$b)  $ret.="<option value='g:".$entry['gr']."'>g:".$entry['gr']."</option>";
		$b=false;
	}

	$query=$ba->select("SELECT port from gsm WHERE gr!='NULL'");
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($frId,"g:")==0) && ($entry['port']==$frId)){
			$ret.="<option value='".$entry['port']."' selected>".$entry['port']."</option>";
			$b=true;
		}
		if (!$b)  $ret.="<option value='".$entry['port']."'>".$entry['port']."</option>";
		$b=false;
	}
	$ret.="</select>";
	$ret.="</fieldset>";
	return $ret;
}

function toIsdn($toId){
	$ba=new beroAri();
	$ret="<fieldset id='toIsdnBox' onmouseover=\"Tip('" . DIALPLAN_TO_ISDN . "')\" onmouseout='UnTip()'>";
	$query=$ba->select("SELECT distinct gr from isdn WHERE gr!='NULL'");
	$ret.="<select name='toIsdn' id='to_isdn'>";
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($toId,"g:")==1) && ("g:".$entry['gr']==$toId)){
			$ret.="<option value='g:".$entry['gr']."' selected>g:".$entry['gr']."</option>";
		}else{
			$ret.="<option value='g:".$entry['gr']."'>g:".$entry['gr']."</option>";
		}
	}
	$query=$ba->select("SELECT port from isdn WHERE gr!='NULL'");
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($toId,"g:")==0) && ($entry['port']==$toId)){
			$ret.="<option value='".$entry['port']."' selected>".$entry['port']."</option>";
		}else{
			$ret.="<option value='".$entry['port']."'>".$entry['port']."</option>";
		}
	}
	$ret.="</select>";
	$ret.="</fieldset>";
	return $ret;
}
function toSip($toId, $toDirection){
	$ba=new beroAri();
	$ret="<fieldset id='toSipBox' onmouseover=\"Tip('" . DIALPLAN_TO_SIP . "')\" onmouseout='UnTip()'>";
	$query=$ba->select("SELECT name from sip");
	$ret.="<select id='to_sip' name='toSip' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");'>";
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($toId,"p:")==1) && ("p:".$entry['name']==$toId)){
			$ret.="<option value='p:".$entry['name']."' selected>p:".$entry['name']."</option>";
		}else{
			$ret.="<option value='p:".$entry['name']."'>p:".$entry['name']."</option>";
		}
	}
	//check if manual
	if (substr_count($toId,"p:")==0 && $toDirection=='sip'){
		$ret.="<option value='manual' selected>".DIALPLAN_MANUAL_ADDRESS_DIS."</option>";
		$ret.="</select><br>";
		$ret.="<input type='text' name='manualsip' id='manualsip' value='".stripslashes($toId)."'>";
	}else{
		$ret.="<option value='manual'>".DIALPLAN_MANUAL_ADDRESS_DIS."</option>";
		$ret.="</select><br>";
		$ret.="<input type='text' name='manualsip' id='manualsip'>";
	}
	$ret.="</fieldset>";
	return $ret;
}
function toAnalog($toId){
	$ba=new beroAri();
	$ret="<fieldset id='toAnalogBox' onmouseover=\"Tip('" . DIALPLAN_TO_ANALOG . "')\" onmouseout='UnTip()'>";
	$query=$ba->select("SELECT distinct gr from analog WHERE gr!='NULL'");
	$ret.="<select name='toAnalog' id='to_analog'>";
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($toId,"g:")==1) && ("g:".$entry['gr']==$toId)){
			$ret.="<option value='g:".$entry['gr']."' selected>g:".$entry['gr']."</option>";
		}else{
			$ret.="<option value='g:".$entry['gr']."'>g:".$entry['gr']."</option>";
		}
	}
	$query=$ba->select("SELECT port from analog WHERE gr!='NULL'");
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($toId,"g:")==0) && ($entry['port']==$toId)){
			$ret.="<option value='".$entry['port']."' selected>".$entry['port']."</option>";
		}else{
			$ret.="<option value='".$entry['port']."'>".$entry['port']."</option>";
		}
	}
	$ret.="</select>";
	$ret.="</fieldset>";
	return $ret;
}
function toGsm($toId){
	$ba=new beroAri();
	$ret="<fieldset id='toGsmBox' onmouseover=\"Tip('" . DIALPLAN_TO_GSM . "')\" onmouseout='UnTip()'>";
	$query=$ba->select("SELECT distinct gr from gsm WHERE gr!='NULL'");
	$ret.="<select name='toGsm' id='to_gsm'>";
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($toId,"g:")==1) && ("g:".$entry['gr']==$toId)){
			$ret.="<option value='g:".$entry['gr']."' selected>g:".$entry['gr']."</option>";
		}else{
			$ret.="<option value='g:".$entry['gr']."'>g:".$entry['gr']."</option>";
		}
	}
	$query=$ba->select("SELECT port from gsm WHERE gr!='NULL'");
	while ($entry=$ba->fetch_array($query)){
		if ((substr_count($toId,"g:")==0) && ($entry['port']==$toId)){
			$ret.="<option value='".$entry['port']."' selected>".$entry['port']."</option>";
		}else{
			$ret.="<option value='".$entry['port']."'>".$entry['port']."</option>";
		}
	}
	$ret.="</select>";
	$ret.="</fieldset>";
	return $ret;
}


function fromDirection($fromDirection) {
	$ba=new beroAri();
	$query_a=$ba->select("SELECT distinct gr from analog WHERE gr!='NULL'");
	$query_i=$ba->select("SELECT distinct gr from isdn WHERE gr!='NULL'");
	$query_g=$ba->select("SELECT distinct gr from gsm WHERE gr!='NULL'");
	if (($fromDirection == 'sip')) {
		$ret = "<select  id='fromDirection' name='fromDirection' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");' onmouseover=\"Tip('" . DIALPLAN_DIRECTION . "')\" onmouseout='UnTip()'>".
			"<option value='sip' selected>SIP</option>";
		if (sqlite_num_rows($query_i)>0)	$ret.="<option value='isdn'>ISDN</option>";
		if (sqlite_num_rows($query_a)>0)	$ret.="<option value='analog'>ANALOG</option>";
		if (sqlite_num_rows($query_g)>0)	$ret.="<option value='gsm'>GSM</option>";
		$ret.="</select>";
	} elseif (($fromDirection == 'isdn')) {
		$ret = "<select id='fromDirection' name='fromDirection' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");' onmouseover=\"Tip('" . DIALPLAN_DIRECTION . "')\" onmouseout='UnTip()'>".
			"<option value='sip'>SIP</option>";
		$ret.="<option value='isdn' selected>ISDN</option>";
		if (sqlite_num_rows($query_a)>0) $ret.="<option value='analog'>ANALOG</option>";
		if (sqlite_num_rows($query_g)>0) $ret.="<option value='gsm'>GSM</option>";
		$ret.="</select>";
	} elseif (($fromDirection == 'analog')) {
		$ret = "<select id='fromDirection' name='fromDirection' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");' onmouseover=\"Tip('" . DIALPLAN_DIRECTION . "')\" onmouseout='UnTip()'>".
			"<option value='sip'>SIP</option>";
		if (sqlite_num_rows($query_i)>0) $ret.="<option value='isdn'>ISDN</option>";
		$ret.="<option value='analog' selected>ANALOG</option>";
		if (sqlite_num_rows($query_g)>0) $ret.="<option value='gsm'>GSM</option>";
		$ret.="</select>";
	} elseif (($fromDirection == 'gsm')) {
		$ret = "<select id='fromDirection' name='fromDirection' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");' onmouseover=\"Tip('" . DIALPLAN_DIRECTION . "')\" onmouseout='UnTip()'>".
			"<option value='sip'>SIP</option>";
		if (sqlite_num_rows($query_i)>0) $ret.="<option value='isdn'>ISDN</option>";
		if (sqlite_num_rows($query_a)>0) $ret.="<option value='analog'>ANALOG</option>";
		$ret.="<option value='gsm' selected>GSM</option>";

		$ret.="</select>";
	} else {
		$ret = "<select id='fromDirection' name='fromDirection' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");' onmouseover=\"Tip('" . DIALPLAN_DIRECTION . "')\" onmouseout='UnTip()'>".
			"<option value='sip'>SIP</option>";
		if (sqlite_num_rows($query_i)>0) $ret.="<option value='isdn'>ISDN</option>";
		if (sqlite_num_rows($query_a)>0)$ret.="<option value='analog'>ANALOG</option>";
		if (sqlite_num_rows($query_g)>0)$ret.="<option value='gsm'>GSM</option>";
		$ret.="</select>";
	}
	return $ret;
}

function toDirection($toDirection) {
	$ba=new beroAri();
	$query_a=$ba->select("SELECT distinct gr from analog WHERE gr!='NULL'");
	$query_i=$ba->select("SELECT distinct gr from isdn WHERE gr!='NULL'");
	$query_g=$ba->select("SELECT distinct gr from gsm WHERE gr!='NULL'");
	if (($toDirection == 'sip')) {
		$ret = "<select  id='toDirection' name='toDirection' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");' onmouseover=\"Tip('" . DIALPLAN_DIRECTION . "')\" onmouseout='UnTip()'>".
			"<option value='sip' selected>SIP</option>";
		if (sqlite_num_rows($query_i)>0) $ret.="<option value='isdn'>ISDN</option>";
		if (sqlite_num_rows($query_a)>0) $ret.="<option value='analog'>ANALOG</option>";
		if (sqlite_num_rows($query_g)>0) $ret.="<option value='gsm'>GSM</option>";
		$ret.="</select>";
	} elseif (($toDirection == 'isdn')) {
		$ret = "<select id='toDirection' name='toDirection' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");' onmouseover=\"Tip('" . DIALPLAN_DIRECTION . "')\" onmouseout='UnTip()'>".
			"<option value='sip'>SIP</option>";
		$ret.="<option value='isdn' selected>ISDN</option>";
		if (sqlite_num_rows($query_a)>0) $ret.="<option value='analog'>ANALOG</option>";
		if (sqlite_num_rows($query_g)>0) $ret.="<option value='gsm'>GSM</option>";
		$ret.="</select>";
	} elseif (($toDirection == 'analog')) {
		$ret = "<select id='toDirection' name='toDirection' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");' onmouseover=\"Tip('" . DIALPLAN_DIRECTION . "')\" onmouseout='UnTip()'>".
			"<option value='sip'>SIP</option>";
		if (sqlite_num_rows($query_i)>0) $ret.="<option value='isdn'>ISDN</option>";
		$ret.="<option value='analog' selected>ANALOG</option>";
		if (sqlite_num_rows($query_g)>0) $ret.="<option value='gsm'>GSM</option>";
		$ret.="</select>";
	} elseif (($toDirection == 'gsm')) {
		$ret = "<select id='toDirection' name='toDirection' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");' onmouseover=\"Tip('" . DIALPLAN_DIRECTION . "')\" onmouseout='UnTip()'>".
			"<option value='sip'>SIP</option>";
		if (sqlite_num_rows($query_i)>0) $ret.="<option value='isdn'>ISDN</option>";
		if (sqlite_num_rows($query_a)>0)  $ret.="<option value='analog'>ANALOG</option>";
		$ret.="<option value='gsm' selected>GSM</option>";
		$ret.="</select>";
	} else {
		$ret = "<select id='toDirection' name='toDirection' onchange='hide_elements(\"".DIALPLAN_FROM_ID_DIS."\",\"".DIALPLAN_MATCH_TYPE_DIS."\");' onmouseover=\"Tip('" . DIALPLAN_DIRECTION . "')\" onmouseout='UnTip()'>".
			"<option value='sip'>SIP</option>";
		if (sqlite_num_rows($query_i)>0) $ret.="<option value='isdn' selected>ISDN</option>" ;
		if (sqlite_num_rows($query_a)>0) $ret.="<option value='analog' selected>ANALOG</option>";
		if (sqlite_num_rows($query_g)>0) $ret.="<option value='gsm' selected>GSM</option>";
		$ret.="</select>";
	}
	return $ret;
}

function hol_daten(){
	$ba=new beroAri();
	if (isset($_GET['isdnid'])){

		$q = $ba->select("select * from dialplan where isdnid='".$_GET['isdnid']."'");
		$en=$ba->fetch_array($q);
		//$q1 = $ba->select("select toId from dialplan where isdnid='".$_GET['isdnid']."' and direction='sip-isdn'");
		//$en1=$ba->fetch_array($q1);

		$e[0]['fromDirection'] = $en['fromDirection'];
		$e[0]['toDirection'] = $en['toDirection'];
		$e[0]['fromId'] = $en['fromId'];
		/*echo "fromId:".$en['fromId']."<br>";
		echo "toId:".$en1['toId']."<br>";*/

		$e[0]['toId'] = $en['toId'];
		$e[0]['dest'] = $en['dest'];
		$newDest=str_replace($_GET['isdnid'],'',$en['newDest']);
		$e[0]['newDest'] = $newDest;
		$e[0]['src'] = $en['src'];
		$e[0]['newSrc'] = $en['newSrc'];
		$e[0]['config'] = $en['config'];
		$e[0]['comment'] = $en['comment'];
		$e[0]['posid'] = $en['posId'];
		return $e;

	}elseif (isset($_GET['id'])){
		$q=$ba->select("select * from dialplan where id='".$_GET['id']."'");
		$e=$ba->stripslashes_deep(sqlite_fetch_all($q));
		return $e;

	}elseif (isset($_GET['copy'])){
		$q=$ba->select("select * from dialplan where id='".$_GET['copy']."'");
		$e=$ba->stripslashes_deep(sqlite_fetch_all($q));
		return $e;
	}

}
	$e=hol_daten();
	echo "<script type=\"text/javascript\" src=\"../includes/notes/wz_tooltip.js\"></script>
		<center>
		<form class='extensions_form' name='dialplan' action='dialplan_submit.php' method='POST' onsubmit='return (is_submit(this) && specChar(comment.value,\"The comment\"));'>
		<table border='1' style='border-collapse:collapse;' width='570'>
		<tr>
		<td>
			<input type=hidden name=start value=" . $page . ">
		    <input type=hidden name=dir value=" . $dir . ">
		    <input type=hidden name=search value=" . $search . ">
		<table border='0'>
		<tr>
		<td><b>".DIALPLAN_FROM_DIRECTION_DIS.":</b></td>
		<td>".fromDirection($e[0]['fromDirection'])."</td>
		<td><b>".DIALPLAN_TO_DIRECTION_DIS.":</b></td>
		<td>".toDirection($e[0]['toDirection'])."</td>
		</tr>
		<tr>
		<td id='from_txt'><b>".DIALPLAN_MATCH_TYPE_DIS.":<br><br>".DIALPLAN_FROM_ID_DIS.":</b></td>
		<td>" . fromSip($e[0]['fromId'], $e[0]['fromDirection']) . fromIsdn($e[0]['fromId']) . fromAnalog($e[0]['fromId']) . fromGsm($e[0]['fromId']) . "</td>
		<td><b>".DIALPLAN_TO_ID_DIS.":</b></td>
		<td>" .  toSip($e[0]['toId'],$e[0]['toDirection']) . toIsdn($e[0]['toId']) . toAnalog($e[0]['toId']) . toGsm($e[0]['toId']) . "</td>
		</tr>
		<tr>
		<td><b>".DIALPLAN_DESTINATION_DIS.":</b></td>
		<td><input type='text' name='dest' value='".$e[0]['dest']."' onmouseover=\"Tip('" . DIALPLAN_DESTINATION . "')\" onmouseout='UnTip()'></td>
		<td><b>".DIALPLAN_NEW_DESTINATION_DIS.":</b></td>
		<td><input type='text' name='newDest' value='".$e[0]['newDest']."' onmouseover=\"Tip('" . DIALPLAN_NEW_DESTINATION . "')\" onmouseout='UnTip()'></td>
		</tr>
		<tr>
		<td><b>".DIALPLAN_SOURCE_DIS.":</b></td>
		<td><input type='text' name='src' value='".$e[0]['src']."' onmouseover=\"Tip('" . DIALPLAN_SOURCE . "')\" onmouseout='UnTip()'></td>
		<td><b>".DIALPLAN_NEW_SOURCE_DIS.":</b></td>
		<td><input type='text' name='newSrc' value='".$e[0]['newSrc']."' onmouseover=\"Tip('" . DIALPLAN_NEW_SOURCE . "')\" onmouseout='UnTip()'></td>
		</tr>
		<tr>
		<td><b>".DIALPLAN_COMMENTS_DIS.":</b></td>
		<td colspan='3'><textarea name='comment' cols='50' rows='4' wrap='physical' onKeyDown='limitText(this);' onKeyUp='limitText(this);'>".$e[0]['comment']."</textarea>
		</td>
		</tr>";
		if (isset($e[0]['activ']) && $e[0]['activ']==0){
			echo "<tr>
			<td><b>".DIALPLAN_ACTIV_DIS.":</b></td>
			<td><input type='checkbox' name='activ' value='1' ></td>
			</tr>";
		}else{
			echo "<tr>
			<td><b>".DIALPLAN_ACTIV_DIS.":</b></td>
			<td><input type='checkbox' name='activ' value='1' checked></td>
			</tr>";
		}
		if (!isset($_GET['id']))
		echo "<tr>
		<td><b>".DIALPLAN_FIRST_POSITION_DIS."</b></td>
		<td colspan='3'><input type='checkbox' name='first' value='1'></td>
		</tr>";
		echo "</table>
		</td>
		</tr>
		</table>";


		if (isset($_GET['id'])) {
			echo "<input name='id_upd' type='hidden' value='" . $_GET['id'] . "'>";
		}
		if (isset($_GET['copy'])) {
			echo "<input name='config' type='hidden' value='" . $e[0]['config'] . "'>";
		}
		if ($_GET['isdnid']!=""){
			echo "<input name='isdnid' type='hidden' value='" . $_GET['isdnid'] . "'>";
		}

		echo "<input name='submit' type='submit' value='".BUTTON_SAVE."' onmouseover=\"Tip('" . DIALPLAN_SAVE . "')\" onmouseout='UnTip()'>
		&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>

