## $Id$

## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002 CERN.
##
## The CDSware is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## The CDSware is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
<?
<protect>
## $Id$
## DO NOT EDIT THIS FILE!  IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.


   ## Description:   function Send_FTT_Mail
   ##                This function sends a warning mail  indicating a 
   ##		     submission has been correctly finished
   ## Author:	     T.Baron
   ## PARAMETERS:    addressesFTT: addresses to which the email is sent
   ##                sourceDOC: kind of document
   ##		     edsrn: name of the file containing the reference
   ##		     authorfile: name of the file containing the author
   ##		     titleFile: name of the file containing the title
   ##		     newrnin: name of the file containing the 2nd reference
   ##		     status: one of "ADDED" or "APPROVAL" 
   ##		     textMailFTT: Text to be appended to the email

   function Send_FTT_Mail ($param_array,$MAINPATH) 
   {
      global $doctypes;

      $edsrn = $param_array[edsrn];
      $newrnin = $param_array[newrnin];

      // The title is read from the specified file.	
      $title = join("",file("$MAINPATH/".$param_array[titleFile]));
      if ($title == "") { $title = "-"; }

      // The author is read from the specified file
      $author = join("",file("$MAINPATH/".$param_array[authorfile]));

      // Any spaces or "/" characters, in the report number, are replaced
      // by the "_" character
      $fp = fopen("$MAINPATH/$edsrn","r");
      $rn = fread($fp,filesize("$MAINPATH/$edsrn"));
      fclose($fp);
      $rn = ereg_replace("[\n\r ]+","",$rn);
      $rn = ereg_replace (" ","_",$rn);
      $rn = ereg_replace ("/","_",$rn);

      if ($newrnin != "" && file_exists("$MAINPATH/$newrnin"))
      {
         $fp = fopen("$MAINPATH/$newrnin","r");
	 $additional_rn = fread($fp,filesize("$MAINPATH/$newrnin"));
	 fclose($fp);
	 $additional_rn = ereg_replace("[\n\r]+","",$additional_rn);
	 $fullrn = "$additional_rn and $rn"; 
      }
      else
         $fullrn = $rn;

      if ($param_array[textMailFTT] == "")
      {
         $email_txt = "A document has just been submitted:\n\n" 
	    . "   Report Number: " . $fullrn . "\n" 
	    . "	  Title:" . $title . "\n";

	 if ($author != "")
	    $email_txt .= "   Author:" . $author . "\n";

	 $email_txt .= "   Source:" . $param_array[sourceDoc] . "\n";

	 if ($param_array[status] == "ADDED")
	    $email_txt .= "\nAutomatic Integration Done!!!";
	 elseif ($param_array[status] == "APPROVAL")
	    $email_txt .= "\nAn email has been sent to the referee.";
      }
      else
      {
         $email_txt = $param_array[textMailFTT];
	 $tag = ereg_replace(".*<([^>]*)>.*","\\1",$email_txt);

	 while ($tag != "" && $tag != $email_txt)
	 {
	    if ($tag == "RN")
	       $email_txt = str_replace("<RN>","$fullrn",$email_txt);
	    else
	    {
	       if (is_file("$MAINPATH/$tag"))
	       {
	          $fp = fopen("$MAINPATH/$tag","r");
		  $replace_text = fread ($fp ,filesize("$MAINPATH/$tag"));
		  fclose($fp);
	       }
	       $email_txt = str_replace("<$tag>","$replace_text",$email_txt);
	    }
	    $tag = ereg_replace(".*<([^>]*)>.*","\\1",$email_txt);
	 }
      }

      mail($param_array[addressesFTT],$fullrn . " submitted!",$email_txt,"from: ".SUPPORTEMAIL."\nbcc: ".ADMIN_EMAIL);
   }
</protect>
?>