<?php

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

chdir("..");

include "./includes/variables.php";
include './misc/database.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>
//Schliesst das fenster
function closeW(){
	this.window.close();
}

function resize(){
	if(window.sizeToContent) window.sizeToContent();
}

function is_submit(form)
{
	if(form.is_submit ) return false;
	form.is_submit = true;
	return true;
}

</script>
<TITLE>ISDN HARDWARE</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="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=isdn_hw'</script>";
        echo "<script>this.window.close();</script>";
}else{
        $_SESSION['beroari_time']=time();
}

$ba= new beroAri();
echo "<script>window.opener.location='../index.php?m=isdn_hw'</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\"/></p><hr size= \"1\" noshade><p><center><font size='3'>ISDN HARDWARE</font></p><br><br>";



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;
}



$form_elements="<form class='isdnhw_form' id='isdn_hw' name='isdn_hw' action='' method='POST' onsubmit='return is_submit(this);'>
<b>Card Type:</b><input type=text value=".$_GET['c'].
" size=7 disabled>&nbsp;&nbsp;<b>Line Interface:</b>
<input type='text' value=".$_GET['lif']." size=1 disabled><br/><br/>
<table class='contenttoc' id='table'>";

$query=$ba->select("select * from isdn where lif='".$_GET['lif']."'");
while ($entry=$ba->fetch_array($query)){
	if ($entry['type']!="bf1E1" && $entry['type']!="bf2E1"){
		$form_elements.="<tr>
			<td><b>Port:</b>&nbsp;<input type='text' value=".$entry['port']." size=3 disabled></td>
			<td><b>Type:</b>&nbsp;<select name='mode".$entry['port']."' onmouseover=\"Tip('".ISDNHW_MODE."')\" 
			onmouseout='UnTip()'>".mode($ba,$entry['ntteHW'],$entry['port'])."</select></td>";
		if ($entry['ptp']==1){
			$form_elements.="<td><b>Protocol:</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']."></td>";
		}else{
			$form_elements.="<td><b>Protocol:</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']."></td>";
		}
		if ($entry['lt']==1){
			$form_elements.="<td><b>Termination:</b>&nbsp;<input type='checkbox' name='lt".$entry['port']."' checked value='1' onmouseover=\"Tip('".ISDNHW_LT."')\" onmouseout='UnTip()'></td>";
		}else{
			$form_elements.="<td><b>Termination:</b>&nbsp;<input type='checkbox' name='lt".$entry['port']."' value='1' onmouseover=\"Tip('".ISDNHW_LT."')\" onmouseout='UnTip()'></td>";
		}
		if ($entry['clock']==1){
        	       $form_elements.="<td><b>Clock Source:</b>&nbsp;<input type='radio' name='master' checked value='".$entry['port']."' onmouseover=\"Tip('".ISDNHW_MASTER."')\" onmouseout='UnTip()'></td></tr>";
	       }else{
        	       $form_elements.="<td><b>Clock Source:</b>&nbsp;<input type='radio' name='master' value='".$entry['port']."' onmouseover=\"Tip('".ISDNHW_MASTER."')\" onmouseout='UnTip()'></td></tr>";
		}
	$i++;
	}else{
		$form_elements.="<tr>
			<!--
			<td><b>Card Type:</b>&nbsp;<input type=text value=".$entry['type']." size=7 disabled></td>
			<td><b>Line Interface:</b>&nbsp;<input type='text' value=".$entry['lif']." size=1 disabled></td>
			-->
			<td><b>Port:</b>&nbsp;<input type='text' value=".$entry['port']." size=3 disabled></td>
			<td><b>Type:</b>&nbsp;<select name='mode".$entry['port']."' onmouseover=\"Tip('".ISDNHW_MODE."')\" 
			onmouseout='UnTip()'>".mode($ba,$entry['ntteHW'],$entry['port'])."</select></td>";
		$form_elements.="<td><b>Protocol:</b>&nbsp;<select name='ptp".$entry['port']."' onmouseover=\"Tip('".ISDNHW_PTPE1."')\" onmouseout='UnTip()'>
			<option value=1 selected>PTP</option>
			<!--<option value=0>PMP</option>-->
			</select>
			<input type=hidden name=id_upd[] value=".$entry['port']."></td>";
		/*
		if ($entry['lt']==1){
			$form_elements.="<td><b>lt:</b>&nbsp;<input type='checkbox' name='lt".$entry['port']."' value='1' checked onmouseover=\"Tip('".ISDNHW_LT."')\" onmouseout='UnTip()'></td>";
		}else{
			$form_elements.="<td><b>Lt:</b>&nbsp;<input type='checkbox' name='lt".$entry['port']."' value='1' onmouseover=\"Tip('".ISDNHW_PTP."')\" onmouseout='UnTip()'></td>";
		}
		*/
		if ($entry['clock']==1){
        	       $form_elements.="<td><b>Clock Source:</b>&nbsp;<input type='radio' name='master' checked value='".$entry['port']."' onmouseover=\"Tip('".ISDNHW_MASTER."')\" onmouseout='UnTip()'></td></tr>";
	       }else{
        	       $form_elements.="<td><b>Clock Source:</b>&nbsp;<input type='radio' name='master' value='".$entry['port']."' onmouseover=\"Tip('".ISDNHW_MASTER."')\" onmouseout='UnTip()'></td></tr>";
		}
$i++;
	}
}

$form_elements.="</table>
<br>
<center><input type='submit' value='Save' onmouseover=\"Tip('".ISDNHW_SAVE."')\" 
onmouseout='UnTip()'>&nbsp&nbsp<input name='close' type='button' value='Close' 
onclick='javascript:closeW();' onmouseover=\"Tip('".POPUPS_BUTTON_CLOSE."')\" onmouseout='UnTip()'></center>";


echo ($form_elements."</form>");


if ($_POST['id_upd']){
	$ba= new beroAri();
	$master=$_POST['master'];
		if ($master){
			$query_new = $ba->update("UPDATE isdn SET clock=1 WHERE port='$master'");
			$query= $ba->select("select * from isdn WHERE port!='$master'");
			while ($isdnhw=$ba->fetch_array($query)){
				$query_new = $ba->update("UPDATE isdn SET clock=0 WHERE port='".$isdnhw['port']."'");
			}
		}

	$id=$_POST['id_upd'];
	for ($i=0;$i<count($id);$i++){
                $id_upd=$id[$i];
                $mode="mode".$id_upd;
                $mode_id=$_POST[$mode];
                $ptp="ptp".$id_upd;
		$ptp_id=$_POST[$ptp];
                $lt="lt".$id_upd;
		$lt_id=$_POST[$lt];
		if ($ptp_id==""){
			$ptp_id="1";
		}
		if ($lt_id==""){
			$lt_id="0";
		}
		$query_upd = $ba->update("UPDATE isdn SET ntteHW='".$mode_id."', ntteSW='".$mode_id."', ptp='".$ptp_id."', lt='".$lt_id."' WHERE port='".$id_upd."'");
        }
	$query=$ba->select("select option from activate where id='activate'");
	while($entry = $ba->fetch_array($query)){
		if ($entry['option'] <= 3) $query =  $ba->update("UPDATE activate SET option=3 where id='activate'");

	}
	if (!$ba->is_error()){
		echo "<script>window.opener.location='../index.php?m=isdn_hw'</script>";
		echo "<script>this.window.close();</script>";
	}else{
		echo "<script>alert(".$ba->error().");</script>";
	}

}

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>

