Added some useful functions from the 6.0 version
This commit is contained in:
parent
daedfa6a21
commit
8f3973d934
|
@ -2220,4 +2220,84 @@ function print_audit_csv ($data) {
|
|||
}
|
||||
}
|
||||
|
||||
function is_metaconsole() {
|
||||
global $config;
|
||||
|
||||
if ($config['metaconsole'])
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function set_if_defined (&$var, $test) {
|
||||
if (isset($test)) {
|
||||
$var = $test;
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function set_unless_defined (&$var, $default) {
|
||||
if (! isset($var)) {
|
||||
$var = $default;
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function set_when_empty (&$var, $default) {
|
||||
if (empty($var)) {
|
||||
$var = $default;
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function sort_by_column (&$array_ref, $column_parameter) {
|
||||
global $column;
|
||||
|
||||
$column = $column_parameter;
|
||||
|
||||
if (!empty($column)) {
|
||||
usort($array_ref, function ($a, $b) {
|
||||
global $column;
|
||||
|
||||
return strcmp($a[$column], $b[$column]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array by extracting a column or columns.
|
||||
*
|
||||
* @param array Array
|
||||
* @param mixed (string/array) Column name/s
|
||||
*
|
||||
* @return array Array formed by the extracted columns of every array iteration.
|
||||
*/
|
||||
function extract_column ($array, $column) {
|
||||
$column_is_arr = is_array($column);
|
||||
|
||||
return array_map(function($item) use ($column_is_arr, $column) {
|
||||
if ($column_is_arr) {
|
||||
return array_reduce($column, function($carry, $col) use ($item) {
|
||||
$carry[$col] = $item[$col];
|
||||
return $item[$col];
|
||||
}, array());
|
||||
}
|
||||
else {
|
||||
return $item[$column];
|
||||
}
|
||||
}, $array);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -8665,4 +8665,78 @@ function reporting_network_interfaces_table ($content, $report, $mini, $item_tit
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a human readable representation of the planned downtime date.
|
||||
*
|
||||
* @param array $planned_downtime Planned downtime row.
|
||||
*
|
||||
* @return string Representation of the date.
|
||||
*/
|
||||
function reporting_format_planned_downtime_dates ($planned_downtime) {
|
||||
$dates = '';
|
||||
|
||||
if (!isset($planned_downtime) || !isset($planned_downtime['type_execution']))
|
||||
return '';
|
||||
|
||||
switch ($planned_downtime['type_execution']) {
|
||||
case 'once':
|
||||
$dates = date ("Y-m-d H:i", $planned_downtime['date_from']) .
|
||||
" " . __('to') . " ".
|
||||
date ("Y-m-d H:i", $planned_downtime['date_to']);
|
||||
break;
|
||||
case 'periodically':
|
||||
if (!isset($planned_downtime['type_periodicity']))
|
||||
return '';
|
||||
|
||||
switch ($planned_downtime['type_periodicity']) {
|
||||
case 'weekly':
|
||||
$dates = __('Weekly:');
|
||||
$dates .= " ";
|
||||
if ($planned_downtime['monday']) {
|
||||
$dates .= __('Mon');
|
||||
$dates .= " ";
|
||||
}
|
||||
if ($planned_downtime['tuesday']) {
|
||||
$dates .= __('Tue');
|
||||
$dates .= " ";
|
||||
}
|
||||
if ($planned_downtime['wednesday']) {
|
||||
$dates .= __('Wed');
|
||||
$dates .= " ";
|
||||
}
|
||||
if ($planned_downtime['thursday']) {
|
||||
$dates .= __('Thu');
|
||||
$dates .= " ";
|
||||
}
|
||||
if ($planned_downtime['friday']) {
|
||||
$dates .= __('Fri');
|
||||
$dates .= " ";
|
||||
}
|
||||
if ($planned_downtime['saturday']) {
|
||||
$dates .= __('Sat');
|
||||
$dates .= " ";
|
||||
}
|
||||
if ($planned_downtime['sunday']) {
|
||||
$dates .= __('Sun');
|
||||
$dates .= " ";
|
||||
}
|
||||
$dates .= " (" . $planned_downtime['periodically_time_from'];
|
||||
$dates .= "-" . $planned_downtime['periodically_time_to'] . ")";
|
||||
break;
|
||||
case 'monthly':
|
||||
$dates = __('Monthly:') . " ";
|
||||
$dates .= __('From day') . " " . $planned_downtime['periodically_day_from'];
|
||||
$dates .= " " . strtolower(__('To day')) . " ";
|
||||
$dates .= $planned_downtime['periodically_day_to'];
|
||||
$dates .= " (" . $planned_downtime['periodically_time_from'];
|
||||
$dates .= "-" . $planned_downtime['periodically_time_to'] . ")";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue