X-Git-Url: https://git.infodrom.org/?p=infodrom%2Fphone;a=blobdiff_plain;f=phone.php;h=ff8e0bd6315777315741827ea8d204aed2159fcf;hp=c8f73818d4321506489b84a8d99fa5e67498ae4c;hb=cb3e539cdc964f2cbfe1bfe2c92adbb13e946c3d;hpb=c5c7c6c010a32a1cbc281b8e9f555b3db16c7e80 diff --git a/phone.php b/phone.php index c8f7381..ff8e0bd 100644 --- 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); @@ -54,21 +56,36 @@ function message_info($dir,$fname) return $info; } -function get_incoming() +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(); - if ($dir = opendir(SPOOL_DIR . '/incoming')) { + 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; } } closedir($dir); } + + usort($result, "call_cmp"); return $result; } @@ -81,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("