<?php


/**
 * Klasse Pstn_hw (PSTN Hardware)
 * Zeigt die Hardware configuration von ISDN (Die Kartennamen)
 * um die Einstellungen zu ändern
 */

class Pstn_hw {

	/*
	 * Funktion display erzeugt den Inhalt von der HTML-Seite
	 */

	public function display($args) {


		$m = $_GET['m'];
		$q = $_GET['q'];
		$start = $_GET['start'];
		include('./includes/header.php');

		//Änderungen speichern
		if ($_POST['id_upd']){
			$database = new beroAri();

			if (isset($_POST['pcm_server']))
				$database->set('pcm_server','1');
			else
				$database->set('pcm_server','0');
			if ($_POST['master_li0']=="0" && $_POST['master_li1']=="0")
				$database->set('pcm_server',$_POST['pcm_ip']);
			elseif ($_POST['master_li0']=="0" && !isset($_POST['master_li1']))
				$database->set('pcm_server',$_POST['pcm_ip']);
			elseif ($_POST['master_li1']=="0" && !isset($_POST['master_li0']))
				$database->set('pcm_server',$_POST['pcm_ip']);

			$database->set('pcm_server_port',$_POST['pcm_server_port']);

			if (isset($_POST['country'])){
				$database->set('country',$_POST['country']);
			}else{
				$database->set('country','');
			}

			if (isset($_POST['boostringer'])){
				$database->set('boostringer',$_POST['boostringer']);
			}else{
				$database->set('boostringer','0');
			}

			$query_new = $database->update("UPDATE isdn SET clock=0");
			if (isset($_POST['sync_li0'])) $database->update("UPDATE isdn SET clock=1 WHERE port='".$_POST['sync_li0']."'");
			if (isset($_POST['sync_li1'])) $database->update("UPDATE isdn SET clock=1 WHERE port='".$_POST['sync_li1']."'");

			$revision=exec('sed -ne "s/.*revision=\(.*\)/\1/p" /proc/cmdline');
			if (isset($_POST['portswitch']) && $revision!="1.80" && $revision!="1.8"){
				$q=$database->select("SELECT value from key_val WHERE key='portswitch'");
				if (sqlite_fetch_single($q)!=""){
					$database->update("UPDATE key_val set value=1 WHERE key='portswitch'");
				}else{
					$database->insert_("INSERT into key_val (key,value) VALUES('portswitch',1)");
				}
			}elseif (!isset($_POST['portswitch']) && $revision!="1.80" && $revision!="1.8"){
				$q=$database->select("SELECT value from key_val WHERE key='portswitch'");
				if (sqlite_fetch_single($q)!=""){
					$database->update("UPDATE key_val set value=0 WHERE key='portswitch'");
				}else{
					$database->insert_("INSERT into key_val (key,value) VALUES('portswitch',0)");
				}
			}

			$id=$_POST['id_upd'];
			$type_array=$_POST['type'];
			for ($i=0;$i<count($id);$i++){
				$id_upd=$id[$i];
				$type=$type_array[$i];
				//ISDN spezifieche Einstellungen speichern
				if ($type=="isdn"){
					$mode="mode".$id_upd;
					$mode_id=$_POST[$mode];
					$ptp="ptp".$id_upd;
					$ptp_id=$_POST[$ptp];
					$lt="lt".$id_upd;
					$lt_id=$_POST[$lt];
					$crc="crc".$id_upd;
					$crc_id=$_POST[$crc];
					if ($ptp_id==""){
						$ptp_id="1";
					}
					if ($lt_id==""){
						$lt_id="0";
					}
					if ($crc_id==""){
						$crc_id="0";
					}
					$query_upd = $database->update("UPDATE isdn SET ntteHW='".$mode_id."', ntteSW='".$mode_id."', ptp='".$ptp_id."', lt='".$lt_id."', crc='".$crc_id."' WHERE port='".$id_upd."'");
				}
			}

			//Master-Slave option speichern
			//ISDN
			if ($_POST['master_li0']=="1" || !isset($_POST['master_li0'])) $database->update("UPDATE isdn SET master='1' where lif='0' ");
			else $database->update("UPDATE isdn SET master='0' where lif='0' ");
			if ($_POST['master_li1']=="1" || !isset($_POST['master_li1'])) $database->update("UPDATE isdn SET master='1' where lif='1' ");
			else $database->update("UPDATE isdn SET master='0' where lif='1' ");
			//ANALOG
			if ($_POST['master_li0']=="1" || !isset($_POST['master_li0'])) $database->update("UPDATE analog SET master='1' where lif='0' ");
			else $database->update("UPDATE analog SET master='0' where lif='0' ");
			if ($_POST['master_li1']=="1" || !isset($_POST['master_li1'])) $database->update("UPDATE analog SET master='1' where lif='1' ");
			else $database->update("UPDATE analog SET master='0' where lif='1' ");
			//GSM
			if ($_POST['master_li0']=="1" || !isset($_POST['master_li0'])) $database->update("UPDATE gsm SET master='1' where lif='0' ");
			else $database->update("UPDATE gsm SET master='0' where lif='0' ");
			if ($_POST['master_li1']=="1" || !isset($_POST['master_li1'])) $database->update("UPDATE gsm SET master='1' where lif='1' ");
			else $database->update("UPDATE gsm SET master='0' where lif='1' ");

			$query=$database->select("select option from activate where id='activate'");
			while($entry = $database->fetch_array($query)){
				if ($entry['option'] <= 3) $query =  $database->update("UPDATE activate SET option=3 where id='activate'");
			}
			$ret.= "<script>aktivieren(1,'pstn_hw','3','".ACTIVATE."');</script>";
		}



		$pstn_hw_table = $this->dynamic_table();
		// build page content
		$ret.="<script>
		function pcm_ip_check(){
			try{
				if (document.getElementsByName('master_li0')[0].selectedIndex==1 && document.getElementsByName('master_li1')[0].selectedIndex==1 && document.getElementsByName('pcm_ip')[0].value==''){
					alert('".HARDWARE_PCM_MASTER_IP_WARNING_DIS."');
					return false;
				}else if(document.getElementsByName('master_li0')[0].selectedIndex==1 && document.getElementsByName('master_li1')[0].selectedIndex==1 && document.getElementsByName('pcm_ip')[0].value.length>=255){
					alert('".HARDWARE_PCM_MASTER_IP_WARNING1_DIS."');
					return false;
				}else{
					return true;
				}
			}catch(e){
				return true;
			}
		}</script>";
		$ret .= "
					<form class='isdnhw_form' name='isdn_hw' id='pstn_hw' action='' method='POST' onsubmit='return pcm_ip_check();'>
					<input type='hidden' name='m' value='" . $m . "'>
					<br>
					" . $pstn_hw_table . "
					<br>
					</form>";

		//Rückgabe: Inhalt der HTML-Seite
		return $ret;
	}

	public function mode ($ba,$act_mode,$id){
                if ($act_mode=='te'){
						$mode.="<option value='nt'>nt<br>";
                        $mode.="<option value='te' selected>te</option><br>";
                }else{
						$mode.="<option value='nt' selected>nt<br>";
                        $mode.="<option value='te'>te</option><br>";
                }
        return $mode;
	}

	/*
	 * Funktion dynamic_table
	 */
	public function dynamic_table() {
		//Ein neues Datenbankobjekt von der Datenbank.
		$database = new beroAri();
		require_once("./includes/lang.php");

		$country=array("FCC","TBR21","1TR110_DE","ARGENTINA","AUSTRALIA","AUSTRIA","BAHRAIN",
		"BELGIUM","BRAZIL","BULGARIA","CANADA","CHILE","CHINA","COLOMBIA","CROATIA",
		"CYPRUS","CZECH","DENMARK","ECUADOR","EGYPT","ELSALVADOR","FINLAND","FRANCE",
		"GERMANY","GREECE","GUAM","HONGKONG","HUNGARY","ICELAND","INDIA","INDONESIA",
		"IRELAND","ISRAEL","ITALY","JAPAN","JORDAN","KAZAKHSTAN","KUWAIT","LATVIA",
		"LEBANON","LUXEMBOURG","MACAO","MALAYSIA","MALTA","MEXICO","MOROCCO","NETHERLANDS",
		"NEWZEALAND","NIGERIA","NORWAY","OMAN","PAKISTAN","PERU","PHILIPPINES","POLAND",
		"PORTUGAL","ROMANIA","RUSSIA","SAUDIARABIA","SINGAPORE","SLOVAKIA","SLOVENIA",
		"SOUTHAFRICA","SOUTHKOREA","SPAIN","SWEDEN","SWITZERLAND","SYRIA","TAIWAN","THAILAND",
		"UAE","UK","USA","YEMEN");

		//Grafische Darstellung der Portsbelegung in Form eines Dialogs
		$form_elements.="<script>
			$(function() {
				\$( \"#accordion\" ).accordion({ collapsible: true, autoHeight: true, active: false });
			});
			</script>
			<div id='accordion' style='width:510px;'>
				<h3><a href='#'>".HARDWARE_GRAPHIC_DIS."</a></h3>
				<div><div >
					<div id='port1' style='z-index:3; position:absolute; width:95px; font-size:1.2em; margin-top:163px; margin-left:17px;'></div>
					<div id='port2' style='z-index:4; position:absolute; width:95px; font-size:1.2em; margin-top:163px; margin-left:123px;'></div>
					<div id='port3' style='z-index:5; position:absolute; width:95px; font-size:1.2em; margin-top:163px; margin-left:225px;'></div>
					<div id='port4' style='z-index:6; position:absolute; width:95px; font-size:1.2em; margin-top:163px; margin-left:327px;'></div>
					<div id='bild1' style='z-index:3; position:absolute; margin-top:93px; margin-left:17px;'></div>
					<div id='bild2' style='z-index:4; position:absolute; margin-top:93px; margin-left:122px;'></div>
					<div id='bild3' style='z-index:5; position:absolute; margin-top:93px; margin-left:223px;'></div>
					<div id='bild4' style='z-index:6; position:absolute; margin-top:93px; margin-left:324px;'></div>
					</div>
					<div style='height:205px'><img src='./includes/images/Zeichnung.png' title='Image Ports'></div>
				</div>
			</div>";

		$portswitch=$database->get("portswitch");
		$query = $database->select('SELECT type  FROM gsm WHERE lif="1"');
		$lif1=sqlite_fetch_single($query);

		if ($portswitch==1  || $lif1=="bf2GSM"){
			$q=$database->select("SELECT port, port_type FROM isdn WHERE lif='0' union SELECT port, port_type FROM analog WHERE lif='0'  union SELECT port, port_type FROM gsm WHERE lif='0' order by port_type, port");
			$i=1;
			while ($ent=$database->fetch_array($q)){
					$form_elements.="<script>
					$(document).ready(function() {
						document.getElementById('bild".$i."').innerHTML='<img src=\"./includes/images/Zeichnung-2.png\" title=\"Image Ports\">';
						document.getElementById('port".$i."').innerHTML='<center>".$ent['port_type']. $ent['port']."</center>';
					});
					</script>";
					$i++;
			}

			//Besonderer Fall, wenn das LI1 GSM ist, wird Portswitch per default aktiviert, die GSM Portsvon LI1 müssen aber extra angezeigt werden.
			if ($lif1=="bf2GSM"){
				$q=$database->select("SELECT port, port_type FROM gsm WHERE lif='1' order by port_type, port");
				$i=3;
				while ($ent=$database->fetch_array($q)){
						$form_elements.="<script>
						$(document).ready(function() {
							if ($('#port".$i."').attr('innerHTML')==''){
								document.getElementById('bild".$i."').innerHTML='<img src=\"./includes/images/Zeichnung-2.png\" title=\"Image Ports\">';
								document.getElementById('port".$i."').innerHTML='<center>".$ent['port_type']. $ent['port']."<center>';
							}else{
								document.getElementById('port".$i."').innerHTML+='<center>/".$ent['port_type']. $ent['port']."<center>';
							}
						});
						</script>";
						$i++;
				}
			}
			$form_elements.="<script>\$( \"#accordion\" ).accordion(\"resize\");</script>";
		}else{
			//Line Interface 0
			$q=$database->select("SELECT type, port, port_type FROM isdn WHERE lif='0' union SELECT type, port, port_type FROM analog WHERE lif='0' union SELECT type, port, port_type FROM gsm WHERE lif='0' order by port_type, port;");
			$i=1;
			$j=1;
			while ($ent0=$database->fetch_array($q)){
				if ($j>3){
					$form_elements.="<script>
					$(document).ready(function() {
						show_line0=false;
						document.getElementById('bild1').innerHTML='<img src=\"./includes/images/Zeichnung-1.png\" title=\"Image Ports\">';
						document.getElementById('bild2').innerHTML='<img src=\"./includes/images/Zeichnung-1.png\" title=\"Image Ports\">';
					});
					</script>";
				 }
				 if ($ent0['type']=="bf2S02FXS"){
					$form_elements.="<script>
					$(document).ready(function() {
						if (typeof(show_line0)=='undefined') document.getElementById('bild".$i."').innerHTML='<img src=\"./includes/images/Zeichnung-2.png\" title=\"Image Ports\">';
						if (document.getElementById('port".$i."').innerHTML!='')
							document.getElementById('port".$i."').innerHTML+='<div style=\'float:right;\'>".$ent0['port_type']. $ent0['port']."</div>';
						else
							document.getElementById('port".$i."').innerHTML+='<div style=\'float:left;\'>".$ent0['port_type']. $ent0['port']."</div>'});
					</script>";
					$i++;
					if ($i==3) $i=1;
					$j++;
				}else{

					$form_elements.="<script>
					$(document).ready(function() {
						if (typeof(show_line0)=='undefined') document.getElementById('bild".$i."').innerHTML='<img src=\"./includes/images/Zeichnung-2.png\" title=\"Image Ports\">';
						if (document.getElementById('port".$i."').innerHTML!='')
							document.getElementById('port".$i."').innerHTML+='<div style=\'float:right;\'>".$ent0['port_type']. $ent0['port']."</div>';
						else";
					if (sqlite_num_rows($q)<=2)
						$form_elements.=" document.getElementById('port".$i."').innerHTML+='<center>".$ent0['port_type']. $ent0['port']."</center>';";
					else
						$form_elements.=" document.getElementById('port".$i."').innerHTML+='<div style=\'float:left;\'>".$ent0['port_type']. $ent0['port']."</div>';";
					$form_elements.="});
					</script>";
					if (sqlite_num_rows($q)<=2)	$j++;
					if ($j%2==0) $i++;
					if (sqlite_num_rows($q)>=2)	$j++;

				}
			}
			//LINE INTERFACE 1
			$q=$database->select("SELECT type, port, port_type FROM isdn WHERE lif='1' union SELECT type, port, port_type FROM analog WHERE lif='1' union SELECT type, port, port_type FROM gsm WHERE lif='1' order by port_type, port;");
			$i=3;
			$j=1;
			while ($ent1=$database->fetch_array($q)){
				if ($j>3) {
					$form_elements.="<script>
					$(document).ready(function() {
						show_line1=false;
						document.getElementById('bild3').innerHTML='<img src=\"./includes/images/Zeichnung-1.png\" title=\"Image Ports\">';
						document.getElementById('bild4').innerHTML='<img src=\"./includes/images/Zeichnung-1.png\" title=\"Image Ports\">';
					});
					</script>";
				}
				if ($ent1['type']=="bf2S02FXS"){
					$form_elements.="<script>
						$(document).ready(function() {
							if (typeof(show_line1)=='undefined') document.getElementById('bild".$i."').innerHTML='<img src=\"./includes/images/Zeichnung-2.png\" title=\"Image Ports\">';
								if (document.getElementById('port".$i."').innerHTML!='')
									document.getElementById('port".$i."').innerHTML+='<div style=\'float:right;\'>".$ent1['port_type']. $ent1['port']."</div>';
								else
									document.getElementById('port".$i."').innerHTML+='<div style=\'float:left;\'>".$ent1['port_type']. $ent1['port']."</div>';
							});
						</script>";
					$i++;
					if ($i==5) $i=3;
					$j++;
				}else{
					$form_elements.="<script>
						$(document).ready(function() {
							if (typeof(show_line1)=='undefined') document.getElementById('bild".$i."').innerHTML='<img src=\"./includes/images/Zeichnung-2.png\" title=\"Image Ports\">';
								if (document.getElementById('port".$i."').innerHTML!='')
									document.getElementById('port".$i."').innerHTML+='<div style=\'float:right;\'>".$ent1['port_type']. $ent1['port']."</div>';
								else";
					if (sqlite_num_rows($q)<=2)
						$form_elements.=" document.getElementById('port".$i."').innerHTML+='<center>".$ent1['port_type']. $ent1['port']."</center>';";
					else
						$form_elements.=" document.getElementById('port".$i."').innerHTML+='<div style=\'float:left;\'>".$ent1['port_type']. $ent1['port']."</div>';";
						$form_elements.="});
						</script>";
					if (sqlite_num_rows($q)<=2)	$j++;
					if ($j%2==0) $i++;
					if (sqlite_num_rows($q)>=2)	$j++;
				}
			}
			$form_elements.="<script>\$( \"#accordion\" ).accordion(\"resize\");</script>";
		}


		//Zeigen des master-slave Drop-downs wenn die beiden Lineinterfaces belegt sind
		$q=$database->select("select type, lif, master from isdn group by type,lif, master union select type, lif, master from analog group by type,lif, master union select type, lif, master from gsm group by type,lif, master order by lif;");
		$i=0;
		while ($ent=$database->fetch_array($q)){
			$li[$i]=$ent['lif'];
			$type[$i]=$ent['type'];
			$i++;
		}
		if (isset($li[0]) && isset($li[1])){
			$show_master=1;
		}

		$q=$database->select("select type, lif, master from isdn group by type,lif, master union select type, lif, master from analog group by type,lif, master union select type, lif, master from gsm group by type,lif, master order by lif;");
		while ($ent=$database->fetch_array($q)){
			if ($ent['type']!="bf1E1" && $ent['type']!="bf2E1"){
				$form_elements.="<br/><br/><table class='contenttoc' width='90%'>
					<tr><th colspan='5'><center>".HARDWARE_CARD_TYPE_DIS.":&nbsp;".$ent['type'].
					"&nbsp;&nbsp;".HARDWARE_LINE_INTERFACE_DIS.":&nbsp;".$ent['lif']."&nbsp;&nbsp;";
			}else{
				$form_elements.="<br/><br/><table class='contenttoc' width='90%'>
					<tr><th colspan='5'><center>".HARDWARE_CARD_TYPE_DIS.":&nbsp;".$ent['type'].
					"&nbsp;&nbsp;".HARDWARE_LINE_INTERFACE_DIS.":&nbsp;".$ent['lif']."&nbsp;&nbsp;";

			}
			$form_elements.=HARDWARE_MASTER_DIS.":&nbsp;";
			$ent['type']=="bf2GSM" ? $dis="disabled" : $dis="";
			if ($ent['master']==1) $form_elements.="<select name='master_li".$ent['lif']."' onchange='check_master()' onmouseover=\"Tip('".HARDWARE_MASTER."')\" onmouseout='UnTip()' $dis>
												<option value='1' selected>".HARDWARE_OPTION_MASTER_DIS."</option>
												<option value='0'>".HARDWARE_OPTION_SLAVE_DIS."</option>
												</select>";
			elseif ($ent['master']==0) $form_elements.="<select name='master_li".$ent['lif']."' onchange='check_master()' onmouseover=\"Tip('".HARDWARE_MASTER."')\" onmouseout='UnTip()' $dis>
								<option value='1'>".HARDWARE_OPTION_MASTER_DIS."</option>
								<option value='0' selected>".HARDWARE_OPTION_SLAVE_DIS."</option>
								</select>";
			else $form_elements.="<select name='master_li".$ent['lif']."' onchange='check_master()' onmouseover=\"Tip('".HARDWARE_MASTER."')\" onmouseout='UnTip()' $dis>
								<option value='1' selected>".HARDWARE_OPTION_MASTER_DIS."</option>
								<option value='0'>".HARDWARE_OPTION_SLAVE_DIS."</option>
								</select>";


			if ($ent['type']!='bf4FXS' && $ent['type']!='bf4FXO' && $ent['type']!='bf2GSM'){
				$form_elements.="<span id='sync_port_li".$ent['lif']."'>&nbsp;&nbsp;".HARDWARE_SYNC_PORT_DIS.":&nbsp<select name='sync_li".$ent['lif']."' onmouseover=\"Tip('".ISDNHW_MASTER."')\" onmouseout='UnTip()'>";
				$query=$database->select("select port, clock from isdn where lif='".$ent['lif']."' and port_type!='FXS'");
				while ($entry=$database->fetch_array($query)){
					if ($entry['clock']==1)
					$form_elements.="<option value='".$entry['port']."' selected>".$entry['port']."</option>";
					else
					$form_elements.="<option value='".$entry['port']."'>".$entry['port']."</option>";
				}
				$form_elements.="</select></span>";
			}
			$form_elements.="</center></th></tr>";
			//ISDN
			$query=$database->select("select * from isdn where lif='".$ent['lif']."'");
			while ($entry=$database->fetch_array($query)){
				if ($entry['type']!="bf1E1" && $entry['type']!="bf2E1"){
						$form_elements.="<tr>
						<td><b>".HARDWARE_PORT_DIS.":</b>&nbsp;".$entry['port']."&nbsp;</td>
						<td><b>".HARDWARE_PORT_TYPE_DIS.":</b>&nbsp;".$entry['port_type']."</td>
						<td><b>".HARDWARE_TYPE_DIS.":</b>&nbsp;<select name='mode".$entry['port']."' onmouseover=\"Tip('".ISDNHW_MODE."')\"
							onmouseout='UnTip()'>".$this->mode($database,$entry['ntteHW'],$entry['port'])."</select></td>";
						if ($entry['ptp']==1){
							$form_elements.="<td><b>".HARDWARE_PROTOCOL_DIS.":</b>&nbsp;<select name='ptp".$entry['port']."' onmouseover=\"Tip('".ISDNHW_PTP."')\" onmouseout='UnTip()'>
								<option value=1 selected>PTP</option>
								<option value=0>PMP</option>
								</select>
								<input type=hidden name=id_upd[] value=".$entry['port'].">
								<input type=hidden name=type[] value='isdn'></td>";
						}else{
							$form_elements.="<td><b>".HARDWARE_PROTOCOL_DIS.":</b>&nbsp;<select name='ptp".$entry['port']."' onmouseover=\"Tip('".ISDNHW_PTP."')\" onmouseout='UnTip()'>
								<option value=1>PTP</option>
								<option value=0 selected>PMP</option>
								</select>
								<input type=hidden name=id_upd[] value=".$entry['port'].">
								<input type=hidden name=type[] value='isdn'></td>";
						}
						if ($entry['lt']==1){
							$form_elements.="<td><b>".HARDWARE_TERMINATION_DIS.":</b>&nbsp;<input type='checkbox' name='lt".$entry['port']."' checked value='1' onmouseover=\"Tip('".ISDNHW_LT."')\" onmouseout='UnTip()'></td>";
						}else{
							$form_elements.="<td><b>".HARDWARE_TERMINATION_DIS.":</b>&nbsp;<input type='checkbox' name='lt".$entry['port']."' value='1' onmouseover=\"Tip('".ISDNHW_LT."')\" onmouseout='UnTip()'></td>";
						}
				}else{
					$form_elements.="<tr>
						<td><b>".HARDWARE_PORT_DIS.":</b>&nbsp;".$entry['port']."&nbsp;</td>
						<td><b>".HARDWARE_PORT_TYPE_DIS.":</b>&nbsp;".$entry['port_type']."</td>
						<td><b>".HARDWARE_TYPE_DIS.":</b>&nbsp;<select name='mode".$entry['port']."' onmouseover=\"Tip('".ISDNHW_MODE."')\"
						onmouseout='UnTip()'>".$this->mode($database,$entry['ntteHW'],$entry['port'])."</select></td>";
					$form_elements.="<td><b>".HARDWARE_PROTOCOL_DIS.":</b>&nbsp;<select name='ptp".$entry['port']."' onmouseover=\"Tip('".ISDNHW_PTPE1."')\" onmouseout='UnTip()'>
						<option value=1 selected>PTP</option>
						</select>
						<input type=hidden name=id_upd[] value=".$entry['port'].">
						<input type=hidden name=type[] value='isdn'></td>";
						if ($entry['crc']==1){
							$form_elements.="<td><b>".HARDWARE_CRC_DIS.":</b>&nbsp;<input type='checkbox' name='crc".$entry['port']."' checked value='1'></td>";
						}else{
							$form_elements.="<td><b>".HARDWARE_CRC_DIS.":</b>&nbsp;<input type='checkbox' name='crc".$entry['port']."' value='1'></td>";
						}
				}
			}

			//ANALOG
			$query=$database->select("select * from analog where lif='".$ent['lif']."'");
			while ($entry=$database->fetch_array($query)){
				$form_elements.="<tr>
				<td><b>".HARDWARE_PORT_DIS.":</b>&nbsp;".$entry['port']."&nbsp;</td>
				<td colspan='4'><b>".HARDWARE_PORT_TYPE_DIS.":</b>&nbsp;".$entry['port_type'].
				"<input type=hidden name=id_upd[] value=".$entry['port'].">
				<input type=hidden name=type[] value='analog'></td>";
			}
			//GSM
			$query=$database->select("select * from gsm where lif='".$ent['lif']."'");
			while ($entry=$database->fetch_array($query)){
				$form_elements.="<tr>
				<td><b>".HARDWARE_PORT_DIS.":</b>&nbsp;".$entry['port']."&nbsp;</td>
				<td colspan='4'><b>".HARDWARE_PORT_TYPE_DIS.":</b>&nbsp;".$entry['port_type'].
				"</td>";
			}
			$form_elements.="</table>";

		}

		$revision=exec('sed -ne "s/.*revision=\(.*\)/\1/p" /proc/cmdline');
		$q=$database->select("select type, lif from isdn group by type,lif union select type, lif from analog group by type,lif order by lif;");
		$i=0;
		while ($ent=$database->fetch_array($q)){
			$li[$i]=$ent['lif'];
			$type[$i]=$ent['type'];
			$i++;
		}

		//Country
		if ($type[0]=="bf4FXO" || $type[1]=="bf4FXO" || $type[0]=="bf4FXS" || $type[1]=="bf4FXS" || $type[0]=="bf2S02FXS" || $type[1]=="bf2S02FXS"){
				$form_elements.="<br/><br/>
							<table class='contenttoc' width='90%'><tr ><th>";
				if ($type[0]=="bf4FXO" || $type[1]=="bf4FXO"){
					$form_elements.="<b>".HARDWARE_COUNTRY_DIS.":</b><select name='country' onmouseover=\"Tip('".HARDWARE_COUNTRY."')\" onmouseout='UnTip()'>";
					foreach ($country as $value){
						if ($value==$database->get('country')) $form_elements.="<option value='".$value."' selected>".$value."</option>";
						else $form_elements.="<option value='".$value."'>".$value."</option>";
					}
					$form_elements.="</select>&nbsp;&nbsp;";
				}
				if ($type[0]=="bf4FXS" || $type[1]=="bf4FXS" || $type[0]=="bf2S02FXS" || $type[1]=="bf2S02FXS"){
					$form_elements.="<b>".HARDWARE_BOOSTRINGER_DIS.":</b><select name='boostringer'>";

					($database->get('boostringer')==0) ? $form_elements.="<option value='0' selected>49V</option>" : $form_elements.="<option value='0'>49V</option>";
					($database->get('boostringer')==1) ? $form_elements.="<option value='1' selected>89V</option>" : $form_elements.="<option value='1'>89V</option>";
					$form_elements.="</select>";
				}
				$form_elements.="</th>
								</tr></table>";
		}

		//Portswitch
		if (($type[0]=="bf4S0" || $type[0]=="bf4FXO" || $type[0]=="bf4FXS" || $type[0]=="bf2S02FXS") && !isset($type[1]) && $revision!="1.80" && $revision!="1.8"){
			$form_elements.="<br/><br/>
							<table class='contenttoc' width='90%'>
							<tr onmouseover=\"Tip('".HARDWARE_PORT_SWITCH."')\" onmouseout='UnTip()'>
								<th>".HARDWARE_CARD_TYPE_DIS.":&nbsp;none&nbsp;&nbsp;".HARDWARE_LINE_INTERFACE_DIS.":&nbsp;1&nbsp;&nbsp;".HARDWARE_PORTSWITCH_DIS.":&nbsp;";
			//$query=$database->select("select value from key_val where key='portswitch'");
			if ($database->get('portswitch')==""){
				$form_elements.="<input type='checkbox' name='portswitch' value='1' checked>";
			}elseif ($database->get('portswitch')=="1"){
				$form_elements.="<input type='checkbox' name='portswitch' value='1' checked>";
			}elseif ($database->get('portswitch')=="0"){
				$form_elements.="<input type='checkbox' name='portswitch' value='1'>";
			}
			$form_elements.="</th>
							</tr>
							</table>";
		}

		//PCM
		$pcm_ip="";
		if ($database->get('pcm_server')!=0 && $database->get('pcm_server')!=1) $pcm_ip=$database->get('pcm_server');
		$pcm_server_port='54329';
		if ($database->get('pcm_server_port')!="") $pcm_server_port=$database->get('pcm_server_port');
		$form_elements.="<br><table id='pcm_client' width='90%' class='contenttoc' style='display:none;'>
		                     <tr>
		                         <th nowrap>
		                         	".HARDWARE_PCM_MASTER_IP_DIS.":&nbsp;
		                         	<input type='text' name='pcm_ip' value='".$pcm_ip."'>
		                         </th>
		                         <th nowrap>
		                         	".HARDWARE_PCM_MASTER_PORT_DIS.":&nbsp;

		                         	<input type='text' name='pcm_server_port' value='".$pcm_server_port."'>
		                         </th>
		                     </tr>
		                 </table>";

		$form_elements.="<br><table id='pcm_server' width='90%' class='contenttoc' style='display:none;'>
		                     <tr>
		                         <th nowrap onmouseover=\"Tip('" . HARDWARE_PCM_BRIDGING . "')\" onmouseout='UnTip()'>
		                         	".HARDWARE_PCM_BRIDGING_DIS.":&nbsp;";
		if ($database->get('pcm_server')==1)
			$form_elements.="<input type='checkbox' name='pcm_server' value='1' checked>";
		else
			$form_elements.="<input type='checkbox' name='pcm_server' value='1'>";
			$form_elements.="</th>
		                         <th nowrap>
		                         	".HARDWARE_PCM_MASTER_PORT_DIS.":&nbsp;

		                         	<input type='text' name='pcm_server_port' value='".$pcm_server_port."'>
		                         </th>
		                     </tr>
		                 </table>";

		$form_elements.="<br>
		<center><input type='submit' value='".BUTTON_SAVE."' onmouseover=\"Tip('".ISDNHW_SAVE."')\"
		onmouseout='UnTip()'></center></form><script>
		function check_master(){
			try{
				if (document.getElementsByName('master_li0')[0].selectedIndex==1 && document.getElementsByName('master_li1')[0].selectedIndex==1){
					document.getElementById('pcm_client').style.display='';
				}else{
					document.getElementById('pcm_client').style.display='none';
				}
			}catch(e){

			}

			try{
				if ((document.getElementsByName('master_li0')[0].selectedIndex==1 && document.getElementsByName('master_li1')[0].selectedIndex==0) || (document.getElementsByName('master_li0')[0].selectedIndex==0 && document.getElementsByName('master_li1')[0].selectedIndex==1)){
					document.getElementById('pcm_server').style.display='';
					document.getElementsByName('pcm_server')[0].disabled=false;
				}else{
					document.getElementById('pcm_server').style.display='none';
					document.getElementsByName('pcm_server')[0].disabled=true;
				}
			}catch(e){

			}

			try{
				if (document.getElementsByName('master_li0')[0].selectedIndex==0){
					document.isdn_hw.sync_li0.disabled=false;
					document.getElementById('sync_port_li0').style.display='';
				}else{
					document.isdn_hw.sync_li0.disabled=true;
					document.getElementById('sync_port_li0').style.display='none';
				}
			}catch(e){

			}

			try{
				if (document.getElementsByName('master_li1')[0].selectedIndex==0){
					document.isdn_hw.sync_li1.disabled=false;
					document.getElementById('sync_port_li1').style.display='';
				}else{
					document.isdn_hw.sync_li1.disabled=true;
					document.getElementById('sync_port_li1').style.display='none';
				}
			}catch(e){

			}";
		if ($li[0]=="0" && $li[1]=="")
			$form_elements.= "try{
				if (document.getElementsByName('master_li0')[0].selectedIndex==1){
					document.getElementById('pcm_client').style.display='';
				}else{
					document.getElementById('pcm_client').style.display='none';
				}
			}catch(e){

			}
			try{
				if (document.getElementsByName('master_li0')[0].selectedIndex==0){
					document.getElementById('pcm_server').style.display='';
				}else{
					document.getElementById('pcm_server').style.display='none';
				}
			}catch(e){

			}";
			if ($li[0]=="1" && $li[1]=="")
			$form_elements.= "try{
				if (document.getElementsByName('master_li1')[0].selectedIndex==1){
					document.getElementById('pcm_client').style.display='';
				}else{
					document.getElementById('pcm_client').style.display='none';
				}
			}catch(e){

			}
			try{
				if (document.getElementsByName('master_li1')[0].selectedIndex==0){
					document.getElementById('pcm_server').style.display='';
				}else{
					document.getElementById('pcm_server').style.display='none';
				}
			}catch(e){

			}";
		//Die funktion check_master wird erst hier geschlossen
		$form_elements.="}
		check_master();
		</script>";

		return $form_elements;
	}

}
?>
