예제 #1
0
function updateRegexp(array $regexp, array $expressions)
{
    try {
        $regexpId = $regexp['regexpid'];
        unset($regexp['regexpid']);
        // check existence
        if (!getRegexp($regexpId)) {
            throw new Exception(_('Regular expression does not exist.'));
        }
        // check required fields
        $dbFields = array('name' => null);
        if (!check_db_fields($dbFields, $regexp)) {
            throw new Exception(_('Incorrect arguments passed to function') . ' [updateRegexp]');
        }
        // check duplicate name
        $dbRegexp = DBfetch(DBselect('SELECT re.regexpid' . ' FROM regexps re' . ' WHERE re.name=' . zbx_dbstr($regexp['name']) . andDbNode('re.regexpid')));
        if ($dbRegexp && bccomp($regexpId, $dbRegexp['regexpid']) != 0) {
            throw new Exception(_s('Regular expression "%s" already exists.', $regexp['name']));
        }
        rewriteRegexpExpressions($regexpId, $expressions);
        DB::update('regexps', array('values' => $regexp, 'where' => array('regexpid' => $regexpId)));
    } catch (Exception $e) {
        error($e->getMessage());
        return false;
    }
    return true;
}
예제 #2
0
    }
    if ($result) {
        add_audit(hasRequest('update') ? AUDIT_ACTION_UPDATE : AUDIT_ACTION_ADD, AUDIT_RESOURCE_REGEXP, _('Name') . NAME_DELIMITER . getRequest('name'));
        unset($_REQUEST['form']);
    }
    $result = DBend($result);
    if ($result) {
        uncheckTableRows();
    }
    show_messages($result, $messageSuccess, $messageFailed);
} elseif (hasRequest('action') && getRequest('action') == 'regexp.massdelete') {
    $regExpIds = getRequest('regexpids', getRequest('regexpid', []));
    zbx_value2array($regExpIds);
    $regExps = [];
    foreach ($regExpIds as $regExpId) {
        $regExps[$regExpId] = getRegexp($regExpId);
    }
    DBstart();
    $result = DBexecute('DELETE FROM regexps WHERE ' . dbConditionInt('regexpid', $regExpIds));
    $regExpCount = count($regExpIds);
    if ($result) {
        foreach ($regExps as $regExpId => $regExp) {
            add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_REGEXP, 'Id [' . $regExpId . '] ' . _('Name') . ' [' . $regExp['name'] . ']');
        }
        unset($_REQUEST['form'], $_REQUEST['regexpid']);
    }
    $result = DBend($result);
    if ($result) {
        uncheckTableRows();
    }
    show_messages($result, _n('Regular expression deleted', 'Regular expressions deleted', $regExpCount), _n('Cannot delete regular expression', 'Cannot delete regular expressions', $regExpCount));
    show_messages($result, $msg1, $msg2);
    if ($result) {
        add_audit(!isset($_REQUEST['regexpid']) ? AUDIT_ACTION_ADD : AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_REGEXP, _('Name') . ': ' . $_REQUEST['rename']);
        unset($_REQUEST['form']);
    }
    Dbend($result);
} elseif (isset($_REQUEST['go'])) {
    if ($_REQUEST['go'] == 'delete') {
        $regExpids = get_request('regexpid', array());
        if (isset($_REQUEST['regexpids'])) {
            $regExpids = $_REQUEST['regexpids'];
        }
        zbx_value2array($regExpids);
        $regExps = array();
        foreach ($regExpids as $regExpid) {
            $regExps[$regExpid] = getRegexp($regExpid);
        }
        DBstart();
        $result = DBexecute('DELETE FROM regexps WHERE ' . dbConditionInt('regexpid', $regExpids));
        $result = Dbend($result);
        $regExpCount = count($regExpids);
        show_messages($result, _n('Regular expression deleted', 'Regular expressions deleted', $regExpCount), _n('Cannot delete regular expression', 'Cannot delete regular expressions', $regExpCount));
        if ($result) {
            foreach ($regExps as $regExpid => $regExp) {
                add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_REGEXP, 'Id [' . $regExpid . '] ' . _('Name') . ' [' . $regExp['name'] . ']');
            }
            unset($_REQUEST['form']);
            unset($_REQUEST['regexpid']);
            $url = new CUrl();
            $path = $url->getPath();
            insert_js('cookie.eraseArray("' . $path . '")');