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)  

edit_block.inc.php
Go to the documentation of this file.
1 <?php
2 
3 
4 
6 // Function: ws_editor()
7 //
8 // Description:
9 // Displays a form for creating/editing an block record.
10 // If $form is a valid BLOCK_ID, it is used to display an existing
11 // record for editing. "Save" button calls the ws_save() function.
13 function ws_editor($window_name, $form='') {
14  global $conf, $self, $onadb;
16  $window = array();
17 
18  // Check permissions
19  if (!auth('advanced')) {
20  $response = new xajaxResponse();
21  $response->addScript("alert('Permission denied!');");
22  return($response->getXML());
23  }
24 
25  // Load an existing host record (and associated info) if $form is a host_id
26  if (is_numeric($form['block_id'])) {
27  list($status, $rows, $block) = ona_get_block_record(array('id' => $form['block_id']));
28  $block['ip_addr_start'] = ip_mangle($block['ip_addr_start'], 'dotted');
29  $block['ip_addr_end'] = ip_mangle($block['ip_addr_end'], 'dotted');
30  }
31 
32 
33  // Escape data for display in html
34  foreach(array_keys((array)$block) as $key) { $block[$key] = htmlentities($block[$key], ENT_QUOTES, $conf['php_charset']); }
35 
36 
37  // Set the window title:
38  $window['title'] = "Add Block";
39  if ($block['id'])
40  $window['title'] = "Edit Block";
41 
42  // Javascript to run after the window is built
43  $window['js'] = <<<EOL
44  /* Put a minimize icon in the title bar */
45  el('{$window_name}_title_r').innerHTML =
46  '&nbsp;<a onClick="toggle_window(\'{$window_name}\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
47  el('{$window_name}_title_r').innerHTML;
48 
49  /* Put a help icon in the title bar */
50  el('{$window_name}_title_r').innerHTML =
51  '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
52  el('{$window_name}_title_r').innerHTML;
53 
54  el('name').focus();
55 EOL;
56 
57  // Define the window's inner html
58  $window['html'] = <<<EOL
59 
60  <!-- Block Edit Form -->
61  <form id="{$window_name}_edit_form" onSubmit="return false;">
62  <input type="hidden" name="block_id" value="{$block['id']}">
63  <input type="hidden" name="js" value="{$form['js']}">
64  <table cellspacing="0" border="0" cellpadding="0" style="background-color: {$color['window_content_bg']}; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px;">
65 
66  <!-- BLOCK RECORD -->
67  <tr>
68  <td align="left" nowrap="true"><b><u>Block Record</u></b>&nbsp;</td>
69  <td class="padding" align="left" width="100%">&nbsp;</td>
70  </tr>
71 
72  <tr>
73  <td class="input_required" align="right" nowrap="true">
74  Block Name
75  </td>
76  <td class="padding" align="left" width="100%">
77  <input
78  id="name"
79  name="name"
80  alt="Block name"
81  value="{$block['name']}"
82  class="edit"
83  type="text"
84  size="27" maxlength="255"
85  >
86  </td>
87  </tr>
88 
89  <tr>
90  <td class="input_required" align="right" nowrap="true">
91  IP Block Start
92  </td>
93  <td class="padding" align="left" width="100%">
94  <input
95  name="start"
96  alt="IP block start"
97  value="{$block['ip_addr_start']}"
98  class="edit"
99  type="text"
100  size="20" maxlength="40"
101  >
102  </td>
103  </tr>
104 
105  <tr>
106  <td class="input_required" align="right" nowrap="true">
107  IP Block End
108  </td>
109  <td class="padding" align="left" width="100%">
110  <input
111  name="end"
112  alt="IP block end"
113  value="{$block['ip_addr_end']}"
114  class="edit"
115  type="text"
116  size="20" maxlength="40"
117  >
118  </td>
119  </tr>
120 
121  <tr>
122  <td align="right" nowrap="true">
123  Notes
124  </td>
125  <td class="padding" align="left" width="100%">
126  <input
127  name="notes"
128  alt="Notes"
129  value="{$block['notes']}"
130  class="edit"
131  type="text"
132  size="17" maxlength="255"
133  >
134  </td>
135  </tr>
136 
137 
138 
139  <tr>
140  <td align="right" valign="top" nowrap="true">
141  &nbsp;
142  </td>
143  <td class="padding" align="right" width="100%">
144  <input type="hidden" name="overwrite" value="{$overwrite}">
145  <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');">
146  <input class="edit" type="button"
147  name="submit"
148  value="Save"
149  accesskey=" "
150  onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_edit_form'), 'save');"
151  >
152  </td>
153  </tr>
154 
155  </table>
156  </form>
157 EOL;
158 
159 
160  return(window_open($window_name, $window));
161 }
162 
163 
164 
165 
167 // Function:
168 // Save Form
169 //
170 // Description:
171 // Creates/updates a block record.
173 function ws_save($window_name, $form='') {
174  global $base, $include, $conf, $self, $onadb;
175 
176  // Check permissions
177  if (! (auth('advanced')) ) {
178  $response = new xajaxResponse();
179  $response->addScript("alert('Permission denied!');");
180  return($response->getXML());
181  }
182 
183  // Instantiate the xajaxResponse object
184  $response = new xajaxResponse();
185  $js = '';
186 
187  // Validate input
188  if (!$form['name'] or !$form['start'] or !$form['end']) {
189  $response->addScript("alert('Please complete all fields to continue!');");
190  return($response->getXML());
191  }
192 
193  // Decide if we're editing or adding
194  $module = 'block_add';
195  if ($form['block_id']) {
196  $module = 'block_modify';
197  $form['set_name'] = $form['name'];
198  $form['set_start'] = $form['start'];
199  $form['set_end'] = $form['end'];
200  $form['set_notes'] = $form['notes'];
201  $form['block'] = $form['block_id'];
202  }
203 
204  // If there's no "refresh" javascript, add a command to view the new block
205  if (!preg_match('/\w/', $form['js']))
206  $form['js'] = "xajax_window_submit('search_results', 'search_form_id=>block_search_form,all_flag=>1');";
207 
208 
209  // Run the module
210  list($status, $output) = run_module($module, $form);
211 
212  // If the module returned an error code display a popup warning
213  if ($status)
214  $js .= "alert('Save failed. ". preg_replace('/[\s\']+/', ' ', $self['error']) . "');";
215  else {
216  $js .= "removeElement('{$window_name}');";
217  if ($form['js']) $js .= $form['js'];
218  }
219 
220  // Insert the new table into the window
221  $response->addScript($js);
222  return($response->getXML());
223 }
224 
225 
226 
227 
229 // Function:
230 // Delete Form
231 //
232 // Description:
233 // Deletes an block record. $form should be an array with an 'block_id'
234 // field.
236 function ws_delete($window_name, $form='') {
237  global $base, $include, $conf, $self, $onadb;
238 
239  // Check permissions
240  if (!auth('advanced')) {
241  $response = new xajaxResponse();
242  $response->addScript("alert('Permission denied!');");
243  return($response->getXML());
244  }
245 
246  // If an array in a string was provided, build the array and store it in $form
247  $form = parse_options_string($form);
248 
249  // Instantiate the xajaxResponse object
250  $response = new xajaxResponse();
251  $js = '';
252 
253  // Run the module
254  list($status, $output) = run_module('block_del', array('block' => $form['block_id'], 'commit' => 'Y'));
255 
256  // If the module returned an error code display a popup warning
257  if ($status) { $js .= "alert('Delete failed. " . preg_replace('/[\s\']+/', ' ', $self['error']) . "');"; }
258  else {
259  // If there's (refresh) js, send it to the browser
260  if ($form['js']) { $js .= $form['js']; }
261  }
262 
263  // Return an XML response
264  $response->addScript($js);
265  return($response->getXML());
266 }
267 
268 
269 
270 
271 ?>
ws_delete
ws_delete($window_name, $form='')
Definition: edit_block.inc.php:236
Name
Full Name
Definition: app_user_info.inc.php:101
ip_mangle
ip_mangle($ip="", $format="default")
Definition: functions_general.inc.php:308
ws_editor
ws_editor($window_name, $form='')
Definition: edit_block.inc.php:13
$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
$window
$window['title']
Definition: install.php:26
$include
$include
Definition: 2-to-3.php:10
window_open
window_open($window_name, $window=array())
Definition: webwin.inc.php:59
run_module
run_module($module='', $options='', $transaction=1)
Definition: functions_general.inc.php:1468
$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
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$style
$style['font-family']
Definition: config.inc.php:158
ws_save
ws_save($window_name, $form='')
Definition: edit_block.inc.php:173
nbsp
& nbsp
Definition: install.php:36
$font_family
global $font_family
Definition: app_admin_tools.inc.php:4
$output
$output
Definition: dcm.php:16
$self
global $self
Definition: 2-to-3.php:15
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
$base
$base
Definition: 2-to-3.php:8
$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