<?php
/*
 *      Class Cdr
 */
class Cdr {
	
	/*
	 * Funktion display erzeugt den Inhalt von der HTML-Seite
	 */
	function display($args) {
		// args
		$m = $_GET['m'];
		
		include('./includes/header.php');
		$cdr_content = $this->dynamic_table();
		// build page content
		$ret .= "
					<form class='extensions_form' name='cdr' action='' method='POST' 
					onsubmit='return (verify_number(port.value, \"Logging Server Port\"));'>
					<input type=hidden name=m value=" . $m . ">
					<input type=hidden name=a value='save'>
					<br>
					" . $cdr_content;

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



	/*
	 * Der boolesche Wert von Logcdr, der in der Datenbank gespeichert ist wird zurückgegeben 
	 * in der Form eines Checkboxs und nachher angezeigt.
	 */
	function logcdr() {
		$ba = new beroAri();
		$option=$ba->get("logcdr");
		if ($option == "1") {
			return "<input type='checkbox' name='logcdr' value='1' checked>";
		} else {
			return "<input type='checkbox' name='logcdr' value='1'>";
		}
		
	}

	
	/*
	 * Funktion dynamic_table
	 */

	function dynamic_table() {
		//Wenn man Änderugen von der Daten macht werden die in der Tabelle der Datenbank
		//aktualisiert
		$ba = new beroAri();
		if ($_POST['a']=="save") {
					
			if ($_POST['logcdr'] == "1") {
				$ba->set("logcdr",$_POST['logcdr']);
			} else {
				$ba->set("logcdr","0");
			}
			
			$query=$ba->select("select option from activate");
			while($entry = $ba->fetch_array($query)){
				if ($entry['option'] <= 2){
					$query =  $ba->update("UPDATE activate SET option=2");
					$table.= "<script>aktivieren(1,'cdr','2','".ACTIVATE."');</script>";
				}
			}
		}
			
		require_once("./includes/lang.php");
		$table .= "<table class='contenttoc' id='table' width='350'>
					<tr>
					<th colspan='2'>".CDR_TABLE_HEADER_DIS."</th>
					</tr>
					<tr onmouseover=\"Tip('" . LOGCDR . "')\" onmouseout='UnTip()'>
					<td><b>".CDR_LOGCDR_DIS.":</b></td>
					<td>".$this->logcdr()."</td>
					</tr>
					<tr>
					<td colspan='2'><input name='submit' type='submit' value='".BUTTON_SAVE."' onmouseover=\"Tip('" . CDR_SAVE . "')\" onmouseout='UnTip()'>
					</td>
					</tr>
					</table>
					
					<br>";
	
		if ($ba->get("logcdr") == "1") {
			$table.="<script>
						function reload_cdr(){
							window.location.href='./index.php?m=cdr';
						}
					</script>
					<table class='contenttoc' width='350'>
					<tr><th>".CDR_DOWNLOAD_DIS."</th></tr>
					<tr>
					<td nowrap><b>".CDR_LOGFILE_DIS."</b>&nbsp;&nbsp;
					<input type='button' value='".CDR_BUTTON_DOWNLOAD_DIS."' onclick=\" window.location.href='misc/cdr_download.php'; window.setTimeout('reload_cdr()', 5000); \" onmouseover=\"Tip('".CDR_DOWNLOAD."')\" onmouseout='UnTip()'>&nbsp;&nbsp;";
					if (file_exists("/tmp/isgw.cdr.gz"))
						$table.="<input type='button' id='deletedatei' value='".CDR_BUTTON_DELETE_FILE_DIS."' onclick=\"javascript:if (confirm('Do you want to delete the logfile?')==true) window.location.href='misc/deletedatei.php?option=cdr';\" onmouseover=\"Tip('".CDR_DELETE."')\" onmouseout='UnTip()'>";
					$table.="</td>
					</tr>
					</table>
					</form>";
		}
		//Rückgabe: Erzeugte Tabelle mit den änderbaren Feldern von den Einstellungen von isgw.conf 					
		return $table;
	}

}
?>

