当前位置: 首页>>代码示例>>PHP>>正文


PHP db_get_record函数代码示例

本文整理汇总了PHP中db_get_record函数的典型用法代码示例。如果您正苦于以下问题:PHP db_get_record函数的具体用法?PHP db_get_record怎么用?PHP db_get_record使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了db_get_record函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: add_permission

function add_permission($options = "")
{
    global $conf, $self, $onadb;
    printmsg('DEBUG => add_permission(' . $options . ') called', 3);
    // Version - UPDATE on every edit!
    $version = '1.00';
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Return the usage summary if we need to
    if ($options['help'] or !$options['name']) {
        $self['error'] = 'ERROR => Insufficient parameters';
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        return array(1, <<<EOM

add_permission-v{$version}
Registers a new permission, this should be used by install scripts that are
creating new functionality that requires a registered permission.

  Synopsis: add_permission(OPTIONS)

  Options:
    name=STRING         Name of permission
    desc=STRING         Quoted string to describe this permission


EOM
);
    }
    // Get a list of the valid "permissions" and their descriptions.
    list($status, $rows, $permissions) = db_get_record($onadb, 'permissions', array('name' => $options['name']), '');
    if ($rows) {
        $self['error'] = "ERROR => add_permission() Permission already exists: {$options['name']}";
        printmsg($self['error'], 0);
        return array(1, $self['error'] . "\n");
    }
    // Get the next ID for the new host record
    $id = ona_get_next_id('permissions');
    if (!$id) {
        $self['error'] = "ERROR => The ona_get_next_id('permissions') call failed!";
        printmsg($self['error'], 0);
        return array(7, $self['error'] . "\n");
    }
    printmsg("DEBUG => ID for new permission record: {$id}", 3);
    // Add the record
    list($status, $rows) = db_insert_record($onadb, 'permissions', array('id' => $id, 'name' => $options['name'], 'description' => $options['desc']));
    if ($status or !$rows) {
        $self['error'] = "ERROR => add_permission() SQL Query failed: " . $self['error'];
        printmsg($self['error'], 0);
        return array(2, $self['error'] . "\n");
    }
    // Return the success notice
    $self['error'] = "INFO => Permission ADDED: {$options['name']} [{$options['desc']}]";
    printmsg($self['error'], 0);
    return array(0, $self['error'] . "\n");
}
开发者ID:edt82,项目名称:ona,代码行数:55,代码来源:permissions.inc.php

示例2: sess_read

function sess_read($key)
{
    global $SESS_DBH, $SESS_LIFE;
    printmsg("sess_read({$key}) called", 6);
    list($status, $rows, $record) = db_get_record($SESS_DBH, 'sessions', "`sesskey` = '{$key}' AND `expiry` > " . time());
    if ($status or $rows == 0) {
        return false;
    }
    if (array_key_exists('sessvalue', $record)) {
        // Update the expiry time (i.e. keep sessions alive even if nothing in the session has changed)
        $expiry = time() + $SESS_LIFE;
        list($status, $rows) = db_update_record($SESS_DBH, 'sessions', "`sesskey` = '{$key}' AND `expiry` > " . time(), array('expiry' => $expiry));
        if ($status) {
            return false;
        }
        // Return the value
        return $record['sessvalue'];
    }
    return false;
}
开发者ID:edt82,项目名称:ona,代码行数:20,代码来源:adodb_sessions.inc.php

示例3: ws_process_alerts_submit

function ws_process_alerts_submit($window_name, $form = '')
{
    global $conf, $self, $onadb, $tip_style;
    global $font_family, $color, $style, $images;
    $html = $js = '';
    // If an array in a string was provided, build the array and store it in $form
    $form = parse_options_string($form);
    printmsg("DEBUG => Processing Alerts:", 5);
    // FIXME: this code is called from html_desktop.inc.php.. however it is failing to process for some reason
    // The intent of this code is to be called to display a "message waiting" type icon in the top menu bar.
    // Check for messages that begin with SYS_ in the table_name_ref column
    list($status, $rows, $msg) = db_get_record($onadb, 'messages', "table_name_ref LIKE 'SYS_%'");
    if ($rows) {
        $js .= "if (el('sys_alert')) {el('sys_alert').style.visibility = 'visible';}";
    } else {
        $js .= "if (el('sys_alert')) {el('sys_alert').style.visibility = 'hidden';}";
    }
    $response = new xajaxResponse();
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
开发者ID:edt82,项目名称:ona,代码行数:23,代码来源:process_alerts.inc.php

示例4: tag_del

function tag_del($options = "")
{
    // The important globals
    global $conf, $self, $onadb;
    // Version - UPDATE on every edit!
    $version = '1.00';
    printmsg("DEBUG => tag_del({$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['tag']) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        $self['error'] = 'ERROR => Insufficient parameters';
        return array(1, <<<EOM

tag_del-v{$version}
Deletes an tag from the database

  Synopsis: tag_del [KEY=VALUE] ...

  Required:
    tag=ID             ID of the tag to delete

  Optional:
    commit=[yes|no]     commit db transaction (no)



EOM
);
    }
    // Sanitize options[commit] (default is no)
    $options['commit'] = sanitize_YN($options['commit'], 'N');
    // If the tag provided is numeric, check to see if it's an tag
    if (is_numeric($options['tag'])) {
        // See if it's a tag_id
        list($status, $rows, $tag) = db_get_record($onadb, 'tags', array('id' => $options['tag']));
    }
    if (!$tag['id']) {
        printmsg("DEBUG => Unable to find tag ({$options['tag']})!", 3);
        $self['error'] = "ERROR => Unable to find tag ({$options['tag']})!";
        return array(2, $self['error'] . "\n");
    }
    // If "commit" is yes, delete the record
    if ($options['commit'] == 'Y') {
        // Check permissions
        if (!(auth('host_del') or auth('subnet_del'))) {
            $self['error'] = "Permission denied!";
            printmsg($self['error'], 0);
            return array(10, $self['error'] . "\n");
        }
        list($status, $rows) = db_delete_records($onadb, 'tags', array('id' => $tag['id']));
        if ($status or !$rows) {
            $self['error'] = "ERROR => tag_del() SQL Query failed: " . $self['error'];
            printmsg($self['error'], 0);
            return array(4, $self['error'] . "\n");
        }
        // Return the success notice
        $self['error'] = "INFO => TAG DELETED: {$tag['name']} from {$tag['type']}[{$tag['reference']}]";
        printmsg($self['error'], 0);
        return array(0, $self['error'] . "\n");
    }
    // Otherwise display the record that would have been deleted
    $text = <<<EOL
Record(s) NOT DELETED (see "commit" option)
Displaying record(s) that would have been deleted:

    NAME:      {$tag['name']}
    TYPE:      {$tag['type']}
    REFERENCE: {$tag['reference']}


EOL;
    return array(6, $text);
}
开发者ID:edt82,项目名称:ona,代码行数:75,代码来源:tag.inc.php

示例5: ws_editor

function ws_editor($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $font_family, $color, $style, $images;
    // Check permissions
    if (!auth('advanced')) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // Set a few parameters for the "results" window we're about to create
    $window = array('title' => 'DHCP Option Editor', 'html' => '', 'js' => '');
    $window['js'] .= <<<EOL
        /* Put a minimize icon in the title bar */
        el('{$window_name}_title_r').innerHTML =
            '&nbsp;<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 =
            '&nbsp;<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;
    // If we got an option, load it for display
    $overwrite = 'no';
    if (is_numeric($form)) {
        list($status, $rows, $record) = db_get_record($onadb, 'dhcp_options', array('id' => $form));
        if (!$status and $rows) {
            $overwrite = 'yes';
        }
    }
    // Internal tag type array, there is no table for this
    $type = array("L" => "IP Address List", "S" => "String", "N" => "Numeric", "I" => "IP Address", "B" => "Boolean");
    // Build tag type list
    while ($tag = current($type)) {
        $selected = "";
        // If this entry matches the record you are editing, set it to selected
        if (key($type) == $record['type']) {
            $selected = "SELECTED=\"selected\"";
        }
        if (key($type)) {
            $type_list .= "<option {$selected} value=\"" . key($type) . "\">{$tag}</option>\n";
        }
        next($type);
    }
    // Escape data for display in html
    foreach (array_keys((array) $record) as $key) {
        $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
    }
    // Load some html into $window['html']
    $window['html'] .= <<<EOL

    <!-- Simple Edit Form -->
    <form id="dhcp_option_edit_form" onSubmit="return false;">
    <input name="id" type="hidden" value="{$record['id']}">
    <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;">
        <tr>
            <td align="right" nowrap="true">
                Display Name
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="display_name"
                    alt="Description"
                    value="{$record['display_name']}"
                    class="edit"
                    type="text"
                    size="30" maxlength="30"
                >
            </td>
        </tr>

        <tr>
            <td align="right">
                Option Name
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="name"
                    alt="Name"
                    value="{$record['name']}"
                    class="edit"
                    type="text"
                    size="30" maxlength="30"
                >
            </td>
        </tr>

        <tr>
            <td align="right">
                Number
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="number"
                    alt="DHCP Number"
                    value="{$record['number']}"
                    class="edit"
                    type="text"
                    size="5" maxlength="10"
//.........这里部分代码省略.........
开发者ID:edt82,项目名称:ona,代码行数:101,代码来源:app_dhcp_option_edit.inc.php

示例6: ws_editor

function ws_editor($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $font_family, $color, $style, $images;
    // Check permissions
    if (!auth('advanced')) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // Set a few parameters for the "results" window we're about to create
    $window = array('title' => 'DNS View Editor', 'html' => '', 'js' => '');
    $window['js'] .= <<<EOL
        /* Put a minimize icon in the title bar */
        el('{$window_name}_title_r').innerHTML =
            '&nbsp;<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 =
            '&nbsp;<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;
    // If an array in a string was provided, build the array and store it in $form
    $form = parse_options_string($form);
    // If we got a view, load it for display
    if (is_numeric($form['id'])) {
        list($status, $rows, $record) = db_get_record($onadb, 'dns_views', array('id' => $form['id']));
    }
    // Escape data for display in html
    foreach (array_keys((array) $record) as $key) {
        $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
    }
    // Load some html into $window['html']
    $window['html'] .= <<<EOL

    <!-- Simple class types Edit Form -->
    <form id="dns_view_edit_form" onSubmit="return false;">
    <input name="id" type="hidden" value="{$record['id']}">
    <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;">
        <tr>
            <td class="input_required" align="right">
                Name
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="dns_view_name"
                    alt="DNS View Name"
                    value="{$record['name']}"
                    class="edit"
                    type="text"
                    size="30" maxlength="64"
                >
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right">
                Description
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="dns_view_description"
                    alt="DNS View Description"
                    value="{$record['description']}"
                    class="edit"
                    type="text"
                    size="30" maxlength="64"
                >
            </td>
        </tr>

        <tr>
            <td align="right" valign="top">
                &nbsp;
            </td>
            <td class="padding" align="right" width="100%">
                <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('dns_view_edit_form'), 'save');"
                >
            </td>
        </tr>

    </table>
    </form>

EOL;
    // Lets build a window and display the results
    return window_open($window_name, $window);
}
开发者ID:edt82,项目名称:ona,代码行数:94,代码来源:app_dns_view_edit.inc.php

示例7: ws_save

function ws_save($window_name, $form = '')
{
    global $conf, $self, $mysql;
    // Make sure they have permission
    if (!auth('admin')) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // Don't allow this in the demo account!
    if ($_SESSION['auth']['client']['url'] == 'demo') {
        $response = new xajaxResponse();
        $response->addScript("alert('Feature disabled in this demo!');");
        return $response->getXML();
    }
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $js = '';
    // Make sure they're logged in
    if (!loggedIn()) {
        return $response->getXML();
    }
    // Validate input
    if (!$form['fname'] or !$form['lname'] or !$form['username']) {
        $js .= "alert('Error! First name, last name, and username are required fields!');";
        $response->addScript($js);
        return $response->getXML();
    }
    if (!$form['id'] and !$form['passwd']) {
        $js .= "alert('Error! A password is required to create a new employee!');";
        $response->addScript($js);
        return $response->getXML();
    }
    // Usernames are stored in lower case
    $form['username'] = strtolower($form['username']);
    // md5sum the password if there is one
    if ($form['passwd']) {
        $form['passwd'] = md5($form['passwd']);
    }
    // Create a new record?
    if (!$form['id']) {
        list($status, $rows) = db_insert_record($mysql, 'users', array('client_id' => $_SESSION['auth']['client']['id'], 'active' => 1, 'fname' => $form['fname'], 'lname' => $form['lname'], 'username' => $form['username'], 'passwd' => $form['passwd'], 'ctime' => date_mangle(time()), 'mtime' => date_mangle(time())));
        printmsg("NOTICE => Added new user: {$form['username']} client url: {$_SESSION['auth']['client']['url']}", 0);
    } else {
        list($status, $rows, $record) = db_get_record($mysql, 'users', array('id' => $form['id'], 'client_id' => $_SESSION['auth']['client']['id']));
        if ($rows != 1 or $record['id'] != $form['id']) {
            $js .= "alert('Error! The record requested could not be loaded from the database!');";
            $response->addScript($js);
            return $response->getXML();
        }
        if (strlen($form['passwd']) < 32) {
            $form['passwd'] = $record['passwd'];
        }
        list($status, $rows) = db_update_record($mysql, 'users', array('id' => $form['id']), array('fname' => $form['fname'], 'lname' => $form['lname'], 'username' => $form['username'], 'passwd' => $form['passwd'], 'mtime' => date_mangle(time()), 'active' => 1));
        printmsg("NOTICE => Updated user: {$form['username']} client url: {$_SESSION['auth']['client']['url']}", 0);
    }
    // If the module returned an error code display a popup warning
    if ($status) {
        printmsg("ERROR => User add/edit failed! {$self['error']}", 0);
        $js .= "alert('Save failed. Contact the webmaster if this problem persists.');";
        $response->addScript($js);
        return $response->getXML();
    }
    $js .= "removeElement('{$window_name}');";
    $js .= "xajax_window_submit('user_list', xajax.getFormValues('user_list_filter_form'), 'display_list');";
    // Handle the "admin" flag
    list($status, $rows, $user) = db_get_record($mysql, 'users', array('username' => $form['username'], 'client_id' => $_SESSION['auth']['client']['id'], 'active' => 1));
    list($status, $rows, $perm) = db_get_record($mysql, 'permissions', array('name' => 'admin'));
    list($status, $rows, $acl) = db_get_record($mysql, 'acl', array('user_id' => $user['id'], 'perm_id' => $perm['id']));
    if ($form['admin'] and !$acl['id'] and $user['id'] and $perm['id']) {
        // Give the user the permission
        list($status, $rows) = db_insert_record($mysql, 'acl', array('user_id' => $user['id'], 'perm_id' => $perm['id']));
    } else {
        if (!$form['admin'] and $acl['id'] and $user['id'] and $perm['id'] and $_SESSION['auth']['user']['id'] != $user['id']) {
            // Take the permission away, UNLESS THEY ARE TRYING TO MODIFY THEIR OWN ACCOUNT!
            list($status, $rows) = db_delete_record($mysql, 'acl', array('user_id' => $user['id'], 'perm_id' => $perm['id']));
        } else {
            if ($_SESSION['auth']['user']['id'] == $user['id']) {
                // IF they did try to remove their own admin status, give them a popup and tell them they can't do that.
                $js .= "alert('WARNING => You can\\'t change your own admin status!');";
            }
        }
    }
    // Insert the new table into the window
    $response->addScript($js);
    return $response->getXML();
}
开发者ID:edt82,项目名称:ona,代码行数:87,代码来源:user_edit.inc.php

示例8: ws_delete

function ws_delete($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 = '';
    // Load the record to make sure it exists
    list($status, $rows, $role) = db_get_record($onadb, 'roles', array('id' => $form));
    if ($status or !$rows) {
        $response->addScript("alert('Delete failed: Role id {$form} does not exist');");
        return $response->getXML();
    }
    // Get a list of device models that use this role
    list($status, $rows, $devicemodels) = db_get_records($onadb, 'models', array('role_id' => $form), '', 0);
    // Check that there are no parent records using this type
    if ($rows > 0) {
        $js .= "alert('Delete failed: There are {$rows} device models using this role.');";
    } else {
        // Delete the record
        list($status, $rows) = db_delete_records($onadb, 'roles', array('id' => $role['id']));
        if ($status or !$rows) {
            // If the module returned an error code display a popup warning
            $js .= "alert('Delete failed: " . trim($self['error']) . "');";
            $self['error'] = "ERROR => role_list ws_delete() SQL Query failed: " . $self['error'];
            printmsg($self['error'], 0);
        } else {
            $self['error'] = "INFO => Role DELETED: {$role['name']} ";
            printmsg($self['error'], 0);
        }
    }
    // Refresh the current list.. it's changed!
    $js .= "xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_filter_form'), 'display_list');";
    // Send an XML response
    $response->addScript($js);
    return $response->getXML();
}
开发者ID:edt82,项目名称:ona,代码行数:42,代码来源:app_device_role_list.inc.php

示例9: ws_save

function ws_save($window_name, $form = '')
{
    global $conf, $self, $onadb;
    // Check permissions
    if (!auth('user_admin')) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $js = '';
    $exit_status = 0;
    // Validate input
    if (!$form['username']) {
        $js .= "alert('Error! All fields are required!');";
        $response->addScript($js);
        return $response->getXML();
    }
    if (!preg_match('/^[A-Za-z0-9.\\-_]+$/', $form['username'])) {
        $js .= "alert('Invalid username! Valid characters: A-Z 0-9 .-_');";
        $response->addScript($js);
        return $response->getXML();
    }
    // Create a new record?
    if (!$form['user_id']) {
        list($status, $rows) = db_insert_record($onadb, 'users', array('username' => $form['username'], 'password' => $form['password']));
        if ($status or !$rows) {
            $self['error'] = "ERROR => user_edit_add ws_save()  SQL Query failed: " . $self['error'];
            printmsg($self['error'], 0);
        } else {
            $self['error'] = "INFO => User ADDED: {$form['username']} ";
            printmsg($self['error'], 0);
        }
    } else {
        list($status, $rows, $user) = db_get_record($onadb, 'users', array('id' => $form['user_id']));
        if ($rows != 1 or $user['id'] != $form['user_id']) {
            $js .= "alert('Error! The record requested could not be loaded from the database!');";
            $response->addScript($js);
            return $response->getXML();
        }
        list($status, $rows) = db_update_record($onadb, 'users', array('id' => $user['id']), array('username' => $form['username'], 'password' => $form['password']));
        if ($status) {
            $self['error'] = "ERROR => user_edit update ws_save()  SQL Query failed: " . $self['error'];
            printmsg($self['error'], 0);
        } else {
            list($status, $rows, $new_record) = db_get_record($onadb, 'users', array('id' => $user['id']));
            // Return the success notice
            $self['error'] = "INFO => User UPDATED:{$user['id']}: {$new_record['username']}";
            $log_msg = "INFO => User UPDATED:{$user['id']}: ";
            $more = "";
            foreach (array_keys($user) as $key) {
                if ($user[$key] != $new_record[$key]) {
                    $log_msg .= $more . $key . "[" . $user[$key] . "=>" . $new_record[$key] . "]";
                    $more = ";";
                }
            }
        }
    }
    // Make sure we can load the user record from the db
    list($status, $rows, $user) = db_get_record($onadb, 'users', array('username' => $form['username']));
    if ($status or $rows != 1) {
        $js .= "alert('Save failed: " . trim($self['error']) . "');";
        // Return some javascript to the browser
        $response->addScript($js);
        return $response->getXML();
    }
    // This is a bit tricky because we want to make sure the user has all the groups
    // that are checked in the form, but no others.  And of course we want to make as
    // few sql queries as possible.  It's tricky because the form only submits us the
    // groups that are checked.
    // Get a list of every group
    list($status, $rows, $groups) = db_get_records($onadb, 'groups', 'id > 0');
    // Loop through each group
    foreach ($groups as $group) {
        // See if the user is assigned to this group or not
        list($status, $rows, $tmp) = db_get_record($onadb, 'group_assignments', array('user_id' => $user['id'], 'group_id' => $group['id']));
        $exit_status += $status;
        // If the user is supposed to be assigned to this group, make sure she is.
        if (array_key_exists($group['name'], $form['groups'])) {
            if ($status == 0 and $rows == 0) {
                list($status, $rows) = db_insert_record($onadb, 'group_assignments', array('user_id' => $user['id'], 'group_id' => $group['id']));
                $log_msg .= $more . "group_add[" . $group['name'] . "]";
                $more = ";";
                $exit_status += $status;
            }
        } else {
            if ($status == 0 and $rows == 1) {
                list($status, $rows) = db_delete_records($onadb, 'group_assignments', array('user_id' => $user['id'], 'group_id' => $group['id']));
                $log_msg .= $more . "group_del[" . $group['name'] . "]";
                $more = ";";
                $exit_status += $status;
            }
        }
    }
    // If the module returned an error code display a popup warning
    if ($status) {
        $js .= "alert('Save failed: " . trim($self['error']) . "');";
    } else {
        // only print to logfile if a change has been made to the record
//.........这里部分代码省略.........
开发者ID:edt82,项目名称:ona,代码行数:101,代码来源:app_user_edit.inc.php

示例10: ws_save

function ws_save($window_name, $form = '')
{
    global $conf, $self, $onadb;
    // Check permissions
    if (!auth('user_admin')) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $js = '';
    // Validate input
    if (!$form['name']) {
        $js .= "alert('Error! All fields are required!');";
        $response->addScript($js);
        return $response->getXML();
    }
    if (!preg_match('/^[A-Za-z0-9.\\-_ ]+$/', $form['name'])) {
        $js .= "alert('Invalid group name! Valid characters: A-Z 0-9 .-_ and space');";
        $response->addScript($js);
        return $response->getXML();
    }
    //MP: zero out the level for now
    //TODO: fix or remove level at some point
    $form['level'] = 0;
    // Create a new record?
    if (!$form['id']) {
        list($status, $rows) = db_insert_record($onadb, 'groups', array('name' => $form['name'], 'description' => $form['description'], 'level' => $form['level']));
        if ($status or !$rows) {
            $self['error'] = "ERROR => group_edit add ws_save()  SQL Query failed: " . $self['error'];
            printmsg($self['error'], 0);
        } else {
            $self['error'] = "INFO => Group ADDED: {$form['name']} ";
            printmsg($self['error'], 0);
        }
    } else {
        list($status, $rows, $record) = db_get_record($onadb, 'groups', array('id' => $form['id']));
        if ($rows != 1 or $record['id'] != $form['id']) {
            $js .= "alert('Error! The record requested could not be loaded from the database!');";
            $response->addScript($js);
            return $response->getXML();
        }
        list($status, $rows) = db_update_record($onadb, 'groups', array('id' => $form['id']), array('name' => $form['name'], 'description' => $form['description']));
        if ($status or !$rows) {
            $self['error'] = "ERROR => group_edit update ws_save()  SQL Query failed: " . $self['error'];
            printmsg($self['error'], 0);
        } else {
            list($status, $rows, $new_record) = db_get_record($onadb, 'groups', array('id' => $form['id']));
            // Return the success notice
            $self['error'] = "INFO => Group UPDATED:{$record['id']}: {$record['name']}";
            $log_msg = "INFO => Group UPDATED:{$record['id']}: ";
            $more = "";
            foreach (array_keys($record) as $key) {
                if ($record[$key] != $new_record[$key]) {
                    $log_msg .= $more . $key . "[" . $record[$key] . "=>" . $new_record[$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);
            }
        }
    }
    // If the module returned an error code display a popup warning
    if ($status) {
        $js .= "alert('Save failed. Contact the webmaster if this problem persists.');";
    } else {
        $js .= "removeElement('{$window_name}');";
        $js .= "xajax_window_submit('app_group_list', xajax.getFormValues('app_group_list_filter_form'), 'display_list');";
    }
    // Insert the new table into the window
    $response->addScript($js);
    return $response->getXML();
}
开发者ID:edt82,项目名称:ona,代码行数:77,代码来源:app_group_edit.inc.php

示例11: load_module

function load_module($name = '')
{
    global $conf, $self, $onadb;
    if (!$name) {
        $self['error'] = "ERROR => load_module() No module specified!";
        return 1;
    }
    // If the module is already loaded, return success
    if (function_exists($name)) {
        return 0;
    }
    // Make sure we're connected to the DB
    // require_once($conf['inc_functions_db']);
    // Use cache if possible
    if (!is_array($self['cache']['modules']) or !array_key_exists('get_module_list', $self['cache']['modules'])) {
        // Get a list of the valid "modules" and their descriptions.
        require_once $conf['dcm_module_dir'] . '/get_module_list.inc.php';
        list($status, $self['cache']['modules']) = get_module_list('type=array');
    }
    // Make sure the user requested a valid "module"
    if (!array_key_exists($name, $self['cache']['modules'])) {
        // Otherwise print an error
        $self['error'] = "ERROR => The requested module is not valid!";
        return 1;
    }
    // Make sure the include file containing the function(s)/module(s) requested exists..
    // We have to find out which file it's in.
    list($status, $rows, $module) = db_get_record($onadb, 'dcm_module_list', array('name' => $name));
    if ($status or $rows != 1) {
        $self['error'] = 'ERROR => The specified module does not exist';
        return 1;
    }
    $file = $conf['dcm_module_dir'] . '/' . $module['file'];
    if (!is_file($file)) {
        // Otherwise print an error
        $self['error'] = "ERROR => The include file ({$file}) for the {$name} module doesn't exist!";
        return 1;
    }
    // Include the file
    // The file should define a function called generate_config() to which we pass a node-name,
    // and receive a configuration file.
    require_once $file;
    // Test that the module function existed in the file we just loaded
    if (!function_exists($name)) {
        $self['error'] = "ERROR => The module function {$name} doesn't exist in file: {$file}";
        return 1;
    }
    return 0;
}
开发者ID:edt82,项目名称:ona,代码行数:49,代码来源:functions_general.inc.php

示例12: subnet_nextip

function subnet_nextip($options = "")
{
    global $conf, $self, $onadb;
    // Version - UPDATE on every edit!
    $version = '1.00';
    printmsg('DEBUG => subnet_del(' . $options . ') called', 3);
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Sanitize options[commit] (default is no)
    $options['commit'] = sanitize_YN($options['commit'], 'N');
    // Return the usage summary if we need to
    if ($options['help'] or !$options['subnet']) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        $self['error'] = 'ERROR => Insufficient parameters';
        return array(1, <<<EOM

subnet_del-v{$version}
Return the next available IP address on a subnet.

  Synopsis: subnet_nextip [KEY=VALUE] ...

  Required:
    subnet=IP or ID               select subnet by search string

  Optional:
    offset=NUMBER                 Starting offset to find next available IP
    output=[dotted|numeric]       Return the number as a dotted or numeric value
                                  DEFAULT: numeric


EOM
);
    }
    // Find the subnet record we're deleting
    list($status, $rows, $subnet) = ona_find_subnet($options['subnet']);
    if ($status or !$rows) {
        $self['error'] = "ERROR => Subnet not found";
        return array(2, $self['error'] . "\n");
    }
    // Create a few variables that will be handy later
    $num_ips = 0xffffffff - $subnet['ip_mask'];
    $last_ip = $subnet['ip_addr'] + $num_ips - 1;
    // check that offset is a number
    if (isset($options['offset']) and !is_numeric($options['offset'])) {
        $self['error'] = "ERROR => Offset must be a numeric number";
        return array(3, $self['error'] . "\n");
    } else {
        $offsetmsg = " beyond offset {$options['offset']}";
    }
    // make sure the offset does not extend beyond the specified subnet
    if ($options['offset'] >= $num_ips - 1) {
        $self['error'] = "ERROR => Offset extends beyond specified subnet boundary";
        return array(4, $self['error'] . "\n");
    }
    if (!isset($options['output'])) {
        $options['output'] = '1';
    } else {
        if ($options['output'] != 'dotted' && $options['output'] != 'numeric') {
            $self['error'] = "ERROR => Output option must be 'dotted' or 'numeric'";
            return array(5, $self['error'] . "\n");
        }
    }
    // Find the first number based on our subnet and offset
    $ip = $subnet['ip_addr'] + $options['offset'];
    // Make sure we skip past the subnet IP to the first usable IP
    if ($ip == $subnet['ip_addr']) {
        $ip++;
    }
    // Start looping through our IP addresses until we find an available one
    while ($ip <= $last_ip) {
        // Find out if the ip is used in an interface
        list($status, $rows, $interfaces) = db_get_records($onadb, 'interfaces', array('ip_addr' => $ip));
        // If we find a free address.. check that it is not in a DHCP pool
        if (!$rows) {
            list($status, $rows, $pool) = db_get_record($onadb, 'dhcp_pools', "{$ip} >= ip_addr_start AND {$ip} <= ip_addr_end");
            if ($rows) {
                $ip = $pool['ip_addr_end'];
            } else {
                break;
            }
        }
        $ip++;
        // increment by one and check again
    }
    // If we checked all the IPs, make sure we are not on the broadcast IP of the subnet
    if ($ip == $last_ip + 1) {
        $self['error'] = "ERROR => No available IP addresses found on subnet{$offsetmsg}";
        return array(5, $self['error'] . "\n");
    }
    // return the IP
    return array(0, ip_mangle($ip, $options['output']) . "\n");
}
开发者ID:edt82,项目名称:ona,代码行数:92,代码来源:subnet.inc.php

示例13: dhcp_pool_modify

function dhcp_pool_modify($options = "")
{
    // The important globals
    global $conf, $self, $onadb;
    // Version - UPDATE on every edit!
    $version = '1.03';
    printmsg("DEBUG => dhcp_pool_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['pool'] and ($options['set_failover_group'] or $options['set_start'] or $options['set_end'] or $options['set_llength'] or $options['set_lgrace'] or $options['set_lrenewal'] or $options['set_lrebind']))) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        $self['error'] = 'ERROR => Insufficient parameters';
        return array(1, <<<EOM

dhcp_pool_modify-v{$version}
Updates a dhcp pool in the database pointing to the specified identifier

  Synopsis: dhcp_pool_modify [KEY=VALUE] ...

  Where:
    pool=ID                             Table ID for the pool

  Optional:
    set_failover_group=ID               group identifier
    set_server=NAME[.DOMAIN] or ID      server identifier
    set_start=IP                        Start ip address of pool
    set_end=IP                          End IP of pool
    set_llength=NUMBER                  Lease Time. Default ({$conf['dhcp_pool']['llength']})
    set_lgrace=NUMBER                   Lease Grace Period. Default ({$conf['dhcp_pool']['lgrace']})
    set_lrenewal=NUMBER                 Lease Renewal. Default ({$conf['dhcp_pool']['lrenewal']})
    set_lrebind=NUMBER                  Lease Rebind. Default ({$conf['dhcp_pool']['lrebind']})



EOM
);
    }
    // get the existing pool to edit
    list($status, $rows, $pool) = db_get_record($onadb, 'dhcp_pools', array('id' => $options['pool']));
    if (!$rows) {
        printmsg("DEBUG => Unable to find the DHCP pool record using id: {$options['id']}!", 3);
        $self['error'] = "ERROR => Unable to find a pool using id: {$options['pool']}";
        return array(1, $self['error'] . "\n");
    }
    // set the pool id in the set variable
    $SET['id'] = $pool['id'];
    // NOTE: currently modify pool does not allow you to change subnets
    // Get subnet info..
    list($status, $rows, $subnet) = ona_find_subnet($pool['subnet_id']);
    $SET['subnet_id'] = $subnet['id'];
    // make sure that the start address is actually part of an existing subnet
    if ($options['set_start']) {
        list($status, $rows, $subnetstart) = ona_find_subnet(ip_mangle($options['set_start'], 'dotted'));
        if (!$rows) {
            printmsg("DEBUG => Unable to find a subnet related to starting address ({$options['set_start']})!", 3);
            $self['error'] = "ERROR => Unable to find a subnet related to your starting address of {$options['set_start']}.";
            return array(1, $self['error'] . "\n");
        }
        if ($subnetstart['id'] != $pool['subnet_id']) {
            printmsg("DEBUG => The starting address ({$options['set_start']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!", 3);
            $self['error'] = "ERROR => The starting address ({$options['set_start']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!";
            return array(1, $self['error'] . "\n");
        }
    }
    // make sure that the end address is actually part of an existing subnet
    if ($options['set_end']) {
        list($status, $rows, $subnetend) = ona_find_subnet(ip_mangle($options['set_end'], 'dotted'));
        if (!$rows) {
            printmsg("DEBUG => Unable to find a subnet related to ending address ({$options['set_end']})!", 3);
            $self['error'] = "ERROR => Unable to find a subnet related to your ending address of {$options['set_end']}.";
            return array(1, $self['error'] . "\n");
        }
        if ($subnetend['id'] != $pool['subnet_id']) {
            printmsg("DEBUG => The ending address ({$options['set_end']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!", 3);
            $self['error'] = "ERROR => The ending address ({$options['set_end']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!";
            return array(1, $self['error'] . "\n");
        }
    }
    // Assign which failover group to use
    if ($options['set_failover_group'] == 0) {
        $desc = 'Not using a failover group';
        $SET['dhcp_failover_group_id'] = 0;
    } else {
        list($status, $rows, $fg) = ona_get_dhcp_failover_group_record(array('id' => $options['set_failover_group']));
        if (!$fg['id']) {
            printmsg("DEBUG => The failover_group specified ({$options['set_failover_group']}) does not exist", 3);
            $self['error'] = "ERROR => The failover_group specified ({$options['set_failover_group']}) does not exist!";
            return array(4, $self['error'] . "\n");
        }
        // get the server names for the two servers
        list($fail_host1, $fail_zone1) = ona_find_host($fg['primary_server_id']);
        list($fail_host2, $fail_zone2) = ona_find_host($fg['secondary_server_id']);
        $desc = $fail_host1['fqdn'] . '/' . $fail_host2['fqdn'];
        $SET['dhcp_failover_group_id'] = $fg['id'];
    }
    // check that start and end are not the same
    //if ($options['set_start'] and $options['set_end'] and $options['set_start'] == $options['set_end']) {
    //    printmsg("DEBUG => The start and end IP addresses (" . ip_mangle($options['set_start'],'dotted') . ") cannot be the same!",3);
    //    $self['error'] = "ERROR => The start and end IP addresses (" . ip_mangle($options['set_start'],'dotted') . ") cannot be the same!";
//.........这里部分代码省略.........
开发者ID:edt82,项目名称:ona,代码行数:101,代码来源:dhcp_pool.inc.php

示例14: ws_change_user_password

function ws_change_user_password($window_name, $form)
{
    global $conf, $self, $onadb;
    $username = $_SESSION['ona']['auth']['user']['username'];
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $js = "el('passchangemsg').innerHTML = '<span style=\"color: green;\">Changed!</span>'";
    $exit_status = 0;
    // Validate the userid was passed and is "clean"
    if (!preg_match('/^[A-Za-z0-9.\\-_]+$/', $username)) {
        $js = "el('passchangemsg').innerHTML = 'Invalid username format';";
        $response->addScript($js);
        return $response->getXML();
    }
    list($status, $rows, $user) = db_get_record($onadb, 'users', "username LIKE '{$username}'");
    if (!$rows) {
        $js = "el('passchangemsg').innerHTML = 'Unknown user';";
        // Return some javascript to the browser
        $response->addScript($js);
        return $response->getXML();
    }
    if ($user['password'] != $form['old']) {
        $js = "el('passchangemsg').innerHTML = 'Password incorrect (old)';";
        // Return some javascript to the browser
        $response->addScript($js);
        return $response->getXML();
    }
    if ($form['new1'] != $form['new2']) {
        $js = "el('passchangemsg').innerHTML = 'New passwords dont match.';";
        // Return some javascript to the browser
        $response->addScript($js);
        return $response->getXML();
    }
    list($status, $rows) = db_update_record($onadb, 'users', array('username' => $username), array('password' => $form['new2']));
    // If the module returned an error code display a popup warning
    if ($status) {
        $js = "alert('Save failed: " . trim($self['error']) . "');";
    }
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
开发者ID:edt82,项目名称:ona,代码行数:43,代码来源:app_user_info.inc.php

示例15: ws_display_list

function ws_display_list($window_name, $form)
{
    global $conf, $self, $mysql;
    global $font_family, $color, $style, $images;
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    // Make sure they're logged in
    if (!loggedIn()) {
        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);
    // Find out what page we're on
    $page = 1;
    if ($form['page'] and is_numeric($form['page'])) {
        $page = $form['page'];
    }
    printmsg("INFO => Displaying user list page: {$page} client url: {$_SESSION['auth']['client']['url']}", 0);
    // Calculate the SQL query offset (based on the page being displayed)
    $offset = $conf['search_results_per_page'] * ($page - 1);
    if ($offset == 0) {
        $offset = -1;
    }
    $where = "`client_id` = {$_SESSION['auth']['client']['id']} AND `active` = 1";
    if (is_array($form) and $form['filter']) {
        $where .= ' AND `username` LIKE ' . $mysql->qstr('%' . $form['filter'] . '%');
    }
    // Get our employees
    list($status, $rows, $records) = db_get_records($mysql, 'users', $where, 'username', $conf['search_results_per_page'], $offset);
    // If we got less than serach_results_per_page, add the current offset to it
    // so that if we're on the last page $rows still has the right number in it.
    if ($rows > 0 and $rows < $conf['search_results_per_page']) {
        $rows += $conf['search_results_per_page'] * ($page - 1);
    } else {
        if ($rows >= $conf['search_results_per_page']) {
            list($status, $rows, $tmp) = db_get_records($mysql, 'users', $where, '', 0);
        }
    }
    $count = $rows;
    // Add a table header
    $html = <<<EOL
    
    <!-- Results Table -->
    <table id="{$form['form_id']}_host_list" class="list-box" cellspacing="0" border="0" cellpadding="0" width="100%">
        
        <!-- Table Header -->
        <tr>
            <td class="list-header" align="center" style="border-right: 1px solid {$color['border']};">Username</td>
            <td class="list-header" align="center" style="border-right: 1px solid {$color['border']};">Full Name</td>
            <td class="list-header" align="center" style="border-right: 1px solid {$color['border']};">Company</td>
            <td class="list-header" align="center" style="border-right: 1px solid {$color['border']};">Admin</td>
            <td class="list-header" align="center">&nbsp</td>
        </tr>
        
EOL;
    // Loop through and display the records
    foreach ($records as $record) {
        list($status, $rows, $client) = db_get_record($mysql, 'clients', array('id' => $record['client_id']));
        $record['company_name'] = $client['company_name'];
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        // If the user is an admin, set some extra html
        $admin_html = "";
        if (empty($perm)) {
            list($status, $rows, $perm) = db_get_record($mysql, 'permissions', array('name' => 'admin'));
        }
        list($status, $rows, $acl) = db_get_record($mysql, 'acl', array('user_id' => $record['id'], 'perm_id' => $perm['id']));
        if ($acl['id']) {
            $admin_html = "<img src=\"{$images}/silk/tick.png\" border=\"0\">";
        }
        $html .= <<<EOL
        <tr onMouseOver="this.className='row-highlight';" onMouseOut="this.className='row-normal';">
            
            <td class="list-row">
                <a title="Edit"
                   class="act"
                   onClick="xajax_window_submit('user_edit', '{$record['id']}', 'editor');"
                >{$record['username']}</a>&nbsp;
            </td>
            
            <td class="list-row" align="left">
                {$record['fname']} {$record['lname']}&nbsp;
            </td>
            
            <td class="list-row" align="left">
                {$record['company_name']}&nbsp;
            </td>
            
            <td class="list-row" align="left">
                {$admin_html}&nbsp;
            </td>
            
            <td class="list-row" align="right">
                <a title="Edit"
                    class="act"
                    onClick="xajax_window_submit('user_edit', '{$record['id']}', 'editor');"
                ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;
            
//.........这里部分代码省略.........
开发者ID:edt82,项目名称:ona,代码行数:101,代码来源:user_list.inc.php


注:本文中的db_get_record函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。