Update os icon the handling. Add title to the os image (#5424)

This commit is contained in:
Tony Murray
2017-01-14 16:14:33 -06:00
committed by Neil Lathwood
parent d7e695e065
commit 20dbda0829
2 changed files with 5 additions and 81 deletions

View File

@ -1,74 +0,0 @@
<?php
if ($_POST['editing']) {
if ($_SESSION['userlevel'] > '7') {
$param = array('icon' => $_POST['icon']);
$rows_updated = dbUpdate($param, 'devices', '`device_id` = ?', array($device['device_id']));
if ($rows_updated > 0 || $updated) {
$update_message = 'Device icon updated.';
$updated = 1;
$device = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', array($device['device_id']));
} elseif ($rows_updated = '-1') {
$update_message = 'Device icon unchanged. No update necessary.';
$updated = -1;
} else {
$update_message = 'Device icon update error.';
}
} else {
include 'includes/error-no-perm.inc.php';
}
}
if ($updated && $update_message) {
print_message($update_message);
} elseif ($update_message) {
print_error($update_message);
}
?>
<h3>Device icon</h3>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<form id="edit" name="edit" method="post" action="">
<input type="hidden" name="editing" value="yes">
<table border="0">
<?php
$numicons = 1;
echo " <tr>\n";
// Default icon
$icon = $config['os'][$device['os']]['icon'];
echo ' <td width="64" align="center"><img src="images/os/'.$icon.'.png"><br /><i>'.nicecase($icon).'</i><p />';
echo '<input name="icon" type="radio" value="'.$icon.'"'.($device['icon'] == '' || $device['icon'] == $icon ? ' checked="1"' : '').' /></td>'."\n";
for ($i = 0; $i < count($config['os'][$device['os']]['icons']); $i++) {
$icon = $config['os'][$device['os']]['icons'][$i];
echo ' <td width="64" align="center"><img src="images/os/'.$icon.'.png"><br /><i>'.nicecase($icon).'</i><p />';
echo '<input name="icon" type="radio" value="'.$icon.'"'.($device['icon'] == $icon ? ' checked="1"' : '').' /></td>'."\n";
}
if (($numicons % 10) == 0) {
echo " </tr>\n";
echo " <tr>\n";
}
?>
</tr>
<tr>
<td colspan="10">
<br />
<input type="submit" name="Submit" value="Save" />
</td>
</tr>
</table>
<br />
</form>
</td>
<td width="50"></td>
<td></td>
</tr>
</table>

View File

@ -214,7 +214,8 @@ function interface_errors($rrd_file, $period = '-1d')
function getImage($device) function getImage($device)
{ {
return '<img src="' . getImageSrc($device) . '" />'; $title = $device['icon'] ? str_replace(array('.svg', '.png'), '', $device['icon']) : $device['os'];
return '<img src="' . getImageSrc($device) . '" title="' . $title . '"/>';
} }
function getImageSrc($device) function getImageSrc($device)
@ -229,7 +230,7 @@ function getImageName($device, $use_database = true)
$device['os'] = strtolower($device['os']); $device['os'] = strtolower($device['os']);
// fetch from the database // fetch from the database
if ($use_database && $device['icon'] != 'generic.png' && is_file($config['html_dir'] . '/images/os/' . $device['icon'])) { if ($use_database && is_file($config['html_dir'] . '/images/os/' . $device['icon'])) {
return $device['icon']; return $device['icon'];
} }
@ -238,9 +239,6 @@ function getImageName($device, $use_database = true)
if ($device['os'] == "linux") { if ($device['os'] == "linux") {
$features = strtolower(trim($device['features'])); $features = strtolower(trim($device['features']));
list($distro) = explode(" ", $features); list($distro) = explode(" ", $features);
if (file_exists($config['html_dir'] . "/images/os/$distro" . ".png")) {
return $distro;
}
} }
$possibilities = array( $possibilities = array(
@ -250,8 +248,8 @@ function getImageName($device, $use_database = true)
); );
foreach ($possibilities as $basename) { foreach ($possibilities as $basename) {
foreach (array("svg", "png") as $ext) { foreach (array('.svg', '.png') as $ext) {
$name = $basename . '.' . $ext; $name = $basename . $ext;
if (is_file($config['html_dir'] . '/images/os/' . $name)) { if (is_file($config['html_dir'] . '/images/os/' . $name)) {
return $name; return $name;
} }