<?php
chdir("..");
chdir("..");

include "./includes/variables.php";
include './misc/database.php';
	if (show==yes){
		$isdn_table = dynamic_table();
		$m = $_GET['m'];
		// build page content
		echo  "<form class='beroari_form' name='isdn' action='' onsubmit='javascript:new_window(\"./misc/isdn_popup.php?ip=".$_GET['ip']."\");' method='GET'>
			<input type=hidden name=m value=" . $m . ">
			<input type=hidden name=f value='action'>
			<input type=hidden name=q value=" . $q . ">
			<input type=hidden name=start value=" . $start . ">
			<input type=hidden name=span value=" . $span . ">
			<input type=hidden name=order value=" . $order . ">
			<input type=hidden name=sort value=" . $sort . ">
			<input type=hidden name=a value='add'>
			<br>
			" . $isdn_table . "
			<br>
			<input name='submit' type='submit' value='Add' onmouseover=\"Tip('" . MOD_ISDN_ADD . "')\" onmouseout='UnTip()'>
			</form>";
		}else{
			echo "<h2>Access Denied</h2>";
		}
function dynamic_table() {
		//ein neues Datenbankobjekt wird erzeugt.
		$ba = new beroAri();


		//Das Header der Tabelle sind die Spaltennamen von dialplan
		$cols .= "<th class='contenttoc'>Group</th>";
		$cols .= "<th class='contenttoc'>Ports</th>";

		/*Die Einträge werden von der Tabelle isdn gelesen, formatiert und in einer
		  Tabelle geschrieben, zusätzlich werden 2 Knöpfe eingebaut: modify und delete*/
		$query = $ba->select('SELECT DISTINCT gr FROM isdn WHERE gr!="NULL"');
		$rows = '';
		while ($entry = $ba->fetch_array($query)) {
			$query_port = $ba->select('SELECT port FROM isdn WHERE gr="'.$entry['gr'].'" ORDER BY port asc');
			$ports="";
			while ($entryp = $ba->fetch_array($query_port)) {
				if($ports!=""){
					$ports.=",".$entryp['port'];
				}else{
					$ports.=$entryp['port'];
				}
			}
			$rows.="<tr><td>".$entry['gr']."</td><td>".$ports."</td>";
			$rows .= "<td class='buttons' bgcolor='#DACECE'><font size='3'><a class='popup_download' onclick=\"javascript:new_window('./misc/isdn_popup.php?gr=".$entry['gr']."&ip=".$_GET['ip']."');\">
				<input type='button' value='modify' onmouseover=\"Tip('" . MOD_ISDN_MODIFY . "')\" onmouseout='UnTip()'></a>&nbsp<a class='popup_download' href=\"./misc/delete.php?gr=" .
				$entry['gr'] . "&table=isdn&ip=".$_GET['ip']."\" onclick=\"if(confirm('Do you want to delete " . $entry['gr'] . "?') == false){return false;}\"><input type='button' value='delete' onmouseover=\"Tip('" . MOD_ISDN_DELETE . "')\" onmouseout='UnTip()'></a></font></td></tr>";
		}

		

		$table = "<table class='contenttoc' id='table'><tr>" . $cols . "<th></th></tr>" . $rows . "</table>";
		//Rückgabe: Erzeugte Tabelle mit den Einträgen der Tabelle isdn der Datenbank
		return $table;
	}
?>
