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_config_type_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'] = "Config Type Administration";
26 
27 // Load some html into $window['html']
28 $form_id = "{$window_name}_filter_form";
29 $tab = 'configuration_type';
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  Configuration Types <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']};">Conf Type</td>
149  <td class="list-header" align="center" style="{$style['borderR']};">Usage</td>
150  <td class="list-header" align="center">&nbsp;</td>
151  </tr>
152 
153 EOL;
154 
155  $where = 'id > 0';
156  if (is_array($form) and $form['filter']) {
157  $where = 'name LIKE ' . $onadb->qstr('%'.$form['filter'].'%');
158  }
159  // Offset for SQL query
160  $offset = ($conf['search_results_per_page'] * ($page - 1));
161  if ($offset == 0) { $offset = -1; }
162 
163  // Get list of elements
164  list($status, $rows, $records) = db_get_records($onadb,
165  'configuration_types',
166  $where,
167  'name',
168  $conf['search_results_per_page'],
169  $offset);
170 
171  // If we got less than serach_results_per_page, add the current offset to it
172  // so that if we're on the last page $rows still has the right number in it.
173  if ($rows > 0 and $rows < $conf['search_results_per_page']) {
174  $rows += ($conf['search_results_per_page'] * ($page - 1));
175  }
176 
177  // If there were more than $conf['search_results_per_page'] find out how many records there really are
178  else if ($rows >= $conf['search_results_per_page']) {
179  list ($status, $rows, $tmp) = db_get_records($onadb,
180  'configuration_types',
181  $where,
182  '',
183  0);
184  }
185  $count = $rows;
186 
187 
188  // Loop through and display the users
189  foreach ($records as $record) {
190 
191  list ($status, $usage_rows, $tmp) = db_get_records($onadb, 'configurations', "configuration_type_id = {$record['id']}", '', 0);
192 
193  // Escape data for display in html
194  foreach(array_keys($record) as $key) {
195  $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
196  }
197 
198  $html .= <<<EOL
199  <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
200 
201  <td class="list-row">
202  <a title="Edit config type. id: {$record['id']}"
203  class="act"
204  onClick="xajax_window_submit('app_config_type_edit', '{$record['id']}', 'editor');"
205  >{$record['name']}</a>&nbsp;
206  </td>
207 
208  <td class="list-row">
209  {$usage_rows}&nbsp;
210  </td>
211 
212  <td align="right" class="list-row" nowrap="true">
213  <a title="Edit config type. id: {$record['id']}"
214  class="act"
215  onClick="xajax_window_submit('app_config_type_edit', '{$record['id']}', 'editor');"
216  ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;
217 
218  <a title="Delete config type. id: {$record['id']}"
219  class="act"
220  onClick="var doit=confirm('Are you sure you want to delete this configuration type?');
221  if (doit == true)
222  xajax_window_submit('{$window_name}', '{$record['id']}', 'delete');"
223  ><img src="{$images}/silk/delete.png" border="0"></a>&nbsp;
224  </td>
225 
226  </tr>
227 EOL;
228  }
229 
230  $html .= <<<EOL
231  </table>
232 
233  <!-- Add a new record -->
234  <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}; border-bottom: 1px solid {$color['border']};">
235  <!-- ADD LINK -->
236  <a title="New config type"
237  class="act"
238  onClick="xajax_window_submit('app_config_type_edit', ' ', 'editor');"
239  ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;
240 
241  <a title="New config type"
242  class="act"
243  onClick="xajax_window_submit('app_config_type_edit', ' ', 'editor');"
244  >Add config type</a>&nbsp;
245  </div>
246 EOL;
247 
248 
249  // Build page links if there are any
250  $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
251 
252 
253  // Insert the new table into the window
254  // Instantiate the xajaxResponse object
255  $response = new xajaxResponse();
256  $response->addAssign("{$form['form_id']}_configuration_type_count", "innerHTML", "({$count})");
257  $response->addAssign("{$form['content_id']}", "innerHTML", $html);
258  // $response->addScript($js);
259  return($response->getXML());
260 }
261 
262 
263 
264 
265 
266 
268 // Function:
269 // Delete
270 //
271 // Description:
272 // Deletes a config type.
274 function ws_delete($window_name, $form='') {
275  global $conf, $self, $onadb;
276 
277  // Check permissions
278  if (!auth('advanced')) {
279  $response = new xajaxResponse();
280  $response->addScript("alert('Permission denied!');");
281  return($response->getXML());
282  }
283 
284  // Instantiate the xajaxResponse object
285  $response = new xajaxResponse();
286  $js = '';
287 
288  // Load the record to make sure it exists
289  list($status, $rows, $conftype) = db_get_record($onadb,
290  'configuration_types',
291  array('id' => $form));
292  if ($status or !$rows) {
293  $response->addScript("alert('Delete failed: Configuration type id {$form} does not exist');");
294  return($response->getXML());
295  }
296 
297  // Get a list of device models that use this manufacturer
298  list($status, $rows, $configs) = db_get_records($onadb,
299  'configurations',
300  array('configuration_type_id' => $form),
301  '',
302  0);
303 
304  // Check that there are no parent records using this type
305  if ($rows > 0) {
306  $js .= "alert('Delete failed: There are {$rows} configurations using this configuration type.');";
307  }
308  else {
309  // Delete the record
310  list($status, $rows) = db_delete_records($onadb,
311  'configuration_types',
312  array('id' => $conftype['id']));
313 
314  if ($status or !$rows) {
315  // If the module returned an error code display a popup warning
316  $js .= "alert('Delete failed: " . trim($self['error']) . "');";
317  $self['error'] = "ERROR => config_type_list ws_delete() SQL Query failed: " . $self['error'];
318  printmsg($self['error'], 0);
319  }
320  else {
321  $self['error'] = "INFO => Configuration type DELETED: {$conftype['name']} ";
322  printmsg($self['error'], 0);
323  }
324  }
325 
326  // Refresh the current list.. it's changed!
327  $js .= "xajax_window_submit('$window_name', xajax.getFormValues('{$window_name}_filter_form'), 'display_list');";
328 
329  // Send an XML response
330  $response->addScript($js);
331  return($response->getXML());
332 }
333 
334 
335 
336 
337 
338 
339 ?>
ws_delete
ws_delete($window_name, $form='')
Definition: app_config_type_list.inc.php:274
$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
$tab
$tab
Definition: app_config_type_list.inc.php:29
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
EOL
EOL
Definition: app_config_type_list.inc.php:108
$window
if(!auth('advanced')) $window['title']
Definition: app_config_type_list.inc.php:25
$form_id
$form_id
Definition: app_config_type_list.inc.php:28
$images
$images
Definition: config.inc.php:26
$submit_window
$submit_window
Definition: app_config_type_list.inc.php:30
$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
$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
ws_display_list
ws_display_list($window_name, $form)
Definition: app_config_type_list.inc.php:122
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