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)  

app_dns_view_list.inc.php
Go to the documentation of this file.
1 <?php
2 
3 //
4 // So, the basic flow of this script is like this:
5 // * When the window is initially opened we define the normal window
6 // parameters for building an almost empty window. After that new
7 // empty window is created it's instructed to run an xajax callback
8 // to the display_list() function. display_list() builds an
9 // html list of users and pushes it into the empty window.
10 // * If a search is entered into the "quick filter" another xajax
11 // call is made to display_list(), this time passing a search
12 // query. display_list() grabs the refined list of users
13 // and pushes them to the window just like the first time.
14 //
15 //
16 //
17 
18 // Check permissions
19 if (!auth('advanced')) {
20  $window['js'] = "removeElement('{$window_name}'); alert('Permission denied!');";
21  return;
22 }
23 
24 // Set the window title:
25 $window['title'] = "DNS View Administration";
26 
27 // Load some html into $window['html']
28 $form_id = "{$window_name}_filter_form";
29 $tab = 'dns_view';
30 $submit_window = $window_name;
31 $content_id = "{$window_name}_list";
32 $window['html'] .= <<<EOL
33  <!-- Tabs & Quick Filter -->
34  <table width="100%" cellspacing="0" border="0" cellpadding="0" >
35  <tr>
36  <td id="{$form_id}_{$tab}_tab" nowrap="true" class="table-tab-active">
37  DNS Views <span id="{$form_id}_{$tab}_count"></span>
38  </td>
39 
40  <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%">
41  <form id="{$form_id}" onSubmit="return false;">
42  <input id="{$form_id}_page" name="page" value="1" type="hidden">
43  <input name="content_id" value="{$content_id}" type="hidden">
44  <input name="form_id" value="{$form_id}" type="hidden">
45  <div id="{$form_id}_filter_overlay"
46  style="position: relative;
47  display: inline;
48  color: #CACACA;
49  cursor: text;"
50  onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();"
51  >Filter</div>
52  <input
53  id="{$form_id}_filter"
54  name="filter"
55  class="filter"
56  type="text"
57  value=""
58  size="10"
59  maxlength="20"
60  alt="Quick Filter"
61  onFocus="el('{$form_id}_filter_overlay').style.display = 'none';"
62  onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';"
63  onKeyUp="
64  if (typeof(timer) != 'undefined') clearTimeout(timer);
65  code = 'if ({$form_id}_last_search != el(\'{$form_id}_filter\').value) {' +
66  ' {$form_id}_last_search = el(\'{$form_id}_filter\').value;' +
67  ' document.getElementById(\'{$form_id}_page\').value = 1;' +
68  ' xajax_window_submit(\'{$submit_window}\', xajax.getFormValues(\'{$form_id}\'), \'display_list\');' +
69  '}';
70  timer = setTimeout(code, 700);"
71  >
72  </form>
73  </td>
74 
75  </tr>
76  </table>
77 
78  <!-- Item List -->
79  <div id='{$content_id}'>
80  {$conf['loading_icon']}
81  </div>
82 EOL;
83 
84 
85 
86 
87 
88 
89 
90 // Define javascript to run after the window is created
91 $window['js'] = <<<EOL
92  /* Put a minimize icon in the title bar */
93  el('{$window_name}_title_r').innerHTML =
94  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
95  el('{$window_name}_title_r').innerHTML;
96 
97  /* Put a help icon in the title bar */
98  el('{$window_name}_title_r').innerHTML =
99  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
100  el('{$window_name}_title_r').innerHTML;
101 
102  /* Setup the quick filter */
103  el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px';
104  {$form_id}_last_search = '';
105 
106  /* Tell the browser to load/display the list */
107  xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list');
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 // This function displays a list (all?) manufacturer types
122 function ws_display_list($window_name, $form) {
123  global $conf, $self, $onadb;
124  global $font_family, $color, $style, $images;
125 
126  // Check permissions
127  if (!auth('advanced')) {
128  $response = new xajaxResponse();
129  $response->addScript("alert('Permission denied!');");
130  return($response->getXML());
131  }
132 
133  // If the user supplied an array in a string, build the array and store it in $form
134  $form = parse_options_string($form);
135 
136  // Find out what page we're on
137  $page = 1;
138  if ($form['page'] and is_numeric($form['page'])) { $page = $form['page']; }
139 
140 
141  $html = <<<EOL
142 
143  <!-- Results Table -->
144  <table cellspacing="0" border="0" cellpadding="0" width="100%" class="list-box">
145 
146  <!-- Table Header -->
147  <tr>
148  <td class="list-header" align="center" style="{$style['borderR']};">Name</td>
149  <td class="list-header" align="center" style="{$style['borderR']};">Description</td>
150  <td class="list-header" align="center" style="{$style['borderR']};">Usage</td>
151  <td class="list-header" align="center">&nbsp;</td>
152  </tr>
153 
154 EOL;
155 
156  $where = 'id >= 0';
157  if (is_array($form) and $form['filter']) {
158  $where = 'name LIKE ' . $onadb->qstr('%'.$form['filter'].'%');
159  }
160  // Offset for SQL query
161  $offset = ($conf['search_results_per_page'] * ($page - 1));
162  if ($offset == 0) { $offset = -1; }
163 
164  // Get list of elements
165  list($status, $rows, $records) = db_get_records($onadb,
166  'dns_views',
167  $where,
168  'name',
169  $conf['search_results_per_page'],
170  $offset);
171 
172  // If we got less than serach_results_per_page, add the current offset to it
173  // so that if we're on the last page $rows still has the right number in it.
174  if ($rows > 0 and $rows < $conf['search_results_per_page']) {
175  $rows += ($conf['search_results_per_page'] * ($page - 1));
176  }
177 
178  // If there were more than $conf['search_results_per_page'] find out how many records there really are
179  else if ($rows >= $conf['search_results_per_page']) {
180  list ($status, $rows, $tmp) = db_get_records($onadb,
181  'dns_views',
182  $where,
183  '',
184  0);
185  }
186  $count = $rows;
187 
188 
189  // Loop through and display the users
190  foreach ($records as $record) {
191 
192  list ($status, $usage_rows, $tmp) = db_get_records($onadb, 'dns', "dns_view_id = {$record['id']}", '', 0);
193 
194  // Escape data for display in html
195  foreach(array_keys($record) as $key) {
196  $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
197  }
198 
199  $html .= <<<EOL
200  <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
201 
202  <td class="list-row">
203  <a title="Edit dns view. id: {$record['id']}"
204  class="act"
205  onClick="xajax_window_submit('app_dns_view_edit', 'id=>{$record['id']}', 'editor');"
206  >{$record['name']}</a>&nbsp;
207  </td>
208 
209  <td class="list-row">
210  {$record['description']}&nbsp;
211  </td>
212 
213  <td class="list-row">
214  {$usage_rows}&nbsp;
215  </td>
216 
217  <td align="right" class="list-row" nowrap="true">
218  <a title="Edit dns view. id: {$record['id']}"
219  class="act"
220  onClick="xajax_window_submit('app_dns_view_edit', 'id=>{$record['id']}', 'editor');"
221  ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;
222 EOL;
223 
224  // Dont allow user to delete the default view
225  if ($record['id'] == 0) {
226  $html .= <<<EOL
227  <a title="You can not delete the default DNS view."
228  class="act"
229  ><img src="{$images}/silk/lock.png" border="0"></a>&nbsp;
230 EOL;
231  } else {
232  $html .= <<<EOL
233  <a title="Delete dns view. id: {$record['id']}"
234  class="act"
235  onClick="var doit=confirm('Are you sure you want to delete this DNS view?');
236  if (doit == true)
237  xajax_window_submit('{$window_name}', '{$record['id']}', 'delete');"
238  ><img src="{$images}/silk/delete.png" border="0"></a>&nbsp;
239 EOL;
240  }
241  $html .= <<<EOL
242  </td>
243 
244  </tr>
245 EOL;
246  }
247 
248  $html .= <<<EOL
249  </table>
250 
251  <!-- Add a new record -->
252  <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}; border-bottom: 1px solid {$color['border']};">
253  <!-- ADD LINK -->
254  <a title="New DNS view"
255  class="act"
256  onClick="xajax_window_submit('app_dns_view_edit', ' ', 'editor');"
257  ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;
258 
259  <a title="New DNS view"
260  class="act"
261  onClick="xajax_window_submit('app_dns_view_edit', ' ', 'editor');"
262  >Add DNS view</a>&nbsp;
263  </div>
264 EOL;
265 
266 
267  // Build page links if there are any
268  $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
269 
270 
271  // Insert the new table into the window
272  // Instantiate the xajaxResponse object
273  $response = new xajaxResponse();
274  $response->addAssign("{$form['form_id']}_dns_view_count", "innerHTML", "({$count})");
275  $response->addAssign("{$form['content_id']}", "innerHTML", $html);
276  // $response->addScript($js);
277  return($response->getXML());
278 }
279 
280 
281 
282 
283 
284 
286 // Function:
287 // Delete
288 //
289 // Description:
290 // Deletes a DNS view.
292 function ws_delete($window_name, $form='') {
293  global $conf, $self, $onadb;
294 
295  // Check permissions
296  if (!auth('advanced')) {
297  $response = new xajaxResponse();
298  $response->addScript("alert('Permission denied!');");
299  return($response->getXML());
300  }
301 
302  // Instantiate the xajaxResponse object
303  $response = new xajaxResponse();
304  $js = '';
305 
306  // Don't allow them to delete the default
307  if ($form == 0) {
308  $response->addScript("alert('You are not allowed to delete the default DNS view.');");
309  return($response->getXML());
310  }
311 
312  // Load the record to make sure it exists
313  list($status, $rows, $record) = db_get_record($onadb,
314  'dns_views',
315  array('id' => $form));
316  if ($status or !$rows) {
317  $response->addScript("alert('Delete failed: DNS view id {$form} does not exist');");
318  return($response->getXML());
319  }
320 
321  // Get a list of device models that use this manufacturer
322  list($status, $rows, $dnsrecords) = db_get_records($onadb,
323  'dns',
324  array('dns_view_id' => $form),
325  '',
326  0);
327 
328  // Check that there are no parent records using this type
329  if ($rows > 0) {
330  $js .= "alert('Delete failed: There are {$rows} DNS records using this view.');";
331  }
332  else {
333  // Delete the record
334  list($status, $rows) = db_delete_records($onadb,
335  'dns_views',
336  array('id' => $record['id']));
337 
338  if ($status or !$rows) {
339  // If the module returned an error code display a popup warning
340  $js .= "alert('Delete failed: " . trim($self['error']) . "');";
341  $self['error'] = "ERROR => dns_view_list ws_delete() SQL Query failed: " . $self['error'];
342  printmsg($self['error'], 1);
343  }
344  else {
345  $self['error'] = "INFO => DNS view DELETED: {$recprd['name']} ";
346  printmsg($self['error'], 0);
347  }
348  }
349 
350  // Refresh the current list.. it's changed!
351  $js .= "xajax_window_submit('$window_name', xajax.getFormValues('{$window_name}_filter_form'), 'display_list');";
352 
353  // Send an XML response
354  $response->addScript($js);
355  return($response->getXML());
356 }
357 
358 
359 
360 
361 
362 
363 ?>
$form_id
$form_id
Definition: app_dns_view_list.inc.php:28
$tab
$tab
Definition: app_dns_view_list.inc.php:29
$window
if(!auth('advanced')) $window['title']
Definition: app_dns_view_list.inc.php:25
Name
Full Name
Definition: app_user_info.inc.php:101
$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
xajax
$submit_window
$submit_window
Definition: app_dns_view_list.inc.php:30
ws_display_list
ws_display_list($window_name, $form)
Definition: app_dns_view_list.inc.php:122
db_delete_records
db_delete_records($dbh=0, $table="", $where="")
Definition: functions_db.inc.php:582
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
$images
$images
Definition: config.inc.php:26
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$style
$style['font-family']
Definition: config.inc.php:158
$content_id
$content_id
Definition: app_dns_view_list.inc.php:31
nbsp
& nbsp
Definition: install.php:36
$font_family
global $font_family
Definition: app_admin_tools.inc.php:4
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
db_get_record
db_get_record($dbh=0, $table="", $where="", $order="")
Definition: functions_db.inc.php:708
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
EOL
EOL
Definition: app_dns_view_list.inc.php:108
ws_delete
ws_delete($window_name, $form='')
Definition: app_dns_view_list.inc.php:292
$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