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_location_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 
19 
20 // Check permissions
21 if (!auth('location_add')) {
22  $window['js'] = "removeElement('{$window_name}'); alert('Permission denied!');";
23  return;
24 }
25 
26 
27 // Set the window title:
28 $window['title'] = "Location Administration";
29 
30 // Load some html into $window['html']
31 $form_id = "{$window_name}_filter_form";
32 $tab = 'locations';
33 $submit_window = $window_name;
34 $content_id = "{$window_name}_list";
35 $window['html'] .= <<<EOL
36  <!-- Tabs & Quick Filter -->
37  <table width="100%" cellspacing="0" border="0" cellpadding="0" >
38  <tr>
39  <td id="{$form_id}_{$tab}_tab" nowrap="true" class="table-tab-active">
40  Locations <span id="{$form_id}_{$tab}_count"></span>
41  </td>
42 
43  <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%">
44  <form id="{$form_id}" onSubmit="return false;">
45  <input id="{$form_id}_page" name="page" value="1" type="hidden">
46  <input name="content_id" value="{$content_id}" type="hidden">
47  <input name="form_id" value="{$form_id}" type="hidden">
48  <div id="{$form_id}_filter_overlay"
49  style="position: relative;
50  display: inline;
51  color: #CACACA;
52  cursor: text;"
53  onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();"
54  >Filter</div>
55  <input
56  id="{$form_id}_filter"
57  name="filter"
58  class="filter"
59  type="text"
60  value=""
61  size="10"
62  maxlength="20"
63  alt="Quick Filter"
64  onFocus="el('{$form_id}_filter_overlay').style.display = 'none';"
65  onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';"
66  onKeyUp="
67  if (typeof(timer) != 'undefined') clearTimeout(timer);
68  code = 'if ({$form_id}_last_search != el(\'{$form_id}_filter\').value) {' +
69  ' {$form_id}_last_search = el(\'{$form_id}_filter\').value;' +
70  ' document.getElementById(\'{$form_id}_page\').value = 1;' +
71  ' xajax_window_submit(\'{$submit_window}\', xajax.getFormValues(\'{$form_id}\'), \'display_list\');' +
72  '}';
73  timer = setTimeout(code, 700);"
74  >
75  </form>
76  </td>
77 
78  </tr>
79  </table>
80 
81  <!-- Item List -->
82  <div id='{$content_id}'>
83  {$conf['loading_icon']}
84  </div>
85 EOL;
86 
87 
88 
89 
90 
91 
92 
93 // Define javascript to run after the window is created
94 $window['js'] = <<<EOL
95  /* Put a minimize icon in the title bar */
96  el('{$window_name}_title_r').innerHTML =
97  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
98  el('{$window_name}_title_r').innerHTML;
99 
100  /* Put a help icon in the title bar */
101  el('{$window_name}_title_r').innerHTML =
102  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
103  el('{$window_name}_title_r').innerHTML;
104 
105  /* Setup the quick filter */
106  el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px';
107  {$form_id}_last_search = '';
108 
109  /* Tell the browser to load/display the list */
110  xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list');
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 // This function displays a list (all?) users in the
125 function ws_display_list($window_name, $form) {
126  global $conf, $self, $onadb;
127  global $font_family, $color, $style, $images;
128 
129  // Check permissions
130  if (!auth('location_add')) {
131  $response = new xajaxResponse();
132  $response->addScript("alert('Permission denied!');");
133  return($response->getXML());
134  }
135 
136  // If the user supplied an array in a string, build the array and store it in $form
137  $form = parse_options_string($form);
138 
139  // Find out what page we're on
140  $page = 1;
141  if ($form['page'] and is_numeric($form['page'])) { $page = $form['page']; }
142 
143 
144  $html = <<<EOL
145 
146  <!-- Results Table -->
147  <table cellspacing="0" border="0" cellpadding="0" width="100%" class="list-box">
148 
149  <!-- Table Header -->
150  <tr>
151  <td class="list-header" align="center" style="{$style['borderR']};">Reference</td>
152  <td class="list-header" align="center" style="{$style['borderR']};">Name</td>
153  <td class="list-header" align="center" style="{$style['borderR']};">City</td>
154  <td class="list-header" align="center" style="{$style['borderR']};">State</td>
155  <td class="list-header" align="center" style="{$style['borderR']};">Usage</td>
156  <td class="list-header" align="center">&nbsp;</td>
157  </tr>
158 
159 EOL;
160 
161  $where = '`id` > 0';
162  if (is_array($form) and $form['filter']) {
163  $where = '`reference` LIKE ' . $onadb->qstr('%'.$form['filter'].'%');
164  }
165  // Offset for SQL query
166  $offset = ($conf['search_results_per_page'] * ($page - 1));
167  if ($offset == 0) { $offset = -1; }
168 
169  // Get our locations
170  list($status, $rows, $records) = db_get_records($onadb, 'locations', $where, 'reference', $conf['search_results_per_page'], $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, 'locations', $where, '', 0);
181  }
182  $count = $rows;
183 
184 
185  // Loop through and display the records
186  foreach ($records as $record) {
187 
188  list($status, $usage, $devs) = db_get_records($onadb, 'devices', array('location_id' => $record['id']), '' ,0);
189 
190  // Escape data for display in html
191  foreach(array_keys($record) as $key) {$record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);}
192 
193  $html .= <<<EOL
194  <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
195 
196  <td class="list-row">
197  <a title="Edit location. ID: {$record['id']}"
198  class="act"
199  onClick="xajax_window_submit('edit_location', 'id=>{$record['id']}', 'editor');"
200  >{$record['reference']}</a>&nbsp;
201  </td>
202 
203  <td class="list-row">
204  {$record['name']}&nbsp;
205  </td>
206 
207  <td class="list-row">
208  {$record['city']}&nbsp;
209  </td>
210 
211  <td class="list-row">
212  {$record['state']}&nbsp;
213  </td>
214 
215  <td class="list-row">
216  {$usage}&nbsp;
217  </td>
218 
219  <td align="right" class="list-row" nowrap="true">
220  <a title="Edit location. ID: {$record['id']}"
221  class="act"
222  onClick="xajax_window_submit('edit_location', 'id=>{$record['id']}', 'editor');"
223  ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;
224 
225  <a title="Delete location: ID: {$record['id']}"
226  class="act"
227  onClick="var doit=confirm('Are you sure you want to delete this location?');
228  if (doit == true)
229  xajax_window_submit('{$window_name}', 'id=>{$record['id']}', 'delete');"
230  ><img src="{$images}/silk/delete.png" border="0"></a>&nbsp;
231  </td>
232 
233  </tr>
234 EOL;
235  }
236 
237  $html .= <<<EOL
238  </table>
239 
240  <!-- Add a new record -->
241  <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}; border-bottom: 1px solid {$color['border']};">
242  <!-- ADD LOCATION LINK -->
243  <a title="New location"
244  class="act"
245  onClick="xajax_window_submit('edit_location', ' ', 'editor');"
246  ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;
247 
248  <a title="New location"
249  class="act"
250  onClick="xajax_window_submit('edit_location', ' ', 'editor');"
251  >Add new location</a>&nbsp;
252  </div>
253 EOL;
254 
255 
256  // Build page links if there are any
257  $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
258 
259 
260  // Insert the new table into the window
261  // Instantiate the xajaxResponse object
262  $response = new xajaxResponse();
263  $response->addAssign("{$form['form_id']}_locations_count", "innerHTML", "({$count})");
264  $response->addAssign("{$form['content_id']}", "innerHTML", $html);
265  $response->addScript($js);
266  return($response->getXML());
267 }
268 
269 
270 
271 
272 
273 
275 // Function:
276 // Delete
277 //
278 // Description:
279 // Deletes a location.
281 function ws_delete($window_name, $form='') {
282  global $conf, $self, $onadb;
283 
284  // Check permissions
285  if (!auth('location_del')) {
286  $response = new xajaxResponse();
287  $response->addScript("alert('Permission denied!');");
288  return($response->getXML());
289  }
290 
291  // If the user supplied an array in a string, build the array and store it in $form
292  $form = parse_options_string($form);
293 
294  // Instantiate the xajaxResponse object
295  $response = new xajaxResponse();
296  $js = '';
297 
298  // Get a list of devices that use this device type
299  list($status, $rows, $devices) = db_get_records($onadb, 'devices', array('location_id' => $form['id']), '', 0);
300  // Check that there are no parent records using this type
301  if ($rows > 0) {
302  $js .= "alert('Delete failed: There are {$rows} devices using this location.');";
303  }
304  else {
305 
306  // Delete the record
307  list($status, $output) = run_module('location_del', array('reference' => $form['id'], 'commit' => 'Y'));
308 
309  // If the module returned an error code display a popup warning
310  if ($status != 0) {
311  $js .= "alert('Delete failed:" . trim($self['error']) . ");";
312  $self['error'] = "ERROR => location delete ws_save() SQL Query failed: " . $self['error'];
313  printmsg($self['error'], 0);
314  }
315  else {
316  $self['error'] = "INFO => location DELETED: {$loc['reference']} ({$loc['name']})";
317  printmsg($self['error'], 0);
318  // Refresh the current list.. it's changed!
319  $js .= "xajax_window_submit('$window_name', xajax.getFormValues('{$window_name}_filter_form'), 'display_list');";
320  }
321  }
322 
323  // Send an XML response
324  $response->addScript($js);
325  return($response->getXML());
326 }
327 
328 
329 
330 
331 
332 
333 ?>
ws_display_list
ws_display_list($window_name, $form)
Definition: app_location_list.inc.php:125
$window
if(!auth('location_add')) $window['title']
Definition: app_location_list.inc.php:28
Name
Full Name
Definition: app_user_info.inc.php:101
ws_delete
ws_delete($window_name, $form='')
Definition: app_location_list.inc.php:281
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
EOL
EOL
Definition: app_location_list.inc.php:111
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
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
$tab
$tab
Definition: app_location_list.inc.php:32
$content_id
$content_id
Definition: app_location_list.inc.php:34
run_module
run_module($module='', $options='', $transaction=1)
Definition: functions_general.inc.php:1468
$images
$images
Definition: config.inc.php:26
$form_id
$form_id
Definition: app_location_list.inc.php:31
$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
$font_family
global $font_family
Definition: app_admin_tools.inc.php:4
$output
$output
Definition: dcm.php:16
$submit_window
$submit_window
Definition: app_location_list.inc.php:33
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