<?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');
include './misc/config_parameter.php';

//Config Felder, die nicht in dem Extra Config Feld reinkommen.
$config_values=array("t38","dtmfmode","codecs",
					"ec","ectl","dnumplan","onumplan",
					"screen","pres","bearer_cap",
					"cd","ie_on_sip",
					"wait_for_cancel","from_sip_src_setting","from_pstn_src_setting",
					"isdn_oad_setting","isdn_oad2_setting",
					"isdn_qsigname_setting","isdn_redirected_nr_setting",
					"analog_oad_setting","analog_display_setting",
					"sip_from_user_setting","sip_from_display_setting","s2i_cpt","i2s_cpt");

?>

<!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/more.js"></script>
<script type="text/javascript" src="../includes/validation_modul.js"></script>
<script type="text/javascript" language="javascript" src="../includes/js/jquery-1.5.1.js"></script>

<script type="text/javascript">
function showdef(){
	//Configuration für neue Parameter
	var conf=new Object();
	//Configuration für die Parameter die schon vorprogrammiert sind
	var conf1=new Object();
	var config;
	<?php
	$e=hol_daten();
	echo "config='".trim($e[0]['config'])."';";
	echo "from='".trim($e[0]['fromDirection'])."';";
	echo "to='".trim($e[0]['toDirection'])."';";
	$conf=showconf($e);
	if ($conf!=NULL){
		foreach ($conf as $key => $value){
			echo "conf[\"".trim($key)."\"]=new Object();";
			foreach ($conf[$key] as $key1 => $value1){
				echo "conf[\"".trim($key)."\"][\"".trim($key1)."\"]=\"".trim($value1)."\";";
			}
		}
	}
	?>
	showdef_(conf,config,from,to)
;}
</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
$e=hol_daten();
print "<body onload='hide_elements(\"".$e[0]['fromDirection'] ."-".$e[0]['toDirection'] ."\"); disable(); showdef(); 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 showconf($e){
	$isgw = new isgwtelnet();
	$result=$isgw->isgw_login();
	//$conf ist die Variable fürs Hash
	$conf=null;
	$ba=new beroAri();
	if ($result!=false){
	$dialplanc=$isgw->isgw_dialplanconfig();
	$zeilen=split("\n",$dialplanc);

	//ISDN Configuration FROM
	if ($e[0]['fromDirection']=="isdn"){
		foreach ($zeilen as $zeile){
			if (stripos($zeile,'[')===0){
				preg_match("/\[(?<bez>.)\]\[(?<name>.+)\] (?<desc>.+) '(?<def>.*)'/",$zeile,$res);
				if ($res['bez']=="i" || $res['bez']=="p")
				$conf['from'][$res['name']]=$res['def'];
			}

		}
		if (substr_count($e[0]['fromId'],"g:")==1){
			$query=$ba->select("SELECT config from isdn WHERE gr='".substr($e[0]['fromId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from isdn WHERE port='".$e[0]['fromId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}
	}

	//ANALOG Configuration FROM
	if ($e[0]['fromDirection']=="analog"){
		foreach ($zeilen as $zeile){
			if (stripos($zeile,'[')===0){
				preg_match("/\[(?<bez>.)\]\[(?<name>.+)\] (?<desc>.+) '(?<def>.*)'/",$zeile,$res);
				if ($res['bez']=="a" || $res['bez']=="p")
				$conf['from'][$res['name']]=$res['def'];
			}

		}
		if (substr_count($e[0]['fromId'],"g:")==1){
			$query=$ba->select("SELECT config from analog WHERE gr='".substr($e[0]['fromId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from analog WHERE port='".$e[0]['fromId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}
	}

	//GSM Configuration FROM
	if ($e[0]['fromDirection']=="gsm"){
		foreach ($zeilen as $zeile){
			if (stripos($zeile,'[')===0){
				preg_match("/\[(?<bez>.)\]\[(?<name>.+)\] (?<desc>.+) '(?<def>.*)'/",$zeile,$res);
				if ($res['bez']=="g")
				$conf['from'][$res['name']]=$res['def'];
			}

		}
		if (substr_count($e[0]['fromId'],"g:")==1){
			$query=$ba->select("SELECT config from gsm WHERE gr='".substr($e[0]['fromId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from gsm WHERE port='".$e[0]['fromId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}
	}

	//SIP Configuration FROM
	if ($e[0]['fromDirection']=="sip"){
		foreach ($zeilen as $zeile){
			if (stripos($zeile,'[')===0){
				preg_match("/\[(?<bez>.)\]\[(?<name>.+)\] (?<desc>.+) '(?<def>.*)'/",$zeile,$res);
				if ($res['bez']=="s")
				$conf['from'][$res['name']]=$res['def'];
			}

		}
		if (substr_count($e[0]['fromId'],"p:")==1 || substr_count($e[0]['fromId'],"d:")==1){
			$query=$ba->select("SELECT config from sip WHERE name='".substr($e[0]['fromId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from sip WHERE name='".$e[0]['fromId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}
	}

	//ISDN Configuration TO
	if ($e[0]['toDirection']=="isdn"){
		foreach ($zeilen as $zeile){
			if (stripos($zeile,'[')===0){
				preg_match("/\[(?<bez>.)\]\[(?<name>.+)\] (?<desc>.+) '(?<def>.*)'/",$zeile,$res);
				if ($res['bez']=="i" || $res['bez']=="p")
				$conf['to'][$res['name']]=$res['def'];
			}

		}
		if (substr_count($e[0]['toId'],"g:")==1){
			$query=$ba->select("SELECT config from isdn WHERE gr='".substr($e[0]['toId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from isdn WHERE port='".$e[0]['toId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}
	}



	//ANALOG Configuration TO
	if ($e[0]['toDirection']=="analog"){
		foreach ($zeilen as $zeile){
			if (stripos($zeile,'[')===0){
				preg_match("/\[(?<bez>.)\]\[(?<name>.+)\] (?<desc>.+) '(?<def>.*)'/",$zeile,$res);
				if ($res['bez']=="a" || $res['bez']=="p")
				$conf['to'][$res['name']]=$res['def'];
			}

		}
		if (substr_count($e[0]['toId'],"g:")==1){
			$query=$ba->select("SELECT config from analog WHERE gr='".substr($e[0]['toId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from analog WHERE port='".$e[0]['toId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}
	}

	//GSM Configuration TO
	if ($e[0]['toDirection']=="gsm"){
		foreach ($zeilen as $zeile){
			if (stripos($zeile,'[')===0){
				preg_match("/\[(?<bez>.)\]\[(?<name>.+)\] (?<desc>.+) '(?<def>.*)'/",$zeile,$res);
				if ($res['bez']=="g")
				$conf['to'][$res['name']]=$res['def'];
			}

		}
		if (substr_count($e[0]['toId'],"g:")==1){
			$query=$ba->select("SELECT config from gsm WHERE gr='".substr($e[0]['toId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from gsm WHERE port='".$e[0]['toId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}
	}

	//SIP Configuration TO
	if ($e[0]['toDirection']=="sip"){
		foreach ($zeilen as $zeile){
			if (stripos($zeile,'[')===0){
				preg_match("/\[(?<bez>.)\]\[(?<name>.+)\] (?<desc>.+) '(?<def>.*)'/",$zeile,$res);
				if ($res['bez']=="s")
				$conf['to'][$res['name']]=$res['def'];
			}

		}
		if (substr_count($e[0]['toId'],"p:")==1 || substr_count($e[0]['toId'],"d:")==1){
			$query=$ba->select("SELECT config from sip WHERE name='".substr($e[0]['toId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from sip WHERE name='".$e[0]['toId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}
	}

	//Dialplan config
	if ($e[0]['config']!=""){
		$configs=split(',',$e[0]['config']);
		foreach ($configs as $value){
			$key=split('=',$value);
			if (($key[0]!="")) {
				if (array_key_exists($key[0],$conf['from'])) $conf['from'][$key[0]]=$key[1];
				if (array_key_exists($key[0],$conf['to'])) $conf['to'][$key[0]]=$key[1];
				if (!array_key_exists($key[0],$conf['from']) && !array_key_exists($key[0],$conf['to'])) $conf['from'][$key[0]]=$key[1];
			}
		}
	}
//Wenn ISGW nicht gestartet ist
}else{
	//ISDN Configuration FROM
	if ($e[0]['fromDirection']=="isdn"){
		if (substr_count($e[0]['fromId'],"g:")==1){
			$query=$ba->select("SELECT config from isdn WHERE gr='".substr($e[0]['fromId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from isdn WHERE port='".$e[0]['fromId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}
	}

	//ANALOG Configuration FROM
	if ($e[0]['fromDirection']=="analog"){
		if (substr_count($e[0]['fromId'],"g:")==1){
			$query=$ba->select("SELECT config from analog WHERE gr='".substr($e[0]['fromId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from analog WHERE port='".$e[0]['fromId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}
	}

	//GSM Configuration FROM
	if ($e[0]['fromDirection']=="gsm"){
		if (substr_count($e[0]['fromId'],"g:")==1){
			$query=$ba->select("SELECT config from gsm WHERE gr='".substr($e[0]['fromId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from gsm WHERE port='".$e[0]['fromId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}
	}

	//SIP Configuration FROM
	if ($e[0]['fromDirection']=="sip"){
		if (substr_count($e[0]['fromId'],"p:")==1 || substr_count($e[0]['fromId'],"d:")==1){
			$query=$ba->select("SELECT config from sip WHERE name='".substr($e[0]['fromId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from sip WHERE name='".$e[0]['fromId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['from'][$key[0]]=$key[1];
			}
		}
	}

	//ISDN Configuration FROM
	if ($e[0]['toDirection']=="isdn"){
		if (substr_count($e[0]['toId'],"g:")==1){
			$query=$ba->select("SELECT config from isdn WHERE gr='".substr($e[0]['toId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from isdn WHERE port='".$e[0]['toId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}
	}

	//ANALOG Configuration FROM
	if ($e[0]['toDirection']=="analog"){
		if (substr_count($e[0]['toId'],"g:")==1){
			$query=$ba->select("SELECT config from analog WHERE gr='".substr($e[0]['toId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from analog WHERE port='".$e[0]['toId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}
	}

	//GSM Configuration FROM
	if ($e[0]['toDirection']=="gsm"){
		if (substr_count($e[0]['toId'],"g:")==1){
			$query=$ba->select("SELECT config from gsm WHERE gr='".substr($e[0]['toId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from gsm WHERE port='".$e[0]['toId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}
	}

	//SIP Configuration FROM
	if ($e[0]['toDirection']=="sip"){
		if (substr_count($e[0]['toId'],"p:")==1 || substr_count($e[0]['toId'],"d:")==1){
			$query=$ba->select("SELECT config from sip WHERE name='".substr($e[0]['toId'], 2)."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}else{
			$query=$ba->select("SELECT config from sip WHERE name='".$e[0]['toId']."'");
			$config=sqlite_fetch_single($query);
			$configs=split(',',$config);
			foreach ($configs as $value){
				$key=split('=',$value);
				if ($key[0]!="") $conf['to'][$key[0]]=$key[1];
			}
		}
	}

	if ($e[0]['config']!=""){
		$configs=split(',',$e[0]['config']);
		foreach ($configs as $value){
			$key=split('=',$value);
			if (($key[0]!="")) {
				if (array_key_exists($key[0],$conf['from'])) $conf['from'][$key[0]]=$key[1];
				elseif (array_key_exists($key[0],$conf['to'])) $conf['to'][$key[0]]=$key[1];
				else $conf['from'][$key[0]]=$key[1];
			}
		}
	}
}
return $conf;
}

function showdefmc($e){
	global $config_values;
	$isgw = new isgwtelnet();
	$result=$isgw->isgw_login();
	if ($result!=false){
		$dialplanc=$isgw->isgw_dialplanconfig();
		$zeilen=split("\n",$dialplanc);
		foreach ($zeilen as $zeile){
			if (stripos($zeile,'[')===0){
				preg_match("/\[(?<bez>.+)\]\[(?<name>.+)\][\s]*(?<desc>.+)[\s]*\<(?<val>.*)\>[\s]*'(?<def>.*)'/",$zeile,$res);
				if (!in_array($res['name'],$config_values)){
					echo "<script>
						var extra_tooltip=document.getElementById('extra_tooltip');
						extra_tooltip.innerHTML=extra_tooltip.innerHTML+'<p>".DIALPLAN_OPTION_DIS."<b>&nbsp;".$res['name']."</b><br>".DIALPLAN_VALUES_DIS."<b>&nbsp;&lt;".$res['val']."&gt;</b><br><i>".$res['desc']."</i></p>';
					</script>";
					//echo "<tr onmouseover=\"Tip('".$res['desc']."')\" onmouseout='UnTip()'><td>".$res['name']." <label id='l".$res['name']."'>(def ".$res['def'].")</label></td><td><input  id='".$res['name']."' size='7' name='config_".$res['name']."' ></td></tr>";
				}
			}
		}

		$conf=showconf($e);
		if ($e[0]['config']!=""){
			$configs=split(',',$e[0]['config']);
				foreach ($configs as $value){
				$key=split('=',$value);
				if (($key[0]!="") && !in_array($key[0],$config_values)){
					echo "<script>var addit_options=document.getElementById('addit_options');
						if (addit_options.innerHTML=='')
							addit_options.innerHTML='".$key[0]."=".$key[1]."';
						else
							addit_options.innerHTML=addit_options.innerHTML+'\\n".$key[0]."=".$key[1]."';</script>";
				}elseif (($key[0]!="") && ($key[1]=='') && !in_array($key[0],$config_values)){
					echo "<script>var addit_options=document.getElementById('addit_options');
						if (addit_options.innerHTML=='')
							addit_options.innerHTML='".$key[0]."=';
						else
							addit_options.innerHTML=addit_options.innerHTML+'\\n".$key[0]."=';</script>";
				}
			}
		}
	}
}



function hol_daten(){
	$ba=new beroAri();
	if  (isset($_GET['id'])){
		$q=$ba->select("select * from dialplan where id='".$_GET['id']."'");
		$e=sqlite_fetch_all($q);
		return $e;

	}
}

	echo "<script type=\"text/javascript\" src=\"../includes/notes/wz_tooltip.js\"></script>
		<center>";
	if ($e[0]['toDirection']=="sip" ||$e[0]['fromDirection']=="sip" || ($e[0]['toDirection']=="isdn" && $e[0]['fromDirection']=="isdn")){
		echo "<a class='popup_download' href='javascript:show_config_sip();'><img border='0' src='../includes/images/sip.png'></a>";
	}
	if ($e[0]['toDirection']=="isdn" ||$e[0]['fromDirection']=="isdn"){
		echo "<a class='popup_download' href='javascript:show_config_isdn();'><img border='0' src='../includes/images/isdn.png'></a>";
	}
	if ($e[0]['toDirection']=="analog" ||$e[0]['fromDirection']=="analog"){
		echo "<a class='popup_download' href='javascript:show_config_analog();'><img border='0' src='../includes/images/analog.png'></a>";
	}
	if ($e[0]['toDirection']=="analog"){
		if ((substr_count($e[0]['toId'],"g:")==1)){
			$q=$ba->select("select distinct port_type from analog where gr='".substr($e[0]['toId'],2)."'");
			$portTypeTo=sqlite_fetch_single($q);
		}else{
			$q=$ba->select("select port_type from analog where port='".$e[0]['toId']."'");
			$portTypeTo=sqlite_fetch_single($q);
		}
	}
	if ($e[0]['fromDirection']=="analog"){
		if ((substr_count($e[0]['fromId'],"g:")==1)){
			$q=$ba->select("select distinct port_type from analog where gr='".substr($e[0]['fromId'],2)."'");
			$portTypeFrom=sqlite_fetch_single($q);
		}else{
			$q=$ba->select("select port_type from analog where port='".$e[0]['fromId']."'");
			$portTypeFrom=sqlite_fetch_single($q);
		}
	}

	//Wenn eine Richtung der Direction FXS ist, wird das Dialplan Source Setting nicht angezeigt
	($portTypeFrom!="FXS" && $portTypeTo!="FXS") ?  $showDialSrc="" : $showDialSrc="style='display:none'";

	//Wenn eine Richtung der Direction FXO ist, wird das Caller ID Mapping nicht angezeigt
	($portTypeFrom!="FXO" && $portTypeTo!="FXO") ?  $showCallerMapp="" : $showCallerMapp="style='display:none'";

	echo "<a class='popup_download' href='javascript:show_config_addit();'><img border='0' src='../includes/images/moreb.png'></a>";
	echo"<form class='extensions_form' name='config' action='more_submit.php' method='POST'>
		<br/>
		<table border='1' cellspacing='0' id='config_additional' width='400' style='border-collapse:collapse;'>
			<tr>
				<td><table border='0'>
						<tr><td colspan='2' align='center'><b>".DIALPLAN_CONFIGURATION_DIS."</b></td></tr>
						<tr><td colspan='2'>&nbsp;</td></tr>

						<tr onmouseover=\"Tip('".ADDIT_OPTIONS."')\" onmouseout='UnTip()'>
							<td colspan='2'><b>".DIALPLAN_ADDITIONAL_CONFIG_DIS."</b></td>
						</tr>
						<tr onmouseover=\"Tip('".ADDIT_OPTIONS."')\" onmouseout='UnTip()'>
							<td colspan='2'><textarea name='addit_options' id='addit_options' rows='4' style='width:305px;'></textarea></td>
						</tr>
						<tr>
							<td colspan='2'>
							<br>
							<b>".DIALPLAN_ADDITIONAL_CONFIG_DOC_DIS."</b>
							</td>
						</tr>
						<tr>
							<td colspan='2'>
							<p id='extra_tooltip' style='height: 150px; width:305px; overflow: auto; border: 1px solid #A31D26; background: none repeat scroll 0% 0% rgb(238, 238, 238); color: rgb(0, 0, 0);'>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<table border='1' cellspacing='0' cellpadding='0' id='config_analog' width='400' style='border-collapse:collapse;'>
			<tr>
				<td><table border='0'>
						<tr><td colspan='3' align='center'><b>".DIALPLAN_CONFIGURATION_DIS."</b></td>
						<tr><td colspan='2' ></td><td><b>".DIALPLAN_DEFAULT_DIS."</b></td></tr>";
						if ($e[0]['fromDirection']!="isdn" && $e[0]['toDirection']!="isdn"){
							echo "<tr onmouseover=\"Tip('".EC."')\" onmouseout='UnTip()'>
								<td><b>".DIALPLAN_EC_DIS."</b></td>
								<td>".ec()."</td>
								<td><input type='checkbox' value='1' name='def_ec' id='def_ec' checked onclick='if (def_ec.checked) ec.disabled=true; else ec.disabled=false;'/></td>
							</tr>
							<tr onmouseover=\"Tip('".EC_TAIL."')\" onmouseout='UnTip()'>
								<td><b>".DIALPLAN_EC_TAIL_LENGTH_DIS."</b></td>
								<td>".ec_tail()."</td>
								<td><input type='checkbox' value='1' name='def_ectl' id='def_ectl' checked  onclick='if (def_ectl.checked) ectl.disabled=true; else ectl.disabled=false;'/></td>
							</tr>";
						}
						echo "<tr onmouseover=\"Tip('".FROM_PSTN_SRC_SETTING."')\" onmouseout='UnTip()' id='from_pstn_src_setting_tr' ". $showDialSrc .">
							<td><b>".DIALPLAN_FROM_PSTN_SRC_SETTING_DIS."</b></td>
							<td>".from_pstn_src_setting('analog')."</td>
							<td><input type='checkbox' value='1' name='def_from_pstn_src_setting_analog' id='def_from_pstn_src_setting_analog' checked onclick='if (def_from_pstn_src_setting_analog.checked) from_pstn_src_setting_analog.disabled=true; else from_pstn_src_setting_analog.disabled=false;'/></td>
						</tr>
						<tr>
							<td colspan='3'>&nbsp;</td>
						</tr>
						<tr ". $showCallerMapp .">
							<th colspan='3'>".DIALPLAN_CALLER_ID_MAPPING_DIS."</th>
						</tr>
						<tr id='analog_oad_setting_tr' ". $showCallerMapp .">
							<td><b>".DIALPLAN_ANALOG_CLIP_SETTING_DIS."</b></td>
							<td>".caller_id_mapping_pstn('analog_oad_setting','analog')."</td>
							<td><input type='checkbox' value='1' name='def_analog_oad_setting' id='def_analog_oad_setting' checked onclick='if (def_analog_oad_setting.checked) analog_oad_setting.disabled=true; else analog_oad_setting.disabled=false;'/></td>
						</tr>
						<tr id='analog_display_setting_tr' ". $showCallerMapp .">
							<td><b>".DIALPLAN_ANALOG_CNIP_SETTING_DIS."</b></td>
							<td>".caller_id_mapping_pstn('analog_display_setting','analog')."</td>
							<td><input type='checkbox' value='1' name='def_analog_display_setting' id='def_analog_display_setting' checked onclick='if (def_analog_display_setting.checked) analog_display_setting.disabled=true; else analog_display_setting.disabled=false;'/></td>
						</tr>
						<tr>
							<td colspan='3'>&nbsp;</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<table border='1' cellspacing='0' id='config_isdn' width='400' style='border-collapse:collapse;'>
			<tr>
				<td><table border='0'>
					<tr><td colspan='3' align='center'><b>".DIALPLAN_CONFIGURATION_DIS."</b></td></tr>
					<tr><td colspan='2' ></td><td><b>".DIALPLAN_DEFAULT_DIS."</b></td></tr>";
					if ($e[0]['fromDirection']=="isdn" || $e[0]['toDirection']=="isdn"){
						echo "<tr onmouseover=\"Tip('".EC."')\" onmouseout='UnTip()'>
							<td><b>".DIALPLAN_EC_DIS."</b></td>
							<td>".ec()."</td>
							<td><input type='checkbox' value='1' name='def_ec' id='def_ec' checked onclick='if (def_ec.checked) ec.disabled=true; else ec.disabled=false;'/></td>
						</tr>
						<tr onmouseover=\"Tip('".EC_TAIL."')\" onmouseout='UnTip()'>
							<td><b>".DIALPLAN_EC_TAIL_LENGTH_DIS."</b></td>
							<td>".ec_tail()."</td>
							<td><input type='checkbox' value='1' name='def_ectl' id='def_ectl' checked  onclick='if (def_ectl.checked) ectl.disabled=true; else ectl.disabled=false;'/></td>
						</tr>";
					}
					echo "<tr onmouseover=\"Tip('".DNUMPLAN."')\" onmouseout='UnTip()'>
						<td><b>".DIALPLAN_DNUMPLAN_DIS."</b></td>
						<td>".dialplans('dnumplan')."</td>
		    			<td><input type='checkbox' value='1' name='def_dnumplan' id='def_dnumplan' checked  onclick='if (def_dnumplan.checked) dnumplan.disabled=true; else dnumplan.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".ONUMPLAN."')\" onmouseout='UnTip()'>
						<td><b>".DIALPLAN_ONUMPLAN_DIS."</b></td>
						<td>".dialplans('onumplan')."</td>
						<td><input type='checkbox' value='1' name='def_onumplan' id='def_onumplan' checked  onclick='if (def_onumplan.checked) onumplan.disabled=true; else onumplan.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".SCREENING."')\" onmouseout='UnTip()'>
						<td><b>".DIALPLAN_SCREENING_DIS."</b></td>
		    			<td>".screen()."</td>
   		    			<td><input type='checkbox' value='1' name='def_screen' id='def_screen' checked onclick='if (def_screen.checked) screen.disabled=true; else screen.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".PRES."')\" onmouseout='UnTip()'>
						<td><b>".DIALPLAN_PRESENTATION_DIS."</b></td>
		    			<td>".pres()."</td>
		    			<td><input type='checkbox' value='1' name='def_pres' id='def_pres' checked onclick='if (def_pres.checked) pres.disabled=true; else pres.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".BEARER."')\" onmouseout='UnTip()'>
						<td><b>".DIALPLAN_BEARER_DIS."</b></td>
		    			<td>".bearer_cap()."</td>
   		    			<td><input type='checkbox' value='1' name='def_bearer_cap' id='def_bearer_cap' checked onclick='if (def_bearer_cap.checked) bearer_cap.disabled=true; else bearer_cap.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".CD."')\" onmouseout='UnTip()'>
						<td><b>".DIALPLAN_CALL_DEFLECTION_DIS."</b></td>
		    			<td>".cd()."</td>
		    			<td><input type='checkbox' value='1' name='def_cd' id='def_cd' checked onclick='if (def_cd.checked) cd.disabled=true; else cd.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".FROM_PSTN_SRC_SETTING."')\" onmouseout='UnTip()' id='from_pstn_src_setting_tr'>
						<td><b>".DIALPLAN_FROM_PSTN_SRC_SETTING_DIS."</b></td>
						<td>".from_pstn_src_setting('isdn')."</td>
						<td><input type='checkbox' value='1' name='def_from_pstn_src_setting_isdn' id='def_from_pstn_src_setting_isdn' checked onclick='if (def_from_pstn_src_setting_isdn.checked) from_pstn_src_setting_isdn.disabled=true; else from_pstn_src_setting_isdn.disabled=false;'/></td>
					</tr>
					<tr>
						<td colspan='3'>&nbsp;</td>
					</tr>
					<tr>
						<th colspan='3'>".DIALPLAN_CALLER_ID_MAPPING_DIS."</th>
					</tr>
					<tr onmouseover=\"Tip('".ISDN_OAD_SETTING."')\" onmouseout='UnTip()' id='isdn_oad_setting_tr'>
						<td><b>".DIALPLAN_ISDN_OAD_SETTING_DIS."</b></td>
						<td>".caller_id_mapping_pstn('isdn_oad_setting')."</td>
						<td><input type='checkbox' value='1' name='def_isdn_oad_setting' id='def_isdn_oad_setting' checked onclick='if (def_isdn_oad_setting.checked) isdn_oad_setting.disabled=true; else isdn_oad_setting.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".ISDN_OAD2_SETTING."')\" onmouseout='UnTip()' id='isdn_oad2_setting_tr'>
						<td><b>".DIALPLAN_ISDN_OAD2_SETTING_DIS."</b></td>
						<td>".caller_id_mapping_pstn('isdn_oad2_setting')."</td>
						<td><input type='checkbox' value='1' name='def_isdn_oad2_setting' id='def_isdn_oad2_setting' checked onclick='if (def_isdn_oad2_setting.checked) isdn_oad2_setting.disabled=true; else isdn_oad2_setting.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".ISDN_QSIGNAME_SETTING."')\" onmouseout='UnTip()' id='isdn_qsigname_setting_tr'>
						<td><b>".DIALPLAN_ISDN_QSIGNAME_SETTING_DIS."</b></td>
						<td>".caller_id_mapping_pstn('isdn_qsigname_setting')."</td>
						<td><input type='checkbox' value='1' name='def_isdn_qsigname_setting' id='def_isdn_qsigname_setting' checked onclick='if (def_isdn_qsigname_setting.checked) isdn_qsigname_setting.disabled=true; else isdn_qsigname_setting.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".ISDN_REDIRECTED_NR_SETTING."')\" onmouseout='UnTip()' id='isdn_redirected_nr_setting_tr'>
						<td><b>".DIALPLAN_ISDN_REDIRECTED_NR_SETTING_DIS."</b></td>
						<td>".caller_id_mapping_pstn('isdn_redirected_nr_setting')."</td>
						<td><input type='checkbox' value='1' name='def_isdn_redirected_nr_setting' id='def_isdn_redirected_nr_setting' checked onclick='if (def_isdn_redirected_nr_setting.checked) isdn_redirected_nr_setting.disabled=true; else isdn_redirected_nr_setting.disabled=false;'/></td>
					</tr>
					<tr>
						<td colspan='3'>&nbsp;</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		<table border='1' cellspacing='0' id='config_sip' width='400' style='border-collapse:collapse;'>
			<tr>
				<td><table border='0'>
					<tr><td colspan='3' align='center'><b>".DIALPLAN_CONFIGURATION_DIS."</b></td></tr>
					<tr><td colspan='2' ></td><td><b>".DIALPLAN_DEFAULT_DIS."</b></td></tr>
					<tr onmouseover=\"Tip('".T38."')\" onmouseout='UnTip()' id='t38_tr'>
						<td><b>".DIALPLAN_T38_SUPPORT_DIS."</b></td>
		    			<td>".t38()."</td>
   		    			<td><input type='checkbox' value='1' name='def_t38' id='def_t38' checked onclick='if (def_t38.checked) t38.disabled=true; else t38.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".DTMFMODE."')\" onmouseout='UnTip()' id='dtmf_tr'>
						<td><b>".DIALPLAN_DTMF_MODE_DIS."</b></td>
		    			<td>".dtmfmode()."</td>
		    			<td><input type='checkbox' name='def_dtmfmode' id='def_dtmfmode' checked onclick='if (def_dtmfmode.checked) dtmfmode.disabled=true; else dtmfmode.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".IE_ON_SIP."')\" onmouseout='UnTip()' id='ie_on_sip_tr'>
						<td><b>".DIALPLAN_IE_ON_SIP_DIS."</b></td>
		    			<td>".ie_on_sip()."</td>
      					<td><input type='checkbox' value='1' name='def_ie_on_sip' id='def_ie_on_sip' checked onclick='if (def_ie_on_sip.checked) ie_on_sip.disabled=true; else ie_on_sip.disabled=false;'/></td>
					</tr>
					<tr id='codecs_tr'>
						<td><b>".DIALPLAN_CODECS_DIS."</b></td>
		    			<td>".codecs()."</td>
   		    			<td><input type='checkbox' value='1' name='def_codecs' id='def_codecs' onmouseover=\"Tip('".CODECS_DEF."')\" onmouseout='UnTip()' checked
				   		    onclick='if (def_codecs.checked){
   		    					document.getElementById(\"sel\").disabled=true;
   		    					document.getElementById(\"sel1\").disabled=true;
   		    					document.getElementById(\"upB\").disabled=true;
   		    					document.getElementById(\"downB\").disabled=true;
   		    					document.getElementById(\"addB\").disabled=true;
   		    					document.getElementById(\"removeB\").disabled=true;
   		    				}else{
   		    					document.getElementById(\"sel\").disabled=false;
   		    					document.getElementById(\"sel1\").disabled=false;
   		    					document.getElementById(\"upB\").disabled=false;
   		    					document.getElementById(\"downB\").disabled=false;
   		    					document.getElementById(\"addB\").disabled=false;
   		    					document.getElementById(\"removeB\").disabled=false;
   		    				}'/></td>
						</tr>
					</tr>
					<tr onmouseover=\"Tip('".WAIT_FOR_CANCEL."')\" onmouseout='UnTip()' id='wait_for_cancel_tr'>
						<td><b>".DIALPLAN_WAIT_FOR_CANCEL_DIS."</b></td>
		    			<td>".wait_for_cancel()."</td>
   		    			<td><input type='checkbox' value='1' name='def_wait_for_cancel' id='def_wait_for_cancel' checked onclick='if (def_wait_for_cancel.checked) wait_for_cancel.disabled=true; else wait_for_cancel.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".CALL_PROGRESS_TABLE."')\" onmouseout='UnTip()' id='s2i_cpt_tr'>
						<td><b>".DIALPLAN_CALL_PROGRESS_TABLE_S2I_DIS."</b></td>
		    			<td>".s2i_cpt()."</td>
		    			<td><input type='checkbox' value='1' name='def_s2i_cpt' id='def_s2i_cpt' checked onclick='if (def_s2i_cpt.checked) s2i_cpt.disabled=true; else s2i_cpt.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".CALL_PROGRESS_TABLE."')\" onmouseout='UnTip()' id='i2s_cpt_tr'>
						<td><b>".DIALPLAN_CALL_PROGRESS_TABLE_I2S_DIS."</b></td>
		    			<td>".i2s_cpt()."</td>
		    			<td><input type='checkbox' value='1' name='def_i2s_cpt' id='def_i2s_cpt' checked onclick='if (def_i2s_cpt.checked) i2s_cpt.disabled=true; else i2s_cpt.disabled=false;'/></td>
					</tr>
					<tr onmouseover=\"Tip('".FROM_SIP_SRC_SETTING."')\" onmouseout='UnTip()' id='from_sip_src_setting_tr'>
						<td><b>".DIALPLAN_FROM_SIP_SRC_SETTING_DIS."</b></td>
						<td>".from_sip_src_setting()."</td>
						<td><input type='checkbox' value='1' name='def_from_sip_src_setting' id='def_from_sip_src_setting' checked onclick='if (def_from_sip_src_setting.checked) from_sip_src_setting.disabled=true; else from_sip_src_setting.disabled=false;'/></td>
					</tr>
					<tr>
						<td colspan='3'>&nbsp;</td>
					</tr>
					<tr id='caller_id_mapping_tr'>
						<th colspan='3'>".DIALPLAN_CALLER_ID_MAPPING_DIS."</th>
					</tr>
					<tr onmouseover=\"Tip('".SIP_FROM_USER_SETTING."')\" onmouseout='UnTip()' id='sip_from_user_setting_tr'>
						<td><b>".DIALPLAN_SIP_FROM_USER_SETTING_DIS."</b></td>
						<td>".caller_id_mapping_sip('sip_from_user_setting')."</td>
						<td><input type='checkbox' value='1' name='def_sip_from_user_setting' id='def_sip_from_user_setting' checked onclick='if (def_sip_from_user_setting.checked) sip_from_user_setting.disabled=true; else sip_from_user_setting.disabled=false;'/></td>
					</tr>
					</tr>
					<tr onmouseover=\"Tip('".SIP_FROM_DISPLAY_SETTING."')\" onmouseout='UnTip()' id='sip_from_display_setting_tr'>
						<td><b>".DIALPLAN_SIP_FROM_DISPLAY_SETTING_DIS."</b></td>
						<td>".caller_id_mapping_sip('sip_from_display_setting')."</td>
						<td><input type='checkbox' value='1' name='def_sip_from_display_setting' id='def_sip_from_display_setting' checked onclick='if (def_sip_from_display_setting.checked) sip_from_display_setting.disabled=true; else sip_from_display_setting.disabled=false;'/></td>
					</tr>
					</tr>
					<tr>
						<td colspan='3'>&nbsp;</td>
					</tr>";
			echo "</table></td></tr></table><br/>
			<input name='page' type='hidden' value='" . $page . "'>
			<input name='dir' type='hidden' value='" . $dir . "'>
			<input name='search' type='hidden' value='" . $search . "'>
			<input name='id_upd' type='hidden' value='" . $_GET['id'] . "'>
			<input name='from' type='hidden' value='" . $e[0]['fromDirection'] . "'>
			<input name='to' type='hidden' value='" . $e[0]['toDirection'] . "'>";
		if ($_GET['isdnid']!=""){
			echo "<input name='isdnid' type='hidden' value='" . $_GET['isdnid'] . "'>";
		}

		echo "<div id='buttons'><input name='submit' type='submit' value='".BUTTON_SAVE."' onclick='selectall();' 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()'>
		</div>
		</form>";

	showdefmc($e);

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>

