#!/usr/bin/perl -w -I/usr/share/eprints3/perl_lib
## Search for eprints and display results in XML format

use EPrints;
use strict;

my @accept_ip;

## Remove ## and edit this list if you want to limit access
##@accept_ip = ('127.0.0.1', '174.143.144.233', '174.143.243.191', '212.44.29.61', '212.44.29.60', '130.209.116.110');

## Testing if array is empty
my $is_empty;
if (@accept_ip) { $is_empty = 0; } else { $is_empty = 1; };

if ((grep { $_ eq $ENV{REMOTE_ADDR} } @accept_ip) || ($is_empty == 1)) 
{
my $wait = "0";
my $repo = EPrints->new()->current_repository();

exit( 0 ) unless( defined $repo );
## Get the keywords (can be multiple)
my $abstract = $repo->param("abstract");

## Get the date (for updates)
my $date = $repo->param("date");
if ($date == '') { $date = "-2013" };
## Get the user id (or anything else that will be needed
## to identify the results for VN
my $uid = $repo->param("uid");

## Get archive dataset
my $ds = $repo->dataset( "archive" );


## Create a filter that will be used for the search
my $filters = [
        { meta_fields=>[ "abstract" ],
          merge=>"ANY",
          value=>"$abstract"
        },
        { meta_fields=>[ "date" ],
          value=>"$date"
        },
        ];

## Perform the search
my $list = $ds->search(filters=>$filters);

$wait = $repo->param("wait");
if ($wait == "1") {
sleep(2);
}

## Print data
my $results = $list->export( "XML" );
print "$results";
exit;
}
else
{
print "Access denied.";
exit;
}
