-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.php
527 lines (465 loc) · 21.1 KB
/
dataset.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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
<?php
/**
* @file dataset.php
* @brief Dataset page
*
* This is a page: so it includes modules: here the _dataset.php module
*
* @author Nathalie Castells
* @date 9/27/2018
*
* TODO: add contributors
*/
include_once 'includes/init.php'; // these are the settings that refer to more than one page
$datasetTitle = "";
$dateCreation = "";
$datePublication = "";
$dateUpdate = "";
$getAuthors = "";
$getAuthorOrganisation = "";
$getContributors = "";
$hasCT = 0;
$getPublisher = "";
$isAuthor = 0;
$refAuthor = "DEFAULT";
$onload = "";
$actualURL = "";
$strDownload = "";
$strMeta = "";
$strUserArea = "";
$zipfile = "";
$pageinfo = getPageInfo($expt);
$KeyRef = $pageinfo['KeyRef'];
$page_title .= ' dataset: ' . $dataset;
$page_description = "";
$page_keywords .="";
$datasetParts = explode("-", $dataset);
$pageinfo = getPageInfo($expt);
$KeyRef = $pageinfo['KeyRef'];
$exptFolder = 'metadata/' . $expt;
$fileDataset = $exptFolder . '/' . $datasetParts[1] . '/' . $dataset . '.json';
$dsinfo = "";
$hasDataset = file_exists($fileDataset);
if ($hasDataset) {
$jdataset = file_get_contents($fileDataset);
$jdataset8 = utf8_encode($jdataset);
$dsinfo = json_decode($jdataset8, true);
$page_description = htmlentities($dsinfo['description'][0]['description']);
$page_keywords .= htmlentities(implode(' , ', $dsinfo['keywords']));
}
if (isset($_SESSION['visitedPages'])) {
$_SESSION['visitedPages'][] = array(
"dataset" => $dataset,
"expt" => $expt
);
} else {
$_SESSION['visitedPages'] = array();
$_SESSION['visitedPages'][] = array(
"dataset" => $dataset,
"expt" => $expt
);
}
$_SESSION['page'] = 'dataset/' . $expt . '/' . $dataset;
$_SESSION['dataset'] = $dataset;
$_SESSION['expt'] = $expt;
function printVocab($localwords)
{
$strvocab = "";
foreach ($localwords as $localword) {
$slug = str_replace(' ', '-', $localword);
$vocab = "<a href=\"keyword/".$slug."\">".$localword."</a>";
$strvocab .= $vocab . " - ";
}
$strvocab = substr_replace($strvocab, " ", - 2); // removes the last -
return $strvocab;
}
$relDatasets = 'List of Related Datasets';
$relDocuments = 'List of Related Documents';
if ($hasDataset) {
$datasetFolder = $dsinfo["shortName"];
$datasetTitle = $dsinfo['name'];
if (strstr(strtolower($datasetTitle), 'dataset'))
{
// title remains the same
}
else
{
$datasetTitle = 'Dataset: '. $dsinfo['name'];
}
$DOI = $dsinfo["identifier"];
$actualURL = "";
$page_title = 'eRA Dataset: '. $dataset. ' - '. $dsinfo['name'];
//$testmbsubstring = substr($DOI, 0,3);
if (substr($DOI, 0, 3) == "10.") {
$actualURL = "https://doi.org/".$DOI;
}
else {
$actualURL = $dsinfo["url"];
}
if (isset($_SESSION['downloads'])) {
if (in_array($DOI, $_SESSION['downloads'])) {
$strUserArea .= "<li class=\"list-group-item\">Downloaded today</li>";
}
}
// this decide what modal we give depending on the type of dataset: the OA at the moment, does not record the download.
$dstype = $dsinfo["dstype"];
$dstypeModal = $dsinfo["dstype"];
$dstypeStr = "<a href=\"info/howtoaccessdata#OA\" \" target=\"out\">Open</a>";
if ($dsinfo["dstype"] != 'OA') {
$dstypeStr = "<a href=\"info/howtoaccessdata#Other\" \" target=\"out\">Registration</a>";
$dstypeModal = 'Other';
}
//$modal = "#modalClickTrough" . $dstypeModal;
$modal = "#modalClickTroughOA";
$butDownload = "<button type=\"button\" class=\"btn btn-primary my-1 mx-3\" data-toggle=\"modal\"
data-target=\"" . $modal . "\">Download Data</button>";
/* $butLogin = "<button type=\"button\" class=\"btn btn-info my-1 mx-3 \" data-toggle=\"modal\"
data-target=\"#modalLogin\">" . $registeredUser . "</button>"; */
if ($dsinfo["dateCreated"]) {
$dateCreation .= "<li class=\"list-group-item\"><b>Created: </b> ".$dsinfo["dateCreated"]."</li>";
} else {
}
if ($dsinfo["datePublished"]) {
$datePublication .= "<li class=\"list-group-item\"><b>Published: </b> ".$dsinfo["datePublished"]."</li>";
} else {
}
$dateUpdate = "";
if ($dsinfo["dateModified"]) {
$dateUpdate .= "<li class=\"list-group-item\"><b>Updated: </b> ".$dsinfo["dateModified"]."</li>";
} else {
}
if (is_array($dsinfo['creator'])) {
foreach ($dsinfo['creator'] as $creator) {
if ($creator['type'] == 'organization') {
$getAuthorOrganisation .= $creator['name'] . ", ";
}
if ($creator['type'] == 'Person') {
$getAuthors .= $creator['Name'] . ", ";
$isAuthor = 1;
}
}
}
if (is_array($dsinfo['contributor'])) {
$tblContributors = " \n <h3>Contributors</h3><ul>";
foreach ($dsinfo['contributor'] as $contributor) {
$hasCT = 1;
if ($contributor['type'] == 'Person') {
$getContributors .= $contributor['name'] . ", ";
$strRole = preg_replace('/([a-z])([A-Z])/', '${1} ${2}', $contributor['jobTitle']);
$strRole = strtolower($strRole);
$strRole = ucfirst($strRole);
$tblContributors .= "\n\t<li><b>" . $contributor['name'] . ": </b> " . $strRole."</li>";
}
}
$tblContributors .= "</ul>";
}
$getAuthorOrganisation = rtrim($getAuthorOrganisation, ', ');
$getAuthors = rtrim($getAuthors, ', ');
$getContributors = rtrim($getContributors, ', ');
if (is_array($dsinfo['publisher'])) {
$getPublisher = $dsinfo['publisher']['name'];
}
$refAuthor = $getAuthorOrganisation;
if ($isAuthor > 0) {
$refAuthor = $getAuthors;
}
$year = "" . $dsinfo["publication_year"];
$risfile = $exptFolder . "/" . $datasetFolder . "/" . $dataset . ".ris";
$enwfile = $exptFolder . "/" . $datasetFolder . "/" . $dataset . ".enw";
if (is_array($dsinfo['distribution'])) {
$zipfile = $exptFolder . "/" . $datasetFolder . "/" . $dataset . ".zip";
if (file_exists($zipfile)) {
$distribution = "<ul>";
foreach ($dsinfo['distribution'] as $filedownloads) {
$distribution .= "<li>";
// $distribution .="<a href=\"" . $exptFolder . "/" . $datasetFolder . "/" . $filedownloads['URL'] . "\">";
$distribution .= $filedownloads['name'] . " (" . $filedownloads['encodingFormat'] . ")";
// $distribution .= "</a>";
$distribution .= "</li>";
}
$distribution .= "</ul>";
} else {
$strDownload = "";
$distribution = "In preparation";
}
}
if (is_array($dsinfo['image'])) {
$illustration = "";
foreach ($dsinfo['image'] as $imgsrc) {
$illustration .= "<div class=\"text-center\"><img src=\"";
// $distribution .="<a href=\"" . $exptFolder . "/" . $datasetFolder . "/" . $filedownloads['URL'] . "\">";
$illustration .= $exptFolder . "/" . $datasetFolder . "/" . $imgsrc['URL'] . " \" class=\"img-fluid\" alt=\"" . $imgsrc['caption'] . "\">";
$illustration .= "<p><b><i>" . $imgsrc['caption'] . "</i></b></p></div>";
// $distribution .= "</a>";
}
}
// added 2024-02-07 - to add the extra funders
if (is_array($dsinfo['funding'])) {
$countFunders = 0;
// assuming we can find etra funders, we start the text for them, A header, then a UL
$strFunders = "<h3 class=\"m-3\">Additional Funding sources</h4>
<p class=\"m-3\">This project also received funding from the following sources<p>
<ul>";
// - this lists the 3 or 4 which are already harcoded within the text. They don't need to be listed again
// - N/A represents LAT until something better comes up.
// - Because the json file does not have teh id for the funder, (like 1, 2, 7, 14) we use the alternameName which is teh grant number
// - Because we use strpos > 0 whatch out that the string we are looking for is not at the start of the altername name. So we look for /A not N/A !
$default = array("000J0300","00005189", "23NB0007", "/A" );
foreach ($dsinfo['funding'] as $funder) {
$isDefault = 0;
//Lets find out is the funder in hand is a default one or not.
foreach ($default as $item){
if (strpos($funder['alternateName'], $item ) > 0 ) {
//found it
$isDefault += 1;
}
}
if ($isDefault == 0 ) {
//we can add this info to the string as this is not found in the default list.
/*
"funding": [{
"type": "Grant",
Title of the grant is: "name": "S2N - Soil to Nutrition Institute Strategic Programme (2017-2022)",
Grant number is: "alternateName": "BBS/E/C/00010310",
URL to the actual grant is: "url": "http://tinyurl.com/grant00010310",
A text to replace all information is : "description": null,
List of work packages is: "disambiguatingDescription": "BBS/E/C/00010310 (WP1)",
this is the fuunding organisationL "funder": {
"type": "organization",
"name": "Biotechnology and Biological Sciences Research Council",
The URL of the funder "url": "https://www.ukri.org/councils/bbsrc/",
The DOi or ROR information for the funder: "identifier": "https://doi.org/10.13039/501100000268"
}
},
*/
if ($funder['description']) {
$strFunders .= "<li>".$funder['description']."<br />";
if ($funder['url']) {
$strFunders .= "<a target = \"_blank\" href=\"". $funder['url'] . "\"> " . $funder['alternateName'] . "</a> <sup><i class=\"fa fa-external-link\" aria-hidden=\"true\"></i></sup> - ";
}
$strFunders .= (isset($funder['disambiguatingDescription']))? " - ". $funder['disambiguatingDescription'] : "";
$strFunders .= "</li>";
} else {
$strFunders .= "<li>".$funder['name']." <a target = \"_blank\" href=\"". $funder['identifier'] . "\"> " . $funder['alternateName'] . "</a> <sup><i class=\"fa fa-external-link\" aria-hidden=\"true\"></i></sup> - ". $funder['disambiguatingDescription'] ." from <a href=\"".$funder['funder']['url']."\">".$funder['funder']['name']. "</li>";
}
$countFunders ++;
}
}
$strFunders .= "</ul>";
//If we have not found any founders except the ones listed in default, then we reset the string to nothing
if ($countFunders == 0 ) {$strFunders = "";}
}
if (is_array($dsinfo['relatedIdentifier'])) {
$hasDatasets = 0;
$hasDocuments = 0;
$hasPVersion = 0;
$hasNVersion = 0;
$relDatasets_prev = " <div class=\"card\">
<div class=\"card-header\" id=\"Related\">
<h5 class=\"mb-0\">
<button class=\"btn btn-link collapsed\" data-toggle=\"collapse\"
data-target=\"#collapseFive\" aria-expanded=\"false\"
aria-controls=\"collapseFive\">Related Datasets</button>
</h5>
</div>
<div id=\"collapseFive\" class=\"collapse\" aria-labelledby=\"Related\"
data-parent=\"#accordion\">
<div class=\"card-body\">";
$relDatasets = " <h3>Related Datasets</h3> <ul>";
$prevVersions = " <h3>Previous Versions</h3> <ul>";
$newVersions = " <h3>Newer Versions</h3> <ul>";
$newVersionShort ="<ul>";
$relDocuments_prev = "\n<div class=\"card\">
\n<div class=\"card-header\" id=\"Supporting\">
\n\t<h5 class=\"mb-0\">
\n\t <button class=\"btn btn-link collapsed\" data-toggle=\"collapse\"
data-target=\"#collapseSupporting\" aria-expanded=\"false\"
aria-controls=\"collapseSupporting\">Related Documents</button>
\n\t</h5>
\n\t</div>
\n\t<div id=\"collapseSupporting\" class=\"collapse\"
aria-labelledby=\"Supporting\" data-parent=\"#accordion\">
\n\t<div class=\"card-body\">";
$relDocuments = "\n<h3>Related Documents</h3> <ul>";
foreach ($dsinfo['relatedIdentifier'] as $n => $ris) {
switch ($ris['relatedIdentifierType']) {
case "DOI":
$urlPrefix = "https://doi.org/";
break;
case "URL":
$urlPrefix = "";
break;
break;
case "PURL":
$urlPrefix = "";
break;
case "ISBN":
$ris['relatedIdentifier'] = str_replace("-", "", $ris['relatedIdentifier']);
$urlPrefix = "https://isbnsearch.org/isbn/";
break;
}
if ($ris['relatedIdentifierGeneralType'] == "Text") {
$hasDocuments = 1;
$relDocuments .= "<li> <a target = \"_blank\" href=\"" . $urlPrefix . $ris['relatedIdentifier'] . "\"> " . $ris['name'] . "</a> <sup><i class=\"fa fa-external-link\" aria-hidden=\"true\"></i></sup>: </li>";
} elseif ($ris['relatedIdentifierGeneralType'] == "Dataset") {
if ($ris['rt_id'] == 13) {
$hasPVersion = 1;
$prevVersions .= "\n<li> " . $ris['relationTypeValue'] . ": <a href=\"" . $urlPrefix . $ris['relatedIdentifier'] . "\"> " . $ris['name'] . "</a></li>";
} elseif ($ris['rt_id'] == 14) {
$hasNVersion = 1;
$newVersions .= "\n<li> <a href=\"" . $urlPrefix . $ris['relatedIdentifier'] . "\"> " . $ris['name'] . "</a></li>";
$newVersionShort .= "\n<li><a href=\"" . $urlPrefix . $ris['relatedIdentifier'] . "\"> " . $ris['name'] . "</a></li>";
} else {
$hasDatasets = 1;
$relDatasets .= "\n<li> <a href=\"" . $urlPrefix . $ris['relatedIdentifier'] . "\"> " . $ris['name'] . "</a></li>";
}
} else {}
}
$relDatasets .= "\n</ul>";
$relDocuments .= "\n</ul>";
$prevVersions .= "\n</ul>";
$newVersions .= "\n</ul>";
$newVersionShort .= "\n</ul>";
}
if (is_array($dsinfo['description'])) {
$arrDescription = array();
foreach ($dsinfo['description'] as $n => $description) {
switch ($description['descriptionType']) {
case "Abstract":
$arrDescription['Abstract'] = $description['description'];
break;
case "Methods":
$arrDescription['Methods'] = $description['description'];
break;
case "TechnicalInfo":
$arrDescription['TechnicalInfo'] = $description['description'];
break;
case "TableOfContents":
$arrDescription['TableOfContents'] = $description['description'];
break;
case "Provenance":
$arrDescription['Provenance'] = $description['description'];
break;
case "Quality":
$arrDescription['Quality'] = $description['description'];
break;
case "Other":
$arrDescription['Other'] = $description['description'];
break;
default:
$arrDescription['Other'] = $description['description'];
}
}
}
/*
* we check that the is downloading a file.
* From the environment: we have everything we need about the file being downloaded and also the username of the user
* On donload:
* 1: make a SQL that writed in the usermanagment table that the user is downloading that dataset at that time
*/
$link = LogMangaAd();
$stmt = $link->prepare("INSERT INTO downloads (`position`, `IP`, DOI, `dldate`,`dlresult`, fullname, country, information, institution) VALUES(?,?,?,?,?,?,?,?,?)");
//$stmt -> bind_param("sssssssss", $positionValue, $IpAddress, $DOI, $today, $dlresult, $fullname, $country, $information, $institution );
$IpAddress = getIp();
if (isset($_REQUEST['dlform'])) {
$today = date('Y/m/d');
if (!isset($_SESSION['user']['startSession'])) {
$_SESSION['user']['startSession'] = $today;
$killdate = date_create($today);
date_add($killdate , date_interval_create_from_date_string("7 days"));
$_SESSION['user']['killSession'] = date_format($killdate,"Y/m/d");
}
//$_SESSION['user']['killSession'] = '2023/01/01'; //testing so need to kill session everytime
$_SESSION['user']['lastDownload'] = $today;
// Check the file exists or not
if (file_exists($zipfile)) {
// we are not collecting emails, but that could change
if (isset($_REQUEST['InputEmail'])) {
$positionValue = mysqli_real_escape_string($link, $_REQUEST['InputEmail']);
$_SESSION['user']['positionValue'] = $positionValue;
}
$positionValue = "Anonymous";
$fullname = "No Name";
$institution = "NONE";
$information = "NONE";
$country = "GB";
$_SESSION['downloads'][] = $DOI;
//we get it from the request and also put it in session! this might need to be done
// if not from the request, we get it from session - if in the session, we do not ask again
if (isset($_REQUEST['InputName'])) {
$fullname = mysqli_real_escape_string($link, $_REQUEST['InputName']);
$_SESSION['user']['fullname'] = $fullname;
} elseif (isset($_SESSION['user']['fullname'])) {
$fullname = $_SESSION['user']['fullname'];
}
if (isset($_REQUEST['inputCountry'])) {
$country = mysqli_real_escape_string($link, $_REQUEST['inputCountry']);
$_SESSION['user']['country'] = $country;
} elseif (isset($_SESSION['user']['country'])) {
$country = $_SESSION['user']['country'];
}
if (isset($_REQUEST['information'])) {
$information = mysqli_real_escape_string($link, $_REQUEST['information']);
$_SESSION['user']['information'] = $information;
} elseif (isset($_SESSION['user']['information'])) {
$information = $_SESSION['user']['information'];
}
if (isset($_REQUEST['InputInstitute'])) {
$institution = mysqli_real_escape_string($link, $_REQUEST['InputInstitute']);
$_SESSION['user']['institution'] = $institution;
} elseif (isset($_SESSION['user']['institution'])) {
$institution = $_SESSION['user']['institution'];
}
$dlresult = $siteType ;
$stmt -> bind_param("sssssssss", $positionValue, $IpAddress, $DOI, $today, $dlresult, $fullname, $country, $information, $institution );
// blocking the favorite ROBOT from russia
if ($IpAddress != "213.109.202.67") {
if ($stmt->execute()) { $onload = " onload=\"modal();\" "; }
}
$strMeta .= " <meta
http-equiv=\"refresh\"
content=\"1; URL=".$root . $zipfile . '?' . time()."\">"; // the Time function to avoid getting the file from the
} else {
//No file present -
$dlresult = "NO FILE" ;
if ($stmt->execute()) {$strUserArea .= "<li>File Not Found - Team notified </li>"; }
}
}
$strUserArea .= "";
mysqli_close($link);
if (file_exists($zipfile)) {
$strDownload = $butDownload;
} else {
$strDownload = "";
}
if ( $dsinfo["isExternal"] ) {$strDownload = "";}
} else {}
?>
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<?php
echo $strMeta;
include 'includes/meta.html'; // that is the <meta and link tags> superseeds head.html
// that is the <head tags>
$script = ''; // $script is added to the header as the
if (isset($jdataset8)) {
$script = "<script type=\"application/ld+json\">" . $jdataset8 . "</script>";
echo $script;
}
?>
</head>
<body <?php echo $onload; ?>>
<div class="container bg-white px-0">
<?php
include 'includes/header.html'; // all the menus at the top
// -- start dependent content ---------------------------------------------------------
include '_dataset.php';
// -- start footers -----------------------------
include_once 'includes/footer.html';
// --------------- page specific scripts -------------
?>
<?php
// ---------------------------------------------------
include_once 'includes/finish.inc';
?>