forked from SIBiUSP/nav_marc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.php
executable file
·448 lines (422 loc) · 16.7 KB
/
result.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
<?php
$tpTitle = 'BDPI USP - Resultado da Busca';
include 'inc/config.php';
include 'inc/header.php';
include_once 'inc/functions.php';
if (empty($_SESSION["citation_style"])) {
$_SESSION["citation_style"]="abnt";
}
if (isset($_POST["citation_style"])) {
$_SESSION["citation_style"] = $_POST['citation_style'];
}
if (empty($_SESSION["login_role"])) {
$_SESSION["login_role"]="annonymous";
}
if (isset($_POST["login_role"])) {
$_SESSION["login_role"] = $_POST['login_role'];
}
/* Citeproc-PHP*/
include 'inc/citeproc-php/CiteProc.php';
$csl = file_get_contents('inc/citeproc-php/style/'.$_SESSION["citation_style"].'.csl');
$lang = "br";
$citeproc = new citeproc($csl,$lang);
$mode = "reference";
/* Pegar a URL atual */
if (strpos($_SERVER['REQUEST_URI'], '?') !== false) {
$url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
} else {
$url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}?";
}
$escaped_url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
/* Query */
if (empty($_GET)) {
$query = json_decode('{}');
} elseif (!empty($_GET['category'])) {
unset($_GET['category']);
$q = str_replace('"', '\\"', $_GET['q']);
unset($_GET['q']);
$consult = '';
foreach ($_GET as $key => $value) {
$consult .= '"'.$key.'":"'.$value.'",';
}
$query = json_decode('{'.$consult.'"$text": {"$search":"'.$q.'"}}');
if ((array_key_exists("date_init", $query))||(array_key_exists("date_end", $query))) {
if (array_key_exists("date_init", $query)) {
$query["year"]["\$gte"] = $query["date_init"];
} else {
$query["year"]["\$gte"] = "1";
}
if (array_key_exists("date_end", $query)) {
$query["year"]["\$lte"] = $query["date_end"];
} else {
$query["year"]["\$lte"] = "20500";
}
unset($query["date_init"]);
unset($query["date_end"]);
}
} else {
$query = array();
foreach ($_GET as $key => $value) {
$query[$key] = $value;
}
if ((array_key_exists("date_init", $query))||(array_key_exists("date_end", $query))) {
if (array_key_exists("date_init", $query)) {
$query["year"]["\$gte"] = $query["date_init"];
} else {
$query["year"]["\$gte"] = "1";
}
if (array_key_exists("date_end", $query)) {
$query["year"]["\$lte"] = $query["date_end"];
} else {
$query["year"]["\$lte"] = "20500";
}
unset($query["date_init"]);
unset($query["date_end"]);
}
}
/* Pagination variables */
$page = isset($_POST['page']) ? (int) $_POST['page'] : 1;
$limit = 15;
$skip = ($page - 1) * $limit;
$next = ($page + 1);
$prev = ($page - 1);
$sort = array('year' => -1);
/* Consultas */
$query_json = json_encode($query);
$query_new = json_decode('[{"$match":'.$query_json.'},{"$lookup":{"from": "producao_bdpi", "localField": "_id", "foreignField": "_id", "as": "bdpi"}},{"$sort":{"year":-1}},{"$skip":'.$skip.'},{"$limit":'.$limit.'}]');
$query_count = json_decode('[{"$match":'.$query_json.'},{"$group":{"_id":null,"count":{"$sum": 1}}}]');
$cursor = $c->aggregate($query_new);
$total_count = $c->aggregate($query_count);
$total = $total_count['result'][0]['count'];
?>
<script src="https://cdn.rawgit.com/mdehoog/Semantic-UI/6e6d051d47b598ebab05857545f242caf2b4b48c/dist/semantic.min.js"></script>
</head>
<body>
<div class="ui main container">
<div class="ui main two column stackable grid">
<div class="four wide column">
<div class="ui fluid vertical accordion menu">
<div class="item">
<a class="active title">
<i class="dropdown icon"></i>
Filtros ativos
</a>
<div class="active content">
<div class="ui form">
<div class="grouped fields">
<form method="get" action="result.php">
<?php foreach ($_GET as $key=>$value): ?>
<div class="field">
<div class="ui checkbox">
<input type="checkbox" checked="checked" name="<?php echo $key; ?>" value="<?php echo $value; ?>">
<label><?php echo $value; ?></label>
</div>
</div>
<?php endforeach;?>
<button type="submit" class="ui icon button">Retirar filtros</button>
</form>
</div>
</div>
</div>
</div>
<?php
/* Gerar facetas */
generateFacet($url, $c, $query, '$type', 'count', -1, 'Tipo de publicação', 50);
if ($_SESSION['login_role'] == 'admin'){
generateFacet($url, $c, $query, '$departamentoFD', 'count', -1, 'Departamento FD', 100);
}
generateFacet($url, $c, $query, '$subject', 'count', -1, 'Assuntos', 50);
generateFacet($url, $c, $query, '$authors', 'count', -1, 'Autores', 50);
if ($_SESSION['login_role'] == 'admin'){
generateFacet($url, $c, $query, '$issn_part', 'count', -1, 'ISSN do todo', 50);
}
generateFacet($url, $c, $query, '$ispartof', 'count', -1, 'É parte de', 50);
generateFacet($url, $c, $query, '$year', '_id', -1, 'Ano de publicação', 50);
generateFacet($url, $c, $query, '$paginacao', 'count', -1, 'Páginação', 50);
generateFacet($url, $c, $query, '$volume', 'count', -1, 'Volume', 50);
generateFacet($url, $c, $query, '$numeracao', 'count', -1, 'Numeração', 50);
generateFacet($url, $c, $query, '$mes', 'count', -1, 'Mês', 50);
generateFacet($url, $c, $query, '$language', 'count', -1, 'Idioma', 50);
generateFacet($url, $c, $query, '$revisado', 'count', -1, 'Revisado', 50);
generateFacet($url, $c, $query, '$producao', 'count', -1, 'Produção científica', 50);
?>
</div>
<h3>Filtrar por data</h3>
<form method="get" action="<?php echo $escaped_url; ?>">
<div class="ui calendar" id="date_init">
<div class="ui input left icon">
<i class="time icon"></i>
<input type="text" placeholder="Ano inicial" name="date_init">
</div>
</div>
<div class="ui calendar" id="date_end">
<div class="ui input left icon">
<i class="time icon"></i>
<input type="text" placeholder="Ano final" name="date_end">
</div>
</div>
<?php foreach ($_GET as $key=>$value) {
echo '<input type="hidden" name="'.$key.'" value="'.$value.'">';
};
?>
<?php if (!empty($q)){
echo '<input type="hidden" name="category" value="buscaindice">';
echo '<input type="hidden" name="q" value="'.$q.'">';
}; ?>
<button type="submit" class="ui icon button">Limitar datas</button>
</form>
<br/><br/>
<div>
<form method="post" action="result_report.php?<?php echo $_SERVER['QUERY_STRING']; ?>">
<button type="submit" name="page" class="ui icon button" value="<?php echo $escaped_url;?>">Gerar relatório</button>
</form>
<br/><br/>
<form method="post" action="result.php?<?php echo $_SERVER['QUERY_STRING']; ?>">
<button type="submit" name="login_role" class="ui icon button" value="admin">Admin</button>
</form>
<br/>
<form method="post" action="result.php?<?php echo $_SERVER['QUERY_STRING']; ?>">
<button type="submit" name="login_role" class="ui icon button" value="annonymous">Anônimo</button>
</form>
</div>
</div>
<div class="twelve wide column">
<div class="page-header"><h3>Resultado da busca <small><?php print_r($total);?></small></h3></div>
<?php
/* Pagination - Start */
echo '<div class="ui buttons">';
if ($page > 1) {
echo '<form method="post" action="'.$escaped_url.'">';
echo '<input type="hidden" name="extra_submit_param" value="extra_submit_value">';
echo '<button type="submit" name="page" class="ui labeled icon button active" value="'.$prev.'"><i class="left chevron icon"></i>Anterior</button>';
echo '<button class="ui button">'.$page.' de '.ceil($total / $limit).'</button>';
if ($page * $limit < $total) {
echo '<button type="submit" name="page" value="'.$next.'" class="ui right labeled icon button active">Próximo<i class="right chevron icon"></i></button>';
} else {
echo '<button class="ui right labeled icon button disabled">Próximo<i class="right chevron icon"></i></button>';
}
echo '</form>';
} else {
if ($page * $limit < $total) {
echo '<form method="post" action="'.$escaped_url.'">';
echo '<input type="hidden" name="extra_submit_param" value="extra_submit_value">';
echo '<button class="ui labeled icon button disabled"><i class="left chevron icon"></i>Anterior</button>';
echo '<button class="ui button">'.$page.' de '.ceil($total / $limit).'</button>';
echo '<button type="submit" name="page" value="'.$next.'" class="ui right labeled icon button active">Próximo<i class="right chevron icon"></i></button>';
echo '</form>';
}
}
echo '</div>';
/* Pagination - End */
?>
<br/> <br/>
<h3> Escolha o estilo da Citação:</h3>
<div class="ui compact menu">
<form method="post" action="result.php?<?php echo $_SERVER['QUERY_STRING']; ?>">
<button type="submit" name="citation_style" class="ui icon button" value="apa">APA</button>
</form>
<form method="post" action="result.php?<?php echo $_SERVER['QUERY_STRING']; ?>">
<button type="submit" name="citation_style" class="ui icon button" value="abnt">ABNT</button>
</form>
<form method="post" action="result.php?<?php echo $_SERVER['QUERY_STRING']; ?>">
<button type="submit" name="citation_style" class="ui icon button" value="nlm">NLM</button>
</form>
<form method="post" action="result.php?<?php echo $_SERVER['QUERY_STRING']; ?>">
<button type="submit" name="citation_style" class="ui icon button" value="vancouver">Vancouver</button>
</form>
</div>
<div class="ui divided items">
<?php foreach ($cursor['result'] as $r): ?>
<div class="item">
<div class="image">
<h4 class="ui center aligned icon header">
<i class="circular file icon"></i>
<?php if (!empty($r['ispartof'])): ?>
<a href="result.php?ispartof=<?php echo $r['ispartof'];?>"><?php echo $r['ispartof'];?></a> |
<?php endif; ?>
<a href="result.php?type=<?php echo $r['type'];?>"><?php echo $r['type'];?></a>
</h4>
</div>
<div class="content">
<a class="header" href="single.php?_id=<?php echo $r['_id'];?>"><?php echo $r['title'];?> (<?php echo $r['year']; ?>)</a>
<!--List authors -->
<div class="extra">
<h4>Autores:</h4>
<?php if (!empty($r['authors'])): ?>
<?php foreach ($r['authors'] as $autores): ?>
<div class="ui label" style="color:black;"><i class="user icon"></i><a href="result.php?authors=<?php echo $autores;?>"><?php echo $autores;?></a></div>
<?php endforeach;?>
<?php endif; ?>
</div>
<div class="extra">
<h4>Unidades USP:</h4>
<?php if (!empty($r['unidadeUSP'])): ?>
<?php $unique = array_unique($r['unidadeUSP']); ?>
<?php foreach ($unique as $unidadeUSP): ?>
<div class="ui label" style="color:black;"><i class="university icon"></i><a href="result.php?unidadeUSP=<?php echo $unidadeUSP;?>"><?php echo $unidadeUSP;?></a></div>
<?php endforeach;?>
<?php endif; ?>
</div>
<div class="extra">
<h4>Assuntos:</h4>
<?php if (!empty($r['subject'])): ?>
<?php foreach ($r['subject'] as $assunto): ?>
<div class="ui label" style="color:black;"><i class="globe icon"></i><a href="result.php?subject=<?php echo $assunto;?>"><?php echo $assunto;?></a></div>
<?php endforeach;?>
<?php endif; ?>
<?php if (!empty($r['url'])): ?>
<?php foreach ($r['url'] as $url): ?>
<?php if ($url != ''): ?>
<br/><br/>
<a href="<?php echo $url;?>">
<div class="ui right floated primary button">
Acesso online
<i class="right chevron icon"></i>
</div>
</a>
<?php endif; ?>
<?php endforeach;?>
<?php endif; ?>
<?php if (!empty($r['doi'])): ?>
<br/><br/>
<a href="http://dx.doi.org/<?php echo $r['doi'][0];?>">
<div class="ui right floated primary button">
Acesso online
<i class="right chevron icon"></i>
</div></a>
<object height="50" data="http://api.elsevier.com/content/abstract/citation-count?doi=<?php echo $r['doi'][0];?>&apiKey=c7af0f4beab764ecf68568961c2a21ea&httpAccept=text/html"></object>
<?php endif; ?>
</div>
<div class="extra" style="color:black;">
<h4>Como citar (<?php echo strtoupper($_SESSION["citation_style"]); ?>)</h4>
<?php
$type = get_type($r['type']);
$author_array = array();
foreach ($r['authors'] as $autor_citation){
$array_authors = explode(',', $autor_citation);
$author_array[] = '{"family":"'.$array_authors[0].'","given":"'.$array_authors[1].'"}';
};
$authors = implode(",",$author_array);
if (!empty($r['ispartof'])) {
$container = '"container-title": "'.$r['ispartof'].'",';
} else {
$container = "";
};
if (!empty($r['doi'])) {
$doi = '"DOI": "'.$r['doi'][0].'",';
} else {
$doi = "";
};
if (!empty($r['url'])) {
$url = '"URL": "'.$r['url'][0].'",';
} else {
$url = "";
};
if (!empty($r['publisher'])) {
$publisher = '"publisher": "'.$r['publisher'].'",';
} else {
$publisher = "";
};
if (!empty($r['publisher-place'])) {
$publisher_place = '"publisher-place": "'.$r['publisher-place'].'",';
} else {
$publisher_place = "";
};
$volume = "";
$issue = "";
$page_ispartof = "";
if (!empty($r['ispartof_data'])) {
foreach ($r['ispartof_data'] as $ispartof_data) {
if (strpos($ispartof_data, 'v.') !== false) {
$volume = '"volume": "'.str_replace("v.","",$ispartof_data).'",';
} elseif (strpos($ispartof_data, 'n.') !== false) {
$issue = '"issue": "'.str_replace("n.","",$ispartof_data).'",';
} elseif (strpos($ispartof_data, 'p.') !== false) {
$page_ispartof = '"page": "'.str_replace("p.","",$ispartof_data).'",';
}
}
}
$data = json_decode('{
"title": "'.$r['title'].'",
"type": "'.$type.'",
'.$container.'
'.$doi.'
'.$url.'
'.$publisher.'
'.$publisher_place.'
'.$volume.'
'.$issue.'
'.$page_ispartof.'
"issued": {
"date-parts": [
[
"'.$r['year'].'"
]
]
},
"author": [
'.$authors.'
]
}');
$output = $citeproc->render($data, $mode);
print_r($output)
?>
</div>
</div>
</div>
<?php endforeach;?>
</div>
<?php
/* Pagination - Start */
echo '<div class="ui buttons">';
if ($page > 1) {
echo '<form method="post" action="'.$escaped_url.'">';
echo '<input type="hidden" name="extra_submit_param" value="extra_submit_value">';
echo '<button type="submit" name="page" class="ui labeled icon button active" value="'.$prev.'"><i class="left chevron icon"></i>Anterior</button>';
echo '<button class="ui button">'.$page.' de '.ceil($total / $limit).'</button>';
if ($page * $limit < $total) {
echo '<button type="submit" name="page" value="'.$next.'" class="ui right labeled icon button active">Próximo<i class="right chevron icon"></i></button>';
} else {
echo '<button class="ui right labeled icon button disabled">Próximo<i class="right chevron icon"></i></button>';
}
echo '</form>';
} else {
if ($page * $limit < $total) {
echo '<form method="post" action="'.$escaped_url.'">';
echo '<input type="hidden" name="extra_submit_param" value="extra_submit_value">';
echo '<button class="ui labeled icon button disabled"><i class="left chevron icon"></i>Anterior</button>';
echo '<button class="ui button">'.$page.' de '.ceil($total / $limit).'</button>';
echo '<button type="submit" name="page" value="'.$next.'" class="ui right labeled icon button active">Próximo<i class="right chevron icon"></i></button>';
echo '</form>';
}
}
echo '</div>';
/* Pagination - End */
?>
</div>
</div>
</div>
<?php
include 'inc/footer.php';
?>
<script>
$('.ui.accordion')
.accordion()
;
</script>
<script>
$('#date_init').calendar({
type: 'year'
});
</script>
<script>
$('#date_end').calendar({
type: 'year'
});
</script>
<script>
$('.ui.checkbox')
.checkbox();
</script>
</body>
</html>