Skip to content

Commit

Permalink
Fixing Issue #4475
Browse files Browse the repository at this point in the history
Running cacti with PHP8.1 shows lots of warnings in the log
  • Loading branch information
TheWitness committed Nov 30, 2021
1 parent a5d2587 commit 86e0bce
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Cacti CHANGELOG
-issue#4457: Titles may show "Missing Datasource" incorectly
-issue#4460: Polling does not complete as expected on larger systems
-issue#4472: Utilities view has calculation errors when there are no data sources
-issue#4475: Running cacti with PHP8.1 shows lots of warnings in the log
-issue#4477: Remote pollers do not force connection when online
-issue#4479: As a repair tool, the rebuild poller cache scripts lacks critical options to reduce runtimes
-issue#4480: Saving a Data Template can damage Data Sources if the Data Template is not constructed properly
Expand Down
34 changes: 20 additions & 14 deletions include/global_languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,19 +330,23 @@ function repair_locale($language) {
global $lang2locale;

/* Repair legacy language support */
$found_locale = '';
$locale = str_replace('_','-', $language);
if (array_key_exists($locale, $lang2locale)) {
$language = $locale;
} else {
$wanted_locale = substr($language, 0, 2);
$language = '';
foreach ($lang2locale as $locale => $data) {
if (substr($locale, 0, 2) == $wanted_locale) {
$language = $locale;
break;
if ($language != '' && $language != null) {
$found_locale = '';
$locale = str_replace('_','-', $language);
if (array_key_exists($locale, $lang2locale)) {
$language = $locale;
} else {
$wanted_locale = substr($language, 0, 2);
$language = '';
foreach ($lang2locale as $locale => $data) {
if (substr($locale, 0, 2) == $wanted_locale) {
$language = $locale;
break;
}
}
}
} else {
$language = 'en-US';
}

return $language;
Expand Down Expand Up @@ -713,10 +717,12 @@ function number_format_i18n($number, $decimals = null, $baseu = 1024) {
$locale['thousands_sep'] = ',';
}

if ($decimals == -1 || $decimals == null) {
$number = number_format($number, null, $locale['decimal_point'], $locale['thousands_sep']);
if ($number == null) {
$number = '';
} elseif ($decimals == -1 || $decimals == null) {
$number = number_format($number, 0, $locale['decimal_point'], $locale['thousands_sep']);
} elseif ($number>=pow($baseu, 4)) {
$number = number_format($number/pow($baseu, 4), $decimals, $locale['decimal_point'], $locale['thousands_sep']) . __(' T');
$number = number_format($number/pow($baseu, 4), $decimals, $locale['decimal_point'], $locale['thousands_sep']) . __(' T');
} elseif ($number>=pow($baseu, 3)) {
$number = number_format($number/pow($baseu, 3), $decimals, $locale['decimal_point'], $locale['thousands_sep']) . __(' G');
} elseif ($number>=pow($baseu, 2)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5422,7 +5422,7 @@ function CactiErrorHandler($level, $message, $file, $line, $context = array()) {

preg_match("/.*\/plugins\/([\w-]*)\/.*/", $file, $output_array);

$plugin = (isset($output_array[1]) ? $output_array[1] : '');
$plugin = (is_array($output_array) && isset($output_array[1]) ? $output_array[1] : '');
$error = 'PHP ' . $phperrors[$level] . ($plugin != '' ? " in Plugin '$plugin'" : '') . ": $message in file: $file on line: $line";

switch ($level) {
Expand Down
7 changes: 4 additions & 3 deletions user_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,7 @@ function clearFilter() {

$user_list = db_fetch_assoc("SELECT id, user_auth.username, full_name,
realm, enabled, policy_graphs, policy_hosts, policy_graph_templates,
time, max(time) as dtime
time, max(UNIX_TIMESTAMP(time)) as dtime
FROM user_auth
LEFT JOIN user_log ON (user_auth.id = user_log.user_id)
$sql_where
Expand Down Expand Up @@ -2340,11 +2340,12 @@ function clearFilter() {

if (cacti_sizeof($user_list)) {
foreach ($user_list as $user) {
if (empty($user['dtime']) || ($user['dtime'] == '12/31/1969')) {
if (empty($user['dtime']) || $user['dtime'] <= 10000) {
$last_login = __('N/A');
} else {
$last_login = strftime('%A, %B %d, %Y %H:%M:%S ', strtotime($user['dtime']));;
$last_login = date('l, F d, Y H:i:s ', $user['dtime']);
}

if ($user['enabled'] == 'on') {
$enabled = __('Yes');
} else {
Expand Down

0 comments on commit 86e0bce

Please sign in to comment.