diff --git a/app/fax/app_config.php b/app/fax/app_config.php index f0bb8b4682..5150fdd6ef 100644 --- a/app/fax/app_config.php +++ b/app/fax/app_config.php @@ -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'; diff --git a/app/fax/fax_files.php b/app/fax/fax_files.php index 655c4b3f59..3b06d7a44a 100644 --- a/app/fax/fax_files.php +++ b/app/fax/fax_files.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - 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 " \n"; echo "
\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 "".$paging_controls_mini."\n"; @@ -301,6 +332,9 @@ echo "
\n"; echo "
\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 "\n"; echo "\n"; - if (permission_exists('fax_file_delete')) { + if (permission_exists('fax_file_delete') || permission_exists('fax_file_edit')) { echo " \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 "\n"; - if (permission_exists('fax_file_delete')) { + if (permission_exists('fax_file_delete') || permission_exists['fax_file_edit']) { echo " \n"; } - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; if ($_REQUEST['box'] == 'sent') { echo " \n"; } if (permission_exists('fax_download_view')) { - echo " \n"; + echo " \n"; } - echo " \n"; - echo " \n"; + echo " \n"; echo "\n"; $x++; } @@ -463,7 +504,23 @@ echo "\n"; echo "\n"; +//unbold new fax rows when clicked/downloaded + if ($_REQUEST['box'] == 'inbox') { + echo "\n"; + } + //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/fax/resources/classes/fax.php b/app/fax/resources/classes/fax.php index a49d225548..dcb05521b4 100644 --- a/app/fax/resources/classes/fax.php +++ b/app/fax/resources/classes/fax.php @@ -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 }
\n"; - echo " \n"; + echo " \n"; echo "
\n"; - echo " \n"; + echo " \n"; echo " \n"; echo " ".escape($row['fax_caller_id_name'])." ".escape(format_phone($row['fax_caller_id_number']))." ".escape($row['fax_caller_id_name'])." ".escape(format_phone($row['fax_caller_id_number']))." ".escape(format_phone($row['fax_destination']))." ".$file_name."".$file_name."".$row['fax_date_formatted']." ".$row['fax_time_formatted']." ".$row['fax_date_formatted']." ".$row['fax_time_formatted']."