Переглянути джерело

Move CDR CSV to trunk/apps/cdr where it can be installed if for those that specifically download and install it.

Mark Crane 13 роки тому
батько
коміт
6992848e61
7 змінених файлів з 1535 додано та 0 видалено
  1. 121 0
      cdr/app_config.php
  2. 50 0
      cdr/root.php
  3. 410 0
      cdr/v_cdr.php
  4. 178 0
      cdr/v_cdr_csv.php
  5. 493 0
      cdr/v_cdr_edit.php
  6. 123 0
      cdr/v_cdr_import.php
  7. 160 0
      cdr/v_cdr_search.php

+ 121 - 0
cdr/app_config.php

@@ -0,0 +1,121 @@
+<?php
+	//application details
+		$apps[$x]['name'] = "CDR CSV";
+		$apps[$x]['uuid'] = '08caaf75-e30b-8b58-e4ad-d9cc76ba2f92';
+		$apps[$x]['category'] = 'Switch';;
+		$apps[$x]['subcategory'] = '';
+		$apps[$x]['version'] = '';
+		$apps[$x]['license'] = 'Mozilla Public License 1.1';
+		$apps[$x]['url'] = 'http://www.fusionpbx.com';
+		$apps[$x]['description']['en'] = 'Call detail records from CSV.';
+
+	//menu details
+		$apps[$x]['menu'][0]['title']['en'] = 'CDR CSV';
+		$apps[$x]['menu'][0]['uuid'] = '57d6bea3-edd3-13c8-e841-cc4cd852b905';
+		$apps[$x]['menu'][0]['parent_uuid'] = 'fd29e39c-c936-f5fc-8e2b-611681b266b5';
+		$apps[$x]['menu'][0]['category'] = 'internal';
+		$apps[$x]['menu'][0]['path'] = '/app/cdr/v_cdr.php';
+		$apps[$x]['menu'][0]['groups'][] = 'hidden';
+
+	//permission details
+		$apps[$x]['permissions'][0]['name'] = 'cdr_csv_view';
+		$apps[$x]['permissions'][0]['groups'][] = 'admin';
+		$apps[$x]['permissions'][0]['groups'][] = 'superadmin';
+
+	//schema details
+		$y = 0; //table array index
+		$z = 0; //field array index
+		$apps[$x]['db'][$y]['table'] = 'v_cdr';
+		$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = 'id';
+		$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = 'cdr_id';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'serial';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'integer';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'INT NOT NULL AUTO_INCREMENT';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = 'true';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'domain_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_domains';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'domain_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'v_id';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = 'true';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'caller_id_name';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'caller_id_number';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'destination_number';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'context';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'start_stamp';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'answer_stamp';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'end_stamp';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'duration';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'numeric';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'billsec';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'numeric';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'hangup_cause';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'bleg_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'accountcode';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'read_codec';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'write_codec';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'remote_media_ip';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'network_addr';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+
+?>

+ 50 - 0
cdr/root.php

@@ -0,0 +1,50 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+
+// make sure the PATH_SEPARATOR is defined
+	if (!defined("PATH_SEPARATOR")) {
+		if ( strpos( $_ENV[ "OS" ], "Win" ) !== false ) { define("PATH_SEPARATOR", ";"); } else { define("PATH_SEPARATOR", ":"); }
+	}
+
+// make sure the document_root is set
+	$_SERVER["SCRIPT_FILENAME"] = str_replace("\\", "/", $_SERVER["SCRIPT_FILENAME"]);
+	$_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]);
+	$_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]);
+	//echo "DOCUMENT_ROOT: ".$_SERVER["DOCUMENT_ROOT"]."<br />\n";
+	//echo "PHP_SELF: ".$_SERVER["PHP_SELF"]."<br />\n";
+	//echo "SCRIPT_FILENAME: ".$_SERVER["SCRIPT_FILENAME"]."<br />\n";
+
+// if the project directory exists then add it to the include path otherwise add the document root to the include path
+	if (is_dir($_SERVER["DOCUMENT_ROOT"].'/fusionpbx')){
+		if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', '/fusionpbx'); }
+		set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER["DOCUMENT_ROOT"].'/fusionpbx' );
+	}
+	else {
+		if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', ''); }
+		set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] );
+	}
+
+?>

+ 410 - 0
cdr/v_cdr.php

@@ -0,0 +1,410 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+require "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('cdr_csv_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+require_once "includes/header.php";
+require_once "includes/paging.php";
+
+require_once "v_cdr_import.php";
+require "includes/lib_cdr.php";
+	
+$order_by = $_GET["order_by"];
+$order = $_GET["order"];
+
+if (count($_REQUEST)>0) {
+	$cdr_id = $_REQUEST["cdr_id"];
+	$caller_id_name = $_REQUEST["caller_id_name"];
+	$caller_id_number = $_REQUEST["caller_id_number"];
+	$destination_number = $_REQUEST["destination_number"];
+	$context = $_REQUEST["context"];
+	$start_stamp = $_REQUEST["start_stamp"];
+	$answer_stamp = $_REQUEST["answer_stamp"];
+	$end_stamp = $_REQUEST["end_stamp"];
+	$duration = $_REQUEST["duration"];
+	$billsec = $_REQUEST["billsec"];
+	$hangup_cause = $_REQUEST["hangup_cause"];
+	$uuid = $_REQUEST["uuid"];
+	$bleg_uuid = $_REQUEST["bleg_uuid"];
+	$accountcode = $_REQUEST["accountcode"];
+	$read_codec = $_REQUEST["read_codec"];
+	$write_codec = $_REQUEST["write_codec"];
+	$remote_media_ip = $_REQUEST["remote_media_ip"];
+	$network_addr = $_REQUEST["network_addr"];
+}
+
+//call detail record list
+	echo "<div align='center'>";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
+
+	echo "<tr class='border'>\n";
+	echo "	<td align=\"center\">\n";
+	echo "      <br>";
+
+	echo "<table width='100%' border='0'><tr>\n";
+	echo "<td align='left' width='50%' nowrap><b>Call Detail Records</b></td>\n";
+	echo "<td align='left' width='50%' align='right'>&nbsp;</td>\n";
+	echo "</tr>\n";
+	echo "<tr>\n";
+	echo "<td align='left' colspan='2'>\n";
+
+	echo "Call Detail Records (CDRs) are detailed information on the calls. \n";
+	echo "The information contains source, destination, duration, and other useful call details. \n";
+	echo "Use the fields to filter the information for the specific call records that are desired. \n";
+	echo "Then view the calls in the list or download them as comma seperated file by using the 'csv' button. \n";
+	//To do an advanced search of the call detail records click on the following advanced button.
+
+	echo "<br />\n";
+	echo "<br />\n";
+
+	echo "</td>\n";
+	echo "</tr></table>\n";
+
+	if (strlen($cdr_id) > 0) { $sql_where .= "and cdr_id like '%$cdr_id%' "; }
+	if (strlen($caller_id_name) > 0) { $sql_where .= "and caller_id_name like '%$caller_id_name%' "; }
+	if (strlen($caller_id_number) > 0) { $sql_where .= "and caller_id_number like '%$caller_id_number%' "; }
+	if (strlen($destination_number) > 0) { $sql_where .= "and destination_number like '%$destination_number%' "; }
+	if (strlen($context) > 0) { $sql_where .= "and context like '%$context%' "; }
+	if (strlen($start_stamp) > 0) { $sql_where .= "and start_stamp like '%$start_stamp%' "; }
+	if (strlen($answer_stamp) > 0) { $sql_where .= "and answer_stamp like '%$answer_stamp%' "; }
+	if (strlen($end_stamp) > 0) { $sql_where .= "and end_stamp like '%$end_stamp%' "; }
+	if (strlen($duration) > 0) { $sql_where .= "and duration like '%$duration%' "; }
+	if (strlen($billsec) > 0) { $sql_where .= "and billsec like '%$billsec%' "; }
+	if (strlen($hangup_cause) > 0) { $sql_where .= "and hangup_cause like '%$hangup_cause%' "; }
+	if (strlen($uuid) > 0) { $sql_where .= "and uuid like '%$uuid%' "; }
+	if (strlen($bleg_uuid) > 0) { $sql_where .= "and bleg_uuid like '%$bleg_uuid%' "; }
+	if (strlen($accountcode) > 0) { $sql_where .= "and accountcode like '%$accountcode%' "; }
+	if (strlen($read_codec) > 0) { $sql_where .= "and read_codec like '%$read_codec%' "; }
+	if (strlen($write_codec) > 0) { $sql_where .= "and write_codec like '%$write_codec%' "; }
+	if (strlen($remote_media_ip) > 0) { $sql_where .= "and remote_media_ip like '%$remote_media_ip%' "; }
+	if (strlen($network_addr) > 0) { $sql_where .= "and network_addr like '%$network_addr%' "; }
+	if (!if_group("admin") && !if_group("superadmin")) {
+		$sql_where = "where ";
+		if (count($_SESSION['user']['extension']) > 0) {
+			foreach ($_SESSION['user']['extension'] as &$row) {
+				if ($row['user'] > 0) { $sql_where .= "or domain_uuid = '$domain_uuid' and caller_id_number = '".$row['user']."' ". $sql_where_orig." \n"; } //source
+				if ($row['user'] > 0) { $sql_where .= "or domain_uuid = '$domain_uuid' and destination_number = '".$row['user']."' ".$sql_where_orig." \n"; } //destination
+				if ($row['user'] > 0) { $sql_where .= "or domain_uuid = '$domain_uuid' and destination_number = '*99".$row['user']."' ".$sql_where_orig." \n"; } //destination
+			}
+		}
+	}
+	else {
+		//superadmin or admin
+		$sql_where = "where domain_uuid = '$domain_uuid' ".$sql_where;
+	}
+	$sql_where = str_replace ("where or", "where", $sql_where);
+	$sql_where = str_replace ("where and", " and", $sql_where);
+
+	$sql = "";
+	$sql .= " select * from v_cdr ";
+	$sql .= $sql_where;
+	if (strlen($order_by) == 0) {
+		$sql .= "order by cdr_id desc "; 
+	}
+	else {
+		$sql .= "order by $order_by $order "; 
+	}
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	$num_rows = count($result);
+	unset ($prep_statement, $result, $sql);
+
+	$param = "";
+	$param .= "&caller_id_name=$caller_id_name";
+	$param .= "&start_stamp=$start_stamp";
+	$param .= "&hangup_cause=$hangup_cause";
+	$param .= "&caller_id_number=$caller_id_number";
+	$param .= "&destination_number=$destination_number";
+	$param .= "&context=$context";
+	$param .= "&answer_stamp=$answer_stamp";
+	$param .= "&end_stamp=$end_stamp";
+	$param .= "&duration=$duration";
+	$param .= "&billsec=$billsec";
+	$param .= "&uuid=$uuid";
+	$param .= "&bleg_uuid=$bleg_uuid";
+	$param .= "&accountcode=$accountcode";
+	$param .= "&read_codec=$read_codec";
+	$param .= "&write_codec=$write_codec";
+	$param .= "&remote_media_ip=$remote_media_ip";
+	$param .= "&network_addr=$network_addr";
+
+	$rows_per_page = 200;
+
+	$page = $_GET['page'];
+	if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } 
+	list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); 
+	$offset = $rows_per_page * $page; 
+
+	$sql = "";
+	$sql .= " select * from v_cdr ";
+	$sql .= $sql_where;
+	if (strlen($order_by) == 0) {
+		$sql .= "order by cdr_id desc "; 
+	}
+	else {
+		$sql .= "order by $order_by $order "; 
+	}
+	$sql .= " limit $rows_per_page offset $offset ";
+	//echo $sql;
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	$result_count = count($result);
+	unset ($prep_statement, $sql);
+
+
+	$c = 0;
+	$row_style["0"] = "row_style0";
+	$row_style["1"] = "row_style1";
+
+	//search the call detail records
+	if (if_group("admin") || if_group("superadmin")) {
+		echo "<div align='center'>\n";
+
+		echo "<form method='post' action=''>";
+
+		echo "<table width='95%' cellpadding='3' border='0'>";
+		echo "<tr>";
+		echo "<td width='33.3%'>\n";
+			echo "<table width='100%'>";
+			//echo "	<tr>";
+			//echo "		<td>Source Name:</td>";
+			//echo "		<td><input type='text' class='txt' name='caller_id_name' value='$caller_id_name'></td>";
+			//echo "	</tr>";
+			echo "	<tr>";
+			echo "		<td align='left' width='25%'>Start:</td>";
+			echo "		<td align='left' width='75%'><input type='text' class='txt' name='start_stamp' value='$start_stamp'></td>";
+			echo "	</tr>";
+			echo "	<tr>";
+			echo "		<td align='left' width='25%'>Status:</td>";
+			echo "		<td align='left' width='75%'><input type='text' class='txt' name='hangup_cause' value='$hangup_cause'></td>";
+			echo "	</tr>";
+			echo "</table>\n";
+
+		echo "</td>\n";
+		echo "<td width='33.3%'>\n";
+
+			echo "<table width='100%'>";
+			echo "	<tr>";
+			echo "		<td align='left' width='25%'>Source:</td>";
+			echo "		<td align='left' width='75%'><input type='text' class='txt' name='caller_id_number' value='$caller_id_number'></td>";
+			echo "	</tr>";
+			echo "	<tr>";
+			echo "		<td align='left' width='25%'>Destination:</td>";
+			echo "		<td align='left' width='75%'><input type='text' class='txt' name='destination_number' value='$destination_number'></td>";
+			echo "	</tr>";	
+			echo "</table>\n";
+
+		echo "</td>\n";
+		echo "<td width='33.3%'>\n";
+
+			echo "<table width='100%'>\n";
+			//echo "	<tr>";
+			//echo "		<td>Context:</td>";
+			//echo "		<td><input type='text' class='txt' name='context' value='$context'></td>";
+			//echo "	</tr>";
+
+			//echo "	<tr>";
+			//echo "		<td>Answer:</td>";
+			//echo "		<td><input type='text' class='txt' name='answer_stamp' value='$answer_stamp'></td>";
+			//echo "	</tr>";
+			//echo "	<tr>";
+			//echo "		<td>End:</td>";
+			//echo "		<td><input type='text' class='txt' name='end_stamp' value='$end_stamp'></td>";
+			//echo "	</tr>";
+			echo "	<tr>";
+			echo "		<td align='left' width='25%'>Duration:</td>";
+			echo "		<td align='left' width='75%'><input type='text' class='txt' name='duration' value='$duration'></td>";
+			echo "	</tr>";
+			echo "	<tr>";
+			echo "		<td align='left' width='25%'>Bill:</td>";
+			echo "		<td align='left' width='75%'><input type='text' class='txt' name='billsec' value='$billsec'></td>";
+			echo "	</tr>";
+
+			//echo "	<tr>";
+			//echo "		<td>UUID:</td>";
+			//echo "		<td><input type='text' class='txt' name='uuid' value='$uuid'></td>";
+			//echo "	</tr>";
+			//echo "	<tr>";
+			//echo "		<td>Bleg UUID:</td>";
+			//echo "		<td><input type='text' class='txt' name='bleg_uuid' value='$bleg_uuid'></td>";
+			//echo "	</tr>";
+			//echo "	<tr>";
+			//echo "		<td>Account Code:</td>";
+			//echo "		<td><input type='text' class='txt' name='accountcode' value='$accountcode'></td>";
+			//echo "	</tr>";
+			//echo "	<tr>";
+			//echo "		<td>Read Codec:</td>";
+			//echo "		<td><input type='text' class='txt' name='read_codec' value='$read_codec'></td>";
+			//echo "	</tr>";
+			//echo "	<tr>";
+			//echo "		<td>Write Codec:</td>";
+			//echo "		<td><input type='text' class='txt' name='write_codec' value='$write_codec'></td>";
+			//echo "	</tr>";
+			//echo "	<tr>";
+			//echo "		<td>Remote Media IP:</td>";
+			//echo "		<td><input type='text' class='txt' name='remote_media_ip' value='$remote_media_ip'></td>";
+			//echo "	</tr>";
+			//echo "	<tr>";
+			//echo "		<td>Network Address:</td>";
+			//echo "		<td><input type='text' class='txt' name='network_addr' value='$network_addr'></td>";
+			//echo "	</tr>";
+			//echo "	<tr>";
+
+			echo "	</tr>";
+			echo "</table>";
+
+		echo "</td>";
+		echo "</tr>";
+		echo "<tr>\n";
+		echo "<td colspan='2' align='right'>\n";
+		//echo "	<input type='button' class='btn' name='' alt='view' onclick=\"window.location='v_cdr_search.php'\" value='advanced'>\n";
+		echo "</td>\n";
+		echo "<td colspan='1' align='right'>\n";
+		echo "	<input type='button' class='btn' name='' alt='view' onclick=\"window.location='v_cdr_search.php'\" value='advanced'>&nbsp;\n";
+		echo "	<input type='submit' class='btn' name='submit' value='filter'>\n";
+		echo "</td>\n";
+		echo "</tr>";
+		echo "</table>";
+		echo "</form>";
+	}
+
+
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+
+	echo "<tr>\n";
+	echo "<th>Start</th>\n";
+	//echo th_order_by('start_stamp', 'Start', $order_by, $order);
+	echo th_order_by('caller_id_name', 'CID Name', $order_by, $order);
+	echo "<th>Source</th>\n";
+	//echo th_order_by('caller_id_number', 'Source', $order_by, $order);
+	echo "<th>Destination</th>\n";
+	//echo th_order_by('destination_number', 'Destination', $order_by, $order);
+	//echo th_order_by('context', 'Context', $order_by, $order);
+	//echo th_order_by('answer_stamp', 'Answer', $order_by, $order);
+	//echo th_order_by('end_stamp', 'End', $order_by, $order);
+	echo "<th>Duration</th>\n";
+	//echo th_order_by('duration', 'Duration', $order_by, $order);
+	echo "<th>Bill</th>\n";
+	//echo th_order_by('billsec', 'Bill', $order_by, $order);
+	echo "<th>Status</th>\n";
+	//echo th_order_by('hangup_cause', 'Status', $order_by, $order);
+
+
+	echo "<form method='post' action='v_cdr_csv.php'>";
+	echo "<td align='left' width='22'>\n";
+	echo "<input type='hidden' name='caller_id_name' value='$caller_id_name'>\n";
+	echo "<input type='hidden' name='start_stamp' value='$start_stamp'>\n";
+	echo "<input type='hidden' name='hangup_cause' value='$hangup_cause'>\n";
+	echo "<input type='hidden' name='caller_id_number' value='$caller_id_number'>\n";
+	echo "<input type='hidden' name='destination_number' value='$destination_number'>\n";
+	echo "<input type='hidden' name='context' value='$context'>\n";
+	echo "<input type='hidden' name='answer_stamp' value='$answer_stamp'>\n";
+	echo "<input type='hidden' name='end_stamp' value='$end_stamp'>\n";
+	echo "<input type='hidden' name='duration' value='$duration'>\n";
+	echo "<input type='hidden' name='billsec' value='$billsec'>\n";
+	echo "<input type='hidden' name='uuid' value='$uuid'>\n";
+	echo "<input type='hidden' name='bleg_uuid' value='$bleg_uuid'>\n";
+	echo "<input type='hidden' name='accountcode' value='$accountcode'>\n";
+	echo "<input type='hidden' name='read_codec' value='$read_codec'>\n";
+	echo "<input type='hidden' name='write_codec' value='$write_codec'>\n";
+	echo "<input type='hidden' name='remote_media_ip' value='$remote_media_ip'>\n";
+	echo "<input type='hidden' name='network_addr' value='$network_addr'>\n";
+	echo "<input type='submit' class='btn' name='submit' value=' csv '>\n";
+	//echo "    <input type='button' class='btn' name='' alt='view' onclick=\"window.location='v_cdr_csv.php?id=".$row[cdr_id]."'\" value='csv'>\n";
+	//echo "  <input type='button' class='btn' name='' alt='add' onclick=\"window.location='v_cdr_edit.php'\" value='+'>\n";
+	echo "</td>\n";
+	echo "</form>\n";
+	echo "<tr>\n";
+
+	if ($result_count == 0) { //no results
+	}
+	else { //received results
+		foreach($result as $row) {
+			//print_r( $row );
+			echo "<tr >\n";
+			echo "   <td valign='top' class='".$row_style[$c]."' nowrap>&nbsp;".$row[start_stamp]."&nbsp;</td>\n";
+			echo "   <td valign='top' class='".$row_style[$c]."'>&nbsp;".$row[caller_id_name]."&nbsp;</td>\n";
+			echo "   <td valign='top' class='".$row_style[$c]."'>&nbsp;".$row[caller_id_number]."&nbsp;</td>\n";
+			echo "   <td valign='top' class='".$row_style[$c]."'>&nbsp;".$row[destination_number]."&nbsp;</td>\n";
+			//echo "   <td valign='top' class='".$row_style[$c]."'>&nbsp;".$row[context]."&nbsp;</td>\n";
+			//echo "   <td valign='top' class='".$row_style[$c]."' nowrap>&nbsp;".$row[answer_stamp]."&nbsp;</td>\n";
+			//echo "   <td valign='top' class='".$row_style[$c]."' nowrap>&nbsp;".$row[end_stamp]."&nbsp;</td>\n";
+			$duration = $row[duration];
+			//if ($duration < 60) { $duration = $duration. " sec"; }
+			//if ($duration > 60) { $duration = round(($duration/60), 2). " min"; }
+			echo "   <td valign='top' class='".$row_style[$c]."'>&nbsp;".$duration."&nbsp;</td>\n";
+			echo "   <td valign='top' class='".$row_style[$c]."' nowrap>&nbsp;".$row[billsec]."&nbsp;</td>\n";
+			echo "   <td valign='top' class='".$row_style[$c]."' nowrap>&nbsp;".strtolower($row[hangup_cause])."&nbsp;</td>\n";
+			echo "   <td valign='top' align='right'>\n";
+			//echo "	<a href='v_cdr_edit.php?id=".$row[cdr_id]."' alt='add'>$v_link_label_view</a>\n";
+			echo "       <input type='button' class='btn' name='' alt='view' onclick=\"window.location='v_cdr_edit.php?id=".$row[cdr_id]."'\" value='  >  '>\n";
+			//echo "       <input type='button' class='btn' name='' alt='delete' onclick=\"if (confirm('Are you sure you want to delete this?')) { window.location='v_cdr_delete.php?id=".$row[cdr_id]."' }\" value='x'>\n";
+			echo "   </td>\n";
+			echo "</tr>\n";
+			if ($c==0) { $c=1; } else { $c=0; }
+		} //end foreach
+		unset($sql, $result, $row_count);
+	} //end if results
+
+
+	echo "<tr>\n";
+	echo "<td colspan='7'>\n";
+	echo "   <table width='100%' cellpadding='0' cellspacing='0'>\n";
+	echo "   <tr>\n";
+	echo "       <td width='33.3%' nowrap>&nbsp;</td>\n";
+	echo "       <td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
+	echo "       <td width='33.3%' align='right'>&nbsp;</td>\n";
+	//echo "       <td width='33.3%' align='right'><input type='button' class='btn' name='' alt='add' onclick=\"window.location='v_cdr_edit.php'\" value='+'></td>\n";
+	echo "   </tr>\n";
+	echo "   </table>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+
+	echo "</table>";
+	echo "</div>";
+	echo "<br><br>";
+	echo "<br><br>";
+
+
+	echo "</td>";
+	echo "</tr>";
+	echo "</table>";
+	echo "</div>";
+	echo "<br><br>";
+
+require "includes/require.php";
+require_once "includes/footer.php";
+?>

+ 178 - 0
cdr/v_cdr_csv.php

@@ -0,0 +1,178 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('cdr_csv_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+require_once "includes/lib_cdr.php";
+
+if (count($_REQUEST)>0) {
+	$cdr_id = $_REQUEST["cdr_id"];
+	$caller_id_name = $_REQUEST["caller_id_name"];
+	$caller_id_number = $_REQUEST["caller_id_number"];
+	$destination_number = $_REQUEST["destination_number"];
+	$context = $_REQUEST["context"];
+	$start_stamp = $_REQUEST["start_stamp"];
+	$answer_stamp = $_REQUEST["answer_stamp"];
+	$end_stamp = $_REQUEST["end_stamp"];
+	$duration = $_REQUEST["duration"];
+	$billsec = $_REQUEST["billsec"];
+	$hangup_cause = $_REQUEST["hangup_cause"];
+	$uuid = $_REQUEST["uuid"];
+	$bleg_uuid = $_REQUEST["bleg_uuid"];
+	$accountcode = $_REQUEST["accountcode"];
+	$read_codec = $_REQUEST["read_codec"];
+	$write_codec = $_REQUEST["write_codec"];
+	$remote_media_ip = $_REQUEST["remote_media_ip"];
+	$network_addr = $_REQUEST["network_addr"];
+}
+
+//get a list of assigned extensions for this user
+	$sql = "";
+	$sql .= " select * from v_extensions ";
+	$sql .= "where domain_uuid = '$domain_uuid' ";
+	$sql .= "and user_list like '%|".$_SESSION["username"]."|%' ";
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	//$v_mailboxes = '';
+	$x = 0;
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		//$v_mailboxes = $v_mailboxes.$row["mailbox"].'|';
+		//$extension_uuid = $row["extension_uuid"];
+		//$mailbox = $row["mailbox"];
+		$extension_array[$x]['extension_uuid'] = $row["extension_uuid"];
+		$extension_array[$x]['extension'] = $row["extension"];
+		$x++;
+	}
+	unset ($prep_statement, $x);
+
+
+if (if_group("admin") || if_group("superadmin")) {
+	$sql_where = "where ";
+}
+if (strlen($domain_uuid) > 0) { $sql_where .= "and domain_uuid like '$domain_uuid' "; }
+if (strlen($cdr_id) > 0) { $sql_where .= "and cdr_id like '%$cdr_id%' "; }
+if (strlen($caller_id_name) > 0) { $sql_where .= "and caller_id_name like '%$caller_id_name%' "; }
+if (strlen($caller_id_number) > 0) { $sql_where .= "and caller_id_number like '%$caller_id_number%' "; }
+if (strlen($destination_number) > 0) { $sql_where .= "and destination_number like '%$destination_number%' "; }
+if (strlen($context) > 0) { $sql_where .= "and context like '%$context%' "; }
+if (strlen($start_stamp) > 0) { $sql_where .= "and start_stamp like '%$start_stamp%' "; }
+if (strlen($answer_stamp) > 0) { $sql_where .= "and answer_stamp like '%$answer_stamp%' "; }
+if (strlen($end_stamp) > 0) { $sql_where .= "and end_stamp like '%$end_stamp%' "; }
+if (strlen($duration) > 0) { $sql_where .= "and duration like '%$duration%' "; }
+if (strlen($billsec) > 0) { $sql_where .= "and billsec like '%$billsec%' "; }
+if (strlen($hangup_cause) > 0) { $sql_where .= "and hangup_cause like '%$hangup_cause%' "; }
+if (strlen($uuid) > 0) { $sql_where .= "and uuid like '%$uuid%' "; }
+if (strlen($bleg_uuid) > 0) { $sql_where .= "and bleg_uuid like '%$bleg_uuid%' "; }
+if (strlen($accountcode) > 0) { $sql_where .= "and accountcode like '%$accountcode%' "; }
+if (strlen($read_codec) > 0) { $sql_where .= "and read_codec like '%$read_codec%' "; }
+if (strlen($write_codec) > 0) { $sql_where .= "and write_codec like '%$write_codec%' "; }
+if (strlen($remote_media_ip) > 0) { $sql_where .= "and remote_media_ip like '%$remote_media_ip%' "; }
+if (strlen($network_addr) > 0) { $sql_where .= "and network_addr like '%$network_addr%' "; }
+if (!if_group("admin") && !if_group("superadmin")) {
+	if (trim($sql_where) == "where") { $sql_where = ""; }
+	//disable member search
+	//$sql_where_orig = $sql_where;
+	$sql_where = "where ";
+	if (count($_SESSION['user']['extension']) > 0) {
+		foreach ($_SESSION['user']['extension'] as &$row) {
+			if ($row['user'] > 0) { $sql_where .= "or caller_id_number = '".$row['user']."' ". $sql_where_orig; } //source
+			if ($row['user'] > 0) { $sql_where .= "or destination_number = '".$row['user']."' ".$sql_where_orig; } //destination
+			if ($row['user'] > 0) { $sql_where .= "or destination_number = '*99".$row['user']."' ".$sql_where_orig; } //destination
+		}
+	}
+}
+$sql_where = str_replace ("where or", "where", $sql_where);
+$sql_where = str_replace ("where and", "where", $sql_where);
+
+$sql = "";
+$sql .= "select * from v_cdr ";
+$sql .= $sql_where;
+if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
+$prep_statement = $db->prepare(check_sql($sql));
+$prep_statement->execute();
+$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
+$result_count = count($result);
+
+
+header('Content-type: application/octet-binary');
+header('Content-Disposition: attachment; filename=cdr.csv');
+
+$z = 0;
+foreach($result[0] as $key => $val) {
+
+    if ($z == 0) {
+        echo '"'.$key.'"';
+    }
+    else {
+        echo ',"'.$key.'"';
+    }
+    $z++;
+}
+echo "\n";
+
+
+$x=0;
+while(true) {
+
+    $z = 0;
+    foreach($result[0] as $key => $val) {
+        if ($z == 0) {
+            echo '"'.$result[$x][$key].'"';
+        }
+        else {
+            echo ',"'.$result[$x][$key].'"';
+        }
+        $z++;
+    }
+    echo "\n";
+
+    ++$x;
+    if ($x > ($result_count-1)) {
+        break;
+    }
+    //$row++;
+}
+
+unset ($result_count);
+unset ($resulttype);
+unset ($result);
+unset ($key);
+unset ($val);
+unset ($msg);
+unset ($errormsg);
+unset ($sql);
+unset ($x);
+unset ($z);
+?>

+ 493 - 0
cdr/v_cdr_edit.php

@@ -0,0 +1,493 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+require "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('cdr_csv_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+require_once "v_cdr_import.php";
+
+//action add or update
+if (isset($_REQUEST["id"])) {
+	$action = "update";
+	$cdr_id = check_str($_REQUEST["id"]);
+}
+else {
+	$action = "add";
+}
+
+//POST to PHP variables
+if (count($_POST)>0) {
+	$caller_id_name = check_str($_POST["caller_id_name"]);
+	$caller_id_number = check_str($_POST["caller_id_number"]);
+	$destination_number = check_str($_POST["destination_number"]);
+	$context = check_str($_POST["context"]);
+	$start_stamp = check_str($_POST["start_stamp"]);
+	$answer_stamp = check_str($_POST["answer_stamp"]);
+	$end_stamp = check_str($_POST["end_stamp"]);
+	$duration = check_str($_POST["duration"]);
+	$billsec = check_str($_POST["billsec"]);
+	$hangup_cause = check_str($_POST["hangup_cause"]);
+	$uuid = check_str($_POST["uuid"]);
+	$bleg_uuid = check_str($_POST["bleg_uuid"]);
+	$accountcode = check_str($_POST["accountcode"]);
+	$read_codec = check_str($_POST["read_codec"]);
+	$write_codec = check_str($_POST["write_codec"]);
+	$remote_media_ip = check_str($_POST["remote_media_ip"]);
+	$network_addr = check_str($_POST["network_addr"]);
+}
+
+/*
+if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
+
+	$msg = '';
+
+	////recommend moving this to the config.php file
+	$uploadtempdir = $_ENV["TEMP"]."\\";
+	ini_set('upload_tmp_dir', $uploadtempdir);
+	////$imagedir = $_ENV["TEMP"]."\\";
+	////$filedir = $_ENV["TEMP"]."\\";
+
+	if ($action == "update") {
+		$cdr_id = check_str($_POST["cdr_id"]);
+	}
+
+	//check for all required data
+		//if (strlen($caller_id_name) == 0) { $msg .= "Please provide: CID Name<br>\n"; }
+		//if (strlen($caller_id_number) == 0) { $msg .= "Please provide: CID Number<br>\n"; }
+		//if (strlen($destination_number) == 0) { $msg .= "Please provide: Destination<br>\n"; }
+		//if (strlen($context) == 0) { $msg .= "Please provide: Context<br>\n"; }
+		//if (strlen($start_stamp) == 0) { $msg .= "Please provide: Start<br>\n"; }
+		//if (strlen($answer_stamp) == 0) { $msg .= "Please provide: Answer<br>\n"; }
+		//if (strlen($end_stamp) == 0) { $msg .= "Please provide: End<br>\n"; }
+		//if (strlen($duration) == 0) { $msg .= "Please provide: Duration<br>\n"; }
+		//if (strlen($billsec) == 0) { $msg .= "Please provide: Bill Seconds<br>\n"; }
+		//if (strlen($hangup_cause) == 0) { $msg .= "Please provide: Hangup Cause<br>\n"; }
+		//if (strlen($uuid) == 0) { $msg .= "Please provide: UUID<br>\n"; }
+		//if (strlen($bleg_uuid) == 0) { $msg .= "Please provide: Bleg UUID<br>\n"; }
+		//if (strlen($accountcode) == 0) { $msg .= "Please provide: Account Code<br>\n"; }
+		//if (strlen($read_codec) == 0) { $msg .= "Please provide: Read Codec<br>\n"; }
+		//if (strlen($write_codec) == 0) { $msg .= "Please provide: Write Codec<br>\n"; }
+		//if (strlen($remote_media_ip) == 0) { $msg .= "Please provide: Remote Media IP<br>\n"; }
+		//if (strlen($network_addr) == 0) { $msg .= "Please provide: Network Addr<br>\n"; }
+		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
+			require "includes/require.php";
+			require_once "includes/header.php";
+			require_once "includes/persistformvar.php";
+			echo "<div align='center'>\n";
+			echo "<table><tr><td>\n";
+			echo $msg."<br />";
+			echo "</td></tr></table>\n";
+			persistformvar($_POST);
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		}
+
+	//add or update the database
+	if ($_POST["persistformvar"] != "true") {
+		if ($action == "add") {
+			$sql = "insert into v_cdr ";
+			$sql .= "(";
+			$sql .= "domain_uuid, ";
+			$sql .= "caller_id_name, ";
+			$sql .= "caller_id_number, ";
+			$sql .= "destination_number, ";
+			$sql .= "context, ";
+			$sql .= "start_stamp, ";
+			$sql .= "answer_stamp, ";
+			$sql .= "end_stamp, ";
+			$sql .= "duration, ";
+			$sql .= "billsec, ";
+			$sql .= "hangup_cause, ";
+			$sql .= "uuid, ";
+			$sql .= "bleg_uuid, ";
+			$sql .= "accountcode, ";
+			$sql .= "read_codec, ";
+			$sql .= "write_codec, ";
+			$sql .= "remote_media_ip, ";
+			$sql .= "network_addr ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'$domain_uuid', ";
+			$sql .= "'$caller_id_name', ";
+			$sql .= "'$caller_id_number', ";
+			$sql .= "'$destination_number', ";
+			$sql .= "'$context', ";
+			$sql .= "'$start_stamp', ";
+			$sql .= "'$answer_stamp', ";
+			$sql .= "'$end_stamp', ";
+			$sql .= "'$duration', ";
+			$sql .= "'$billsec', ";
+			$sql .= "'$hangup_cause', ";
+			$sql .= "'$uuid', ";
+			$sql .= "'$bleg_uuid', ";
+			$sql .= "'$accountcode', ";
+			$sql .= "'$read_codec', ";
+			$sql .= "'$write_codec', ";
+			$sql .= "'$remote_media_ip', ";
+			$sql .= "'$network_addr' ";
+			$sql .= ")";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			require "includes/require.php";
+			require_once "includes/header.php";
+			echo "<meta http-equiv=\"refresh\" content=\"2;url=v_cdr.php\">\n";
+			echo "<div align='center'>\n";
+			echo "Add Complete\n";
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		} //if ($action == "add")
+
+		if ($action == "update") {
+			$sql = "update v_cdr set ";
+			$sql .= "caller_id_name = '$caller_id_name', ";
+			$sql .= "caller_id_number = '$caller_id_number', ";
+			$sql .= "destination_number = '$destination_number', ";
+			$sql .= "context = '$context', ";
+			$sql .= "start_stamp = '$start_stamp', ";
+			$sql .= "answer_stamp = '$answer_stamp', ";
+			$sql .= "end_stamp = '$end_stamp', ";
+			$sql .= "duration = '$duration', ";
+			$sql .= "billsec = '$billsec', ";
+			$sql .= "hangup_cause = '$hangup_cause', ";
+			$sql .= "uuid = '$uuid', ";
+			$sql .= "bleg_uuid = '$bleg_uuid', ";
+			$sql .= "accountcode = '$accountcode', ";
+			$sql .= "read_codec = '$read_codec', ";
+			$sql .= "write_codec = '$write_codec', ";
+			$sql .= "remote_media_ip = '$remote_media_ip', ";
+			$sql .= "network_addr = '$network_addr' ";
+			$sql .= "where domain_uuid = '$domain_uuid' ";
+			$sql .= "and cdr_id = '$cdr_id' ";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			require "includes/require.php";
+			require_once "includes/header.php";
+			echo "<meta http-equiv=\"refresh\" content=\"2;url=v_cdr.php\">\n";
+			echo "<div align='center'>\n";
+			echo "Update Complete\n";
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		} //if ($action == "update")
+	} //if ($_POST["persistformvar"] != "true") { 
+} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
+*/
+
+//pre-populate the form
+if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
+	$cdr_id = $_GET["id"];
+	$sql = "";
+	$sql .= "select * from v_cdr ";	
+	if (!(if_group("admin") || if_group("superadmin"))) {
+		if (trim($sql_where) == "where") { $sql_where = ""; }
+		if (count($_SESSION['user']['extension']) > 0) {
+			foreach ($_SESSION['user']['extension'] as &$row) {
+				if ($row['user'] > 0) { $sql_where .= "or caller_id_number = '".$row['user']."' ". $sql_where_orig; } //source
+				if ($row['user'] > 0) { $sql_where .= "or destination_number = '".$row['user']."' ".$sql_where_orig; } //destination
+				if ($row['user'] > 0) { $sql_where .= "or destination_number = '*99".$row['user']."' ".$sql_where_orig; } //destination
+			}
+		}
+	}
+	else {
+		$sql .= "where domain_uuid = '$domain_uuid' ";
+		$sql .= "and cdr_id = '$cdr_id' ";
+	}
+	$sql_where = str_replace ("where or", "where", $sql_where);
+	$sql_where = str_replace ("where and", "where", $sql_where);
+	$sql .= $sql_where;
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+	foreach ($result as &$row) {
+		$caller_id_name = $row["caller_id_name"];
+		$caller_id_number = $row["caller_id_number"];
+		$destination_number = $row["destination_number"];
+		$context = $row["context"];
+		$start_stamp = $row["start_stamp"];
+		$answer_stamp = $row["answer_stamp"];
+		$end_stamp = $row["end_stamp"];
+		$duration = $row["duration"];
+		$billsec = $row["billsec"];
+		$hangup_cause = $row["hangup_cause"];
+		$uuid = $row["uuid"];
+		$bleg_uuid = $row["bleg_uuid"];
+		$accountcode = $row["accountcode"];
+		$read_codec = $row["read_codec"];
+		$write_codec = $row["write_codec"];
+		$remote_media_ip = $row["remote_media_ip"];
+		$network_addr = $row["network_addr"];
+		break; //limit to 1 row
+	}
+	unset ($prep_statement);
+}
+
+
+require "includes/require.php";
+require_once "includes/header.php";
+
+
+echo "<div align='center'>";
+echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
+
+echo "<tr class='border'>\n";
+echo "	<td align=\"left\">\n";
+echo "      <br>";
+
+
+
+echo "<form method='post' name='frm' action=''>\n";
+
+echo "<div align='center'>\n";
+echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
+
+echo "<tr>\n";
+if ($action == "add") {
+	echo "<td align='left' width='30%' nowrap><b>Call Detail Records Add</b></td>\n";
+}
+if ($action == "update") {
+	echo "<td align='left' width='30%' nowrap><b>Call Detail Records: Details</b></td>\n";
+}
+echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"window.location='v_cdr.php'\" value='Back'></td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    CID Name:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='caller_id_name' maxlength='255' value=\"$caller_id_name\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    CID Number:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='caller_id_number' maxlength='255' value=\"$caller_id_number\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Destination:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='destination_number' maxlength='255' value=\"$destination_number\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Context:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='context' maxlength='255' value=\"$context\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Start:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='start_stamp' maxlength='255' value=\"$start_stamp\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Answer:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='answer_stamp' maxlength='255' value=\"$answer_stamp\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    End:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='end_stamp' maxlength='255' value=\"$end_stamp\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Duration:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='duration' maxlength='255' value=\"$duration\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Bill Seconds:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='billsec' maxlength='255' value=\"$billsec\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Hangup Cause:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='hangup_cause' maxlength='255' value=\"$hangup_cause\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    UUID:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='uuid' maxlength='255' value=\"$uuid\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Bleg UUID:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='bleg_uuid' maxlength='255' value=\"$bleg_uuid\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Account Code:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='accountcode' maxlength='255' value=\"$accountcode\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Read Codec:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='read_codec' maxlength='255' value=\"$read_codec\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Write Codec:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='write_codec' maxlength='255' value=\"$write_codec\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Remote Media IP:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='remote_media_ip' maxlength='255' value=\"$remote_media_ip\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+echo "    Network Addr:\n";
+echo "</td>\n";
+echo "<td class='vtable' align='left'>\n";
+echo "    <input class='formfld' type='text' name='network_addr' maxlength='255' value=\"$network_addr\">\n";
+echo "<br />\n";
+echo "\n";
+echo "</td>\n";
+echo "</tr>\n";
+echo "	<tr>\n";
+echo "		<td colspan='2' align='right'>\n";
+if ($action == "update") {
+	echo "				<input type='hidden' name='cdr_id' value='$cdr_id'>\n";
+}
+//echo "				<input type='submit' name='submit' class='btn' value='Save'>\n";
+echo "		</td>\n";
+echo "	</tr>";
+echo "</table>";
+echo "</form>";
+
+
+echo "	</td>";
+echo "	</tr>";
+echo "</table>";
+echo "</div>";
+
+require "includes/require.php";
+require_once "includes/footer.php";
+?>

+ 123 - 0
cdr/v_cdr_import.php

@@ -0,0 +1,123 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+require "includes/require.php";
+if(php_sapi_name() == 'cli') {
+	//allow access for command line interface
+}
+else {
+	//require authentication
+	require_once "includes/checkauth.php";
+	if (permission_exists('cdr_csv_view')) {
+		//access granted
+	}
+	else {
+		echo "access denied";
+		exit;
+	}
+}
+
+require "includes/lib_cdr.php";
+
+//---- begin import cdr records -----------------------------------------------------------------------------------
+
+	$v_file = $_SESSION['switch']['log']['dir']."/cdr-csv/Master.csv";
+	//echo filesize($v_file);
+	//Open file (DON'T USE a+ pointer will be wrong!)
+	$fh = fopen($v_file, 'r');
+	
+	$read = 524288;
+	//$read = 524288;
+	//$read = 1048576;
+	//$read = 16777216; //Read 16meg chunks
+	$x = 0;
+	$part = 0;
+	$strcount=0;
+	while(!feof($fh)) {
+		$rbuf = fread($fh, $read);
+		for($i=$read;$i > 0 || $n == chr(10);$i--) {
+			$n=substr($rbuf, $i, 1);
+			if($n == chr(10))break;
+				//If we are at the end of the file, just grab the rest and stop loop
+			elseif(feof($fh)) {
+				$i = $read;
+				$buf = substr($rbuf, 0, $i+1);
+				break;
+		   }
+		}
+		$count = $db->exec("BEGIN;"); //returns affected rows
+
+		//This is the buffer we want to do stuff with, maybe thow to a function?
+		$buf = substr($rbuf, 0, $i+1);
+		$buf = str_replace("{domain_uuid}", $domain_uuid, $buf);
+		$totalsize = strlen($buf)+$totalsize;
+
+		$lnarray = explode ("\n", $buf);
+		//print_r($lnarray);
+
+		$columnvaluecount=0;
+		foreach($lnarray as $sql) {
+
+			//--- Begin SQLite -------------------------------------
+
+					if (strlen($sql) > 0) {
+						//echo $sql."<br /><br />\n";
+						$count = $db->exec(check_sql($sql)); //returns affected rows
+
+						$x++;
+						if ($x > 10000) {
+							$count = $db->exec("COMMIT;"); //returns affected rows
+							$count = $db->exec("BEGIN;"); //returns affected rows
+						}
+
+					}
+					unset($sql);
+
+			//---EndSQLite-------------------------------------
+
+			//if ($columnvaluecount > 10) { break; }
+			$columnvaluecount++;
+		}
+
+		//Point marker back to last \n point
+		$part = ftell($fh)-($read-($i+1));
+		fseek($fh, $part);
+		if ($strcount >= 5000) { break; } //handle up to a gig file
+		$strcount++;
+
+	}
+
+	$count = $db->exec("COMMIT;"); //returns affected rows
+	fclose($fh);
+
+	//truncate the file now that it has been processed
+		$fh = fopen($v_file, 'w');
+		fclose($fh);
+
+
+//---- begin import cdr records -----------------------------------------------------------------------------------
+
+?>

+ 160 - 0
cdr/v_cdr_search.php

@@ -0,0 +1,160 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Copyright (C) 2008-2012 
+	All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('calls_active_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+if (count($_POST)>0) {
+	$cdr_id = $_POST["cdr_id"];
+	$caller_id_name = $_POST["caller_id_name"];
+	$caller_id_number = $_POST["caller_id_number"];
+	$destination_number = $_POST["destination_number"];
+	$context = $_POST["context"];
+	$start_stamp = $_POST["start_stamp"];
+	$answer_stamp = $_POST["answer_stamp"];
+	$end_stamp = $_POST["end_stamp"];
+	$duration = $_POST["duration"];
+	$billsec = $_POST["billsec"];
+	$hangup_cause = $_POST["hangup_cause"];
+	$uuid = $_POST["uuid"];
+	$bleg_uuid = $_POST["bleg_uuid"];
+	$accountcode = $_POST["accountcode"];
+	$read_codec = $_POST["read_codec"];
+	$write_codec = $_POST["write_codec"];
+	$remote_media_ip = $_POST["remote_media_ip"];
+	$network_addr = $_POST["network_addr"];
+}
+else {
+
+	echo "\n";    
+	require_once "includes/header.php";
+	echo "<div align='center'>";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
+
+	echo "<tr class='border'>\n";
+	echo "	<td align=\"left\">\n";
+	echo "      <br>";
+
+	echo "<form method='post' action='v_cdr.php'>";
+	echo "<table width='100%' cellpadding='6' cellspacing='0'>";
+
+	echo "<tr>\n";
+	echo "<td width='30%' nowrap valign='top'><b>Advanced Search</b></td>\n";
+	echo "<td width='70%' align='right' valign='top'><input type='button' class='btn' name='' alt='back' onclick=\"window.location='v_cdr.php'\" value='Back'><br /><br /></td>\n";
+	echo "</tr>\n";
+
+	echo "	<tr>";
+	echo "		<td class='vncell'>Source Name:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='caller_id_name' value='$caller_id_name'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Source Number:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='caller_id_number' value='$caller_id_number'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Destination Number:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='destination_number' value='$destination_number'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Context:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='context' value='$context'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Start:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='start_stamp' value='$start_stamp'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Answer:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='answer_stamp' value='$answer_stamp'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>End:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='end_stamp' value='$end_stamp'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Duration:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='duration' value='$duration'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Bill Sec:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='billsec' value='$billsec'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Status:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='hangup_cause' value='$hangup_cause'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>UUID:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='uuid' value='$uuid'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Bleg UUID:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='bleg_uuid' value='$bleg_uuid'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Account Code:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='accountcode' value='$accountcode'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Read Codec:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='read_codec' value='$read_codec'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Write Codec:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='write_codec' value='$write_codec'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Remote Media IP:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='remote_media_ip' value='$remote_media_ip'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td class='vncell'>Network Address:</td>";
+	echo "		<td class='vtable'><input type='text' class='formfld' name='network_addr' value='$network_addr'></td>";
+	echo "	</tr>";
+	echo "	<tr>";
+	echo "		<td colspan='2' align='right'><input type='submit' name='submit' class='btn' value='Search'></td>";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</form>";
+
+
+	echo "	</td>";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</div>";
+
+
+require_once "includes/footer.php";
+
+} //end if not post
+?>