Ejemplo n.º 1
0
/**
 * Update section
 */
function UpdateSection($update, $api = false)
{
    global $database;
    # replace special chars for permissions
    $update['permissions'] = mysqli_real_escape_string($database, $update['permissions']);
    $update['description'] = mysqli_real_escape_string($database, $update['description']);
    $update['name'] = mysqli_real_escape_string($database, $update['name']);
    if (!$api && !$update['name']) {
        die('<div class="alert alert-danger">' . _('Name is mandatory') . '!</div>');
    }
    # section name is mandatory
    $query = setUpdateSectionQuery($update);
    # set update section query
    $log = prepareLogFromArray($update);
    # prepare log
    /* save old if delete */
    if ($update['action'] == "delete") {
        $dold = getSectionDetailsById($update['id']);
    } elseif ($update['action'] == "edit") {
        $old = getSectionDetailsById($update['id']);
    }
    # delete and edit requires multiquery
    if ($update['action'] == "delete" || $update['action'] == "edit") {
        # execute
        try {
            $result = $database->executeMultipleQuerries($query, true);
        } catch (Exception $e) {
            $error = $e->getMessage();
            updateLogTable('Section ' . $update['action'] . ' failed (' . $update['name'] . ') - ' . $error, $log, 2);
            # write error log
            if (!$api) {
                print '<div class="alert alert-danger">' . "Cannot {$update['action']} all entries" . ' - ' . $error . '!</div>';
            }
            return false;
        }
        # success
        updateLogTable('Section ' . $update['name'] . ' ' . $update['action'] . ' ok', $log, 1);
        # write success log
        /* for changelog */
        if ($update['action'] == "delete") {
            $dold['id'] = $update['id'];
            writeChangelog('section', $update['action'], 'success', $dold, array());
        } else {
            writeChangelog('section', $update['action'], 'success', $old, $update);
        }
        return true;
    } else {
        # execute
        try {
            $result = $database->executeQuery($query, true);
        } catch (Exception $e) {
            $error = $e->getMessage();
            updateLogTable('Adding section ' . $update['name'] . 'failed - ' . $error, $log, 2);
            # write error log
            if (!$api) {
                die('<div class="alert alert-danger">' . 'Cannot update database' . '!<br>' . $error . '</div>');
            }
            return false;
        }
        # success
        updateLogTable('Section ' . $update['name'] . ' added succesfully', $log, 1);
        # write success log
        /* for changelog */
        $update['id'] = $result;
        writeChangelog('section', $update['action'], 'success', array(), $update);
        return true;
    }
}
Ejemplo n.º 2
0
/**
 * Write new changelog
 */
function write_changelog($ctype, $action, $result, $old, $new)
{
    return writeChangelog($ctype, $action, $result, $old, $new);
}
Ejemplo n.º 3
0
/**
 * Modify ( add / edit / delete ) IP address
 */
function modifyIpAddress($ip)
{
    global $database;
    /* set query, open db connection and fetch results */
    $query = SetInsertQuery($ip);
    /* save old if delete */
    if ($ip['action'] == "delete") {
        $dold = getIpAddrDetailsById($ip['id']);
    } elseif ($ip['action'] == "edit") {
        $old = getIpAddrDetailsById($ip['id']);
    }
    /* execute */
    try {
        $id = $database->executeQuery($query, true);
    } catch (Exception $e) {
        print "<div class='alert alert-danger'>" . _('Error') . ": " . $e->getMessage() . "</div>";
        //save changelog
        writeChangelog('ip_addr', $ip['action'], 'error', $old, $new);
        return false;
    }
    /* for changelog */
    if ($ip['action'] == "add") {
        $ip['id'] = $id;
        writeChangelog('ip_addr', $ip['action'], 'success', array(), $ip);
    } elseif ($ip['action'] == "delete") {
        writeChangelog('ip_addr', $ip['action'], 'success', $dold, array());
    } else {
        writeChangelog('ip_addr', $ip['action'], 'success', $old, $ip);
    }
    # success
    return true;
}
Ejemplo n.º 4
0
/**
 * Modify ( add / edit / delete ) IP address
 */
function modifyIpAddress($ip)
{
    global $db;
    # get variables from config file
    $database = new database($db['host'], $db['user'], $db['pass'], $db['name']);
    /* escape special characters */
    $ip['description'] = mysqli_real_escape_string($database, $ip['description']);
    $ip['note'] = mysqli_real_escape_string($database, $ip['note']);
    /* set query, open db connection and fetch results */
    $query = SetInsertQuery($ip);
    /* save old if delete */
    if ($ip['action'] == "delete") {
        $dold = getIpAddrDetailsById($ip['id']);
    } elseif ($ip['action'] == "edit") {
        $old = getIpAddrDetailsById($ip['id']);
    }
    /* execute */
    try {
        $id = $database->executeQuery($query, true);
    } catch (Exception $e) {
        $error = $e->getMessage();
        print "<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>";
        //save changelog
        writeChangelog('ip_addr', $ip['action'], 'error', $old, $new);
        return false;
    }
    /* for changelog */
    if ($ip['action'] == "add") {
        $ip['id'] = $id;
        writeChangelog('ip_addr', $ip['action'], 'success', array(), $ip);
    } elseif ($ip['action'] == "delete") {
        writeChangelog('ip_addr', $ip['action'], 'success', $dold, array());
    } else {
        writeChangelog('ip_addr', $ip['action'], 'success', $old, $ip);
    }
    # success
    return true;
}