From 6d7e125743a9fc4de46c808af0eb4d31389102ae Mon Sep 17 00:00:00 2001 From: markjcrane Date: Wed, 17 May 2023 10:07:49 -0600 Subject: [PATCH] Fix all PHP 8.1 messages for upgrade.php --- app/call_centers/app_defaults.php | 10 ++-- app/destinations/app_defaults.php | 12 ++--- app/devices/app_defaults.php | 22 ++++---- app/dialplans/resources/classes/dialplan.php | 27 ++++++---- app/email_templates/app_defaults.php | 54 ++++++++++--------- app/fax/app_defaults.php | 20 +++---- app/ivr_menus/app_defaults.php | 18 ++++--- app/number_translations/app_defaults.php | 8 +-- .../resources/classes/number_translations.php | 2 +- app/phrases/app_defaults.php | 8 +-- app/recordings/app_defaults.php | 33 ++++++++---- app/scripts/resources/classes/scripts.php | 4 +- app/sofia_global_settings/app_defaults.php | 2 +- app/vars/app_defaults.php | 4 +- app/voicemail_greetings/app_defaults.php | 31 ++++++----- core/authentication/app_defaults.php | 12 +++-- core/dashboard/app_defaults.php | 8 +-- core/software/app_defaults.php | 4 +- core/upgrade/app_defaults.php | 4 +- resources/classes/database.php | 42 +++++++++------ resources/classes/switch_settings.php | 12 +++++ resources/switch.php | 30 +++++------ 22 files changed, 215 insertions(+), 152 deletions(-) diff --git a/app/call_centers/app_defaults.php b/app/call_centers/app_defaults.php index 7d683ae4b1..cfb76ae96b 100644 --- a/app/call_centers/app_defaults.php +++ b/app/call_centers/app_defaults.php @@ -35,7 +35,7 @@ if ($domains_processed == 1) { $sql .= "and (t.call_center_queue_uuid is null or t.call_center_agent_uuid is null) "; $database = new database; $tiers = $database->select($sql, null, 'all'); - if (is_array($tiers) && @sizeof($tiers) != 0) { + if (!empty($tiers)) { foreach ($tiers as $index => &$row) { if ($row['call_center_queue_uuid'] == null && $row['queue_uuid'] != null) { $array['call_center_tiers'][$index]['call_center_queue_uuid'] = $row['queue_uuid']; @@ -74,7 +74,7 @@ if ($domains_processed == 1) { $database = new database; $call_center_queues = $database->select($sql, null, 'all'); $id = 0; - if (is_array($call_center_queues)) { + if (!empty($call_center_queues)) { foreach ($call_center_queues as $row) { //get the application and data @@ -100,7 +100,7 @@ if ($domains_processed == 1) { $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; - if (is_uuid($row['call_center_queue_uuid'])) { + if (!empty($row['call_center_queue_uuid']) && is_uuid($row['call_center_queue_uuid'])) { $dialplan_xml .= " \n"; } if (is_numeric($row['queue_extension'])) { @@ -111,7 +111,7 @@ if ($domains_processed == 1) { if ($row['queue_time_base_score_sec'] != '') { $dialplan_xml .= " \n"; } - if ($row['queue_greeting'] != '') { + if (!empty($row['queue_greeting'])) { $greeting_array = explode(':', $row['queue_greeting']); if (count($greeting_array) == 1) { $dialplan_xml .= " \n"; @@ -158,7 +158,7 @@ if ($domains_processed == 1) { unset ($prep_statement); //save the array to the database - if (is_array($array)) { + if (!empty($array)) { //add the dialplan permission $p = new permissions; $p->add("dialplan_add", "temp"); diff --git a/app/destinations/app_defaults.php b/app/destinations/app_defaults.php index f48e1d8757..3a39e1d0b7 100644 --- a/app/destinations/app_defaults.php +++ b/app/destinations/app_defaults.php @@ -37,7 +37,7 @@ if ($domains_processed == 1) { $extensions = $database->select($sql, null, 'all'); unset($sql); - if (is_array($extensions) && @sizeof($extensions) != 0) { + if (!empty($extensions)) { foreach($extensions as $row) { $sql = "update v_destinations "; $sql .= "set destination_app = :destination_app, destination_data = :destination_data "; @@ -65,17 +65,17 @@ if ($domains_processed == 1) { //loop through the array foreach ($destinations as $row) { //prepare the actions array - if (isset($row['destination_app']) && $row['destination_data'] != '') { + if (isset($row['destination_app']) && !empty($row['destination_data'])) { $actions[0]['destination_app'] = $row['destination_app']; $actions[0]['destination_data'] = $row['destination_data']; } - if (isset($row['destination_alternate_data']) && $row['destination_alternate_data'] != '') { + if (isset($row['destination_alternate_data']) && !empty($row['destination_alternate_data'])) { $actions[1]['destination_app'] = $row['destination_alternate_app']; $actions[1]['destination_data'] = $row['destination_alternate_data']; } //build the array of destinations - if (is_array($actions)) { + if (!empty($actions)) { $array['destinations'][$z]['destination_uuid'] = $row['destination_uuid']; $array['destinations'][$z]['destination_actions'] = json_encode($actions); $z++; @@ -84,7 +84,7 @@ if ($domains_processed == 1) { //process a chunk of the array if ($row_id === 1000) { //save to the data - if (is_array($array)) { + if (!empty($array)) { //add temporary permissions $p = new permissions; $p->add('destination_edit', 'temp'); @@ -111,7 +111,7 @@ if ($domains_processed == 1) { unset($actions); } - if (is_array($array)) { + if (!empty($array)) { //add temporary permissions $p = new permissions; $p->add('destination_edit', 'temp'); diff --git a/app/devices/app_defaults.php b/app/devices/app_defaults.php index 917dd811f5..e29d3acb5f 100644 --- a/app/devices/app_defaults.php +++ b/app/devices/app_defaults.php @@ -30,7 +30,7 @@ if ($domains_processed == 1) { $sql .= "where enabled is null or enabled = '' "; $database = new database; $device_lines = $database->select($sql, null, 'all'); - if (is_array($device_lines) && @sizeof($device_lines) != 0) { + if (!empty($device_lines)) { $sql = "update v_device_lines set "; $sql .= "enabled = 'true' "; $sql .= "where enabled is null "; @@ -46,7 +46,7 @@ if ($domains_processed == 1) { $sql .= "where label is null "; $database = new database; $device_lines = $database->select($sql, null, 'all'); - if (is_array($device_lines) && @sizeof($device_lines) != 0) { + if (!empty($device_lines)) { foreach($device_lines as $row) { $sql = "update v_device_lines "; $sql .= "set label = user_id "; @@ -62,7 +62,7 @@ if ($domains_processed == 1) { $sql .= "and k.device_key_vendor is null "; $database = new database; $device_keys = $database->select($sql, null, 'all'); - if (is_array($device_keys) && @sizeof($device_keys)) { + if (!empty($device_keys)) { foreach ($device_keys as $index => &$row) { $array['device_keys'][$index]['device_key_uuid'] = $row["device_key_uuid"]; $array['device_keys'][$index]['device_key_vendor'] = $row["device_vendor"]; @@ -95,7 +95,7 @@ if ($domains_processed == 1) { $device_profile_keys = $database->select($sql, null, 'all'); //loop through the device_keys to build the data array - if (is_array($device_profile_keys) && @sizeof($device_profile_keys)) { + if (!empty($device_profile_keys)) { foreach ($device_profile_keys as $index => &$row) { $array['device_profile_keys'][$index]['device_profile_key_uuid'] = $row["device_key_uuid"]; $array['device_profile_keys'][$index]['domain_uuid'] = $row["domain_uuid"]; @@ -114,7 +114,7 @@ if ($domains_processed == 1) { } //save the array - if (is_array($array) && @sizeof($array)) { + if (!empty($array)) { $p = new permissions; $p->add('device_profile_key_add', 'temp'); @@ -142,7 +142,7 @@ if ($domains_processed == 1) { $device_profile_keys = $database->select($sql, null, 'all'); //loop through the device_keys to build the data array - if (is_array($device_profile_keys) && @sizeof($device_profile_keys)) { + if (!empty($device_profile_keys)) { foreach ($device_profile_keys as $index => &$row) { $array['device_profile_settings'][$index]['device_profile_setting_uuid'] = $row["device_setting_uuid"]; $array['device_profile_settings'][$index]['domain_uuid'] = $row["domain_uuid"]; @@ -155,7 +155,7 @@ if ($domains_processed == 1) { } //save the array - if (is_array($array) && @sizeof($array)) { + if (!empty($array)) { $p = new permissions; $p->add('device_profile_setting_add', 'temp'); @@ -192,7 +192,7 @@ if ($domains_processed == 1) { unset($sql, $groups, $row); //build the array - if (is_array($vendors) && @sizeof($vendors) != 0) { + if (!empty($vendors)) { $x = 0; $y = 0; $z = 0; foreach ($vendors as $vendor) { //insert the data into the database @@ -203,7 +203,7 @@ if ($domains_processed == 1) { $array['device_vendors'][$x]['description'] = $vendor['description']; //add the vendor functions - if (is_array($vendor['functions']) && @sizeof($vendor['functions'])) { + if (!empty($vendor['functions'])) { foreach ($vendor['functions'] as $function) { //add the device vendor function @@ -217,7 +217,7 @@ if ($domains_processed == 1) { $array['device_vendor_functions'][$y]['description'] = $function['description']; //add the device vendor function groups - if (is_array($function['groups']) && @sizeof($function['groups']) != 0) { + if (!empty($function['groups'])) { foreach ($function['groups'] as $group_name) { $array['device_vendor_function_groups'][$z]['device_vendor_function_group_uuid'] = uuid(); $array['device_vendor_function_groups'][$z]['device_vendor_function_uuid'] = $device_vendor_function_uuid; @@ -239,7 +239,7 @@ if ($domains_processed == 1) { } //execute - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array)) { $p = new permissions; $p->add('device_vendor_add', 'temp'); $p->add('device_vendor_function_add', 'temp'); diff --git a/app/dialplans/resources/classes/dialplan.php b/app/dialplans/resources/classes/dialplan.php index 2febd323ab..4042fa1198 100644 --- a/app/dialplans/resources/classes/dialplan.php +++ b/app/dialplans/resources/classes/dialplan.php @@ -109,19 +109,23 @@ $array['dialplans'][0]['dialplan_context'] = $this->dialplan_context; $array['dialplans'][0]['dialplan_enabled'] = $this->dialplan_enabled; $array['dialplans'][0]['dialplan_description'] = $this->dialplan_description; + //grant temporary permissions $p = new permissions; $p->add('dialplan_add', 'temp'); + //execute insert $database = new database; $database->app_name = 'dialplans'; $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; $database->save($array); unset($array); + //clear the destinations session array if (isset($_SESSION['destinations']['array'])) { unset($_SESSION['destinations']['array']); } + //revoke temporary permissions $p->delete('dialplan_add', 'temp'); } @@ -133,19 +137,23 @@ if (!empty($this->dialplan_continue)) { $array['dialplans'][0]['dialplan_continue'] = $this->dialplan_continue; } + $array['dialplans'][0]['dialplan_order'] = $this->dialplan_order; $array['dialplans'][0]['dialplan_context'] = $this->dialplan_context; $array['dialplans'][0]['dialplan_enabled'] = $this->dialplan_enabled; $array['dialplans'][0]['dialplan_description'] = $this->dialplan_description; + //grant temporary permissions $p = new permissions; $p->add('dialplan_edit', 'temp'); + //execute update $database = new database; $database->app_name = 'dialplans'; $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; $database->save($array); unset($array); + //revoke temporary permissions $p->delete('dialplan_edit', 'temp'); } @@ -342,16 +350,16 @@ } $y++; - if (is_array($row['action']) || is_array($row['anti-action'])) { + if (!empty($row['action']) || !empty($row['anti-action'])) { $condition_self_closing_tag = false; - if (!is_array($row['action'][0])) { + if (empty($row['action'][0])) { if ($row['action']['@attributes']['application']) { $tmp = $row['action']; unset($row['action']); $row['action'][0] = $tmp; } } - if (!is_array($row['anti-action'][0])) { + if (empty($row['anti-action'][0])) { if ($row['anti-action']['@attributes']['application']) { $tmp = $row['anti-action']; unset($row['anti-action']); @@ -445,7 +453,7 @@ $p->add('dialplan_detail_edit', 'temp'); //save the data - if (is_array($array)) { + if (!empty($array)) { //$database = new database; $database->app_name = 'dialplans'; $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; @@ -475,7 +483,7 @@ $destination_number = trim($destination_number); //check the session array if it doesn't exist then build the array - if (!is_array($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) { + if (empty($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) { //get the outbound routes from the database $sql = "select * "; $sql .= "from v_dialplans as d, "; @@ -535,6 +543,7 @@ $previous_dialplan_uuid = $row['dialplan_uuid']; } } + //set the session array $_SESSION[$_SESSION['domain_uuid']]['outbound_routes'] = $array; } @@ -676,7 +685,7 @@ $sql .= "else 100 end, \n"; $sql .= "s.dialplan_detail_order asc \n"; $database = new database; - $results = $database->select($sql, $parameters, 'all'); + $results = $database->select($sql, $parameters ?? null, 'all'); unset($sql, $parameters); //loop through the results to get the xml from the dialplan_xml field or from dialplan details table @@ -914,8 +923,8 @@ unset($row); // prevent partial dialplan (pass=nil may be error in sql or empty resultset) - if ($pass == false) { - if (count($results)) { + if (isset($pass) && $pass == false) { + if (!empty($results)) { echo 'error while build context: ' . $this->context; } } @@ -953,7 +962,7 @@ //save the dialplan xml if ($this->destination == "database") { - if (is_array($dialplans)) { + if (!empty($dialplans)) { $x = 0; foreach ($dialplans as $key => $value) { //build update array diff --git a/app/email_templates/app_defaults.php b/app/email_templates/app_defaults.php index fa91451d6a..0a7a07e909 100644 --- a/app/email_templates/app_defaults.php +++ b/app/email_templates/app_defaults.php @@ -34,9 +34,9 @@ $array['email_templates'][$x]['template_category'] = 'voicemail'; $array['email_templates'][$x]['template_subcategory'] = 'default'; $array['email_templates'][$x]['template_subject'] = 'Sprachnachricht von ${caller_id_name} <${caller_id_number}> ${message_duration}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; - $array['email_templates'][$x]['template_body'] = "Neue Sprachnachricht
\n"; + $array['email_templates'][$x]['template_body'] .= "Neue Sprachnachricht
\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; $array['email_templates'][$x]['template_body'] .= "Nebenstelle \${voicemail_name_formatted}
\n"; $array['email_templates'][$x]['template_body'] .= "Anrufer \${caller_id_number}
\n"; @@ -69,9 +69,9 @@ $array['email_templates'][$x]['template_category'] = 'voicemail'; $array['email_templates'][$x]['template_subcategory'] = 'default'; $array['email_templates'][$x]['template_subject'] = 'Sprachnachricht von ${caller_id_name} <${caller_id_number}> ${message_duration}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; - $array['email_templates'][$x]['template_body'] = "Neue Sprachnachricht
\n"; + $array['email_templates'][$x]['template_body'] .= "Neue Sprachnachricht
\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; $array['email_templates'][$x]['template_body'] .= "Nebenstelle \${voicemail_name_formatted}
\n"; $array['email_templates'][$x]['template_body'] .= "Anrufer \${caller_id_number}
\n"; @@ -104,7 +104,7 @@ $array['email_templates'][$x]['template_category'] = 'voicemail'; $array['email_templates'][$x]['template_subcategory'] = 'default'; $array['email_templates'][$x]['template_subject'] = 'Voicemail from ${caller_id_name} <${caller_id_number}> ${message_duration}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "From \${caller_id_name} \${caller_id_number}
\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; @@ -139,7 +139,7 @@ $array['email_templates'][$x]['template_category'] = 'voicemail'; $array['email_templates'][$x]['template_subcategory'] = 'transcription'; $array['email_templates'][$x]['template_subject'] = 'Voicemail from ${caller_id_name} <${caller_id_number}> ${message_duration}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "Voicemail from \${caller_id_name} \${caller_id_number}
\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; @@ -180,7 +180,7 @@ $array['email_templates'][$x]['template_category'] = 'voicemail'; $array['email_templates'][$x]['template_subcategory'] = 'default'; $array['email_templates'][$x]['template_subject'] = 'Voicemail from ${caller_id_name} <${caller_id_number}> ${message_duration}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "Voicemail from \${caller_id_name} \${caller_id_number}
\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; @@ -215,7 +215,7 @@ $array['email_templates'][$x]['template_category'] = 'voicemail'; $array['email_templates'][$x]['template_subcategory'] = 'transcription'; $array['email_templates'][$x]['template_subject'] = 'Voicemail from ${caller_id_name} <${caller_id_number}> ${message_duration}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "Voicemail from \${caller_id_name} \${caller_id_number}
\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; @@ -256,9 +256,9 @@ $array['email_templates'][$x]['template_category'] = 'missed'; $array['email_templates'][$x]['template_subcategory'] = 'default'; $array['email_templates'][$x]['template_subject'] = 'Missed Call from ${caller_id_name} <${caller_id_number}>'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; - $array['email_templates'][$x]['template_body'] = "Missed Call from \${caller_id_name} <\${caller_id_number}> to \${sip_to_user} ext \${dialed_user}\n"; + $array['email_templates'][$x]['template_body'] .= "Missed Call from \${caller_id_name} <\${caller_id_number}> to \${sip_to_user} ext \${dialed_user}\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_type'] = 'html'; @@ -281,7 +281,7 @@ $array['email_templates'][$x]['template_category'] = 'missed'; $array['email_templates'][$x]['template_subcategory'] = 'default'; $array['email_templates'][$x]['template_subject'] = 'Missed Call from ${caller_id_name} <${caller_id_number}>'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "Missed Call from \${caller_id_name} <\${caller_id_number}> to \${sip_to_user} ext \${dialed_user}\n"; $array['email_templates'][$x]['template_body'] .= "\n"; @@ -295,7 +295,7 @@ $array['email_templates'][$x]['template_category'] = 'missed'; $array['email_templates'][$x]['template_subcategory'] = 'default'; $array['email_templates'][$x]['template_subject'] = 'Missed Call from ${caller_id_name} <${caller_id_number}>'; - $array['email_templates'][$x]['template_body'] .= "Missed Call from \${caller_id_name} <\${caller_id_number}> to \${sip_to_user} ext \${dialed_user}\n"; + $array['email_templates'][$x]['template_body'] = "Missed Call from \${caller_id_name} <\${caller_id_number}> to \${sip_to_user} ext \${dialed_user}\n"; $array['email_templates'][$x]['template_type'] = 'text'; $array['email_templates'][$x]['template_enabled'] = 'false'; $array['email_templates'][$x]['template_description'] = ''; @@ -306,7 +306,7 @@ $array['email_templates'][$x]['template_category'] = 'voicemail'; $array['email_templates'][$x]['template_subcategory'] = 'default'; $array['email_templates'][$x]['template_subject'] = 'Messagerie vocale à partir de ${caller_id_name} <${caller_id_number}> ${message_duration}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "Messagerie vocale à partir de \${caller_id_name} \${caller_id_number}
\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; @@ -340,7 +340,7 @@ $array['email_templates'][$x]['template_category'] = 'missed'; $array['email_templates'][$x]['template_subcategory'] = 'default'; $array['email_templates'][$x]['template_subject'] = 'Appel manqué de ${caller_id_name} <${caller_id_number}>'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "Appel manqué de \${caller_id_name} <\${caller_id_number}> À \${sip_to_user} ext \${dialed_user}\n"; $array['email_templates'][$x]['template_body'] .= "\n"; @@ -354,7 +354,7 @@ $array['email_templates'][$x]['template_category'] = 'missed'; $array['email_templates'][$x]['template_subcategory'] = 'default'; $array['email_templates'][$x]['template_subject'] = 'Appel manqué de ${caller_id_name} <${caller_id_number}>'; - $array['email_templates'][$x]['template_body'] .= "Appel manqué de \${caller_id_name} <\${caller_id_number}> À \${sip_to_user} ext \${dialed_user}\n"; + $array['email_templates'][$x]['template_body'] = "Appel manqué de \${caller_id_name} <\${caller_id_number}> À \${sip_to_user} ext \${dialed_user}\n"; $array['email_templates'][$x]['template_type'] = 'text'; $array['email_templates'][$x]['template_enabled'] = 'false'; $array['email_templates'][$x]['template_description'] = ''; @@ -365,7 +365,7 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'success_default'; $array['email_templates'][$x]['template_subject'] = 'Subject, Fax to: ${number_dialed} SENT'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "We are happy to report the fax was sent successfully. It has been attached for your records.\n"; $array['email_templates'][$x]['template_body'] .= "\n"; @@ -379,7 +379,7 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'fail_default'; $array['email_templates'][$x]['template_subject'] = 'Fax to: ${number_dialed} has Failed'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "We are sorry the fax failed to go through. It has been attached. Please check the number \${number_dialed}, and if it was correct you might consider emailing it instead.\n"; $array['email_templates'][$x]['template_body'] .= "\n"; @@ -393,7 +393,7 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'fail_busy'; $array['email_templates'][$x]['template_subject'] = 'Fax to: ${number_dialed} was Busy'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "We tried sending, but the call was busy \${fax_busy_attempts} of those times.\n"; $array['email_templates'][$x]['template_body'] .= "\n"; @@ -407,7 +407,7 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'fail_invalid'; $array['email_templates'][$x]['template_subject'] = 'Fax to: ${number_dialed} was Invalid'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "We tried sending, but the number entered was not a working phone number.\n"; $array['email_templates'][$x]['template_body'] .= "\n"; @@ -422,7 +422,7 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'success_default'; $array['email_templates'][$x]['template_subject'] = 'Subject, Fax to: ${number_dialed} SENT'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "We are happy to report the fax was sent successfully. It has been attached for your records.\n"; $array['email_templates'][$x]['template_body'] .= "\n"; @@ -436,7 +436,7 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'fail_default'; $array['email_templates'][$x]['template_subject'] = 'Fax to: ${number_dialed} has Failed'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "We are sorry the fax failed to go through. It has been attached. Please check the number \${number_dialed}, and if it was correct you might consider emailing it instead.\n"; $array['email_templates'][$x]['template_body'] .= "\n"; @@ -450,7 +450,7 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'fail_busy'; $array['email_templates'][$x]['template_subject'] = 'Fax to: ${number_dialed} was Busy'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "We tried sending, but the call was busy \${fax_busy_attempts} of those times.\n"; $array['email_templates'][$x]['template_body'] .= "\n"; @@ -464,7 +464,7 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'fail_invalid'; $array['email_templates'][$x]['template_subject'] = 'Fax to: ${number_dialed} was Invalid'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "We tried sending, but the number entered was not a working phone number.\n"; $array['email_templates'][$x]['template_body'] .= "\n"; @@ -482,7 +482,7 @@ } //add the email templates to the database - if (is_array($uuids) && @sizeof($uuids) != 0) { + if (!empty($uuids)) { $sql = "select * from v_email_templates where "; foreach ($uuids as $index => $uuid) { $sql_where[] = "email_template_uuid = :email_template_uuid_".$index; @@ -507,7 +507,7 @@ } //add the missing email templates - if (is_array($array['email_templates']) && @sizeof($array['email_templates']) != 0) { + if (!empty($array['email_templates'])) { //add the temporary permission $p = new permissions; $p->add("email_template_add", 'temp'); @@ -526,7 +526,9 @@ } //remove the array - unset($array); + if (!empty($array)) { + unset($array); + } } diff --git a/app/fax/app_defaults.php b/app/fax/app_defaults.php index 0f978243e6..ba415caead 100644 --- a/app/fax/app_defaults.php +++ b/app/fax/app_defaults.php @@ -11,10 +11,10 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'inbound'; $array['email_templates'][$x]['template_subject'] = 'FAX Received: ${fax_subject_tag} ${fax_file_name}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; - $array['email_templates'][$x]['template_body'] = "
Fax Received

"; + $array['email_templates'][$x]['template_body'] .= "
Fax Received

"; $array['email_templates'][$x]['template_body'] .= "Name: \${fax_file_name}
"; $array['email_templates'][$x]['template_body'] .= "Extension: \${fax_extension}
"; $array['email_templates'][$x]['template_body'] .= "Messages: \${fax_messages}
"; @@ -30,10 +30,10 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'relay'; $array['email_templates'][$x]['template_subject'] = 'FAX Received: ${fax_subject_tag} ${fax_file_name}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; - $array['email_templates'][$x]['template_body'] = "
Fax Received

"; + $array['email_templates'][$x]['template_body'] .= "
Fax Received

"; $array['email_templates'][$x]['template_body'] .= "Name: \${fax_file_name}
"; $array['email_templates'][$x]['template_body'] .= "Extension: \${fax_extension}
"; $array['email_templates'][$x]['template_body'] .= "Messages: \${fax_messages}
"; @@ -50,10 +50,10 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'inbound'; $array['email_templates'][$x]['template_subject'] = 'FAX Received: ${fax_subject_tag} ${fax_file_name}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; - $array['email_templates'][$x]['template_body'] = "
Fax Received

"; + $array['email_templates'][$x]['template_body'] .= "
Fax Received

"; $array['email_templates'][$x]['template_body'] .= "Name: \${fax_file_name}
"; $array['email_templates'][$x]['template_body'] .= "Extension: \${fax_extension}
"; $array['email_templates'][$x]['template_body'] .= "Messages: \${fax_messages}
"; @@ -69,10 +69,10 @@ $array['email_templates'][$x]['template_category'] = 'fax'; $array['email_templates'][$x]['template_subcategory'] = 'relay'; $array['email_templates'][$x]['template_subject'] = 'FAX Received: ${fax_subject_tag} ${fax_file_name}'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= "\n"; $array['email_templates'][$x]['template_body'] .= "
\n"; - $array['email_templates'][$x]['template_body'] = "
Fax Received

"; + $array['email_templates'][$x]['template_body'] .= "
Fax Received

"; $array['email_templates'][$x]['template_body'] .= "Name: \${fax_file_name}
"; $array['email_templates'][$x]['template_body'] .= "Extension: \${fax_extension}
"; $array['email_templates'][$x]['template_body'] .= "Messages: \${fax_messages}
"; @@ -91,7 +91,7 @@ } //add the email templates to the database - if (is_array($uuids) && @sizeof($uuids) != 0) { + if (!empty($uuids)) { $sql = "select * from v_email_templates where "; foreach ($uuids as $index => $uuid) { $sql_where[] = "email_template_uuid = :email_template_uuid_".$index; @@ -116,7 +116,7 @@ } //add the missing email templates - if (is_array($array['email_templates']) && @sizeof($array['email_templates']) != 0) { + if (!empty($array['email_templates'])) { //add the temporary permission $p = new permissions; $p->add("email_template_add", 'temp'); diff --git a/app/ivr_menus/app_defaults.php b/app/ivr_menus/app_defaults.php index 307bf9a9f4..2f8edab382 100644 --- a/app/ivr_menus/app_defaults.php +++ b/app/ivr_menus/app_defaults.php @@ -33,7 +33,7 @@ if ($domains_processed == 1) { $ivr_menus = $database->select($sql, null, 'all'); unset($sql); - if (is_array($ivr_menus)) { + if (!empty($ivr_menus)) { //get the domain list $sql = "select * from v_domains "; @@ -42,16 +42,18 @@ if ($domains_processed == 1) { //update the ivr menu context $x = 0; - foreach ($ivr_menus as $row) { - foreach ($domains as $domain) { - if ($row['domain_uuid'] == $domain['domain_uuid']) { - $array['ivr_menus'][$x]['ivr_menu_uuid'] = $row['ivr_menu_uuid']; - $array['ivr_menus'][$x]['ivr_menu_context'] = $domain['domain_name']; - $x++; + if (!empty($ivr_menus)) { + foreach ($ivr_menus as $row) { + foreach ($domains as $domain) { + if ($row['domain_uuid'] == $domain['domain_uuid']) { + $array['ivr_menus'][$x]['ivr_menu_uuid'] = $row['ivr_menu_uuid']; + $array['ivr_menus'][$x]['ivr_menu_context'] = $domain['domain_name']; + $x++; + } } } } - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array)) { $p = new permissions; $p->add('ivr_menu_edit', 'temp'); diff --git a/app/number_translations/app_defaults.php b/app/number_translations/app_defaults.php index 0074c0d7dc..7d9da76c09 100644 --- a/app/number_translations/app_defaults.php +++ b/app/number_translations/app_defaults.php @@ -34,25 +34,27 @@ //process the xml files foreach ($xml_list as &$xml_file) { //get and parse the xml - $number_translation->display_type = $display_type; $number_translation->xml = file_get_contents($xml_file); $number_translation->import(); } //check for existing configuration - if (file_exists($_SESSION['switch']['conf']['dir']."/autoload_configs/translate.conf.xml")) { + if (!empty($_SESSION['switch']['conf']['dir']) && file_exists($_SESSION['switch']['conf']['dir']."/autoload_configs/translate.conf.xml")) { //import existing data $xml = file_get_contents($_SESSION['switch']['conf']['dir']."/autoload_configs/translate.conf.xml"); + //convert the xml string to an xml object $xml = simplexml_load_string($xml); + //convert to json $json = json_encode($xml); + //convert to an array $number_translations = json_decode($json, true); if (array_key_exists('include', $number_translations)) { $number_translations = $number_translations['include']; } - if ($number_translations['configuration']['@attributes']['autogenerated'] != 'true') { + if (!empty($number_translations['configuration']) && $number_translations['configuration']['@attributes']['autogenerated'] != 'true') { foreach ($number_translations['configuration']['profiles']['profile'] as $profile) { $json = json_encode($profile); $number_translation->display_type = $display_type; diff --git a/app/number_translations/resources/classes/number_translations.php b/app/number_translations/resources/classes/number_translations.php index be5f3ed3fd..6e1ab86bcb 100644 --- a/app/number_translations/resources/classes/number_translations.php +++ b/app/number_translations/resources/classes/number_translations.php @@ -127,7 +127,7 @@ if (!class_exists('number_translations')) { $database->app_uuid = '6ad54de6-4909-11e7-a919-92ebcb67fe33'; $database->save($array); unset($array); - if ($this->display_type == "text") { + if (!empty($this->display_type) && $this->display_type == "text") { if ($database->message['code'] != '200') { echo "number_translation:".$number_translation['@attributes']['name'].": failed: ".$database->message['message']."\n"; } diff --git a/app/phrases/app_defaults.php b/app/phrases/app_defaults.php index 5b0038b0c3..fa31dddd71 100644 --- a/app/phrases/app_defaults.php +++ b/app/phrases/app_defaults.php @@ -65,7 +65,7 @@ if ($domains_processed == 1) { */ //if base64, convert existing incompatible phrases - if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { + if (!empty($_SESSION['recordings']['storage_type']['text']) && $_SESSION['recordings']['storage_type']['text'] == 'base64') { $sql = "select phrase_detail_uuid, phrase_detail_data "; $sql .= "from v_phrase_details where phrase_detail_function = 'play-file' "; $database = new database; @@ -100,7 +100,7 @@ if ($domains_processed == 1) { } //if not base64, revert base64 phrases to standard method - else if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { + else if (!empty($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] != 'base64') { $sql = "select phrase_detail_uuid, phrase_detail_data "; $sql .= "from v_phrase_details where "; $sql .= "phrase_detail_function = 'execute' "; @@ -121,7 +121,7 @@ if ($domains_processed == 1) { $array['phrase_details'][$index]['phrase_detail_function'] = 'play-file'; $array['phrase_details'][$index]['phrase_detail_data'] = $phrase_detail_data; } - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array)) { $p = new permissions; $p->add('phrase_detail_edit', 'temp'); @@ -149,7 +149,7 @@ if ($domains_processed == 1) { $database = new database; $result = $database->select($sql, null, 'all'); //delete memcache var - if (is_array($result) && @sizeof($result) != 0) { + if (!empty($result)) { foreach ($result as $row) { //clear the cache $cache = new cache; diff --git a/app/recordings/app_defaults.php b/app/recordings/app_defaults.php index 64faa9b454..52c2156a07 100644 --- a/app/recordings/app_defaults.php +++ b/app/recordings/app_defaults.php @@ -25,7 +25,7 @@ */ //if the recordings directory doesn't exist then create it - if (is_array($_SESSION['switch']['recordings']) && !empty($_SESSION['switch']['recordings']['dir']."/".$domain_name)) { + if (!empty($_SESSION['switch']['recordings']) && !empty($_SESSION['switch']['recordings']['dir']."/".$domain_name)) { if (!is_readable($_SESSION['switch']['recordings']['dir']."/".$domain_name)) { mkdir($_SESSION['switch']['recordings']['dir']."/".$domain_name, 0770, true); } @@ -35,7 +35,7 @@ if ($domains_processed == 1) { //if base64, populate from existing recording files, then remove - if (is_array($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] == 'base64') { + if (!empty($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] == 'base64') { //get recordings without base64 in db $sql = "select recording_uuid, domain_uuid, recording_filename "; $sql .= "from v_recordings "; @@ -45,11 +45,14 @@ $result = $database->select($sql, null, 'all'); if (is_array($result) && @sizeof($result) != 0) { foreach ($result as &$row) { - $recording_uuid = $row['recording_uuid']; - $recording_domain_uuid = $row['domain_uuid']; - $recording_filename = $row['recording_filename']; + //set the variables + $recording_uuid = $row['recording_uuid']; + $recording_domain_uuid = $row['domain_uuid']; + $recording_filename = $row['recording_filename']; + //set recording directory $recording_directory = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name; + //encode recording file (if exists) if (file_exists($recording_directory.'/'.$recording_filename)) { //build array @@ -76,41 +79,49 @@ unset($sql, $result, $row); } //if not base64, decode to local files, remove base64 data from db - else if (is_array($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] != 'base64') { + else if (!empty($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] != 'base64') { //get recordings with base64 in db $sql = "select recording_uuid, domain_uuid, recording_filename, recording_base64 "; $sql .= "from v_recordings "; $sql .= "where recording_base64 is not null "; $database = new database; $result = $database->select($sql, null, 'all'); - if (is_array($result) && @sizeof($result) != 0) { + if (!empty($result)) { foreach ($result as &$row) { - $recording_uuid = $row['recording_uuid']; - $recording_domain_uuid = $row['domain_uuid']; - $recording_filename = $row['recording_filename']; - $recording_base64 = $row['recording_base64']; + //set the variables + $recording_uuid = $row['recording_uuid']; + $recording_domain_uuid = $row['domain_uuid']; + $recording_filename = $row['recording_filename']; + $recording_base64 = $row['recording_base64']; + //set recording directory $recording_directory = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name; + //remove local file, if any if (file_exists($recording_directory.'/'.$recording_filename)) { @unlink($recording_directory.'/'.$recording_filename); } + //decode base64, save to local file $recording_decoded = base64_decode($recording_base64); file_put_contents($recording_directory.'/'.$recording_filename, $recording_decoded); + //build array $array['recordings'][0]['recording_uuid'] = $recording_uuid; $array['recordings'][0]['domain_uuid'] = $recording_domain_uuid; $array['recordings'][0]['recording_base64'] = null; + //grant temporary permissions $p = new permissions; $p->add('recording_edit', 'temp'); + //update recording record $database = new database; $database->app_name = 'recordings'; $database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e'; $database->save($array, false); unset($array); + //revoke temporary permissions $p->delete('recording_edit', 'temp'); } diff --git a/app/scripts/resources/classes/scripts.php b/app/scripts/resources/classes/scripts.php index 2d42e7d247..8819b490cb 100644 --- a/app/scripts/resources/classes/scripts.php +++ b/app/scripts/resources/classes/scripts.php @@ -85,9 +85,9 @@ if (!class_exists('scripts')) { * Copy the switch scripts from the web directory to the switch directory */ public function copy_files() { - if (is_array($_SESSION['switch']['scripts'])) { + if (!empty($_SESSION['switch']['scripts'])) { $destination_directory = $_SESSION['switch']['scripts']['dir']; - if (file_exists($destination_directory)) { + if ($destination_directory != '' && file_exists($destination_directory)) { //get the source directory if (file_exists('/usr/share/examples/fusionpbx/scripts')) { $source_directory = '/usr/share/examples/fusionpbx/scripts'; diff --git a/app/sofia_global_settings/app_defaults.php b/app/sofia_global_settings/app_defaults.php index b46ed82dc6..766ab9a8c9 100644 --- a/app/sofia_global_settings/app_defaults.php +++ b/app/sofia_global_settings/app_defaults.php @@ -68,7 +68,7 @@ if ($domains_processed == 1) { } //add settings that are not in the database - if (is_array($array) && count($array) > 0) { + if (!empty($array)) { //grant temporary permissions $p = new permissions; $p->add('sofia_global_setting_add', 'temp'); diff --git a/app/vars/app_defaults.php b/app/vars/app_defaults.php index 7f35f3ce78..0127245fc0 100644 --- a/app/vars/app_defaults.php +++ b/app/vars/app_defaults.php @@ -175,16 +175,18 @@ if ($domains_processed == 1) { unset($num_rows, $countries); } - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array)) { //grant temporary permissions $p = new permissions; $p->add("var_add", "temp"); + //execute inserts $database = new database; $database->app_name = 'vars'; $database->app_uuid = '54e08402-c1b8-0a9d-a30a-f569fc174dd8'; $database->save($array, false); unset($array); + //revoke temporary permissions $p->delete("var_add", "temp"); } diff --git a/app/voicemail_greetings/app_defaults.php b/app/voicemail_greetings/app_defaults.php index 7c233f1d4e..369030e94f 100644 --- a/app/voicemail_greetings/app_defaults.php +++ b/app/voicemail_greetings/app_defaults.php @@ -40,7 +40,7 @@ if ($domains_processed == 1) { $sql .= "where greeting_id is null "; $database = new database; $result = $database->select($sql, null, 'all'); - if (is_array($result) && @sizeof($result) != 0) { + if (!empty($result)) { foreach ($result as $x => &$row) { $voicemail_greeting_uuid = $row['voicemail_greeting_uuid']; $greeting_id = preg_replace('{\D}', '', $row['greeting_filename']); @@ -49,7 +49,7 @@ if ($domains_processed == 1) { $array['voicemail_greetings'][$x]['greeting_id'] = $greeting_id; unset($voicemail_greeting_uuid, $greeting_id); } - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array)) { //grant temporary permissions $p = new permissions; $p->add('voicemail_greeting_edit', 'temp'); @@ -66,7 +66,7 @@ if ($domains_processed == 1) { unset($sql, $result, $x, $row); //if base64, populate from existing greeting files, then remove - if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') { + if (!empty($_SESSION['voicemail']['storage_type']['text']) && $_SESSION['voicemail']['storage_type']['text'] == 'base64') { //get greetings without base64 in db $sql = "select voicemail_greeting_uuid, domain_uuid, voicemail_id, greeting_filename "; $sql .= "from v_voicemail_greetings "; @@ -74,7 +74,7 @@ if ($domains_processed == 1) { $sql .= "or greeting_base64 = '' "; $database = new database; $result = $database->select($sql, null, 'all'); - if (is_array($result) && @sizeof($result) != 0) { + if (!empty($result)) { foreach ($result as $x => &$row) { $voicemail_greeting_uuid = $row['voicemail_greeting_uuid']; $greeting_domain_uuid = $row['domain_uuid']; @@ -91,7 +91,7 @@ if ($domains_processed == 1) { @unlink($greeting_directory.'/'.$greeting_filename); } } - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array)) { //grant temporary permissions $p = new permissions; $p->add('voicemail_greeting_edit', 'temp'); @@ -109,7 +109,7 @@ if ($domains_processed == 1) { } //if not base64, decode to local files, remove base64 data from db - else if ($_SESSION['voicemail']['storage_type']['text'] != 'base64') { + else if (!empty($_SESSION['voicemail']['storage_type']['text']) && $_SESSION['voicemail']['storage_type']['text'] != 'base64') { //get greetings with base64 in db $sql = "select voicemail_greeting_uuid, domain_uuid, voicemail_id, greeting_filename, greeting_base64 "; $sql .= "from v_voicemail_greetings "; @@ -118,31 +118,38 @@ if ($domains_processed == 1) { $result = $database->select($sql, null, 'all'); if (is_array($result) && @sizeof($result) != 0) { foreach ($result as $x => &$row) { - $voicemail_greeting_uuid = $row['voicemail_greeting_uuid']; - $greeting_domain_uuid = $row['domain_uuid']; - $voicemail_id = $row['voicemail_id']; - $greeting_filename = $row['greeting_filename']; - $greeting_base64 = $row['greeting_base64']; + //set variables + $voicemail_greeting_uuid = $row['voicemail_greeting_uuid']; + $greeting_domain_uuid = $row['domain_uuid']; + $voicemail_id = $row['voicemail_id']; + $greeting_filename = $row['greeting_filename']; + $greeting_base64 = $row['greeting_base64']; + //set greeting directory $greeting_directory = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domains'][$greeting_domain_uuid]['domain_name'].'/'.$voicemail_id; + //remove local file, if any @unlink($greeting_directory.'/'.$greeting_filename); + //build update array $array['voicemail_greetings'][$x]['voicemail_greeting_uuid'] = $voicemail_greeting_uuid; $array['voicemail_greetings'][$x]['greeting_base64'] = null; + //decode base64, save to local file file_put_contents($greeting_directory.'/'.$greeting_filename, base64_decode($greeting_base64)); } - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array)) { //grant temporary permissions $p = new permissions; $p->add('voicemail_greeting_edit', 'temp'); + //execute update $database = new database; $database->app_name = 'voicemail_greetings'; $database->app_uuid = 'e4b4fbee-9e4d-8e46-3810-91ba663db0c2'; $database->save($array, false); unset($array); + //revoke temporary permissions $p->delete('voicemail_greeting_edit', 'temp'); } diff --git a/core/authentication/app_defaults.php b/core/authentication/app_defaults.php index dae50a3e13..8ec8732555 100644 --- a/core/authentication/app_defaults.php +++ b/core/authentication/app_defaults.php @@ -11,7 +11,7 @@ $array['email_templates'][$x]['template_category'] = 'authentication'; $array['email_templates'][$x]['template_subcategory'] = 'email'; $array['email_templates'][$x]['template_subject'] = 'Authentication Code'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= " \n"; $array['email_templates'][$x]['template_body'] .= "
\n"; $array['email_templates'][$x]['template_body'] .= "
Security Code

\n"; @@ -28,7 +28,7 @@ $array['email_templates'][$x]['template_category'] = 'authentication'; $array['email_templates'][$x]['template_subcategory'] = 'email'; $array['email_templates'][$x]['template_subject'] = 'Authentication Code'; - $array['email_templates'][$x]['template_body'] .= "\n"; + $array['email_templates'][$x]['template_body'] = "\n"; $array['email_templates'][$x]['template_body'] .= " \n"; $array['email_templates'][$x]['template_body'] .= "
\n"; $array['email_templates'][$x]['template_body'] .= "
Security Code

\n"; @@ -49,7 +49,7 @@ } //add the email templates to the database - if (is_array($uuids) && @sizeof($uuids) != 0) { + if (!empty($uuids)) { $sql = "select * from v_email_templates where "; foreach ($uuids as $index => $uuid) { $sql_where[] = "email_template_uuid = :email_template_uuid_".$index; @@ -74,7 +74,7 @@ } //add the missing email templates - if (is_array($array['email_templates']) && @sizeof($array['email_templates']) != 0) { + if (!empty($array['email_templates'])) { //add the temporary permission $p = new permissions; $p->add("email_template_add", 'temp'); @@ -93,7 +93,9 @@ } //remove the array - unset($array); + if (!empty($array)) { + unset($array); + } } diff --git a/core/dashboard/app_defaults.php b/core/dashboard/app_defaults.php index fdb1cfab28..5cf6992615 100644 --- a/core/dashboard/app_defaults.php +++ b/core/dashboard/app_defaults.php @@ -15,7 +15,7 @@ if ($domains_processed == 1) { $sql = "select * from v_groups "; $sql .= "where domain_uuid is null "; $database = new database; - $groups = $database->select($sql, $parameters, 'all'); + $groups = $database->select($sql, null, 'all'); //get the dashboard $sql = "select "; @@ -27,7 +27,7 @@ if ($domains_processed == 1) { $sql .= "dashboard_description "; $sql .= "from v_dashboard "; $database = new database; - $dashboard_widgets = $database->select($sql, $parameters, 'all'); + $dashboard_widgets = $database->select($sql, null, 'all'); unset($sql, $parameters); //add the dashboard widgets @@ -60,7 +60,7 @@ if ($domains_processed == 1) { $array['dashboard'][$x]['dashboard_enabled'] = $row['dashboard_enabled']; $array['dashboard'][$x]['dashboard_description'] = $row['dashboard_description']; $y = 0; - if (is_array($row['dashboard_groups'])) { + if (!empty($row['dashboard_groups'])) { foreach ($row['dashboard_groups'] as $row) { if (isset($row['group_name'])) { foreach($groups as $field) { @@ -84,7 +84,7 @@ if ($domains_processed == 1) { $p->add('dashboard_group_add', 'temp'); //save the data - if (is_array($array)) { + if (!empty($array)) { $database = new database; $database->app_name = 'dashboard'; $database->app_uuid = '55533bef-4f04-434a-92af-999c1e9927f7'; diff --git a/core/software/app_defaults.php b/core/software/app_defaults.php index 32d2b0dba3..6742ea399b 100644 --- a/core/software/app_defaults.php +++ b/core/software/app_defaults.php @@ -33,7 +33,7 @@ if ($domains_processed == 1) { $sql = "select software_version from v_software "; $database = new database; $software_version = $database->select($sql, null, 'column'); - if ($software_version == '') { + if (empty($software_version)) { $array['software'][0]['software_uuid'] = '7de057e7-333b-4ebf-9466-315ae7d44efd'; $array['software'][0]['software_name'] = 'FusionPBX'; $array['software'][0]['software_url'] = 'https://www.fusionpbx.com'; @@ -45,7 +45,7 @@ if ($domains_processed == 1) { } //save the data in the array - if (is_array($array) && count($array) > 0) { + if (!empty($array)) { //add the temporary permission $p = new permissions; $p->add("software_add", 'temp'); diff --git a/core/upgrade/app_defaults.php b/core/upgrade/app_defaults.php index bd3fb275b1..0acf6f3220 100644 --- a/core/upgrade/app_defaults.php +++ b/core/upgrade/app_defaults.php @@ -27,7 +27,9 @@ if ($domains_processed == 1) { //remove smarty cache - system('rm '.sys_get_temp_dir().'/*.php'); + foreach(glob(sys_get_temp_dir().'*.php') as $file) { + unlink($file); + } //ensure the login message is set, if new message exists $sql = "select count(*) as num_rows from v_default_settings "; diff --git a/resources/classes/database.php b/resources/classes/database.php index 1b683f5fef..40eaff5144 100644 --- a/resources/classes/database.php +++ b/resources/classes/database.php @@ -1299,7 +1299,9 @@ $transaction_type = 'delete'; //get the UUIDs - $user_uuid = $_SESSION['user_uuid']; + if (!empty($_SESSION['user_uuid'])) { + $user_uuid = $_SESSION['user_uuid']; + } //log the transaction results if (file_exists($_SERVER["PROJECT_ROOT"]."/app/database_transactions/app_config.php")) { @@ -2131,7 +2133,7 @@ } elseif ($array_value === "user_uuid()") { $sql .= ':'.$array_key.", "; - $params[$array_key] = $_SESSION['user_uuid']; + $params[$array_key] = $_SESSION['user_uuid'] ?? null; } elseif ($array_value === "remote_address()") { $sql .= ':'.$array_key.", "; @@ -2151,7 +2153,9 @@ $sql .= ");"; //add insert user parameter - $params['insert_user'] = $_SESSION['user_uuid']; + if (!empty($_SESSION['user_uuid'])) { + $params['insert_user'] = $_SESSION['uer_uuid']; + } //set the error mode $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -2230,7 +2234,7 @@ } elseif ($array_value === "user_uuid()") { $sql .= $array_key." = :".$array_key.", "; - $params[$array_key] = $_SESSION['user_uuid']; + $params[$array_key] = $_SESSION['user_uuid'] ?? null; } elseif ($array_value === "remote_address()") { $sql .= $array_key." = :".$array_key.", "; @@ -2245,16 +2249,20 @@ } //add the modified date and user - $sql .= "update_date = now(), "; - $sql .= "update_user = :update_user "; - $params['update_user'] = $_SESSION['user_uuid']; + if (!empty($_SESSION['user_uuid'])) { + $sql .= "update_date = now(), "; + $sql .= "update_user = :update_user "; + $params['update_user'] = $_SESSION['user_uuid']; + } //add the where with the parent name and value $sql .= "WHERE ".$parent_key_name." = '".$parent_key_value."'; "; $sql = str_replace(", WHERE", " WHERE", $sql); //add update user parameter - $params['update_user'] = $_SESSION['user_uuid']; + if (!empty($_SESSION['user_uuid'])) { + $params['update_user'] = $_SESSION['user_uuid']; + } //set the error mode $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -2277,7 +2285,7 @@ $message["details"][$m]["code"] = "200"; $message["details"][$m]["uuid"] = $parent_key_value; $message["details"][$m]["sql"] = $sql; - if (is_array($params)) { + if (!empty($params)) { $message["details"][$m]["params"] = $params; } unset($params); @@ -2293,7 +2301,7 @@ $message["details"][$m]["message"] = $e->getMessage(); $message["details"][$m]["code"] = "400"; $message["details"][$m]["sql"] = $sql; - if (is_array($params)) { + if (!empty($params)) { $message["details"][$m]["params"] = $params; } unset($params); @@ -2416,7 +2424,7 @@ } elseif ($v === "user_uuid()") { $sql .= $k." = :".$k.", "; - $params[$k] = $_SESSION['user_uuid']; + $params[$k] = $_SESSION['user_uuid'] ?? null; } elseif ($v === "remote_address()") { $sql .= $k." = :".$k.", "; @@ -2433,7 +2441,7 @@ //add the modified date and user $sql .= "update_date = now(), "; $sql .= "update_user = :update_user "; - $params['update_user'] = $_SESSION['user_uuid']; + $params['update_user'] = $_SESSION['user_uuid'] ?? null; //add the where with the parent name and value $sql .= "WHERE ".$parent_key_name." = '".$parent_key_value."' "; @@ -2564,7 +2572,7 @@ } elseif ($v === "user_uuid()") { $sql .= ':'.$k.", "; - $params[$k] = $_SESSION['user_uuid']; + $params[$k] = $_SESSION['user_uuid'] ?? null; } elseif ($v === "remote_address()") { $sql .= ':'.$k.", "; @@ -2589,7 +2597,9 @@ $sql .= ");"; //add insert user parameter - $params['insert_user'] = $_SESSION['user_uuid']; + if (!empty($_SESSION['user_uuid'])) { + $params['insert_user'] = $_SESSION['user_uuid']; + } //set the error mode $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -2675,7 +2685,9 @@ } //get the UUIDs - $user_uuid = $_SESSION['user_uuid']; + if (!empty($_SESSION['user_uuid'])) { + $user_uuid = $_SESSION['user_uuid']; + } //log the transaction results if ($transaction_save && file_exists($_SERVER["PROJECT_ROOT"]."/app/database_transactions/app_config.php")) { diff --git a/resources/classes/switch_settings.php b/resources/classes/switch_settings.php index 9ac5ab527b..fd61108335 100644 --- a/resources/classes/switch_settings.php +++ b/resources/classes/switch_settings.php @@ -66,6 +66,18 @@ if (!class_exists('switch_settings')) { } } + //set defaults + $vars['base_dir'] = empty($vars['base_dir']) ?? ''; + $vars['conf_dir'] = empty($vars['conf_dir']) ?? ''; + $vars['db_dir'] = empty($vars['db_dir']) ?? ''; + $vars['recordings_dir'] = empty($vars['recordings_dir']) ?? ''; + $vars['script_dir'] = empty($vars['script_dir']) ?? ''; + $vars['sounds_dir'] = empty($vars['sounds_dir']) ?? ''; + $vars['storage_dir'] = empty($vars['storage_dir']) ?? ''; + $vars['grammar_dir'] = empty($vars['grammar_dir']) ?? ''; + $vars['log_dir'] = empty($vars['log_dir']) ?? ''; + $vars['mod_dir'] = empty($vars['mod_dir']) ?? ''; + //set the bin directory if ($vars['base_dir'] == "/usr/local/freeswitch") { $bin = "/usr/local/freeswitch/bin"; diff --git a/resources/switch.php b/resources/switch.php index 5643d2e49c..e1c992b490 100644 --- a/resources/switch.php +++ b/resources/switch.php @@ -39,7 +39,7 @@ $sql = "select * from v_settings "; $database = new database; $row = $database->select($sql, null, 'row'); - if (is_array($row) && @sizeof($row) != 0) { + if (!empty($row)) { $_SESSION['event_socket_ip_address'] = $row["event_socket_ip_address"]; $_SESSION['event_socket_port'] = $row["event_socket_port"]; $_SESSION['event_socket_password'] = $row["event_socket_password"]; @@ -74,7 +74,7 @@ function event_socket_request_cmd($cmd) { $sql = "select * from v_settings "; $database = new database; $row = $database->select($sql, null, 'row'); - if (is_array($row) && @sizeof($row) != 0) { + if (!empty($row)) { $event_socket_ip_address = $row["event_socket_ip_address"]; $event_socket_port = $row["event_socket_port"]; $event_socket_password = $row["event_socket_password"]; @@ -127,7 +127,7 @@ function save_setting_xml() { $sql = "select * from v_settings "; $database = new database; $row = $database->select($sql, null, 'row'); - if (is_array($row) && @sizeof($row) != 0) { + if (!empty($row)) { $fout = fopen($_SESSION['switch']['conf']['dir']."/directory/default/default.xml","w"); $xml = "\n"; $xml .= " \n"; @@ -248,7 +248,7 @@ function save_gateway_xml() { $parameters['domain_uuid'] = $domain_uuid; $database = new database; $result = $database->select($sql, $parameters, 'all'); - if (is_array($result) && @sizeof($result) != 0) { + if (!empty($result)) { foreach ($result as &$row) { if ($row['enabled'] != "false") { //set the default profile as external @@ -382,10 +382,10 @@ function save_var_xml() { $sql .= "where var_enabled = 'true' "; $sql .= "order by var_category, var_order asc "; $database = new database; - $variables = $database->select($sql, $parameters, 'all'); + $variables = $database->select($sql, null, 'all'); $prev_var_category = ''; $xml = ''; - if (is_array($variables) && @sizeof($variables) != 0) { + if (!empty($variables)) { foreach ($variables as &$row) { if ($row['var_category'] != 'Provision') { if ($prev_var_category != $row['var_category']) { @@ -463,7 +463,7 @@ function outbound_route_to_bridge($domain_uuid, $destination_number, array $chan $result = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); - if (is_array($result) && @sizeof($result) != 0) { + if (!empty($result)) { foreach ($result as &$row) { $dialplan_uuid = $row["dialplan_uuid"]; $dialplan_detail_uuid = $row["dialplan_detail_uuid"]; @@ -474,7 +474,7 @@ function outbound_route_to_bridge($domain_uuid, $destination_number, array $chan } } - if (is_array($outbound_routes) && @sizeof($outbound_routes) != 0) { + if (!empty($outbound_routes)) { $x = 0; foreach ($outbound_routes as &$dialplan) { $condition_match = false; @@ -568,7 +568,7 @@ function extension_presence_id($extension, $number_alias = false) { $parameters['extension'] = $extension; $database = new database; $row = $database->select($sql, $parameters, 'row'); - if (is_array($row) && @sizeof($row) != 0) { + if (!empty($row)) { $extension = $row['extension']; $number_alias = $row['number_alias']; } @@ -596,7 +596,7 @@ function get_recording_filename($id) { $parameters['domain_uuid'] = $domain_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); - if (is_array($row) && @sizeof($row) != 0) { + if (!empty($row)) { //$filename = $row["filename"]; //$recording_name = $row["recording_name"]; //$recording_uuid = $row["recording_uuid"]; @@ -656,7 +656,7 @@ if (!function_exists('save_call_center_xml')) { $call_center_queues = $database->select($sql, null, 'all'); unset($sql); - if (is_array($call_center_queues) && @sizeof($call_center_queues) != 0) { + if (!empty($call_center_queues)) { //prepare Queue XML string $x=0; @@ -729,7 +729,7 @@ if (!function_exists('save_call_center_xml')) { unset($sql); $x=0; - if (is_array($result) && @sizeof($result) != 0) { + if (!empty($result)) { foreach ($result as &$row) { //get the values from the db and set as php variables $agent_name = $row["agent_name"]; @@ -819,7 +819,7 @@ if (!function_exists('save_call_center_xml')) { unset($sql); $x=0; - if (is_array($result) && @sizeof($result) != 0) { + if (!empty($result)) { foreach ($result as &$row) { $agent_name = $row["agent_name"]; $queue_name = $row["queue_name"]; @@ -980,7 +980,7 @@ if (!function_exists('save_sip_profile_xml')) { $result = $database->select($sql, null, 'all'); unset($sql); - if (is_array($result) && @sizeof($result) != 0) { + if (!empty($result)) { foreach($result as $row) { $sip_profile_uuid = $row['sip_profile_uuid']; $sip_profile_name = $row['sip_profile_name']; @@ -1009,7 +1009,7 @@ if (!function_exists('save_sip_profile_xml')) { $parameters['sip_profile_uuid'] = $sip_profile_uuid; $database = new database; $result_2 = $database->select($sql, $parameters, 'all'); - if (is_array($result_2) && @sizeof($result_2) != 0) { + if (!empty($result_2)) { $sip_profile_settings = ''; foreach ($result_2 as &$row_2) { $sip_profile_settings .= " \n";