r4073 minor change in UI for recent change: VST form commit on ENTER and hints on...
[racktables] / inc / ajax-interface.php
CommitLineData
65e557dd
AA
1<?php
2/*
3 *
4 * This file contains HTML-generating funcitons which are needed in ajax handler
5 *
6 *
7*/
8
9// retrieves ports link status from switch and formats results to dynamic-HTML
10// returns array which could be packed into json and passed to client's browser
11function formatPortLinkHints ($object_id)
12{
13 $result = array();
14 $linkStatus = gwRetrieveDeviceConfig ($object_id, 'getportstatus');
15 foreach ($linkStatus as $portname => $link_info)
16 {
17 $link_info = $linkStatus[$portname];
18 switch ($link_info['status'])
19 {
20 case 'up':
21 $img_filename = 'link-up.png';
22 break;
23 case 'down':
24 $img_filename = 'link-down.png';
25 break;
26 case 'disabled':
27 $img_filename = 'link-disabled.png';
28 break;
29 }
30
31 $hidden_lines = array();
32 $hidden_lines[] = $portname . ': ' . $link_info['status'];
33 if (isset ($link_info['speed']))
34 $hidden_lines[] = 'Speed: ' . $link_info['speed'];
35 if (isset ($link_info['duplex']))
36 $hidden_lines[] = 'Duplex: ' . $link_info['duplex'];
37 if (count ($hidden_lines))
38 $result[$portname]['popup'] = implode ('<br>', $hidden_lines);
39 $visible_part = '<img width="16" height="16" src="pix/' . $img_filename . '">';
40 $result[$portname]['inline'] = $visible_part;
41 }
42 // put empty pictures for not-found ports
43 $object = spotEntity ('object', $object_id);
44 amplifyCell ($object);
45 foreach ($object['ports'] as $port)
46 if (! isset ($result[$port['name']]))
47 $result[$port['name']]['inline'] = '<img width="16" height="16" src="pix/1x1t.gif">';
48 return $result;
49}
50
51// retrieves MAC address list from switch and formats results to dynamic-HTML
52// returns array which could be packed into json and passed to client's browser
53function formatPortMacHints ($object_id)
54{
55 $result = array();
56 $macList = gwRetrieveDeviceConfig ($object_id, 'getmaclist');
57 foreach ($macList as $portname => $list)
58 {
59 $list = $macList[$portname];
60 $visible_part = count ($list) . ' MACs';
61 $result[$portname]['inline'] = $visible_part;
62 if (count ($list))
63 {
64 $hidden_part = '<table width="100%"><tr><th>MAC<th>VID</tr>';
65 foreach ($list as $mac)
66 $hidden_part .= '<tr><td>' . $mac['mac'] . '<td>' . $mac['vid'] . '</tr>';
67 $result[$portname]['popup'] = $hidden_part;
68 }
69 }
70 return $result;
71}
72
73// retrieves port configs from switch and formats results to dynamic-HTML
74// returns array which could be packed into json and passed to client's browser
75function formatPortConfigHints ($object_id, $R = NULL)
76{
77 $result = array();
78 if (! isset ($R))
79 $R = getRunning8021QConfig ($object_id);
80 foreach ($R['portdata'] as $portname => $portdata)
81 if (isset ($portdata['config']))
82 {
83 $hidden_part = '';
84 foreach ($portdata['config'] as $line)
85 $hidden_part .= '<span class="'. $line['type'] . '">' . htmlentities ($line['line']) . '</span><br />';
86 $result[$portname]['popup'] = $hidden_part;
87 }
88 return $result;
89}
90
91?>