Allow playing of internal messages
[infodrom/phone] / phone.php
index 660e0b6..ff8e0bd 100644 (file)
--- a/phone.php
+++ b/phone.php
@@ -4,7 +4,9 @@ define('SPOOL_DIR', '/var/spool/vbox/ttyI6');
 function read_info($dir, $call)
 {
   $info = array();
-  if (($f = fopen(SPOOL_DIR . '/' . $dir . '/' . $call . '.info', 'r')) !== false) {
+  $fname = SPOOL_DIR . '/' . $dir . '/' . $call . '.info';
+
+  if (is_file($fname) && ($f = fopen($fname, 'r')) !== false) {
     $line = fgets($f, 1024);
     fclose($f);
     $info = unserialize($line);
@@ -73,9 +75,9 @@ function read_directory($directory)
 
   if ($dir = opendir(SPOOL_DIR . '/' . $directory)) {
     while (($filename = readdir($dir)) !== false) {
-      if (($pos = strpos($filename, '.vmsg')) !== false) {
+      if (($pos = strpos($filename, '.vmsg')) !== false || ($pos = strpos($filename, '.msg')) !== false) {
        $fname = substr($filename,0,$pos);
-       $info = message_info('incoming', $fname);
+       $info = message_info($directory, $fname);
        $info['fname'] = $fname;
        $result[] = $info;
       }
@@ -96,7 +98,13 @@ function send_call($dir, $call)
 {
   $dir = str_replace('/','x',$dir);
   $call = str_replace('/','x',$call);
-  $fname = SPOOL_DIR . '/' . $dir . '/' . $call . '.vmsg';
+
+  if ($dir == 'messages')
+    $ext = '.msg';
+  else
+    $ext = '.vmsg';
+
+  $fname = SPOOL_DIR . '/' . $dir . '/' . $call . $ext;
 
   if (!is_file($fname)) {
     printf("<html><body><h3>Anruf %s in %s nicht gefunden!</h3></body></html>", $call, $dir);
@@ -124,4 +132,29 @@ function send_call($dir, $call)
   pclose($p);
 }
 
-?>
\ No newline at end of file
+function archive_call($call)
+{
+  $basename = SPOOL_DIR . '/' . 'incoming' . '/' . $call;
+  $basenew = SPOOL_DIR . '/' . 'archive' . '/' . $call;
+
+  rename($basename . '.vmsg', $basenew . '.vmsg');
+  rename($basename . '.info', $basenew . '.info');
+}
+
+function delete_call($dir, $call)
+{
+  $basename = SPOOL_DIR . '/' . $dir . '/' . $call;
+
+  unlink($basename . '.vmsg');
+  unlink($basename . '.info');
+}
+
+function save_call()
+{
+  $info = read_info($_POST['dir'], $_POST['call']);
+  $info['name'] = $_POST['name'];
+  $info['note'] = $_POST['note'];
+  write_info($_POST['dir'], $_POST['call'], $info);
+}
+
+?>