diff --git a/app/fax/fax_emails.php b/app/fax/fax_emails.php index 1c7cf64b91..f707d8eb19 100644 --- a/app/fax/fax_emails.php +++ b/app/fax/fax_emails.php @@ -26,7 +26,7 @@ */ //includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; +require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/functions/object_to_array.php"; require_once "resources/functions/parse_message.php"; require_once "resources/classes/text.php"; @@ -52,26 +52,6 @@ function arr_to_map(&$arr){ if (!empty($result) && @sizeof($result) != 0) { - //load default settings - $default_settings = load_default_settings(); - - //get event socket connection parameters - $sql = "select event_socket_ip_address, event_socket_port, event_socket_password from v_settings"; - $database = new database; - $row = $database->select($sql, null, 'row'); - $event_socket['ip_address'] = $row['event_socket_ip_address']; - $event_socket['port'] = $row['event_socket_port']; - $event_socket['password'] = $row['event_socket_password']; - unset($sql, $row); - - $fax_cover_font_default = $_SESSION['fax']['cover_font']['text']; - - $fax_allowed_extension_default = arr_to_map($_SESSION['fax']['allowed_extension']); - if($fax_allowed_extension_default == false){ - $tmp = array('.pdf', '.tiff', '.tif'); - $fax_allowed_extension_default = arr_to_map($tmp); - } - foreach ($result as $row) { //get fax server and account connection details $fax_uuid = $row["fax_uuid"]; @@ -95,41 +75,40 @@ if (!empty($result) && @sizeof($result) != 0) { $fax_accountcode = $row["accountcode"]; $fax_toll_allow = $row["fax_toll_allow"]; - //load default settings, then domain settings over top - unset($_SESSION); - $_SESSION = $default_settings; - load_domain_settings($domain_uuid); + //get event socket connection parameters + $setting = new settings(["domain_uuid" => $domain_uuid]); - $fax_cover_font = $_SESSION['fax']['cover_font']['text']; + $fax_cover_font_default =$setting->get('fax','cover_font'); + + $fax_allowed_extension_default = arr_to_map($setting->get('fax','allowed_extension')); + if($fax_allowed_extension_default == false){ + $tmp = array('.pdf', '.tiff', '.tif'); + $fax_allowed_extension_default = arr_to_map($tmp); + } + + $fax_cover_font = $setting->get('fax','cover_font'); if(empty($fax_cover_font)){ $fax_cover_font = $fax_cover_font_default; } - $fax_allowed_extension = arr_to_map($_SESSION['fax']['allowed_extension']); + $fax_allowed_extension = arr_to_map($setting->get('fax','allowed_extension')); if($fax_allowed_extension == false) { $fax_allowed_extension = $fax_allowed_extension_default; } - //load event socket connection parameters - $_SESSION['event_socket_ip_address'] = $event_socket['ip_address']; - $_SESSION['event_socket_port'] = $event_socket['port']; - $_SESSION['event_socket_password'] = $event_socket['password']; - - //get domain name, set local and session variables + //get domain name, set the domain_name variable $sql = "select domain_name from v_domains where domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); $domain_name = $row['domain_name']; - $_SESSION['domain_name'] = $row['domain_name']; - $_SESSION['domain_uuid'] = $domain_uuid; unset($sql, $parameters, $row); //set needed variables - $fax_page_size = $_SESSION['fax']['page_size']['text']; - $fax_resolution = $_SESSION['fax']['resolution']['text']; - $fax_header = $_SESSION['fax']['cover_header']['text']; - $fax_footer = $_SESSION['fax']['cover_footer']['text']; + $fax_page_size = $setting->get('fax','page_size'); + $fax_resolution = $setting->get('fax','resolution'); + $fax_header = $setting->get('fax','cover_header'); + $fax_footer = $setting->get('fax','cover_footer'); $fax_sender = $fax_caller_id_name; //open account connection @@ -232,7 +211,7 @@ if (!empty($result) && @sizeof($result) != 0) { } // set fax directory (used for pdf creation - cover and/or attachments) - $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.(($domain_name != '') ? '/'.$domain_name : null); + $fax_dir = $setting->get('switch','storage').'/fax'.(($domain_name != '') ? '/'.$domain_name : null); //handle attachments (if any) $emailed_files = Array(); @@ -298,86 +277,4 @@ if (!empty($result) && @sizeof($result) != 0) { } } -//functions used above -function load_default_settings() { - $sql = "select * from v_default_settings "; - $sql .= "where default_setting_enabled = 'true' "; - $database = new database; - $result = $database->select($sql, null, 'all'); - //load the settings into an array - if (!empty($result) && @sizeof($result) != 0) { - foreach ($result as $row) { - $name = $row['default_setting_name']; - $category = $row['default_setting_category']; - $subcategory = $row['default_setting_subcategory']; - if (empty($subcategory)) { - if ($name == "array") { - $settings[$category][] = $row['default_setting_value']; - } - else { - $settings[$category][$name] = $row['default_setting_value']; - } - } - else { - if ($name == "array") { - $settings[$category][$subcategory][] = $row['default_setting_value']; - } - else { - $settings[$category][$subcategory][$name] = $row['default_setting_value']; - $settings[$category][$subcategory][$name] = $row['default_setting_value']; - } - } - } - } - unset($sql, $parameters, $result, $row); - return $settings; -} - -function load_domain_settings($domain_uuid) { - if (is_uuid($domain_uuid)) { - $sql = "select * from v_domain_settings "; - $sql .= "where domain_uuid = :domain_uuid "; - $sql .= "and domain_setting_enabled = 'true' "; - $sql .= "order by domain_setting_order asc "; - $parameters['domain_uuid'] = $domain_uuid; - $database = new database; - $result = $database->select($sql, $parameters, 'all'); - if (!empty($result) && @sizeof($result) != 0) { - //unset the arrays that domains are overriding - foreach ($result as $row) { - $name = $row['domain_setting_name']; - $category = $row['domain_setting_category']; - $subcategory = $row['domain_setting_subcategory']; - if ($name == "array") { - unset($_SESSION[$category][$subcategory]); - } - } - //set the settings as a session - foreach ($result as $row) { - $name = $row['domain_setting_name']; - $category = $row['domain_setting_category']; - $subcategory = $row['domain_setting_subcategory']; - if (empty($subcategory)) { - //$$category[$name] = $row['domain_setting_value']; - if ($name == "array") { - $_SESSION[$category][] = $row['domain_setting_value']; - } - else { - $_SESSION[$category][$name] = $row['domain_setting_value']; - } - } - else { - //$$category[$subcategory][$name] = $row['domain_setting_value']; - if ($name == "array") { - $_SESSION[$category][$subcategory][] = $row['domain_setting_value']; - } - else { - $_SESSION[$category][$subcategory][$name] = $row['domain_setting_value']; - } - } - } - } - } -} - ?> diff --git a/app/fax/fax_send.php b/app/fax/fax_send.php index 483f1ed773..a03d2e3b33 100644 --- a/app/fax/fax_send.php +++ b/app/fax/fax_send.php @@ -41,6 +41,16 @@ if (!$included) { require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; + //set the domain_uuid and domain_name + $domain_uuid = $_SESSION['domain_uuid']; + $domain_name = $_SESSION['domain_name']; + $user_uuid = $_SESSION['user_uuid']; + + //get event socket connection parameters + if (empty($setting)) { + $setting = new settings(["domain_uuid" => $domain_uuid]); + } + //check permissions if (permission_exists('fax_send')) { //access granted @@ -69,7 +79,7 @@ if (!$included) { $sql .= "from v_fax "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and fax_uuid = :fax_uuid "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $parameters['domain_uuid'] = $domain_uuid; $parameters['fax_uuid'] = $fax_uuid; } else { @@ -81,9 +91,9 @@ if (!$included) { $sql .= "and f.domain_uuid = :domain_uuid "; $sql .= "and f.fax_uuid = :fax_uuid "; $sql .= "and u.user_uuid = :user_uuid "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $parameters['domain_uuid'] = $domain_uuid; $parameters['fax_uuid'] = $fax_uuid; - $parameters['user_uuid'] = $_SESSION['user_uuid']; + $parameters['user_uuid'] = $user_uuid; } $database = new database; $row = $database->select($sql, $parameters, 'row'); @@ -107,15 +117,12 @@ if (!$included) { } //set the fax directory - if (!empty($_SESSION['switch']['storage']['dir'])) { - $fax_dir = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name']; + if (!empty($setting->get('switch','storage')) { + $fax_dir = $setting->get('switch','storage').'/fax/'.$domain_name; } //set fax cover font to generate pdf - $fax_cover_font = $_SESSION['fax']['cover_font']['text'] ?? null; -} -else { - require_once "resources/classes/event_socket.php"; + $fax_cover_font = $setting->get('fax','cover_font') ?? null; } if (!function_exists('correct_path')) { @@ -159,14 +166,14 @@ if (!function_exists('fax_split_dtmf')) { $dir_fax_temp = $fax_dir.'/'.$fax_extension.'/temp'; //make sure the directories exist - if (!empty($_SESSION['switch']['storage']['dir']) && !is_dir($_SESSION['switch']['storage']['dir'])) { - mkdir($_SESSION['switch']['storage']['dir'], 0770); + if (!empty($setting->get('switch','storage')) && !is_dir($setting->get('switch','storage'))) { + mkdir($setting->get('switch','storage'), 0770); } - if (!empty($_SESSION['switch']['storage']['dir']) && !is_dir($_SESSION['switch']['storage']['dir'].'/fax')) { - mkdir($_SESSION['switch']['storage']['dir'].'/fax', 0770); + if (!empty($setting->get('switch','storage')) && !is_dir($setting->get('switch','storage').'/fax')) { + mkdir($setting->get('switch','storage').'/fax', 0770); } - if (!empty($_SESSION['switch']['storage']['dir']) && !is_dir($_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'])) { - mkdir($_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'], 0770); + if (!empty($setting->get('switch','storage')) && !is_dir($setting->get('switch','storage').'/fax/'.$domain_name)) { + mkdir($setting->get('switch','storage').'/fax/'.$domain_name, 0770); } if (!is_dir($fax_dir.'/'.$fax_extension)) { mkdir($fax_dir.'/'.$fax_extension, 0770); @@ -183,12 +190,17 @@ if (!function_exists('fax_split_dtmf')) { } //check if the domain is enabled -if($_SESSION['domains'][$_SESSION['domain_uuid']]['domain_enabled'] == "1" || $_SESSION['domains'][$_SESSION['domain_uuid']]['domain_enabled'] == "true") { - $domain_enabled = true; -} -else { - $domain_enabled = false; -} + $sql = "select domain_enabled::text from v_domains where domain_uuid = :domain_uuid "; + $parameters['domain_uuid'] = $domain_uuid; + $database = new database; + $row = $database->select($sql, $parameters, 'row'); + if ($row['domain_enabled'] == "true") { + $domain_enabled = true; + } + else { + $domain_enabled = false; + } + unset($sql, $parameters, $row); //clear file status cache clearstatcache(); @@ -389,23 +401,23 @@ else { //logo $display_logo = false; - if (empty($_SESSION['fax']['cover_logo']) || !is_array($_SESSION['fax']['cover_logo'])) { + if (empty($setting->get('fax','cover_logo')) || !is_array($setting->get('fax','cover_logo'))) { $logo = $_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/app/fax/resources/images/logo.jpg"; $display_logo = true; } - else if (is_null($_SESSION['fax']['cover_logo']['text'])) { + else if (is_null($setting->get('fax','cover_logo'))) { $logo = ''; //explicitly empty } - else if ($_SESSION['fax']['cover_logo']['text'] != '') { - if (substr($_SESSION['fax']['cover_logo']['text'], 0, 4) == 'http') { - $logo = $_SESSION['fax']['cover_logo']['text']; + else if ($setting->get('fax','cover_logo') != '') { + if (substr($setting->get('fax','cover_logo'), 0, 4) == 'http') { + $logo = $setting->get('fax','cover_logo'); } - else if (substr($_SESSION['fax']['cover_logo']['text'], 0, 1) == '/') { - if (substr($_SESSION['fax']['cover_logo']['text'], 0, strlen($_SERVER['DOCUMENT_ROOT'])) != $_SERVER['DOCUMENT_ROOT']) { - $logo = $_SERVER['DOCUMENT_ROOT'].$_SESSION['fax']['cover_logo']['text']; + else if (substr($$setting->get('fax','cover_logo'), 0, 1) == '/') { + if (substr($setting->get('fax','cover_logo'), 0, strlen($_SERVER['DOCUMENT_ROOT'])) != $_SERVER['DOCUMENT_ROOT']) { + $logo = $_SERVER['DOCUMENT_ROOT'].$setting->get('fax','cover_logo'); } else { - $logo = $_SESSION['fax']['cover_logo']['text']; + $logo = $setting->get('fax','cover_logo'); } } } @@ -646,9 +658,9 @@ else { } exit; } - + //prepare variables send the fax - $mail_from_address = (isset($_SESSION['fax']['smtp_from']['text'])) ? $_SESSION['fax']['smtp_from']['text'] : $_SESSION['email']['smtp_from']['text']; + $mail_from_address = (!empty($setting->get('fax','smtp_from'))) ? $setting->get('fax','smtp_from') : $setting->get('email','smtp_from'); //get the fax mail to address and fax prefix $sql = "select * from v_fax where fax_uuid = :fax_uuid "; @@ -685,7 +697,7 @@ else { $sql .= ") "; $sql .= "and dialplan_detail_data like 'provider_prefix%' "; $sql .= "and dialplan_detail_enabled = 'true' "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $parameters['domain_uuid'] = $domain_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); $dialplan_detail_data = $row["dialplan_detail_data"]; @@ -702,8 +714,8 @@ else { $common_variables = "fax_queue_uuid=".$fax_queue_uuid.","; $common_variables .= "accountcode='".$fax_accountcode."',"; $common_variables .= "sip_h_accountcode='".$fax_accountcode."',"; - $common_variables .= "domain_uuid=".$_SESSION["domain_uuid"].","; - $common_variables .= "domain_name=".$_SESSION["domain_name"].","; + $common_variables .= "domain_uuid=".$domain_uuid.","; + $common_variables .= "domain_name=".$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."',"; @@ -720,11 +732,11 @@ else { //prepare the fax command $channel_variables["toll_allow"] = !empty($fax_toll_allow) ? $fax_toll_allow : null; - $route_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $fax_prefix . $fax_number, $channel_variables); + $route_array = outbound_route_to_bridge($domain_uuid, $fax_prefix . $fax_number, $channel_variables); if (!empty($route_array) && count($route_array) == 0) { //send the internal call to the registered extension - $fax_uri = "user/".$fax_number."@".$_SESSION['domain_name']; + $fax_uri = "user/".$fax_number."@".$domain_name; $fax_variables = ""; } else { @@ -741,7 +753,7 @@ else { //send the external call $fax_variables = ''; - foreach($_SESSION['fax']['variable'] as $variable) { + foreach($setting->get('fax','variable') as $variable) { $fax_variables .= $variable.","; } } @@ -762,7 +774,7 @@ else { //build an array to add the fax to the queue $array['fax_queue'][0]['fax_queue_uuid'] = $fax_queue_uuid; - $array['fax_queue'][0]['domain_uuid'] = $_SESSION['domain_uuid']; + $array['fax_queue'][0]['domain_uuid'] = $domain_uuid; $array['fax_queue'][0]['fax_uuid'] = $fax_uuid; $array['fax_queue'][0]['fax_date'] = 'now()'; $array['fax_queue'][0]['hostname'] = gethostname(); @@ -814,7 +826,7 @@ if (!$included) { } //add user's uuid to group uuid list to include private (non-shared) contacts - $user_group_uuids[] = $_SESSION["user_uuid"]; + $user_group_uuids[] = $user_uuid; $sql = "select "; $sql .= "c.contact_organization, "; $sql .= "c.contact_name_given, "; @@ -831,7 +843,7 @@ if (!$included) { $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 ($setting->get('contact','permissions') == "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 ("; @@ -856,7 +868,7 @@ if (!$included) { $sql .= ") "; } } - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $parameters['domain_uuid'] = $domain_uuid; $database = new database; $contacts = $database->select($sql, $parameters, 'all'); unset($sql, $parameters, $row); @@ -947,7 +959,7 @@ if (!$included) { echo "