getfile and convo gen
getfile and convo gen

<?php <?php
include('common.inc.php'); include('common.inc.php');
function getTGIDValuesByHour($TGID, $timeFrom, $timeTo) { function getTGIDValuesByHour($TGID, $timeFrom, $timeTo) {
global $conn; global $conn;
$sth = $conn->prepare( 'select tgid, min(call_timestamp) as time, count(*), min(length), max(length), avg(length), stddev(length) from recordings $sth = $conn->prepare( 'select tgid, min(call_timestamp) as time, count(*), min(length), max(length), avg(length), stddev(length) from recordings
  where call_timestamp between to_timestamp(?) and to_timestamp(?)
group by tgid, date_trunc(\'hour\', call_timestamp) order by time'); group by tgid, date_trunc(\'hour\', call_timestamp) order by time');
   
$sth->execute( ); $sth->execute(Array($timeFrom, $timeTo));
//Array($TGID, $timeFrom, $timeTo)  
return $sth->fetchAll(); return $sth->fetchAll();
   
   
} }
   
function getTGIDValuesByDay($TGID, $dayFrom, $dayTo) { function getTGIDValuesByDay($TGID, $dayFrom, $dayTo) {
global $conn; global $conn;
$sth = $conn->prepare('select min(time) as time, min(value), max(value), avg(value), stddev(value) from sensor_values where sensor_id = ? $sth = $conn->prepare('select min(time) as time, min(value), max(value), avg(value), stddev(value) from sensor_values where sensor_id = ?
group by sensor_id, date_trunc(\'day\', time) order by time'); group by sensor_id, date_trunc(\'day\', time) order by time');
   
$sth->execute( Array($TGID)); $sth->execute( Array($TGID));
return $sth->fetchAll(); return $sth->fetchAll();
} }
function getTGIDDataYears($TGID, $timeFrom, $timeTo) { function getTGIDDataYears($TGID, $timeFrom, $timeTo) {
global $conn; global $conn;
$sth = $conn->prepare("select distinct extract('year' from call_timestamp) as year from recordings where tgid = ? order by year"); $sth = $conn->prepare("select distinct extract('year' from call_timestamp) as year from recordings where tgid = ? order by year");
   
$sth->execute(Array($TGID)); $sth->execute(Array($TGID));
return $sth->fetchAll(); return $sth->fetchAll();
} }
   
function getTGIDDataMonths($TGID, $timeFrom, $timeTo) { function getTGIDDataMonths($TGID, $timeFrom, $timeTo) {
global $conn; global $conn;
$sth = $conn->prepare("select distinct extract('month' from call_timestamp) as month, extract('year' from call_timestamp) as year from recordings where tgid = ? order by year, month"); $sth = $conn->prepare("select distinct extract('month' from call_timestamp) as month, extract('year' from call_timestamp) as year from recordings where tgid = ? order by year, month");
   
$sth->execute(Array($TGID)); $sth->execute(Array($TGID));
return $sth->fetchAll(); return $sth->fetchAll();
} }
   
function getTGIDDataDays($TGID, $timeFrom, $timeTo) { function getTGIDDataDays($TGID, $timeFrom, $timeTo) {
global $conn; global $conn;
$sth = $conn->prepare("select distinct extract('day' from call_timestamp) as day, extract('month' from call_timestamp) as month, extract('year' from call_timestamp) as year from recordings where tgid = ? order by year,month,day"); $sth = $conn->prepare("select distinct extract('day' from call_timestamp) as day, extract('month' from call_timestamp) as month, extract('year' from call_timestamp) as year from recordings where tgid = ? order by year,month,day");
   
   
$sth->execute(Array($TGID)); $sth->execute(Array($TGID));
return $sth->fetchAll(); return $sth->fetchAll();
} }
$action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : ''); $action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : '');
$TGID = (isset($_REQUEST['tgid']) ? $_REQUEST['tgid'] : ''); $TGID = (isset($_REQUEST['tgid']) ? $_REQUEST['tgid'] : '');
$timefrom = (isset($_REQUEST['from']) ? $_REQUEST['from'] : ''); $timefrom = (isset($_REQUEST['from']) ? $_REQUEST['from'] : '');
$timeto = (isset($_REQUEST['to']) ? $_REQUEST['to'] : ''); $timeto = (isset($_REQUEST['to']) ? $_REQUEST['to'] : '');
   
if ($action == "data_description") { if ($action == "data_description") {
$timefrom = strtotime($timefrom); $timefrom = strtotime($timefrom);
$timeto = strtotime($timeto); $timeto = strtotime($timeto);
$years = getTGIDDataYears($TGID, $timefrom, $timeto); $years = getTGIDDataYears($TGID, $timefrom, $timeto);
   
$months = getTGIDDataMonths($TGID, $timefrom, $timeto); $months = getTGIDDataMonths($TGID, $timefrom, $timeto);
$days = getTGIDDataDays($TGID, $timefrom, $timeto); $days = getTGIDDataDays($TGID, $timefrom, $timeto);
   
echo json_encode(Array("years" => $years, "months" => $months, "days" => $days echo json_encode(Array("years" => $years, "months" => $months, "days" => $days
)); ));
} }
   
   
if (strpos($action,"graph") !== false) { if (strpos($action,"graph") !== false) {
$values = getTGIDValuesByHour($TGID, $timefrom, $timeto); $values = getTGIDValuesByHour($TGID, $timefrom, $timeto);
$label = $TGID; $label = $TGID;
$data = Array(); $data = Array();
$tzoffset = get_timezone_offset("UTC"); $tzoffset = get_timezone_offset("UTC");
foreach ($values as $value) { foreach ($values as $value) {
if ($action == "graphlength") { if ($action == "graphlength") {
$data[$value['tgid']][] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['avg'])); $data[$value['tgid']][] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['avg']));
} else if ($action == "graphcount") { } else if ($action == "graphcount") {
$data[$value['tgid']][] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['count'])); $data[$value['tgid']][] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['count']));
} }
} }
echo json_encode(Array("label" => $label, "data" => $data, echo json_encode(Array("label" => $label, "data" => $data,
"previous" => Array( "previous" => Array(
"from" => $timefrom - (24 * 60 * 60), "from" => $timefrom - (24 * 60 * 60),
"to" => $timefrom) "to" => $timefrom)
, ,
"next" => Array( "next" => Array(
"to" => $timeto + (24 * 60 * 60), "to" => $timeto + (24 * 60 * 60),
"from" => $timeto) "from" => $timeto)
) )
); );
} }
   
   
   
?> ?>
   
<?php <?php
include('common.inc.php'); include('common.inc.php');
$sth = $conn->prepare( 'select * from recordings limit 100;'); $sth = $conn->prepare( 'select * from recordings limit 100;');
   
$sth->execute( ); $sth->execute( );
$recordings = $sth->fetchAll(); $recordings = $sth->fetchAll();
$convos = Array(); $convos = Array();
$convo = Array(); $convo = Array();
foreach ($recordings as $i => $recording) { foreach ($recordings as $i => $recording) {
   
if (count($convo) > 0 && strcasecmp($convo[count($convos)]['tgid'], $recording['tgid']) != 0) { if (count($convo) > 0) {
  echo "<br> ".strcasecmp($convos[count($convos)-1][0]['call_timestamp'],$recording['call_timestamp']);
  if (abs(strcasecmp($convos[count($convos)-1][0]['call_timestamp'],$recording['call_timestamp'])) > 2) {
  echo " ".$convos[count($convos)-1][0]['call_timestamp']." ".$recording['call_timestamp'];
  }
  if (strcasecmp($convos[count($convos)-1][0]['tgid'], $recording['tgid']) != 0 ) {
$convos[] = $convo; $convos[] = $convo;
$convo = Array(); $convo = Array();
  }
} ; } ;
//print_r($recording); //print_r($recording);
$convo[] = $recording; $convo[] = $recording;
//print_r($convo); //print_r($convo);
echo "<br>\n"; //echo "<br>\n";
} }
foreach ($convos as $i => $convo) { foreach ($convos as $i => $convo) {
print_r($convo); foreach($convo as $recording) {
echo "<br>\n"; echo $recording['filename']." , ";
  }
  echo "<br><hr>\n";
} }
?> ?>
   
   
file:b/getfile.php (new)
  <?php
  $reqfile = "path/to/file.3gp";
  $contenttype="audio/3gpp";
 
  if($fn=fopen($reqfile, "rba")){
  header("Content-Type: ".$contenttype);
  header("Content-Length: ".filesize($reqfile));
  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  header("Pragma: no-cache");
  header("Expires: Mon, 26 Jul 1997 06:00:00 GMT");
  header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
  passthru("ffmpeg -i 2012-09-29-1348911268.34-demo.wav -ar 8000 -ab 4.75k -");
  fpassthru($fn);
  fclose($fn);
  }else{
  exit("error....");
  }
  exit();
  ?>
 
// ============== Formatting extensions ============================ // ============== Formatting extensions ============================
// A common storage for all mode-specific formatting features // A common storage for all mode-specific formatting features
if (!CodeMirror.modeExtensions) CodeMirror.modeExtensions = {}; if (!CodeMirror.modeExtensions) CodeMirror.modeExtensions = {};
   
// Returns the extension of the editor's current mode // Returns the extension of the editor's current mode
CodeMirror.defineExtension("getModeExt", function () { CodeMirror.defineExtension("getModeExt", function () {
return CodeMirror.modeExtensions[this.getOption("mode")]; return CodeMirror.modeExtensions[this.getOption("mode")];
}); });
   
// If the current mode is 'htmlmixed', returns the extension of a mode located at // If the current mode is 'htmlmixed', returns the extension of a mode located at
// the specified position (can be htmlmixed, css or javascript). Otherwise, simply // the specified position (can be htmlmixed, css or javascript). Otherwise, simply
// returns the extension of the editor's current mode. // returns the extension of the editor's current mode.
CodeMirror.defineExtension("getModeExtAtPos", function (pos) { CodeMirror.defineExtension("getModeExtAtPos", function (pos) {
var token = this.getTokenAt(pos); var token = this.getTokenAt(pos);
if (token && token.state && token.state.mode) if (token && token.state && token.state.mode)
return CodeMirror.modeExtensions[token.state.mode == "html" ? "htmlmixed" : token.state.mode]; return CodeMirror.modeExtensions[token.state.mode == "html" ? "htmlmixed" : token.state.mode];
else else
return this.getModeExt(); return this.getModeExt();
}); });
   
// Comment/uncomment the specified range // Comment/uncomment the specified range
CodeMirror.defineExtension("commentRange", function (isComment, from, to) { CodeMirror.defineExtension("commentRange", function (isComment, from, to) {
var curMode = this.getModeExtAtPos(this.getCursor()); var curMode = this.getModeExtAtPos(this.getCursor());
if (isComment) { // Comment range if (isComment) { // Comment range
var commentedText = this.getRange(from, to); var commentedText = this.getRange(from, to);
this.replaceRange(curMode.commentStart + this.getRange(from, to) + curMode.commentEnd this.replaceRange(curMode.commentStart + this.getRange(from, to) + curMode.commentEnd
, from, to); , from, to);
if (from.line == to.line && from.ch == to.ch) { // An empty comment inserted - put cursor inside if (from.line == to.line && from.ch == to.ch) { // An empty comment inserted - put cursor inside
this.setCursor(from.line, from.ch + curMode.commentStart.length); this.setCursor(from.line, from.ch + curMode.commentStart.length);
} }
} }
else { // Uncomment range else { // Uncomment range
var selText = this.getRange(from, to); var selText = this.getRange(from, to);
var startIndex = selText.indexOf(curMode.commentStart); var startIndex = selText.indexOf(curMode.commentStart);
var endIndex = selText.lastIndexOf(curMode.commentEnd); var endIndex = selText.lastIndexOf(curMode.commentEnd);
if (startIndex > -1 && endIndex > -1 && endIndex > startIndex) { if (startIndex > -1 && endIndex > -1 && endIndex > startIndex) {
// Take string till comment start // Take string till comment start
selText = selText.substr(0, startIndex) selText = selText.substr(0, startIndex)
// From comment start till comment end // From comment start till comment end
+ selText.substring(startIndex + curMode.commentStart.length, endIndex) + selText.substring(startIndex + curMode.commentStart.length, endIndex)
// From comment end till string end // From comment end till string end
+ selText.substr(endIndex + curMode.commentEnd.length); + selText.substr(endIndex + curMode.commentEnd.length);
} }
this.replaceRange(selText, from, to); this.replaceRange(selText, from, to);
} }
}); });
   
// Applies automatic mode-aware indentation to the specified range // Applies automatic mode-aware indentation to the specified range
CodeMirror.defineExtension("autoIndentRange", function (from, to) { CodeMirror.defineExtension("autoIndentRange", function (from, to) {
var cmInstance = this; var cmInstance = this;
this.operation(function () { this.operation(function () {
for (var i = from.line; i <= to.line; i++) { for (var i = from.line; i <= to.line; i++) {
cmInstance.indentLine(i); cmInstance.indentLine(i);
} }
}); });
}); });
   
// Applies automatic formatting to the specified range // Applies automatic formatting to the specified range
CodeMirror.defineExtension("autoFormatRange", function (from, to) { CodeMirror.defineExtension("autoFormatRange", function (from, to) {
var absStart = this.indexFromPos(from); var absStart = this.indexFromPos(from);
var absEnd = this.indexFromPos(to); var absEnd = this.indexFromPos(to);
// Insert additional line breaks where necessary according to the // Insert additional line breaks where necessary according to the
// mode's syntax // mode's syntax
var res = this.getModeExt().autoFormatLineBreaks(this.getValue(), absStart, absEnd); var res = this.getModeExt().autoFormatLineBreaks(this.getValue(), absStart, absEnd);
var cmInstance = this; var cmInstance = this;
   
// Replace and auto-indent the range // Replace and auto-indent the range
this.operation(function () { this.operation(function () {
cmInstance.replaceRange(res, from, to); cmInstance.replaceRange(res, from, to);
var startLine = cmInstance.posFromIndex(absStart).line; var startLine = cmInstance.posFromIndex(absStart).line;
var endLine = cmInstance.posFromIndex(absStart + res.length).line; var endLine = cmInstance.posFromIndex(absStart + res.length).line;
for (var i = startLine; i <= endLine; i++) { for (var i = startLine; i <= endLine; i++) {
cmInstance.indentLine(i); cmInstance.indentLine(i);
} }
}); });
}); });
   
// Define extensions for a few modes // Define extensions for a few modes
   
CodeMirror.modeExtensions["css"] = { CodeMirror.modeExtensions["css"] = {
commentStart: "/*", commentStart: "/*",
commentEnd: "*/", commentEnd: "*/",
wordWrapChars: [";", "\\{", "\\}"], wordWrapChars: [";", "\\{", "\\}"],
autoFormatLineBreaks: function (text) { autoFormatLineBreaks: function (text) {
return text.replace(new RegExp("(;|\\{|\\})([^\r\n])", "g"), "$1\n$2"); return text.replace(new RegExp("(;|\\{|\\})([^\r\n])", "g"), "$1\n$2");
} }
}; };
   
CodeMirror.modeExtensions["javascript"] = { CodeMirror.modeExtensions["javascript"] = {
commentStart: "/*", commentStart: "/*",
commentEnd: "*/", commentEnd: "*/",
wordWrapChars: [";", "\\{", "\\}"], wordWrapChars: [";", "\\{", "\\}"],
   
getNonBreakableBlocks: function (text) { getNonBreakableBlocks: function (text) {
var nonBreakableRegexes = [ var nonBreakableRegexes = [
new RegExp("for\\s*?\\(([\\s\\S]*?)\\)"), new RegExp("for\\s*?\\(([\\s\\S]*?)\\)"),
new RegExp("'([\\s\\S]*?)('|$)"), new RegExp("'([\\s\\S]*?)('|$)"),
new RegExp("\"([\\s\\S]*?)(\"|$)"), new RegExp("\"([\\s\\S]*?)(\"|$)"),
new RegExp("//.*([\r\n]|$)") new RegExp("//.*([\r\n]|$)")
]; ];
var nonBreakableBlocks = new Array(); var nonBreakableBlocks = new Array();
for (var i = 0; i < nonBreakableRegexes.length; i++) { for (var i = 0; i < nonBreakableRegexes.length; i++) {
var curPos = 0; var curPos = 0;
while (curPos < text.length) { while (curPos < text.length) {
var m = text.substr(curPos).match(nonBreakableRegexes[i]); var m = text.substr(curPos).match(nonBreakableRegexes[i]);
if (m != null) { if (m != null) {
nonBreakableBlocks.push({ nonBreakableBlocks.push({
start: curPos + m.index, start: curPos + m.index,
end: curPos + m.index + m[0].length end: curPos + m.index + m[0].length
}); });
curPos += m.index + Math.max(1, m[0].length); curPos += m.index + Math.max(1, m[0].length);
} }
else { // No more matches else { // No more matches
break; break;
} }
} }
} }
nonBreakableBlocks.sort(function (a, b) { nonBreakableBlocks.sort(function (a, b) {
return a.start - b.start; return a.start - b.start;
}); });
   
return nonBreakableBlocks; return nonBreakableBlocks;
}, },
   
autoFormatLineBreaks: function (text) { autoFormatLineBreaks: function (text) {
var curPos = 0; var curPos = 0;
var reLinesSplitter = new RegExp("(;|\\{|\\})([^\r\n])", "g"); var reLinesSplitter = new RegExp("(;|\\{|\\})([^\r\n])", "g");
var nonBreakableBlocks = this.getNonBreakableBlocks(text); var nonBreakableBlocks = this.getNonBreakableBlocks(text);
if (nonBreakableBlocks != null) { if (nonBreakableBlocks != null) {
var res = ""; var res = "";
for (var i = 0; i < nonBreakableBlocks.length; i++) { for (var i = 0; i < nonBreakableBlocks.length; i++) {
if (nonBreakableBlocks[i].start > curPos) { // Break lines till the block if (nonBreakableBlocks[i].start > curPos) { // Break lines till the block
res += text.substring(curPos, nonBreakableBlocks[i].start).replace(reLinesSplitter, "$1\n$2"); res += text.substring(curPos, nonBreakableBlocks[i].start).replace(reLinesSplitter, "$1\n$2");
curPos = nonBreakableBlocks[i].start; curPos = nonBreakableBlocks[i].start;
} }
if (nonBreakableBlocks[i].start <= curPos if (nonBreakableBlocks[i].start <= curPos
&& nonBreakableBlocks[i].end >= curPos) { // Skip non-breakable block && nonBreakableBlocks[i].end >= curPos) { // Skip non-breakable block
res += text.substring(curPos, nonBreakableBlocks[i].end); res += text.substring(curPos, nonBreakableBlocks[i].end);
curPos = nonBreakableBlocks[i].end; curPos = nonBreakableBlocks[i].end;
} }
} }
if (curPos < text.length - 1) { if (curPos < text.length - 1) {
res += text.substr(curPos).replace(reLinesSplitter, "$1\n$2"); res += text.substr(curPos).replace(reLinesSplitter, "$1\n$2");
} }
return res; return res;
} }
else { else {
return text.replace(reLinesSplitter, "$1\n$2"); return text.replace(reLinesSplitter, "$1\n$2");
} }
} }
}; };
   
CodeMirror.modeExtensions["xml"] = { CodeMirror.modeExtensions["xml"] = {
commentStart: "<!--", commentStart: "<!--",
commentEnd: "-->", commentEnd: "-->",
wordWrapChars: [">"], wordWrapChars: [">"],
   
autoFormatLineBreaks: function (text) { autoFormatLineBreaks: function (text) {
var lines = text.split("\n"); var lines = text.split("\n");
var reProcessedPortion = new RegExp("(^\\s*?<|^[^<]*?)(.+)(>\\s*?$|[^>]*?$)"); var reProcessedPortion = new RegExp("(^\\s*?<|^[^<]*?)(.+)(>\\s*?$|[^>]*?$)");
var reOpenBrackets = new RegExp("<", "g"); var reOpenBrackets = new RegExp("<", "g");
var reCloseBrackets = new RegExp("(>)([^\r\n])", "g"); var reCloseBrackets = new RegExp("(>)([^\r\n])", "g");
for (var i = 0; i < lines.length; i++) { for (var i = 0; i < lines.length; i++) {
var mToProcess = lines[i].match(reProcessedPortion); var mToProcess = lines[i].match(reProcessedPortion);
if (mToProcess != null && mToProcess.length > 3) { // The line starts with whitespaces and ends with whitespaces if (mToProcess != null && mToProcess.length > 3) { // The line starts with whitespaces and ends with whitespaces
lines[i] = mToProcess[1] lines[i] = mToProcess[1]
+ mToProcess[2].replace(reOpenBrackets, "\n$&").replace(reCloseBrackets, "$1\n$2") + mToProcess[2].replace(reOpenBrackets, "\n$&").replace(reCloseBrackets, "$1\n$2")
+ mToProcess[3]; + mToProcess[3];
continue; continue;
} }
} }
   
return lines.join("\n"); return lines.join("\n");
} }
}; };
   
CodeMirror.modeExtensions["htmlmixed"] = { CodeMirror.modeExtensions["htmlmixed"] = {
commentStart: "<!--", commentStart: "<!--",
commentEnd: "-->", commentEnd: "-->",