<?php

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

chdir("..");

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

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

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

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

function type($type,$direction){
	$ret="<select name='type' id='type'>";
	if ($type=="te") $ret.="<option value='te' selected>te</option>";
	else $ret.="<option value='te'>te</option>";
	if ($type=="nt") $ret.="<option value='nt' selected >nt</option>";
	else $ret.="<option value='nt'>nt</option>";
	if ($type=="ntte" && $direction!='ISDN-SIP') $ret.="<option value='ntte' selected>ntte</option>";
	else if($direction!='ISDN-SIP') $ret.="<option value='ntte'>ntte</option>";
	$ret.="</select>";
	return $ret;
}
function chann_det($chann_det,$direction){
	$ret="<select name='chann_det' id='chann_det'>";
	if ($chann_det=="no_channel") $ret.="<option value='without_channel' selected >no channel</option>";
	else $ret.="<option value='no_channel'>no channel</option>";
	if ($chann_det=="with_channel") $ret.="<option value='with_channel' selected>with channel</option>";
	else $ret.="<option value='with_channel'>with channel</option>";
	if ($chann_det=="without_inband") $ret.="<option value='without_inband' selected>without inband</option>";
	else $ret.="<option value='without_inband'>without inband</option>";
	if ($chann_det=="with_inband") $ret.="<option value='with_inband' selected>with inband</option>";
	else $ret.="<option value='with_inband'>with inband</option>";
	if ($chann_det=="any_state") $ret.="<option value='any_state' selected>any state</option>";
	else $ret.="<option value='any_state'>any_state</option>";
	$ret.="</select>";
	return $ret;
}
function resp($resp,$direction){
	if ($direction=='SIP-ISDN'){
		$resp=preg_split("/_/",$resp);
		$sdp=$resp[1];
		$resp=$resp[0];
		$ret="<select name='resp' id='resp'>";
		if ($resp=="180") $ret.="<option value='180' selected >180</option>";
		else $ret.="<option value='180'>180</option>";
		if ($resp=="183") $ret.="<option value='183' selected>183</option>";
		else $ret.="<option value='183'>183</option>";
		if ($resp=="200") $ret.="<option value='200' selected>200</option>";
		else $ret.="<option value='200'>200</option>";
		if ($resp=="none") $ret.="<option value='none' selected >none</option>";
		else $ret.="<option value='none'>none</option>";
		$ret.="</select>";
		if ($sdp) $ret.="&nbsp;SDP<input type='checkbox' name='sdp' value='1' checked>";
		else $ret.="&nbsp;SDP<input type='checkbox' name='sdp' value='1'>";
	}else if($direction=='ISDN-SIP'){
		$all_events = array ("PROCEEDING", "PROGRESS", "ALERTING", "CONNECT");
		$ret='<select name="resp" id="resp">';
		for ($i=0;$i<count($all_events);$i++){
			if ($resp==$all_events[$i]) $ret.='<option value="'.$all_events[$i].'" selected>'.$all_events[$i].'</option>';
			else $ret.='<option value="'.$all_events[$i].'">'.$all_events[$i].'</option>';
		}
		$ret .='</select>';
	}
	return $ret;
}

function events($events,$direction){
	if ($direction=='SIP-ISDN'){
		$all_events = Array ("PROCEEDING", "PROGRESS", "ALERTING", "CONNECT");
		$event=preg_split('/:/',$events);
		$ret='<p style="height: 100px; width:150px; overflow: auto; border: 1px solid #CCCCCC; background: none repeat scroll 0% 0% rgb(238, 238, 238); color: rgb(0, 0, 0);">';
		for ($i=0;$i<count($all_events);$i++){
			if (in_array($all_events[$i],$event)) $ret.='<label><input type="checkbox" name="events[]" value="'.$all_events[$i].'" checked>'.$all_events[$i].'</label><br>';
			else $ret.='<label><input type="checkbox" name="events[]" value="'.$all_events[$i].'">'.$all_events[$i].'</label><br>';
		}
		$ret .='</p>';
	}else if($direction=='ISDN-SIP'){
		$all_events = Array ("Dialplan Match", "183", "180", "200");
		$event=preg_split('/:/',$events);
		$ret='<p style="height: 100px; width:150px; overflow: auto; border: 1px solid #CCCCCC; background: none repeat scroll 0% 0% rgb(238, 238, 238); color: rgb(0, 0, 0);">';
		for ($i=0;$i<count($all_events);$i++){
			if (in_array($all_events[$i],$event) || in_array($all_events[$i]."_SDP",$event)) $ret.='<label><input type="checkbox" name="events[]" value="'.$all_events[$i].'" checked>'.$all_events[$i].'</label>';
			else $ret.='<label><input type="checkbox" name="events[]" value="'.$all_events[$i].'">'.$all_events[$i].'</label>';
			//SDP Zeigen wenn Event ungleich "Dialplan Match" ist
			if (in_array($all_events[$i]."_SDP",$event) && $all_events[$i]!="Dialplan Match") $ret.='<label><input type="checkbox" name="'.$all_events[$i].'_sdp" value="1" checked>&nbsp;SDP</label><br>';
			else if($all_events[$i]!="Dialplan Match") $ret.='<label><input type="checkbox" name="'.$all_events[$i].'_sdp" value="1">&nbsp;SDP</label><br>';
			else $ret.='<br>';
		}
		$ret .='</p>';
	}
	return $ret;

}

function get_data(){
	$ba=new beroAri();
	if (isset($_GET['id'])){
		$q=$ba->select("select * from callprogress_entries where id='".$_GET['id']."'");
		$e=sqlite_fetch_all($q);
		return $e;
	}
	return array();
}
$query_name=$ba->select('SELECT * FROM callprogress WHERE id="'.$_GET['id_name'].'"');
$tmp=$ba->fetch_array($query_name);
$name=$tmp['name'];
$direction=$tmp['direction'];

//echo "<script>window.opener.location='../index.php?m=isdn'</script>";
print "<br><table align=\"center\" bgcolor=\"#f0f0ec\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450\">
<colgroup>
<col width=\"39\"></col>
</colgroup>
<tbody><tr>
<td colspan=\"2\"><img src=\"../includes/images/bg_top.png\"></td>
</tr>
<tr>
<td background=\"../includes/images/bg_left.png\" style='background-repeat:repeat-y;' width=\"30\"><img src=\"../includes/images/trans.gif\" height=\"10\" width=\"39\"></td>
<td><p align='left'><img src=\"../includes/images/berofixlogo.png\"/><hr size= \"1\" noshade></p><p><center><font size='3'>".CALL_PROGRESS_TITLE_DIS."</font></p><br><br>";
$data=get_data();
/*
 * isdn_event = event
 * sip_resp = resp
 * Da die Möglichkeiten für Up und Downgrade offen gelassen werden sollten, wurden die Spaltennamen nicht geändert
 */
if ($direction=='SIP-ISDN'){
	echo ("<form class='extensions_form' name='isdn' action='callprogress_ent_submit.php' method='POST'>

			<table border='0' style='border-collapse:collapse' width='250'>
			<tr>
			<td><b>".CALL_PROGRESS_IFACE_TYPE_DIS.":</b>&nbsp;</td>
			<td>".type($data[0]['type'],$direction)."</td>
			</tr>
			<tr>
			<td><b>".CALL_PROGRESS_ISDN_EVENT_DIS.":</b>&nbsp;</td>
			<td>".events($data[0]['isdn_event'],$direction)."</td>
			</tr>
			<tr>
			<td><b>".CALL_PROGRESS_ISDN_CHANN_DET_DIS.":</b>&nbsp;</td>
			<td>".chann_det($data[0]['chann_det'],$direction)."</td>
			</tr>

			<tr>
			<td><b>".CALL_PROGRESS_SIP_RESP_DIS.":</b>&nbsp;</td>
			<td>".resp($data[0]['sip_resp'],$direction)."</td>
			</tr>
			<tr>
			<td><b>".CALL_PROGRESS_RESP_TEXT_DIS.":</b>&nbsp;</td>
			<td><input type='text' value='".$data[0]['resp_text']."' name='resp_text'></td>
			</tr>
			</table>
			<br/>");
		if (isset($_GET['id'])) echo" <input type='hidden' name='id_upd' value='". $_GET['id']."'>";
		echo" <input type='hidden' name='id_name' value='". $_GET['id_name']."'>";
		echo ("<input name='submit' type='submit' value='".BUTTON_SAVE."'>
			 &nbsp;&nbsp;<input name='close' type='button' value='".BUTTON_CLOSE."' onclick='javascript:closeW();' onmouseover=\"Tip('".POPUPS_BUTTON_CLOSE."');\" onmouseout='UnTip();'>
			</form>");
}else if ($direction=='ISDN-SIP'){
	//Bei Add default response text "*"
	if (!isset($data[0]['resp_text'])) $data[0]['resp_text']="*";

	echo ("<form class='extensions_form' name='isdn' action='callprogress_ent_submit.php' method='POST'>

			<table border='0' style='border-collapse:collapse' width='250'>
			<tr>
			<td><b>".CALL_PROGRESS_SIP_EVENT_DIS.":</b>&nbsp;</td>
			<td>".events($data[0]['isdn_event'],$direction)."</td>
			</tr>
			<tr>
			<td><b>".CALL_PROGRESS_RESP_TEXT_DIS.":</b>&nbsp;</td>
			<td><input type='text' value='".$data[0]['resp_text']."' name='resp_text'></td>
			</tr>
			<tr>
			<td><b>".CALL_PROGRESS_IFACE_TYPE_DIS.":</b>&nbsp;</td>
			<td>".type($data[0]['type'],$direction)."</td>
			</tr>
			<tr>
			<td><b>".CALL_PROGRESS_ISDN_EVENT_DIS.":</b>&nbsp;</td>
			<td>".resp($data[0]['sip_resp'],$direction)."</td>
			</tr>
			</table>
			<br/>");
		if (isset($_GET['id'])) echo" <input type='hidden' name='id_upd' value='". $_GET['id']."'>";
		echo" <input type='hidden' name='id_name' value='". $_GET['id_name']."'>";
		echo ("<input name='submit' type='submit' value='".BUTTON_SAVE."'>
			 &nbsp;&nbsp;<input name='close' type='button' value='".BUTTON_CLOSE."' onclick='javascript:closeW();' onmouseover=\"Tip('".POPUPS_BUTTON_CLOSE."');\" onmouseout='UnTip();'>
			</form>");
}



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

