Fax Server: Implement Read/Unread Toggle.

This commit is contained in:
fusionate
2024-06-05 06:34:07 -06:00
parent fbe10bbe04
commit e61868a4ec
3 changed files with 158 additions and 28 deletions

View File

@@ -793,6 +793,12 @@
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "read_date";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'timestamptz';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'date';
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'date';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "insert_date";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'timestamptz';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'date';

View File

@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2018-2023
Portions created by the Initial Developer are Copyright (C) 2018-2024
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -60,6 +60,18 @@
//process the http post data by action
if (!empty($action) && !empty($fax_files) && is_array($fax_files) && @sizeof($fax_files) != 0) {
switch ($action) {
case 'toggle':
if (permission_exists('fax_file_edit')) {
$fax = new fax;
$fax->domain_uuid = $_SESSION['domain_uuid'];
$fax_files_toggled = $fax->fax_file_toggle($fax_files);
unset($fax, $fax_files);
if ($fax_files_toggled != 0) {
message::add($text['message-toggle'].': '.$fax_files_toggled);
}
}
break;
case 'delete':
if (permission_exists('fax_file_delete')) {
$obj = new fax;
@@ -70,7 +82,7 @@
break;
}
header('Location: fax_files.php?orderby='.$order_by.'&order='.$order.'&id='.$fax_uuid.'&box='.$box);
header('Location: fax_files.php?order_by='.$order_by.'&order='.$order.'&id='.$fax_uuid.'&box='.$box);
exit;
}
@@ -125,7 +137,7 @@
$fax_extension = preg_replace('/[^0-9]/', '', $_GET['ext']);
$fax_filename = preg_replace('/[\/\\\&\%\#]/', '', $_GET['filename']);
//check if the file is in the inbox or sent directory.
//check if the file is in the inbox or sent directory
if ($_GET['type'] == "fax_inbox") {
if (file_exists($fax_dir.'/'.$fax_extension.'/inbox/'.$fax_filename)) {
$download_filename = $fax_dir.'/'.$fax_extension.'/inbox/'.$fax_filename;
@@ -137,6 +149,19 @@
}
}
//mark fax file as read if in inbox
if ($_GET['type'] == "fax_inbox" && !empty($_GET['fax_file_uuid']) && is_uuid($_GET['fax_file_uuid'])) {
$fax_files[0] = ['checked'=>'true','uuid'=>$_GET['fax_file_uuid']];
$fax = new fax;
$fax->domain_uuid = $_SESSION['domain_uuid'];
$fax->fax_uuid = $_GET['id'] ?? '';
$fax->order_by = $_GET['order_by'] ?? '';
$fax->order = $_GET['order'] ?? '';
$fax->box = $_GET['box'] ?? '';
$fax->fax_file_toggle($fax_files);
unset($fax, $fax_files);
}
//add the headers and stream the file
if (!empty($download_filename)) {
$fd = fopen($download_filename, "rb");
@@ -249,7 +274,8 @@
$sql .= "fax_destination, fax_file_type, fax_file_path, fax_caller_id_name, \n";
$sql .= "fax_caller_id_number, fax_epoch, fax_base64, fax_date, \n";
$sql .= "to_char(timezone(:time_zone, fax_date), 'DD Mon YYYY') as fax_date_formatted, \n";
$sql .= "to_char(timezone(:time_zone, fax_date), '".$time_format."') as fax_time_formatted \n";
$sql .= "to_char(timezone(:time_zone, fax_date), '".$time_format."') as fax_time_formatted, \n";
$sql .= "to_char(timezone(:time_zone, read_date), 'YYYY-MM-DD') as read_date_formatted \n";
$sql .= "from v_fax_files \n";
$sql .= "where fax_uuid = :fax_uuid \n";
$sql .= "and domain_uuid = :domain_uuid \n";
@@ -291,8 +317,13 @@
echo " </div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'fax.php']);
$margin_left = false;
if (permission_exists('fax_file_edit') && $_REQUEST['box'] == 'inbox' && $fax_files) {
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','collapse'=>'hide-xs','style'=>'display: none; margin-left: 15px;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]);
$margin_left = true;
}
if (permission_exists('fax_file_delete') && $fax_files) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>'margin-left: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; '.(!$margin_left ? 'margin-left: 15px;' : null),'onclick'=>"modal_open('modal-delete','btn_delete');"]);
}
if ($paging_controls_mini != '') {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
@@ -301,6 +332,9 @@
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
if (permission_exists('fax_file_edit') && $_REQUEST['box'] == 'inbox' && $fax_files) {
echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]);
}
if (permission_exists('fax_file_delete') && $fax_files) {
echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
}
@@ -312,9 +346,9 @@
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
if (permission_exists('fax_file_delete')) {
if (permission_exists('fax_file_delete') || permission_exists('fax_file_edit')) {
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".(empty($fax_files) ? "style='visibility: hidden;'" : null).">\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(empty($fax_files) ? "style='visibility: hidden;'" : null).">\n";
echo " </th>\n";
}
echo th_order_by('fax_caller_id_name', $text['label-fax_caller_id_name'], $order_by, $order, "&id=".$fax_uuid."&box=".$_GET['box']."&page=".$page);
@@ -414,44 +448,51 @@
if (file_exists($dir_fax_temp.'/'.$file_name.'.tif')) { @unlink($dir_fax_temp.'/'.$file_name.'.tif'); }
}
if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) {
$list_row_url = "fax_files.php?id=".urlencode($fax_uuid)."&a=download&type=fax_inbox&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file);
}
if ($_REQUEST['box'] == 'sent' && permission_exists('fax_sent_view')) {
$list_row_url = "fax_files.php?id=".urlencode($fax_uuid)."&a=download&type=fax_sent&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file);
//set fax as bold if unread and normal font weight if read
$bold = $_REQUEST['box'] == 'inbox' && empty($row['read_date_formatted']) ? 'font-weight: bold;' : null;
$list_row_url = null;
if (permission_exists('fax_inbox_view') || permission_exists('fax_sent_view')) {
$list_row_url = "fax_files.php?id=".urlencode($fax_uuid);
$list_row_url .= "&fax_file_uuid=".urlencode($row['fax_file_uuid']);
$list_row_url .= "&a=download";
$list_row_url .= "&type=fax_".urlencode($_REQUEST['box']);
$list_row_url .= "&t=bin";
$list_row_url .= "&order_by=".urlencode($_REQUEST['order_by']);
$list_row_url .= "&order=".urlencode($_REQUEST['order']);
$list_row_url .= "&box=".urlencode($_REQUEST['box']);
$list_row_url .= "&ext=".urlencode($fax_extension);
$list_row_url .= "&".$token['name']."=".$token['hash'];
$list_row_url .= "&filename=".urlencode($file);
}
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('fax_file_delete')) {
if (permission_exists('fax_file_delete') || permission_exists['fax_file_edit']) {
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='fax_files[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='checkbox' name='fax_files[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; } checkbox_on_change(this);\">\n";
echo " <input type='hidden' name='fax_files[$x][uuid]' value='".escape($row['fax_file_uuid'])."' />\n";
echo " </td>\n";
}
echo " <td>".escape($row['fax_caller_id_name'])."&nbsp;</td>\n";
echo " <td>".escape(format_phone($row['fax_caller_id_number']))."&nbsp;</td>\n";
echo " <td style='".$bold."'>".escape($row['fax_caller_id_name'])."&nbsp;</td>\n";
echo " <td style='".$bold."'>".escape(format_phone($row['fax_caller_id_number']))."&nbsp;</td>\n";
if ($_REQUEST['box'] == 'sent') {
echo " <td>".escape(format_phone($row['fax_destination']))."&nbsp;</td>\n";
}
if (permission_exists('fax_download_view')) {
echo " <td><a href='".$list_row_url."'>".$file_name."</a></td>\n";
echo " <td style='".$bold."'><a href='".$list_row_url."'>".$file_name."</a></td>\n";
}
echo " <td class='no-link'>\n";
echo " <td class='no-link' style='".$bold."'>\n";
if ($_REQUEST['box'] == 'inbox') {
$dir_fax = $dir_fax_inbox;
}
if ($_REQUEST['box'] == 'sent') {
$dir_fax = $dir_fax_sent;
}
if (file_exists($dir_fax.'/'.$file_name.".pdf")) {
if ($_REQUEST['box'] == 'inbox' && permission_exists('fax_inbox_view')) {
echo " <a href=\"fax_files.php?id=".urlencode($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_files.php?id=".urlencode($fax_uuid)."&a=download&type=fax_sent&t=bin&ext=".urlencode($fax_extension)."&filename=".urlencode($file_name).".pdf\">PDF</a>\n";
}
if ((permission_exists('fax_inbox_view') || permission_exists('fax_sent_view')) && file_exists($dir_fax.'/'.$file_name.".pdf")) {
echo " <a href=\"".substr($list_row_url, 0, -4).".pdf\">PDF</a>\n";
}
echo " </td>\n";
echo " <td>".$row['fax_date_formatted']." ".$row['fax_time_formatted']."&nbsp;</td>\n";
echo " <td style='".$bold."'>".$row['fax_date_formatted']." ".$row['fax_time_formatted']."&nbsp;</td>\n";
echo "</tr>\n";
$x++;
}
@@ -463,7 +504,23 @@
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
//unbold new fax rows when clicked/downloaded
if ($_REQUEST['box'] == 'inbox') {
echo "<script>\n";
echo " $(document).ready(function() {\n";
echo " $('.list-row').each(function(i,e) {\n";
echo " $(e).children('td:not(.checkbox)').on('click',function() {\n";
echo " $(this).closest('tr').children('td').css('font-weight','normal');\n";
echo " });\n";
echo " $(e).children('td').children('button').on('click',function() {\n";
echo " $(this).closest('tr').children('td').css('font-weight','normal');\n";
echo " });\n";
echo " });\n";
echo " });\n";
echo "</script>\n";
}
//include the footer
require_once "resources/footer.php";
?>
?>

View File

@@ -40,7 +40,8 @@ if (!class_exists('fax')) {
public $fax_forward_number;
public $destination_number;
public $box;
private $forward_prefix;
public $order_by;
public $order;
/**
* declare private variables
@@ -53,6 +54,7 @@ if (!class_exists('fax')) {
private $uuid_prefix;
private $toggle_field;
private $toggle_values;
private $forward_prefix;
/**
* Called when the object is created
@@ -654,6 +656,71 @@ if (!class_exists('fax')) {
}
} //method
/**
* toggle read/unread
*/
public function fax_file_toggle($records) {
if (permission_exists('fax_file_edit')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: fax_files.php?order_by='.urlencode($this->order_by).'&order='.urlencode($this->order).'&id='.urlencode($this->fax_uuid).'&box='.urlencode($this->box));
exit;
}
//toggle multiple records
if (is_array($records) && @sizeof($records) != 0) {
//filter out unchecked fax files, build the toggle array
$fax_files_toggled = 0;
foreach ($records as $x => $record) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
//get current read state
$sql = "select read_date from v_fax_files where fax_file_uuid = :fax_file_uuid";
$parameters['fax_file_uuid'] = $record['uuid'];
$database = new database;
$read_date = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
//toggle read state
$array['fax_files'][$x]['fax_file_uuid'] = $record['uuid'];
$array['fax_files'][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
$array['fax_files'][$x]['read_date'] = empty($read_date) ? 'now()' : null;
$fax_files_toggled++;
}
}
unset($records);
//update the checked rows
if (!empty($array) && is_array($array)) {
//execute save
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//return toggled count
return $fax_files_toggled;
}
}
//return none
return 0;
}
}
} //class
}