forked from ormestad/publications
-
Notifications
You must be signed in to change notification settings - Fork 4
/
_publication_add.php
47 lines (42 loc) · 1.21 KB
/
_publication_add.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
<?php
require 'lib/global.php';
global $CONFIG;
$errors = [];
if($USER->auth>1) {
if(isset($_REQUEST['lab_id'])) {
$pubmed=new PHPMed();
$researchers=new NGIresearchers();
$publications=new NGIpublications();
if($lab=$researchers->getLab($_REQUEST['lab_id'])) {
$added=0;
$found=0;
if(isset($_REQUEST['from_date'])) {
// Build pubmed query with a limitation on publication date
date_default_timezone_set('UTC');
$timestamp = new DateTime($_REQUEST['from_date']);
$dt = $timestamp->format('Y/m/d');
$pmq = '('.$lab['query']['query_string']['pi'].')' . ' AND ("'.$dt.'"[Date - Publication] : "3000"[Date - Publication])';
$data=$pubmed->parsedSearch($pmq);
$found=count($data);
foreach($data as $pmid => $article) {
$add=$publications->addPublication($article,$lab);
if($add['data']['status']=="added") {
$added++;
}
}
} else {
$errors[]='from_date not set';
}
} else {
// Lab not found
$errors[]='Invalid Lab ID';
}
} else {
// lab_id not set
$errors[]='Lab ID not set';
}
} else {
// Not logged in
$errors[]='Not logged in';
}
echo json_encode(array('added' => $added, 'found' => $found, 'errors' => implode(', ', $errors)));