ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

display_device.inc.php
Go to the documentation of this file.
1 <?
2 
3 
4 
6 // Function: ws_display()
7 //
8 // Description:
9 // Displays a device record and all associated info in the work_space div.
11 function ws_display($window_name, $form='') {
12  global $conf, $self, $onadb, $base;
13  global $images, $color, $style, $msgtype;
14  $html = '';
15  $js = '';
16  $debug_val = 3; // used in the auth() calls to supress logging
17 
18  // If the user supplied an array in a string, build the array and store it in $form
19  $form = parse_options_string($form);
20 
21  // Load the host record
22  if ($form['device_id'])
23  list($status, $rows, $record) = ona_get_device_record(array('id' => $form['device_id']));
24  else if ($form['device']) { // FIXME.. no find_device yet
25  list($status, $rows, $record) = ona_find_device($form['device']);
26  }
27  if ($status or !$rows) {
28  array_pop($_SESSION['ona']['work_space']['history']);
29  $html .= "<br><center><font color=\"red\"><b>Device doesn't exist!</b></font></center>";
30  $response = new xajaxResponse();
31  $response->addAssign("work_space_content", "innerHTML", $html);
32  return($response->getXML());
33  }
34 
35  // Update History Title (and tell the browser to re-draw the history div)
36  $history = array_pop($_SESSION['ona']['work_space']['history']);
37  $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');";
38  if ($history['title'] == $window_name) {
39  $history['title'] = $record['name'];
40  array_push($_SESSION['ona']['work_space']['history'], $history);
41  }
42 
43  // Create some javascript to refresh the current page
44  $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']);
45  $refresh = "xajax_window_submit('work_space', '{$refresh}');";
46 
47  // Interface (and find out how many there are)
48  list($status, $interfaces, $interface) = ona_get_interface_record(array('host_id' => $record['id']), '');
49  $record['ip_address'] = ip_mangle($interface['ip_addr'], 'dotted');
50  $interface_style = '';
51  if ($interfaces > 1) {
52  $interface_style = 'font-weight: bold;';
53  }
54 
55  // Subnet description
56  list($status, $rows, $subnet) = ona_get_subnet_record(array('ID' => $interface['subnet_id']));
57  $record['subnet'] = $subnet['name'];
58  $record['ip_subnet_mask'] = ip_mangle($subnet['ip_mask'], 'dotted');
59  $record['ip_subnet_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr');
60 
61  // Device Description
62  list($status, $rows, $device_type) = ona_get_device_type_record(array('id' => $record['device_type_id']));
63  list($status, $rows, $role) = ona_get_role_record(array('id' => $device_type['role_id']));
64  list($status, $rows, $model) = ona_get_model_record(array('id' => $device_type['model_id']));
65  list($status, $rows, $manufacturer) = ona_get_manufacturer_record(array('id' => $model['manufacturer_id']));
66  $record['devicefull'] = "{$manufacturer['name']}, {$model['name']} ({$role['name']})";
67  $record['device'] = str_replace('Unknown', '?', $record['devicefull']);
68 
69  // Get location_number from the location_id
70  list($status, $rows, $location) = ona_get_location_record(array('id' => $record['location_id']));
71  // extra stuff to pass to ws_plugins
72  $extravars['refresh']=$refresh;
73  $extravars['window_name']=$window_name;
74 
75  $style['content_box'] = <<<EOL
76  margin: 10px 20px;
77  padding: 2px 4px;
78  background-color: #FFFFFF;
79  vertical-align: top;
80 EOL;
81 
82  $style['label_box'] = <<<EOL
83  font-weight: bold;
84  padding: 2px 4px;
85  border: solid 1px {$color['border']};
86  background-color: {$color['window_content_bg']};
87 EOL;
88 
89  // Escape data for display in html
90  foreach(array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); }
91  // force 300px width to Notes field if the length is longer than 50 characters and put Notes at the top of the td
92  $notes_width = "";
93  $notes_valign = "";
94  if(strlen($record['notes']) > 50) {
95  $notes_width =' style="width: 300px" ';
96  $notes_valign = ' valign="top" ';
97  }
98 
99  $html .= <<<EOL
100 
101  <!-- FORMATTING TABLE -->
102  <div style="{$style['content_box']}">
103  <table cellspacing="0" border="0" cellpadding="0"><tr>
104 
105  <!-- START OF FIRST COLUMN OF SMALL BOXES -->
106  <td nowrap="true" valign="top" style="padding-right: 15px;">
107 
108  <form id="form_device_{$record['id']}"
109  ><input type="hidden" name="device_id" value="{$record['id']}"
110  ><input type="hidden" name="js" value="{$refresh}"
111  ></form>
112 
113 EOL;
114 
115  $wspl = workspace_plugin_loader('host_detail',$record,$extravars);
116  $html .= $wspl[0]; $js .= $wspl[1];
117 
118  $wspl = workspace_plugin_loader('location_detail',$record,$extravars);
119  $html .= $wspl[0]; $js .= $wspl[1];
120 
121  $html .= <<<EOL
122  <!-- END OF FIRST COLUMN OF SMALL BOXES -->
123  </td>
124 
125  <!-- START OF SECOND COLUMN OF SMALL BOXES -->
126  <td valign="top" style="padding-right: 15px;">
127 EOL;
128 
129  $html .= <<<EOL
130  <!-- END OF SECOND COLUMN OF SMALL BOXES -->
131  </td>
132 
133 
134  <!-- START OF THIRD COLUMN OF SMALL BOXES -->
135  <td valign="top">
136 EOL;
137 
138 
139 
140  // START MESSAGES BOX
141  // $tablename is a reference directly to the table that contains the item
142  // we are displaying to the user.
143  // It is possible that you can have the same ID in multiple tables, currently.
144  $tablename = 'devices';
145  require_once('winc/tooltips.inc.php');
146  list($lineshtml, $linesjs) = get_message_lines_html("table_id_ref = {$record['id']} AND table_name_ref LIKE '{$tablename}'");
147  if ($lineshtml) {
148  $html .= <<<EOL
149  <!-- MESSAGES LIST -->
150  <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;">
151  <tr><td colspan="99" nowrap="true" style="{$style['label_box']}">
152  Messages
153  </td></tr>
154  <tr><td>
155 EOL;
156  $html .= $lineshtml;
157  $js .= $linesjs;
158  $html .= "</td></tr></table>";
159  }
160  // END MESSAGES LIST
161 
162 
163  $html .= <<<EOL
164  </td>
165  <!-- END OF THIRD COLUMN OF SMALL BOXES -->
166  </tr></table>
167  </div>
168  <!-- END OF TOP SECTION -->
169 
170 EOL;
171 
172 
173 
174 
175 
176 
177 
178  // RECORD LIST
179  $tab = 'hosts';
180  $submit_window = "list_{$tab}";
181  $form_id = "{$submit_window}_filter_form";
182  $_SESSION['ona'][$form_id]['tab'] = $tab;
183  $content_id = "{$window_name}_{$submit_window}";
184  $html .= <<<EOL
185  <!-- INTERFACE LIST -->
186  <div style="border: 1px solid {$color['border']}; margin: 10px 20px;">
187 
188  <!-- Tab & Quick Filter -->
189  <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0">
190  <tr>
191  <td id="{$form_id}_{$tab}_tab" class="table-tab-active">
192  Associated Hosts {$tab} <span id="{$form_id}_{$tab}_count"></span>
193  </td>
194 
195  <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%">
196  <form id="{$form_id}" onSubmit="return false;">
197  <input id="{$form_id}_page" name="page" value="1" type="hidden">
198  <input name="content_id" value="{$content_id}" type="hidden">
199  <input name="form_id" value="{$form_id}" type="hidden">
200  <input name="device_id" value="{$record['id']}" type="hidden">
201  <div id="{$form_id}_filter_overlay"
202  title="Filter"
203  style="position: relative;
204  display: inline;
205  color: #CACACA;
206  cursor: text;"
207  onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();"
208  >Name</div>
209  <input
210  id="{$form_id}_filter"
211  name="filter"
212  class="filter"
213  type="text"
214  value=""
215  size="10"
216  maxlength="20"
217  alt="Quick Filter"
218  onFocus="el('{$form_id}_filter_overlay').style.display = 'none';"
219  onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';"
220  onKeyUp="
221  if (typeof(timer) != 'undefined') clearTimeout(timer);
222  code = 'if ({$form_id}_last_search != el(\'{$form_id}_filter\').value) {' +
223  ' {$form_id}_last_search = el(\'{$form_id}_filter\').value;' +
224  ' document.getElementById(\'{$form_id}_page\').value = 1;' +
225  ' xajax_window_submit(\'{$submit_window}\', xajax.getFormValues(\'{$form_id}\'), \'display_list\');' +
226  '}';
227  timer = setTimeout(code, 700);"
228  >
229  </form>
230  </td>
231 
232  </tr>
233  </table>
234 
235  <div id='{$content_id}'>
236  {$conf['loading_icon']}
237  </div>
238 EOL;
239 
240  if (auth('host_add',$debug_val)) {
241  $html .= <<<EOL
242 
243  <!-- ADD RECORD LINK -->
244  <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}">
245  <form id="form_record_{$record['id']}"
246  ><input type="hidden" name="host_id" value="{$record['id']}"
247  ><input type="hidden" name="js" value="{$refresh}"
248  ></form>
249 
250  <a title="Add host"
251  class="act"
252  onClick="xajax_window_submit('edit_host', xajax.getFormValues('form_record_{$record['id']}'), 'editor');"
253  ><img src="{$images}/silk/font_add.png" border="0"></a>&nbsp;
254 
255  <a title="Add host"
256  class="act"
257  onClick="xajax_window_submit('edit_host', xajax.getFormValues('form_record_{$record['id']}'), 'editor');"
258  >Add host</a>&nbsp;
259  </div>
260 EOL;
261  }
262 
263  $html .= " </div>";
264 
265  $js .= <<<EOL
266  /* Setup the quick filter */
267  el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px';
268  {$form_id}_last_search = '';
269 
270  /* Tell the browser to load/display the list */
271  xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list');
272 EOL;
273 
274 
275 
276 
277 
278 
279  // Insert the new html into the window
280  // Instantiate the xajaxResponse object
281  $response = new xajaxResponse();
282  $response->addAssign("work_space_content", "innerHTML", $html);
283  if ($js) { $response->addScript($js); }
284  return($response->getXML());
285 }
286 
287 
288 
289 
290 
291 
292 
293 
294 
295 
296 
297 
298 
299 
300 
301 
302 
303 
304 ?>
ona_get_manufacturer_record
ona_get_manufacturer_record($array)
Definition: functions_db.inc.php:1210
workspace_plugin_loader
workspace_plugin_loader($modulename, $record=array(), $extravars=array())
Definition: functions_gui.inc.php:140
ona_get_location_record
ona_get_location_record($array='', $order='')
Definition: functions_db.inc.php:1122
ona_get_device_record
ona_get_device_record($array)
Definition: functions_db.inc.php:1218
Name
Full Name
Definition: app_user_info.inc.php:101
ip_mangle
ip_mangle($ip="", $format="default")
Definition: functions_general.inc.php:308
ona_get_interface_record
ona_get_interface_record($array='', $order='')
Definition: functions_db.inc.php:1126
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
xajax
ona_get_role_record
ona_get_role_record($array)
Definition: functions_db.inc.php:1222
$tab
$tab
Definition: app_config_type_list.inc.php:29
ona_get_device_type_record
ona_get_device_type_record($array)
Definition: functions_db.inc.php:1214
ona_get_model_record
ona_get_model_record($array)
Definition: functions_db.inc.php:1197
ws_display
ws_display($window_name, $form='')
Definition: display_device.inc.php:11
$form_id
$form_id
Definition: app_config_type_list.inc.php:28
ona_find_device
ona_find_device($search="")
Definition: functions_db.inc.php:2105
$images
$images
Definition: config.inc.php:26
EOL
< a style="text-decoration: none;" href="/">< input class='edit' type="button" value="I don't like free stuff?" onclick=""/></a ></center ></div > EOL
Definition: install.php:40
$submit_window
$submit_window
Definition: app_config_type_list.inc.php:30
get_message_lines_html
get_message_lines_html($where)
Definition: tooltips.inc.php:192
$_SESSION
$_SESSION['ona']['auth']
Definition: login.php:14
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$content_id
$content_id
Definition: app_config_type_list.inc.php:31
$style
$style['font-family']
Definition: config.inc.php:158
nbsp
& nbsp
Definition: install.php:36
$self
global $self
Definition: 2-to-3.php:15
$wspl
$wspl
Definition: main.inc.php:113
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
$base
$base
Definition: 2-to-3.php:8
ona_get_subnet_record
ona_get_subnet_record($array)
Definition: functions_db.inc.php:1226
$color
if($_SERVER['SERVER_PORT']==443) $color['bg']
Definition: config.inc.php:119
parse_options_string
parse_options_string($input)
Definition: xajax_setup.inc.php:88