Example #1
0
function ona_find_dhcp_option($search = "")
{
    global $self;
    // Validate input
    if ($search == "") {
        return array(1, 0, array());
    }
    // If it's numeric, search by record ID
    if (is_numeric($search)) {
        $field = 'id';
        list($status, $rows, $record) = ona_get_dhcp_option_record(array($field => $search));
        // If we got it, return it
        if ($status == 0 and $rows == 1) {
            printmsg("DEBUG => ona_find_dhcp_option(): found type record by {$field}", 2);
            return array(0, $rows, $record);
        }
    }
    foreach (array('name', 'display_name', 'number', 'tag') as $field) {
        // Do several sql queries and see if we can get a unique match
        list($status, $rows, $record) = ona_get_dhcp_option_record(array($field => $search));
        // If we got it, return it
        if ($status == 0 and $rows == 1) {
            printmsg("DEBUG => ona_find_dhcp_option(): Found type record -> {$record['display_name']}", 2);
            return array(0, $rows, $record);
        }
    }
    // We didn't find it - return and error code, 0 matches, and an empty record.
    $self['error'] = "NOTICE => couldn't find a unique DHCP option record with specified search criteria";
    printmsg($self['error'], 2);
    return array(2, 0, array());
}
Example #2
0
function ws_save($window_name, $form = '')
{
    global $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 = '';
    // If you get a numeric in $form, update the record
    if (is_numeric($form['id'])) {
        // Get the option record before updating (logging)
        list($status, $rows, $original_option) = ona_get_dhcp_option_record(array('id' => $form['id']));
        list($status, $rows) = db_update_record($onadb, 'dhcp_options', array('id' => $form['id']), array('display_name' => $form['display_name'], 'type' => $form['type'], 'number' => $form['number'], 'name' => $form['name']));
        if ($status or !$rows) {
            $self['error'] = "ERROR => dhcp_option update ws_save()  SQL Query failed: " . $self['error'];
            printmsg($self['error'], 0);
        } else {
            // Get the record after updating (logging)
            list($status, $rows, $new_option) = ona_get_dhcp_option_record(array('id' => $form['id']));
            // Return the success notice
            $self['error'] = "INFO => DHCP Option UPDATED:{$new_option['id']}: {$new_option['name']}";
            $log_msg = "INFO => DHCP Option UPDATED:{$new_option['id']}: ";
            $more = "";
            foreach (array_keys($original_option) as $key) {
                if ($original_option[$key] != $new_option[$key]) {
                    $log_msg .= $more . $key . "[" . $original_option[$key] . "=>" . $new_option[$key] . "]";
                    $more = ";";
                }
            }
            // only print to logfile if a change has been made to the record
            if ($more != '') {
                printmsg($self['error'], 0);
                printmsg($log_msg, 0);
            }
        }
    } else {
        $id = ona_get_next_id('dhcp_options');
        if (!$id) {
            $self['error'] = "ERROR => The ona_get_next_id() call failed!";
            printmsg($self['error'], 0);
        } else {
            printmsg("DEBUG => ID for new dhcp option: {$id}", 3);
            list($status, $rows) = db_insert_record($onadb, "dhcp_options", array('id' => $id, 'display_name' => $form['display_name'], 'type' => $form['type'], 'number' => $form['number'], 'name' => $form['name']));
            if ($status or !$rows) {
                $self['error'] = "ERROR => dhcp_option_edit add ws_save()  SQL Query failed: " . $self['error'];
                printmsg($self['error'], 0);
            } else {
                $self['error'] = "INFO => DHCP Option ADDED: {$form['name']} ";
                printmsg($self['error'], 0);
            }
        }
    }
    // If the module returned an error code display a popup warning
    if ($status) {
        $js .= "alert('Save failed. " . trim($self['error']) . " (Hint: All fields are required!)');";
    } else {
        $js .= "removeElement('{$window_name}');";
        $js .= "xajax_window_submit('app_dhcp_option_list', xajax.getFormValues('app_dhcp_option_list_filter_form'), 'display_list');";
    }
    // Return some javascript to the browser
    $response->addScript($js);
    return $response->getXML();
}