diff --git a/app/fax/fax_send.php b/app/fax/fax_send.php index c81befa57f..193aaa91cb 100644 --- a/app/fax/fax_send.php +++ b/app/fax/fax_send.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) 2008-2021 + Portions created by the Initial Developer are Copyright (C) 2008-2022 the Initial Developer. All Rights Reserved. Contributor(s): @@ -87,13 +87,13 @@ if (!$included) { $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { //set database fields as variables - $fax_uuid = $row["fax_uuid"]; - $fax_extension = $row["fax_extension"]; - $fax_caller_id_name = $row["fax_caller_id_name"]; - $fax_caller_id_number = $row["fax_caller_id_number"]; - $fax_toll_allow = $row["fax_toll_allow"]; - $fax_accountcode = $row["accountcode"]; - $fax_send_greeting = $row["fax_send_greeting"]; + $fax_uuid = $row["fax_uuid"]; + $fax_extension = $row["fax_extension"]; + $fax_caller_id_name = $row["fax_caller_id_name"]; + $fax_caller_id_number = $row["fax_caller_id_number"]; + $fax_toll_allow = $row["fax_toll_allow"]; + $fax_accountcode = $row["accountcode"]; + $fax_send_greeting = $row["fax_send_greeting"]; } else { if (!permission_exists('fax_extension_view_domain')) { @@ -102,11 +102,6 @@ if (!$included) { } } unset($sql, $parameters, $row); - - $fax_send_mode = $_SESSION['fax']['send_mode']['text']; - if(strlen($fax_send_mode) == 0){ - $fax_send_mode = 'direct'; - } } //set the fax directory @@ -139,69 +134,6 @@ if (!function_exists('gs_cmd')) { } } -if (!function_exists('fax_enqueue')) { - function fax_enqueue($fax_uuid, $fax_file, $wav_file, $reply_address, $fax_uri, $fax_dtmf, $dial_string){ - global $db_type; - - $fax_task_uuid = uuid(); - $dial_string .= "fax_task_uuid='" . $fax_task_uuid . "',"; - $description = ''; //! @todo add description - if ($db_type == "pgsql") { - $date_utc_now_sql = "NOW() at time zone 'utc'"; - } - if ($db_type == "mysql") { - $date_utc_now_sql = "UTC_TIMESTAMP()"; - } - if ($db_type == "sqlite") { - $date_utc_now_sql = "datetime('now')"; - } - - $array['fax_tasks'][0]['fax_task_uuid'] = $fax_task_uuid; - $array['fax_tasks'][0]['fax_uuid'] = $fax_uuid; - $array['fax_tasks'][0]['task_next_time'] = $date_utc_now_sql; - $array['fax_tasks'][0]['task_lock_time'] = null; - $array['fax_tasks'][0]['task_fax_file'] = $fax_file; - $array['fax_tasks'][0]['task_wav_file'] = $wav_file; - $array['fax_tasks'][0]['task_uri'] = $fax_uri; - $array['fax_tasks'][0]['task_dial_string'] = $dial_string; - $array['fax_tasks'][0]['task_dtmf'] = $fax_dtmf; - $array['fax_tasks'][0]['task_interrupted'] = 'false'; - $array['fax_tasks'][0]['task_status'] = 0; - $array['fax_tasks'][0]['task_no_answer_counter'] = 0; - $array['fax_tasks'][0]['task_no_answer_retry_counter'] = 0; - $array['fax_tasks'][0]['task_retry_counter'] = 0; - $array['fax_tasks'][0]['task_reply_address'] = $reply_address; - $array['fax_tasks'][0]['task_description'] = $description; - - $p = new permissions; - $p->add('fax_task_add', 'temp'); - - $database = new database; - $database->app_name = 'fax'; - $database->app_uuid = '24108154-4ac3-1db6-1551-4731703a4440'; - $database->save($array); - $message = $database->message; - unset($array); - - $p->delete('fax_task_add', 'temp'); - - if ($message['message'] == 'OK' && $message['code'] == 200) { - $response = 'Enqueued'; - } - else { - $response = 'Fail Enqueue'; - - echo $message['message'].' ['.$message['code']."]
\n"; - if (is_array($message['error']) && @sizeof($message['error']) != 0) { - foreach ($message['error'] as $error) { - echo "
".$error."


\n"; - } - } - } - return $response; - } -} - if (!function_exists('fax_split_dtmf')) { function fax_split_dtmf(&$fax_number, &$fax_dtmf){ $tmp = array(); @@ -251,18 +183,19 @@ if (!function_exists('fax_split_dtmf')) { $continue = false; if (!$included) { if (($_POST['action'] == "send")) { - $fax_numbers = $_POST['fax_numbers']; - $fax_uuid = $_POST["id"]; - $fax_caller_id_name = $_POST['fax_caller_id_name']; - $fax_caller_id_number = $_POST['fax_caller_id_number']; - $fax_header = $_POST['fax_header']; - $fax_sender = $_POST['fax_sender']; - $fax_recipient = $_POST['fax_recipient']; - $fax_subject = $_POST['fax_subject']; - $fax_message = $_POST['fax_message']; - $fax_resolution = $_POST['fax_resolution']; - $fax_page_size = $_POST['fax_page_size']; - $fax_footer = $_POST['fax_footer']; + //Get values from the HTTP POST to set as variables + $fax_numbers = $_POST['fax_numbers']; + $fax_uuid = $_POST["id"]; + $fax_caller_id_name = $_POST['fax_caller_id_name']; + $fax_caller_id_number = $_POST['fax_caller_id_number']; + $fax_header = $_POST['fax_header']; + $fax_sender = $_POST['fax_sender']; + $fax_recipient = $_POST['fax_recipient']; + $fax_subject = $_POST['fax_subject']; + $fax_message = $_POST['fax_message']; + $fax_resolution = $_POST['fax_resolution']; + $fax_page_size = $_POST['fax_page_size']; + $fax_footer = $_POST['fax_footer']; //validate the token $token = new token; @@ -577,20 +510,20 @@ if (!function_exists('fax_split_dtmf')) { $pages = $pdf->getNumPages(); if ($pages > 1) { - # save ynew for last page + //save ynew for last page $yn = $pdf->GetY(); - # First page + //first page $pdf->setPage(1, 0); $pdf->Rect($x + 0.5, $y + 3.4, 7.5, $page_height - 3.9, 'D'); - # 2nd to N-th page + //2nd to n-th page for ($n = 2; $n < $pages; $n++) { $pdf->setPage($n, 0); $pdf->Rect($x + 0.5, $y + 0.5, 7.5, $page_height - 1, 'D'); } - #Last page + //last page $pdf->setPage($pages, 0); $pdf->Rect($x + 0.5, 0.5, 7.5, $yn, 'D'); $y = $yn; @@ -612,7 +545,7 @@ if (!function_exists('fax_split_dtmf')) { $pdf->SetAutoPageBreak(false); $pdf->SetTopMargin(0); - // save cover pdf + //save cover pdf $pdf->Output($dir_fax_temp.'/'.$fax_instance_uuid.'_cover.pdf', "F"); // Display [I]nline, Save to [F]ile, [D]ownload //convert pdf to tif, add to array of pages, delete pdf @@ -727,16 +660,17 @@ if (!function_exists('fax_split_dtmf')) { //send the fax $fax_file = $dir_fax_temp."/".$fax_instance_uuid.".tif"; - $tmp_dial_string = "for_fax=1,"; - $tmp_dial_string .= "accountcode='" . $fax_accountcode . "',"; - $tmp_dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',"; - $tmp_dial_string .= "domain_uuid=" . $_SESSION["domain_uuid"] . ","; - $tmp_dial_string .= "domain_name=" . $_SESSION["domain_name"] . ","; - $tmp_dial_string .= "origination_caller_id_name='" . $fax_caller_id_name . "',"; - $tmp_dial_string .= "origination_caller_id_number='" . $fax_caller_id_number . "',"; - $tmp_dial_string .= "fax_ident='" . $fax_caller_id_number . "',"; - $tmp_dial_string .= "fax_header='" . $fax_caller_id_name . "',"; - $tmp_dial_string .= "fax_file='" . $fax_file . "',"; + $common_variables = "for_fax=1,"; + $common_variables .= "accountcode='" . $fax_accountcode . "',"; + $common_variables .= "sip_h_X-accountcode='" . $fax_accountcode . "',"; + $common_variables .= "domain_uuid=" . $_SESSION["domain_uuid"] . ","; + $common_variables .= "domain_name=" . $_SESSION["domain_name"] . ","; + $common_variables .= "origination_caller_id_name='" . $fax_caller_id_name . "',"; + $common_variables .= "origination_caller_id_number='" . $fax_caller_id_number . "',"; + $common_variables .= "fax_ident='" . $fax_caller_id_number . "',"; + $common_variables .= "fax_header='" . $fax_caller_id_name . "',"; + $common_variables .= "fax_file='" . $fax_file . "',"; + foreach ($fax_numbers as $fax_number) { $fax_number = trim($fax_number); @@ -761,40 +695,67 @@ if (!function_exists('fax_split_dtmf')) { } } - if ($fax_send_mode != 'queue') { - $dial_string = $tmp_dial_string; - $dial_string .= $fax_variables; - $dial_string .= "mailto_address='" . $mailto_address . "',"; - $dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; - $dial_string .= "fax_uri=" . $fax_uri . ","; - $dial_string .= "fax_retry_attempts=1" . ","; - $dial_string .= "fax_retry_limit=20" . ","; - $dial_string .= "fax_retry_sleep=180" . ","; - $dial_string .= "fax_verbose=true" . ","; - $dial_string .= "fax_use_ecm=off" . ","; - $dial_string .= "api_hangup_hook='lua fax_retry.lua'"; - $dial_string = "{" . $dial_string . "}" . $fax_uri." &txfax('".$fax_file."')"; + //build the fax dial string + $dial_string = $common_variables; + $dial_string .= $fax_variables; + $dial_string .= "mailto_address='" . $mailto_address . "',"; + $dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; + $dial_string .= "fax_uri=" . $fax_uri . ","; + $dial_string .= "fax_retry_attempts=1" . ","; + $dial_string .= "fax_retry_limit=20" . ","; + $dial_string .= "fax_retry_sleep=180" . ","; + $dial_string .= "fax_verbose=true" . ","; + $dial_string .= "fax_use_ecm=off" . ","; + $dial_string .= "api_hangup_hook='lua fax_retry.lua'"; + $dial_string = "{" . $dial_string . "}" . $fax_uri." &txfax('".$fax_file."')"; + //add fax to the fax queue or send it directly + if (isset($_SESSION['fax']['send_mode']['text']) && $_SESSION['fax']['send_mode']['text'] == 'queue') { + //build an array to add the fax to the queue + $fax_queue_uuid = uuid(); + $array['fax_queue'][0]['fax_queue_uuid'] = $fax_queue_uuid; + $array['fax_queue'][0]['domain_uuid'] = $_SESSION['domain_uuid']; + $array['fax_queue'][0]['fax_uuid'] = $fax_uuid; + $array['fax_queue'][0]['fax_date'] = 'now()'; + $array['fax_queue'][0]['hostname'] = gethostname(); + $array['fax_queue'][0]['fax_caller_id_name'] = $fax_caller_id_name; + $array['fax_queue'][0]['fax_caller_id_number'] = $fax_caller_id_number; + $array['fax_queue'][0]['fax_number'] = $fax_number; + $array['fax_queue'][0]['fax_prefix'] = $fax_prefix; + $array['fax_queue'][0]['fax_email_address'] = $mailto_address; + $array['fax_queue'][0]['fax_file'] = $fax_file; + $array['fax_queue'][0]['fax_status'] = 'waiting'; + //$array['fax_queue'][0]['fax_retry_date'] = $fax_retry_date; + $array['fax_queue'][0]['fax_retry_count'] = 0; + $array['fax_queue'][0]['fax_accountcode'] = $fax_accountcode; + $array['fax_queue'][0]['fax_command'] = 'originate '.$dial_string; + + //add temporary permisison + $p = new permissions; + $p->add('fax_queue_add', 'temp'); + + //save the data + $database = new database; + $database->app_name = 'fax queue'; + $database->app_uuid = '3656287f-4b22-4cf1-91f6-00386bf488f4'; + $database->save($array); + + //remove temporary permisison + $p->delete('fax_queue_add', 'temp'); + } + else { + //send the fax directly $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $cmd = "api originate " . $dial_string; - //send the command to event socket $response = event_socket_request($fp, $cmd); $response = str_replace("\n", "", $response); $uuid = str_replace("+OK ", "", $response); } fclose($fp); } - else { // enqueue - $wav_file = ''; //! @todo add custom message - $dial_string = $tmp_dial_string; - $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $mailto_address, $fax_uri, $fax_dtmf, $dial_string); - } } - //wait for a few seconds - sleep(5); - //move the generated tif (and pdf) files to the sent directory if (file_exists($dir_fax_temp.'/'.$fax_instance_uuid.".tif")) { copy($dir_fax_temp.'/'.$fax_instance_uuid.".tif", $dir_fax_sent.'/'.$fax_instance_uuid.".tif"); @@ -804,11 +765,11 @@ if (!function_exists('fax_split_dtmf')) { copy($dir_fax_temp.'/'.$fax_instance_uuid.".pdf ", $dir_fax_sent.'/'.$fax_instance_uuid.".pdf"); } + //redirect the browser if (!$included && is_uuid($fax_uuid)) { - //redirect the browser message::add($response, 'default'); if (isset($_SESSION['fax']['send_mode']['text']) && $_SESSION['fax']['send_mode']['text'] == 'queue') { - header("Location: fax_active.php?id=".$fax_uuid); + header("Location: ".PROJECT_PATH."/app/fax_queue/fax_queue.php?id=".$fax_uuid); } else { header("Location: fax_files.php?id=".$fax_uuid."&box=sent"); @@ -822,6 +783,84 @@ if (!function_exists('fax_split_dtmf')) { if (!$included) { + //retrieve current user's assigned groups (uuids) + foreach ($_SESSION['groups'] as $group_data) { + $user_group_uuids[] = $group_data['group_uuid']; + } + + //add user's uuid to group uuid list to include private (non-shared) contacts + $user_group_uuids[] = $_SESSION["user_uuid"]; + $sql = "select "; + $sql .= "c.contact_organization, "; + $sql .= "c.contact_name_given, "; + $sql .= "c.contact_name_family, "; + $sql .= "c.contact_nickname, "; + $sql .= "cp.phone_number "; + $sql .= "from "; + $sql .= "v_contacts as c, "; + $sql .= "v_contact_phones as cp "; + $sql .= "where "; + $sql .= "c.contact_uuid = cp.contact_uuid "; + $sql .= "and c.domain_uuid = :domain_uuid "; + $sql .= "and cp.domain_uuid = :domain_uuid "; + $sql .= "and cp.phone_type_fax = 1 "; + $sql .= "and cp.phone_number is not null "; + $sql .= "and cp.phone_number <> '' "; + if ($_SESSION['contact']['permissions']['boolean'] == "true") { + if (is_array($user_group_uuids) && @sizeof($user_group_uuids) != 0) { + //only show contacts assigned to current user's group(s) and those not assigned to any group + $sql .= "and ("; + $sql .= " c.contact_uuid in ( "; + $sql .= " select contact_uuid from v_contact_groups "; + $sql .= " where ("; + foreach ($user_group_uuids as $index => $user_group_uuid) { + $sql .= $or; + $sql .= " group_uuid = :group_uuid_".$index." "; + $parameters['group_uuid_'.$index] = $user_group_uuid; + $or = " or "; + } + unset($user_group_uuids, $index, $user_group_uuid, $or); + $sql .= " ) "; + $sql .= " and domain_uuid = :domain_uuid "; + $sql .= " ) "; + $sql .= " or "; + $sql .= " c.contact_uuid not in ( "; + $sql .= " select contact_uuid from v_contact_groups "; + $sql .= " where domain_uuid = :domain_uuid "; + $sql .= " ) "; + $sql .= ") "; + } + } + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $contacts = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters, $row); + + //build the contact labels + if (is_array($contacts) && @sizeof($contacts) != 0) { + foreach ($contacts as &$row) { + if ($row['contact_organization'] != '') { + $contact_option_label = $row['contact_organization']; + } + if ($row['contact_name_given'] != '' || $row['contact_name_family'] != '' || $row['contact_nickname'] != '') { + $contact_option_label .= ($row['contact_organization'] != '') ? "," : null; + $contact_option_label .= ($row['contact_name_given'] != '') ? (($row['contact_organization'] != '') ? " " : null).$row['contact_name_given'] : null; + $contact_option_label .= ($row['contact_name_family'] != '') ? (($row['contact_organization'] != '' || $row['contact_name_given'] != '') ? " " : null).$row['contact_name_family'] : null; + $contact_option_label .= ($row['contact_nickname'] != '') ? (($row['contact_organization'] != '' || $row['contact_name_given'] != '' || $row['contact_name_family'] != '') ? " (".$row['contact_nickname'].")" : $row['contact_nickname']) : null; + } + $contact_option_value_recipient = $contact_option_label; + $contact_option_value_faxnumber = $row['phone_number']; + $contact_option_label .= " ".escape(format_phone($row['phone_number'])); + $contact_labels[] = $contact_option_label; + $contact_values[] = $contact_option_value_faxnumber."|".$contact_option_value_recipient; + unset($contact_option_label); + } + if (is_array($contact_labels)) { + //sort by name(s) + asort($contact_labels, SORT_NATURAL); + } + } + //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); @@ -921,85 +960,16 @@ if (!$included) { echo " ".$text['label-fax-recipient']."\n"; echo "\n"; echo "\n"; - //retrieve current user's assigned groups (uuids) - foreach ($_SESSION['groups'] as $group_data) { - $user_group_uuids[] = $group_data['group_uuid']; - } - //add user's uuid to group uuid list to include private (non-shared) contacts - $user_group_uuids[] = $_SESSION["user_uuid"]; - $sql = "select "; - $sql .= "c.contact_organization, "; - $sql .= "c.contact_name_given, "; - $sql .= "c.contact_name_family, "; - $sql .= "c.contact_nickname, "; - $sql .= "cp.phone_number "; - $sql .= "from "; - $sql .= "v_contacts as c, "; - $sql .= "v_contact_phones as cp "; - $sql .= "where "; - $sql .= "c.contact_uuid = cp.contact_uuid "; - $sql .= "and c.domain_uuid = :domain_uuid "; - $sql .= "and cp.domain_uuid = :domain_uuid "; - $sql .= "and cp.phone_type_fax = 1 "; - $sql .= "and cp.phone_number is not null "; - $sql .= "and cp.phone_number <> '' "; - if ($_SESSION['contact']['permissions']['boolean'] == "true") { - if (is_array($user_group_uuids) && @sizeof($user_group_uuids) != 0) { - //only show contacts assigned to current user's group(s) and those not assigned to any group - $sql .= "and ("; - $sql .= " c.contact_uuid in ( "; - $sql .= " select contact_uuid from v_contact_groups "; - $sql .= " where ("; - foreach ($user_group_uuids as $index => $user_group_uuid) { - $sql .= $or; - $sql .= " group_uuid = :group_uuid_".$index." "; - $parameters['group_uuid_'.$index] = $user_group_uuid; - $or = " or "; - } - unset($user_group_uuids, $index, $user_group_uuid, $or); - $sql .= " ) "; - $sql .= " and domain_uuid = :domain_uuid "; - $sql .= " ) "; - $sql .= " or "; - $sql .= " c.contact_uuid not in ( "; - $sql .= " select contact_uuid from v_contact_groups "; - $sql .= " where domain_uuid = :domain_uuid "; - $sql .= " ) "; - $sql .= ") "; - } - } - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; - $contacts = $database->select($sql, $parameters, 'all'); if (is_array($contacts) && @sizeof($contacts) != 0) { - foreach ($contacts as &$row) { - if ($row['contact_organization'] != '') { - $contact_option_label = $row['contact_organization']; - } - if ($row['contact_name_given'] != '' || $row['contact_name_family'] != '' || $row['contact_nickname'] != '') { - $contact_option_label .= ($row['contact_organization'] != '') ? "," : null; - $contact_option_label .= ($row['contact_name_given'] != '') ? (($row['contact_organization'] != '') ? " " : null).$row['contact_name_given'] : null; - $contact_option_label .= ($row['contact_name_family'] != '') ? (($row['contact_organization'] != '' || $row['contact_name_given'] != '') ? " " : null).$row['contact_name_family'] : null; - $contact_option_label .= ($row['contact_nickname'] != '') ? (($row['contact_organization'] != '' || $row['contact_name_given'] != '' || $row['contact_name_family'] != '') ? " (".$row['contact_nickname'].")" : $row['contact_nickname']) : null; - } - $contact_option_value_recipient = $contact_option_label; - $contact_option_value_faxnumber = $row['phone_number']; - $contact_option_label .= ":  ".escape(format_phone($row['phone_number'])); - $contact_labels[] = $contact_option_label; - $contact_values[] = $contact_option_value_faxnumber."|".$contact_option_value_recipient; - unset($contact_option_label); - } - if (is_array($contact_labels)) { - asort($contact_labels, SORT_NATURAL); // sort by name(s) - } echo " \n"; } - unset($sql, $parameters, $row); echo " \n"; if (is_array($contacts)) { echo " \n"; diff --git a/app/fax_queue/app_config.php b/app/fax_queue/app_config.php new file mode 100644 index 0000000000..9ab3d53165 --- /dev/null +++ b/app/fax_queue/app_config.php @@ -0,0 +1,166 @@ + \ No newline at end of file diff --git a/app/fax_queue/app_defaults.php b/app/fax_queue/app_defaults.php new file mode 100644 index 0000000000..adadacce42 --- /dev/null +++ b/app/fax_queue/app_defaults.php @@ -0,0 +1,7 @@ + diff --git a/app/fax_queue/app_languages.php b/app/fax_queue/app_languages.php new file mode 100644 index 0000000000..10f9f3f804 --- /dev/null +++ b/app/fax_queue/app_languages.php @@ -0,0 +1,624 @@ + \ No newline at end of file diff --git a/app/fax_queue/app_menu.php b/app/fax_queue/app_menu.php new file mode 100644 index 0000000000..e0e92b4fdb --- /dev/null +++ b/app/fax_queue/app_menu.php @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/app/fax_queue/fax_queue.php b/app/fax_queue/fax_queue.php new file mode 100644 index 0000000000..b44904f342 --- /dev/null +++ b/app/fax_queue/fax_queue.php @@ -0,0 +1,291 @@ + + Portions created by the Initial Developer are Copyright (C) 2022 + the Initial Developer. All Rights Reserved. +*/ + +//includes + require_once "root.php"; + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + require_once "resources/paging.php"; + +//check permissions + if (permission_exists('fax_queue_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//get the http post data + if (is_array($_POST['fax_queue'])) { + $action = $_POST['action']; + $search = $_POST['search']; + $fax_queue = $_POST['fax_queue']; + } + +//process the http post data by action + if ($action != '' && is_array($fax_queue) && @sizeof($fax_queue) != 0) { + + switch ($action) { + case 'copy': + if (permission_exists('fax_queue_add')) { + $obj = new fax_queue; + $obj->copy($fax_queue); + } + break; + //case 'toggle': + // if (permission_exists('fax_queue_edit')) { + // $obj = new fax_queue; + // $obj->toggle($fax_queue); + // } + // break; + case 'delete': + if (permission_exists('fax_queue_delete')) { + $obj = new fax_queue; + $obj->delete($fax_queue); + } + break; + } + + //redirect the user + header('Location: fax_queue.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + +//get order and order by + $order_by = $_GET["order_by"]; + $order = $_GET["order"]; + +//add the search + if (isset($_GET["search"])) { + $search = strtolower($_GET["search"]); + } + +//get the count + $sql = "select count(fax_queue_uuid) "; + $sql .= "from v_fax_queue "; + if (isset($search)) { + $sql .= "where ("; + $sql .= " lower(hostname) like :search "; + $sql .= " or lower(fax_caller_id_name) like :search "; + $sql .= " or lower(fax_caller_id_number) like :search "; + $sql .= " or lower(fax_number) like :search "; + $sql .= " or lower(fax_email_address) like :search "; + $sql .= " or lower(fax_file) like :search "; + $sql .= " or lower(fax_status) like :search "; + $sql .= " or lower(fax_accountcode) like :search "; + $sql .= ") "; + $parameters['search'] = '%'.$search.'%'; + } + else { + $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; + if (isset($sql_search)) { + $sql .= "and ".$sql_search; + } + $parameters['domain_uuid'] = $domain_uuid; + } + $database = new database; + $num_rows = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + +//prepare to page the results + $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; + $param = $search ? "&search=".$search : null; + $param = ($_GET['show'] == 'all' && permission_exists('fax_queue_all')) ? "&show=all" : null; + $page = is_numeric($_GET['page']) ? $_GET['page'] : 0; + list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page); + list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true); + $offset = $rows_per_page * $page; + +//get the list + $sql = "select "; + $sql .= "fax_queue_uuid, "; + $sql .= "fax_uuid, "; + $sql .= "fax_date, "; + $sql .= "hostname, "; + $sql .= "fax_caller_id_name, "; + $sql .= "fax_caller_id_number, "; + $sql .= "fax_number, "; + $sql .= "fax_prefix, "; + $sql .= "fax_email_address, "; + $sql .= "fax_file, "; + $sql .= "fax_status, "; + $sql .= "fax_retry_date, "; + $sql .= "fax_retry_count, "; + $sql .= "fax_accountcode, "; + $sql .= "fax_command "; + $sql .= "from v_fax_queue "; + if (isset($_GET["search"])) { + $sql .= "where ("; + $sql .= " lower(hostname) like :search "; + $sql .= " or lower(fax_caller_id_name) like :search "; + $sql .= " or lower(fax_caller_id_number) like :search "; + $sql .= " or lower(fax_number) like :search "; + $sql .= " or lower(fax_email_address) like :search "; + $sql .= " or lower(fax_file) like :search "; + $sql .= " or lower(fax_status) like :search "; + $sql .= " or lower(fax_accountcode) like :search "; + $sql .= ") "; + $parameters['search'] = '%'.$search.'%'; + } + $sql .= order_by($order_by, $order, '', ''); + $sql .= limit_offset($rows_per_page, $offset); + $database = new database; + $fax_queue = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//additional includes + $document['title'] = $text['title-fax_queue']; + require_once "resources/header.php"; + +//show the content + echo "
\n"; + echo "
".$text['title-fax_queue']." (".$num_rows.")
\n"; + echo "
\n"; + //if (permission_exists('fax_queue_add')) { + // echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','name'=>'btn_add','link'=>'fax_queue_edit.php']); + //} + if (permission_exists('fax_queue_add') && $fax_queue) { + echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display:none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); + } + //if (permission_exists('fax_queue_edit') && $fax_queue) { + // echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display:none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]); + //} + if (permission_exists('fax_queue_delete') && $fax_queue) { + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display:none;','onclick'=>"modal_open('modal-delete','btn_delete');"]); + } + echo "\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + + if (permission_exists('fax_queue_add') && $fax_queue) { + echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]); + } + //if (permission_exists('fax_queue_edit') && $fax_queue) { + // 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_queue_delete') && $fax_queue) { + 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');"])]); + } + + + echo "
\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + if (permission_exists('fax_queue_add') || permission_exists('fax_queue_edit') || permission_exists('fax_queue_delete')) { + echo " \n"; + } + if ($_GET['show'] == 'all' && permission_exists('fax_queue_all')) { + echo th_order_by('domain_name', $text['label-domain'], $order_by, $order); + } + echo th_order_by('fax_date', $text['label-fax_date'], $order_by, $order); + echo th_order_by('hostname', $text['label-hostname'], $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_number', $text['label-fax_number'], $order_by, $order); + echo th_order_by('fax_email_address', $text['label-fax_email_address'], $order_by, $order); + echo th_order_by('fax_file', $text['label-fax_file'], $order_by, $order); + echo th_order_by('fax_status', $text['label-fax_status'], $order_by, $order); + echo th_order_by('fax_retry_date', $text['label-fax_retry_date'], $order_by, $order); + echo th_order_by('fax_retry_count', $text['label-fax_retry_count'], $order_by, $order); + if (permission_exists('fax_queue_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; + } + echo "\n"; + + if (is_array($fax_queue) && @sizeof($fax_queue) != 0) { + $x = 0; + foreach ($fax_queue as $row) { + if (permission_exists('fax_queue_edit')) { + $list_row_url = "fax_queue_edit.php?id=".urlencode($row['fax_queue_uuid']); + } + echo "\n"; + if (permission_exists('fax_queue_add') || permission_exists('fax_queue_edit') || permission_exists('fax_queue_delete')) { + echo " \n"; + } + if ($_GET['show'] == 'all' && permission_exists('fax_queue_all')) { + echo " \n"; + } + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + if (permission_exists('fax_queue_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; + } + echo "\n"; + $x++; + } + unset($fax_queue); + } + + echo "
\n"; + echo " \n"; + echo "  
\n"; + echo " \n"; + echo " \n"; + echo " ".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."".escape($row['fax_date'])."".escape($row['hostname'])."".escape($row['fax_caller_id_name'])."".escape($row['fax_caller_id_number'])."".escape($row['fax_number'])."".escape($row['fax_email_address'])."".escape($row['fax_file'])."".escape($row['fax_status'])."".escape($row['fax_retry_date'])."".escape($row['fax_retry_count'])."\n"; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo "
\n"; + echo "
\n"; + echo "
".$paging_controls."
\n"; + echo "\n"; + echo "
\n"; + +//include the footer + require_once "resources/footer.php"; + +?> \ No newline at end of file diff --git a/app/fax_queue/fax_queue_delete.php b/app/fax_queue/fax_queue_delete.php new file mode 100644 index 0000000000..6978f96722 --- /dev/null +++ b/app/fax_queue/fax_queue_delete.php @@ -0,0 +1,41 @@ +get(); + +//delete the message + message::add($text['message-delete']); + +//delete the data + if (isset($_GET["id"]) && is_uuid($_GET["id"])) { + + //get the id + $id = $_GET["id"]; + + //delete the data + $array['fax_queue'][]['fax_queue_uuid'] = $id; + $database = new database; + $database->delete($array); + unset($array); + + //redirect the user + header('Location: fax_queues.php'); + } + + +?> \ No newline at end of file diff --git a/app/fax_queue/fax_queue_edit.php b/app/fax_queue/fax_queue_edit.php new file mode 100644 index 0000000000..9ec5524b90 --- /dev/null +++ b/app/fax_queue/fax_queue_edit.php @@ -0,0 +1,437 @@ + + Portions created by the Initial Developer are Copyright (C) 2022 + the Initial Developer. All Rights Reserved. +*/ + +//includes + require_once "root.php"; + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('fax_queue_add') || permission_exists('fax_queue_edit')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//action add or update + if (is_uuid($_REQUEST["id"])) { + $action = "update"; + $fax_queue_uuid = $_REQUEST["id"]; + $id = $_REQUEST["id"]; + } + else { + $action = "add"; + } + +//get http post variables and set them to php variables + if (is_array($_POST)) { + $fax_uuid = $_POST["fax_uuid"]; + $fax_date = $_POST["fax_date"]; + $hostname = $_POST["hostname"]; + $fax_caller_id_name = $_POST["fax_caller_id_name"]; + $fax_caller_id_number = $_POST["fax_caller_id_number"]; + $fax_number = $_POST["fax_number"]; + $fax_prefix = $_POST["fax_prefix"]; + $fax_email_address = $_POST["fax_email_address"]; + $fax_file = $_POST["fax_file"]; + $fax_status = $_POST["fax_status"]; + $fax_retry_date = $_POST["fax_retry_date"]; + $fax_retry_count = $_POST["fax_retry_count"]; + $fax_accountcode = $_POST["fax_accountcode"]; + $fax_command = $_POST["fax_command"]; + } + +//process the user data and save it to the database + if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: fax_queue.php'); + exit; + } + + //process the http post data by submitted action + if ($_POST['action'] != '' && strlen($_POST['action']) > 0) { + + //prepare the array(s) + //send the array to the database class + switch ($_POST['action']) { + case 'copy': + if (permission_exists('fax_queue_add')) { + $obj = new database; + $obj->copy($array); + } + break; + case 'delete': + if (permission_exists('fax_queue_delete')) { + $obj = new database; + $obj->delete($array); + } + break; + case 'toggle': + if (permission_exists('fax_queue_update')) { + $obj = new database; + $obj->toggle($array); + } + break; + } + + //redirect the user + if (in_array($_POST['action'], array('copy', 'delete', 'toggle') && is_uuid($id))) { + header('Location: fax_queue_edit.php?id='.$id); + exit; + } + } + + //check for all required data + $msg = ''; + //if (strlen($fax_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-fax_uuid']."
\n"; } + if (strlen($fax_date) == 0) { $msg .= $text['message-required']." ".$text['label-fax_date']."
\n"; } + if (strlen($hostname) == 0) { $msg .= $text['message-required']." ".$text['label-hostname']."
\n"; } + //if (strlen($fax_caller_id_name) == 0) { $msg .= $text['message-required']." ".$text['label-fax_caller_id_name']."
\n"; } + //if (strlen($fax_caller_id_number) == 0) { $msg .= $text['message-required']." ".$text['label-fax_caller_id_number']."
\n"; } + if (strlen($fax_number) == 0) { $msg .= $text['message-required']." ".$text['label-fax_number']."
\n"; } + //if (strlen($fax_prefix) == 0) { $msg .= $text['message-required']." ".$text['label-fax_prefix']."
\n"; } + if (strlen($fax_email_address) == 0) { $msg .= $text['message-required']." ".$text['label-fax_email_address']."
\n"; } + if (strlen($fax_file) == 0) { $msg .= $text['message-required']." ".$text['label-fax_file']."
\n"; } + if (strlen($fax_status) == 0) { $msg .= $text['message-required']." ".$text['label-fax_status']."
\n"; } + //if (strlen($fax_retry_date) == 0) { $msg .= $text['message-required']." ".$text['label-fax_retry_date']."
\n"; } + //if (strlen($fax_retry_count) == 0) { $msg .= $text['message-required']." ".$text['label-fax_retry_count']."
\n"; } + if (strlen($fax_accountcode) == 0) { $msg .= $text['message-required']." ".$text['label-fax_accountcode']."
\n"; } + //if (strlen($fax_command) == 0) { $msg .= $text['message-required']." ".$text['label-fax_command']."
\n"; } + if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { + require_once "resources/header.php"; + require_once "resources/persist_form_var.php"; + echo "
\n"; + echo "
\n"; + echo $msg."
"; + echo "
\n"; + persistformvar($_POST); + echo "
\n"; + require_once "resources/footer.php"; + return; + } + + //add the fax_queue_uuid + if (!is_uuid($_POST["fax_queue_uuid"])) { + $fax_queue_uuid = uuid(); + } + + //prepare the array + $array['fax_queue'][0]['fax_queue_uuid'] = $fax_queue_uuid; + $array['fax_queue'][0]['domain_uuid'] = $_SESSION['domain_uuid']; + //$array['fax_queue'][0]['fax_uuid'] = $fax_uuid; + $array['fax_queue'][0]['fax_date'] = $fax_date; + $array['fax_queue'][0]['hostname'] = $hostname; + $array['fax_queue'][0]['fax_caller_id_name'] = $fax_caller_id_name; + $array['fax_queue'][0]['fax_caller_id_number'] = $fax_caller_id_number; + $array['fax_queue'][0]['fax_number'] = $fax_number; + $array['fax_queue'][0]['fax_prefix'] = $fax_prefix; + $array['fax_queue'][0]['fax_email_address'] = $fax_email_address; + $array['fax_queue'][0]['fax_file'] = $fax_file; + $array['fax_queue'][0]['fax_status'] = $fax_status; + $array['fax_queue'][0]['fax_retry_date'] = $fax_retry_date; + $array['fax_queue'][0]['fax_retry_count'] = $fax_retry_count; + $array['fax_queue'][0]['fax_accountcode'] = $fax_accountcode; + $array['fax_queue'][0]['fax_command'] = $fax_command; + + //save the data + $database = new database; + $database->app_name = 'fax queue'; + $database->app_uuid = '3656287f-4b22-4cf1-91f6-00386bf488f4'; + $database->save($array); + + //redirect the user + if (isset($action)) { + if ($action == "add") { + $_SESSION["message"] = $text['message-add']; + } + if ($action == "update") { + $_SESSION["message"] = $text['message-update']; + } + //header('Location: fax_queue.php'); + header('Location: fax_queue_edit.php?id='.urlencode($fax_queue_uuid)); + return; + } + } + +//pre-populate the form + if (is_array($_GET) && $_POST["persistformvar"] != "true") { + $sql = "select "; + $sql .= " fax_uuid, "; + $sql .= " fax_date, "; + $sql .= " hostname, "; + $sql .= " fax_caller_id_name, "; + $sql .= " fax_caller_id_number, "; + $sql .= " fax_number, "; + $sql .= " fax_prefix, "; + $sql .= " fax_email_address, "; + $sql .= " fax_file, "; + $sql .= " fax_status, "; + $sql .= " fax_retry_date, "; + $sql .= " fax_retry_count, "; + $sql .= " fax_accountcode, "; + $sql .= " fax_command "; + $sql .= "from v_fax_queue "; + $sql .= "where fax_queue_uuid = :fax_queue_uuid "; + //$sql .= "and domain_uuid = :domain_uuid "; + //$parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $parameters['fax_queue_uuid'] = $fax_queue_uuid; + $database = new database; + $row = $database->select($sql, $parameters, 'row'); + if (is_array($row) && @sizeof($row) != 0) { + $fax_uuid = $row["fax_uuid"]; + $fax_date = $row["fax_date"]; + $hostname = $row["hostname"]; + $fax_caller_id_name = $row["fax_caller_id_name"]; + $fax_caller_id_number = $row["fax_caller_id_number"]; + $fax_number = $row["fax_number"]; + $fax_prefix = $row["fax_prefix"]; + $fax_email_address = $row["fax_email_address"]; + $fax_file = $row["fax_file"]; + $fax_status = $row["fax_status"]; + $fax_retry_date = $row["fax_retry_date"]; + $fax_retry_count = $row["fax_retry_count"]; + $fax_accountcode = $row["fax_accountcode"]; + $fax_command = $row["fax_command"]; + } + unset($sql, $parameters, $row); + } + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//show the header + $document['title'] = $text['title-fax_queue']; + require_once "resources/header.php"; + +//show the content + echo "
\n"; + echo "\n"; + + echo "
\n"; + echo "
".$text['title-fax_queue']."
\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'fax_queue.php']); + if ($action == 'update') { + if (permission_exists('_add')) { + echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); + } + if (permission_exists('_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-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]); + } + } + echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['title_description-fax_queue']."\n"; + echo "

\n"; + + if ($action == 'update') { + if (permission_exists('fax_queue_add')) { + echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'copy','onclick'=>"modal_close();"])]); + } + if (permission_exists('fax_queue_delete')) { + echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]); + } + } + + 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 "\n"; + + 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 "\n"; + 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 "\n"; + 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 "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + //echo " ".$text['label-fax_uuid']."\n"; + //echo "\n"; + //echo " \n"; + //echo "
\n"; + //echo $text['description-fax_uuid']."\n"; + //echo "
\n"; + echo " ".$text['label-fax_date']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_date']."\n"; + echo "
\n"; + echo " ".$text['label-hostname']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-hostname']."\n"; + echo "
\n"; + echo " ".$text['label-fax_caller_id_name']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_caller_id_name']."\n"; + echo "
\n"; + echo " ".$text['label-fax_caller_id_number']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_caller_id_number']."\n"; + echo "
\n"; + echo " ".$text['label-fax_number']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_number']."\n"; + echo "
\n"; + echo " ".$text['label-fax_prefix']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_prefix']."\n"; + echo "
\n"; + echo " ".$text['label-fax_email_address']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_email_address']."\n"; + echo "
\n"; + echo " ".$text['label-fax_file']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_file']."\n"; + echo "
\n"; + echo " ".$text['label-fax_status']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_status']."\n"; + echo "
\n"; + echo " ".$text['label-fax_retry_date']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_retry_date']."\n"; + echo "
\n"; + echo " ".$text['label-fax_retry_count']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_retry_count']."\n"; + echo "
\n"; + echo " ".$text['label-fax_accountcode']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_accountcode']."\n"; + echo "
\n"; + echo " ".$text['label-fax_command']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-fax_command']."\n"; + echo "
"; + echo "

"; + + echo "\n"; + + echo "
"; + +//include the footer + require_once "resources/footer.php"; + +?> \ No newline at end of file diff --git a/app/fax_queue/resources/classes/fax_queue.php b/app/fax_queue/resources/classes/fax_queue.php new file mode 100644 index 0000000000..d34b80e61b --- /dev/null +++ b/app/fax_queue/resources/classes/fax_queue.php @@ -0,0 +1,263 @@ + + Portions created by the Initial Developer are Copyright (C) 2019 - 2021 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +/** + * fax_queue class + * + * @method null delete + * @method null toggle + * @method null copy + */ +if (!class_exists('fax_queue')) { + class fax_queue { + + /** + * declare the variables + */ + private $app_name; + private $app_uuid; + private $name; + private $table; + private $toggle_field; + private $toggle_values; + private $location; + + /** + * called when the object is created + */ + public function __construct() { + //assign the variables + $this->app_name = 'fax_queue'; + $this->app_uuid = '3656287f-4b22-4cf1-91f6-00386bf488f4'; + $this->name = 'fax_queue'; + $this->table = 'fax_queue'; + $this->toggle_field = ''; + $this->toggle_values = ['true','false']; + $this->location = 'fax_queue.php'; + } + + /** + * called when there are no references to a particular object + * unset the variables used in the class + */ + public function __destruct() { + foreach ($this as $key => $value) { + unset($this->$key); + } + } + + /** + * delete rows from the database + */ + public function delete($records) { + if (permission_exists($this->name.'_delete')) { + + //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: '.$this->location); + exit; + } + + //delete multiple records + if (is_array($records) && @sizeof($records) != 0) { + //build the delete array + $x = 0; + foreach ($records as $record) { + //add to the array + if ($record['checked'] == 'true' && is_uuid($record['fax_queue_uuid'])) { + $array[$this->table][$x]['fax_queue_uuid'] = $record['fax_queue_uuid']; + $array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid']; + } + + //increment the id + $x++; + } + + //delete the checked rows + if (is_array($array) && @sizeof($array) != 0) { + //execute delete + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->delete($array); + unset($array); + + //set message + message::add($text['message-delete']); + } + unset($records); + } + } + } + + /** + * toggle a field between two values + */ + public function toggle($records) { + if (permission_exists($this->name.'_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: '.$this->location); + exit; + } + + //toggle the checked records + if (is_array($records) && @sizeof($records) != 0) { + //get current toggle state + foreach($records as $record) { + if ($record['checked'] == 'true' && is_uuid($record['fax_queue_uuid'])) { + $uuids[] = "'".$record['fax_queue_uuid']."'"; + } + } + if (is_array($uuids) && @sizeof($uuids) != 0) { + $sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." "; + $sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") "; + $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $row) { + $states[$row['uuid']] = $row['toggle']; + } + } + unset($sql, $parameters, $rows, $row); + } + + //build update array + $x = 0; + foreach($states as $uuid => $state) { + //create the array + $array[$this->table][$x][$this->name.'_uuid'] = $uuid; + $array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0]; + + //increment the id + $x++; + } + + //save the changes + if (is_array($array) && @sizeof($array) != 0) { + //save the array + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->save($array); + unset($array); + + //set message + message::add($text['message-toggle']); + } + unset($records, $states); + } + } + } + + /** + * copy rows from the database + */ + public function copy($records) { + if (permission_exists($this->name.'_add')) { + + //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: '.$this->location); + exit; + } + + //copy the checked records + if (is_array($records) && @sizeof($records) != 0) { + + //get checked records + foreach($records as $record) { + if ($record['checked'] == 'true' && is_uuid($record['fax_queue_uuid'])) { + $uuids[] = "'".$record['fax_queue_uuid']."'"; + } + } + + //create the array from existing data + if (is_array($uuids) && @sizeof($uuids) != 0) { + $sql = "select * from v_".$this->table." "; + $sql .= "where fax_queue_uuid in (".implode(', ', $uuids).") "; + $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + if (is_array($rows) && @sizeof($rows) != 0) { + $x = 0; + foreach ($rows as $row) { + //copy data + $array[$this->table][$x] = $row; + + //add copy to the description + $array[$this->table][$x][fax_queue.'_uuid'] = uuid(); + + //increment the id + $x++; + } + } + unset($sql, $parameters, $rows, $row); + } + + //save the changes and set the message + if (is_array($array) && @sizeof($array) != 0) { + //save the array + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->save($array); + unset($array); + + //set message + message::add($text['message-copy']); + } + unset($records); + } + } + } + + } +} + +?> \ No newline at end of file diff --git a/app/fax_queue/resources/job/fax_queue.php b/app/fax_queue/resources/job/fax_queue.php new file mode 100644 index 0000000000..9d3a2fe1a5 --- /dev/null +++ b/app/fax_queue/resources/job/fax_queue.php @@ -0,0 +1,190 @@ + :interval "; + $sql .= ") "; + $sql .= "order by domain_uuid asc "; + $sql .= "limit :limit "; + if (isset($hostname)) { + $parameters['hostname'] = $hostname; + } + else { + $parameters['hostname'] = gethostname(); + } + $parameters['limit'] = $fax_queue_limit; + $parameters['interval'] = $fax_queue_interval; + $database = new database; + $fax_queue = $database->select($sql, $parameters, 'all'); + unset($parameters); + +//process the messages + if (is_array($fax_queue) && @sizeof($fax_queue) != 0) { + foreach($fax_queue as $row) { + $command = "/usr/bin/php /var/www/fusionpbx/app/fax_queue/resources/job/fax_send.php "; + $command .= "'action=send&fax_queue_uuid=".$row["fax_queue_uuid"]."&hostname=".$hostname."'"; + if (isset($debug)) { + //run process inline to see debug info + echo $command."\n"; + $result = system($command); + echo $result."\n"; + } + else { + //starts process rapidly doesn't wait for previous process to finish (used for production) + $handle = popen($command." > /dev/null &", 'r'); + echo "'$handle'; " . gettype($handle) . "\n"; + $read = fread($handle, 2096); + echo $read; + pclose($handle); + } + } + } + +//remove the old pid file + if (file_exists($file)) { + unlink($pid_file); + } + +//save output to + //$fp = fopen(sys_get_temp_dir()."/mailer-app.log", "a"); + +//prepare the output buffers + //ob_end_clean(); + //ob_start(); + +//message divider for log file + //echo "\n\n=============================================================================================================================================\n\n"; + +//get and save the output from the buffer + //$content = ob_get_contents(); //get the output from the buffer + //$content = str_replace("
", "", $content); + + //ob_end_clean(); //clean the buffer + + //fwrite($fp, $content); + //fclose($fp); + +//notes + //echo __line__."\n"; + // if not keeping the email then need to delete it after the voicemail is emailed + +//how to use this feature + // cd /var/www/fusionpbx; /usr/bin/php /var/www/fusionpbx/app/fax_queue/resources/send.php + +?> diff --git a/app/fax_queue/resources/job/fax_send.php b/app/fax_queue/resources/job/fax_send.php new file mode 100644 index 0000000000..2512b06d96 --- /dev/null +++ b/app/fax_queue/resources/job/fax_send.php @@ -0,0 +1,263 @@ +select($sql, $parameters, 'row'); + if (is_array($row)) { + $fax_queue_uuid = $row['fax_queue_uuid']; + $domain_uuid = $row['domain_uuid']; + $domain_name = $row['domain_name']; + $fax_uuid = $row['fax_uuid']; + $hostname = $row["hostname"]; + $fax_date = $row["fax_date"]; + $fax_caller_id_name = $row["fax_caller_id_name"]; + $fax_caller_id_number = $row["fax_caller_id_number"]; + $fax_prefix = $row["fax_prefix"]; + $fax_number = $row["fax_number"]; + $fax_email_address = $row["fax_email_address"]; + $fax_file = $row["fax_file"]; + $fax_status = $row["fax_status"]; + $fax_retry_count = $row["fax_retry_count"]; + $fax_accountcode = $row["fax_accountcode"]; + $fax_command = $row["fax_command"]; + } + unset($parameters); + +//get some more info to send the fax + $mail_from_address = (isset($_SESSION['fax']['smtp_from']['text'])) ? $_SESSION['fax']['smtp_from']['text'] : $_SESSION['email']['smtp_from']['text']; + +//get the call center settings + $retry_limit = $_SESSION['fax_queue']['retry_limit']['numeric']; + //$retry_interval = $_SESSION['fax_queue']['retry_interval']['numeric']; + +//prepare the fax retry count + if (strlen($fax_retry_count) == 0) { + $fax_retry_count = 0; + } + else { + $fax_retry_count = $fax_retry_count + 1; + } + +//fax options + if ($fax_retry_count == 0) { + $fax_options = "fax_use_ecm=false,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=default"; + } + elseif ($fax_retry_count == 1) { + $fax_options = "fax_use_ecm=true,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=false"; + } + elseif ($fax_retry_count == 2) { + $fax_options = "fax_use_ecm=true,fax_enable_t38=false,fax_enable_t38_request=false,fax_disable_v17=false"; + } + elseif ($fax_retry_count == 3) { + $fax_options = "fax_use_ecm=true,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=true"; + } + elseif ($fax_retry_count == 4) { + $fax_options = "fax_use_ecm=false,fax_enable_t38=false,fax_enable_t38_request=false,fax_disable_v17=false"; + } + +//define the fax file + $tmp_dial_string = "for_fax=1,"; + $tmp_dial_string .= "accountcode='" . $fax_accountcode . "',"; + $tmp_dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',"; + $tmp_dial_string .= "domain_uuid=" . $domain_uuid . "',"; + $tmp_dial_string .= "domain_name=" . $domain_name . "',"; + $tmp_dial_string .= "origination_caller_id_name='" . $fax_caller_id_name . "',"; + $tmp_dial_string .= "origination_caller_id_number='" . $fax_caller_id_number . "',"; + $tmp_dial_string .= "fax_ident='" . $fax_caller_id_number . "',"; + $tmp_dial_string .= "fax_header='" . $fax_caller_id_name . "',"; + $tmp_dial_string .= "fax_file='" . $fax_file . "',"; + +//extract fax_dtmf from the fax number + fax_split_dtmf($fax_number, $fax_dtmf); + +//prepare the fax command + if (strlen($fax_toll_allow) > 0) { + $channel_variables["toll_allow"] = $fax_toll_allow; + } + $route_array = outbound_route_to_bridge($domain_uuid, $fax_prefix . $fax_number, $channel_variables); + if (count($route_array) == 0) { + //send the internal call to the registered extension + $fax_uri = "user/".$fax_number."@".$domain_name; + $fax_variables = ""; + } + else { + //send the external call + $fax_uri = $route_array[0]; + $fax_variables = ""; + foreach($_SESSION['fax']['variable'] as $variable) { + $fax_variables .= $variable.","; + } + } + +//set the fax file name without the extension + $fax_instance_uuid = pathinfo($fax_file, PATHINFO_FILENAME); + +//build a list of fax variables + $dial_string = $tmp_dial_string; + $dial_string .= $fax_variables; + $dial_string .= $fax_options.","; + $dial_string .= "fax_uuid=" . $fax_uuid. ","; + $dial_string .= "fax_queue_uuid=" . $fax_queue_uuid. ","; + $dial_string .= "mailto_address='" . $fax_email_address . "',"; + $dial_string .= "mailfrom_address='" . $mail_from_address . "',"; + $dial_string .= "fax_uri=" . $fax_uri . ","; + $dial_string .= "fax_retry_attempts=1" . ","; + $dial_string .= "fax_retry_limit=1" . ","; + //$dial_string .= "fax_retry_sleep=180" . ","; + $dial_string .= "fax_verbose=true" . ","; + //$dial_string .= "fax_use_ecm=off" . ","; + $dial_string .= "api_hangup_hook='lua app/fax/resources/scripts/hangup.lua'"; + $fax_command = "originate {" . $dial_string . "}" . $fax_uri." &txfax('".$fax_file."')"; + //echo $fax_command."\n"; + +//connect to event socket and send the command + if (file_exists($fax_file)) { + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + if ($fp) { + $response = event_socket_request($fp, "api " . $fax_command); + //$response = event_socket_request($fp, $fax_command); + $response = str_replace("\n", "", $response); + $uuid = str_replace("+OK ", "", $response); + echo "uuid ".$uuid."\n"; + } + fclose($fp); + } + else { + echo "fax file missing: ".$fax_file."\n"; + } + +//update the database to say status to trying and set the command + $array['fax_queue'][0]['fax_queue_uuid'] = $fax_queue_uuid; + $array['fax_queue'][0]['domain_uuid'] = $domain_uuid; + if ($fax_retry_count >= $retry_limit) { + $array['fax_queue'][0]['fax_status'] = 'failed'; + } + else { + $array['fax_queue'][0]['fax_status'] = 'trying'; + } + $array['fax_queue'][0]['fax_retry_count'] = $fax_retry_count; + $array['fax_queue'][0]['fax_retry_date'] = 'now()'; + $array['fax_queue'][0]['fax_command'] = $fax_command; + +//add temporary permissions + $p = new permissions; + $p->add('fax_queue_edit', 'temp'); + +//save the data + $database = new database; + $database->app_name = 'fax queue'; + $database->app_uuid = '3656287f-4b22-4cf1-91f6-00386bf488f4'; + $database->save($array, false); + +//remove temporary permissions + $p->delete('fax_queue_edit', 'temp'); + +//wait for a few seconds + //sleep(1); + +//move the generated tif (and pdf) files to the sent directory + //if (file_exists($dir_fax_temp.'/'.$fax_instance_uuid.".tif")) { + // copy($dir_fax_temp.'/'.$fax_instance_uuid.".tif", $dir_fax_sent.'/'.$fax_instance_uuid.".tif"); + //} +// if (file_exists($dir_fax_temp.'/'.$fax_instance_uuid.".pdf")) { +// copy($dir_fax_temp.'/'.$fax_instance_uuid.".pdf ", $dir_fax_sent.'/'.$fax_instance_uuid.".pdf"); +// } + +//send context to the temp log + //echo "Subject: ".$email_subject."\n"; + //echo "From: ".$email_from."\n"; + //echo "Reply-to: ".$email_from."\n"; + //echo "To: ".$email_to."\n"; + //echo "Date: ".$email_date."\n"; + //echo "Transcript: ".$array['message']."\n"; + //echo "Body: ".$email_body."\n"; + +//send email + //ob_start(); + //$sent = !send_email($email_to, $email_subject, $email_body, $email_error, null, null, 3, 3, $email_attachments) ? false : true; + //$response = ob_get_clean(); + //echo $response; + +//save output to + //$fp = fopen(sys_get_temp_dir()."/mailer-app.log", "a"); + +//prepare the output buffers + //ob_end_clean(); + //ob_start(); + +//message divider for log file + //echo "\n\n====================================================\n\n"; + +//get and save the output from the buffer + //$content = ob_get_contents(); //get the output from the buffer + //$content = str_replace("
", "", $content); + + //ob_end_clean(); //clean the buffer + + //fwrite($fp, $content); + //fclose($fp); + + +?> diff --git a/app/fax_queue/root.php b/app/fax_queue/root.php new file mode 100644 index 0000000000..b35ebdf68d --- /dev/null +++ b/app/fax_queue/root.php @@ -0,0 +1,66 @@ +