#!/usr/bin/perl

use strict;
use warnings;

use EPrints;

my $session = EPrints::Session->new();
return unless( defined $session );

my $userid = $session->param( "userid" );
return unless defined( $userid );

my $user = EPrints::DataObj::User->new( $session, $userid );

my $current_user = $session->current_user;

return unless( defined $user && defined $current_user && $user->get_value( "userid" ) == $current_user->get_value( 'userid' ) );

$session->send_http_header( "content_type"=>"application/msword" );

	my $page = $session->make_doc_fragment();

	my $page_title = $session->make_element( "H1", "class"=>"ep_tm_pagetitle"); 

	$page_title->appendChild( $user->render_citation( 'profile_title' ) );
	$page->appendChild( $page_title );

	my $h2 = $session->make_element( "H2" ); 
   	$h2->appendChild( $session->html_phrase( "meprints:profile:userdata" ) );
	$page->appendChild( $h2 );

	my ( $table, $tr, $td, $widget, $box );

	$table = $session->make_element( "table", 'cellpadding'=>'0', cellspacing=>'0');

	$widget = $session->plugin( 'MePrints::Widget::Details' );
	$widget->{user} = $user;
	$tr = $session->make_element( "tr" );
	$table->appendChild( $tr );
	$td = $session->make_element( "td", valign=>"top" );
	$tr->appendChild( $td );
	$td->appendChild( $widget->render_content );

	$page->appendChild( $table );

	$h2 = $session->make_element( "H2" ); 
   	$h2->appendChild( $session->html_phrase( "meprints:profile:outputs" ) );
	$page->appendChild( $h2 );

	$table = $session->make_element( "table", 'cellpadding'=>'0', cellspacing=>'0');

	$widget = $session->plugin( 'MePrints::Widget::AllOutputs' );
	$widget->{user} = $user;
	$tr = $session->make_element( "tr" );
	$table->appendChild( $tr );
	$td = $session->make_element( "td", valign=>"top" );
	$tr->appendChild( $td );
	$td->appendChild( $widget->render_content );

	$page->appendChild( $table );


print EPrints::XML::to_string($page, "utf-8", 1);

$session->terminate();
exit;

