function ws_vlan($window_name, $form = '') { global $conf, $self, $onadb; global $color, $style, $images; $html = $js = ''; // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Set max_results and max_usage_bars if we need to if (!is_numeric($form['max_results'])) { $form['max_results'] = 250; } // // *** QF VLAN SEARCH *** // // Get the specified VLAN Campus record by name // If it isn't exact, don't accept it. list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $form['campus'])); if ($status or !$rows) { // Send a javascript popup error $response = new xajaxResponse(); $response->addScript("alert('ERROR => Invalid VLAN campus!');"); return $response->getXML(); } // Get a list of vlan's in the selected campus list($status, $count, $results) = db_get_records($onadb, 'vlans', array('vlan_campus_id' => $campus['id']), 'number', $form['max_results']); // If there were more than $form['max_results'] find out how many records there really are if ($count >= $form['max_results']) { list($status, $count, $tmp) = db_get_records($onadb, 'vlans', array('vlan_campus_id' => $campus['id']), '', 0); } // // *** BUILD RESULTS HTML *** // $html .= <<<EOL <table style="cursor: pointer;" width="100%" cellspacing="0" border="0" cellpadding="0"> <!-- The "None" option.. they need to be able to de-select a vlan --> <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';" onClick="el('{$form['input_id']}').value = ''; el('{$form['text_id']}').innerHTML = 'None'; removeElement('{$form['id']}');"> <td style="font-size: 10px; padding: 0px 2px;">None (i.e. no vlan)</td> </tr> EOL; if ($count > $form['max_results']) { $html .= <<<EOL <tr><td style="cursor: default; font-size: 12px; background-color: #FFCCCC; color: 000;" colspan="5" align="center">Displaying {$form['max_results']} of {$count} results</td></tr> EOL; } $campus['name'] = htmlentities($campus['name'], ENT_QUOTES, $conf['php_charset']); foreach ($results as $record) { // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } $html .= <<<EOL <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';" onClick="el('{$form['input_id']}').value = '{$record['id']}'; el('{$form['text_id']}').innerHTML = '{$campus['name']} / {$record['name']}'; removeElement('{$form['id']}');"> <td style="font-size: 10px; padding: 0px 2px;">{$campus['name']} / [{$record['number']}] {$record['name']}</td> </tr> EOL; } $html .= <<<EOL </table> EOL; $js .= <<<EOL el('{$form['content_id']}').style.display = 'block'; /* Reposition the popup if the new content is displayed off the screen */ wwTT_position('{$form['id']}'); EOL; // Insert the new html into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign($form['content_id'], "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function ona_find_vlan($vlan_search = "", $campus_search = "") { global $self; if (!$vlan_search and !$campus_search) { return array(1, 0, array()); } // If we got a vlan campus search string, let's look for that first. if ($campus_search) { $campus_search = strtoupper($campus_search); // Do a few sql queries and see if we can get a unique match $search = $campus_search; foreach (array('name', 'id') as $field) { list($status, $rows, $campus) = ona_get_vlan_campus_record(array($field => $search)); if (!$status and $rows == 1) { printmsg("DEBUG => ona_find_vlan() found vlan campus record by {$field}", 2); break; } else { $campus = array(); } } } // Search by a vlan number if (is_numeric($vlan_search)) { $where = array('number' => $vlan_search); } else { // Search for a vlan by NAME, use the campus[ID] if we have one $vlan_search = strtoupper($vlan_search); $where = array('name' => $vlan_search); } if ($campus['id']) { $where['vlan_campus_id'] = $campus['id']; } list($status, $rows, $vlan) = ona_get_vlan_record($where); if (!$status and $rows == 1) { return array($status, $rows, $vlan); } // We didn't find it - return and error code, 0 matches, and an empty record. $self['error'] = "NOTICE => couldn't find a unique vlan record with specified search criteria"; printmsg($self['error'], 1); return array(2, 0, array()); }
function vlan_campus_display($options = "") { global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.00'; printmsg("DEBUG => vlan_campus_display({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[verbose] (default is yes) $options['verbose'] = sanitize_YN($options['verbose'], 'Y'); // Return the usage summary if we need to if ($options['help'] or !$options['campus']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM vlan_campus_display-v{$version} Displays a vlan campus record from the database Synopsis: vlan_campus_display [KEY=VALUE] ... Required: campus=NAME or ID Campus name or ID of the campus display Optional: verbose=[yes|no] Display additional info (DEFAULT: yes) EOM ); } // The formatting rule on campus names is all upper and trim it $options['campus'] = strtoupper(trim($options['campus'])); // If the campus provided is numeric, check to see if it's valid if (is_numeric($options['campus'])) { // See if it's an vlan_campus_id list($status, $rows, $campus) = ona_get_vlan_campus_record(array('id' => $options['campus'])); if (!$campus['id']) { printmsg("DEBUG => Unable to find campus using the ID {$options['campus']}!", 3); $self['error'] = "ERROR => Unable to find campus using the ID {$options['campus']}!"; return array(2, $self['error'] . "\n"); } } else { list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $options['campus'])); if (!$campus['id']) { $self['error'] = "ERROR => Unable to find campus using the name {$options['campus']}!"; printmsg("DEBUG => Unable to find campus using the name {$options['campus']}!", 3); return array(2, $self['error'] . "\n"); } } printmsg("DEBUG => Found campus: {$campus['name']}", 3); // Build text to return $text = "VLAN CAMPUS RECORD\n"; $text .= format_array($campus); // If 'verbose' is enabled, grab some additional info to display if ($options['verbose'] == 'Y') { // vlan record(s) $i = 0; do { list($status, $rows, $vlan) = ona_get_vlan_record(array('vlan_campus_id' => $campus['id'])); if ($rows == 0) { break; } $i++; $text .= "\nASSOCIATED VLAN RECORD ({$i} of {$rows})\n"; $text .= format_array($vlan); } while ($i < $rows); } // Return the success notice return array(0, $text); }
function ws_editor($window_name, $form = '') { global $conf, $self, $onadb; global $font_family, $color, $style, $images; $window = array(); // Check permissions if (!auth('vlan_add')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Load an existing host record (and associated info) if $form is a vlan_campus_id if (is_numeric($form['vlan_campus_id'])) { list($status, $rows, $vlan_campus) = ona_get_vlan_campus_record(array('id' => $form['vlan_campus_id'])); } else { list($status, $rows, $vlan_campus) = ona_get_vlan_campus_record(array('name' => $form['vlan_campus_name'])); } // Escape data for display in html foreach (array_keys((array) $vlan_campus) as $key) { $vlan_campus[$key] = htmlentities($vlan_campus[$key], ENT_QUOTES, $conf['php_charset']); } // Set the window title: $window['title'] = "Add VLAN campus"; if ($vlan_campus['id']) { $window['title'] = "Edit VLAN campus"; } // Javascript to run after the window is built $window['js'] = <<<EOL /* Put a minimize icon in the title bar */ el('{$window_name}_title_r').innerHTML = ' <a onClick="toggle_window(\\'{$window_name}\\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' + el('{$window_name}_title_r').innerHTML; /* Put a help icon in the title bar */ el('{$window_name}_title_r').innerHTML = ' <a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' + el('{$window_name}_title_r').innerHTML; EOL; // Define the window's inner html $window['html'] = <<<EOL <!-- Vlan Campus Edit Form --> <form id="{$window_name}_edit_form" onSubmit="return false;"> <input type="hidden" name="vlan_campus_id" value="{$vlan_campus['id']}"> <input type="hidden" name="js" value="{$form['js']}"> <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;"> <!-- VLAN CAMPUS RECORD --> <tr> <td align="left" nowrap="true"><b><u>Vlan Campus Record</u></b> </td> <td class="padding" align="left" width="100%"> </td> </tr> <tr> <td class="input_required" align="right" nowrap="true"> Vlan Campus Name </td> <td class="padding" align="left" width="100%"> <input name="name" alt="Vlan Campus Name" value="{$vlan_campus['name']}" class="edit" type="text" size="17" maxlength="255" > </td> </tr> <tr> <td align="right" valign="top" nowrap="true"> </td> <td class="padding" align="right" width="100%"> <input type="hidden" name="overwrite" value="{$overwrite}"> <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');"> <input class="edit" type="button" name="submit" value="Save" accesskey=" " onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_edit_form'), 'save');" > </td> </tr> </table> </form> EOL; return window_open($window_name, $window); }
function ws_display($window_name, $form = '') { global $conf, $self, $onadb; global $images, $color, $style; $html = ''; $js = ''; $debug_val = 3; // used in the auth() calls to supress logging // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Load the campus record if (is_numeric($form['vlan_campus_id'])) { list($status, $rows, $record) = ona_get_vlan_campus_record(array('id' => $form['vlan_campus_id'])); } else { list($status, $rows, $record) = ona_get_vlan_campus_record(array('name' => $form['vlan_campus_name'])); } if ($status or !$rows) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>VLAN campus doesn't exist!</b></font></center>"; $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); return $response->getXML(); } // Update History Title (and tell the browser to re-draw the history div) $history = array_pop($_SESSION['ona']['work_space']['history']); $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');"; if ($history['title'] == $window_name) { $history['title'] = $record['name']; array_push($_SESSION['ona']['work_space']['history'], $history); } // Create some javascript to refresh the current page $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']); $refresh = "xajax_window_submit('work_space', '{$refresh}');"; $style['content_box'] = <<<EOL margin: 10px 20px; padding: 2px 4px; background-color: #FFFFFF; vertical-align: top; EOL; $style['label_box'] = <<<EOL font-weight: bold; padding: 2px 4px; border: solid 1px {$color['border']}; background-color: {$color['window_content_bg']}; EOL; // Escape data for display in html foreach (array_keys($record) as $key) { $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']); } $html .= <<<EOL <!-- FORMATTING TABLE --> <div style="{$style['content_box']}"> <table cellspacing="0" border="0" cellpadding="0"><tr> <!-- START OF FIRST COLUMN OF SMALL BOXES --> <td nowrap="true" valign="top" style="padding-right: 15px;"> EOL; // VLAN CAMPUS INFORMATION $html .= <<<EOL <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;"> <tr><td colspan="99" nowrap="true" style="{$style['label_box']}"> <!-- LABEL --> <form id="form_campus_{$record['id']}" ><input type="hidden" name="vlan_campus_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> EOL; if (auth('vlan_del', $debug_val)) { $html .= <<<EOL <a title="Edit Vlan Campus. ID: {$record['id']}" class="act" onClick="xajax_window_submit('edit_vlan_campus', xajax.getFormValues('form_campus_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_edit.png" border="0"></a> <a title="Delete Vlan Campus. ID: {$record['id']}" class="act" onClick="var doit=confirm('Are you sure you want to delete this vlan campus?'); if (doit == true) xajax_window_submit('edit_vlan_campus', xajax.getFormValues('form_campus_{$record['id']}'), 'delete');" ><img src="{$images}/silk/delete.png" border="0"></a> {$record['name']}</a> EOL; } else { $html .= " {$record['name']}"; } $html .= <<<EOL <a href="?work_space={$window_name}&vlan_campus_id={$record['id']}"><img title="Direct link to {$record['name']}" src="{$images}/silk/application_link.png" border="0"></a> </td></tr> <tr> <td align="right" nowrap="true"><b>Vlan Campus Name</b> </td> <td class="padding" align="left">{$record['name']} </td> </tr> </table> EOL; // END VLAN INFORMATION $html .= <<<EOL <!-- END OF FIRST COLUMN OF SMALL BOXES --> </td> <!-- START OF SECOND COLUMN OF SMALL BOXES --> <td valign="top" style="padding-right: 15px;"> EOL; $html .= <<<EOL <!-- END OF SECOND COLUMN OF SMALL BOXES --> </td> <!-- START OF THIRD COLUMN OF SMALL BOXES --> <td valign="top" style="padding-right: 15px;"> EOL; $html .= <<<EOL </td> <!-- END OF THIRD COLUMN OF SMALL BOXES --> </tr></table> </div> <!-- END OF TOP SECTION --> EOL; // VLAN LIST $tab = 'vlans'; $submit_window = "list_{$tab}"; $form_id = "{$submit_window}_filter_form"; $_SESSION['ona'][$form_id]['tab'] = $tab; $content_id = "{$window_name}_{$submit_window}"; $html .= <<<EOL <!-- VLAN LIST --> <div style="border: 1px solid {$color['border']}; margin: 10px 20px;"> <!-- Tab & Quick Filter --> <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0"> <tr> <td id="{$form_id}_{$tab}_tab" class="table-tab-active"> Associated {$tab} <span id="{$form_id}_{$tab}_count"></span> </td> <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%"> <form id="{$form_id}" onSubmit="return false;"> <input id="{$form_id}_page" name="page" value="1" type="hidden"> <input name="content_id" value="{$content_id}" type="hidden"> <input name="form_id" value="{$form_id}" type="hidden"> <input name="vlan_campus_id" value="{$record['id']}" type="hidden"> <div id="{$form_id}_filter_overlay" title="Filter" style="position: relative; display: inline; color: #CACACA; cursor: text;" onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();" >Vlan Name</div> <input id="{$form_id}_filter" name="filter" class="filter" type="text" value="" size="10" maxlength="20" alt="Quick Filter" onFocus="el('{$form_id}_filter_overlay').style.display = 'none';" onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';" onKeyUp=" if (typeof(timer) != 'undefined') clearTimeout(timer); code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' + ' {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' + ' document.getElementById(\\'{$form_id}_page\\').value = 1;' + ' xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' + '}'; timer = setTimeout(code, 700);" > </form> </td> </tr> </table> <div id='{$content_id}'> {$conf['loading_icon']} </div> EOL; if (auth('vlan_add', $debug_val)) { $html .= <<<EOL <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}"> <form id="form_vlan_campus_{$record['id']}" ><input type="hidden" name="vlan_campus_name" value="{$record['name']}" ><input type="hidden" name="vlan_campus_id" value="{$record['id']}" ><input type="hidden" name="js" value="{$refresh}" ></form> <!-- ADD VLAN LINK --> <a title="Add Vlan" class="act" onClick="xajax_window_submit('edit_vlan', xajax.getFormValues('form_vlan_campus_{$record['id']}'), 'editor');" ><img src="{$images}/silk/page_add.png" border="0"></a> <a title="Add Vlan" class="act" onClick="xajax_window_submit('edit_vlan', xajax.getFormValues('form_vlan_campus_{$record['id']}'), 'editor');" >Add Vlan</a> </div> EOL; } $html .= " </div>"; $js .= <<<EOL /* Setup the quick filter */ el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px'; {$form_id}_last_search = ''; /* Tell the browser to load/display the list */ xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list'); EOL; // Insert the new html into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); if ($js) { $response->addScript($js); } return $response->getXML(); }
function vlan_modify($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.01'; printmsg("DEBUG => vlan_modify({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !$options['vlan'] or !($options['set_name'] or $options['set_number'] or $options['set_campus'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM vlan_modify-v{$version} Modifies an vlan entry in the database Synopsis: vlan_modify [KEY=VALUE] ... Where: vlan=ID vlan ID Update: set_name=NAME change vlan name set_number=NUMBER change vlan number set_campus=NAME or ID change campus the vlan belongs to EOM ); } // The formatting rule on vlan names/campus names is all upper and trim it, spaces to - $options['set_name'] = strtoupper(trim($options['set_name'])); $options['set_name'] = preg_replace('/\\s+/', '-', $options['set_name']); $options['set_campus'] = strtoupper(trim($options['set_campus'])); $options['set_number'] = trim($options['set_number']); // Load the record we will be modifying list($status, $rows, $vlan) = ona_get_vlan_record(array('id' => $options['vlan'])); // Validate that we got a record back, or return an error if (!$vlan['id']) { printmsg("DEBUG => The VLAN ID specified ({$options['vlan']}) does not exist!", 3); $self['error'] = "ERROR => The VLAN ID specified, {$options['vlan']}, does not exist!"; return array(2, $self['error'] . "\n"); } printmsg("DEBUG => Found VLAN: {$vlan['name']}", 3); // This variable will contain the updated info we'll insert into the DB $SET = array(); // If they are specifying a new name, process it. if ($options['set_name']) { // Validate that there isn't already an vlan with this name $options['set_name'] = strtoupper(trim($options['set_name'])); list($status, $rows, $record) = db_get_records($onadb, 'vlans', "vlan_campus_id = {$vlan['vlan_campus_id']} AND name LIKE '{$options['set_name']}' AND number != {$vlan['number']}"); if ($status or $rows) { printmsg("DEBUG => The VLAN ({$options['set_name']}) already exists on this campus!", 3); $self['error'] = "ERROR => The VLAN {$options['set_name']} already exists on this campus!"; return array(4, $self['error'] . "\n"); } if ($vlan['name'] != $options['set_name']) { $SET['name'] = $options['set_name']; } } if ($options['set_number']) { // Validate that there isn't already an vlan on this campus with this vlan number list($status, $rows, $record) = db_get_records($onadb, 'vlans', "vlan_campus_id = {$vlan['vlan_campus_id']} AND number = {$options['set_number']} AND name NOT LIKE '{$vlan['name']}'"); if ($status or $rows) { printmsg("DEBUG => The VLAN with the number ({$options['set_number']}) already exists on this campus!", 3); $self['error'] = "ERROR => The vlan with the number {$options['set_number']} already exists on this campus!"; return array(3, $self['error'] . "\n"); } // Add the new info to $SET if ($vlan['number'] != $options['set_number']) { $SET['number'] = $options['set_number']; } } // FIXME: yes I'm lazy.. test that the new campus does not have the vlan name or number already on it. // If they are changing the campus the vlan points to, process it if ($options['set_campus']) { $options['set_campus'] = strtoupper(trim($options['set_campus'])); if (is_numeric($options['set_campus'])) { list($status, $rows, $record) = ona_get_vlan_campus_record(array('id' => $options['set_campus'])); } if (!array_key_exists('id', $record)) { list($status, $rows, $record) = ona_get_vlan_campus_record(array('name' => $options['set_campus'])); } // Make sure that worked - or return an error if (!$record['id']) { printmsg("DEBUG => The campus ({$options['set_campus']}) does not exist!", 3); $self['error'] = "ERROR => The campus specified, {$options['set_campus']}, does not exist!"; return array(5, $self['error'] . "\n"); } // test that the new campus does not have the vlan name or number already on it. // only check if the campus has changed if ($record['id'] != $vlan['vlan_campus_id']) { // build where clause for checking the new campus for the vlan name/number $where = ''; $OR = ''; if (array_key_exists('number', $SET)) { $where .= " number = {$SET['number']} "; $OR = " OR "; } if (array_key_exists('name', $SET)) { $where .= "{$OR} name LIKE '{$SET['name']}' "; } list($status, $rows, $new_campus_record) = db_get_records($onadb, 'vlans', "vlan_campus_id = {$record['id']} AND ({$where})"); if ($rows > 0) { printmsg("DEBUG => The campus ({$options['set_campus']}) already contains this VLAN name or number ({$SET['name']} {$SET['number']})!", 3); $self['error'] = "ERROR => The campus specified, {$options['set_campus']}, already contains this VLAN name or number ({$SET['name']} {$SET['number']})!"; return array(7, $self['error'] . "\n"); } } // Add the new info to $SET if ($vlan['vlan_campus_id'] != $record['id']) { $SET['vlan_campus_id'] = $record['id']; } } // Check permissions if (!auth('vlan_modify')) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } if ($SET) { // Update the record list($status, $rows) = db_update_record($onadb, 'vlans', array('id' => $vlan['id']), $SET); if ($status or !$rows) { $self['error'] = "ERROR => vlan_modify() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(6, $self['error'] . "\n"); } } // Get the VLAN record after updating (logging) list($status, $rows, $new_vlan) = ona_get_vlan_record(array('id' => $options['vlan'])); list($status, $rows, $campus) = ona_get_vlan_campus_record(array('id' => $new_vlan['vlan_campus_id'])); $text = <<<EOL NAME: {$new_vlan['name']} NUMBER: {$new_vlan['number']} CAMPUS: {$campus['name']} EOL; // Return the success notice $renamed = ''; if ($new_vlan['name'] != $vlan['name']) { $renamed .= "{$vlan['name']} => {$new_vlan['name']} "; } if ($new_vlan['number'] != $vlan['number']) { $renamed .= "VLAN Num {$vlan['number']} => {$new_vlan['number']} "; } if ($new_vlan['vlan_campus_id'] != $vlan['vlan_campus_id']) { $renamed .= "Campus ID {$vlan['vlan_campus_id']} => {$new_vlan['vlan_campus_id']}"; } $self['error'] = "INFO => VLAN UPDATED: {$renamed}"; return array(0, $self['error'] . "\n {$text}"); }
function ws_save($window_name, $form = '') { global $base, $include, $conf, $self, $onadb; // Check permissions if (!auth('advanced')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Instantiate the xajaxResponse object $response = new xajaxResponse(); $js = ''; // Validate input if (!$form['campus'] or !$form['name'] or !$form['number']) { $response->addScript("alert('Please complete all fields to continue!');"); return $response->getXML(); } // Validate zone is valid list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $form['campus'])); if ($status or !$rows) { $response->addScript("alert('Invalid VLAN campus!');"); return $response->getXML(); } // Decide if we're editing or adding $module = 'vlan_add'; if ($form['vlan_id']) { $module = 'vlan_modify'; $form['set_name'] = $form['name']; $form['set_campus'] = $form['campus']; $form['set_number'] = $form['number']; $form['vlan'] = $form['vlan_id']; } // If there's no "refresh" javascript, add a command to view the new host if (!preg_match('/\\w/', $form['js'])) { $form['js'] = "xajax_window_submit('work_space', 'xajax_window_submit(\\'display_vlan_campus\\', \\'vlan_campus_id=>{$campus['id']}\\', \\'display\\')');"; } // Run the module list($status, $output) = run_module($module, $form); // If the module returned an error code display a popup warning if ($status) { $js .= "alert('Save failed. " . preg_replace('/[\\s\']+/', ' ', $self['error']) . "');"; } else { // if they have checked the keep adding box then dont remove the window if (!$form['keepadding']) { $js .= "removeElement('{$window_name}');"; } else { $js .= "el('statusinfo_{$window_name}').innerHTML = 'Previously added:<br>\\'{$form['name']}\\' to campus: {$form['campus']}';"; } if ($form['js']) { $js .= $form['js']; } } // Insert the new table into the window $response->addScript($js); return $response->getXML(); }