Sort list of phone calls
authorJoey Schulze <joey@infodrom.org>
Sat, 12 Dec 2009 10:52:46 +0000 (11:52 +0100)
committerJoey Schulze <joey@infodrom.org>
Fri, 25 Feb 2011 17:40:22 +0000 (18:40 +0100)
phone.php

index 9258c9f..660e0b6 100644 (file)
--- a/phone.php
+++ b/phone.php
@@ -54,6 +54,19 @@ function message_info($dir,$fname)
   return $info;
 }
 
+function call_cmp($a, $b)
+{
+  if (!empty($a['read']) && empty($b['read']))
+    return 1;
+  elseif (!empty($b['read']) && empty($a['read']))
+    return -1;
+  elseif ($a['timestamp'] > $b['timestamp'])
+    return -1;
+  else
+    return 1;
+  return 0;
+}
+
 function read_directory($directory)
 {
   $result = array();
@@ -69,6 +82,8 @@ function read_directory($directory)
     }
     closedir($dir);
   }
+
+  usort($result, "call_cmp");
   return $result;
 }
 
@@ -93,6 +108,12 @@ function send_call($dir, $call)
     return;
   }
 
+  $info = read_info($dir, $call);
+  if (empty($info['read'])) {
+    $info['read'] = date('U');
+    write_info($dir, $call, $info);
+  }
+
   header(sprintf('Content-disposition: inline; filename="%s.au"', $call));
   header('Content-Type: audio/basic');
   header("Cache-Control: ");