Fax: Upgrade script to generate and store meta-data from existing fax files, fix Lua script to insert correct fax file path into db, JavaScript prompt corrections, adjust redirect after send to use new interface, fix delete so files on file system are removed (using path from db), fix paging and sorting on Inbox and Sent, fix TIF to PDF conversion for viewing sent/received faxes (if PDF version not present).

This commit is contained in:
Nate Jones
2015-05-09 05:22:29 +00:00
parent 771ebbdc1a
commit 95e965b108
10 changed files with 219 additions and 657 deletions
+142 -95
View File
@@ -51,13 +51,13 @@ else {
}
if (if_group("superadmin") || if_group("admin")) {
//show all fax extensions
$sql = "select * from v_fax ";
$sql = "select fax_name, fax_extension 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 = "select fax_name, fax_extension 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' ";
@@ -88,6 +88,56 @@ else {
//set the fax directory
$fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null);
//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
@@ -122,17 +172,8 @@ else {
require_once "resources/header.php";
require_once "resources/paging.php";
//show the content
echo "<div align='center'>";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
echo "<tr class='border'>\n";
echo " <td align=\"center\">\n";
echo " <br />";
//show the header
//$text['title-fax_files']
//$text['description-fax_file']
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td align='left' valign='top'>\n";
if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) {
@@ -159,7 +200,6 @@ else {
if ($_REQUEST['box'] == 'sent') {
$sql .= "and fax_mode = 'tx' ";
}
if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
@@ -173,12 +213,12 @@ else {
}
//prepare to page the results
$rows_per_page = 10;
$param = "";
$rows_per_page = 50;
$param = "&id=".$_GET['id']."&box=".$_GET['box']."&order_by=".$_GET['order_by']."&order=".$_GET['order'];
$page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
$offset = $rows_per_page * $page;
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
$offset = $rows_per_page * $page;
//get the list
$sql = "select * from v_fax_files ";
@@ -190,7 +230,7 @@ else {
if ($_REQUEST['box'] == 'sent') {
$sql .= "and fax_mode = 'tx' ";
}
if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
$sql .= "order by ".((strlen($order_by) > 0) ? $order_by.' '.$order : "fax_date desc")." ";
$sql .= "limit $rows_per_page offset $offset ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
@@ -203,21 +243,18 @@ else {
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
echo "<div align='center'>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo th_order_by('fax_caller_id_name', $text['label-fax_caller_id_name'], $order_by, $order, "&id=".$_GET['id']."&box=".$_GET['box']."&page=".$_GET['page']);
echo th_order_by('fax_caller_id_number', $text['label-fax_caller_id_number'], $order_by, $order, "&id=".$_GET['id']."&box=".$_GET['box']."&page=".$_GET['page']);
if ($_REQUEST['box'] == 'sent') {
echo th_order_by('fax_destination', $text['label-fax_destination'], $order_by, $order, "&id=".$_GET['id']."&box=".$_GET['box']."&page=".$_GET['page']);
}
echo "<th width=''>".$text['table-file']."</th>\n";
echo "<th width='10%'>".$text['table-view']."</th>\n";
echo th_order_by('fax_number', $text['label-fax_number'], $order_by, $order);
//echo th_order_by('fax_file_type', $text['label-fax_file_type'], $order_by, $order);
//echo th_order_by('fax_file_path', $text['label-fax_file_path'], $order_by, $order);
echo th_order_by('fax_caller_id_name', $text['label-fax_caller_id_name'], $order_by, $order);
echo th_order_by('fax_caller_id_number', $text['label-fax_caller_id_number'], $order_by, $order);
echo th_order_by('fax_date', $text['label-fax_date'], $order_by, $order);
//echo th_order_by('fax_epoch', $text['label-fax_epoch'], $order_by, $order);
//echo th_order_by('fax_base64', $text['label-fax_base64'], $order_by, $order);
echo "<td>&nbsp;</td>\n";
echo "<tr>\n";
echo th_order_by('fax_date', $text['label-fax_date'], $order_by, $order, "&id=".$_GET['id']."&box=".$_GET['box']."&page=".$_GET['page']);
echo "<td style='width: 25px;' class='list_control_icons'>&nbsp;</td>\n";
echo "</tr>\n";
if ($result_count > 0) {
foreach($result as $row) {
$file = basename($row['fax_file_path']);
@@ -239,43 +276,85 @@ else {
file_put_contents($dir_fax_sent.'/'.$file, base64_decode($row['fax_base64']));
}
}
}
//convert the tif to pdf
if (!file_exists($dir_fax_inbox.'/'.$file_name.".pdf")) {
if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) {
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 ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) {
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");
}
}
}
echo "<tr ".$tr_link.">\n";
echo "<tr>\n";
echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
//convert the tif to pdf
unset($dir_fax);
if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) {
echo " <a href=\"fax_box.php?id=".$fax_uuid."&a=download&type=fax_inbox&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file)."\">\n";
if (!file_exists($dir_fax_inbox.'/'.$file_name.".pdf")) {
$dir_fax = $dir_fax_inbox;
}
}
if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) {
echo " <a href=\"fax_box.php?id=".$fax_uuid."&a=download&type=fax_sent&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file)."\">\n";
if (!file_exists($dir_fax_sent.'/'.$file_name.".pdf")) {
$dir_fax = $dir_fax_sent;
}
}
if ($dir_fax != '') {
chdir($dir_fax);
//get fax resolution (ppi, W & H)
$resp = exec("tiffinfo ".$file_name.".tif | grep 'Resolution:'");
$resp_array = explode(' ', trim($resp));
$ppi_w = (int) $resp_array[1];
$ppi_h = (int) $resp_array[2];
unset($resp_array);
$gs_r = $ppi_w.'x'.$ppi_h; //used by ghostscript
//get page dimensions/size (pixels/inches, W & H)
$resp = exec("tiffinfo ".$file_name.".tif | grep 'Image Width:'");
$resp_array = explode(' ', trim($resp));
$pix_w = $resp_array[2];
$pix_h = $resp_array[5];
unset($resp_array);
$gs_g = $pix_w.'x'.$pix_h; //used by ghostscript
$page_width = $pix_w / $ppi_w;
$page_height = $pix_h / $ppi_h;
if ($page_width > 8.4 && $page_height > 13) {
$page_width = 8.5;
$page_height = 14;
$page_size = 'legal';
}
else if ($page_width > 8.4 && $page_height < 12) {
$page_width = 8.5;
$page_height = 11;
$page_size = 'letter';
}
else if ($page_width < 8.4 && $page_height > 11) {
$page_width = 8.3;
$page_height = 11.7;
$page_size = 'a4';
}
//generate pdf (a work around, as tiff2pdf improperly inverts the colors)
$cmd_tif2pdf = "tiff2pdf -i -u i -p ".$page_size." -w ".$page_width." -l ".$page_height." -f -o ".$dir_fax_temp.'/'.$file_name.".pdf ".$dir_fax.'/'.$file_name.".tif";
//echo $cmd_tif2pdf."<br>";
exec($cmd_tif2pdf);
chdir($dir_fax_temp);
$cmd_pdf2tif = "gs -q -sDEVICE=tiffg3 -r".$gs_r." -g".$gs_g." -dNOPAUSE -sOutputFile=".$file_name."_temp.tif -- ".$file_name.".pdf -c quit";
//echo $cmd_pdf2tif."<br>";
exec($cmd_pdf2tif); //convert pdf to tif
@unlink($dir_fax_temp.'/'.$file_name.".pdf");
$cmd_tif2pdf = "tiff2pdf -i -u i -p ".$page_size." -w ".$page_width." -l ".$page_height." -f -o ".$dir_fax.'/'.$file_name.".pdf ".$dir_fax_temp.'/'.$file_name."_temp.tif";
//echo $cmd_tif2pdf."<br>";
exec($cmd_tif2pdf);
@unlink($dir_fax_temp.'/'.$file_name."_temp.tif");
}
echo "</td></tr>";
echo "<tr ".$tr_link.">\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['fax_caller_id_name']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".format_phone($row['fax_caller_id_number'])."&nbsp;</td>\n";
if ($_REQUEST['box'] == 'sent') {
echo " <td valign='top' class='".$row_style[$c]."'>".format_phone($row['fax_destination'])."&nbsp;</td>\n";
}
echo " <td class='".$row_style[$c]."' ondblclick=\"\">\n";
if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) {
echo " <a href=\"fax_files.php?id=".$fax_uuid."&a=download&type=fax_inbox&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file)."\">\n";
}
if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) {
echo " <a href=\"fax_files.php?id=".$fax_uuid."&a=download&type=fax_sent&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";
echo " <td class='".$row_style[$c]."' ondblclick=''>\n";
if ($_REQUEST['box'] == 'inbox') {
$dir_fax = $dir_fax_inbox;
}
@@ -284,65 +363,33 @@ else {
}
if (file_exists($dir_fax.'/'.$file_name.".pdf")) {
if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) {
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 " <a href=\"fax_files.php?id=".$fax_uuid."&a=download&type=fax_inbox&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file_name).".pdf\">PDF</a>\n";
}
if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) {
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 " <a href=\"fax_files.php?id=".$fax_uuid."&a=download&type=fax_sent&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file_name).".pdf\">PDF</a>\n";
}
echo " PDF";
echo " </a>";
}
else {
echo "&nbsp;\n";
}
echo " </td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".basename($row['fax_file_path'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>PDF&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['fax_number']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['fax_file_type']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['fax_caller_id_name']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['fax_caller_id_number']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".date("F d Y H:i:s", strtotime($row['fax_date']))."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['fax_epoch']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['fax_base64']."&nbsp;</td>\n";
echo " <td>";
//if (permission_exists('fax_file_edit')) {
// echo "<a href='fax_file_edit.php?id=".$row['fax_file_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
//}
echo " <td style='width: 25px;' class='list_control_icons'>";
if (permission_exists('fax_file_delete')) {
echo "<a href='fax_file_delete.php?id=".$row['fax_file_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
}
echo " </td>\n";
echo "</tr>\n";
if ($c==0) { $c=1; } else { $c=0; }
$c = ($c) ? 0 : 1;
} //end foreach
unset($sql, $result, $row_count);
} //end if results
//show the paging controls
echo "<tr>\n";
echo "<td colspan='11' align='left'>\n";
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
echo " <td class='list_control_icons'>";
echo "&nbsp;";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "</div>";
echo "<br /><br />";
//close the table and div
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
echo "<div align='center'>".$paging_controls."</div>\n";
echo "<br /><br />";
//include the footer