This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scholarsearch.php
67 lines (60 loc) · 1.89 KB
/
scholarsearch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* List of active records
*
* @author Jared Howland <[email protected]>
* @version 2013-02-26
* @since 2013-02-26
*
*/
require_once 'config.php';
// TODO: Convert to OOP
$format = $_REQUEST['format'];
$database = new db;
$db = $database->connect();
$sql = 'SELECT r.id, r.resource_name, r.last_load, r.num_records, r.file_exists, v.name AS vendor_name FROM records r INNER JOIN vendors v ON r.vendor_id = v.id WHERE load_records = "Y" ORDER BY vendor_name, resource_name';
$query = $db->prepare($sql);
$query->execute();
$marc_record_loads = $query->fetchAll(PDO::FETCH_ASSOC);
$db = null;
$records = array();
foreach($marc_record_loads as $resource) {
$last_load = $resource['last_load'];
$vendor_name = $resource['vendor_name'];
$resource_name = $resource['resource_name'];
$resource_id = $resource['id'];
$num_records = $resource['num_records'];
$file_exists = $resource['file_exists'];
$name = $vendor_name . '-' . $resource_name;
$filename = config::UPLOAD_DIRECTORY . '/' . $resource_id . '.xml';
// Only show if file actually exists
if($file_exists == 'Y') {
$file = config::URL . '/' . config::UPLOAD_DIRECTORY . '/' . $resource_id . '.xml';
$records[$file] = array('last_updated' => $last_load, 'name' => $name, 'num_records' => $num_records);
}
}
// JSON
if($format == 'json') {
echo json_encode($records);
// HTML
} elseif($format == 'html') {
$links = NULL;
foreach($records as $url => $record) {
$links .= '<li><a href="' . $url . '">' . $record['name'] . '</a></li>';
}
$html = <<<HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Scholarsearch Links</title>
</head>
<body>
<ul>$links</ul>
</body>
</html>
HTML;
echo $html;
// Error for incorrect format request
} else { die('Valid formats include "html" and "json". Please go back and try again.');}
?>