<?php


/**
 * Klasse General
 * Zeigt algemeine Einstellungen von der isgw.conf Datei
 */

class Call_progress {

	/*
	 * Funktion display erzeugt den Inhalt von der HTML-Seite
	 */
	function display($args) {

		// args
		$m = $_GET['m'];
		$q = $_GET['q'];
		$start = $_GET['start'];
		$order = $_GET['order'];
		$sort = $_GET['sort'];
		include "./includes/functions.php";
		$functions = new functions();
		include('./includes/header.php');

		// build page content

		$callprogress_table = $this->dynamic_table();
		$ret .= "<script>
					function del(table,id){
						conf = confirm('".CALL_PROGRESS_DELETE_MESSAGE_DIS."');
						if (conf==false)
							return false;
						else
							window.location='./misc/delete.php?id='+id+'&table='+table;
					}
					function del_ent(table,id){
						conf = confirm('".CALL_PROGRESS_ENT_DELETE_MESSAGE_DIS."?');
						if (conf==false)
							return false;
						else
							window.location='./misc/delete.php?id='+id+'&table='+table;
					}
				 </script>
					<form class='extensions_form' name='isgw_causes' action='' method='POST' >
					<input type=hidden name=m value=" . $m . ">
					<input type=hidden name=a value='save'>
					<br>
					" . $callprogress_table.
					"<br><input name='submit' type='submit' value='".BUTTON_ADD_TABLE."' onclick='javascript:new_window(\"./misc/callprogress_popup.php\");'>
					</form>";


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





	/*
	 * Funktion dynamic_table
	 */

	function dynamic_table() {
		//Wenn man Änderugen von der Daten macht werden die in der Tabelle der Datenbank
		//aktualisiert
		$ba = new beroAri();

		require_once("./includes/lang.php");

		$columns = $ba->column_type('callprogress');
		$i = 0;
		foreach ($columns as $column => $type) {
			if (($column != 'id') && ($column != 'direction')) {
				$cols_name[$i] = $column;
				//if ($column == "direction")
					//$column = CALL_PROGRESS_DIRECTION_DIS;
				if ($column == "name")
					$column = CALL_PROGRESS_NAME_DIS;
				$cols .= "<th class='contenttoc'>" . $column . "</th>";
				$i++;
			}
		}

		/*Die Einträge werden von der Tabelle sip gelesen, formatiert und in einer
		  Tabelle geschrieben, zusätzlich werden 2 Knöpfe eingebaut: modify und delete*/
		$start = $_GET['start'];
		$page = (($start / 15) + 1);
		if (!$start)
			$start = 0;
		$id = 0;
		for ($j = 1; $j <= $page; $j++) {
			$query_t = $ba->select('SELECT * FROM callprogress ORDER BY id');
			$rows = '';
			$dir=array(	"SIP-ISDN_TEXT"=>array(CALL_PROGRESS_IFACE_TYPE_DIS,CALL_PROGRESS_ISDN_EVENT_DIS,CALL_PROGRESS_ISDN_CHANN_DET_DIS,CALL_PROGRESS_SIP_RESP_DIS,CALL_PROGRESS_RESP_TEXT_DIS),
						"SIP-ISDN_KEY"=>array("type","isdn_event","chann_det","sip_resp","resp_text"),
						"ISDN-SIP_TEXT"=>array(CALL_PROGRESS_SIP_EVENT_DIS,CALL_PROGRESS_RESP_TEXT_DIS,CALL_PROGRESS_IFACE_TYPE_DIS,CALL_PROGRESS_ISDN_EVENT_DIS),
						"ISDN-SIP_KEY"=>array("isdn_event","resp_text","type","sip_resp"),);
			while ($entry_t = $ba->fetch_array($query_t)) {
				$rows = "<tr>";
				if ($entry_t['direction']=="SIP-ISDN") $colspan=5;
				if ($entry_t['direction']=="ISDN-SIP") $colspan=4;
				$rows.="<th class='contenttoc' colspan='".$colspan."'><font color='#595959'>" . $entry_t['name'] ."   " . $entry_t['direction'] . "</font>";
				$id = $entry_t['id'];
				$rows .= "&nbsp;&nbsp;&nbsp;<input type='button' value='".BUTTON_MODIFY_TABLE."' onclick=\"javascript:new_window('./misc/callprogress_popup.php?id=" .
				$entry_t['id'] ."');\">&nbsp;
				<input type='button' value='".BUTTON_DELETE_TABLE."' onclick=\"del('callprogress','".$id."');\"></th>
				<th><input name='submit' type='submit' value='".BUTTON_ADD_ENTRY."' style='background-color: #fed;'  onclick='javascript:new_window(\"./misc/callprogress_ent_popup.php?id_name=".$id."\");'></th></tr>";
				$rows .= "<tr>";
				foreach ($dir[$entry_t['direction']."_TEXT"] as $value){
					$rows.="<th class='contenttoc'>".$value."</th>";
				}

				$rows .= "<th class='contenttoc'></th></tr>";
				$query = $ba->select('SELECT * FROM callprogress_entries WHERE id_name="'.$id.'" ORDER BY id asc');
				while ($entry = $ba->fetch_array($query)) {
					$rows .= "<tr>";
					foreach ($dir[$entry_t['direction']."_KEY"] as $value){
						$rows .= "<td>" . $entry[$value] . "</td>";
					}

					$id_ent = $entry['id'];
					$rows .= "<td class='buttons' bgcolor='#DACECE'>
					<a class='popup_download' onclick=\"javascript:new_window('./misc/callprogress_ent_popup.php?id=" .
					$entry['id'] ."&id_name=".$id."');\">
					<img src='./includes/images/modify.png' >
				</a>&nbsp;
				<a class='popup_download' onclick=\"del_ent('callprogress_entries','".$id_ent."');\">
            	    <img src='./includes/images/delete.png'>
				</a>

				</td></tr>";
				}
				$table .= "<table class='contenttoc' id='table'>" . $rows . "</table><br><br>";
			}
		}
		//$table .= "<table class='contenttoc' id='table'><tr>" . $cols . "<th></th></tr>" . $rows . "</table>";

		return $table;
	}

}
?>
