This repository has been archived by the owner on Aug 25, 2020. It is now read-only.
/
publications.results.php
393 lines (348 loc) · 11.7 KB
/
publications.results.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<?php
$skip_login = true;
$show_breadcrumbs = true;
require_once 'functions.php';
require_once 'functions.omat.php';
$section = 4;
$page = 4;
if ($_POST['source']) {
$_GET['source'] = $_POST['source'];
}
if ($_POST['searchphrase']) {
$explode = explode(" ", $_POST['searchphrase']);
foreach ($explode as $key => $value) {
if ($_POST['title'] && $_POST['abstract']) {
$sql .= " AND (abstract LIKE '%" . mysql_clean($value, "wildcard") . "%' OR title LIKE '%" . mysql_clean($value, "wildcard") . "%')";
} elseif ($_POST['title']) {
$sql .= " AND (title LIKE '%" . mysql_clean($value, "wildcard") . "%')";
} elseif ($_POST['abstract']) {
$sql .= " AND (abstract LIKE '%" . mysql_clean($value, "wildcard") . "%')";
}
}
$filters = "<strong>Search phrase:</strong> " . html($_POST['searchphrase'], false);
}
if ($_GET['source']) {
$source = (int)$_GET['source'];
$this_page = "Filter publications";
$info = $db->record("SELECT * FROM sources WHERE id = $source");
$filters .= "<strong>Source</strong>: " . $info->name . "<br />";
$sql .= " AND papers.source = $source";
}
if ($_POST['start']) {
$start = (int)$_POST['start'];
$sql .= " AND papers.year >= $start";
$filters .= "<strong>Year</strong>: ";
$filters .= $_POST['end'] ? "$start - " . (int)$_POST['end'] : "during or after $start";
$filters .= "<br />";
}
if ($_POST['end']) {
$end = (int)$_POST['end'];
$sql .= " AND papers.year <= $end";
$filters = !$start ? "<strong>Year</strong>: during or before $end<br />" : '';
}
if ($_GET['year']) {
$year = (int)$_GET['year'];
$sql .= " AND papers.year = $year";
}
if (is_array($_POST['tags'])) {
$this_page = "Filter publications";
foreach ($_POST['tags'] as $key => $value) {
$id = (int)$key;
$parent = $db->record("SELECT name FROM tags_parents WHERE id = $id");
$filters .= '<strong>'.$parent->name.'</strong>: ';
$in_tags = false;
foreach ($value as $subvalue) {
$tag = (int)$subvalue;
$in_tags .= $tag.",";
$info = $db->record("SELECT * FROM tags WHERE id = $tag");
$filters .= $info->tag . " or ";
}
$filters = substr($filters, 0, -4) . '<br />'; // Take out ' or '
$in_tags = substr($in_tags, 0, -1); // Take out extra comma
$sql .= " AND EXISTS (SELECT * FROM tags_papers WHERE tags_papers.paper = papers.id AND tag IN ($in_tags))";
}
}
if ($_GET['tag']) {
$_GET['search'][] = $_GET['tag'];
unset($_GET['tag']);
}
if (is_array($_GET['search'])) {
$this_page = "Filter publications";
foreach ($_GET['search'] as $key => $value) {
$tag = (int)$value;
if ($tag == 213) {
$tag = 1045;
$alias = true;
}
if ($tag) {
$in_tags .= $tag.",";
$info = $db->record("SELECT * FROM tags WHERE id = $tag");
$filters .= $info->tag . " or ";
} else {
$info = $db->record("SELECT * FROM tags WHERE tag = '".html($value)."'");
}
if ($info->id) {
$sql .= " AND EXISTS (SELECT * FROM tags_papers WHERE tags_papers.paper = papers.id AND tag IN ($info->id))";
$tags_selected[$info->id] = true;
} else {
// Freely typed, search through abstract and title
$sql .= " AND (abstract LIKE '%" . mysql_clean($value, "wildcard") . "%' OR title LIKE '%" . mysql_clean($value, "wildcard") . "%')";
$value = htmlentities($value);
$additional_keywords[$value] = $value;
}
}
$filters = substr($filters, 0, -4) . '<br />'; // Take out ' or '
$in_tags = substr($in_tags, 0, -1); // Take out extra comma
//$sql .= " AND EXISTS (SELECT * FROM tags_papers WHERE tags_papers.paper = papers.id AND tag IN ($in_tags))";
}
if ($_POST['update_tag'] && defined("ADMIN")) {
$post = array(
'tag' => html($_POST['tag']),
'gps' => html($_POST['gps']),
'parent' => (int)$_POST['parent'],
'description' => $_POST['description'],
);
$update_tag = (int)$_POST['update_tag'];
$db->update("tags",$post,"id = $update_tag");
$print = "Information was saved";
}
if ($_GET['tag']) {
$tag = (int)$_GET['tag'];
$this_page = "Filter publications";
if (defined("ADMIN")) {
$parent_tag_list = $db->query("SELECT * FROM tags_parents ORDER BY name");
}
$list = $db->query("SELECT papers.*
FROM
tags_papers
JOIN
papers ON tags_papers.paper = papers.id
WHERE tags_papers.tag = $tag AND papers.status = 'active' ORDER BY year DESC, title");
$info = $db->record("SELECT * FROM tags WHERE id = $tag");
$filters = "<strong>Tag</strong>: " . $info->tag;
$title = $info->tag . " | ";
} elseif ($_GET['keyword']) {
$keyword = (int)$_GET['keyword'];
$this_page = "Filter publications";
$list = $db->query("SELECT papers.*
FROM
keywords_papers
JOIN
papers ON keywords_papers.paper = papers.id
WHERE keywords_papers.keyword = $keyword AND papers.status = 'active' ORDER BY year DESC, title");
$info = $db->record("SELECT * FROM keywords WHERE id = $keyword");
$filters = "<strong>Keyword</strong>: " . $info->keyword;
$title = $info->keyword . " | ";
} else {
$list = $db->query("SELECT papers.*
FROM papers
WHERE status = 'active' $sql
ORDER BY year DESC, title");
}
$years = $db->query("SELECT COUNT(*) AS total, year FROM papers WHERE status = 'active' $sql GROUP BY year ORDER BY year DESC");
$types = $db->query("SELECT COUNT(*) AS total, type FROM papers WHERE status = 'active' $sql GROUP BY type ORDER BY total DESC, type");
$tags = $db->query("SELECT tags.id, tags.tag, tags_papers.paper
FROM tags_papers
JOIN tags ON tags_papers.tag = tags.id
JOIN papers ON tags_papers.paper = papers.id
WHERE papers.status = 'active' $sql
");
foreach ($tags as $row) {
$tag_hits[$row['id']]++;
$tag_names[$row['id']] = $row['tag'];
$tag_papers[$row['paper']][$row['id']] = true;
}
$all_tags = $db->query("SELECT * FROM tags ORDER BY tag");
// Create a list of the most common tags
if (count($tag_hits)) {
arsort($tag_hits);
}
// Temporary fix until we unify queries
$get_types = $db->query("SELECT * FROM paper_types");
foreach ($get_types as $row) {
$type[$row['id']] = $row['name'];
}
$gps_tagged = ID == 2 ? 2 : 4;
$results_page = true;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php echo $header ?>
<title><?php echo $title ?>Publications | <?php echo SITENAME ?></title>
<link rel="stylesheet" href="css/select2.min.css" />
<style type="text/css">
.resultbox .row {
padding:10px;
}
.resultbox h4 {
padding:10px 10px 0 10px;
}
.nav-section-menu.nav a.show-all.nav-link {
background:#6b6b6b;
color:#f4f4f4;
}
.nav-section-menu.nav .nav-link {
font-size:14px;
}
.recordbox h3 {
font-size:18px;
}
.recordbox {
border-bottom:1px solid #999;
padding:20px 0;
}
.recordbox .type {
opacity:0.7;
}
.hide {
display:none;
}
.nav-header {
font-weight:bold;
margin-top:20px;
}
</style>
</head>
<body>
<?php require_once 'include.header.php'; ?>
<?php require_once 'include.search.php'; ?>
<?php if (!count($_GET) && !count($_POST) && !$_GET['all']) { $hide_results = true; } ?>
<?php if (!count($list) && !$hide_results) { ?>
<div class="alert alert-warning">No records were found.</div>
<?php } ?>
<?php if (count($list)) { ?>
<div class="row filters">
<script type="text/javascript">
$(function(){
$(".filters .filter").click(function(e){
e.preventDefault();
var type = $(this).data("type");
var id = $(this).data("id");
var hide = ".recordbox:not(."+type+"-"+id+")";
var show = ".recordbox."+type+"-"+id;
$(show).show('fast');
$(hide).hide('fast');
$(this).closest("ul").find("li a").removeClass('active');
$(this).addClass("active");
});
});
</script>
<?php if (!$hide_results) { ?>
<div class="col-md-3 ">
<ul class="nav nav-section-menu nav-sidebar">
<li class="nav-header">Filter by Year</li>
<?php $hidden_items = false; $i = 0; foreach ($years as $row) { ?>
<?php
$i++;
if ($i > 5) {
$class = "hide hide-year";
$hidden_items = true;
}
?>
<li class="<?php echo $class ?>">
<a href="#" class="nav-link filter" data-id="<?php echo $row['year'] ?>" data-type="year"><?php echo $row['year'] ?>
<span class="pull-right badge badge-default"><?php echo $row['total'] ?></span>
</a>
</li>
<?php } ?>
<?php if ($hidden_items) { ?>
<li>
<a href="#" class="show-all nav-link" data-type="year">Show all
<i class="fa fa-angle-down"></i>
</a>
</li>
<?php } ?>
</ul>
<ul class="nav nav-section-menu nav-sidebar">
<li class="nav-header">Filter by Type</li>
<?php $hidden_items = false; $i = 0; foreach ($types as $row) { ?>
<?php
$i++;
$class = "reg";
if ($i > 5) {
$class = "hide hide-type";
$hidden_items = true;
}
?>
<li class="<?php echo $class ?>">
<a href="#" class="nav-link filter" data-id="<?php echo $row['type'] ?>" data-type="type"><?php echo $type[$row['type']] ?>
<span class="badge badge-default pull-right"><?php echo $row['total'] ?></span>
</a>
</li>
<?php } ?>
<?php if ($hidden_items) { ?>
<li>
<a href="#" class="show-all nav-link" data-type="type">Show all
<i class="fa fa-angle-down"></i>
</a>
</li>
<?php } ?>
</ul>
<ul class="nav nav-section-menu nav-sidebar">
<li class="nav-header">Filter by Tag</li>
<?php $hidden_items = true; $i = 0; foreach ($tag_hits as $row['tag'] => $row['total']) { ?>
<?php
$i++;
$class = "reg";
if ($i > 10) {
$class = "hide hide-tag";
}
if ($i < 30) {
?>
<li class="<?php echo $class ?>">
<a href="#" class="nav-link filter" data-id="<?php echo $row['tag'] ?>" data-type="tag"><?php echo $tag_names[$row['tag']] ?>
<span class="badge badge-default pull-right"><?php echo $row['total'] ?></span>
</a>
</li>
<?php } } ?>
<?php if ($hidden_items) { ?>
<li>
<a href="#" class="show-all nav-link" data-type="tag">Show all
<i class="fa fa-angle-down"></i>
</a>
</li>
<?php } ?>
</ul>
</div>
<?php } ?>
<div class="col-md-<?php echo $hide_results ? 12 : 9 ?> main records">
<?php if ($hide_results) { ?>
<div class="alert alert-default hide">
Enter a search phrase in the box above, or
use the filters on the left to browse through our database.
Alternatively, click the button below to view our entire list.
<br /><br />
<a href="publications/all" class="btn btn-primary"><i class="fa fa-list"></i> View All</a>
</div>
<div class="" style="height:200px;"></div>
<?php } else { ?>
<div class="resultbox">
<i class="fa fa-info-circle"></i>
<strong><?php echo count($list) ?></strong>
<?php echo count($list) > 1 ? 'publications' : 'publication' ?> found.
</div>
<?php foreach ($list as $row) { ?>
<div class="recordbox year-<?php echo $row['year'] ?> type-<?php echo $row['type'] ?> <?php foreach ($tag_papers[$row['id']] as $key => $value) { echo "tag-$key "; } ?>">
<h3><a href="publication/<?php echo $row['id'] ?>"><?php echo $row['title'] ?></a></h3>
<div class="row">
<div class="col-md-2">
<span class="type">
<?php echo $type[$row['type']] ?>
</span>
<br />
<?php echo $row['year'] ?>
</div>
<div class="col-md-10">
<?php echo $row['author'] ?>
</div>
</div>
</div>
<?php } ?>
<?php } ?>
</div>
</div>
<?php } ?>
<?php require_once 'include.footer.php'; ?>
</body>
</html>