Portions created by the Initial Developer are Copyright (C) 2008-2012 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane James Rose */ 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 require_once "app_languages.php"; foreach($text as $key => $value) { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } //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_extension = $row["fax_extension"]; //limit to one row break; } unset ($prep_statement); } //set the fax directory if (count($_SESSION["domains"]) > 1) { $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name']; } else { $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'; } //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-Type: application/download"); 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 " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['header-inbox']." ".$fax_extension."\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; echo "
\n"; echo " \n"; echo " \n"; echo " "; 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 "\n"; echo " \n"; echo " \n"; //echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; } } } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
".$text['table-file']."\n"; echo " ".$text['table-view']."\n"; echo " ".$text['table-modified']."\n"; echo " ".$text['table-size']."\n"; echo "
\n"; echo " \n"; echo " $file_name"; echo " "; echo " \n"; if (file_exists($dir_fax_inbox.'/'.$file_name.".pdf")) { echo " \n"; echo " PDF"; echo " "; } else { echo " \n"; } echo " \n"; //if (file_exists($dir_fax_inbox.'/'.$file_name.".jpg")) { // echo " \n"; // echo " jpg"; // echo " "; //} //else { // echo " \n"; //} //echo "  \n"; echo " ".date("F d Y H:i:s", $file_modified); echo " \n"; echo " ".$file_size_bytes; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('fax_inbox_delete')) { echo " \n"; } echo " \n"; echo "
$v_link_label_delete
\n"; echo "
\n"; echo "\n"; echo "
\n"; if (if_group('superadmin')) { echo "".$text['label-location'].":  ".$dir_fax_inbox; } echo "

\n"; echo "\n"; } //show the sent box if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) { echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['header-sent']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo "\n"; echo " \n"; echo " "; $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 inbox $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 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_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 "\n"; echo " \n"; echo " \n"; //echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; if ($c==0) { $c=1; } else { $c=0; } } //check if the file is a .tif file } } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
".$text['table-file']."\n"; echo " ".$text['table-view']."\n"; echo " ".$text['table-modified']."\n"; echo " ".$text['table-size']."\n"; echo "
\n"; echo " \n"; echo " $file"; echo " "; echo " \n"; if (file_exists($dir_fax_sent.'/'.$file_name.".pdf")) { echo " \n"; echo " PDF"; echo " "; } else { echo " \n"; } echo " \n"; //if (file_exists($dir_fax_sent.'/'.$file_name.".jpg")) { // echo " \n"; // echo " jpg"; // echo " "; //} //else { // echo " \n"; //} //echo " \n"; echo " ".date("F d Y H:i:s", $file_modified); echo " \n"; echo " ".$file_size_bytes; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('fax_sent_delete')) { echo " \n"; } echo " \n"; echo "
$v_link_label_delete
\n"; echo "
\n"; echo "\n"; echo "
\n"; if (if_group('superadmin')) { echo "".$text['label-location'].":  ".$dir_fax_sent; } echo "

\n"; } echo " "; echo " "; echo ""; echo "
"; //show the footer require_once "resources/footer.php"; ?>