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)  

search_results.inc.php
Go to the documentation of this file.
1 <?php
2 
3 
4 
6 // Function:
7 // _submit ($window_name, $form_id)
8 //
9 // Description:
10 // Builds a new search results window and sends the browser instructions
11 // to make an xajax callback to the proper display_list() function to
12 // actually do the search and display results. $form should be an
13 // array of key=>value pairs from the web form.
15 function ws_search_results_submit($window_name, $form='') {
16  global $conf, $self, $onadb;
18 
19  // If the user supplied an array in a string, build the array and store it in $form
20  $form = parse_options_string($form);
21 
22  // We're building the window in $window and will use window_open() to create the window
23  $window = array(
24  'title' => "Search Results",
25  'html' => "",
26  'js' => "",
27  );
28  $max_img = "{$images}/silk/bullet_arrow_down.png";
29  $min_img = "{$images}/silk/bullet_arrow_up.png";
30 
31  // Build subnet type list
32  list($status, $rows, $records) = db_get_records($onadb, 'subnet_types', 'id >= 1', 'display_name');
33  $subnet_type_list = '<option value="">&nbsp;</option>\n';
34  foreach ($records as $record) {
35  $record['display_name'] = htmlentities($record['display_name']);
36  $subnet_type_list .= "<option value=\"{$record['id']}\">{$record['display_name']}</option>\n";
37  }
38 
39  // Build subnet type list
40  if ($conf['dns_views']) {
41  list($status, $rows, $records) = db_get_records($onadb, 'dns_views', 'id >= 0', 'name');
42  $dns_view_list = '<option value="">&nbsp;</option>\n';
43  foreach ($records as $record) {
44  $record['name'] = htmlentities($record['name']);
45  $dns_view_list .= "<option value=\"{$record['name']}\">{$record['name']}</option>\n";
46  }
47  }
48 
49  // keep wildcard checkbox value
50  if ($form['nowildcard']) $wildchecked = 'checked="yes"';
51 
52  // Load some html into $window['html']
53  $form_id = "{$window_name}_filter_form";
54  $content_id = $_SESSION['ona'][$form_id]['content_id'] = "{$window_name}_list";
55  $window['html'] .= <<<EOL
56 
57  <!-- Tabs & Quick Filter -->
58  <table id="{$form_id}_table" width="100%" cellspacing="0" border="0" cellpadding="0" style="{$style['borderT']} {$style['borderB']}">
59  <tr>
60  <td id="{$form_id}_blocks_tab" class="table-tab-inactive" onClick="xajax_window_submit('{$window_name}', 'form_id=>{$form_id},tab=>blocks', 'change_tab');">
61  Blocks <span id="{$form_id}_blocks_count"></span>
62  </td>
63 
64  <td id="{$form_id}_vlan_campus_tab" class="table-tab-inactive" onClick="xajax_window_submit('{$window_name}', 'form_id=>{$form_id},tab=>vlan_campus', 'change_tab');">
65  Vlan campuses <span id="{$form_id}_vlan_campus_count"></span>
66  </td>
67 
68  <td id="{$form_id}_subnets_tab" class="table-tab-inactive" onClick="xajax_window_submit('{$window_name}', 'form_id=>{$form_id},tab=>subnets', 'change_tab');">
69  Subnets <span id="{$form_id}_subnets_count"></span>
70  </td>
71 
72  <td id="{$form_id}_hosts_tab" class="table-tab-inactive" onClick="xajax_window_submit('{$window_name}', 'form_id=>{$form_id},tab=>hosts', 'change_tab');">
73  Hosts <span id="{$form_id}_hosts_count"></span>
74  </td>
75 
76  <td id="{$form_id}_records_tab" class="table-tab-inactive" onClick="xajax_window_submit('{$window_name}', 'form_id=>{$form_id},tab=>records', 'change_tab');">
77  DNS records <span id="{$form_id}_records_count"></span>
78  </td>
79 
80  <td style="vertical-align: middle;" class="padding" nowrap="true">
81  <img id="adv_search_img" src="{$min_img}" />
82  <span id="adv_search_div_toggle"
83  style="text-align: right;"
84  title="Min/Max"
85  onclick="if (el('adv_search_div').style.display=='none') {
86  el('adv_search_div').style.display='';
87  el('toggle_text').innerHTML='Hide search form';
88  el('adv_search_img').src='{$min_img}';
89  } else {
90  el('adv_search_div').style.display='none';
91  el('toggle_text').innerHTML='Show search form';
92  el('adv_search_img').src='{$max_img}';}" >
93  <span id="toggle_text" style="font-size: xx-small;">Hide search form</span>
94  </span>
95  </td>
96 
97  <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%">
98  <form id="{$form_id}" onSubmit="return false;">
99  <input id="{$form_id}_page" name="page" value="1" type="hidden">
100  <input id="{$form_id}_tab" name="tab" value="" type="hidden">
101  <input name="content_id" value="{$content_id}" type="hidden">
102  <input name="form_id" value="{$form_id}" type="hidden">
103  <div id="{$form_id}_filter_overlay"
104  style="position: relative;
105  display: inline;
106  color: #CACACA;
107  cursor: text;"
108  onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();"
109  >Filter</div>
110  <input
111  id="{$form_id}_filter"
112  name="filter"
113  class="filter"
114  type="text"
115  value=""
116  size="10"
117  maxlength="20"
118  alt="Quick Filter"
119  onFocus="el('{$form_id}_filter_overlay').style.display = 'none';"
120  onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';"
121  onKeyUp="
122  if (typeof(timer) != 'undefined') clearTimeout(timer);
123  code = 'if ({$form_id}_last_search != el(\'{$form_id}_filter\').value) {' +
124  ' {$form_id}_last_search = el(\'{$form_id}_filter\').value;' +
125  ' el(\'{$form_id}_page\').value = 1;' +
126  ' xajax_window_submit(\'list_\' + el(\'{$form_id}_tab\').value, xajax.getFormValues(\'{$form_id}\'), \'display_list\');' +
127  '}';
128  timer = setTimeout(code, 700);"
129  >
130  </form>
131  </td>
132 
133  </tr>
134  </table>
135 
136  <div id="adv_search_div" style="background-color: {$color['window_content_bg']};padding-top: 5px;">
137  <!-- Block Search Tab -->
138  <form id="block_search_form">
139  <input type="hidden" name="search_form_id" value="block_search_form">
140  <table id="blocks_search" style="display: none;" cellspacing="0" border="0" cellpadding="0">
141 
142  <tr>
143  <td align="right" class="asearch-line">
144  <u>B</u>lock name
145  </td>
146  <td align="left" class="asearch-line">
147  <input id="blocks_field1" name="blockname" type="text" class="edit" size="35" accesskey="b" value="{$form['blockname']}" />
148  <div id="suggest_hostname" class="suggest"></div>
149  </td>
150  </tr>
151 
152  <tr>
153  <td align="right" class="asearch-line">
154  &nbsp;
155  </td>
156  <td align="right" class="asearch-line">
157  <input class="button" type="button" name="clear" value="Clear" onClick="clearElements('block_search_form');">
158  <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results', xajax.getFormValues('block_search_form'));">
159  </td>
160  </tr>
161 
162  </table>
163  </form>
164 
165 
166  <!-- Vlan Campus Search Tab -->
167  <form id="vlan_campus_search_form">
168  <input type="hidden" name="search_form_id" value="vlan_campus_search_form">
169  <table id="vlan_campus_search" style="display: none;" cellspacing="0" border="0" cellpadding="0">
170 
171  <tr>
172  <td align="right" class="asearch-line">
173  <u>C</u>ampus name
174  </td>
175  <td align="left" class="asearch-line">
176  <input id="vlan_campus_field1" name="campusname" type="text" class="edit" size="35" accesskey="c" value="{$form['campusname']}" />
177  <div id="suggest_hostname" class="suggest"></div>
178  </td>
179  </tr>
180 
181  <tr>
182  <td align="right" class="asearch-line">
183  &nbsp;
184  </td>
185  <td align="right" class="asearch-line">
186  <input class="button" type="button" name="clear" value="Clear" onClick="clearElements('vlan_campus_search_form');">
187  <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results', xajax.getFormValues('vlan_campus_search_form'));">
188  </td>
189  </tr>
190 
191  </table>
192  </form>
193 
194 
195 
196  <!-- Host Search Tab -->
197  <form id="host_search_form">
198  <input type="hidden" name="search_form_id" value="host_search_form">
199  <table id="hosts_search" style="display: none;" cellspacing="0" border="0" cellpadding="0">
200 
201  <tr>
202  <td>
203  <table cellspacing="0" border="0" cellpadding="0">
204  <tr>
205  <td align="right" class="asearch-line">
206  <u>H</u>ostname
207  </td>
208  <td align="left" class="asearch-line">
209  <input id="hosts_field1" name="hostname" type="text" class="edit" size="35" accesskey="h" value="{$form['hostname']}" />
210  <div id="suggest_hostname" class="suggest"></div>
211  </td>
212  </tr>
213 
214  <tr>
215  <td align="right" class="asearch-line">
216  Subdomain (<u>z</u>one)
217  </td>
218  <td align="left" class="asearch-line">
219  <input id="domain" name="domain" type="text" class="edit" size="35" accesskey="z" value="{$form['domain']}" />
220  <div id="suggest_domain" class="suggest"></div>
221  </td>
222  </tr>
223 
224  <tr>
225  <td align="right" class="asearch-line">
226  <u>M</u>AC
227  </td>
228  <td align="left" class="asearch-line">
229  <input id="mac" name="mac" type="text" class="edit" size="17" accesskey="m" value="{$form['mac']}" />
230  <div id="suggest_mac" class="suggest"></div>
231  </td>
232  </tr>
233 
234  <tr>
235  <td align="right" class="asearch-line">
236  <u>I</u>P Address
237  </td>
238  <td align="left" class="asearch-line" nowrap="true">
239  <input id="ip" name="ip" type="text" class="edit" size="15" accesskey="i" value="{$form['ip']}" />
240  <div id="suggest_ip" class="suggest"></div>
241  thru
242  <input id="ip_thru" name="ip_thru" class="edit" type="text" size="15" value="{$form['ip_thru']}">
243  <div id="suggest_ip_thru" class="suggest"></div>
244  </td>
245  </tr>
246 
247  <tr>
248  <td align="right" class="asearch-line">
249  <u>N</u>otes
250  </td>
251  <td align="left" class="asearch-line">
252  <input id="notes" name="notes" type="text" class="edit" size="17" accesskey="n" value="{$form['notes']}" />
253  <div id="suggest_notes" class="suggest"></div>
254  </td>
255  </tr>
256 
257  <tr>
258  <td align="right" class="asearch-line">
259  <u>L</u>ocation Ref
260  </td>
261  <td align="left" class="asearch-line">
262  <input id="location" class="edit" type="text" name="location" size="8" accesskey="l" value="{$form['location']}" />
263  <span id="qf_location_{$window_name}"><img src="{$images}/silk/find.png" border="0"/></span>
264  <div id="suggest_location" class="suggest"></div>
265  </td>
266  </tr>
267 
268  </table>
269 
270  </td>
271  <td>
272 
273  <table cellspacing="0" border="0" cellpadding="0">
274 
275  <tr>
276  <td align="right" class="asearch-line">
277  <u>C</u>ustom attribute
278  </td>
279  <td align="left" class="asearch-line">
280  <input id="custom_attribute_type" type="text" name="custom_attribute_type" size="20" class="edit" accesskey="c" value="{$form['custom_attribute_type']}">
281  <div id="suggest_custom_attribute_type" class="suggest"></div>
282  <u>V</u>alue
283  <input id="ca_value" name="ca_value" type="text" class="edit" size="15" accesskey="v" value="{$form['ca_value']}"/>
284  </td>
285  </tr>
286 
287  <tr>
288  <td align="right" class="asearch-line">
289  Device mode<u>l</u>
290  </td>
291  <td align="left" class="asearch-line">
292  <input id="model" type="text" name="model" class="edit" size="20" accesskey="l" value="{$form['model']}">
293  <div id="suggest_model" class="suggest"></div>
294  </td>
295  </tr>
296 
297  <tr>
298  <td align="right" class="asearch-line">
299  Device <u>t</u>ype Role
300  </td>
301  <td align="left" class="asearch-line">
302  <input id="role" type="text" name="role" class="edit" size="20" accesskey="t" value="{$form['role']}">
303  <div id="suggest_role" class="suggest"></div>
304  </td>
305  </tr>
306 
307  <tr>
308  <td align="right" class="asearch-line">
309  Device man<u>u</u>facturer
310  </td>
311  <td align="left" class="asearch-line">
312  <input id="manufacturer" type="text" name="manufacturer" class="edit" size="20" accesskey="u" value="{$form['manufacturer']}">
313  <div id="suggest_manufacturer" class="suggest"></div>
314  </td>
315  </tr>
316 
317  <tr>
318  <td align="right" class="asearch-line">
319  <u>T</u>ag
320  </td>
321  <td align="left" class="asearch-line">
322  <input id="tag_host" type="text" name="tag_host" size="20" class="edit" accesskey="t" value="{$form['tag_host']}">
323  <div id="suggest_tag_host" class="suggest"></div>
324  </td>
325  </tr>
326 
327  </table>
328 
329  </td>
330  </tr>
331 
332  <tr>
333  <td colspan=4 align="right" class="asearch-line">
334  Disable Wildcards: <input class="button" type="checkbox" name="nowildcard" {$wildchecked} title="Disable usage of SQL wildcards in queries, you must supply your own in the search form as needed.">
335  <input class="button" type="button" name="reset" value="Clear" onClick="clearElements('host_search_form');">
336  <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results', xajax.getFormValues('host_search_form'));">
337  </td>
338  </tr>
339 
340  </table>
341  </form>
342 
343 
344 
345 
346  <!-- DNS record Search Tab -->
347  <form id="dns_record_search_form">
348  <input type="hidden" name="search_form_id" value="dns_record_search_form">
349  <table id="records_search" style="display: none;" cellspacing="0" border="0" cellpadding="0">
350 
351 EOL;
352 
353  // Display view dropdown
354  if ($conf['dns_views']) {
355  $window['html'] .= <<<EOL
356  <tr>
357  <td align="right" class="asearch-line">
358  DNS <u>V</u>iew
359  </td>
360  <td align="left" class="asearch-line">
361  <select id="dns_view" name="dns_view" class="edit" accesskey="v" >
362  {$dns_view_list}
363  </select>
364  </td>
365  </tr>
366 EOL;
367  }
368 
369  $window['html'] .= <<<EOL
370  <tr>
371  <td align="right" class="asearch-line">
372  <u>H</u>ostname
373  </td>
374  <td align="left" class="asearch-line">
375  <input id="records_field1" name="hostname" type="text" class="edit" size="35" accesskey="h" value="{$form['hostname']}" />
376  <div id="suggest_hostname" class="suggest"></div>
377  </td>
378  </tr>
379 
380  <tr>
381  <td align="right" class="asearch-line">
382  Subdomain (<u>z</u>one)
383  </td>
384  <td align="left" class="asearch-line">
385  <input id="dns_domain" name="domain" type="text" class="edit" size="35" accesskey="z" value="{$form['domain']}" />
386  <div id="suggest_dns_domain" class="suggest"></div>
387  </td>
388  </tr>
389 
390  <tr>
391  <td align="right" class="asearch-line">
392  Type
393  </td>
394  <td align="left" class="asearch-line">
395  <select id="dnstype" name="dnstype" class="edit" accesskey="u" >
396  <option></option>
397  <option>A</option>
398  <option>CNAME</option>
399  <option>NS</option>
400  <option>PTR</option>
401  <option>MX</option>
402  <option>SRV</option>
403  <option>TXT</option>
404  </select>
405  </td>
406  </tr>
407 
408  <tr>
409  <td align="right" class="asearch-line">
410  <u>I</u>P Address
411  </td>
412  <td align="left" class="asearch-line" nowrap="true">
413  <input id="dns_ip" name="ip" type="text" class="edit" size="15" accesskey="i" value="{$form['ip']}" />
414  <div id="suggest_dns_ip" class="suggest"></div>
415  </td>
416  </tr>
417 
418  <tr>
419  <td align="right" class="asearch-line">
420  <u>N</u>otes
421  </td>
422  <td align="left" class="asearch-line">
423  <input id="notes" name="notes" type="text" class="edit" size="17" accesskey="n" value="{$form['notes']}" />
424  <div id="suggest_notes" class="suggest"></div>
425  </td>
426  </tr>
427 
428 
429  <tr>
430  <td align="right" class="asearch-line">
431  &nbsp;
432  </td>
433  <td align="right" class="asearch-line">
434  Disable Wildcards: <input class="button" type="checkbox" name="nowildcard" {$wildchecked} title="Disable usage of SQL wildcards in queries, you must supply your own in the search form as needed.">
435  <input class="button" type="button" name="clear" value="Clear" onClick="clearElements('dns_record_search_form');">
436  <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results', xajax.getFormValues('dns_record_search_form'));">
437  </td>
438  </tr>
439 
440  </table>
441  </form>
442 
443  <!-- END DNS record Search Tab -->
444 
445 
446 
447  <!-- subnet Search Tab -->
448  <form id="subnet_search_form">
449  <input type="hidden" name="search_form_id" value="subnet_search_form">
450  <table id="subnets_search" style="display: none;" cellspacing="0" border="0" cellpadding="0">
451 
452  <tr>
453  <td align="right" class="asearch-line">
454  <u>V</u>lan
455  </td>
456  <td align="left" class="asearch-line">
457  <input id="subnets_field1" name="vlandesc" type="text" class="edit" size="32" accesskey="v" value="{$form['vlandesc']}" />
458  </td>
459  </tr>
460 
461  <tr>
462  <td align="right" class="asearch-line">
463  Subnet <u>T</u>ype
464  </td>
465  <td align="left" class="asearch-line">
466  <select id="nettype" name="nettype" class="edit" accesskey="u" accesskey="t" >
468  </select>
469  </td>
470  </tr>
471 
472  <tr>
473  <td align="right" class="asearch-line">
474  Subnet <u>N</u>ame
475  </td>
476  <td align="left" class="asearch-line">
477  <input id="subnet" name="subnetname" type="text" class="edit" size="32" accesskey="n" value="{$form['subnetname']}" />
478  <div id="suggest_subnet" class="suggest"></div>
479  </td>
480  </tr>
481 
482  <tr>
483  <td align="right" class="asearch-line">
484  <u>I</u>P Address
485  </td>
486  <td align="left" class="asearch-line" nowrap="true">
487  <input id="ip_subnet" name="ip_subnet" class="edit" type="text" size="15" accesskey="i" value="{$form['ip_subnet']}" />
488  <div id="suggest_ip_subnet" class="suggest"></div>
489  thru
490  <input id="ip_subnet_thru" name="ip_subnet_thru" class="edit" type="text" size="15" value="{$form['ip_subnet_thru']}" />
491  <div id="suggest_ip_subnet_thru" class="suggest"></div>
492  </td>
493  </tr>
494 
495  <tr>
496  <td align="right" class="asearch-line">
497  <u>C</u>ustom attribute
498  </td>
499  <td align="left" class="asearch-line">
500  <input id="custom_attribute_type_net" type="text" name="custom_attribute_type_net" size="20" class="edit" value="{$form['custom_attribute_type_net']}">
501  <div id="suggest_custom_attribute_type_net" class="suggest"></div>
502  <u>V</u>alue
503  <input id="ca_value_net" name="ca_value_net" type="text" class="edit" size="15" value="{$form['ca_value_net']}"/>
504  </td>
505  </tr>
506 
507  <tr>
508  <td align="right" class="asearch-line">
509  <u>T</u>ag
510  </td>
511  <td align="left" class="asearch-line">
512  <input id="tag_net" type="text" name="tag_net" size="20" class="edit" accesskey="t" value="{$form['tag_net']}">
513  <div id="suggest_tag_net" class="suggest"></div>
514  </td>
515  <tr>
516 
517  <tr>
518  <td align="right" class="asearch-line">
519  &nbsp;
520  </td>
521  <td align="right" class="asearch-line">
522  Disable Wildcards: <input class="button" type="checkbox" name="nowildcard" {$wildchecked} title="Disable usage of SQL wildcards in queries, you must supply your own in the search form as needed.">
523  <input class="button" type="button" name="reset" value="Clear" onClick="clearElements('subnet_search_form');">
524  <input class="button" type="button" name="search" value="Search" accesskey="s" onClick="xajax_window_submit('search_results', xajax.getFormValues('subnet_search_form'));">
525  </td>
526  </tr>
527 
528  </table>
529  </form>
530  <center><span style="font-weight: bold;color: green; font-size: small;" id="search_results_msg"></span></center>
531  </div>
532 
533  <!-- Item List -->
534  <div id="{$content_id}">{$conf['loading_icon']}</div>
535 EOL;
536 
537 //TODO: this is a test I did on having a click focus bring up the full list of entries.. kinda like a dropdown dialog..
538 //onfocus="suggest_display('role', 'suggest_role');searchKeyDown('37', el('role'), 'suggest_role');"
539 
540  // Before we can let the browser call "display_list"
541  // we need to make sure we know what type of list we'll be displaying
542  switch ($form['search_form_id']) {
543  case 'host_search_form':
544  $tab = 'hosts';
545  break;
546 
547  case 'subnet_search_form':
548  $tab = 'subnets';
549  break;
550 
551  case 'block_search_form':
552  $tab = 'blocks';
553  break;
554 
555  case 'vlan_campus_search_form':
556  $tab = 'vlan_campus';
557  break;
558 
559  case 'dns_record_search_form':
560  $tab = 'records';
561  break;
562 
563  case 'qsearch_form':
564  // If the quick search begins with a "/" it's a command
565  if (strpos($form['q'], '/') === 0) {
566  $form['q'] = substr($form['q'], 1);
567  return(qsearch_command($form['q']));
568  }
569  // We (unfortunately) have to do a few sql queries to see what kind of
570  // search this is and what "tab" we'll be displaying data on.
571  list($tab, $form) = quick_search($form['q']);
572  break;
573  }
574 
575  // Save a few things in the session (the search query, page, and tab)
576  $_SESSION['ona'][$form_id]['tab'] = $tab;
577  $_SESSION['ona'][$form_id][$tab]['q'] = $form;
578 
579 
580  // A little javascript for the browser to run once we've created the window
581  $window['js'] .= <<<EOL
582  /* Put a minimize icon in the title bar */
583  el('{$window_name}_title_r').innerHTML =
584  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
585  el('{$window_name}_title_r').innerHTML;
586 
587  /* Put a help icon in the title bar */
588  el('{$window_name}_title_r').innerHTML =
589  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
590  el('{$window_name}_title_r').innerHTML;
591 
592  /* Setup the quick filter */
593  el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px';
594  {$form_id}_last_search = '';
595 
596  /* Save the new tab and make it look active */
597  el('{$form_id}_tab').value = '{$tab}';
598  el('{$form_id}_{$tab}_tab').className = 'table-tab-active';
599  el('{$tab}_search').style.display = 'block';
600 
601  /* make the first field have focus */
602  el('{$tab}_field1').focus();
603 
604  suggest_setup('hosts_field1', 'suggest_hostname');
605  suggest_setup('domain', 'suggest_domain');
606  suggest_setup('dns_domain', 'suggest_dns_domain');
607  suggest_setup('mac', 'suggest_mac');
608  suggest_setup('ip', 'suggest_ip');
609  suggest_setup('dns_ip', 'suggest_dns_ip');
610  suggest_setup('ip_thru', 'suggest_ip_thru');
611  suggest_setup('notes', 'suggest_notes');
612  suggest_setup('ip_subnet', 'suggest_ip_subnet');
613  suggest_setup('ip_subnet_thru', 'suggest_ip_subnet_thru');
614  suggest_setup('subnet', 'suggest_subnet');
615  suggest_setup('location', 'suggest_location');
616  suggest_setup('custom_attribute_type', 'suggest_custom_attribute_type');
617  suggest_setup('custom_attribute_type_net', 'suggest_custom_attribute_type_net');
618  suggest_setup('role', 'suggest_role');
619  suggest_setup('model', 'suggest_model');
620  suggest_setup('manufacturer', 'suggest_manufacturer');
621  suggest_setup('tag_host', 'suggest_tag_host');
622  suggest_setup('tag_net', 'suggest_tag_net');
623 
624 
625  el('host_search_form').onsubmit = function() { return false; };
626  el('subnet_search_form').onsubmit = function() { return false; };
627 
628  /* Setup the Quick Find location icon */
629  var _button = el('qf_location_{$window_name}');
630  _button.style.cursor = 'pointer';
631  _button.onclick =
632  function(ev) {
633  if (!ev) ev = event;
634  /* Create the popup div */
635  wwTT(this, ev,
636  'id', 'tt_qf_location_{$window_name}',
637  'type', 'static',
638  'direction', 'south',
639  'delay', 0,
640  'styleClass', 'wwTT_qf',
641  'javascript',
642  "xajax_window_submit('tooltips', '" +
643  "tooltip=>qf_location," +
644  "id=>tt_qf_location_{$window_name}," +
645  "input_id=>qf_location_{$window_name}');"
646  );
647  };
648 
649  /* Display the list of results */
650  xajax_window_submit('list_' + el('{$form_id}_tab').value, xajax.getFormValues('{$form_id}'), 'display_list');
651 
652 
653 
654 EOL;
655 
656 
657  // Lets build a window and display the results
658  return(window_open($window_name, $window));
659 }
660 
661 
662 
663 
664 
665 
666 
667 
668 
669 
670 
671 
673 // Function:
674 // quick_search (string $q)
675 //
676 // Description:
677 // If a quick-search is being performed, find out if we'll be displaying
678 // subnets or hosts, and return a $tab and $form that will tell the
679 // appropriate display_list() function what to display.
681 function quick_search($q) {
682  global $conf, $self;
683 
684  //
685  // *** Quick Search ***
686  //
687  // If it's an IP or MAC address (string or numeric):
688  // Look for an interface and display associated host record
689  // Look for the subnet that IP is on and display a single subnet record
690  // If it's a string:
691  // Look for a hostname
692  // Look for an alias name (and display associated hosts)
693  // Look for a subnet name
694 
695  printmsg("DEBUG => quick_search({$q}) called", 3);
696 
697  // Check to see if it is a MAC.. do it here instead of in the next interface section
698  // so that we can properly find multiple hosts with the same mac
699  $mac = mac_mangle($q, 1);
700  if ($mac != -1) {
701  printmsg("DEBUG => quick_search() Looks like a MAC, Returning mac = {$q}" ,3);
702  return( array('hosts', array('mac' => $q) ) );
703  }
704 
705  // See if $q identifies an interface record (by IP, MAC, etc)
706  list($status, $rows, $record) = ona_find_interface($q);
707  // If it was, display the associated host record
708  if ($rows) {
709  printmsg("DEBUG => quick_search() returning host match (ID={$record['host_id']})", 3);
710  return( array('hosts', array('host_id' => $record['host_id']) ) );
711  }
712 
713  // See if $q identifies a subnet record (by IP, ID, or Description)
714  list($status, $rows, $record) = ona_find_subnet($q);
715  // If it was, display the associated subnet record
716  if ($rows) {
717  printmsg("DEBUG => quick_search() returning subnet match (ID={$record['id']})", 3);
718  return( array('subnets', array('subnet_id' => $record['id']) ) );
719  }
720 
721  // Well, I guess we'll assume $q is a hostname/alias search
722  printmsg("DEBUG => quick_search() found no subnet or host match. Returning hostname = {$q}" ,3);
723  return( array('hosts', array('hostname' => $q) ) );
724 }
725 
726 
727 
728 
729 
730 
731 
732 
733 
734 
735 
737 // Function:
738 // qsearch_command (string $q)
739 //
740 // QSearch Command Intrepreter
742 function qsearch_command($q) {
743  global $conf, $self, $images, $baseURL;
744  $js = "";
745 
746  // Instantiate the xajaxResponse object
747  $response = new xajaxResponse();
748 
749  // bz: FIXME!! Most of these should be moved to a user preferences application
750 
751  // Set list row length
752  // Note that when you remove this, you must also remove a few lines in the ona_functions include file
753  if (strpos($q, 'rows ') === 0) {
754  $q = str_replace('rows ', '', $q);
755  if (is_numeric($q)) {
756  $conf['search_results_per_page'] = $q;
757  $_SESSION['search_results_per_page'] = $q;
758  $js .= "alert('Lists will now display {$q} rows.');";
759  }
760  }
761 
762  if (strpos($q, 'context ') === 0) {
763  $q = str_replace('context ', '', $q);
764  if ($q) {
765  setcookie("ona_context_name", $q);
766  $js .= "alert('Database context is now: {$q}.');";
767  }
768  }
769 
770  // Reverse text flow
771  if ($q == 'textrtl') $js .= "document.body.style.direction = 'rtl';";
772 
773  // Normal text flow
774  if ($q == 'textltr') $js .= "document.body.style.direction = 'ltr';";
775 
776 
777  if ($js) {
778  $js .= "el('qsearch').value = ''; el('suggest_qsearch').style.display = 'none';";
779  $response->addScript($js);
780  return($response->getXML());
781  }
782  else {
783  $response->addScript("alert('Invalid command!');");
784  return($response->getXML());
785  }
786 }
787 
788 
789 
790 
791 
792 
793 
794 
795 
796 
797 
798 
800 // Function:
801 // change_tab (string $window_name, string $form_id, string $tab)
802 //
803 // Description:
804 // This function changes the "tab" a person is viewing by setting the
805 // new tab value in the _SESSION and then instructing the browser to do
806 // an xajax callback to the display_list() function.
808 function ws_change_tab($window_name, $form, $display_list=1, $return_text=0) {
809  global $conf, $self;
810 
811  // If the user supplied an array in a string, build the array and store it in $form
812  $form = parse_options_string($form);
813  $form_id = $form['form_id'];
814  $tab = $form['tab'];
815 
816  // Instantiate the xajaxResponse object
817  $response = new xajaxResponse();
818  $js = '';
819 
820  // Save the new tab in the session
821  $old_tab = $_SESSION['ona'][$form_id]['tab'];
822  $_SESSION['ona'][$form_id]['tab'] = $tab;
823 
824  // remove any messages
825  $js .= "el('search_results_msg').innerHTML = '';";
826 
827  // Make the old tab look inactive
828  $js .= "_el = el('{$form_id}_{$old_tab}_tab'); if (_el) _el.className = 'table-tab-inactive'; el('{$old_tab}_search').style.display = 'none';";
829 
830  // Make the new tab look active
831  $js .= "el('{$form_id}_{$tab}_tab').className = 'table-tab-active'; el('{$tab}_search').style.display = 'block';";
832 
833  // Set the "filter" to the correct value
834  $js .= "el('{$form_id}_filter').value = '{$_SESSION['ona'][$form_id][$tab]['filter']}';";
835 
836  // Set the "page" and "tab" to the correct value
837  $js .= "el('{$form_id}_page').value = '{$_SESSION['ona'][$form_id][$tab]['page']}';";
838  $js .= "el('{$form_id}_tab').value = '{$tab}';";
839 
840  // Put the cursor in the first field
841  $js .= "_el = el('{$tab}_field1'); if (_el) el('{$tab}_field1').focus();";
842 
843  // Hide/show the filter overlay
844  $js .= "el('{$form_id}_filter_overlay').style.display = (el('{$form_id}_filter').value == '') ? 'inline' : 'none';";
845 
846  // Tell the browser to ask for a new list of data
847  if ($display_list) {
848  $js .= "xajax_window_submit('list_{$tab}', xajax.getFormValues('{$form_id}'), 'display_list');";
849  }
850 
851  // If they asked us to return text, we return the javascript text..
852  if ($return_text) {
853  return($js);
854  }
855 
856  // Send an XML response to the window
857  $response->addAssign($_SESSION['ona'][$form_id]['content_id'], 'innerHTML', $conf['loading_icon']);
858  $response->addScript($js);
859  return($response->getXML());
860 }
861 
862 
863 
864 
865 
866 
867 
868 
869 
870 
871 
872 
873 
874 
875 ?>
onclick
_button onclick
Definition: app_advanced_search.inc.php:50
ona_find_subnet
ona_find_subnet($search="")
Definition: functions_db.inc.php:2003
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
db_get_records
db_get_records($dbh=0, $table="", $where="", $order="", $rows=-1, $offset=-1)
Definition: functions_db.inc.php:891
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
mac_mangle
mac_mangle($input="", $format="default")
Definition: functions_general.inc.php:964
xajax
$tab
$tab
Definition: app_config_type_list.inc.php:29
$window
$window['title']
Definition: install.php:26
$baseURL
$baseURL
Definition: config.inc.php:25
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
_button
_button
Definition: app_advanced_search.inc.php:48
ona_find_interface
ona_find_interface($search="")
Definition: functions_db.inc.php:1910
window_open
window_open($window_name, $window=array())
Definition: webwin.inc.php:59
ws_change_tab
ws_change_tab($window_name, $form, $display_list=1, $return_text=0)
Definition: search_results.inc.php:808
quick_search
quick_search($q)
Definition: search_results.inc.php:681
$form_id
$form_id
Definition: app_config_type_list.inc.php:28
$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
qsearch_command
qsearch_command($q)
Definition: search_results.inc.php:742
$_SESSION
$_SESSION['ona']['auth']
Definition: login.php:14
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$subnet_type_list
$subnet_type_list
Definition: app_advanced_search.inc.php:11
$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
$font_family
global $font_family
Definition: app_admin_tools.inc.php:4
$self
global $self
Definition: 2-to-3.php:15
ws_search_results_submit
ws_search_results_submit($window_name, $form='')
Definition: search_results.inc.php:15
$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