476 lines
17 KiB
PHP
476 lines
17 KiB
PHP
<?php
|
|
/*
|
|
FusionPBX
|
|
Version: MPL 1.1
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
the License. You may obtain a copy of the License at
|
|
http://www.mozilla.org/MPL/
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
for the specific language governing rights and limitations under the
|
|
License.
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
The Initial Developer of the Original Code is
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2012
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
Contributor(s):
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
James Rose <james.o.rose@gmail.com>
|
|
*/
|
|
include "root.php";
|
|
require_once "resources/require.php";
|
|
require_once "resources/check_auth.php";
|
|
if (permission_exists('fax_extension_view')) {
|
|
//access granted
|
|
}
|
|
else {
|
|
echo "access denied";
|
|
exit;
|
|
}
|
|
|
|
//add multi-lingual support
|
|
$language = new text;
|
|
$text = $language->get();
|
|
|
|
//get the fax_extension and save it as a variable
|
|
if (strlen($_REQUEST["fax_extension"]) > 0) {
|
|
$fax_extension = check_str($_REQUEST["fax_extension"]);
|
|
}
|
|
|
|
//get fax extension
|
|
if (strlen($_GET['id']) > 0) {
|
|
$fax_uuid = check_str($_GET["id"]);
|
|
if (if_group("superadmin") || if_group("admin")) {
|
|
//show all fax extensions
|
|
$sql = "select * from v_fax ";
|
|
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
|
$sql .= "and fax_uuid = '$fax_uuid' ";
|
|
}
|
|
else {
|
|
//show only assigned fax extensions
|
|
$sql = "select * from v_fax as f, v_fax_users as u ";
|
|
$sql .= "where f.fax_uuid = u.fax_uuid ";
|
|
$sql .= "and f.domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
|
$sql .= "and f.fax_uuid = '$fax_uuid' ";
|
|
$sql .= "and u.user_uuid = '".$_SESSION['user_uuid']."' ";
|
|
}
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
$prep_statement->execute();
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
if (count($result) == 0) {
|
|
if (if_group("superadmin") || if_group("admin")) {
|
|
//allow access
|
|
}
|
|
else {
|
|
echo "access denied";
|
|
exit;
|
|
}
|
|
}
|
|
foreach ($result as &$row) {
|
|
//set database fields as variables
|
|
$fax_name = $row["fax_name"];
|
|
$fax_extension = $row["fax_extension"];
|
|
//limit to one row
|
|
break;
|
|
}
|
|
unset ($prep_statement);
|
|
}
|
|
|
|
//set the fax directory
|
|
$fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null);
|
|
|
|
//delete a fax
|
|
if ($_GET['a'] == "del") {
|
|
$file_name = substr(check_str($_GET['filename']), 0, -4);
|
|
$file_ext = substr(check_str($_GET['filename']), -3);
|
|
if ($_GET['type'] == "fax_inbox" && permission_exists('fax_inbox_delete')) {
|
|
unlink($fax_dir.'/'.$fax_extension.'/inbox/'.$file_name.".tif");
|
|
unlink($fax_dir.'/'.$fax_extension.'/inbox/'.$file_name.".pdf");
|
|
$box = 'inbox';
|
|
}
|
|
if ($_GET['type'] == "fax_sent" && permission_exists('fax_sent_delete')) {
|
|
unlink($fax_dir.'/'.$fax_extension.'/sent/'.$file_name.".tif");
|
|
unlink($fax_dir.'/'.$fax_extension.'/sent/'.$file_name.".pdf");
|
|
$box = 'sent';
|
|
}
|
|
unset($file_name);
|
|
unset($file_ext);
|
|
|
|
$_SESSION["message"] = $text['confirm-delete'];
|
|
header("Location: fax_box.php?id=".$fax_uuid."&box=".$box);
|
|
exit;
|
|
}
|
|
|
|
//download the fax
|
|
if ($_GET['a'] == "download") {
|
|
session_cache_limiter('public');
|
|
//test to see if it is in the inbox or sent directory.
|
|
if ($_GET['type'] == "fax_inbox") {
|
|
if (file_exists($fax_dir.'/'.check_str($_GET['ext']).'/inbox/'.check_str($_GET['filename']))) {
|
|
$tmp_faxdownload_file = $fax_dir.'/'.check_str($_GET['ext']).'/inbox/'.check_str($_GET['filename']);
|
|
}
|
|
}
|
|
else if ($_GET['type'] == "fax_sent") {
|
|
if (file_exists($fax_dir.'/'.check_str($_GET['ext']).'/sent/'.check_str($_GET['filename']))) {
|
|
$tmp_faxdownload_file = $fax_dir.'/'.check_str($_GET['ext']).'/sent/'.check_str($_GET['filename']);
|
|
}
|
|
}
|
|
//let's see if we found it.
|
|
if (strlen($tmp_faxdownload_file) > 0) {
|
|
$fd = fopen($tmp_faxdownload_file, "rb");
|
|
if ($_GET['t'] == "bin") {
|
|
header("Content-Type: application/force-download");
|
|
header("Content-Type: application/octet-stream");
|
|
header("Content-Description: File Transfer");
|
|
header('Content-Disposition: attachment; filename="'.check_str($_GET['filename']).'"');
|
|
}
|
|
else {
|
|
$file_ext = substr(check_str($_GET['filename']), -3);
|
|
if ($file_ext == "tif") {
|
|
header("Content-Type: image/tiff");
|
|
}
|
|
else if ($file_ext == "png") {
|
|
header("Content-Type: image/png");
|
|
}
|
|
else if ($file_ext == "jpg") {
|
|
header('Content-Type: image/jpeg');
|
|
}
|
|
else if ($file_ext == "pdf") {
|
|
header("Content-Type: application/pdf");
|
|
}
|
|
}
|
|
header('Accept-Ranges: bytes');
|
|
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
|
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // date in the past
|
|
header("Content-Length: " . filesize($tmp_faxdownload_file));
|
|
fpassthru($fd);
|
|
}
|
|
else {
|
|
echo "".$text['label-file']."";
|
|
}
|
|
exit;
|
|
}
|
|
|
|
//get the fax extension
|
|
if (strlen($fax_extension) > 0) {
|
|
//set the fax directories. example /usr/local/freeswitch/storage/fax/329/inbox
|
|
$dir_fax_inbox = $fax_dir.'/'.$fax_extension.'/inbox';
|
|
$dir_fax_sent = $fax_dir.'/'.$fax_extension.'/sent';
|
|
$dir_fax_temp = $fax_dir.'/'.$fax_extension.'/temp';
|
|
|
|
//make sure the directories exist
|
|
if (!is_dir($_SESSION['switch']['storage']['dir'])) {
|
|
mkdir($_SESSION['switch']['storage']['dir']);
|
|
chmod($dir_fax_sent,0774);
|
|
}
|
|
if (!is_dir($fax_dir.'/'.$fax_extension)) {
|
|
mkdir($fax_dir.'/'.$fax_extension,0774,true);
|
|
chmod($fax_dir.'/'.$fax_extension,0774);
|
|
}
|
|
if (!is_dir($dir_fax_inbox)) {
|
|
mkdir($dir_fax_inbox,0774,true);
|
|
chmod($dir_fax_inbox,0774);
|
|
}
|
|
if (!is_dir($dir_fax_sent)) {
|
|
mkdir($dir_fax_sent,0774,true);
|
|
chmod($dir_fax_sent,0774);
|
|
}
|
|
if (!is_dir($dir_fax_temp)) {
|
|
mkdir($dir_fax_temp,0774,true);
|
|
chmod($dir_fax_temp,0774);
|
|
}
|
|
}
|
|
|
|
//show the header
|
|
require_once "resources/header.php";
|
|
|
|
//show the inbox
|
|
if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) {
|
|
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
|
|
echo " <tr>\n";
|
|
echo " <td align='left' valign='top'>\n";
|
|
echo " <b>".$text['header-inbox'].": <span style='color: #000;'>".$fax_name." (".$fax_extension.")</span></b>\n";
|
|
echo " </td>\n";
|
|
echo " <td width='70%' align='right' valign='top'>\n";
|
|
echo " <input type='button' class='btn' name='' alt='back' onclick=\"window.location='fax.php'\" value='".$text['button-back']."'>\n";
|
|
echo " </td>\n";
|
|
echo " </tr>\n";
|
|
echo "</table>\n";
|
|
echo "<br>\n";
|
|
|
|
$c = 0;
|
|
$row_style["0"] = "row_style0";
|
|
$row_style["1"] = "row_style1";
|
|
|
|
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
|
|
echo " <tr>\n";
|
|
echo " <th width='60%'>".$text['table-file']."</th>\n";
|
|
echo " <th width='10%'>".$text['table-view']."</th>\n";
|
|
echo " <th width='20%'>".$text['table-modified']."</th>\n";
|
|
echo " <th width='10%' nowrap>".$text['table-size']."</th>\n";
|
|
echo " </tr>";
|
|
|
|
if ($handle = opendir($dir_fax_inbox)) {
|
|
//build an array of the files in the inbox
|
|
$i = 0;
|
|
$files = array();
|
|
while (false !== ($file = readdir($handle))) {
|
|
if ($file != "." && $file != ".." && is_file($dir_fax_inbox.'/'.$file)) {
|
|
$file_path = $dir_fax_inbox.'/'.$file;
|
|
$modified = filemtime($file_path);
|
|
$index = $modified.$file;
|
|
$files[$index]['file'] = $file;
|
|
$files[$index]['name'] = substr($file, 0, -4);
|
|
$files[$index]['ext'] = substr($file, -3);
|
|
//$files[$index]['path'] = $file_path;
|
|
$files[$index]['size'] = filesize($file_path);
|
|
$files[$index]['size_bytes'] = byte_convert(filesize($file_path));
|
|
$files[$index]['modified'] = filemtime($file_path);
|
|
$file_name_array[$i++] = $index;
|
|
}
|
|
}
|
|
closedir($handle);
|
|
//order the index array
|
|
sort($file_name_array,SORT_STRING);
|
|
|
|
//loop through the file array
|
|
foreach($file_name_array as $i) {
|
|
if (strtolower($files[$i]['ext']) == "tif") {
|
|
$file = $files[$i]['file'];
|
|
$file_name = $files[$i]['name'];
|
|
$file_ext = $files[$i]['ext'];
|
|
$file_modified = $files[$i]['modified'];
|
|
$file_size_bytes = byte_convert($files[$i]['size']);
|
|
if (!file_exists($dir_fax_inbox.'/'.$file_name.".pdf")) {
|
|
//convert the tif to pdf
|
|
chdir($dir_fax_inbox);
|
|
if (is_file("/usr/local/bin/tiff2pdf")) {
|
|
exec("/usr/local/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_inbox.'/'.$file_name.".tif");
|
|
}
|
|
if (is_file("/usr/bin/tiff2pdf")) {
|
|
exec("/usr/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_inbox.'/'.$file_name.".tif");
|
|
}
|
|
}
|
|
//if (!file_exists($dir_fax_inbox.'/'.$file_name.".jpg")) {
|
|
// //convert the tif to jpg
|
|
// chdir($dir_fax_inbox);
|
|
// if (is_file("/usr/local/bin/tiff2rgba")) {
|
|
// exec("/usr/local/bin/tiff2rgba ".$file_name.".tif ".$dir_fax_inbox.'/'.$file_name.".jpg");
|
|
// }
|
|
// if (is_file("/usr/bin/tiff2rgba")) {
|
|
// exec("/usr/bin/tiff2rgba ".$file_name.".tif ".$dir_fax_inbox.'/'.$file_name.".jpg");
|
|
// }
|
|
//}
|
|
echo "<tr>\n";
|
|
echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
|
|
echo " <a href=\"fax_box.php?id=".$fax_uuid."&a=download&type=fax_inbox&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file)."\">\n";
|
|
echo " $file_name";
|
|
echo " </a>";
|
|
echo " </td>\n";
|
|
|
|
echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
|
|
if (file_exists($dir_fax_inbox.'/'.$file_name.".pdf")) {
|
|
echo " <a href=\"fax_box.php?id=".$fax_uuid."&a=download&type=fax_inbox&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file_name).".pdf\">\n";
|
|
echo " PDF";
|
|
echo " </a>";
|
|
}
|
|
else {
|
|
echo " \n";
|
|
}
|
|
echo " </td>\n";
|
|
|
|
//echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
|
|
//if (file_exists($dir_fax_inbox.'/'.$file_name.".jpg")) {
|
|
// echo " <a href=\"fax_box.php?id=".$fax_uuid."&a=download&type=fax_inbox&t=jpg&ext=".$fax_extension."&filename=".$file_name.".jpg\" target=\"_blank\">\n";
|
|
// echo " jpg";
|
|
// echo " </a>";
|
|
//}
|
|
//else {
|
|
// echo " \n";
|
|
//}
|
|
//echo " </td>\n";
|
|
|
|
echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
|
|
echo " ".date("F d Y H:i:s", $file_modified);
|
|
echo " </td>\n";
|
|
|
|
echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
|
|
echo " ".$file_size_bytes;
|
|
echo " </td>\n";
|
|
|
|
echo " <td valign=\"middle\" nowrap class=\"list\">\n";
|
|
echo " <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">\n";
|
|
echo " <tr>\n";
|
|
if (permission_exists('fax_inbox_delete')) {
|
|
echo " <td><a href=\"fax_box.php?id=".$fax_uuid."&type=fax_inbox&a=del&fax_extension=".urlencode($fax_extension)."&filename=".urlencode($file)."\" onclick=\"return confirm('".$text['message-confirm-delete']."')\">$v_link_label_delete</a></td>\n";
|
|
}
|
|
echo " </tr>\n";
|
|
echo " </table>\n";
|
|
echo " </td>\n";
|
|
echo "</tr>\n";
|
|
$c = ($c) ? 0 : 1;
|
|
}
|
|
}
|
|
}
|
|
echo " <tr>\n";
|
|
echo " <td class=\"list\" colspan=\"3\"></td>\n";
|
|
echo " <td class=\"list\"></td>\n";
|
|
echo " </tr>\n";
|
|
echo "</table>\n";
|
|
echo "<br><br><br>\n";
|
|
if (if_group('superadmin')) {
|
|
echo "<strong>".$text['label-location'].":</strong> ".$dir_fax_inbox;
|
|
}
|
|
echo "<br /><br />\n";
|
|
}
|
|
|
|
//show the sent box
|
|
if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) {
|
|
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
|
|
echo " <tr>\n";
|
|
echo " <td align='left' valign='top'>\n";
|
|
echo " <b>".$text['header-sent'].": <span style='color: #000;'>".$fax_name." (".$fax_extension.")</span></b>\n";
|
|
echo " </td>\n";
|
|
echo " <td width='70%' align='right' valign='top'>\n";
|
|
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='fax.php'\" value='".$text['button-back']."'>\n";
|
|
echo " </td>\n";
|
|
echo " </tr>\n";
|
|
echo "</table>\n";
|
|
echo "<br>\n";
|
|
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
|
|
echo " <tr>\n";
|
|
echo " <th width='60%'>".$text['table-file']."</td>\n";
|
|
echo " <th width='10%'>".$text['table-view']."</td>\n";
|
|
echo " <th width='20%'>".$text['table-modified']."</td>\n";
|
|
echo " <th width='10%' nowrap>".$text['table-size']."</td>\n";
|
|
echo " </tr>";
|
|
|
|
$c = 0;
|
|
$row_style["0"] = "row_style0";
|
|
$row_style["1"] = "row_style1";
|
|
|
|
if ($handle = opendir($dir_fax_sent)) {
|
|
//build an array of the files in the sent box
|
|
$i = 0;
|
|
$files = array();
|
|
while (false !== ($file = readdir($handle))) {
|
|
if ($file != "." && $file != ".." && is_file($dir_fax_sent.'/'.$file)) {
|
|
$file_path = $dir_fax_sent.'/'.$file;
|
|
$modified = filemtime($file_path);
|
|
$index = $modified.$file;
|
|
$files[$index]['file'] = $file;
|
|
$files[$index]['name'] = substr($file, 0, -4);
|
|
$files[$index]['ext'] = substr($file, -3);
|
|
//$files[$index]['path'] = $file_path;
|
|
$files[$index]['size'] = filesize($file_path);
|
|
$files[$index]['size_bytes'] = byte_convert(filesize($file_path));
|
|
$files[$index]['modified'] = filemtime($file_path);
|
|
$file_name_array[$i++] = $index;
|
|
}
|
|
}
|
|
closedir($handle);
|
|
//order the index array
|
|
rsort($file_name_array,SORT_STRING);
|
|
|
|
//loop through the file array
|
|
foreach($file_name_array as $i) {
|
|
if (strtolower($files[$i]['ext']) == "tif") {
|
|
$file = $files[$i]['file'];
|
|
$file_name = $files[$i]['name'];
|
|
$file_ext = $files[$i]['ext'];
|
|
$file_modified = $files[$i]['modified'];
|
|
$file_size_bytes = byte_convert($files[$i]['size']);
|
|
|
|
if (!file_exists($dir_fax_sent.'/'.$file_name.".pdf")) {
|
|
//convert the tif to pdf
|
|
chdir($dir_fax_sent);
|
|
if (is_file("/usr/local/bin/tiff2pdf")) {
|
|
exec("/usr/local/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_sent.'/'.$file_name.".tif");
|
|
}
|
|
if (is_file("/usr/bin/tiff2pdf")) {
|
|
exec("/usr/bin/tiff2pdf -f -o ".$file_name.".pdf ".$dir_fax_sent.'/'.$file_name.".tif");
|
|
}
|
|
}
|
|
if (!file_exists($dir_fax_sent.'/'.$file_name.".jpg")) {
|
|
//convert the tif to jpg
|
|
//chdir($dir_fax_sent);
|
|
//if (is_file("/usr/local/bin/tiff2rgba")) {
|
|
// exec("/usr/local/bin/tiff2rgba -c jpeg -n ".$file_name.".tif ".$dir_fax_sent.'/'.$file_name.".jpg");
|
|
//}
|
|
//if (is_file("/usr/bin/tiff2rgba")) {
|
|
// exec("/usr/bin/tiff2rgba -c lzw -n ".$file_name.".tif ".$dir_fax_sent.'/'.$file_name.".jpg");
|
|
//}
|
|
}
|
|
echo "<tr>\n";
|
|
echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
|
|
echo " <a href=\"fax_box.php?id=".$fax_uuid."&a=download&type=fax_sent&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file)."\">\n";
|
|
echo " $file";
|
|
echo " </a>";
|
|
echo " </td>\n";
|
|
echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
|
|
if (file_exists($dir_fax_sent.'/'.$file_name.".pdf")) {
|
|
echo " <a href=\"fax_box.php?id=".$fax_uuid."&a=download&type=fax_sent&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file_name).".pdf\">\n";
|
|
echo " PDF";
|
|
echo " </a>";
|
|
}
|
|
else {
|
|
echo " \n";
|
|
}
|
|
echo " </td>\n";
|
|
//echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
|
|
//if (file_exists($dir_fax_sent.'/'.$file_name.".jpg")) {
|
|
// echo " <a href=\"fax_box.php?id=".$fax_uuid."&a=download&type=fax_sent&t=jpg&ext=".$fax_extension."&filename=".$file_name.".jpg\" target=\"_blank\">\n";
|
|
// echo " jpg";
|
|
// echo " </a>";
|
|
//}
|
|
//else {
|
|
// echo " \n";
|
|
//}
|
|
//echo " </td>\n";
|
|
echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
|
|
echo " ".date("F d Y H:i:s", $file_modified);
|
|
echo " </td>\n";
|
|
|
|
echo " <td class=\"".$row_style[$c]."\" ondblclick=\"list\">\n";
|
|
echo " ".$file_size_bytes;
|
|
echo " </td>\n";
|
|
|
|
echo " <td class='' valign=\"middle\" nowrap>\n";
|
|
echo " <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">\n";
|
|
echo " <tr>\n";
|
|
if (permission_exists('fax_sent_delete')) {
|
|
echo " <td><a href=\"fax_box.php?id=".$fax_uuid."&type=fax_sent&a=del&fax_extension=".urlencode($fax_extension)."&filename=".urlencode($file)."\" onclick=\"return confirm('".$text['message-confirm-delete']."')\">$v_link_label_delete</a></td>\n";
|
|
}
|
|
echo " </tr>\n";
|
|
echo " </table>\n";
|
|
echo " </td>\n";
|
|
echo "</tr>\n";
|
|
$c = ($c) ? 0 : 1;
|
|
} //check if the file is a .tif file
|
|
}
|
|
}
|
|
echo " <tr>\n";
|
|
echo " <td class=\"list\" colspan=\"3\"></td>\n";
|
|
echo " <td class=\"list\"></td>\n";
|
|
echo " </tr>\n";
|
|
echo " </table>\n";
|
|
echo " <br><br><br>\n";
|
|
if (if_group('superadmin')) {
|
|
echo "<strong>".$text['label-location'].":</strong> ".$dir_fax_sent;
|
|
}
|
|
echo "<br /><br />\n";
|
|
}
|
|
echo " </td>";
|
|
echo " </tr>";
|
|
echo "</table>";
|
|
|
|
//show the footer
|
|
require_once "resources/footer.php";
|
|
?>
|