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)  

list_blocks.inc.php
Go to the documentation of this file.
1 <?php
2 
3 
4 
6 // Function: ws_display_list()
7 //
8 // Description:
9 // Displays A list of blocks based on search criteria.
10 // Input: An array from xajaxGetFormValues() from a quick filter form.
12 function ws_display_list($window_name, $form='') {
13  global $conf, $self, $onadb;
14  global $images, $color, $style;
15  $html = '';
16  $js = '';
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  // Find the "tab" we're on
22  $tab = $_SESSION['ona'][$form['form_id']]['tab'];
23 
24  // Build js to refresh this list
25  $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
26 
27  // If it's not a new query, load the previous query from the session
28  // into $form and save the current page and filter in the session.
29  // Also find/set the "page" we're viewing
30  $page = 1;
31  if ($form['page'] and is_numeric($form['page'])) {
32  $form = array_merge($form, (array)$_SESSION['ona'][$form['form_id']][$tab]['q']);
33  $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page'];
34  $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter'];
35  }
36 
37  // Calculate the SQL query offset (based on the page being displayed)
38  $offset = ($conf['search_results_per_page'] * ($page - 1));
39  if ($offset == 0) { $offset = -1; }
40 
41  // Search results go in here
42  $results = array();
43  $count = 0;
44 
45  // Start building the "where" clause for the sql query to find the blocks to display
46  $where = "";
47  $and = "";
48 
49  // DISPLAY ALL BLOCKS
50  if ($form['all_flag']) {
51  $where .= $and . "id > 0";
52  $and = " AND ";
53  }
54 
55  // BLOCK ID
56  if ($form['id']) {
57  $where .= $and . "id = " . $onadb->qstr($form['id']);
58  $and = " AND ";
59  }
60 
61  // BLOCK , assume a block descripton
62  if ($form['blockname']) {
63  $where .= $and . "name LIKE " . $onadb->qstr('%'.strtoupper($form['blockname']).'%');
64  $and = " AND ";
65  }
66 
67  // display a nice message when we dont find all the records
68  if ($where == '' and $form['content_id'] == 'search_results_list') {
69  $js .= "el('search_results_msg').innerHTML = 'Unable to find blocks matching your query, showing all records';";
70  }
71 
72  // Wild card .. if $while is still empty, add a 'ID > 0' to it so you see everything.
73  if ($where == '')
74  $where = 'id > 0';
75 
76  // Do the SQL Query
77  $filter = '';
78  if ($form['filter']) {
79 
80  $filter = ' AND name LIKE ' . $onadb->qstr('%'.$form['filter'].'%');
81  }
82  list ($status, $rows, $results) =
84  $onadb,
85  'blocks',
86  $where . $filter,
87  "ip_addr_start ASC",
88  $conf['search_results_per_page'],
89  $offset
90  );
91 
92  // If we got less than search_results_per_page, add the current offset to it
93  // so that if we're on the last page $rows still has the right number in it.
94  if ($rows > 0 and $rows < $conf['search_results_per_page']) {
95  $rows += ($conf['search_results_per_page'] * ($page - 1));
96  }
97 
98  // If there were more than $conf['search_results_per_page'] find out how many records there really are
99  else if ($rows >= $conf['search_results_per_page']) {
100  list ($status, $rows, $records) =
102  $onadb,
103  'blocks',
104  $where . $filter,
105  "",
106  0
107  );
108  }
109  $count = $rows;
110 
111  $html .= <<<EOL
112  <!-- Block List -->
113  <table id="{$form['form_id']}_block_list" class="list-box" cellspacing="0" border="0" cellpadding="0">
114 
115  <!-- Table Header -->
116  <tr>
117  <td class="list-header" align="center" style="{$style['borderR']};">Block Name</td>
118  <td class="list-header" align="center" style="{$style['borderR']};">Starting IP</td>
119  <td class="list-header" align="center" style="{$style['borderR']};">Ending IP</td>
120  <td class="list-header" align="center">&nbsp;</td>
121  </tr>
122 EOL;
123 
124  // Loop and display each record
125  foreach($results as $record) {
126  // Grab some info from the associated block record
127  list($status, $rows, $block) = ona_get_block_record(array('id' => $record['id']));
128  $num_hosts = 0xffffffff - $block['ip_addr_end'];
129  $block['ip_block_end'] = ($block['ip_addr'] + $num_hosts);
130 
131  $record['name'] = $block['name'];
132 
133  // Convert IP and Netmask to a presentable format
134  $record['ip_addr_start'] = ip_mangle($record['ip_addr_start'], 'dotted');
135  $record['ip_addr_end'] = ip_mangle($block['ip_addr_end'], 'dotted');
136 
137  // Escape data for display in html
138  foreach(array_keys($record) as $key) {
139  $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
140  }
141 
142  $primary_object_js = "xajax_window_submit('work_space', 'xajax_window_submit(\'display_block\', \'block_id=>{$record['id']}\', \'display\')');";
143  $html .= <<<EOL
144  <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
145 
146  <td class="list-row" align="left">
147  <a title="View block. ID: {$record['id']}"
148  class="nav"
149  onClick="{$primary_object_js}"
150  >{$record['name']}</a>
151  </td>
152 
153  <td class="list-row" align="left">
154  {$record['ip_addr_start']}&nbsp;
155  </td>
156 
157  <td class="list-row" align="left">
158  {$record['ip_addr_end']}&nbsp;
159  </td>
160 
161  <td class="list-row" align="right">
162  <form id="{$form['form_id']}_list_block_{$record['id']}"
163  ><input type="hidden" name="block_id" value="{$record['id']}"
164  ><input type="hidden" name="js" value="{$refresh}"
165  ></form>
166 EOL;
167 
168  if (auth('advanced')) {
169  $html .= <<<EOL
170 
171  <a title="Edit block. ID: {$record['id']}"
172  class="act"
173  onClick="xajax_window_submit('edit_block', xajax.getFormValues('{$form['form_id']}_list_block_{$record['id']}'), 'editor');"
174  ><img src="{$images}/silk/brick_edit.png" border="0"></a>&nbsp;
175 EOL;
176  }
177  $html .= <<<EOL
178  <a title="Display subnet map"
179  class="act"
180  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_block_map\', \'ip_block_start=>{$record['ip_addr_start']},ip_block_end=>{$record['ip_addr_end']},id=>{$record['id']}\', \'display\');');"
181  ><img src="{$images}/silk/shape_align_left.png" border="0"></a>&nbsp;
182 EOL;
183 
184  if (auth('advanced')) {
185  $html .= <<<EOL
186 
187  <a title="Delete block"
188  class="act"
189  onClick="var doit=confirm('Are you sure you want to delete this block?');
190  if (doit == true)
191  xajax_window_submit('edit_block', xajax.getFormValues('{$form['form_id']}_list_block_{$record['id']}'), 'delete');"
192  ><img src="{$images}/silk/delete.png" border="0"></a>
193 EOL;
194  }
195 
196  $html .= <<<EOL
197  &nbsp;
198  </td>
199 
200  </tr>
201 
202 EOL;
203  }
204 
205  $html .= <<<EOL
206  </table>
207 EOL;
208  // Build page links if there are any
209  $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
210 
211  // If there was only 1 result, and we're about to display results in the "Search Results" window, display it.
212  if ($count == 1 and $form['content_id'] == 'search_results_list' and $form['filter'] == '')
213  $js .= $primary_object_js;
214 
215 
216 
217  // Insert the new html into the content div specified
218  // Instantiate the xajaxResponse object
219  $response = new xajaxResponse();
220  $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
221  $response->addAssign($form['content_id'], "innerHTML", $html);
222  if ($js) { $response->addScript($js); }
223  return($response->getXML());
224 }
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 ?>
Name
Full Name
Definition: app_user_info.inc.php:101
ip_mangle
ip_mangle($ip="", $format="default")
Definition: functions_general.inc.php:308
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
ws_display_list
ws_display_list($window_name, $form='')
Definition: list_blocks.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
ona_get_block_record
ona_get_block_record($array='', $order='')
Definition: functions_db.inc.php:1118
$tab
$tab
Definition: app_config_type_list.inc.php:29
$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
$_SESSION
$_SESSION['ona']['auth']
Definition: login.php:14
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$style
$style['font-family']
Definition: config.inc.php:158
nbsp
& nbsp
Definition: install.php:36
get_page_links
get_page_links($page=1, $per_page=1, $total=1, $window_name='', $form_id='')
Definition: xajax_setup.inc.php:115
$self
global $self
Definition: 2-to-3.php:15
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
$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