".$device['hostname'];
  if($device['hardware']) { $contents .= " - ".$device['hardware']; }
  $contents .= "";
  $contents .= "
";
  if($device['os']) { $contents .= $config['os'][$device['os']]['text']; }
  if($device['version']) { $contents .= " ".$device['version']; }
  if($device['features']) { $contents .= " (".$device['features'].")"; }
#  if($device['hardware']) { $contents .= " - ".$device['hardware']; }
  $contents .= "
";
#  if (isset($device['location'])) { $contents .= "" . htmlentities($device['location'])."
"; }
  foreach ($graphs as $entry)
  {
    $graph     = $entry['graph'];
    $graphhead = $entry['text']; 
    $contents .= '';
    $contents .= '
'.$graphhead.'';
    $contents .= '

';
    $contents .= '

';
    $contents .= '
".$graph_array['popup_title']."
";
  $content .= "";
  $graph_array['legend']   = "yes";
  $graph_array['height']   = "100";
  $graph_array['width']    = "340";
  $graph_array['from']     = $config['day'];
  $content .= generate_graph_tag($graph_array);
  $graph_array['from']     = $config['week'];
  $content .= generate_graph_tag($graph_array);
  $graph_array['from']     = $config['month'];
  $content .= generate_graph_tag($graph_array);
  $graph_array['from']     = $config['year'];
  $content .= generate_graph_tag($graph_array);
  $content .= "
";
  return overlib_link($graph_array['link'], $graph, $content, NULL);
}
function print_graph_popup($graph_array)
{
  echo (generate_graph_popup($graph_array));
}
function permissions_cache($user_id) 
{
  $permissions = array();
  $query = mysql_query("SELECT * FROM devices_perms WHERE user_id = '".$user_id."'");
  while($device = mysql_fetch_assoc($query)) {
    $permissions['device'][$device['device_id']] = 1;    
  }
  $query = mysql_query("SELECT * FROM ports_perms WHERE user_id = '".$user_id."'");
  while($port = mysql_fetch_assoc($query)) {
    $permissions['port'][$port['interface_id']] = 1;
  }
  $query = mysql_query("SELECT * FROM bill_perms WHERE user_id = '".$user_id."'");
  while($bill = mysql_fetch_assoc($query)) {
    $permissions['bill'][$bill['bill_id']] = 1;
  }
  return $permissions;
}
function bill_permitted($bill_id) 
{
  global $_SESSION; global $permissions;
  if ($_SESSION['userlevel'] >= "5") {
    $allowed = TRUE;
  } elseif ( $permissions['bill'][$bill_id]) {
    $allowed = TRUE;
  } else {
    $allowed = FALSE;
  }
  return $allowed;
}
function port_permitted($interface_id, $device_id = NULL)
{
  global $_SESSION; global $permissions;
  if(!is_numeric($device_id)) { $device_id = get_device_id_by_interface_id($interface_id); }
  if ($_SESSION['userlevel'] >= "5") {
    $allowed = TRUE;
  } elseif ( device_permitted($device_id)) {
    $allowed = TRUE;
  } elseif ( $permissions['port'][$interface_id]) {
    $allowed = TRUE;
  } else {
    $allowed = FALSE;
  }
  return $allowed;
}
function application_permitted($app_id, $device_id = NULL)
{
  global $_SESSION; global $permissions;
  if(is_numeric($app_id)) 
  {
    if(!$device_id) { $device_id = device_by_id_cache ($app_id); }
    if ($_SESSION['userlevel'] >= "5") {
      $allowed = TRUE;
    } elseif ( device_permitted($device_id)) {
      $allowed = TRUE;
    } elseif ( $permissions['application'][$app_id]) {
      $allowed = TRUE;
    } else {
      $allowed = FALSE;
    }
  } else {
    $allowed = FALSE;
  }
  return $allowed;
}
function device_permitted($device_id)
{
  global $_SESSION; global $permissions;
  if ($_SESSION['userlevel'] >= "5") {
    $allowed = true;
  } elseif ( $permissions['device'][$device_id] ) {
    $allowed = true;
  } else {
    $allowed = false;
  }
  return $allowed;
}
function print_graph_tag ($args) 
{
  echo generate_graph_tag ($args);
}
function generate_graph_tag ($args) 
{
  global $config;
  $sep = "?";
  $url = $config['base_url'] . "/graph.php";
  foreach ($args as $key => $arg) 
  {
    $url .= $sep.$key."=".$arg;
    $sep="&";
  }
  return " ";
}
function print_percentage_bar ($width, $height, $percent, $left_text, $left_colour, $left_background, $right_text, $right_colour, $right_background) 
{
  $output = '
";
}
function print_percentage_bar ($width, $height, $percent, $left_text, $left_colour, $left_background, $right_text, $right_colour, $right_background) 
{
  $output = '
  
    
    '.$left_text.'
    '.$right_text.'
   
 ';
  return $output;
}
function generate_port_link($args, $text = NULL, $type = NULL)
{
  global $twoday; global $now; global $config; global $day; global $month;
  $args = ifNameDescr($args);
  if(!$text) { $text = fixIfName($args['label']); }
  if($type) { $args['graph_type'] = $type; }
  if(!$args['graph_type']) { $args['graph_type'] = 'port_bits'; }
  
  $class = ifclass($args['ifOperStatus'], $args['ifAdminStatus']);
  if(!isset($args['hostname'])) { $args = array_merge($args, device_by_id_cache($args['device_id'])); }
  $content = "".$args['hostname']." - " . fixifName($args['label']) . "
";
  if($args['ifAlias']) { $content .= $args['ifAlias']."
"; }
  $content .= "";
  $graph_array['type']     = $args['graph_type'];
  $graph_array['legend']   = "yes";
  $graph_array['height']   = "100";
  $graph_array['width']    = "340";
  $graph_array['to']	   = $config['now'];
  $graph_array['from']     = $config['day'];
  $graph_array['id']       = $args['interface_id'];
  $content .= generate_graph_tag($graph_array);
  $graph_array['from']     = $config['week'];
  $content .= generate_graph_tag($graph_array);
  $graph_array['from']     = $config['month'];
  $content .= generate_graph_tag($graph_array);
  $graph_array['from']     = $config['year'];
  $content .= generate_graph_tag($graph_array);
  $content .= "
";
  
  $url = $config['base_url']."/device/".$args['device_id']."/interface/" . $args['interface_id'] . "/";
  if(port_permitted($args['interface_id'])) {
    return overlib_link($url, $text, $content, $class);
  } else {
    return fixifName($text);
  }
}
function generate_port_thumbnail($args) 
{
    if(!$args['bg']) { $args['bg'] = "FFFFF"; }
    $args['content'] = " ";
    $output = generate_port_link($args, $args['content']);
    echo $output;
}
function print_optionbar_start ($height = 20, $width = 0, $marginbottom = 5) 
{
  echo("
";
    $output = generate_port_link($args, $args['content']);
    echo $output;
}
function print_optionbar_start ($height = 20, $width = 0, $marginbottom = 5) 
{
  echo("
    
    
    
    
    
    
    
    
    ");
}
function print_optionbar_end () 
{
  echo("  
     
    
    
    
    
    
    
   ");
}
function geteventicon ($message) 
{
  if ($message == "Device status changed to Down") { $icon = "server_connect.png"; }
  if ($message == "Device status changed to Up") { $icon = "server_go.png"; }
  if ($message == "Interface went down" || $message == "Interface changed state to Down" ) { $icon = "if-disconnect.png"; }
  if ($message == "Interface went up" || $message == "Interface changed state to Up" ) { $icon = "if-connect.png"; }
  if ($message == "Interface disabled") { $icon = "if-disable.png"; }
  if ($message == "Interface enabled") { $icon = "if-enable.png"; }
  if (isset($icon)) { return $icon; } else { return false; }
}
function overlibprint($text) {
	return "onmouseover=\"return overlib('" . $text . "');\" onmouseout=\"return nd();\"";
}
function humanmedia($media) 
{
  array_preg_replace($rewrite_iftype, $media);	
  return $media;
}
function humanspeed($speed) 
{
  $speed = formatRates($speed);
  if ($speed == "") { $speed = "-"; }
  return $speed;
}
function print_error($text)
{
  echo('|  '.$text.' | 
');
}
function print_message($text)
{
  echo('|  '.$text.' | 
');
}
function devclass($device) 
{
   if (isset($device['status']) && $device['status'] == '0') { $class = "list-device-down"; } else { $class = "list-device"; }
   if (isset($device['ignore']) && $device['ignore'] == '1') {
     $class = "list-device-ignored";
     if (isset($device['status']) && $device['status'] == '1') { $class = "list-device-ignored-up"; }
   }
   if (isset($device['disabled']) && $device['disabled'] == '1') { $class = "list-device-disabled"; }
  return $class;
}
?>