Support archive of phone calls
authorJoey Schulze <joey@infodrom.org>
Sat, 12 Dec 2009 09:24:21 +0000 (10:24 +0100)
committerJoey Schulze <joey@infodrom.org>
Fri, 25 Feb 2011 17:40:22 +0000 (18:40 +0100)
index.php
phone.js
phone.php

index 579282b..7525c2a 100644 (file)
--- a/index.php
+++ b/index.php
@@ -4,7 +4,9 @@ include_once('phone.php');
 if (!empty($_POST['func'])) {
   $data = array();
   if ($_POST['func'] == 'incoming') {
-    $data['incoming'] = get_incoming();
+    $data['incoming'] = read_directory('incoming');
+  } elseif ($_POST['func'] == 'archive') {
+    $data['archive'] = read_directory('archive');
   } elseif ($_POST['func'] == 'callinfo') {
     $data = callinfo($_POST['dir'],$_POST['call']);
   }
index f69498c..42343eb 100644 (file)
--- a/phone.js
+++ b/phone.js
@@ -3,6 +3,7 @@ function page_init()
     var frame = document.getElementById('phonecall');
     frame.src = '';
     fetch_incoming();
+    fetch_archive();
 }
 
 function fetch_incoming_callback(data)
@@ -42,6 +43,43 @@ function fetch_incoming()
     ajax_request('incoming', '', fetch_incoming_callback);
 }
 
+function fetch_archive_callback(data)
+{
+    var calls = document.getElementById('archive_calls');
+    var div = document.getElementById('archive');
+
+    while (calls.childNodes.length > 0)
+       calls.removeChild(calls.childNodes[0]);
+
+    if (data.archive.length > 0) {
+       div.style.display = '';
+
+       for (var i=0; i < data.archive.length; i++) {
+           var elem = document.createElement('li');
+           var text = data.archive[i].date + ', ';
+           if (data.archive[i].name == '*** Unknown ***' && data.archive[i].number != '0')
+               text += data.archive[i].number;
+           else
+               text += data.archive[i].name;
+           text += ', ' + data.archive[i].length;
+
+           elem.innerHTML = text;
+           elem.payload = new Array();
+           elem.payload['dir'] = 'archive';
+           elem.payload['fname'] = data.archive[i].fname;
+           elem.onclick = play_message;
+           calls.appendChild(elem);
+       }
+    } else {
+       div.style.display = 'none';
+    }
+}
+
+function fetch_archive()
+{
+    ajax_request('archive', '', fetch_archive_callback);
+}
+
 function play_message_callback(data)
 {
     var speaker = document.getElementById('callspeaker');
index c8f7381..9258c9f 100644 (file)
--- a/phone.php
+++ b/phone.php
@@ -54,11 +54,11 @@ function message_info($dir,$fname)
   return $info;
 }
 
-function get_incoming()
+function read_directory($directory)
 {
   $result = array();
 
-  if ($dir = opendir(SPOOL_DIR . '/incoming')) {
+  if ($dir = opendir(SPOOL_DIR . '/' . $directory)) {
     while (($filename = readdir($dir)) !== false) {
       if (($pos = strpos($filename, '.vmsg')) !== false) {
        $fname = substr($filename,0,$pos);