-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpesquisa-bdpi-anuario.php
More file actions
255 lines (227 loc) · 8.42 KB
/
pesquisa-bdpi-anuario.php
File metadata and controls
255 lines (227 loc) · 8.42 KB
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
<?php
/*
* Jan Leduc de Lara - Sistema Integrado de Bibliotecas da USP - 16/jan/2014
* alterado em 27/mar/2017
*/
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
include('autentica-oauth1.php');
include('config.php');
$page = ((isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 0);
$limit = 1000;
$offset = ($page * $limit);
$sibiocnxstr = DB_BDPI_CONNSTR;
$bdpihostname = BDPI_HOSTNAME;
$conexao = pg_connect($sibiocnxstr) or die("Nao Conectado");
$thisfilename = basename(__FILE__);
?>
<html>
<head>
<title>USP - SIBi</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<style>
* {
font-family: tahoma;
font-size: 12px;
color: black;
text-decoration: none;
}
table, th, td
{
border: 1px solid black;
border-spacing:0;
border-collapse:collapse;
padding: 1px 6px 1px 6px;
}
thead tr {
background-color: yellow;
}
tbody tr:nth-child(even) {
background-color: #FBE1CC;
}
tbody tr:nth-child(odd) {
background-color: #C0CBAF;
}
</style>
</head>
<body>
<?php
$showh = array('outs' => NULL, 'tam' => 0);
switch(true){
case (isset($_GET['mfidi']) && isset($_GET['tvl'])):
$sqlqry1=<<<EOT
select row_number() over () as linha, h.handle, 'http://${bdpihostname}/handle/'||h.handle _ahref_
from item i
inner join (select distinct item_id from metadatavalue where metadata_field_id = $1 and text_value = $2) m on (m.item_id = i.item_id)
inner join handle h on (h.resource_id = i.item_id and h.resource_type_id = 2)
where i.in_archive is true and i.withdrawn is false
limit $limit offset $offset
EOT
;
$showh = tabula($conexao,$sqlqry1,array($_GET['mfidi'],$_GET['tvl']));
break;
case (isset($_GET['mfidt']) && isset($_GET['mftt'])):
$sqlqry1=<<<EOT
select row_number() over (order by count(*) desc) as linha,
coalesce(m.text_value,'n/a') mftttit, '${thisfilename}?mfidi='||m.metadata_field_id||'&tvl='||m.text_value _ahref_, count(*) quantidade
from item i
inner join (select distinct item_id, text_value, metadata_field_id from metadatavalue where metadata_field_id = $1) m on m.item_id = i.item_id
where i.in_archive is true and i.withdrawn is false
group by m.text_value, m.metadata_field_id
order by quantidade desc
limit ${limit} offset ${offset}
EOT
;
$showh = tabula($conexao,$sqlqry1,array($_GET['mfidt']),array('mftttit' => $_GET['mftt']));
break;
case (isset($_GET['sid']) && isset($_GET['sit'])):
$sqlqry1=<<<EOT
select row_number() over (order by coalesce($1||'.'||element||'.'||qualifier,$1||'.'||element)) as linha,
coalesce($1||'.'||element ||'.'||qualifier,$1||'.'||element) metadado,
scope_note as nota_de_escopo, '{$thisfilename}?mfidt='||metadata_field_id||'&mftt='||coalesce($1||'.'||element ||'.'||qualifier,$1||'.'||element) _ahref_
from metadatafieldregistry
where metadata_schema_id = $2
order by metadado
limit ${limit} offset ${offset}
EOT
;
$showh = tabula($conexao,$sqlqry1,array($_GET['sit'],$_GET['sid']));
break;
case (isset($_GET['navby']) && ($_GET['navby']=='metadados')) :
$sqlqry1=<<<EOT
select namespace, short_id id, '${thisfilename}?sid='||metadata_schema_id||'&sit='||short_id as _ahref_
from metadataschemaregistry
EOT
;
$showh = tabula($conexao,$sqlqry1,array());
break;
case (isset($_GET['cid']) && array_key_exists('ano',$_GET) && array_key_exists('intl',$_GET) && array_key_exists('txa',$_GET)) :
$sqlqry1=<<<EOT
select row_number() over (order by name, left(A.text_value,4), B.text_value asc) as linha,
community.name, left(A.text_value,4) ano, B.text_value intl, handle.handle, 'http://${bdpihostname}/handle/'||handle.handle as _ahref_
from community
inner join communities2item on communities2item.community_id = community.community_id
left join metadatavalue A on (communities2item.item_id = A.item_id and A.metadata_field_id = 15)
left join metadatavalue B on (communities2item.item_id = B.item_id and B.metadata_field_id = 105)
left join community2community on communities2item.community_id = community2community.child_comm_id
left join handle on handle.resource_type_id = 2 and resource_id = communities2item.item_id
where community2community.child_comm_id is null
and community.community_id = $1
and coalesce(left(A.text_value,4),'') = $2
and coalesce(B.text_value,'') = $3
order by name, ano, intl asc
EOT
;
$showh = tabula($conexao,$sqlqry1,array($_GET['cid'], $_GET['ano'], $_GET['intl']));
break;
case (isset($_GET['navby']) && ($_GET['navby']=='qtrabxintlxano')) :
$sqlqry1=<<<EOT
select community.name, left(A.text_value,4) ano,
B.text_value intl, count(communities2item.item_id) q,
'${thisfilename}?cid='||community.community_id||'&ano='||coalesce(left(A.text_value,4),'')||'&intl='||coalesce(B.text_value,'')||'&txa=1' as _ahref_
from community
inner join communities2item on communities2item.community_id = community.community_id
left join metadatavalue A on (communities2item.item_id = A.item_id and A.metadata_field_id = 15)
left join metadatavalue B on (communities2item.item_id = B.item_id and B.metadata_field_id = 105)
left join community2community on communities2item.community_id = community2community.child_comm_id
where community2community.child_comm_id is null
group by community.community_id, community.name, left(A.text_value,4), B.text_value
order by name, ano, intl asc
EOT
;
$showh = tabula($conexao,$sqlqry1,array());
break;
case (count($_GET) == 0) :
$sqlqry1=<<<EOT
select A.tipo, A._ahref_ from
(select 1 as lin, 'quantidade de trabalhos por ano (nacional/internacional)' as tipo, '${thisfilename}?navby=qtrabxintlxano' as _ahref_
union select 3, 'navegar por metadados', '${thisfilename}?navby=metadados'
union select 4, 'estatísticas do awstats', 'http://www.producao.usp.br/awstats/cgi-bin/awstats.pl') as A
order by A.lin
EOT
;
$showh = tabula($conexao,$sqlqry1,array());
break;
}
if(strlen($showh['outs'])>0){
prevnext();
echo $showh['outs'];
prevnext();
echo "<br><br><br><br>\n";
}
else{
echo "nada";
}
?>
</body>
</html>
<?php
function prevnext(){
global $showh, $limit, $page, $_SERVER, $thisfilename;
if(($page>0) || ($showh['tam'] == $limit)){
$conector = '';
$newqs = '?';
if(strlen(trim($_SERVER["QUERY_STRING"]))>0){
$conector = '&';
$newqs .= $_SERVER["QUERY_STRING"];
if(isset($_GET['page'])){
$newqs = str_replace('&page='.$_GET['page'],'',$newqs);
$newqs = str_replace('?page='.$_GET['page'],'',$newqs);
}
}
if($page>0){
echo "<a href='".$thisfilename.$newqs.$conector.'page='.($page-1)."'><anterior</a> ";
}
if($showh['tam'] == $limit){
echo "<a href='".$thisfilename.$newqs.$conector.'page='.($page+1)."'>próxima></a><br>\n";
}
}
}
function tabula($cons,$sqls,$arrs,$alls = array()){
$ahref = -1;
$pgq = pg_query_params($cons, $sqls, $arrs) or die("nao foi possivel realizar o select...\n".$sqls."\n");
$arrout = array('outs' => '', 'tam' => 0);
$arrout['outs'] = "<table>\n";
$pgt = pg_num_fields($pgq);
if($pgt>0){
$arrout['outs'] .= "<thead><tr>\n";
for($i=0;$i<$pgt;$i++){
if(($ahref==-1) && strtolower(pg_field_name($pgq,$i)) == '_ahref_'){
$ahref = $i;
continue;
}
if(isset($alls[pg_field_name($pgq,$i)])) {
$arrout['outs'] .= '<th>'.implode(' ',explode('_',$alls[pg_field_name($pgq,$i)])).'</th>';
continue;
}
$arrout['outs'] .= '<th>'.implode(' ',explode('_',pg_field_name($pgq,$i))).'</th>';
}
$arrout['outs'] .= "</tr></thead>\n";
}
$arrout['outs'] .= "<tbody>\n";
while ($pgr=pg_fetch_row($pgq)) {
$arrout['outs'] .= "<tr>";
for($i=0; $i < count($pgr); $i++) {
if($ahref > -1){
if($ahref == $i) continue;
$arrout['outs'] .= "<td><a href='$pgr[$ahref]' target='_new'>$pgr[$i]</a></td>\n";
}
else {
$arrout['outs'] .= ' <td>'.$pgr[$i].'</td>'."\n";
}
}
$arrout['outs'] .= "</tr>\n";
$arrout['tam']++;
}
$arrout['outs'] .= "</tbody>\n</table>\n";
return $arrout;
}
?>