Exemple #1
0
            }
        }
        $z++;
    }
    $y = 0;
    foreach ($withoutReplicates as $table) {
        if ($table != null) {
            $removedNull[$y] = $table;
        }
        $y++;
    }
    $arrayValues = array_values($removedNull);
    //klucze od 0 liczone
    //var_dump($withoutReplicates);
    //var_dump($removedNull);
    //var_dump($arrayValues);
    return $arrayValues;
}
/*
 * Kod popniżej służy wygenerowaniu testów i strony poglądaowej - nie modyfikujcie go!
 */
$testCases = [[[1, 2, "jan", "kowlaski", 2, "jan"], [1, 2, "jan", "kowlaski"]], [[3.4, "jablko", 'banan', 'banan', "gruszka", 5], [3.4, "jablko", 'banan', "gruszka", 5]], [[1, 2, 3, "jablko", 'banan'], [1, 2, 3, "jablko", 'banan']], [[], []], [[1, 2, 3, 4], [1, 2, 3, 4]]];
$results = "";
foreach ($testCases as $case) {
    if (($funcValue = findDuplicates($case[0])) === $case[1]) {
        $results .= "<tr class='success'><td> Ok </td><td>[" . implode($case[0], ",") . "] </td><td>[" . implode($case[1], ",") . "]</td><td>[" . implode($funcValue, ",") . "]</td></tr>";
    } else {
        $results .= "<tr class='danger'><td> Fail </td><td> [" . implode($case[0], ",") . "] </td><td>[" . implode($case[1], ",") . "]</td><td>[" . implode($funcValue, ",") . "]</td></tr>";
    }
}
echo "\n<!DOCTYPE html>\n<html lang='pl'>\n  <head>\n    <meta charset='utf-8'>\n    <title>Usuń duplikaty</title>\n    <link href='./css/bootstrap.min.css' rel='stylesheet'>\n\n  </head>\n\n  <body>\n\n    <div class='container'>\n      <div class='jumbotron'>\n        <h1>Usuń duplikaty</h1>\n        <p><a class='btn btn-lg btn-success' href='javascript:window.location.reload();' role='button'>Odśwież</a></p>\n      </div>\n\n      <div class='row'>\n          <h1>Testy:</h1>\n          <table class='table'>\n            <thead>\n              <tr>\n                <th>Stan testu:</th>\n                <th>Dane:</th>\n                <th>Wartość spodziewana:</th>\n                <th>Wartość otrzymana:</th>\n              </tr>\n            </thead>\n            <tbody>\n                {$results}\n            </tbody>\n          </table>\n      </div>\n    </div>\n  </body>\n</html>\n";
foreach ($resources as $resource) {
    // use extension to get scrambled path
    $extension = $resource['file_extension'];
    $scrambled = get_resource_path($resource['ref'], true, "", false, $extension);
    // get original file name
    $filename = get_data_by_field($resource['ref'], $filename_field);
    // save original file name (may be appended to indicate dupe)
    $orig_filename = $filename;
    // check if a file has already been processed with this name
    if (in_array($filename, $filenames)) {
        // if so, append a dupe tag
        $path_parts = pathinfo($filename);
        if (isset($path_parts['extension']) && isset($path_parts['filename'])) {
            $filename_ext = $path_parts['extension'];
            $filename_wo = $path_parts['filename'];
            $x = findDuplicates($filenames, $filename);
            $filename = $filename_wo . "_DUPE" . $x . "." . $filename_ext;
            fwrite($fp, 'DUPE: ');
            echo "DUPE: ";
        }
    }
    //add original file name to array
    $filenames[] = $orig_filename;
    //copy file if both paths exist
    if (file_exists($scrambled) && $filename != "") {
        echo "copying " . $drive_path . $filename;
        fwrite($fp, "copying " . $drive_path . $filename . "\n");
        // allow to re-run script without re-copying files
        if (!file_exists($drive_path . $filename)) {
            // optionally write metadata
            if ($write_metadata) {
Exemple #3
0
} else {
    $userID = 0;
}
// set variable to zero (a user with '$userID = 0' definitely doesn't exist) in order to prevent 'Undefined variable...' messages
// --------------------------------------------------------------------
// CONSTRUCT SQL QUERY from user input provided by any of the search forms:
// --- Form 'sql_search.php': ------------------
if ($formType == "sqlSearch") {
    // verify the SQL query specified by the user and modify it if security concerns are encountered:
    // (this function does add/remove user-specific query code as required and will fix problems with escape sequences within the SQL query)
    $query = verifySQLQuery($sqlQuery, $referer, $displayType, $showLinks);
    // function 'verifySQLQuery()' is defined in 'include.inc.php' (since it's also used by 'rss.php')
} elseif ($formType == "duplicateSearch") {
    // find duplicate records within results of the given SQL query (using settings extracted from the 'duplicateSearch' form
    // in 'duplicate_search.php') and return a modified database query that only matches these duplicate entries:
    list($sqlQuery, $displayType) = findDuplicates($sqlQuery, $originalDisplayType);
    // by passing the generated SQL query thru the 'verifySQLQuery()' function we ensure that necessary fields are added as needed:
    // (this function does add/remove user-specific query code as required and will fix problems with escape sequences within the SQL query)
    $query = verifySQLQuery($sqlQuery, $referer, $displayType, $showLinks);
    // function 'verifySQLQuery()' is defined in 'include.inc.php' (since it's also used by 'rss.php')
} elseif ($formType == "simpleSearch") {
    $query = extractFormElementsSimple($showLinks, $userID);
} elseif ($formType == "librarySearch") {
    $query = extractFormElementsLibrary($showLinks, $userID);
} elseif ($formType == "advancedSearch") {
    $query = extractFormElementsAdvanced($showLinks, $loginEmail, $userID);
} elseif ($formType == "refineSearch" or $formType == "displayOptions") {
    list($query, $displayType) = extractFormElementsRefineDisplay($tableRefs, $displayType, $originalDisplayType, $sqlQuery, $showLinks, $citeOrder, $userID);
    // function 'extractFormElementsRefineDisplay()' is defined in 'include.inc.php' since it's also used by 'users.php'
} elseif ($formType == "queryResults") {
    list($query, $displayType) = extractFormElementsQueryResults($displayType, $originalDisplayType, $showLinks, $citeOrder, $orderBy, $userID, $sqlQuery, $referer, $recordSerialsArray, $recordsSelectionRadio);