#!/usr/bin/perl
use lib '/home/website/www.linuxforge.net/tools';
use common::dbi ( db=> projects ) ;
use common::json ;
use Data::Dumper ;
use CGI::Fast ;
eval { go() } ;
my (%query,%hash) ;
my $sum_ ;
my $jstr, $limit, $ct= 0 ;
sub clear
{
%query= (), %hash= (), ;
$limit= "", $jstr= "" ;
}
sub setvals
{
%query = $q->Vars ;
$ct ++ ;
$hash{json_content_type}= "Content-type: application/json\n\n" ;
$hash{xml_content_type}= "Content-type: text/xml\n\n" ;
$hash{help}= "Folding Project Export
" ;
$hash{help}.= "Usage: export_psummary.fpl?export=json|xml&kfactor=1" ;
$hash{help}.= "
Options:
" ;
$hash{help}.= "kfactor: 0 returns all projects, 1 returns only bonus-qualified projects with k_factor > 0" ;
$hash{help}.= "
callback: JSON callback function - wrap JSON data in function name specified for cross domain support" ;
}
sub do_usage
{
print "Content-type: text/html\n\n" ;
print $hash{help} ;
}
sub pdebug
{
print "Content-type: text/html\n\n" ;
print "Request type: " . $ENV{REQUEST_METHOD} . "\n" ;
print "\nQuery:\n" . Dumper(\%query) . "\n" ;
print "Internal Hash:\n" . Dumper(\%hash) . "\n" ;
print "Requests Received: $ct\n" ;
}
sub prequests
{
print "
Requests Received: $ct\n" ;
}
sub get_data
{
$limit= "AND k_factor > 0" if $query{kfactor} ;
$sum_= $dbh->selectall_arrayref("SELECT project_id, atoms, basepoints, preferred_deadline/86400 AS preferred_deadline, final_deadline/86400 AS final_deadline, k_factor, core_name, title, ws, contact, beta, public
FROM psummary WHERE isactive='Y' $limit ORDER BY project_id", { Slice => {} } ) ;
}
sub psummary_json
{
$jstr= json_dumper($sum_) ;
print $hash{json_content_type} ;
$query{callback} ? ($hash{json} = $query{callback} . '(' . $jstr . ')') : ($hash{json}= $jstr) ;
print $hash{json} if $hash{json} ;
}
sub psummary_xml
{
print $hash{xml_content_type} ;
print "" ;
print "" ;
foreach ( @$sum_ ) {
print "" ;
print "$_->{project_id}" ;
print "$_->{atoms}" ;
print "$_->{basepoints}" ;
print "$_->{preferred_deadline}" ;
print "$_->{final_deadline}" ;
print "$_->{k_factor}" ;
print "$_->{core_name}" ;
print "$_->{title}" ;
print "$_->{ws}" ;
print "$_->{contact}" ;
print "$_->{beta}" ;
print "$_->{public}" ;
print "" ;
}
print "" ;
}
sub go
{
while ($q = CGI::Fast->new) {
&clear ;
&setvals ;
&do_usage if ! $query{export} ;
&pdebug if $query{debug} ;
&prequests if $query{requests} ;
&get_data if $query{export} eq 'json' || $query{export} eq 'xml' ;
&psummary_json if $query{export} eq 'json' ;
&psummary_xml if $query{export} eq 'xml' ;
}
}