#!/usr/bin/ksh -x
#
# Script to generate registration receipt for TELECOM exhibition
# in PDF file and attach it to email
#
# Young HAN, DAD/IS/SG, ITU, June 2001
# Olivier TROLLIET , DAD/IS/SG, ITU, June 2002
# -------------------------------------------------------------------------
# House keeping
# -------------------------------------------------------------------------
export LOUTLIB="/usr/local/lib/lout.lib"
export SYSLIB="/usr/local/bin"
export GS_DEVICE="pdfwrite"
export PDF_FILE="$home_dir_pdf_file/$_addressid.$_date_filename.pdf"
export URL_PDF_FILE="$pdf_file_url/$_addressid.$_date_filename.pdf"
export PICTURE_FILE="$home_dir_picture_file/$_addressid.eps"

if [[ -z pdf_color || $pdf_color = "" ]]
then
   export pdf_color=lightred
fi

# -------------------------------------------------------------------------
# LOUT code to generate postscript output
# -------------------------------------------------------------------------

cd $HTSH_WORK_DIR
$SYSLIB/lout -s -S << EOD |
@SysInclude {barcodes}
@SysInclude {tbl}
@SysInclude {doc}


@Doc @Text  @Begin

@LP
@LP
@CurveBox
{
@Display @Heading {Helvetica Bold +4p} @Font {
   @Underline {RECEIPT}
   }
	@Tbl
         paint { $pdf_color }
    rule  {no}

    aformat {@Cell A | @Cell indent { right } break {rlines} B }
  {
    @Rowa
    A {@IncludeGraphic {"$PICTURE_FILE"}}
    B {Geneva, $_date }
  }

@LLP
@LLP
@LLP
{BarCode Base +2p} @Font { *$_addressid* }
@LLP
{*$_addressid* }
@LLP
@LLP
@CurveBox  
{
$_addr1
@LLP
$_addr2
@LLP
$_addr3
@LLP
$_addr4
@LLP
$_addr5
@LLP
$_addr6
@LLP
$_addr7
@LLP
$_addr8
@LLP
$_addr9
@LLP
$_addr10
}
@PP
@LP 
 {Helvetica Bold +1p} @Font {
      "IMPORTANT:"
  }
@IndentedDisplay {
@Lozenge No refund or cancellation possible.
@LP
@Lozenge Please present this receipt at any visitor registration desk on-site to be issued with an entry pass.  Holders of a weekly pass who registered on-line before $ers_reg_beforedate will receive their entry pass by mail.
}
@PP
@PP
@PP
@PP
@DP
{Helvetica Base -3p} @Font {  
@Center {© Copyright 2002 ITU. All rights reserved.}
@LLP
@Center {ITU TELECOM, Place des Nations, CH-1211 Geneva 20, Switzerland }
}
}
@End @Text
EOD

# -------------------------------------------------------------------------
# The output from Lout goes to GS to create PDF file
# -------------------------------------------------------------------------

$SYSLIB/gs -q -sDEVICE=pdfwrite -sOutputFile=- - > $PDF_FILE

# -------------------------------------------------------------------------
# Informs that the file is sucessfully created
# -------------------------------------------------------------------------
if [[ "$?" = "0" ]]; then
   _result=0
fi