#! /usr/bin/perl
#
# send_dpc_url.pl
#
# Purpose:
#    This is a function to email the Data Product Center's URL to the
#    Project Data Center.  Running this script will overwrite an 
#    existing email address and URL that the PDC has on 'file' for 
#    the Data Product Center.
#
# Notes:
#    1)  Successfully updating the DPC URL using this script does not
#        result in any kind of response that indicates the update was
#        successful.  A web-based form on the AIM Science Data System 
#        website (http://aim.hamptonu.edu/sds/ under "Data Services/Admin")
#        provides the same functionality as this script and indicates
#        success or failure.  
#    2)  This is hard coded to GATS right now.  After the server is moved 
#        to Hamton U the variable $toAdress will need to be changed.
#

use XML::Simple;


# ---------------------------------------------------------------------
# sub send_email 
# ---------------------------------------------------------------------
#
# PURPOSE:
#   Forwards the PAN RES to the SDS manager.  This is called when
#   a pan_res may need further analysis.
#
# ARGUMENTS:
#   $subject - the subject of the forwarded email.
#   $message - the message received from the PDC. 
#
# NOTES:
#
sub send_email 
{ 
   $subject = "Subject: " . $_[0] . "\n\n";
   $message = $_[1];
    
   unless(open (MAIL, "|/usr/sbin/sendmail -t")) {
      print "error.\n";
      warn "Error starting sendmail: $!";
   }else{      
      print MAIL "From: aim.sds\@lasp.colorado.edu\n";
      print MAIL "To: aimsds\@aim.hamptonu.edu\n";  
      #print MAIL "To: k.i.beaumont\@gats-inc.com\n"; 
      #print MAIL "To: lon_riesberg\@hotmail.com\n";   
      print MAIL $subject;
      print MAIL $message;
      close(MAIL) || warn "Error closing mail: $!";
   }
}


# ---------------------------------------------------------------------
# sub dpc_url
# ---------------------------------------------------------------------
#
# Arguments: 
#    Instrument (CIPS, CDE), DPC email, DPC URL
#
sub dpc_url {

   my $xml = new XML::Simple ( RootName=>'DPC_URL');
   my $dpc = $_[0];
   my @product =(
	          {DPC   => $_[0]},
	          {EMAIL => $_[1]},
              {URL   => $_[2]},
	          );

   $out = $xml->XMLout(\@product);

   &send_email("$dpc DPC_URL", "$out");
}



#
# ---------------------------------------------------------------------
# update DPC info here
# ---------------------------------------------------------------------
#

my $email = "aim.sds\@lasp.colorado.edu";

# CDE
#my $dpc = "CDE";
#my $url = "http://lasp.colorado.edu/aim/cde/data/";

# CIPS
my $dpc = "CIPS"; 
my $url = "http://lasp.colorado.edu/aim/aim_data.htm";


&dpc_url($dpc, $email, $url);


