Ejemplo n.º 1
0
<?php

include_once '../data.php';
include_once '../functions.php';
if (isset($_GET['file'])) {
    database_connect(IL_DATABASE_PATH, 'library');
    attach_clipboard($dbHandle);
    $file_query = $dbHandle->quote($_GET['file']);
    $dbHandle->beginTransaction();
    // Does item exist in clipboard?
    $result = $dbHandle->query("SELECT COUNT(*) FROM clipboard.files WHERE id={$file_query}");
    $exists = $result->fetchColumn();
    $result = null;
    if ($exists !== '1') {
        // Does item still exist in library?
        $result = $dbHandle->query("SELECT COUNT(*) FROM library WHERE id={$file_query}");
        $exists = $result->fetchColumn();
        $result = null;
        if ($exists !== '1') {
            die('Error! This item does not exist anymore.');
        }
        // Can't add over 100,000
        $result = $dbHandle->query("SELECT count(*) FROM clipboard.files");
        $count = $result->fetchColumn();
        $result = null;
        if ($count >= 100000) {
            $dbHandle->rollBack();
            echo 'Error! Clipboard can hold up to 100,000 items.';
            die;
        }
        // Add item to clipboard.
Ejemplo n.º 2
0
function delete_record($dbHandle, $files)
{
    settype($files, "array");
    // get PDF filenames of deleted items
    $result = $dbHandle->query("SELECT file FROM library WHERE id IN (" . join(',', $files) . ")");
    $filenames = $result->fetchAll(PDO::FETCH_COLUMN);
    $result = null;
    // delete PDFs, PDF cache, supplementary files and images
    while (list(, $filename) = each($filenames)) {
        $pdf_path = IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($filename) . DIRECTORY_SEPARATOR;
        if (is_file($pdf_path . $filename)) {
            unlink($pdf_path . $filename);
        }
        if (is_file(IL_PDF_CACHE_PATH . DIRECTORY_SEPARATOR . $filename . '.sq3')) {
            unlink(IL_PDF_CACHE_PATH . DIRECTORY_SEPARATOR . $filename . '.sq3');
        }
        $integer1 = sprintf("%05d", intval($filename));
        $supplementary_files = glob(IL_SUPPLEMENT_PATH . DIRECTORY_SEPARATOR . get_subfolder($filename) . DIRECTORY_SEPARATOR . $integer1 . '*', GLOB_NOSORT);
        if (is_array($supplementary_files)) {
            foreach ($supplementary_files as $supplementary_file) {
                @unlink($supplementary_file);
            }
        }
        $png_files = glob(IL_IMAGE_PATH . DIRECTORY_SEPARATOR . $integer1 . '*.jpg', GLOB_NOSORT);
        if (is_array($png_files)) {
            foreach ($png_files as $png_file) {
                @unlink($png_file);
            }
        }
    }
    // delete from clipboard, make sure session_write_close was not called before this
    attach_clipboard($dbHandle);
    $dbHandle->exec("DELETE FROM clipboard.files WHERE id IN (" . join(',', $files) . ")");
    $dbHandle->exec("DETACH DATABASE clipboard");
    // delete from main database
    $dbHandle->beginTransaction();
    $dbHandle->exec("DELETE FROM library WHERE id IN (" . join(',', $files) . ")");
    $dbHandle->exec("DELETE FROM shelves WHERE fileID IN (" . join(',', $files) . ")");
    $dbHandle->exec("DELETE FROM filescategories WHERE fileID IN (" . join(',', $files) . ")");
    $dbHandle->exec("DELETE FROM projectsfiles WHERE fileID IN (" . join(',', $files) . ")");
    $dbHandle->exec("DELETE FROM notes WHERE fileID IN (" . join(',', $files) . ")");
    $dbHandle->exec("DELETE FROM yellowmarkers WHERE filename IN ('" . join("','", $filenames) . "')");
    $dbHandle->exec("DELETE FROM annotations WHERE filename IN ('" . join("','", $filenames) . "')");
    $dbHandle->commit();
    $dbHandle = null;
    // delete full texts
    $fdbHandle = database_connect(IL_DATABASE_PATH, 'fulltext');
    $fdbHandle->exec("DELETE FROM full_text WHERE fileID IN (" . join(',', $files) . ")");
    $fdbHandle = null;
    // delete discussions
    if (file_exists(IL_DATABASE_PATH . DIRECTORY_SEPARATOR . 'discussions.sq3')) {
        $fdbHandle = database_connect(IL_DATABASE_PATH, 'discussions');
        $fdbHandle->exec("DELETE FROM filediscussion WHERE fileID IN (" . join(',', $files) . ")");
        $fdbHandle = null;
    }
    // delete PDF bookmarks and history
    if (file_exists(IL_DATABASE_PATH . DIRECTORY_SEPARATOR . 'history.sq3')) {
        $fdbHandle = database_connect(IL_DATABASE_PATH, 'history');
        $fdbHandle->beginTransaction();
        $fdbHandle->exec("DELETE FROM usersfiles WHERE fileID IN (" . join(',', $files) . ")");
        $fdbHandle->exec("DELETE FROM bookmarks WHERE file IN ('" . join("','", $filenames) . "')");
        $fdbHandle->commit();
        $fdbHandle = null;
    }
    if (!empty($error)) {
        return $error;
    }
}